OSDN Git Service

ExifInterface: fix creating pointer tags which indicate 0 offset
authorJaesung Chung <jaesung@google.com>
Wed, 23 Mar 2016 16:41:46 +0000 (09:41 -0700)
committerJaesung Chung <jaesung@google.com>
Wed, 23 Mar 2016 17:22:48 +0000 (10:22 -0700)
When saving attributes(that it writes JPEG again.), now ExifInterface
generates some uncessary pointer tags which refer to an empty EXIF IFD
group, that makes a warning message by ExifInterface when reading again,
which warns that the value of the pointer tag pointing to is invalid.

Bug: 27583378
Change-Id: Id0170c5644541565c98fe4978284098e6664c395

media/java/android/media/ExifInterface.java

index dbedf34..ff07570 100644 (file)
@@ -1874,6 +1874,19 @@ public class ExifInterface {
         for (ExifTag tag : IFD_POINTER_TAGS) {
             setAttribute(tag.name, null);
         }
+        // Remove old thumbnail data
+        setAttribute(JPEG_INTERCHANGE_FORMAT_TAG.name, null);
+        setAttribute(JPEG_INTERCHANGE_FORMAT_LENGTH_TAG.name, null);
+
+        // Remove null value tags.
+        for (int hint = 0; hint < EXIF_TAGS.length; ++hint) {
+            for (Object obj : mAttributes[hint].entrySet().toArray()) {
+                Map.Entry entry = (Map.Entry) obj;
+                if (entry.getValue() == null) {
+                    mAttributes[hint].remove(entry.getKey());
+                }
+            }
+        }
 
         // Add IFD pointer tags. The next offset of primary image TIFF IFD will have thumbnail IFD
         // offset when there is one or more tags in the thumbnail IFD.
@@ -1886,25 +1899,12 @@ public class ExifInterface {
         if (!mAttributes[IFD_GPS_HINT].isEmpty()) {
             mAttributes[IFD_TIFF_HINT].put(IFD_POINTER_TAGS[1].name, "0");
         }
-        // Remove old thumbnail data
-        setAttribute(JPEG_INTERCHANGE_FORMAT_TAG.name, null);
-        setAttribute(JPEG_INTERCHANGE_FORMAT_LENGTH_TAG.name, null);
         if (mHasThumbnail) {
             mAttributes[IFD_TIFF_HINT].put(JPEG_INTERCHANGE_FORMAT_TAG.name, "0");
             mAttributes[IFD_TIFF_HINT].put(JPEG_INTERCHANGE_FORMAT_LENGTH_TAG.name,
                     String.valueOf(mThumbnailLength));
         }
 
-        // Remove null value tags.
-        for (int hint = 0; hint < EXIF_TAGS.length; ++hint) {
-            for (Object obj : mAttributes[hint].entrySet().toArray()) {
-                Map.Entry entry = (Map.Entry) obj;
-                if (entry.getValue() == null) {
-                    mAttributes[hint].remove(entry.getKey());
-                }
-            }
-        }
-
         // Calculate IFD group data area sizes. IFD group data area is assigned to save the entry
         // value which has a bigger size than 4 bytes.
         for (int i = 0; i < 5; ++i) {