summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/data/LocalImage.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/gallery3d/data/LocalImage.java')
-rw-r--r--src/com/android/gallery3d/data/LocalImage.java74
1 files changed, 23 insertions, 51 deletions
diff --git a/src/com/android/gallery3d/data/LocalImage.java b/src/com/android/gallery3d/data/LocalImage.java
index d5fad5483..1ed67ecf4 100644
--- a/src/com/android/gallery3d/data/LocalImage.java
+++ b/src/com/android/gallery3d/data/LocalImage.java
@@ -23,7 +23,6 @@ import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapRegionDecoder;
-import android.media.ExifInterface;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore.Images;
@@ -37,8 +36,7 @@ import com.android.gallery3d.app.StitchingProgressManager;
import com.android.gallery3d.common.ApiHelper;
import com.android.gallery3d.common.BitmapUtils;
import com.android.gallery3d.common.Utils;
-import com.android.gallery3d.exif.ExifInvalidFormatException;
-import com.android.gallery3d.exif.ExifModifier;
+import com.android.gallery3d.exif.ExifInterface;
import com.android.gallery3d.exif.ExifTag;
import com.android.gallery3d.util.GalleryUtils;
import com.android.gallery3d.util.ThreadPool.Job;
@@ -46,6 +44,7 @@ import com.android.gallery3d.util.ThreadPool.JobContext;
import com.android.gallery3d.util.UpdateHelper;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel.MapMode;
@@ -196,15 +195,15 @@ public class LocalImage extends LocalMediaItem {
// try to decode from JPEG EXIF
if (type == MediaItem.TYPE_MICROTHUMBNAIL) {
- ExifInterface exif = null;
- byte [] thumbData = null;
+ ExifInterface exif = new ExifInterface();
+ byte[] thumbData = null;
try {
- exif = new ExifInterface(mLocalFilePath);
- if (exif != null) {
- thumbData = exif.getThumbnail();
- }
- } catch (Throwable t) {
- Log.w(TAG, "fail to get exif thumb", t);
+ exif.readExif(mLocalFilePath);
+ thumbData = exif.getThumbnail();
+ } catch (FileNotFoundException e) {
+ Log.w(TAG, "failed to find file to read thumbnail: " + mLocalFilePath);
+ } catch (IOException e) {
+ Log.w(TAG, "failed to get thumbnail from: " + mLocalFilePath);
}
if (thumbData != null) {
Bitmap bitmap = DecodeUtils.decodeIfBigEnough(
@@ -276,21 +275,6 @@ public class LocalImage extends LocalMediaItem {
new String[]{String.valueOf(id)});
}
- private static int getExifOrientation(int orientation) {
- switch (orientation) {
- case 0:
- return ExifInterface.ORIENTATION_NORMAL;
- case 90:
- return ExifInterface.ORIENTATION_ROTATE_90;
- case 180:
- return ExifInterface.ORIENTATION_ROTATE_180;
- case 270:
- return ExifInterface.ORIENTATION_ROTATE_270;
- default:
- throw new AssertionError("invalid: " + orientation);
- }
- }
-
@Override
public void rotate(int degrees) {
GalleryUtils.assertNotInRenderThread();
@@ -300,34 +284,22 @@ public class LocalImage extends LocalMediaItem {
if (rotation < 0) rotation += 360;
if (mimeType.equalsIgnoreCase("image/jpeg")) {
- RandomAccessFile file = null;
- try {
- // Because most of the images contain the orientation tag, we
- // use ExifModifier to modify the tag for better efficiency.
- // If the tag doesn't exist, ExifInterface will be used to replace the entire
- // header.
- file = new RandomAccessFile(filePath, "rw");
- ExifModifier modifier = new ExifModifier(
- file.getChannel().map(MapMode.READ_WRITE, 0, file.length()));
- ExifTag tag = ExifTag.buildTag(ExifTag.TAG_ORIENTATION);
- tag.setValue(getExifOrientation(rotation));
- modifier.modifyTag(tag);
- if (!modifier.commit()) {
- // Need to change the file size, use ExifInterface instead.
- ExifInterface exif = new ExifInterface(filePath);
- exif.setAttribute(ExifInterface.TAG_ORIENTATION,
- String.valueOf(getExifOrientation(rotation)));
- exif.saveAttributes();
- // We need to update the filesize as well
+ ExifInterface exifInterface = new ExifInterface();
+ ExifTag tag = exifInterface.buildTag(ExifInterface.TAG_ORIENTATION,
+ ExifInterface.getOrientationValueForRotation(rotation));
+ if(tag != null) {
+ exifInterface.setTag(tag);
+ try {
+ exifInterface.forceRewriteExif(filePath);
fileSize = new File(filePath).length();
values.put(Images.Media.SIZE, fileSize);
+ } catch (FileNotFoundException e) {
+ Log.w(TAG, "cannot find file to set exif: " + filePath);
+ } catch (IOException e) {
+ Log.w(TAG, "cannot set exif data: " + filePath);
}
- } catch (IOException e) {
- Log.w(TAG, "cannot set exif data: " + filePath);
- } catch (ExifInvalidFormatException e) {
- Log.w(TAG, "cannot set exif data: " + filePath);
- } finally {
- Utils.closeSilently(file);
+ } else {
+ Log.w(TAG, "Could not build tag: " + ExifInterface.TAG_ORIENTATION);
}
}