@@ -85,7 +85,8 @@ print_help(bool full)
8585 " -V --version print GPUJPEG version\n"
8686 );
8787 if ( full ) {
88- printf (" -b, --debug debug helpers (reset GPU for leakcheck, dump infile if not regular)\n" );
88+ printf (" -b, --debug debug helpers (reset GPU for leakcheck, dump infile if not regular)\n"
89+ " -O dec_tga_rle=[0|1] set decoder option\n" );
8990 }
9091 else {
9192 printf (" -H, --fullhelp print all options\n" );
@@ -275,6 +276,46 @@ debug_dump_infile(const char* filename, const uint8_t* image_data, size_t image_
275276 }
276277}
277278
279+ enum { CODER_OPTS_COUNT = 10 };
280+ struct coder_opts
281+ {
282+ char * opt ;
283+ char * val ;
284+ };
285+ static bool
286+ assign_decoder_opt (struct coder_opts * opts , char * optarg )
287+ {
288+ char * opt = optarg ;
289+ char * delim = strchr (optarg , '=' );
290+ if ( delim == NULL ) {
291+ fprintf (stderr , "No value for %s!\n" , optarg );
292+ return false;
293+ }
294+ * delim = '\0' ;
295+ char * val = delim + 1 ;
296+ for ( int i = 0 ; i < CODER_OPTS_COUNT ; ++ i ) {
297+ if ( opts [i ].opt == NULL ) {
298+ opts [i ].opt = opt ;
299+ opts [i ].val = val ;
300+ return true;
301+ }
302+ }
303+ fprintf (stderr , "Too much optiosn!\n" );
304+ return false;
305+ }
306+ static bool
307+ set_decoder_opts (struct gpujpeg_decoder * decoder , const struct coder_opts * opts )
308+ {
309+ while ( (* opts ).opt != NULL ) {
310+ if ( gpujpeg_decoder_set_option (decoder , (* opts ).opt , (* opts ).val ) != 0 ) {
311+ return false;
312+ }
313+ opts ++ ;
314+ }
315+
316+ return true;
317+ }
318+
278319#ifndef GIT_REV
279320#define GIT_REV "unknown"
280321#endif
@@ -308,6 +349,7 @@ main(int argc, char *argv[])
308349 int iterate = 1 ;
309350 _Bool use_opengl = 0 ;
310351 bool debug = false;
352+ struct coder_opts decoder_options [CODER_OPTS_COUNT + 1 ] = {0 };
311353
312354 // Flags
313355 struct options opts = {.subsampling = GPUJPEG_SUBSAMPLING_UNKNOWN ,
@@ -351,7 +393,7 @@ main(int argc, char *argv[])
351393 int ch = '\0' ;
352394 int optindex = 0 ;
353395 char * pos = 0 ;
354- while ( (ch = getopt_long (argc , argv , "CD:HI:LNRS ::Vabc:edf:ghin:oq:r:s:v" , longopts , & optindex )) != -1 ) {
396+ while ( (ch = getopt_long (argc , argv , "CD:HI:LNO:RS ::Vabc:edf:ghin:oq:r:s:v" , longopts , & optindex )) != -1 ) {
355397 switch (ch ) {
356398 case 'a' :
357399 opts .keep_alpha = true;
@@ -465,6 +507,11 @@ main(int argc, char *argv[])
465507 case 'b' :
466508 debug = true;
467509 break ;
510+ case 'O' :
511+ if ( !assign_decoder_opt (decoder_options , optarg ) ) {
512+ return 1 ;
513+ }
514+ break ;
468515 case '?' :
469516 return -1 ;
470517 default :
@@ -684,7 +731,7 @@ main(int argc, char *argv[])
684731
685732 // Create decoder
686733 struct gpujpeg_decoder * decoder = gpujpeg_decoder_create (NULL );
687- if ( decoder == NULL ) {
734+ if ( decoder == NULL || ! set_decoder_opts ( decoder , decoder_options ) ) {
688735 fprintf (stderr , "Failed to create decoder!\n" );
689736 return -1 ;
690737 }
0 commit comments