summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWu-cheng Li <wuchengli@google.com>2011-10-04 22:03:45 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-10-04 22:03:45 -0700
commit2aa8185ae2efbafd7e4efd65fdf798819058c600 (patch)
treeeae1834fdf37c244ac2f5feba7d9ba85a1d346b4
parentb4d98e8e64d606beea6e131efbdee4f3cb8416a3 (diff)
parentb416f542580970aeac320219b80137b1e9f8d4cd (diff)
downloadLegacyCamera-2aa8185ae2efbafd7e4efd65fdf798819058c600.zip
LegacyCamera-2aa8185ae2efbafd7e4efd65fdf798819058c600.tar.gz
LegacyCamera-2aa8185ae2efbafd7e4efd65fdf798819058c600.tar.bz2
Merge "Fix display of preview thumbnail after recording video."
-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);
}