summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera
diff options
context:
space:
mode:
authorRuben Brunk <rubenbrunk@google.com>2013-03-11 19:00:12 -0700
committerRuben Brunk <rubenbrunk@google.com>2013-03-13 18:01:42 -0700
commit29fd4aa661f7e626a1d11558f09e8f7c011efcc2 (patch)
treec493ac90f0f3783e2efeea17083164a742cc621f /src/com/android/camera
parentacca4ee0fefe6442b853510b6b360f6cb7ad1bc5 (diff)
downloadandroid_packages_apps_Snap-29fd4aa661f7e626a1d11558f09e8f7c011efcc2.tar.gz
android_packages_apps_Snap-29fd4aa661f7e626a1d11558f09e8f7c011efcc2.tar.bz2
android_packages_apps_Snap-29fd4aa661f7e626a1d11558f09e8f7c011efcc2.zip
Exif parser modifications.
Bug: 8018327 Change-Id: I66a2ec309f9807ac255bbf29d8f5f26de60e89b8
Diffstat (limited to 'src/com/android/camera')
-rw-r--r--src/com/android/camera/Exif.java45
-rw-r--r--src/com/android/camera/PanoramaModule.java51
2 files changed, 21 insertions, 75 deletions
diff --git a/src/com/android/camera/Exif.java b/src/com/android/camera/Exif.java
index 605556599..ee39d675e 100644
--- a/src/com/android/camera/Exif.java
+++ b/src/com/android/camera/Exif.java
@@ -18,9 +18,7 @@ package com.android.camera;
import android.util.Log;
-import com.android.gallery3d.exif.ExifInvalidFormatException;
-import com.android.gallery3d.exif.ExifParser;
-import com.android.gallery3d.exif.ExifTag;
+import com.android.gallery3d.exif.ExifInterface;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -31,44 +29,23 @@ public class Exif {
// Returns the degrees in clockwise. Values are 0, 90, 180, or 270.
public static int getOrientation(byte[] jpeg) {
- if (jpeg == null) return 0;
+ if (jpeg == null) {
+ return 0;
+ }
+ ExifInterface exif = new ExifInterface();
InputStream is = new ByteArrayInputStream(jpeg);
-
try {
- ExifParser parser = ExifParser.parse(is, ExifParser.OPTION_IFD_0);
- int event = parser.next();
- while(event != ExifParser.EVENT_END) {
- if (event == ExifParser.EVENT_NEW_TAG) {
- ExifTag tag = parser.getTag();
- if (tag.getTagId() == ExifTag.TAG_ORIENTATION &&
- tag.hasValue()) {
- int orient = (int) tag.getValueAt(0);
- switch (orient) {
- case ExifTag.Orientation.TOP_LEFT:
- return 0;
- case ExifTag.Orientation.BOTTOM_LEFT:
- return 180;
- case ExifTag.Orientation.RIGHT_TOP:
- return 90;
- case ExifTag.Orientation.RIGHT_BOTTOM:
- return 270;
- default:
- Log.i(TAG, "Unsupported orientation");
- return 0;
- }
- }
- }
- event = parser.next();
+ exif.readExif(is);
+ Integer val = exif.getTagIntValue(ExifInterface.TAG_ORIENTATION);
+ if (val == null) {
+ return 0;
+ } else {
+ return ExifInterface.getRotationForOrientationValue(val.shortValue());
}
- Log.i(TAG, "Orientation not found");
- return 0;
} catch (IOException e) {
Log.w(TAG, "Failed to read EXIF orientation", e);
return 0;
- } catch (ExifInvalidFormatException e) {
- Log.w(TAG, "Failed to read EXIF orientation", e);
- return 0;
}
}
}
diff --git a/src/com/android/camera/PanoramaModule.java b/src/com/android/camera/PanoramaModule.java
index 623d96dc6..dc27f56f1 100644
--- a/src/com/android/camera/PanoramaModule.java
+++ b/src/com/android/camera/PanoramaModule.java
@@ -60,10 +60,7 @@ import com.android.camera.ui.PopupManager;
import com.android.camera.ui.Rotatable;
import com.android.gallery3d.R;
import com.android.gallery3d.common.ApiHelper;
-import com.android.gallery3d.exif.ExifData;
-import com.android.gallery3d.exif.ExifInvalidFormatException;
-import com.android.gallery3d.exif.ExifOutputStream;
-import com.android.gallery3d.exif.ExifReader;
+import com.android.gallery3d.exif.ExifInterface;
import com.android.gallery3d.exif.ExifTag;
import com.android.gallery3d.ui.GLRootView;
import com.android.gallery3d.util.UsageStatistics;
@@ -913,31 +910,18 @@ public class PanoramaModule implements CameraModule,
mActivity.getResources().getString(R.string.pano_file_name_format), mTimeTaken);
String filepath = Storage.generateFilepath(filename);
- ExifOutputStream out = null;
- InputStream is = null;
+ ExifInterface exif = new ExifInterface();
try {
- is = new ByteArrayInputStream(jpegData);
- ExifReader reader = new ExifReader();
- ExifData data = reader.read(is);
-
- // Add Exif tags.
- data.addGpsDateTimeStampTag(mTimeTaken);
- data.addDateTimeStampTag(ExifTag.TAG_DATE_TIME, mTimeTaken, TimeZone.getDefault());
- data.addTag(ExifTag.TAG_ORIENTATION).
- setValue(getExifOrientation(orientation));
-
- out = new ExifOutputStream(new FileOutputStream(filepath));
- out.setExifData(data);
- out.write(jpegData);
+ exif.readExif(jpegData);
+ exif.addGpsDateTimeStampTag(mTimeTaken);
+ exif.addDateTimeStampTag(ExifInterface.TAG_DATE_TIME, mTimeTaken,
+ TimeZone.getDefault());
+ exif.setTag(exif.buildTag(ExifInterface.TAG_ORIENTATION,
+ ExifInterface.getOrientationValueForRotation(orientation)));
+ exif.writeExif(jpegData, filepath);
} catch (IOException e) {
- Log.e(TAG, "Cannot set EXIF for " + filepath, e);
+ Log.e(TAG, "Cannot set exif for " + filepath, e);
Storage.writeFile(filepath, jpegData);
- } catch (ExifInvalidFormatException e) {
- Log.e(TAG, "Cannot set EXIF for " + filepath, e);
- Storage.writeFile(filepath, jpegData);
- } finally {
- Util.closeSilently(out);
- Util.closeSilently(is);
}
int jpegLength = (int) (new File(filepath).length());
@@ -947,21 +931,6 @@ public class PanoramaModule implements CameraModule,
return null;
}
- private static int getExifOrientation(int orientation) {
- switch (orientation) {
- case 0:
- return ExifTag.Orientation.TOP_LEFT;
- case 90:
- return ExifTag.Orientation.RIGHT_TOP;
- case 180:
- return ExifTag.Orientation.BOTTOM_LEFT;
- case 270:
- return ExifTag.Orientation.RIGHT_BOTTOM;
- default:
- throw new AssertionError("invalid: " + orientation);
- }
- }
-
private void clearMosaicFrameProcessorIfNeeded() {
if (!mPaused || mThreadRunning) return;
// Only clear the processor if it is initialized by this activity