From 6a05b7a9c1613e76059c4669be4e6c3360aaafe7 Mon Sep 17 00:00:00 2001 From: Xerbo Date: Tue, 25 Feb 2020 19:54:41 +0000 Subject: [PATCH] Add -o flag Allows custom filenames for the output image Fix formatting in help text --- README.md | 3 +++ common.h | 1 + main.c | 29 +++++++++++++++++------------ pngio.c | 6 +++++- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 8f59e81..211092f 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,9 @@ Defaults: off -m Map file generated by wxmap +-o +Output image filename + -r Realtime decode. When decoding in realtime it is highly recommended to choose a plain raw image. ``` diff --git a/common.h b/common.h index 4d4920e..9e79c44 100644 --- a/common.h +++ b/common.h @@ -42,4 +42,5 @@ typedef struct { char *map; // Path to a map file char *path; // Output directory int realtime; // Realtime decoding + char *filename; // Output filename } options_t; \ No newline at end of file diff --git a/main.c b/main.c index 4ee7ea7..5d4ebea 100644 --- a/main.c +++ b/main.c @@ -61,7 +61,7 @@ static SNDFILE *audioFile; // Number of channels in audio file int channels = 1; -// Function predeclarations +// Function declarations static int initsnd(char *filename); int getsample(float *sample, int nb); static int processAudio(char *filename, options_t *opts); @@ -76,11 +76,11 @@ int main(int argc, char **argv) { usage(); } - options_t opts = { "r", "", 19, "", ".", 0 }; + options_t opts = { "r", "", 19, "", ".", 0, "" }; // Parse arguments int opt; - while ((opt = getopt(argc, argv, "m:d:i:s:e:r")) != EOF) { + while ((opt = getopt(argc, argv, "o:m:d:i:s:e:r")) != EOF) { switch (opt) { case 'd': opts.path = optarg; @@ -104,6 +104,9 @@ int main(int argc, char **argv) { case 'r': opts.realtime = 1; break; + case 'o': + opts.filename = optarg; + break; default: usage(); } @@ -139,14 +142,15 @@ static int processAudio(char *filename, options_t *opts){ strcpy(path, dirname(path)); sscanf(basename(filename), "%[^.].%s", img.name, extension); - // Set output filename to current time when in realtime mode if(opts->realtime){ + // Set output filename to current time when in realtime mode time_t t; time(&t); strncpy(img.name, ctime(&t), 24); - } - if(opts->realtime) initWriter(opts, &img, IMG_WIDTH, MAX_HEIGHT, "Unprocessed realtime image", "r"); + // Init a row writer + initWriter(opts, &img, IMG_WIDTH, MAX_HEIGHT, "Unprocessed realtime image", "r"); + } if(strcmp(extension, "png") == 0){ // Read PNG into image buffer @@ -185,7 +189,7 @@ static int processAudio(char *filename, options_t *opts){ printf("Total rows: %d\n", img.nrow); // Fallback for detecting the zenith - // TODO: encode zenith in raw images + // TODO: encode metadata in raw images if(opts->map != NULL && opts->map[0] != '\0' && zenith == 0){ fprintf(stderr, "Guessing zenith in image, map will most likely be misaligned.\n"); zenith = img.nrow / 2; @@ -258,7 +262,7 @@ static int processAudio(char *filename, options_t *opts){ ImageOut(opts, &img, CHB_OFFSET, CH_WIDTH, desc, ch.id[img.chB], NULL); } - // Distribution image + // Value distribution image if (CONTAINS(opts->type, 'd')) distrib(opts, &img, "d"); @@ -326,10 +330,11 @@ static void usage(void) { " c: False color\n" " t: Temperature\n" " m: MCIR\n" - " -d Image destination directory.\n" - " -s [15-19] Satellite number\n" - " -m Map file\n" - " -r Realtime decode\n" + " -d Image destination directory.\n" + " -o Output filename\n" + " -s [15-19] Satellite number\n" + " -m Map file\n" + " -r Realtime decode\n" "\nRefer to the README for more infomation\n"); exit(EINVAL); diff --git a/pngio.c b/pngio.c index 9de24c6..e34d504 100644 --- a/pngio.c +++ b/pngio.c @@ -193,7 +193,11 @@ png_text meta[] = { int ImageOut(options_t *opts, image_t *img, int offset, int width, char *desc, char *chid, char *palette){ char outName[384]; - sprintf(outName, "%s/%s-%s.png", opts->path, img->name, chid); + if(opts->filename == NULL || opts->filename[0] == '\0'){ + sprintf(outName, "%s/%s-%s.png", opts->path, img->name, chid); + }else{ + sprintf(outName, "%s/%s", opts->path, opts -> filename); + } meta[1].text = desc; meta[1].text_length = sizeof(desc);