OSDN Git Service

Fix HDR+ landscape transform
authorDoris Liu <tianliu@google.com>
Sat, 8 Mar 2014 04:00:22 +0000 (20:00 -0800)
committerDoris Liu <tianliu@google.com>
Mon, 10 Mar 2014 18:20:22 +0000 (11:20 -0700)
Some logic in resetting translation overlooked the fact that HDR+ has
rotation baked in the transform matrix because camera2 api requires
that surface texture gets rotated by app for device rotation. As a
result, simply setting the translation to 0 for transform matrix when
there is rotation set on the matrix as well offsets the preview off
the screen.

Bug: 13367662
Change-Id: I0529fe4913b55aebc058c93a901b6689da1208ba

src/com/android/camera/TextureViewHelper.java

index 595fa59..37d0b0d 100644 (file)
@@ -83,7 +83,6 @@ public class TextureViewHelper implements TextureView.SurfaceTextureListener,
     @Override
     public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
                                int oldTop, int oldRight, int oldBottom) {
-        Log.d("SPK", "TextureViewHelper::onLayoutChange()");
         int width = right - left;
         int height = bottom - top;
         if (mWidth != width || mHeight != height) {
@@ -221,7 +220,6 @@ public class TextureViewHelper implements TextureView.SurfaceTextureListener,
                                (int) (rect.width() * mAspectRatio));
         }
 
-        Log.d("SPK", "fitPreviewInRect, old size -> new size: (" + mWidth + ", " + mHeight + ") -> (" + width + ", " + height + ")");
         mWidth = width;
         mHeight = height;
 
@@ -240,8 +238,6 @@ public class TextureViewHelper implements TextureView.SurfaceTextureListener,
             return;
         }
 
-        Log.d("SPK", "updateTransform(), size = (" + mWidth + ", " + mHeight + ")");
-
         Matrix matrix = mPreview.getTransform(null);
         float scaledTextureWidth, scaledTextureHeight;
 
@@ -368,32 +364,21 @@ public class TextureViewHelper implements TextureView.SurfaceTextureListener,
     }
 
     /**
-     * Clears the translation of the matrix.
-     *
-     * @param m The matrix in which the translation will be cleared.
-     */
-    private void clearMatrixTrans(Matrix m) {
-        m.getValues(mMatrixVal);
-        mMatrixVal[Matrix.MTRANS_X] = 0;
-        mMatrixVal[Matrix.MTRANS_Y] = 0;
-        m.setValues(mMatrixVal);
-    }
-
-    /**
      * Updates {@code mUntranslatedMatrix} and {mUntranslatedPreviewArea}.
      */
     private void fitUntranslatedMatrixAndArea(RectF rect) {
         mPreview.getTransform(mUntranslatedMatrix);
-        clearMatrixTrans(mUntranslatedMatrix);
         mUntranslatedPreviewArea.set(0, 0, mPreview.getWidth(), mPreview.getHeight());
         mUntranslatedMatrix.mapRect(mUntranslatedPreviewArea);
 
-        // Fit in the rect.
-        final float wRatio = rect.width() / mUntranslatedPreviewArea.width();
-        final float hRatio = rect.height() / mUntranslatedPreviewArea.height();
-        final float smallerRatio = Math.min(wRatio, hRatio);
-        mUntranslatedMatrix.postScale(smallerRatio, smallerRatio, 0f, 0f);
-        mUntranslatedPreviewArea.set(0, 0, mPreview.getWidth(), mPreview.getHeight());
-        mUntranslatedMatrix.mapRect(mUntranslatedPreviewArea);
+        // Remove translation needed for fitting the rect.
+        RectF mapToRect = new RectF(rect);
+        mapToRect.offsetTo(0, 0);
+
+        // Fit preview in the rect while maintaining the original aspect ratio.
+        Matrix transform = new Matrix();
+        transform.setRectToRect(mUntranslatedPreviewArea, mapToRect, Matrix.ScaleToFit.START);
+        mUntranslatedMatrix.postConcat(transform);
+        transform.mapRect(mUntranslatedPreviewArea);
     }
 }