diff options
author | Sascha Haeberling <haeberling@google.com> | 2013-05-07 15:09:54 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-05-07 15:09:54 -0700 |
commit | 77a66b210f6a272ccb3c4c494516de08df6afb76 (patch) | |
tree | 58498d8aa398f7589ebd5d0bf1cd2291b2540bd4 /src/com/android/gallery3d/filtershow/imageshow | |
parent | a133a41f9773d2197a675312b8e6d13fedeabdeb (diff) | |
parent | 59733de14afde5e9c1b34dd72f40837e486e43b4 (diff) | |
download | android_packages_apps_Snap-77a66b210f6a272ccb3c4c494516de08df6afb76.tar.gz android_packages_apps_Snap-77a66b210f6a272ccb3c4c494516de08df6afb76.tar.bz2 android_packages_apps_Snap-77a66b210f6a272ccb3c4c494516de08df6afb76.zip |
am 6febbfc6: Merge "Avoid rounding errors from cropping uncropped images." into gb-ub-photos-bryce
* commit '6febbfc6c9c2d645f22fb200574fe14fa1201046':
Avoid rounding errors from cropping uncropped images.
Diffstat (limited to 'src/com/android/gallery3d/filtershow/imageshow')
-rw-r--r-- | src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java | 30 |
1 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 b0b4c4fe5..77dbd5e7b 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java +++ b/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java @@ -168,8 +168,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() { @@ -403,11 +416,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); @@ -579,4 +603,4 @@ public class GeometryMetadata extends FilterRepresentation { } } } -}
\ No newline at end of file +} |