Loading src/com/android/gallery3d/filtershow/imageshow/GeometryMath.java +6 −0 Original line number Diff line number Diff line Loading @@ -93,4 +93,10 @@ public class GeometryMath { return (float) Math.sqrt(a[0] * a[0] + a[1] * a[1]); } public static float scale(float oldWidth, float oldHeight, float newWidth, float newHeight) { if (oldHeight == 0 || oldWidth == 0) return 1; return Math.min(newWidth / oldWidth , newHeight / oldHeight); } } src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java +5 −6 Original line number Diff line number Diff line Loading @@ -105,9 +105,8 @@ public class GeometryMetadata { public RectF getCropBounds(Bitmap bitmap) { float scale = 1.0f; if (mPhotoBounds.width() > 0) { scale = bitmap.getWidth() / mPhotoBounds.width(); } scale = GeometryMath.scale(mPhotoBounds.width(), mPhotoBounds.height(), bitmap.getWidth(), bitmap.getHeight()); return new RectF(mCropBounds.left * scale, mCropBounds.top * scale, mCropBounds.right * scale, mCropBounds.bottom * scale); } Loading Loading @@ -299,8 +298,8 @@ public class GeometryMetadata { /** * Builds a matrix to transform a bitmap of width bmWidth and height * bmHeight so that the region of the bitmap being cropped to is * oriented and centered at displayCenter. * bmHeight so that the region of the bitmap being cropped to is oriented * and centered at displayCenter. * * @param bmWidth * @param bmHeight Loading @@ -311,7 +310,7 @@ public class GeometryMetadata { RectF rp = getPhotoBounds(); RectF rc = getPreviewCropBounds(); float scale = bmWidth / rp.width(); float scale = GeometryMath.scale(rp.width(), rp.height(), bmWidth, bmHeight); RectF scaledCrop = GeometryMath.scaleRect(rc, scale); RectF scaledPhoto = GeometryMath.scaleRect(rp, scale); Loading src/com/android/gallery3d/filtershow/imageshow/ImageGeometry.java +29 −17 Original line number Diff line number Diff line Loading @@ -106,11 +106,7 @@ public abstract class ImageGeometry extends ImageSlave { protected float computeScale(float width, float height) { float imageWidth = mLocalGeometry.getPhotoBounds().width(); float imageHeight = mLocalGeometry.getPhotoBounds().height(); float zoom = width / imageWidth; if (imageHeight > imageWidth) { zoom = height / imageHeight; } return zoom; return GeometryMath.scale(imageWidth, imageHeight, width, height); } private void calculateLocalScalingFactorAndOffset() { Loading Loading @@ -221,7 +217,6 @@ public abstract class ImageGeometry extends ImageSlave { return getLocalRotation() + getLocalStraighten(); } protected static float[] getCornersFromRect(RectF r) { // Order is: // 0------->1 Loading Loading @@ -406,7 +401,12 @@ public abstract class ImageGeometry extends ImageSlave { } protected Matrix getGeoMatrix(RectF r, boolean onlyRotate) { float scale = computeScale(getWidth(), getHeight()); RectF pbounds = getLocalPhotoBounds(); float scale = GeometryMath .scale(pbounds.width(), pbounds.height(), getWidth(), getHeight()); if (((int) (getLocalRotation() / 90)) % 2 != 0) { scale = GeometryMath.scale(pbounds.width(), pbounds.height(), getHeight(), getWidth()); } float yoff = getHeight() / 2; float xoff = getWidth() / 2; float w = r.left * 2 + r.width(); Loading Loading @@ -449,7 +449,8 @@ public abstract class ImageGeometry extends ImageSlave { float scale = computeScale(getWidth(), getHeight()); float yoff = getHeight() / 2; float xoff = getWidth() / 2; Matrix m = mLocalGeometry.buildGeometryMatrix(pbounds.width(), pbounds.height(), scale, xoff, yoff, 0); Matrix m = mLocalGeometry.buildGeometryMatrix(pbounds.width(), pbounds.height(), scale, xoff, yoff, 0); m.mapRect(bounds); return bounds; } Loading Loading @@ -549,10 +550,16 @@ public abstract class ImageGeometry extends ImageSlave { RectF photoBounds = getLocalPhotoBounds(); RectF cropBounds = getLocalCropBounds(); float scale = computeScale(getWidth(), getHeight()); // checks if local rotation is an odd multiple of 90. if (((int) (getLocalRotation() / 90)) % 2 != 0) { scale = computeScale(getHeight(), getWidth()); } // put in screen coordinates RectF scaledCrop = GeometryMath.scaleRect(cropBounds, scale); RectF scaledPhoto = GeometryMath.scaleRect(photoBounds, scale); float [] displayCenter = { getWidth() / 2f, getHeight() / 2f }; float[] displayCenter = { getWidth() / 2f, getHeight() / 2f }; Matrix m = GeometryMetadata.buildCenteredPhotoMatrix(scaledPhoto, scaledCrop, getLocalRotation(), getLocalStraighten(), getLocalFlip(), displayCenter); Loading @@ -579,17 +586,22 @@ public abstract class ImageGeometry extends ImageSlave { RectF cropBounds = getLocalCropBounds(); float imageWidth = cropBounds.width(); float imageHeight = cropBounds.height(); float scale = getWidth() / imageWidth; if (imageHeight > imageWidth) { scale = getHeight() / imageHeight; float scale = GeometryMath.scale(imageWidth, imageHeight, getWidth(), getHeight()); // checks if local rotation is an odd multiple of 90. if (((int) (getLocalRotation() / 90)) % 2 != 0) { scale = GeometryMath.scale(imageWidth, imageHeight, getHeight(), getWidth()); } // put in screen coordinates RectF scaledCrop = GeometryMath.scaleRect(cropBounds, scale); RectF scaledPhoto = GeometryMath.scaleRect(photoBounds, scale); float [] displayCenter = { getWidth() / 2f, getHeight() / 2f }; float[] displayCenter = { getWidth() / 2f, getHeight() / 2f }; Matrix m1 = GeometryMetadata.buildWanderingCropMatrix(scaledPhoto, scaledCrop, getLocalRotation(), getLocalStraighten(), getLocalFlip(), displayCenter); float [] cropCenter = { scaledCrop.centerX(), scaledCrop.centerY() }; float[] cropCenter = { scaledCrop.centerX(), scaledCrop.centerY() }; m1.mapPoints(cropCenter); GeometryMetadata.concatRecenterMatrix(m1, cropCenter, displayCenter); m1.preRotate(getLocalStraighten(), scaledPhoto.centerX(), scaledPhoto.centerY()); Loading src/com/android/gallery3d/filtershow/imageshow/ImageShow.java +9 −12 Original line number Diff line number Diff line Loading @@ -467,18 +467,15 @@ public class ImageShow extends View implements OnGestureListener, if (image != null) { Rect s = new Rect(0, 0, image.getWidth(), image.getHeight()); float ratio = image.getWidth() / (float) image.getHeight(); float w = getWidth(); float h = w / ratio; float scale = GeometryMath.scale(image.getWidth(), image.getHeight(), getWidth(), getHeight()); float w = image.getWidth() * scale; float h = image.getHeight() * scale; float ty = (getHeight() - h) / 2.0f; float tx = 0; if (ratio < 1.0f || (getHeight() < w)) { h = getHeight(); w = h * ratio; tx = (getWidth() - w) / 2.0f; ty = 0; } float tx = (getWidth() - w) / 2.0f; Rect d = new Rect((int) tx, (int) ty, (int) (w + tx), (int) (h + ty)); mImageBounds = d; Loading Loading
src/com/android/gallery3d/filtershow/imageshow/GeometryMath.java +6 −0 Original line number Diff line number Diff line Loading @@ -93,4 +93,10 @@ public class GeometryMath { return (float) Math.sqrt(a[0] * a[0] + a[1] * a[1]); } public static float scale(float oldWidth, float oldHeight, float newWidth, float newHeight) { if (oldHeight == 0 || oldWidth == 0) return 1; return Math.min(newWidth / oldWidth , newHeight / oldHeight); } }
src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java +5 −6 Original line number Diff line number Diff line Loading @@ -105,9 +105,8 @@ public class GeometryMetadata { public RectF getCropBounds(Bitmap bitmap) { float scale = 1.0f; if (mPhotoBounds.width() > 0) { scale = bitmap.getWidth() / mPhotoBounds.width(); } scale = GeometryMath.scale(mPhotoBounds.width(), mPhotoBounds.height(), bitmap.getWidth(), bitmap.getHeight()); return new RectF(mCropBounds.left * scale, mCropBounds.top * scale, mCropBounds.right * scale, mCropBounds.bottom * scale); } Loading Loading @@ -299,8 +298,8 @@ public class GeometryMetadata { /** * Builds a matrix to transform a bitmap of width bmWidth and height * bmHeight so that the region of the bitmap being cropped to is * oriented and centered at displayCenter. * bmHeight so that the region of the bitmap being cropped to is oriented * and centered at displayCenter. * * @param bmWidth * @param bmHeight Loading @@ -311,7 +310,7 @@ public class GeometryMetadata { RectF rp = getPhotoBounds(); RectF rc = getPreviewCropBounds(); float scale = bmWidth / rp.width(); float scale = GeometryMath.scale(rp.width(), rp.height(), bmWidth, bmHeight); RectF scaledCrop = GeometryMath.scaleRect(rc, scale); RectF scaledPhoto = GeometryMath.scaleRect(rp, scale); Loading
src/com/android/gallery3d/filtershow/imageshow/ImageGeometry.java +29 −17 Original line number Diff line number Diff line Loading @@ -106,11 +106,7 @@ public abstract class ImageGeometry extends ImageSlave { protected float computeScale(float width, float height) { float imageWidth = mLocalGeometry.getPhotoBounds().width(); float imageHeight = mLocalGeometry.getPhotoBounds().height(); float zoom = width / imageWidth; if (imageHeight > imageWidth) { zoom = height / imageHeight; } return zoom; return GeometryMath.scale(imageWidth, imageHeight, width, height); } private void calculateLocalScalingFactorAndOffset() { Loading Loading @@ -221,7 +217,6 @@ public abstract class ImageGeometry extends ImageSlave { return getLocalRotation() + getLocalStraighten(); } protected static float[] getCornersFromRect(RectF r) { // Order is: // 0------->1 Loading Loading @@ -406,7 +401,12 @@ public abstract class ImageGeometry extends ImageSlave { } protected Matrix getGeoMatrix(RectF r, boolean onlyRotate) { float scale = computeScale(getWidth(), getHeight()); RectF pbounds = getLocalPhotoBounds(); float scale = GeometryMath .scale(pbounds.width(), pbounds.height(), getWidth(), getHeight()); if (((int) (getLocalRotation() / 90)) % 2 != 0) { scale = GeometryMath.scale(pbounds.width(), pbounds.height(), getHeight(), getWidth()); } float yoff = getHeight() / 2; float xoff = getWidth() / 2; float w = r.left * 2 + r.width(); Loading Loading @@ -449,7 +449,8 @@ public abstract class ImageGeometry extends ImageSlave { float scale = computeScale(getWidth(), getHeight()); float yoff = getHeight() / 2; float xoff = getWidth() / 2; Matrix m = mLocalGeometry.buildGeometryMatrix(pbounds.width(), pbounds.height(), scale, xoff, yoff, 0); Matrix m = mLocalGeometry.buildGeometryMatrix(pbounds.width(), pbounds.height(), scale, xoff, yoff, 0); m.mapRect(bounds); return bounds; } Loading Loading @@ -549,10 +550,16 @@ public abstract class ImageGeometry extends ImageSlave { RectF photoBounds = getLocalPhotoBounds(); RectF cropBounds = getLocalCropBounds(); float scale = computeScale(getWidth(), getHeight()); // checks if local rotation is an odd multiple of 90. if (((int) (getLocalRotation() / 90)) % 2 != 0) { scale = computeScale(getHeight(), getWidth()); } // put in screen coordinates RectF scaledCrop = GeometryMath.scaleRect(cropBounds, scale); RectF scaledPhoto = GeometryMath.scaleRect(photoBounds, scale); float [] displayCenter = { getWidth() / 2f, getHeight() / 2f }; float[] displayCenter = { getWidth() / 2f, getHeight() / 2f }; Matrix m = GeometryMetadata.buildCenteredPhotoMatrix(scaledPhoto, scaledCrop, getLocalRotation(), getLocalStraighten(), getLocalFlip(), displayCenter); Loading @@ -579,17 +586,22 @@ public abstract class ImageGeometry extends ImageSlave { RectF cropBounds = getLocalCropBounds(); float imageWidth = cropBounds.width(); float imageHeight = cropBounds.height(); float scale = getWidth() / imageWidth; if (imageHeight > imageWidth) { scale = getHeight() / imageHeight; float scale = GeometryMath.scale(imageWidth, imageHeight, getWidth(), getHeight()); // checks if local rotation is an odd multiple of 90. if (((int) (getLocalRotation() / 90)) % 2 != 0) { scale = GeometryMath.scale(imageWidth, imageHeight, getHeight(), getWidth()); } // put in screen coordinates RectF scaledCrop = GeometryMath.scaleRect(cropBounds, scale); RectF scaledPhoto = GeometryMath.scaleRect(photoBounds, scale); float [] displayCenter = { getWidth() / 2f, getHeight() / 2f }; float[] displayCenter = { getWidth() / 2f, getHeight() / 2f }; Matrix m1 = GeometryMetadata.buildWanderingCropMatrix(scaledPhoto, scaledCrop, getLocalRotation(), getLocalStraighten(), getLocalFlip(), displayCenter); float [] cropCenter = { scaledCrop.centerX(), scaledCrop.centerY() }; float[] cropCenter = { scaledCrop.centerX(), scaledCrop.centerY() }; m1.mapPoints(cropCenter); GeometryMetadata.concatRecenterMatrix(m1, cropCenter, displayCenter); m1.preRotate(getLocalStraighten(), scaledPhoto.centerX(), scaledPhoto.centerY()); Loading
src/com/android/gallery3d/filtershow/imageshow/ImageShow.java +9 −12 Original line number Diff line number Diff line Loading @@ -467,18 +467,15 @@ public class ImageShow extends View implements OnGestureListener, if (image != null) { Rect s = new Rect(0, 0, image.getWidth(), image.getHeight()); float ratio = image.getWidth() / (float) image.getHeight(); float w = getWidth(); float h = w / ratio; float scale = GeometryMath.scale(image.getWidth(), image.getHeight(), getWidth(), getHeight()); float w = image.getWidth() * scale; float h = image.getHeight() * scale; float ty = (getHeight() - h) / 2.0f; float tx = 0; if (ratio < 1.0f || (getHeight() < w)) { h = getHeight(); w = h * ratio; tx = (getWidth() - w) / 2.0f; ty = 0; } float tx = (getWidth() - w) / 2.0f; Rect d = new Rect((int) tx, (int) ty, (int) (w + tx), (int) (h + ty)); mImageBounds = d; Loading