summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Dodd <mdodd@google.com>2011-09-26 06:59:20 -0700
committerWu-cheng Li <wuchengli@google.com>2011-10-04 18:45:08 +0800
commitb416f542580970aeac320219b80137b1e9f8d4cd (patch)
tree731e8169066294a89528a279d96d63fc8867ff9d
parenta90deafe482fafe3109668491287c94710c02fdc (diff)
downloadLegacyCamera-b416f542580970aeac320219b80137b1e9f8d4cd.zip
LegacyCamera-b416f542580970aeac320219b80137b1e9f8d4cd.tar.gz
LegacyCamera-b416f542580970aeac320219b80137b1e9f8d4cd.tar.bz2
Fix display of preview thumbnail after recording video.
The first was that the code was trying to rotate the video thumbnail retrieved from MetadataRetriever back by just reversing whatever rotation we set as a playback hint when we started recording. But this isn't actually correct -- the bitmap we get back from MetadataRetriever is going to be oriented correctly for display if the device is oriented in the locked UI orientation (landscape), and we need to rotate it to compensate for what the actual device orientation is relative to that. Phrased another way, we were taking into account the camera and device orientation, but not the UI orientation. This just happened to work on some devices because of their camera orientations, but not all. bug:5360349 Change-Id: I8b481907c211328726ecd91fa054b9e9a4798601
-rw-r--r--src/com/android/camera/Util.java9
-rw-r--r--src/com/android/camera/VideoCamera.java22
2 files changed, 19 insertions, 12 deletions
diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java
index c5bc79d..61a55dd 100644
--- a/src/com/android/camera/Util.java
+++ b/src/com/android/camera/Util.java
@@ -115,8 +115,8 @@ public class Util {
public static Bitmap rotateAndMirror(Bitmap b, int degrees, boolean mirror) {
if ((degrees != 0 || mirror) && b != null) {
Matrix m = new Matrix();
- m.setRotate(degrees,
- (float) b.getWidth() / 2, (float) b.getHeight() / 2);
+ // Mirror first.
+ // horizontal flip + rotation = -rotation + horizontal flip
if (mirror) {
m.postScale(-1, 1);
degrees = (degrees + 360) % 360;
@@ -128,6 +128,11 @@ public class Util {
throw new IllegalArgumentException("Invalid degrees=" + degrees);
}
}
+ if (degrees != 0) {
+ // clockwise
+ m.postRotate(degrees,
+ (float) b.getWidth() / 2, (float) b.getHeight() / 2);
+ }
try {
Bitmap b2 = Bitmap.createBitmap(
diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java
index 81ce3a9..3198953 100644
--- a/src/com/android/camera/VideoCamera.java
+++ b/src/com/android/camera/VideoCamera.java
@@ -235,7 +235,8 @@ public class VideoCamera extends ActivityBase
// The orientation compensation for icons and thumbnails. Ex: if the value
// is 90, the UI components should be rotated 90 degrees counter-clockwise.
private int mOrientationCompensation = 0;
- private int mOrientationHint; // the orientation hint for video playback
+ // The orientation compenstaion when we start recording.
+ private int mOrientationCompensationAtRecordStart;
private static final int ZOOM_STOPPED = 0;
private static final int ZOOM_START = 1;
@@ -511,7 +512,7 @@ public class VideoCamera extends ActivityBase
mOrientationCompensation = orientationCompensation;
if (effectsActive()) {
CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
- int rotation = (info.orientation + mOrientation) % 360;;
+ int rotation = (info.orientation + mOrientation) % 360;
mEffectsRecorder.setOrientationHint(rotation);
}
// Do not rotate the icons during recording because the video
@@ -1169,6 +1170,9 @@ public class VideoCamera extends ActivityBase
// See android.hardware.Camera.Parameters.setRotation for
// documentation.
+ // Note that mOrientation here is the device orientation, which is the opposite of
+ // what activity.getWindowManager().getDefaultDisplay().getRotation() would return,
+ // which is the orientation the graphics need to rotate in order to render correctly.
int rotation = 0;
if (mOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
@@ -1179,7 +1183,7 @@ public class VideoCamera extends ActivityBase
}
}
mMediaRecorder.setOrientationHint(rotation);
- mOrientationHint = rotation;
+ mOrientationCompensationAtRecordStart = mOrientationCompensation;
try {
mMediaRecorder.prepare();
@@ -1214,7 +1218,7 @@ public class VideoCamera extends ActivityBase
rotation = (info.orientation + mOrientation) % 360;
}
mEffectsRecorder.setOrientationHint(rotation);
- mOrientationHint = rotation;
+ mOrientationCompensationAtRecordStart = mOrientationCompensation;
mEffectsRecorder.setPreviewDisplay(
mSurfaceHolder,
@@ -1546,13 +1550,11 @@ public class VideoCamera extends ActivityBase
mPreviewFrameLayout.getWidth());
if (bitmap != null) {
// MetadataRetriever already rotates the thumbnail. We should rotate
- // it back (and mirror if it is front-facing camera).
+ // it to match the UI orientation (and mirror if it is front-facing camera).
CameraInfo[] info = CameraHolder.instance().getCameraInfo();
- if (info[mCameraId].facing == CameraInfo.CAMERA_FACING_BACK) {
- bitmap = Util.rotateAndMirror(bitmap, -mOrientationHint, false);
- } else {
- bitmap = Util.rotateAndMirror(bitmap, -mOrientationHint, true);
- }
+ boolean mirror = (info[mCameraId].facing == CameraInfo.CAMERA_FACING_FRONT);
+ bitmap = Util.rotateAndMirror(bitmap, -mOrientationCompensationAtRecordStart,
+ mirror);
mReviewImage.setImageBitmap(bitmap);
mReviewImage.setVisibility(View.VISIBLE);
}