summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow/imageshow
diff options
context:
space:
mode:
authorJohn Hoford <hoford@google.com>2013-09-03 07:48:29 -0700
committerJohn Hoford <hoford@google.com>2013-09-03 19:19:06 -0700
commitec1f915006e5ec2db8be633b5d3d73e568951da4 (patch)
tree3d50e20d672f0231c34675f776a4c2a54d1dd703 /src/com/android/gallery3d/filtershow/imageshow
parentb95b3e9d5be75687e5f07cc2b245c27074ce4cf9 (diff)
downloadandroid_packages_apps_Gallery2-ec1f915006e5ec2db8be633b5d3d73e568951da4.tar.gz
android_packages_apps_Gallery2-ec1f915006e5ec2db8be633b5d3d73e568951da4.tar.bz2
android_packages_apps_Gallery2-ec1f915006e5ec2db8be633b5d3d73e568951da4.zip
fix crop issues
Change-Id: I885828b041278531fbcbe203d413131ad8f46613
Diffstat (limited to 'src/com/android/gallery3d/filtershow/imageshow')
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/GeometryMathUtils.java14
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ImageCrop.java16
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ImageStraighten.java16
3 files changed, 44 insertions, 2 deletions
diff --git a/src/com/android/gallery3d/filtershow/imageshow/GeometryMathUtils.java b/src/com/android/gallery3d/filtershow/imageshow/GeometryMathUtils.java
index e3cd56db7..e8e8a9824 100644
--- a/src/com/android/gallery3d/filtershow/imageshow/GeometryMathUtils.java
+++ b/src/com/android/gallery3d/filtershow/imageshow/GeometryMathUtils.java
@@ -22,6 +22,7 @@ import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
+import android.util.Log;
import com.android.gallery3d.filtershow.cache.BitmapCache;
import com.android.gallery3d.filtershow.cache.ImageLoader;
@@ -38,6 +39,9 @@ import java.util.Collection;
import java.util.Iterator;
public final class GeometryMathUtils {
+ private static final String TAG = "GeometryMathUtils";
+ public static final float SHOW_SCALE = .9f;
+
private GeometryMathUtils() {};
// Holder class for Geometry data.
@@ -434,7 +438,15 @@ public final class GeometryMathUtils {
public static Matrix getFullGeometryToScreenMatrix(GeometryHolder holder, int bitmapWidth,
int bitmapHeight, int viewWidth, int viewHeight) {
- float scale = GeometryMathUtils.scale(bitmapWidth, bitmapHeight, viewWidth, viewHeight);
+ int bh = bitmapHeight;
+ int bw = bitmapWidth;
+ if (GeometryMathUtils.needsDimensionSwap(holder.rotation)) {
+ bh = bitmapWidth;
+ bw = bitmapHeight;
+ }
+ float scale = GeometryMathUtils.scale(bw, bh, viewWidth, viewHeight);
+ scale *= SHOW_SCALE;
+ float s = Math.min(viewWidth / (float) bitmapWidth, viewHeight / (float) bitmapHeight);
Matrix m = getFullGeometryMatrix(holder, bitmapWidth, bitmapHeight);
m.postScale(scale, scale);
m.postTranslate(viewWidth / 2f, viewHeight / 2f);
diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageCrop.java b/src/com/android/gallery3d/filtershow/imageshow/ImageCrop.java
index e027d01e8..b6e964163 100644
--- a/src/com/android/gallery3d/filtershow/imageshow/ImageCrop.java
+++ b/src/com/android/gallery3d/filtershow/imageshow/ImageCrop.java
@@ -282,6 +282,22 @@ public class ImageCrop extends ImageShow {
// Scale min side and tolerance by display matrix scale factor
mCropObj.setMinInnerSideSize(mDisplayMatrixInverse.mapRadius(mMinSideSize));
mCropObj.setTouchTolerance(mDisplayMatrixInverse.mapRadius(mTouchTolerance));
+ // drive Crop engine to clamp to crop bounds
+ int[] sides = {CropObject.MOVE_TOP,
+ CropObject.MOVE_BOTTOM,
+ CropObject.MOVE_LEFT,
+ CropObject.MOVE_RIGHT};
+ int delta = Math.min(canvas.getWidth(), canvas.getHeight()) / 4;
+ int[] dy = {delta, -delta, 0, 0};
+ int[] dx = {0, 0, delta, -delta};
+
+ for (int i = 0; i < sides.length; i++) {
+ mCropObj.selectEdge(sides[i]);
+
+ mCropObj.moveCurrentSelection(dx[i], dy[i]);
+ mCropObj.moveCurrentSelection(-dx[i], -dy[i]);
+ }
+ mCropObj.selectEdge(CropObject.MOVE_NONE);
}
// Draw actual bitmap
mPaint.reset();
diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageStraighten.java b/src/com/android/gallery3d/filtershow/imageshow/ImageStraighten.java
index a85f58de0..92cdadb8b 100644
--- a/src/com/android/gallery3d/filtershow/imageshow/ImageStraighten.java
+++ b/src/com/android/gallery3d/filtershow/imageshow/ImageStraighten.java
@@ -28,6 +28,7 @@ import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.MotionEvent;
+import com.android.gallery3d.app.Log;
import com.android.gallery3d.filtershow.editors.EditorStraighten;
import com.android.gallery3d.filtershow.filters.FilterCropRepresentation;
import com.android.gallery3d.filtershow.filters.FilterRepresentation;
@@ -175,12 +176,25 @@ public class ImageStraighten extends ImageShow {
private void updateCurrentCrop(Matrix m, GeometryHolder h, RectF tmp, int imageWidth,
int imageHeight, int viewWidth, int viewHeight) {
+ tmp.set(0, 0, imageHeight, imageWidth);
+ m.mapRect(tmp);
+ float top = tmp.top;
+ float bottom = tmp.bottom;
+ float left = tmp.left;
+ float right = tmp.right;
+ m.mapRect(tmp);
+ int iw,ih;
if (GeometryMathUtils.needsDimensionSwap(h.rotation)) {
tmp.set(0, 0, imageHeight, imageWidth);
+ iw = imageHeight;
+ ih = imageWidth;
} else {
tmp.set(0, 0, imageWidth, imageHeight);
+ iw = imageWidth;
+ ih = imageHeight;
}
- float scale = GeometryMathUtils.scale(imageWidth, imageHeight, viewWidth, viewHeight);
+ float scale = GeometryMathUtils.scale(iw, ih, viewWidth, viewHeight);
+ scale *= GeometryMathUtils.SHOW_SCALE;
GeometryMathUtils.scaleRect(tmp, scale);
getUntranslatedStraightenCropBounds(tmp, mAngle);
tmp.offset(viewWidth / 2f - tmp.centerX(), viewHeight / 2f - tmp.centerY());