Open glebignatieff opened 2 years ago
APP1 sections are not EXIF only, but also XMP. Currently, libjpeg leaves an empty EXIF section instead of copy-pasting XMP section.
libjpeg
Before copy:
JPEG APP1 (8188 bytes): + [XMP directory, 8159 bytes] | About = DJI Meta Data | ModifyDate = 2022-04-22 | CreateDate = 2022-04-22 ...
After copy:
JPEG APP1 (20 bytes): ExifByteOrder = MM + [IFD0 directory with 0 entries]
extern "C" { #include <libjpeg/jpeg-data.h> } auto main() -> int { auto jpeg_data = ::jpeg_data_new_from_file("source.JPG"); auto exif_data = ::jpeg_data_get_exif_data(jpeg_data); ::jpeg_data_set_exif_data(jpeg_data, exif_data); ::jpeg_data_save_file(jpeg_data, "dest.JPG"); return 0; }
jpeg_data_load_data()
NULL
default
generic
app1
jpeg_data_save_data()
Description
APP1 sections are not EXIF only, but also XMP. Currently,
libjpeg
leaves an empty EXIF section instead of copy-pasting XMP section.Before copy:
After copy:
MWE
Suggested solution
jpeg_data_load_data()
check if EXIF buffer isNULL
and if it is, then fall back todefault
, i.e.generic
instead ofapp1
. https://github.com/libexif/exif/blob/4cd915d1119d7dfd33ac7b9148c46afe6f92fbc2/libjpeg/jpeg-data.c#L241-L242jpeg_data_save_data()
check ifgeneric
buffer size is 0, if it is, then handle as EXIF, otherwise fallback todefault
.I can't upload a file with the patch for some reason, so here it is.
```diff diff --git a/libjpeg/jpeg-data.c b/libjpeg/jpeg-data.c index a64d362..a2528d4 100644 --- a/libjpeg/jpeg-data.c +++ b/libjpeg/jpeg-data.c @@ -25,6 +25,7 @@ #include