From 61fb740c198763f30744c0069cbd52b33d4af717 Mon Sep 17 00:00:00 2001 From: Xerbo Date: Thu, 16 Apr 2020 23:27:55 +0100 Subject: [PATCH] Small bug fixes Processing more than one image at once didn't work (quite bodgey) MCIR would run even without a map Error handling for map/raw images that don't exist --- dsp.c | 4 +++- main.c | 6 +++--- pngio.c | 18 +++++++++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/dsp.c b/dsp.c index e16e9bf..bf02f1b 100755 --- a/dsp.c +++ b/dsp.c @@ -210,13 +210,15 @@ int getpixelv(float *pvbuff, int count) { // Get an entire row of pixels, aligned with sync markers // FIXME: skips noisy lines with no findable sync marker -int getpixelrow(float *pixelv, int nrow, int *zenith) { +int getpixelrow(float *pixelv, int nrow, int *zenith, int reset) { static float pixels[PixelLine + SyncFilterLen]; static int npv; static int synced = 0; static double max = 0.0; static double minDoppler = 100; + if(reset) synced = 0; + double corr, ecorr, lcorr; int res; diff --git a/main.c b/main.c index 5d4ebea..dc2a7a1 100644 --- a/main.c +++ b/main.c @@ -32,7 +32,7 @@ // DSP extern int init_dsp(double F); -extern int getpixelrow(float *pixelv, int nrow, int *zenith); +extern int getpixelrow(float *pixelv, int nrow, int *zenith, int reset); // I/O extern int readRawImage(char *filename, float **prow, int *nrow); @@ -156,7 +156,7 @@ static int processAudio(char *filename, options_t *opts){ // Read PNG into image buffer printf("Reading %s\n", filename); if(readRawImage(filename, img.prow, &img.nrow) == 0){ - fprintf(stderr, "Skipping %s; see above.\n", img.name); + fprintf(stderr, "Skipping %s\n", img.name); return 0; } }else{ @@ -171,7 +171,7 @@ static int processAudio(char *filename, options_t *opts){ img.prow[img.nrow] = (float *) malloc(sizeof(float) * 2150); // Write into memory and break the loop when there are no more samples to read - if (getpixelrow(img.prow[img.nrow], img.nrow, &zenith) == 0) + if (getpixelrow(img.prow[img.nrow], img.nrow, &zenith, (img.nrow == 0)) == 0) break; if(opts->realtime) pushRow(img.prow[img.nrow], IMG_WIDTH); diff --git a/pngio.c b/pngio.c index 6fe6a4d..1727d88 100644 --- a/pngio.c +++ b/pngio.c @@ -33,6 +33,10 @@ extern rgb_t RGBcomposite(rgb_t top, float top_a, rgb_t bottom, float bottom_a); int mapOverlay(char *filename, rgb_t **crow, int nrow, int zenith, int MCIR) { FILE *fp = fopen(filename, "rb"); + if(!fp) { + fprintf(stderr, "Cannot open %s\n", filename); + return 0; + } // Create reader png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); @@ -133,6 +137,10 @@ int mapOverlay(char *filename, rgb_t **crow, int nrow, int zenith, int MCIR) { int readRawImage(char *filename, float **prow, int *nrow) { FILE *fp = fopen(filename, "r"); + if(!fp) { + fprintf(stderr, "Cannot open %s\n", filename); + return 0; + } // Create reader png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); @@ -205,7 +213,7 @@ int ImageOut(options_t *opts, image_t *img, int offset, int width, char *desc, c FILE *pngfile; // Reduce the width of the image to componsate for the missing telemetry - int fc = strcmp(desc, "False Color") == 0; + int fc = (chid[0] == 'c'); int greyscale = 0; int skiptele = 0; if(opts->effects != NULL && CONTAINS(opts->effects, 't')){ @@ -227,7 +235,7 @@ int ImageOut(options_t *opts, image_t *img, int offset, int width, char *desc, c return 0; } - if(palette == NULL && !CONTAINS(opts->effects, 'p') && !fc && opts->map[0] == '\0' && strcmp(chid, "MCIR") != 0){ + if(palette == NULL && !CONTAINS(opts->effects, 'p') && !fc && opts->map[0] == '\0' && chid[0] != 'm'){ greyscale = 1; // Greyscale image @@ -281,11 +289,11 @@ int ImageOut(options_t *opts, image_t *img, int offset, int width, char *desc, c // Map stuff if(opts->map != NULL && opts->map[0] != '\0'){ - if(mapOverlay(opts->map, crow, img->nrow, zenith, strcmp(desc, "MCIR") == 0) == 0){ - fprintf(stderr, "Skipping MCIR generation; see above.\n"); + if(mapOverlay(opts->map, crow, img->nrow, zenith, (chid[0] == 'm')) == 0){ + fprintf(stderr, "Skipping MCIR generation.\n"); return 0; } - }else if(strcmp(chid, "MCIR") == 0){ + }else if(chid[0] == 'm'){ fprintf(stderr, "Skipping MCIR generation; no map provided.\n"); return 0; }