Skip to content

Commit 6c1d330

Browse files
committed
gpujpegtool: inline help for opts
1 parent 0ae7dd8 commit 6c1d330

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

libgpujpeg/gpujpeg_decoder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ gpujpeg_decoder_get_image_info(uint8_t *image, size_t image_size, struct gpujpeg
277277
*/
278278
GPUJPEG_API int
279279
gpujpeg_decoder_set_option(struct gpujpeg_decoder* decoder, const char *opt, const char* val);
280-
280+
GPUJPEG_API void
281+
gpujpeg_decoder_print_options();
281282

282283
#ifdef __cplusplus
283284
}

libgpujpeg/gpujpeg_encoder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ gpujpeg_encoder_suggest_restart_interval(const struct gpujpeg_image_parameters*
254254
*/
255255
GPUJPEG_API int
256256
gpujpeg_encoder_set_option(struct gpujpeg_encoder* encoder, const char* opt, const char* val);
257+
GPUJPEG_API void
258+
gpujpeg_encoder_print_options();
257259

258260
/**
259261
* Destory JPEG encoder

src/gpujpeg_decoder.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,13 @@ gpujpeg_decoder_set_option(struct gpujpeg_decoder* decoder, const char *opt, con
497497
return GPUJPEG_ERROR;
498498
}
499499

500+
GPUJPEG_API void
501+
gpujpeg_decoder_print_options()
502+
{
503+
printf("\t" GPUJPEG_DEC_OPT_TGA_RLE_BOOL "=[" GPUJPEG_VAL_FALSE "|" GPUJPEG_VAL_TRUE
504+
"] - set decoder option (not) to output RLE TGA\n");
505+
}
506+
500507
/* Documented at declaration */
501508
int
502509
gpujpeg_decoder_destroy(struct gpujpeg_decoder* decoder)

src/gpujpeg_encoder.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,17 @@ gpujpeg_encoder_set_option(struct gpujpeg_encoder* encoder, const char *opt, con
746746
ERROR_MSG("Invalid encoder option: %s!\n", opt);
747747
return GPUJPEG_ERROR;
748748
}
749+
GPUJPEG_API void
750+
gpujpeg_encoder_print_options() {
751+
printf("\t" GPUJPEG_ENC_OPT_OUT "=[" GPUJPEG_ENC_OUT_VAL_PAGEABLE "|" GPUJPEG_ENC_OUT_VAL_PINNED
752+
"] - compressed data buffer allocation property\n");
753+
printf("\t" GPUJPEG_ENC_OPT_HDR "=[" GPUJPEG_ENC_HDR_VAL_JFIF "|" GPUJPEG_ENC_HDR_VAL_ADOBE "|" GPUJPEG_ENC_HDR_VAL_SPIFF
754+
"] - output JPEG header\n");
755+
printf("\t" GPUJPEG_ENC_OPT_FLIPPED_BOOL "=[" GPUJPEG_VAL_FALSE "|" GPUJPEG_VAL_TRUE
756+
"] - whether is the input image should be vertically flipped (prior encode)\n");
757+
printf("\t" GPUJPEG_ENC_OPT_CHANNEL_REMAP "=XYZ[W] - input channel mapping, eg. '210F' for GBRX,\n"
758+
"\t\t'210' for GBR; special placeholders 'F' and 'Z' to set a channel to all-ones or all-zeros\n");
759+
}
749760

750761
/* Documented at declaration */
751762
int

src/main.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,11 @@ static void
107107
print_help(bool full)
108108
{
109109
printf("gpujpegtool [options] input.rgb output.jpg [input2.rgb output2.jpg ...]\n"
110-
" -h, --help print help\n"
111-
" -v, --verbose verbose output (multiply to increase verbosity - max 3) \n"
110+
" -h, --help print help\n");
111+
if (!full) {
112+
printf(" -H, --fullhelp print all options\n");
113+
}
114+
printf(" -v, --verbose verbose output (multiply to increase verbosity - max 3) \n"
112115
" -D, --device set cuda device id (default 0)\n"
113116
" -L, --device-list list cuda devices\n"
114117
"\n");
@@ -145,11 +148,7 @@ print_help(bool full)
145148
);
146149
if ( full ) {
147150
printf(" -b, --debug debug helpers (reset GPU for leakcheck, dump infile if not regular)\n"
148-
" -O " GPUJPEG_DEC_OPT_TGA_RLE_BOOL "=[" GPUJPEG_VAL_FALSE "|" GPUJPEG_VAL_TRUE
149-
"] set decoder option (not) to output RLE TGA; other options exist\n");
150-
}
151-
else {
152-
printf(" -H, --fullhelp print all options\n");
151+
" -O <key>=<value>|help set encoder/decoder option, 'help' for list\n");
153152
}
154153
printf("recognized raw input/output file extensions: rgb, yuv, pnm... (use`gpujpegtool exts` for the full list)\n");
155154
}
@@ -351,18 +350,26 @@ struct coder_opts
351350
char* opt;
352351
char* val;
353352
};
354-
static bool
353+
static int
355354
assign_coder_opt(struct coder_opts* encoder_opts, struct coder_opts* decoder_opts, char* optval)
356355
{
356+
if (strcmp(optval, "help") == 0) {
357+
printf("Available options:\n");
358+
printf("decoder:\n");
359+
gpujpeg_decoder_print_options();
360+
printf("\nencoder:\n");
361+
gpujpeg_encoder_print_options();
362+
return 1;
363+
}
357364
char* opt = optval;
358365
char* delim = strchr(optval, '=');
359366
if ( delim == NULL ) {
360367
fprintf(stderr, "No value for %s!\n", optval);
361-
return false;
368+
return -1;
362369
}
363370
if ( strncmp(optval, "enc_", 4) != 0 && strncmp(optval, "dec_", 4) != 0 ) {
364371
fprintf(stderr, "Option should start with either enc_ or dec_, given %s!\n", optval);
365-
return false;
372+
return -1;
366373
}
367374
*delim = '\0';
368375
char *val = delim + 1;
@@ -371,11 +378,11 @@ assign_coder_opt(struct coder_opts* encoder_opts, struct coder_opts* decoder_opt
371378
if ( opts[i].opt == NULL ) {
372379
opts[i].opt = opt;
373380
opts[i].val = val;
374-
return true;
381+
return 0;
375382
}
376383
}
377384
fprintf(stderr, "Too much options!\n");
378-
return false;
385+
return -1;
379386
}
380387
static bool
381388
set_encoder_opts(struct gpujpeg_encoder* encoder, const struct coder_opts* opts)
@@ -612,8 +619,9 @@ main(int argc, char *argv[])
612619
debug = true;
613620
break;
614621
case 'O':
615-
if ( !assign_coder_opt(encoder_options, decoder_options, tstr_to_mbs(optarg)) ) {
616-
return 1;
622+
rc = assign_coder_opt(encoder_options, decoder_options, tstr_to_mbs(optarg));
623+
if (rc != 0) {
624+
return rc < 0 ? 1 : 0;
617625
}
618626
break;
619627
case '?':

0 commit comments

Comments
 (0)