Skip to content

Commit 5772f73

Browse files
committed
Exif: allow setting ASCII/UNDEFINED
1 parent c2ad456 commit 5772f73

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

src/gpujpeg_exif.c

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,8 @@ usage()
437437
"\t" GPUJPEG_ENC_OPT_EXIF_TAG "=<name>=<value>\n"
438438
"\t\tname must be a tag name known to GPUJPEG\n");
439439
printf("\n");
440-
printf("If multple values required, separate with a comma; rationals are in format num/den.\n");
440+
printf("If mulitple numeric values required, separate with a comma; rationals are in format num/den.\n");
441+
printf("UNDEFINED and ASCII should be raw strings.\n");
441442
printf("\n");
442443
printf("recognized tag name (type, count):\n");
443444
for ( unsigned i = 0; i < ARR_SIZE(exif_tiff_tag_info); ++i ) {
@@ -483,35 +484,42 @@ gpujpeg_exif_add_tag(struct gpujpeg_exif_tags** exif_tags, const char* cfg)
483484
endptr += 1;
484485
void* val_alloc = NULL;
485486
size_t val_count = 0;
486-
do {
487-
if ( *endptr == ',' ) {
488-
endptr += 1;
489-
}
490-
if ( (exif_tag_type_info[type].type_flags & T_NUMERIC) != 0U ) {
491-
unsigned long long val = strtoull(endptr, &endptr, 0);
492-
val_count += 1;
493-
uint32_t* val_a = realloc(val_alloc, val_count * sizeof *val_a);
494-
val_a[val_count - 1] = val;
495-
val_alloc = val_a;
487+
if ( (exif_tag_type_info[type].type_flags & T_BYTE_ARRAY) != 0 ) {
488+
char* val_str = strdup(endptr);
489+
val_alloc = val_str;
490+
val_count = strlen(val_str);
491+
endptr += val_count;
492+
if (type == ET_ASCII) {
493+
val_count += 1; // include '\0'
496494
}
497-
else if ( (exif_tag_type_info[type].type_flags & T_RATIONAL) != 0U ) {
498-
unsigned long long num = strtoull(endptr, &endptr, 0);
499-
if ( *endptr != '/' ) {
500-
ERROR_MSG("[Exif] Malformed rational, expected '/', got '%c'!\n", *endptr);
495+
}
496+
else {
497+
do {
498+
if ( *endptr == ',' ) {
499+
endptr += 1;
501500
}
502-
endptr += 1;
503-
unsigned long long den = strtoull(endptr, &endptr, 0);
504-
val_count += 1;
505-
uint32_t* val_a = realloc(val_alloc, val_count * 2 * sizeof *val_a);
506-
val_a[2 * (val_count - 1)] = num;
507-
val_a[(2 * (val_count - 1)) + 1] = den;
508-
val_alloc = val_a;
509-
}
510-
else {
511-
ERROR_MSG("Only integer or rational values are currently supported!\n");
512-
return false;
513-
}
514-
} while ( *endptr == ',' );
501+
if ( (exif_tag_type_info[type].type_flags & T_NUMERIC) != 0U ) {
502+
unsigned long long val = strtoull(endptr, &endptr, 0);
503+
val_count += 1;
504+
uint32_t* val_a = realloc(val_alloc, val_count * sizeof *val_a);
505+
val_a[val_count - 1] = val;
506+
val_alloc = val_a;
507+
}
508+
else if ( (exif_tag_type_info[type].type_flags & T_RATIONAL) != 0U ) {
509+
unsigned long long num = strtoull(endptr, &endptr, 0);
510+
if ( *endptr != '/' ) {
511+
ERROR_MSG("[Exif] Malformed rational, expected '/', got '%c'!\n", *endptr);
512+
}
513+
endptr += 1;
514+
unsigned long long den = strtoull(endptr, &endptr, 0);
515+
val_count += 1;
516+
uint32_t* val_a = realloc(val_alloc, val_count * 2 * sizeof *val_a);
517+
val_a[2 * (val_count - 1)] = num;
518+
val_a[(2 * (val_count - 1)) + 1] = den;
519+
val_alloc = val_a;
520+
}
521+
} while ( *endptr == ',' );
522+
}
515523

516524
if ( *endptr != '\0' ) {
517525
free(val_alloc);

0 commit comments

Comments
 (0)