summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java
diff options
context:
space:
mode:
authornicolasroard <nicolasroard@google.com>2012-10-29 08:53:16 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-10-29 08:53:17 -0700
commit17b9bd8f1baed2f788d179d90b775a9c16087b50 (patch)
treefd9f4349bda54cd80c1e06c6bfdab483844e4651 /src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java
parent7fcf15ec7f1dc20d211c6211bb3a464d12449ffa (diff)
parent180282b9c90e2b387e6c65f1b35bb637c170aacf (diff)
downloadandroid_packages_apps_Snap-17b9bd8f1baed2f788d179d90b775a9c16087b50.tar.gz
android_packages_apps_Snap-17b9bd8f1baed2f788d179d90b775a9c16087b50.tar.bz2
android_packages_apps_Snap-17b9bd8f1baed2f788d179d90b775a9c16087b50.zip
Merge "Fix zooming position" into gb-ub-photos-arches
Diffstat (limited to 'src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java')
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java96
1 files changed, 95 insertions, 1 deletions
diff --git a/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java b/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java
index 24586e718..cf52b15ca 100644
--- a/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java
+++ b/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java
@@ -21,6 +21,7 @@ import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.RectF;
+import com.android.gallery3d.filtershow.cache.ImageLoader;
import com.android.gallery3d.filtershow.filters.ImageFilterGeometry;
public class GeometryMetadata {
@@ -65,7 +66,7 @@ public class GeometryMetadata {
if (!cropBounds.equals(photoBounds)) {
return true;
}
- if (!mFlip.equals(FLIP.NONE)){
+ if (!mFlip.equals(FLIP.NONE)) {
return true;
}
return false;
@@ -239,6 +240,99 @@ public class GeometryMetadata {
}
}
+ public Matrix getMatrixOriginalOrientation(int orientation, float originalWidth,
+ float originalHeight) {
+ Matrix imageRotation = new Matrix();
+ switch (orientation) {
+ case ImageLoader.ORI_ROTATE_90: {
+ imageRotation.setRotate(90, originalWidth / 2f, originalHeight / 2f);
+ imageRotation.postTranslate(-(originalWidth - originalHeight) / 2f,
+ -(originalHeight - originalWidth) / 2f);
+ break;
+ }
+ case ImageLoader.ORI_ROTATE_180: {
+ imageRotation.setRotate(180, originalWidth / 2f, originalHeight / 2f);
+ break;
+ }
+ case ImageLoader.ORI_ROTATE_270: {
+ imageRotation.setRotate(270, originalWidth / 2f, originalHeight / 2f);
+ imageRotation.postTranslate(-(originalWidth - originalHeight) / 2f,
+ -(originalHeight - originalWidth) / 2f);
+ break;
+ }
+ case ImageLoader.ORI_FLIP_HOR: {
+ imageRotation.preScale(-1, 1);
+ break;
+ }
+ case ImageLoader.ORI_FLIP_VERT: {
+ imageRotation.preScale(1, -1);
+ break;
+ }
+ case ImageLoader.ORI_TRANSPOSE: {
+ imageRotation.setRotate(90, originalWidth / 2f, originalHeight / 2f);
+ imageRotation.postTranslate(-(originalWidth - originalHeight) / 2f,
+ -(originalHeight - originalWidth) / 2f);
+ imageRotation.preScale(1, -1);
+ break;
+ }
+ case ImageLoader.ORI_TRANSVERSE: {
+ imageRotation.setRotate(270, originalWidth / 2f, originalHeight / 2f);
+ imageRotation.postTranslate(-(originalWidth - originalHeight) / 2f,
+ -(originalHeight - originalWidth) / 2f);
+ imageRotation.preScale(1, -1);
+ break;
+ }
+ }
+ return imageRotation;
+ }
+
+ public Matrix getOriginalToScreen(boolean rotate, float originalWidth, float originalHeight,
+ float viewWidth, float viewHeight) {
+ RectF photoBounds = getPhotoBounds();
+ RectF cropBounds = getPreviewCropBounds();
+ float imageWidth = cropBounds.width();
+ float imageHeight = cropBounds.height();
+
+ int orientation = ImageLoader.getZoomOrientation();
+ Matrix imageRotation = getMatrixOriginalOrientation(orientation, originalWidth,
+ originalHeight);
+ if (orientation == ImageLoader.ORI_ROTATE_90 ||
+ orientation == ImageLoader.ORI_ROTATE_270 ||
+ orientation == ImageLoader.ORI_TRANSPOSE ||
+ orientation == ImageLoader.ORI_TRANSVERSE) {
+ float tmp = originalWidth;
+ originalWidth = originalHeight;
+ originalHeight = tmp;
+ }
+
+ float preScale = GeometryMath.scale(originalWidth, originalHeight,
+ photoBounds.width(), photoBounds.height());
+ float scale = GeometryMath.scale(imageWidth, imageHeight, viewWidth, viewHeight);
+ // checks if local rotation is an odd multiple of 90.
+ if (((int) (getRotation() / 90)) % 2 != 0) {
+ scale = GeometryMath.scale(imageWidth, imageHeight, viewHeight, viewWidth);
+ }
+ // put in screen coordinates
+ RectF scaledCrop = GeometryMath.scaleRect(cropBounds, scale);
+ RectF scaledPhoto = GeometryMath.scaleRect(photoBounds, scale);
+ float[] displayCenter = {
+ viewWidth / 2f, viewHeight / 2f
+ };
+ Matrix m1 = GeometryMetadata.buildWanderingCropMatrix(scaledPhoto, scaledCrop,
+ getRotation(), getStraightenRotation(), getFlipType(), displayCenter);
+ float[] cropCenter = {
+ scaledCrop.centerX(), scaledCrop.centerY()
+ };
+ m1.mapPoints(cropCenter);
+ GeometryMetadata.concatRecenterMatrix(m1, cropCenter, displayCenter);
+ m1.preRotate(getStraightenRotation(), scaledPhoto.centerX(), scaledPhoto.centerY());
+ m1.preScale(scale, scale);
+ m1.preScale(preScale, preScale);
+ m1.preConcat(imageRotation);
+
+ return m1;
+ }
+
// TODO: refactor away
public Matrix getFlipMatrix(float width, float height) {
FLIP type = getFlipType();