summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gallerycommon/src/com/android/gallery3d/common/ExifTags.java27
-rw-r--r--gallerycommon/src/com/android/gallery3d/exif/Rational.java9
-rw-r--r--src/com/android/gallery3d/data/MediaDetails.java59
3 files changed, 50 insertions, 45 deletions
diff --git a/gallerycommon/src/com/android/gallery3d/common/ExifTags.java b/gallerycommon/src/com/android/gallery3d/common/ExifTags.java
deleted file mode 100644
index 9b11fe4..0000000
--- a/gallerycommon/src/com/android/gallery3d/common/ExifTags.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.common;
-
-/**
- * The class holds the EXIF tag names that are not available in
- * {@link android.media.ExifInterface} prior to API level 11.
- */
-public interface ExifTags {
- static final String TAG_ISO = "ISOSpeedRatings";
- static final String TAG_EXPOSURE_TIME = "ExposureTime";
- static final String TAG_APERTURE = "FNumber";
-}
diff --git a/gallerycommon/src/com/android/gallery3d/exif/Rational.java b/gallerycommon/src/com/android/gallery3d/exif/Rational.java
index 7d90262..202c5d4 100644
--- a/gallerycommon/src/com/android/gallery3d/exif/Rational.java
+++ b/gallerycommon/src/com/android/gallery3d/exif/Rational.java
@@ -42,4 +42,13 @@ public class Rational {
}
return false;
}
+
+ @Override
+ public String toString() {
+ return mNominator + "/" + mDenominator;
+ }
+
+ public double toDouble() {
+ return mNominator / (double) mDenominator;
+ }
} \ No newline at end of file
diff --git a/src/com/android/gallery3d/data/MediaDetails.java b/src/com/android/gallery3d/data/MediaDetails.java
index 2982247..c255da7 100644
--- a/src/com/android/gallery3d/data/MediaDetails.java
+++ b/src/com/android/gallery3d/data/MediaDetails.java
@@ -20,8 +20,15 @@ import android.media.ExifInterface;
import com.android.gallery3d.R;
import com.android.gallery3d.common.ExifTags;
+import com.android.gallery3d.common.Utils;
+import com.android.gallery3d.exif.ExifData;
+import com.android.gallery3d.exif.ExifInvalidFormatException;
+import com.android.gallery3d.exif.ExifReader;
+import com.android.gallery3d.exif.ExifTag;
+import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
@@ -105,10 +112,18 @@ public class MediaDetails implements Iterable<Entry<Integer, Object>> {
return mUnits.get(index);
}
- private static void setExifData(MediaDetails details, ExifInterface exif, String tag,
+ private static void setExifData(MediaDetails details, ExifTag tag,
int key) {
- String value = exif.getAttribute(tag);
- if (value != null) {
+ if (tag != null) {
+ String value = null;
+ int type = tag.getDataType();
+ if (type == ExifTag.TYPE_UNSIGNED_RATIONAL || type == ExifTag.TYPE_RATIONAL) {
+ value = String.valueOf(tag.getRational(0).toDouble());
+ } else if (type == ExifTag.TYPE_ASCII) {
+ value = tag.getString();
+ } else {
+ value = String.valueOf(tag.getValueAt(0));
+ }
if (key == MediaDetails.INDEX_FLASH) {
MediaDetails.FlashState state = new MediaDetails.FlashState(
Integer.valueOf(value.toString()));
@@ -120,29 +135,37 @@ public class MediaDetails implements Iterable<Entry<Integer, Object>> {
}
public static void extractExifInfo(MediaDetails details, String filePath) {
+ InputStream is = null;
try {
- ExifInterface exif = new ExifInterface(filePath);
- setExifData(details, exif, ExifInterface.TAG_FLASH, MediaDetails.INDEX_FLASH);
- setExifData(details, exif, ExifInterface.TAG_IMAGE_WIDTH, MediaDetails.INDEX_WIDTH);
- setExifData(details, exif, ExifInterface.TAG_IMAGE_LENGTH,
- MediaDetails.INDEX_HEIGHT);
- setExifData(details, exif, ExifInterface.TAG_MAKE, MediaDetails.INDEX_MAKE);
- setExifData(details, exif, ExifInterface.TAG_MODEL, MediaDetails.INDEX_MODEL);
- setExifData(details, exif, ExifTags.TAG_APERTURE, MediaDetails.INDEX_APERTURE);
- setExifData(details, exif, ExifTags.TAG_ISO, MediaDetails.INDEX_ISO);
- setExifData(details, exif, ExifInterface.TAG_WHITE_BALANCE,
+ is = new FileInputStream(filePath);
+ ExifData data = new ExifReader().read(is);
+ setExifData(details, data.getTag(ExifTag.TAG_FLASH), MediaDetails.INDEX_FLASH);
+ setExifData(details, data.getTag(ExifTag.TAG_IMAGE_WIDTH), MediaDetails.INDEX_WIDTH);
+ setExifData(details, data.getTag(ExifTag.TAG_IMAGE_LENGTH), MediaDetails.INDEX_HEIGHT);
+ setExifData(details, data.getTag(ExifTag.TAG_MAKE), MediaDetails.INDEX_MAKE);
+ setExifData(details, data.getTag(ExifTag.TAG_MODEL),MediaDetails.INDEX_MODEL);
+ setExifData(details, data.getTag(ExifTag.TAG_APERTURE_VALUE),
+ MediaDetails.INDEX_APERTURE);
+ setExifData(details, data.getTag(ExifTag.TAG_ISO_SPEED_RATINGS),
+ MediaDetails.INDEX_ISO);
+ setExifData(details, data.getTag(ExifTag.TAG_WHITE_BALANCE),
MediaDetails.INDEX_WHITE_BALANCE);
- setExifData(details, exif, ExifTags.TAG_EXPOSURE_TIME,
+ setExifData(details, data.getTag(ExifTag.TAG_EXPOSURE_TIME),
MediaDetails.INDEX_EXPOSURE_TIME);
-
- double data = exif.getAttributeDouble(ExifInterface.TAG_FOCAL_LENGTH, 0);
- if (data != 0f) {
- details.addDetail(MediaDetails.INDEX_FOCAL_LENGTH, data);
+ ExifTag focalTag = data.getTag(ExifTag.TAG_FOCAL_LENGTH);
+ if (focalTag != null) {
+ details.addDetail(MediaDetails.INDEX_FOCAL_LENGTH,
+ focalTag.getRational(0).toDouble());
details.setUnit(MediaDetails.INDEX_FOCAL_LENGTH, R.string.unit_mm);
}
} catch (IOException ex) {
// ignore it.
Log.w(TAG, "", ex);
+ } catch (ExifInvalidFormatException ex) {
+ // ignore it.
+ Log.w(TAG, "", ex);
+ } finally {
+ Utils.closeSilently(is);
}
}
}