Skip to content

Commit c81f970

Browse files
committed
gpujpeg_writer_write_exif: only generic metadata
Removed Exif custom metadata stuff altogether. On one hand this removes functionality but Exif contains mostly useless crap and this allows to keep it not so much complicated As for the issue GH-100, instead of `-O enc_exif_tag=Orientation=4` (for cmdline), one needs `-O enc_metadata=orientation=180- -O enc_hdr=Exif` (Exif header now not implied).
1 parent bc41d4a commit c81f970

File tree

6 files changed

+85
-272
lines changed

6 files changed

+85
-272
lines changed

libgpujpeg/gpujpeg_encoder.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,8 @@ gpujpeg_encoder_suggest_restart_interval(const struct gpujpeg_image_parameters*
225225

226226
/// input image is vertically flipped (bottom-up): values @ref GPUJPEG_VAL_TRUE or @ref GPUJPEG_VAL_FALSE
227227
#define GPUJPEG_ENC_OPT_FLIPPED_BOOL "enc_opt_flipped"
228-
229-
/// custom exif tag in format <key>:TYPE=<value>
230-
#define GPUJPEG_ENC_OPT_EXIF_TAG "enc_exif_tag"
228+
/// set image orientation - syntax "<name>=<deg>[-]" or "help"; only if header supports (Exif, SPIFF)
229+
#define GPUJPEG_ENC_OPT_METADATA "enc_metadata"
231230

232231
/**
233232
* remap channel order

src/gpujpeg_encoder.c

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
701736
GPUJPEG_API int
702737
gpujpeg_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

Comments
 (0)