From 34388b93ea92a979d0575ecc1aee48b854ffcc9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Thu, 8 Jun 2023 18:58:21 +0200 Subject: info: decode JPEGs from all CR2 IFDs --- tools/info.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/info.h b/tools/info.h index d640f35..7476f9a 100644 --- a/tools/info.h +++ b/tools/info.h @@ -247,19 +247,23 @@ parse_exif_ifd(struct tiffer *T, const struct tiff_entry *info) } // This is how Exif specifies it, which doesn't follow TIFF 6.0. - if (info == tiff_entries && compression == TIFF_Compression_JPEG && + // Also support CR2 IFD1, which isn't tagged with compression at all. + if (info == tiff_entries && /* compression == TIFF_Compression_JPEG && */ jpeg > 0 && jpeg_length > 0 && - jpeg + jpeg_length < (T->end - T->begin)) { + jpeg + jpeg_length <= (T->end - T->begin)) { ifd = jv_set(ifd, jv_string("JPEG image data"), parse_jpeg( jv_object(), T->begin + jpeg, jpeg_length)); } + // As specified by DRAFT TIFF Technical Note 2 + TIFFphotoshop.pdf. // Theoretically, there may be more strips, but this is not expected. + // Also support CR2 IFD0, which is tagged with the "wrong" compression. if (info == tiff_entries && - compression == TIFF_Compression_JPEGDatastream && + (compression == TIFF_Compression_JPEGDatastream || + compression == TIFF_Compression_JPEG) && strip_offsets > 0 && strip_byte_counts > 0 && - strip_offsets + strip_byte_counts < (T->end - T->begin)) { + strip_offsets + strip_byte_counts <= (T->end - T->begin)) { ifd = jv_set(ifd, jv_string("JPEG image data"), parse_jpeg( jv_object(), T->begin + strip_offsets, strip_byte_counts)); -- cgit v1.2.3