Browse Source

Improve syncing, fix segfault

Lack of clamping while reading a pixel from a palette resulted in reading invalid memory
tags/v1.8.0
Xerbo 4 years ago
parent
commit
e6674512e3
2 changed files with 10 additions and 3 deletions
  1. +8
    -1
      dsp.c
  2. +2
    -2
      pngio.c

+ 8
- 1
dsp.c View File

@@ -209,7 +209,6 @@ int getpixelv(float *pvbuff, int count) {
}

// Get an entire row of pixels, aligned with sync markers
// FIXME: loses sync easily
int getpixelrow(float *pixelv, int nrow, int *zenith, int reset) {
static float pixels[PixelLine + SyncFilterLen];
static int npv;
@@ -256,6 +255,7 @@ int getpixelrow(float *pixelv, int nrow, int *zenith, int reset) {

if (synced < 8) {
int mshift;
static int lastmshift;

if (npv < PixelLine + SyncFilterLen) {
res = getpixelv(&(pixelv[npv]), PixelLine + SyncFilterLen - npv);
@@ -276,6 +276,13 @@ int getpixelrow(float *pixelv, int nrow, int *zenith, int reset) {
}
}

// Stop rows dissapearing into the void
int mshiftOrig = mshift;
if(abs(lastmshift-mshift) > 3 && nrow != 0){
mshift = 0;
}
lastmshift = mshiftOrig;
// If we are already as aligned as we can get, just continue
if (mshift == 0) {
synced++;


+ 2
- 2
pngio.c View File

@@ -294,8 +294,8 @@ int applyUserPalette(float **prow, int nrow, char *filename, rgb_t **crow){

for(int y = 0; y < nrow; y++){
for(int x = 0; x < CH_WIDTH; x++){
int cha = prow[y][x + CHA_OFFSET];
int chb = prow[y][x + CHB_OFFSET];
int cha = CLIP(prow[y][x + CHA_OFFSET], 0, 255);
int chb = CLIP(prow[y][x + CHB_OFFSET], 0, 255);
crow[y][x + CHA_OFFSET] = pal_row[chb][cha];
}
}


Loading…
Cancel
Save