summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWu-cheng Li <wuchengli@google.com>2010-11-09 22:00:27 +0800
committerWu-cheng Li <wuchengli@google.com>2010-11-09 22:16:57 +0800
commitd56274ad69e088a1682d33c6d414261ed080b378 (patch)
treeb692d97db7da67fb4bc22a808632b82a84d66f28 /src
parent6e5a8f04d04155f7e3a8681f42475ce5863ee046 (diff)
downloadLegacyCamera-d56274ad69e088a1682d33c6d414261ed080b378.zip
LegacyCamera-d56274ad69e088a1682d33c6d414261ed080b378.tar.gz
LegacyCamera-d56274ad69e088a1682d33c6d414261ed080b378.tar.bz2
Rotate the postview to correct orientation in video attach mode. do not merge
bug:3163671 Change-Id: I78d8de1b2fc5f15a268c94062a58b3065772b688
Diffstat (limited to 'src')
-rw-r--r--src/com/android/camera/Util.java18
-rw-r--r--src/com/android/camera/VideoCamera.java16
2 files changed, 31 insertions, 3 deletions
diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java
index d5cd768..560a565 100644
--- a/src/com/android/camera/Util.java
+++ b/src/com/android/camera/Util.java
@@ -52,10 +52,28 @@ public class Util {
// Rotates the bitmap by the specified degree.
// If a new bitmap is created, the original bitmap is recycled.
public static Bitmap rotate(Bitmap b, int degrees) {
+ return rotateAndMirror(b, degrees, false);
+ }
+
+ // Rotates and/or mirrors the bitmap. If a new bitmap is created, the
+ // original bitmap is recycled.
+ public static Bitmap rotateAndMirror(Bitmap b, int degrees, boolean mirror) {
if (degrees != 0 && b != null) {
Matrix m = new Matrix();
m.setRotate(degrees,
(float) b.getWidth() / 2, (float) b.getHeight() / 2);
+ if (mirror) {
+ m.postScale(-1, 1);
+ degrees = (degrees + 360) % 360;
+ if (degrees == 0 || degrees == 180) {
+ m.postTranslate((float) b.getWidth(), 0);
+ } else if (degrees == 90 || degrees == 270) {
+ m.postTranslate((float) b.getHeight(), 0);
+ } else {
+ throw new IllegalArgumentException("Invalid degrees=" + degrees);
+ }
+ }
+
try {
Bitmap b2 = Bitmap.createBitmap(
b, 0, 0, b.getWidth(), b.getHeight(), m, true);
diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java
index eae320a..1d17104 100644
--- a/src/com/android/camera/VideoCamera.java
+++ b/src/com/android/camera/VideoCamera.java
@@ -185,6 +185,7 @@ public class VideoCamera extends NoSearchActivity
private int mOrientation = OrientationEventListener.ORIENTATION_UNKNOWN;
// The orientation compensation for icons and thumbnails.
private int mOrientationCompensation = 0;
+ private int mOrientationHint; // the orientation hint for video playback
// This Handler is used to post message back onto the main thread of the
// application
@@ -1005,6 +1006,7 @@ public class VideoCamera extends NoSearchActivity
}
}
mMediaRecorder.setOrientationHint(rotation);
+ mOrientationHint = rotation;
try {
mMediaRecorder.prepare();
@@ -1262,9 +1264,17 @@ public class VideoCamera extends NoSearchActivity
private void showAlert() {
fadeOut(findViewById(R.id.shutter_button));
if (mCurrentVideoFilename != null) {
- mVideoFrame.setImageBitmap(
- ThumbnailUtils.createVideoThumbnail(mCurrentVideoFilename,
- Video.Thumbnails.MINI_KIND));
+ Bitmap src = ThumbnailUtils.createVideoThumbnail(
+ mCurrentVideoFilename, Video.Thumbnails.MINI_KIND);
+ // MetadataRetriever already rotates the thumbnail. We should rotate
+ // it back (and mirror if it is front-facing camera).
+ CameraInfo[] info = CameraHolder.instance().getCameraInfo();
+ if (info[mCameraId].facing == CameraInfo.CAMERA_FACING_BACK) {
+ src = Util.rotateAndMirror(src, -mOrientationHint, false);
+ } else {
+ src = Util.rotateAndMirror(src, -mOrientationHint, true);
+ }
+ mVideoFrame.setImageBitmap(src);
mVideoFrame.setVisibility(View.VISIBLE);
}
int[] pickIds = {R.id.btn_retake, R.id.btn_done, R.id.btn_play};