浏览代码

Add -o flag

Allows custom filenames for the output image
Fix formatting in help text
tags/v1.8.0
Xerbo 4 年前
父节点
当前提交
6a05b7a9c1
共有 4 个文件被更改,包括 26 次插入13 次删除
  1. +3
    -0
      README.md
  2. +1
    -0
      common.h
  3. +17
    -12
      main.c
  4. +5
    -1
      pngio.c

+ 3
- 0
README.md 查看文件

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


-o <filename>
Output image filename

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


+ 1
- 0
common.h 查看文件

@@ -42,4 +42,5 @@ typedef struct {
char *map; // Path to a map file char *map; // Path to a map file
char *path; // Output directory char *path; // Output directory
int realtime; // Realtime decoding int realtime; // Realtime decoding
char *filename; // Output filename
} options_t; } options_t;

+ 17
- 12
main.c 查看文件

@@ -61,7 +61,7 @@ static SNDFILE *audioFile;
// Number of channels in audio file // Number of channels in audio file
int channels = 1; int channels = 1;


// Function predeclarations
// Function declarations
static int initsnd(char *filename); static int initsnd(char *filename);
int getsample(float *sample, int nb); int getsample(float *sample, int nb);
static int processAudio(char *filename, options_t *opts); static int processAudio(char *filename, options_t *opts);
@@ -76,11 +76,11 @@ int main(int argc, char **argv) {
usage(); usage();
} }


options_t opts = { "r", "", 19, "", ".", 0 };
options_t opts = { "r", "", 19, "", ".", 0, "" };


// Parse arguments // Parse arguments
int opt; 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) { switch (opt) {
case 'd': case 'd':
opts.path = optarg; opts.path = optarg;
@@ -104,6 +104,9 @@ int main(int argc, char **argv) {
case 'r': case 'r':
opts.realtime = 1; opts.realtime = 1;
break; break;
case 'o':
opts.filename = optarg;
break;
default: default:
usage(); usage();
} }
@@ -139,14 +142,15 @@ static int processAudio(char *filename, options_t *opts){
strcpy(path, dirname(path)); strcpy(path, dirname(path));
sscanf(basename(filename), "%[^.].%s", img.name, extension); sscanf(basename(filename), "%[^.].%s", img.name, extension);


// Set output filename to current time when in realtime mode
if(opts->realtime){ if(opts->realtime){
// Set output filename to current time when in realtime mode
time_t t; time_t t;
time(&t); time(&t);
strncpy(img.name, ctime(&t), 24); 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){ if(strcmp(extension, "png") == 0){
// Read PNG into image buffer // Read PNG into image buffer
@@ -185,7 +189,7 @@ static int processAudio(char *filename, options_t *opts){
printf("Total rows: %d\n", img.nrow); printf("Total rows: %d\n", img.nrow);


// Fallback for detecting the zenith // 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){ if(opts->map != NULL && opts->map[0] != '\0' && zenith == 0){
fprintf(stderr, "Guessing zenith in image, map will most likely be misaligned.\n"); fprintf(stderr, "Guessing zenith in image, map will most likely be misaligned.\n");
zenith = img.nrow / 2; 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); ImageOut(opts, &img, CHB_OFFSET, CH_WIDTH, desc, ch.id[img.chB], NULL);
} }


// Distribution image
// Value distribution image
if (CONTAINS(opts->type, 'd')) if (CONTAINS(opts->type, 'd'))
distrib(opts, &img, "d"); distrib(opts, &img, "d");


@@ -326,10 +330,11 @@ static void usage(void) {
" c: False color\n" " c: False color\n"
" t: Temperature\n" " t: Temperature\n"
" m: MCIR\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"); "\nRefer to the README for more infomation\n");


exit(EINVAL); exit(EINVAL);


+ 5
- 1
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){ int ImageOut(options_t *opts, image_t *img, int offset, int width, char *desc, char *chid, char *palette){
char outName[384]; 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 = desc;
meta[1].text_length = sizeof(desc); meta[1].text_length = sizeof(desc);


正在加载...
取消
保存