summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-02-10 06:21:41 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-02-10 06:21:41 +0000
commite7f3f6946141387df1fbd8dba127bcb463d66a1a (patch)
tree3568c0b3090880092c384861291d9f7163069d33
parent32d078ac0ad0e61634090b974059afa9a92149e4 (diff)
parentf2af1112fa72329e4ffc616f6184a084868b037e (diff)
Merge "Fix bug where JPEG file with XMP is incorrectly saved"
-rw-r--r--media/java/android/media/ExifInterface.java20
1 files changed, 19 insertions, 1 deletions
diff --git a/media/java/android/media/ExifInterface.java b/media/java/android/media/ExifInterface.java
index 767b67b7e885..d2379757f226 100644
--- a/media/java/android/media/ExifInterface.java
+++ b/media/java/android/media/ExifInterface.java
@@ -1457,6 +1457,9 @@ public class ExifInterface {
private int mRw2JpgFromRawOffset;
private boolean mIsSupportedFile;
private boolean mModified;
+ // XMP data can be contained as either part of the EXIF data (tag number 700), or as a
+ // separate data marker (a separate MARKER_APP1).
+ private boolean mXmpIsFromSeparateMarker;
// Pattern to check non zero timestamp
private static final Pattern sNonZeroTimePattern = Pattern.compile(".*[1-9].*");
@@ -2837,10 +2840,12 @@ public class ExifInterface {
final long offset = start + IDENTIFIER_XMP_APP1.length;
final byte[] value = Arrays.copyOfRange(bytes,
IDENTIFIER_XMP_APP1.length, bytes.length);
-
+ // TODO: check if ignoring separate XMP data when tag 700 already exists is
+ // valid.
if (getAttribute(TAG_XMP) == null) {
mAttributes[IFD_TYPE_PRIMARY].put(TAG_XMP, new ExifAttribute(
IFD_FORMAT_BYTE, value.length, offset, value));
+ mXmpIsFromSeparateMarker = true;
}
}
break;
@@ -3445,11 +3450,24 @@ public class ExifInterface {
}
dataOutputStream.writeByte(MARKER_SOI);
+ // Remove XMP data if it is from a separate marker (IDENTIFIER_XMP_APP1, not
+ // IDENTIFIER_EXIF_APP1)
+ // Will re-add it later after the rest of the file is written
+ ExifAttribute xmpAttribute = null;
+ if (getAttribute(TAG_XMP) != null && mXmpIsFromSeparateMarker) {
+ xmpAttribute = (ExifAttribute) mAttributes[IFD_TYPE_PRIMARY].remove(TAG_XMP);
+ }
+
// Write EXIF APP1 segment
dataOutputStream.writeByte(MARKER);
dataOutputStream.writeByte(MARKER_APP1);
writeExifSegment(dataOutputStream);
+ // Re-add previously removed XMP data.
+ if (xmpAttribute != null) {
+ mAttributes[IFD_TYPE_PRIMARY].put(TAG_XMP, xmpAttribute);
+ }
+
byte[] bytes = new byte[4096];
while (true) {