Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 616a42f9 authored by Jaesung Chung's avatar Jaesung Chung
Browse files

ExifInterface: fix creating pointer tags which indicate 0 offset

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
parent 285bbbbd
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -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) {