diff options
author | Earl Ou <shunhsingou@google.com> | 2012-12-07 16:56:10 +0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-12-19 05:28:18 -0800 |
commit | 428afc0b79d1fa911df89b94c6b1517688667c2d (patch) | |
tree | 77712d31c109788a62056f9d9efad5187597fcd8 /gallerycommon/src/com/android | |
parent | acc9b347ded215b08ea09263812525efafd91b13 (diff) | |
download | android_packages_apps_Snap-428afc0b79d1fa911df89b94c6b1517688667c2d.tar.gz android_packages_apps_Snap-428afc0b79d1fa911df89b94c6b1517688667c2d.tar.bz2 android_packages_apps_Snap-428afc0b79d1fa911df89b94c6b1517688667c2d.zip |
add help function to decode user comment in ExifData
Change-Id: Ida19ce45bfc8b00972e751b652d99f6b19798116
Diffstat (limited to 'gallerycommon/src/com/android')
-rw-r--r-- | gallerycommon/src/com/android/gallery3d/exif/ExifData.java | 49 |
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 88593e651..adaceb519 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; + } + + } } |