Skip to content

Commit

Permalink
ExifInterface: Write new XMP data out to a separate segment
Browse files Browse the repository at this point in the history
The XMP spec part 3 section 3.3.2 makes it clear that JPEG files should
store XMP data in separate APP1 segment, not the Exif segment under tag
700. ExifInterface is documented to (incorrectly) prefer XMP data stored
in the Exif segment if both are present. But the behaviour of where XMP
data is added in the file if it wasn't previously present isn't
explicitly documented. This change ensures that XMP data added to a file
that didn't previously have any is added in a standalone segment.

This change also adds some additional documentation to describe this
behaviour.

Test: ExifInterfaceTest
Change-Id: I84328802a3b43b4766850fcdc6731c1e7c59e909
  • Loading branch information
icbaker authored and Tommy-Geenexus committed Aug 15, 2024
1 parent 7d0fd9e commit 0855f1a
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5565,7 +5565,13 @@ private void getJpegAttributes(final ByteOrderedDataInputStream source,
+ IDENTIFIER_EXIF_APP1.length;
readExifSegment(value, imageType);
setThumbnailData(new ByteOrderedDataInputStream(value));
if (xmpBeforeReadingExif != getAttributeBytes(TAG_XMP)) {
if (getAttributeBytes(TAG_XMP) == null) {
// XMP should be stored in a separate APP1 segment (see XMP spec part 3
// section 3.3.2). If the Exif segment didn't contain XMP then we set
// this to true to ensure any XMP data added will get written out to a
// separate segment.
mXmpIsFromSeparateMarker = true;
} else if (xmpBeforeReadingExif != getAttributeBytes(TAG_XMP)) {
mXmpIsFromSeparateMarker = false;
}
} else if (ExifInterfaceExtendedUtils.startsWith(bytes, IDENTIFIER_XMP_APP1)) {
Expand Down

0 comments on commit 0855f1a

Please sign in to comment.