From 4d9236336cdd59b4dc7d933e50ef51a62eff3b72 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Sat, 4 Dec 2021 06:31:24 +0100 Subject: jpeginfo: parse TIFF UNDEFINED values --- tools/jpeginfo.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/jpeginfo.c b/tools/jpeginfo.c index ea2218f..e4e9a67 100644 --- a/tools/jpeginfo.c +++ b/tools/jpeginfo.c @@ -601,6 +601,20 @@ parse_exif_ascii(struct tiffer_entry *entry) return a; } +static jv +parse_exif_undefined(struct tiffer_entry *entry) +{ + const char *alphabet = "0123456789abcdef"; + char *buf = calloc(1, 2 * entry->remaining_count + 1); + for (uint32_t i = 0; i < entry->remaining_count; i++) { + buf[2 * i + 0] = alphabet[entry->p[i] >> 4]; + buf[2 * i + 1] = alphabet[entry->p[i] & 0xF]; + } + jv s = jv_string(buf); + free(buf); + return s; +} + static jv parse_exif_entry(jv o, struct tiffer *T, struct tiffer_entry *entry) { @@ -613,11 +627,13 @@ parse_exif_entry(jv o, struct tiffer *T, struct tiffer_entry *entry) value = parse_exif_subifds(T, entry); } else if (entry->type == ASCII) { value = parse_exif_ascii(entry); + } else if (entry->type == UNDEFINED) { + value = parse_exif_undefined(entry); } else if ((numeric = tiffer_real(T, entry, &real))) { value = jv_number(real); } - // TODO(p): Decode UNDEFINED as a hex dump, and iterate over all values. + // TODO(p): Iterate over all numeric values. for (const struct tiff_entry *p = tiff_entries; p->name; p++) { if (p->tag != entry->tag) continue; -- cgit v1.2.3-70-g09d2