summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHung-ying Tyan <tyanh@google.com>2012-08-29 23:55:33 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-08-29 23:55:33 -0700
commitb282374131b3f9b306968440550fca0dbe756ee0 (patch)
treeba949e25f5851e4d485c5ed3b65a455ff75c5edc
parentc2ac168aaeb959f9f33db3b574a845a4d6686af3 (diff)
parent1d3dfbf55bb320dc4d1d4379c385b629c107f713 (diff)
downloadandroid_packages_apps_Snap-b282374131b3f9b306968440550fca0dbe756ee0.tar.gz
android_packages_apps_Snap-b282374131b3f9b306968440550fca0dbe756ee0.tar.bz2
android_packages_apps_Snap-b282374131b3f9b306968440550fca0dbe756ee0.zip
Merge "Add equals() function in ExifData, IfdData, and ExifTag" into gb-ub-photos-arches
-rw-r--r--src/com/android/gallery3d/exif/ExifData.java21
-rw-r--r--src/com/android/gallery3d/exif/ExifTag.java44
-rw-r--r--src/com/android/gallery3d/exif/IfdData.java29
-rw-r--r--src/com/android/gallery3d/exif/Rational.java9
-rw-r--r--src/com/android/gallery3d/exif/Util.java23
5 files changed, 122 insertions, 4 deletions
diff --git a/src/com/android/gallery3d/exif/ExifData.java b/src/com/android/gallery3d/exif/ExifData.java
index 14d482221..eca819ea0 100644
--- a/src/com/android/gallery3d/exif/ExifData.java
+++ b/src/com/android/gallery3d/exif/ExifData.java
@@ -18,6 +18,7 @@ package com.android.gallery3d.exif;
import java.nio.ByteOrder;
import java.util.ArrayList;
+import java.util.Arrays;
/**
* This class stores the EXIF header in IFDs according to the JPEG specification.
@@ -114,4 +115,24 @@ public class ExifData {
public ByteOrder getByteOrder() {
return mByteOrder;
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof ExifData) {
+ ExifData data = (ExifData) obj;
+ if (data.mByteOrder != mByteOrder
+ || !Arrays.equals(data.mThumbnail, mThumbnail)
+ || data.mStripBytes.size() != mStripBytes.size()) return false;
+
+ for (int i = 0; i < mStripBytes.size(); i++) {
+ if (!Arrays.equals(data.mStripBytes.get(i), mStripBytes.get(i))) return false;
+ }
+
+ for (int i = 0; i < IfdId.TYPE_IFD_COUNT; i++) {
+ if (!Util.equals(data.getIfdData(i), getIfdData(i))) return false;
+ }
+ return true;
+ }
+ return false;
+ }
} \ No newline at end of file
diff --git a/src/com/android/gallery3d/exif/ExifTag.java b/src/com/android/gallery3d/exif/ExifTag.java
index b2cbe61d7..fd5826ef5 100644
--- a/src/com/android/gallery3d/exif/ExifTag.java
+++ b/src/com/android/gallery3d/exif/ExifTag.java
@@ -17,6 +17,7 @@
package com.android.gallery3d.exif;
import java.lang.reflect.Array;
+import java.util.Arrays;
/**
* This class stores information of an EXIF tag.
@@ -568,7 +569,7 @@ public class ExifTag {
if (mValue instanceof long[]) {
return (short) (((long[]) mValue) [index]);
} else {
- throw new RuntimeException("There is numerical value in this tag");
+ throw new RuntimeException("There is no numerical value in this tag");
}
}
@@ -576,7 +577,7 @@ public class ExifTag {
if (mValue instanceof long[]) {
return (int) (((long[]) mValue) [index]);
} else {
- throw new RuntimeException("There is numerical value in this tag");
+ throw new RuntimeException("There is no numerical value in this tag");
}
}
@@ -584,7 +585,7 @@ public class ExifTag {
if (mValue instanceof long[]) {
return (int) (((long[]) mValue) [index]);
} else {
- throw new RuntimeException("There is numerical value in this tag");
+ throw new RuntimeException("There is no numerical value in this tag");
}
}
@@ -592,7 +593,7 @@ public class ExifTag {
if (mValue instanceof long[]) {
return ((long[]) mValue) [index];
} else {
- throw new RuntimeException("There is numerical value in this tag");
+ throw new RuntimeException("There is no numerical value in this tag");
}
}
@@ -671,4 +672,39 @@ public class ExifTag {
}
return sbuilder.toString();
}
+
+ /**
+ * Returns true if the ID is one of the following: {@link TIFF_TAG#TAG_EXIF_IFD},
+ * {@link TIFF_TAG#TAG_GPS_IFD}, {@link TIFF_TAG#TAG_JPEG_INTERCHANGE_FORMAT},
+ * {@link TIFF_TAG#TAG_STRIP_OFFSETS}, {@link EXIF_TAG#TAG_INTEROPERABILITY_IFD}
+ */
+ public static boolean isOffsetTag(short tagId) {
+ return tagId == ExifTag.TIFF_TAG.TAG_EXIF_IFD
+ || tagId == ExifTag.TIFF_TAG.TAG_GPS_IFD
+ || tagId == ExifTag.TIFF_TAG.TAG_JPEG_INTERCHANGE_FORMAT
+ || tagId == ExifTag.TIFF_TAG.TAG_STRIP_OFFSETS
+ || tagId == ExifTag.EXIF_TAG.TAG_INTEROPERABILITY_IFD;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof ExifTag) {
+ ExifTag tag = (ExifTag) obj;
+ boolean isArray = mValue != null && mValue.getClass().isArray();
+ if (mValue != null) {
+ if (mValue instanceof long[]) {
+ if (!(tag.mValue instanceof long[])) return false;
+ return Arrays.equals((long[]) mValue, (long[]) tag.mValue);
+ } else if (mValue instanceof Rational[]) {
+ if (!(tag.mValue instanceof Rational[])) return false;
+ return Arrays.equals((Rational[]) mValue, (Rational[]) tag.mValue);
+ } else {
+ return mValue.equals(tag.mValue);
+ }
+ } else {
+ return tag.mValue == null;
+ }
+ }
+ return false;
+ }
} \ No newline at end of file
diff --git a/src/com/android/gallery3d/exif/IfdData.java b/src/com/android/gallery3d/exif/IfdData.java
index 41093617f..079613b2c 100644
--- a/src/com/android/gallery3d/exif/IfdData.java
+++ b/src/com/android/gallery3d/exif/IfdData.java
@@ -77,6 +77,14 @@ public class IfdData {
public void setTag(ExifTag tag) {
mExifTags.put(tag.getTagId(), tag);
}
+
+ /**
+ * Gets the tags count in the IFD.
+ */
+ public int getTagCount() {
+ return mExifTags.size();
+ }
+
/**
* Sets the offset of next IFD.
*/
@@ -90,4 +98,25 @@ public class IfdData {
int getOffsetToNextIfd() {
return mOffsetToNextIfd;
}
+
+ /**
+ * Returns true if all tags in this two IFDs are equal. Note that tags of IFDs offset or
+ * thumbnail offset will be ignored.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof IfdData) {
+ IfdData data = (IfdData) obj;
+ if (data.getId() == mIfdId && data.getTagCount() == getTagCount()) {
+ ExifTag[] tags = data.getAllTags(new ExifTag[0]);
+ for (ExifTag tag: tags) {
+ if (ExifTag.isOffsetTag(tag.getTagId())) continue;
+ ExifTag tag2 = mExifTags.get(tag.getTagId());
+ if (!tag.equals(tag2)) return false;
+ }
+ return true;
+ }
+ }
+ return false;
+ }
} \ No newline at end of file
diff --git a/src/com/android/gallery3d/exif/Rational.java b/src/com/android/gallery3d/exif/Rational.java
index 4c3c77ffb..7d9026261 100644
--- a/src/com/android/gallery3d/exif/Rational.java
+++ b/src/com/android/gallery3d/exif/Rational.java
@@ -33,4 +33,13 @@ public class Rational {
public long getDenominator() {
return mDenominator;
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Rational) {
+ Rational data = (Rational) obj;
+ return mNominator == data.mNominator && mDenominator == data.mDenominator;
+ }
+ return false;
+ }
} \ No newline at end of file
diff --git a/src/com/android/gallery3d/exif/Util.java b/src/com/android/gallery3d/exif/Util.java
new file mode 100644
index 000000000..c7d9ce842
--- /dev/null
+++ b/src/com/android/gallery3d/exif/Util.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.gallery3d.exif;
+
+class Util {
+ public static boolean equals(Object a, Object b) {
+ return (a == b) || (a == null ? false : a.equals(b));
+ }
+}