Browse Source

Add -o flag

Allows custom filenames for the output image
Fix formatting in help text
tags/v1.8.0
Xerbo 4 years ago
parent
commit
6a05b7a9c1
4 changed files with 26 additions and 13 deletions
  1. +3
    -0
      README.md
  2. +1
    -0
      common.h
  3. +17
    -12
      main.c
  4. +5
    -1
      pngio.c

+ 3
- 0
README.md View File

@@ -73,6 +73,9 @@ Defaults: off
-m <file>
Map file generated by wxmap

-o <filename>
Output image filename

-r
Realtime decode. When decoding in realtime it is highly recommended to choose a plain raw image.
```


+ 1
- 0
common.h View File

@@ -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;

+ 17
- 12
main.c View File

@@ -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 <dir> Image destination directory.\n"
" -s [15-19] Satellite number\n"
" -m <file> Map file\n"
" -r Realtime decode\n"
" -d <dir> Image destination directory.\n"
" -o <name> Output filename\n"
" -s [15-19] Satellite number\n"
" -m <file> Map file\n"
" -r Realtime decode\n"
"\nRefer to the README for more infomation\n");

exit(EINVAL);


+ 5
- 1
pngio.c View File

@@ -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);


Loading…
Cancel
Save