diff options
8 files changed, 42 insertions, 86 deletions
diff --git a/gallerycommon/src/com/android/gallery3d/exif/ExifOutputStream.java b/gallerycommon/src/com/android/gallery3d/exif/ExifOutputStream.java index 46cd65594..51a30ffa2 100644 --- a/gallerycommon/src/com/android/gallery3d/exif/ExifOutputStream.java +++ b/gallerycommon/src/com/android/gallery3d/exif/ExifOutputStream.java @@ -225,8 +225,9 @@ public class ExifOutputStream extends FilterOutputStream { } break; case ExifTag.TYPE_LONG: + case ExifTag.TYPE_UNSIGNED_LONG: for (int i = 0, n = tag.getComponentCount(); i < n; i++) { - dataOutputStream.writeInt(tag.getLong(i)); + dataOutputStream.writeInt((int) tag.getValueAt(i)); } break; case ExifTag.TYPE_RATIONAL: @@ -241,14 +242,9 @@ public class ExifOutputStream extends FilterOutputStream { tag.getBytes(buf); dataOutputStream.write(buf); break; - case ExifTag.TYPE_UNSIGNED_LONG: - for (int i = 0, n = tag.getComponentCount(); i < n; i++) { - dataOutputStream.writeInt((int) tag.getUnsignedLong(i)); - } - break; case ExifTag.TYPE_UNSIGNED_SHORT: for (int i = 0, n = tag.getComponentCount(); i < n; i++) { - dataOutputStream.writeShort((short) tag.getUnsignedShort(i)); + dataOutputStream.writeShort((short) tag.getValueAt(i)); } break; } diff --git a/gallerycommon/src/com/android/gallery3d/exif/ExifParser.java b/gallerycommon/src/com/android/gallery3d/exif/ExifParser.java index a6bbda078..2cff12a3d 100644 --- a/gallerycommon/src/com/android/gallery3d/exif/ExifParser.java +++ b/gallerycommon/src/com/android/gallery3d/exif/ExifParser.java @@ -435,13 +435,7 @@ public class ExifParser { */ public int getStripSize() { if (mStripSizeTag == null) return 0; - if (mStripSizeTag.getDataType() == ExifTag.TYPE_UNSIGNED_SHORT) { - return mStripSizeTag.getUnsignedShort(mImageEvent.stripIndex); - } else { - // Cast unsigned int to int since the strip size is always smaller - // than the size of APP1 (65536) - return (int) mStripSizeTag.getUnsignedLong(mImageEvent.stripIndex); - } + return (int) mStripSizeTag.getValueAt(0); } /** @@ -450,15 +444,7 @@ public class ExifParser { */ public int getCompressedImageSize() { if (mJpegSizeTag == null) return 0; - - // Some invalid image use short type tag - if (mJpegSizeTag.getDataType() == ExifTag.TYPE_UNSIGNED_SHORT) { - return mJpegSizeTag.getUnsignedShort(0); - } - - // Cast unsigned int to int since the thumbnail is always smaller - // than the size of APP1 (65536) - return (int) mJpegSizeTag.getUnsignedLong(0); + return (int) mJpegSizeTag.getValueAt(0); } private void skipTo(int offset) throws IOException { @@ -546,22 +532,22 @@ public class ExifParser { case ExifTag.TAG_EXIF_IFD: if (isIfdRequested(IfdId.TYPE_IFD_EXIF) || isIfdRequested(IfdId.TYPE_IFD_INTEROPERABILITY)) { - registerIfd(IfdId.TYPE_IFD_EXIF, tag.getUnsignedLong(0)); + registerIfd(IfdId.TYPE_IFD_EXIF, tag.getValueAt(0)); } break; case ExifTag.TAG_GPS_IFD: if (isIfdRequested(IfdId.TYPE_IFD_GPS)) { - registerIfd(IfdId.TYPE_IFD_GPS, tag.getUnsignedLong(0)); + registerIfd(IfdId.TYPE_IFD_GPS, tag.getValueAt(0)); } break; case ExifTag.TAG_INTEROPERABILITY_IFD: if (isIfdRequested(IfdId.TYPE_IFD_INTEROPERABILITY)) { - registerIfd(IfdId.TYPE_IFD_INTEROPERABILITY, tag.getUnsignedLong(0)); + registerIfd(IfdId.TYPE_IFD_INTEROPERABILITY, tag.getValueAt(0)); } break; case ExifTag.TAG_JPEG_INTERCHANGE_FORMAT: if (isThumbnailRequested()) { - registerCompressedImage(tag.getUnsignedLong(0)); + registerCompressedImage(tag.getValueAt(0)); } break; case ExifTag.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH: @@ -574,9 +560,9 @@ public class ExifParser { if (tag.hasValue()) { for (int i = 0; i < tag.getComponentCount(); i++) { if (tag.getDataType() == ExifTag.TYPE_UNSIGNED_SHORT) { - registerUncompressedStrip(i, tag.getUnsignedShort(i)); + registerUncompressedStrip(i, tag.getValueAt(i)); } else { - registerUncompressedStrip(i, tag.getUnsignedLong(i)); + registerUncompressedStrip(i, tag.getValueAt(i)); } } } else { diff --git a/gallerycommon/src/com/android/gallery3d/exif/ExifTag.java b/gallerycommon/src/com/android/gallery3d/exif/ExifTag.java index d914f5869..cda67c2e2 100644 --- a/gallerycommon/src/com/android/gallery3d/exif/ExifTag.java +++ b/gallerycommon/src/com/android/gallery3d/exif/ExifTag.java @@ -1286,7 +1286,8 @@ public class ExifTag { setValue(value, 0, value.length); } - private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("yyyy:MM:dd kk:mm:ss"); + private static final SimpleDateFormat TIME_FORMAT = + new SimpleDateFormat("yyyy:MM:dd kk:mm:ss"); /** * Sets a timestamp to this tag. The method converts the timestamp with the format of @@ -1302,41 +1303,23 @@ public class ExifTag { setValue(TIME_FORMAT.format(new Date(time))); } } - /** - * Gets the {@link #TYPE_UNSIGNED_SHORT} data. - * @exception IllegalArgumentException If the type is NOT {@link #TYPE_UNSIGNED_SHORT}. - */ - public int getUnsignedShort(int index) { - if (mDataType != TYPE_UNSIGNED_SHORT) { - throw new IllegalArgumentException("Cannot get UNSIGNED_SHORT value from " - + convertTypeToString(mDataType)); - } - return (int) (((long[]) mValue) [index]); - } - - /** - * Gets the {@link #TYPE_LONG} data. - * @exception IllegalArgumentException If the type is NOT {@link #TYPE_LONG}. - */ - public int getLong(int index) { - if (mDataType != TYPE_LONG) { - throw new IllegalArgumentException("Cannot get LONG value from " - + convertTypeToString(mDataType)); - } - return (int) (((long[]) mValue) [index]); - } - - /** - * Gets the {@link #TYPE_UNSIGNED_LONG} data. - * @exception IllegalArgumentException If the type is NOT {@link #TYPE_UNSIGNED_LONG}. + * Gets the value for type {@link #TYPE_ASCII}, {@link #TYPE_LONG}, + * {@link #TYPE_UNDEFINED}, {@link #TYPE_UNSIGNED_BYTE}, {@link #TYPE_UNSIGNED_LONG}, or + * {@link #TYPE_UNSIGNED_SHORT}. For {@link #TYPE_RATIONAL} or {@link #TYPE_UNSIGNED_RATIONAL}, + * call {@link #getRational(int)} instead. + * + * @exception IllegalArgumentException if the data type is {@link #TYPE_RATIONAL} or + * {@link #TYPE_UNSIGNED_RATIONAL}. */ - public long getUnsignedLong(int index) { - if (mDataType != TYPE_UNSIGNED_LONG) { - throw new IllegalArgumentException("Cannot get UNSIGNED LONG value from " - + convertTypeToString(mDataType)); + public long getValueAt(int index) { + if (mValue instanceof long[]) { + return ((long[]) mValue) [index]; + } else if (mValue instanceof byte[]) { + return ((byte[]) mValue) [index]; } - return ((long[]) mValue) [index]; + throw new IllegalArgumentException("Cannot get integer value from " + + convertTypeToString(mDataType)); } /** diff --git a/src/com/android/gallery3d/data/Exif.java b/src/com/android/gallery3d/data/Exif.java index 4d1fc9453..30aba7e97 100644 --- a/src/com/android/gallery3d/data/Exif.java +++ b/src/com/android/gallery3d/data/Exif.java @@ -41,7 +41,7 @@ public class Exif { ExifTag tag = parser.getTag(); if (tag.getTagId() == ExifTag.TAG_ORIENTATION && tag.hasValue()) { - int orient = tag.getUnsignedShort(0); + int orient = (int) tag.getValueAt(0); switch (orient) { case ExifTag.Orientation.TOP_LEFT: return 0; diff --git a/tests/src/com/android/gallery3d/exif/ExifDataTest.java b/tests/src/com/android/gallery3d/exif/ExifDataTest.java index ba656bfa8..fed8e1eaf 100644 --- a/tests/src/com/android/gallery3d/exif/ExifDataTest.java +++ b/tests/src/com/android/gallery3d/exif/ExifDataTest.java @@ -42,13 +42,13 @@ public class ExifDataTest extends TestCase { // check data assertEquals("test", exifData.getTag(ExifTag.TAG_MAKE).getString()); - assertEquals(1000, exifData.getTag(ExifTag.TAG_IMAGE_WIDTH).getUnsignedLong(0)); - assertEquals(1, exifData.getTag(ExifTag.TAG_ISO_SPEED_RATINGS).getUnsignedShort(0)); + assertEquals(1000, (int) exifData.getTag(ExifTag.TAG_IMAGE_WIDTH).getValueAt(0)); + assertEquals(1, (int) exifData.getTag(ExifTag.TAG_ISO_SPEED_RATINGS).getValueAt(0)); assertEquals(new Rational(10, 100), exifData.getTag(ExifTag.TAG_GPS_ALTITUDE).getRational(0)); assertEquals("inter_test", exifData.getInteroperabilityTag(ExifTag.TAG_INTEROPERABILITY_INDEX).getString()); assertEquals("test_thumb", exifData.getThumbnailTag(ExifTag.TAG_MAKE).getString()); - assertEquals(100, exifData.getThumbnailTag(ExifTag.TAG_IMAGE_WIDTH).getUnsignedLong(0)); + assertEquals(100, (int) exifData.getThumbnailTag(ExifTag.TAG_IMAGE_WIDTH).getValueAt(0)); } } diff --git a/tests/src/com/android/gallery3d/exif/ExifParserTest.java b/tests/src/com/android/gallery3d/exif/ExifParserTest.java index e86390e87..7a9d6e631 100644 --- a/tests/src/com/android/gallery3d/exif/ExifParserTest.java +++ b/tests/src/com/android/gallery3d/exif/ExifParserTest.java @@ -201,7 +201,7 @@ public class ExifParserTest extends ExifXmlDataTestCase { case ExifParser.EVENT_NEW_TAG: ExifTag tag = parser.getTag(); if (tag.getTagId() == ExifTag.TAG_COMPRESSION) { - if (tag.getUnsignedShort(0) == ExifTag.Compression.JPEG) { + if (tag.getValueAt(0) == ExifTag.Compression.JPEG) { mIsContainCompressedImage = true; } } diff --git a/tests/src/com/android/gallery3d/exif/ExifReaderTest.java b/tests/src/com/android/gallery3d/exif/ExifReaderTest.java index 374d5b034..30f34c09a 100644 --- a/tests/src/com/android/gallery3d/exif/ExifReaderTest.java +++ b/tests/src/com/android/gallery3d/exif/ExifReaderTest.java @@ -64,8 +64,7 @@ public class ExifReaderTest extends ExifXmlDataTestCase { String typeTagTruth = typeTagValue.get(0); - ExifTag typeTag = ifd1.getTag(ExifTag.TAG_COMPRESSION); - int type = typeTag.getUnsignedShort(0); + int type = (int) ifd1.getTag(ExifTag.TAG_COMPRESSION).getValueAt(0); if (String.valueOf(ExifTag.Compression.JPEG).equals(typeTagTruth)) { assertTrue(getImageTitle(), type == ExifTag.Compression.JPEG); @@ -79,7 +78,7 @@ public class ExifReaderTest extends ExifXmlDataTestCase { int planarType = ExifTag.PlanarConfiguration.CHUNKY; ExifTag planarTag = ifd1.getTag(ExifTag.TAG_PLANAR_CONFIGURATION); if (planarTag != null) { - planarType = planarTag.getUnsignedShort(0); + planarType = (int) planarTag.getValueAt(0); } if (!ifd1Truth.containsKey(ExifTag.TAG_IMAGE_LENGTH) || @@ -91,8 +90,8 @@ public class ExifReaderTest extends ExifXmlDataTestCase { // Fail the test if required tags are missing if (heightTag == null || rowPerStripTag == null) fail(getImageTitle()); - int imageLength = getUnsignedIntOrShort(heightTag); - int rowsPerStrip = getUnsignedIntOrShort(rowPerStripTag); + int imageLength = (int) heightTag.getValueAt(0); + int rowsPerStrip = (int) rowPerStripTag.getValueAt(0); int stripCount = ifd1.getTag( ExifTag.TAG_STRIP_OFFSETS).getComponentCount(); @@ -102,7 +101,7 @@ public class ExifReaderTest extends ExifXmlDataTestCase { } else { if (!ifd1Truth.containsKey(ExifTag.TAG_SAMPLES_PER_PIXEL)) return; ExifTag samplePerPixelTag = ifd1.getTag(ExifTag.TAG_SAMPLES_PER_PIXEL); - int samplePerPixel = samplePerPixelTag.getUnsignedShort(0); + int samplePerPixel = (int) samplePerPixelTag.getValueAt(0); assertTrue(getImageTitle(), stripCount == (imageLength + rowsPerStrip - 1) / rowsPerStrip * samplePerPixel); @@ -114,23 +113,15 @@ public class ExifReaderTest extends ExifXmlDataTestCase { for (int i = 0; i < stripCount; i++) { if (byteCountDataType == ExifTag.TYPE_UNSIGNED_SHORT) { assertEquals(getImageTitle(), - byteCountTag.getUnsignedShort(i), exifData.getStrip(i).length); + byteCountTag.getValueAt(i), exifData.getStrip(i).length); } else { assertEquals(getImageTitle(), - byteCountTag.getUnsignedLong(i), exifData.getStrip(i).length); + byteCountTag.getValueAt(i), exifData.getStrip(i).length); } } } } - private int getUnsignedIntOrShort(ExifTag tag) { - if (tag.getDataType() == ExifTag.TYPE_UNSIGNED_SHORT) { - return tag.getUnsignedShort(0); - } else { - return (int) tag.getUnsignedLong(0); - } - } - private void checkIfd(IfdData ifd, Map<Short, List<String>> ifdValue) { if (ifd == null) { assertEquals(getImageTitle(), 0 ,ifdValue.size()); diff --git a/tests/src/com/android/gallery3d/exif/Util.java b/tests/src/com/android/gallery3d/exif/Util.java index 633063078..0e51fd7bf 100644 --- a/tests/src/com/android/gallery3d/exif/Util.java +++ b/tests/src/com/android/gallery3d/exif/Util.java @@ -116,7 +116,7 @@ class Util { case ExifTag.TYPE_UNSIGNED_LONG: for(int i = 0, n = tag.getComponentCount(); i < n; i++) { if(i != 0) sbuilder.append(" "); - sbuilder.append(tag.getUnsignedLong(i)); + sbuilder.append(tag.getValueAt(i)); } break; case ExifTag.TYPE_RATIONAL: @@ -130,13 +130,13 @@ class Util { case ExifTag.TYPE_UNSIGNED_SHORT: for(int i = 0, n = tag.getComponentCount(); i < n; i++) { if(i != 0) sbuilder.append(" "); - sbuilder.append(tag.getUnsignedShort(i)); + sbuilder.append((int) tag.getValueAt(i)); } break; case ExifTag.TYPE_LONG: for(int i = 0, n = tag.getComponentCount(); i < n; i++) { if(i != 0) sbuilder.append(" "); - sbuilder.append(tag.getLong(i)); + sbuilder.append((int) tag.getValueAt(i)); } break; } |