From 1c515f1aed514638cc030cd5cba5258231e74bb5 Mon Sep 17 00:00:00 2001 From: Hung-ying Tyan Date: Mon, 22 Oct 2012 16:23:41 -0700 Subject: am bdc0f6f2: Merge "Move new exif lib to gallerycommon." into gb-ub-photos-arches * commit 'bdc0f6f2784b46ebe5d33d5e7e85bc347f07c468': Move new exif lib to gallerycommon. --- .../src/com/android/gallery3d/exif/ExifData.java | 36 +++++++++++------ .../src/com/android/gallery3d/exif/ExifTag.java | 45 ++++++++++++++++++++-- 2 files changed, 65 insertions(+), 16 deletions(-) (limited to 'gallerycommon') diff --git a/gallerycommon/src/com/android/gallery3d/exif/ExifData.java b/gallerycommon/src/com/android/gallery3d/exif/ExifData.java index 39eb57455..7f7971384 100644 --- a/gallerycommon/src/com/android/gallery3d/exif/ExifData.java +++ b/gallerycommon/src/com/android/gallery3d/exif/ExifData.java @@ -216,7 +216,8 @@ public class ExifData { } /** - * Adds a tag with the given tag ID. The original tag will be replaced by the new tag. For tags + * Adds a tag with the given tag ID. If the tag of the given ID already exists, + * the original tag will be returned. Otherwise, a new ExifTag will be created. For tags * related to interoperability or thumbnail, call {@link #addInteroperabilityTag(short)} or * {@link #addThumbnailTag(short)} respectively. * @exception IllegalArgumentException if the tag ID is invalid. @@ -224,32 +225,43 @@ public class ExifData { public ExifTag addTag(short tagId) { int ifdId = ExifTag.getIfdIdFromTagId(tagId); IfdData ifdData = getOrCreateIfdData(ifdId); - ExifTag tag = ExifTag.buildTag(tagId); - ifdData.setTag(tag); + ExifTag tag = ifdData.getTag(tagId); + if (tag == null) { + tag = ExifTag.buildTag(tagId); + ifdData.setTag(tag); + } return tag; } /** - * Adds a thumbnail-related tag with the given tag ID. The original tag will be replaced - * by the new tag. + * Adds a thumbnail-related tag with the given tag ID. If the tag of the given ID + * already exists, the original tag will be returned. Otherwise, a new ExifTag will + * be created. * @exception IllegalArgumentException if the tag ID is invalid. */ public ExifTag addThumbnailTag(short tagId) { IfdData ifdData = getOrCreateIfdData(IfdId.TYPE_IFD_1); - ExifTag tag = ExifTag.buildThumbnailTag(tagId); - ifdData.setTag(tag); + ExifTag tag = ifdData.getTag(tagId); + if (tag == null) { + tag = ExifTag.buildThumbnailTag(tagId); + ifdData.setTag(tag); + } return tag; } /** - * Adds an interoperability-related tag with the given tag ID. The original tag will be - * replaced by the new tag. + * Adds an interoperability-related tag with the given tag ID. If the tag of the given ID + * already exists, the original tag will be returned. Otherwise, a new ExifTag will + * be created. * @exception IllegalArgumentException if the tag ID is invalid. */ public ExifTag addInteroperabilityTag(short tagId) { IfdData ifdData = getOrCreateIfdData(IfdId.TYPE_IFD_INTEROPERABILITY); - ExifTag tag = ExifTag.buildInteroperabilityTag(tagId); - ifdData.setTag(tag); + ExifTag tag = ifdData.getTag(tagId); + if (tag == null) { + tag = ExifTag.buildInteroperabilityTag(tagId); + ifdData.setTag(tag); + } return tag; } @@ -258,4 +270,4 @@ public class ExifData { mStripBytes.clear(); mIfdDatas[IfdId.TYPE_IFD_1] = null; } -} \ No newline at end of file +} diff --git a/gallerycommon/src/com/android/gallery3d/exif/ExifTag.java b/gallerycommon/src/com/android/gallery3d/exif/ExifTag.java index 49cb6edbc..def80a939 100644 --- a/gallerycommon/src/com/android/gallery3d/exif/ExifTag.java +++ b/gallerycommon/src/com/android/gallery3d/exif/ExifTag.java @@ -1354,23 +1354,51 @@ public class ExifTag { (length > mComponentCount) ? mComponentCount : length); } + private String undefinedTypeValueToString() { + StringBuilder sbuilder = new StringBuilder(); + switch (mTagId) { + case TAG_COMPONENTS_CONFIGURATION: + case TAG_FILE_SOURCE: + case TAG_SCENE_TYPE: + byte buf[] = (byte[]) mValue; + for(int i = 0, n = getComponentCount(); i < n; i++) { + if(i != 0) sbuilder.append(" "); + sbuilder.append(buf[i]); + } + break; + default: + sbuilder.append(new String((byte[]) mValue)); + } + return sbuilder.toString(); + } + /** * Returns a string representation of the value of this tag. */ - public String valueToString() { + String valueToString() { StringBuilder sbuilder = new StringBuilder(); switch (getDataType()) { case ExifTag.TYPE_UNDEFINED: + sbuilder.append(undefinedTypeValueToString()); + break; case ExifTag.TYPE_UNSIGNED_BYTE: - byte buf[] = new byte[getComponentCount()]; - getBytes(buf); + byte buf[] = (byte[]) mValue; for(int i = 0, n = getComponentCount(); i < n; i++) { if(i != 0) sbuilder.append(" "); sbuilder.append(String.format("%02x", buf[i])); } break; case ExifTag.TYPE_ASCII: - sbuilder.append(getString()); + String s = getString(); + for (int i = 0, n = s.length(); i < n; i++) { + int code = s.codePointAt(i); + if (code == 0) continue; + if (code > 31 && code < 127) { + sbuilder.append((char) code); + } else { + sbuilder.append('.'); + } + } break; case ExifTag.TYPE_UNSIGNED_LONG: for(int i = 0, n = getComponentCount(); i < n; i++) { @@ -1415,6 +1443,15 @@ public class ExifTag { || tagId == TAG_INTEROPERABILITY_IFD; } + /** + * Returns true if the ID is one of the following: {@link #TAG_EXIF_IFD}, + * {@link #TAG_GPS_IFD}, {@link #TAG_INTEROPERABILITY_IFD} + */ + static boolean isSubIfdOffsetTag(short tagId) { + return tagId == TAG_EXIF_IFD + || tagId == TAG_GPS_IFD + || tagId == TAG_INTEROPERABILITY_IFD; + } @Override public boolean equals(Object obj) { if (obj instanceof ExifTag) { -- cgit v1.2.3