@@ -283,16 +283,21 @@ struct coder_opts
283283 char * val ;
284284};
285285static bool
286- assign_decoder_opt (struct coder_opts * opts , char * optarg )
286+ assign_coder_opt (struct coder_opts * encoder_opts , struct coder_opts * decoder_opts , char * optarg )
287287{
288- char * opt = optarg ;
289- char * delim = strchr (optarg , '=' );
288+ char * opt = optarg ;
289+ char * delim = strchr (optarg , '=' );
290290 if ( delim == NULL ) {
291291 fprintf (stderr , "No value for %s!\n" , optarg );
292292 return false;
293293 }
294+ if ( strncmp (optarg , "enc_" , 4 ) != 0 && strncmp (optarg , "dec_" , 4 ) != 0 ) {
295+ fprintf (stderr , "Option should start with either enc_ or dec_, given %s!\n" , optarg );
296+ return false;
297+ }
294298 * delim = '\0' ;
295299 char * val = delim + 1 ;
300+ struct coder_opts * opts = strncmp (optarg , "enc_" , 4 ) == 0 ? encoder_opts : decoder_opts ;
296301 for ( int i = 0 ; i < CODER_OPTS_COUNT ; ++ i ) {
297302 if ( opts [i ].opt == NULL ) {
298303 opts [i ].opt = opt ;
@@ -304,6 +309,18 @@ assign_decoder_opt(struct coder_opts* opts, char *optarg)
304309 return false;
305310}
306311static bool
312+ set_encoder_opts (struct gpujpeg_encoder * encoder , const struct coder_opts * opts )
313+ {
314+ while ( (* opts ).opt != NULL ) {
315+ if ( gpujpeg_encoder_set_option (encoder , (* opts ).opt , (* opts ).val ) != 0 ) {
316+ return false;
317+ }
318+ opts ++ ;
319+ }
320+
321+ return true;
322+ }
323+ static bool
307324set_decoder_opts (struct gpujpeg_decoder * decoder , const struct coder_opts * opts )
308325{
309326 while ( (* opts ).opt != NULL ) {
@@ -350,6 +367,7 @@ main(int argc, char *argv[])
350367 _Bool use_opengl = 0 ;
351368 bool debug = false;
352369 struct coder_opts decoder_options [CODER_OPTS_COUNT + 1 ] = {0 };
370+ struct coder_opts encoder_options [CODER_OPTS_COUNT + 1 ] = {0 };
353371
354372 // Flags
355373 struct options opts = {.subsampling = GPUJPEG_SUBSAMPLING_UNKNOWN ,
@@ -508,7 +526,7 @@ main(int argc, char *argv[])
508526 debug = true;
509527 break ;
510528 case 'O' :
511- if ( !assign_decoder_opt ( decoder_options , optarg ) ) {
529+ if ( !assign_coder_opt ( encoder_options , decoder_options , optarg ) ) {
512530 return 1 ;
513531 }
514532 break ;
@@ -608,7 +626,7 @@ main(int argc, char *argv[])
608626
609627 // Create encoder
610628 struct gpujpeg_encoder * encoder = gpujpeg_encoder_create (NULL );
611- if ( encoder == NULL ) {
629+ if ( encoder == NULL || ! set_encoder_opts ( encoder , encoder_options ) ) {
612630 fprintf (stderr , "Failed to create encoder!\n" );
613631 return -1 ;
614632 }
0 commit comments