diff options
author | Sascha Haeberling <haeberling@google.com> | 2013-05-07 11:04:08 -0700 |
---|---|---|
committer | Sascha Haeberling <haeberling@google.com> | 2013-05-07 11:04:08 -0700 |
commit | 559970b1af0333ead040b68cbcc632072f2e7a76 (patch) | |
tree | d197c5ddc51d4d33231406577737e2d8335e02ff /src/com | |
parent | 93240535cafe2b1a7630f8350963a3d84cbb9937 (diff) | |
download | android_packages_apps_Snap-559970b1af0333ead040b68cbcc632072f2e7a76.tar.gz android_packages_apps_Snap-559970b1af0333ead040b68cbcc632072f2e7a76.tar.bz2 android_packages_apps_Snap-559970b1af0333ead040b68cbcc632072f2e7a76.zip |
Avoid rounding errors from cropping uncropped images.
Bug: 8736111
Also don't treat "none" as a non-modifying filter.
Change-Id: I6478c557dbb68d7eecabb29f062285b83de05cda
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java | 28 | ||||
-rw-r--r-- | src/com/android/gallery3d/filtershow/presets/ImagePreset.java | 2 |
2 files changed, 27 insertions, 3 deletions
diff --git a/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java b/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java index 898fdf021..e5820a8f2 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java +++ b/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java @@ -140,8 +140,21 @@ public class GeometryMetadata extends FilterRepresentation { float scale = 1.0f; scale = GeometryMath.scale(mPhotoBounds.width(), mPhotoBounds.height(), bitmap.getWidth(), bitmap.getHeight()); - return new RectF(mCropBounds.left * scale, mCropBounds.top * scale, + RectF croppedRegion = new RectF(mCropBounds.left * scale, mCropBounds.top * scale, mCropBounds.right * scale, mCropBounds.bottom * scale); + + // If no crop has been applied, make sure to use the exact size values. + // Multiplying using scale will introduce rounding errors that modify + // even un-cropped images. + if (mCropBounds.left == 0 && mCropBounds.right == mPhotoBounds.right) { + croppedRegion.left = 0; + croppedRegion.right = bitmap.getWidth(); + } + if (mCropBounds.top == 0 && mCropBounds.bottom == mPhotoBounds.bottom) { + croppedRegion.top = 0; + croppedRegion.bottom = bitmap.getHeight(); + } + return croppedRegion; } public FLIP getFlipType() { @@ -375,11 +388,22 @@ public class GeometryMetadata extends FilterRepresentation { public Matrix buildTotalXform(float bmWidth, float bmHeight, float[] displayCenter) { RectF rp = getPhotoBounds(); RectF rc = getPreviewCropBounds(); - float scale = GeometryMath.scale(rp.width(), rp.height(), bmWidth, bmHeight); RectF scaledCrop = GeometryMath.scaleRect(rc, scale); RectF scaledPhoto = GeometryMath.scaleRect(rp, scale); + // If no crop has been applied, make sure to use the exact size values. + // Multiplying using scale will introduce rounding errors that modify + // even un-cropped images. + if (rc.left == 0 && rc.right == rp.right) { + scaledCrop.left = scaledPhoto.left = 0; + scaledCrop.right = scaledPhoto.right = bmWidth; + } + if (rc.top == 0 && rc.bottom == rp.bottom) { + scaledCrop.top = scaledPhoto.top = 0; + scaledCrop.bottom = scaledPhoto.bottom = bmHeight; + } + Matrix m1 = GeometryMetadata.buildWanderingCropMatrix(scaledPhoto, scaledCrop, getRotation(), getStraightenRotation(), getFlipType(), displayCenter); diff --git a/src/com/android/gallery3d/filtershow/presets/ImagePreset.java b/src/com/android/gallery3d/filtershow/presets/ImagePreset.java index ed0a72a33..2a7e601ee 100644 --- a/src/com/android/gallery3d/filtershow/presets/ImagePreset.java +++ b/src/com/android/gallery3d/filtershow/presets/ImagePreset.java @@ -194,7 +194,7 @@ public class ImagePreset { } for (int i = 0; i < mFilters.size(); i++) { FilterRepresentation filter = mFilters.elementAt(i); - if (!filter.isNil()) { + if (!filter.isNil() && !filter.getName().equalsIgnoreCase("none")) { return true; } } |