summaryrefslogtreecommitdiffstats
path: root/gallerycommon/src
diff options
context:
space:
mode:
authorEarl Ou <shunhsingou@google.com>2012-12-07 16:56:10 +0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-12-19 05:28:18 -0800
commitbd901975af58c496ea8408b7b8427a0ddab61e22 (patch)
tree81cad6d716aaad0642cc4dbd52d68f8850b26630 /gallerycommon/src
parent4313f3ddeb6afa090cafd5cd4d845d0ee076c8ec (diff)
downloadandroid_packages_apps_Snap-bd901975af58c496ea8408b7b8427a0ddab61e22.zip
android_packages_apps_Snap-bd901975af58c496ea8408b7b8427a0ddab61e22.tar.gz
android_packages_apps_Snap-bd901975af58c496ea8408b7b8427a0ddab61e22.tar.bz2
add help function to decode user comment in ExifData
Change-Id: Ida19ce45bfc8b00972e751b652d99f6b19798116
Diffstat (limited to 'gallerycommon/src')
-rw-r--r--gallerycommon/src/com/android/gallery3d/exif/ExifData.java49
1 files changed, 48 insertions, 1 deletions
diff --git a/gallerycommon/src/com/android/gallery3d/exif/ExifData.java b/gallerycommon/src/com/android/gallery3d/exif/ExifData.java
index 88593e6..adaceb5 100644
--- a/gallerycommon/src/com/android/gallery3d/exif/ExifData.java
+++ b/gallerycommon/src/com/android/gallery3d/exif/ExifData.java
@@ -16,6 +16,10 @@
package com.android.gallery3d.exif;
+import android.util.Log;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Array;
import java.nio.ByteOrder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@@ -31,10 +35,19 @@ import java.util.TimeZone;
* @see IfdData
*/
public class ExifData {
-
+ private static final String TAG = "ExifData";
private static final String GPS_DATE_FORMAT_STR = "yyyy:MM:dd";
private static final String DATETIME_FORMAT_STR = "yyyy:MM:dd kk:mm:ss";
+ private static final byte[] USER_COMMENT_ASCII = {
+ 0x41, 0x53, 0x43, 0x49, 0x49, 0x00, 0x00, 0x00};
+ private static final byte[] USER_COMMENT_JIS = {
+ 0x4A, 0x49, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00};
+ private static final byte[] USER_COMMENT_UNICODE = {
+ 0x55, 0x4E, 0x49, 0x43, 0x4F, 0x44, 0x45, 0x00};
+ private static final byte[] USER_COMMENT_UNDEFINED = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
private final DateFormat mDateTimeStampFormat =
new SimpleDateFormat(DATETIME_FORMAT_STR);
private final DateFormat mGPSDateStampFormat =
@@ -323,4 +336,38 @@ public class ExifData {
mStripBytes.clear();
mIfdDatas[IfdId.TYPE_IFD_1] = null;
}
+
+ /**
+ * Decodes the user comment tag into string as specified in the EXIF standard.
+ * Returns null if decoding failed.
+ */
+ public String decodeUserComment() {
+ IfdData ifdData = mIfdDatas[IfdId.TYPE_IFD_0];
+ if (ifdData == null) return null;
+ ExifTag tag = ifdData.getTag(ExifTag.TAG_USER_COMMENT);
+ if (tag == null) return null;
+ if (tag.getComponentCount() < 8) return null;
+
+ byte[] buf = new byte[tag.getComponentCount()];
+ tag.getBytes(buf);
+
+ byte[] code = new byte[8];
+ System.arraycopy(buf, 0, code, 0, 8);
+
+ try {
+ if (Arrays.equals(code, USER_COMMENT_ASCII)) {
+ return new String(buf, 8, buf.length - 8, "US-ASCII");
+ } else if (Arrays.equals(code, USER_COMMENT_JIS)) {
+ return new String(buf, 8, buf.length - 8, "EUC-JP");
+ } else if (Arrays.equals(code, USER_COMMENT_UNICODE)) {
+ return new String(buf, 8, buf.length - 8, "UTF-16");
+ } else {
+ return null;
+ }
+ } catch (UnsupportedEncodingException e) {
+ Log.w(TAG, "Failed to decode the user comment");
+ return null;
+ }
+
+ }
}