@@ -698,6 +698,41 @@ gpujpeg_opt_set_channel_remap(struct gpujpeg_coder* coder, const char* val, cons
698698 return GPUJPEG_NOERR ;
699699}
700700
701+ static int
702+ add_metadata (struct gpujpeg_image_metadata * metadata , const char * config )
703+ {
704+ if ( strstr (config , "help" ) != NULL ) {
705+ printf (GPUJPEG_ENC_OPT_METADATA " usage:\n" );
706+ printf ("\t" GPUJPEG_ENC_OPT_METADATA "=orientation=<deg>[-]\n" );
707+ printf ("\t\t<deg> - clockwise rotation - 0, 90, 180 or 270 degrees\n" );
708+ printf ("\t\t'-' - mirror the image horizontally after rotation applied\n" );
709+ return GPUJPEG_ERROR ;
710+ }
711+ if ( strstr (config , "orientation=" ) != config ) {
712+ printf ("Wrong metadata item: %s\n" , config );
713+ return GPUJPEG_ERROR ;
714+ }
715+
716+ const char * val = strchr (config , '=' ) + 1 ;
717+ char * endptr = NULL ;
718+ int deg = (int ) strtol (val , & endptr , 10 );
719+ bool flip = false;
720+ if ( * endptr == '-' ) {
721+ flip = true;
722+ endptr += 1 ;
723+ }
724+ if ( * endptr != '\0' || deg < 0 || deg > 270 || deg % 90 != 0 ) {
725+ printf ("Wrong orientation value: %s\n" , config );
726+ return GPUJPEG_ERROR ;
727+ }
728+
729+ metadata -> vals [GPUJPEG_METADATA_ORIENTATION ].set = 1 ;
730+ metadata -> vals [GPUJPEG_METADATA_ORIENTATION ].orient .rotation = deg / 90 ;
731+ metadata -> vals [GPUJPEG_METADATA_ORIENTATION ].orient .flip = flip ;
732+
733+ return GPUJPEG_NOERR ;
734+ }
735+
701736GPUJPEG_API int
702737gpujpeg_encoder_set_option (struct gpujpeg_encoder * encoder , const char * opt , const char * val )
703738{
@@ -735,10 +770,8 @@ gpujpeg_encoder_set_option(struct gpujpeg_encoder* encoder, const char *opt, con
735770 if ( strcmp (opt , GPUJPEG_ENC_OPT_CHANNEL_REMAP ) == 0 ) {
736771 return gpujpeg_opt_set_channel_remap (& encoder -> coder , val , GPUJPEG_ENC_OPT_CHANNEL_REMAP );
737772 }
738- if ( strcmp (opt , GPUJPEG_ENC_OPT_EXIF_TAG ) == 0 ) {
739- encoder -> header_type = GPUJPEG_HEADER_EXIF ;
740- return gpujpeg_exif_add_tag (& encoder -> writer -> exif_tags , val ) ? GPUJPEG_NOERR : GPUJPEG_ERROR ;
741-
773+ if ( strcmp (opt , GPUJPEG_ENC_OPT_METADATA ) == 0 ) {
774+ return add_metadata (& encoder -> writer -> metadata , val );
742775 }
743776 ERROR_MSG ("Invalid encoder option: %s!\n" , opt );
744777 return GPUJPEG_ERROR ;
@@ -753,7 +786,7 @@ gpujpeg_encoder_print_options() {
753786 "] - whether is the input image should be vertically flipped (prior encode)\n" );
754787 printf ("\t" GPUJPEG_ENC_OPT_CHANNEL_REMAP "=XYZ[W] - input channel mapping, eg. '210F' for GBRX,\n"
755788 "\t\t'210' for GBR; special placeholders 'F' and 'Z' to set a channel to all-ones or all-zeros\n" );
756- printf ("\t" GPUJPEG_ENC_OPT_EXIF_TAG "=<key>=<value>|help - custom EXIF tag (use help for syntax) \n" );
789+ printf ("\t" GPUJPEG_ENC_OPT_METADATA "=<key>=<value>|help - set image metadata \n" );
757790}
758791
759792/* Documented at declaration */
0 commit comments