Merge "SnapdragonCamera: Fix rotation angle when the rear in differ angle" into camera.lnx.1.0-dev.1.0
diff --git a/src/com/android/camera/ui/PanoCaptureProcessView.java b/src/com/android/camera/ui/PanoCaptureProcessView.java
index 95e9a09..ec3c7dd 100644
--- a/src/com/android/camera/ui/PanoCaptureProcessView.java
+++ b/src/com/android/camera/ui/PanoCaptureProcessView.java
@@ -930,16 +930,29 @@
         Canvas canvas = new Canvas(dstBitmap);
         matrix.reset();
         int sensorOrientation = mController.getCameraSensorOrientation();
-        if(mOrientation == 0 || mOrientation == 270) {
-            matrix.postRotate((sensorOrientation + mOrientation + 360) % 360, srcBitmap.getHeight() / 2, srcBitmap.getHeight() / 2);
+        matrix.setScale(ratio, ratio);
+        // See android.hardware.Camera.Parameters.setRotation for documentation.
+        // refer to CameraUtil.java getJpegRotation method
+        float rotationAngle = (sensorOrientation + mOrientation) % 360;
+        if (mOrientation == 0) {
+            if (sensorOrientation == 90) {
+                matrix.postRotate(rotationAngle, dstBitmap.getWidth() / 2,
+                        dstBitmap.getWidth() / 2);
+            } else if (sensorOrientation == 270) {
+                matrix.postRotate(rotationAngle, dstBitmap.getHeight() / 2,
+                        dstBitmap.getHeight() / 2);
+            }
         } else  if (mOrientation == 180){
-            matrix.postRotate((sensorOrientation + mOrientation + 180 + 360) % 360, srcBitmap.getHeight() / 2, srcBitmap.getHeight() / 2);
-            matrix.postRotate(180, srcBitmap.getHeight() / 2, srcBitmap.getWidth() / 2);
-        } else if(mOrientation == 90) {
-            matrix.postRotate((sensorOrientation + mOrientation + 180 + 360) % 360, srcBitmap.getHeight() / 2, srcBitmap.getHeight() / 2);
-            matrix.postRotate(180, srcBitmap.getWidth() / 2, srcBitmap.getHeight() / 2);
+            if (sensorOrientation == 90) {
+                matrix.postRotate(rotationAngle, dstBitmap.getHeight() / 2,
+                        dstBitmap.getHeight() / 2);
+            } else if (sensorOrientation == 270) {
+                matrix.postRotate(rotationAngle, dstBitmap.getWidth() / 2,
+                        dstBitmap.getWidth() / 2);
+            }
+        } else if (mOrientation == 270 || mOrientation == 90) {
+            matrix.postRotate(rotationAngle, dstBitmap.getWidth() / 2, dstBitmap.getHeight() / 2);
         }
-        matrix.postScale(ratio, ratio);
         canvas.drawBitmap(srcBitmap, matrix, null);
     }