From bcea53b010546ef1fe948ea7d9667e635496d55e Mon Sep 17 00:00:00 2001 From: nicolasroard Date: Thu, 11 Oct 2012 18:12:09 -0700 Subject: Fixes Rotate, Flip, Straighten tools. bug:7314849 Bug:7224232 Bug:7218935 Change-Id: I418287ff1f81c25f8e089821d823dc29ee62ff0e --- .../gallery3d/filtershow/FilterShowActivity.java | 29 +- .../gallery3d/filtershow/PanelController.java | 3 + .../filtershow/filters/ImageFilterGeometry.java | 134 +++------- .../filtershow/imageshow/GeometryMetadata.java | 89 +++---- .../gallery3d/filtershow/imageshow/ImageCrop.java | 83 +++--- .../gallery3d/filtershow/imageshow/ImageFlip.java | 54 +--- .../filtershow/imageshow/ImageGeometry.java | 295 ++++++++++----------- .../filtershow/imageshow/ImageRotate.java | 57 +--- .../gallery3d/filtershow/imageshow/ImageShow.java | 11 +- .../filtershow/imageshow/ImageSmallFilter.java | 9 +- .../filtershow/imageshow/ImageStraighten.java | 56 +--- .../gallery3d/filtershow/presets/ImagePreset.java | 2 +- 12 files changed, 311 insertions(+), 511 deletions(-) (limited to 'src') diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java index d544e53d3..0dfaf082b 100644 --- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java +++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java @@ -21,10 +21,8 @@ import android.util.TypedValue; import android.view.Display; import android.view.Menu; import android.view.MenuItem; -import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; -import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ImageButton; @@ -51,14 +49,6 @@ import com.android.gallery3d.filtershow.imageshow.ImageSmallFilter; import com.android.gallery3d.filtershow.imageshow.ImageStraighten; import com.android.gallery3d.filtershow.imageshow.ImageZoom; import com.android.gallery3d.filtershow.presets.ImagePreset; -import com.android.gallery3d.filtershow.presets.ImagePresetBW; -import com.android.gallery3d.filtershow.presets.ImagePresetBWBlue; -import com.android.gallery3d.filtershow.presets.ImagePresetBWGreen; -import com.android.gallery3d.filtershow.presets.ImagePresetBWRed; -import com.android.gallery3d.filtershow.presets.ImagePresetFX; -import com.android.gallery3d.filtershow.presets.ImagePresetOld; -import com.android.gallery3d.filtershow.presets.ImagePresetSaturated; -import com.android.gallery3d.filtershow.presets.ImagePresetXProcessing; import com.android.gallery3d.filtershow.provider.SharedImageProvider; import com.android.gallery3d.filtershow.tools.SaveCopyTask; import com.android.gallery3d.filtershow.ui.ImageCurves; @@ -78,7 +68,7 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, private ImageBorder mImageBorders = null; private ImageStraighten mImageStraighten = null; private ImageZoom mImageZoom = null; - private ImageCrop mImageCrop = null; + private final ImageCrop mImageCrop = null; private ImageRotate mImageRotate = null; private ImageFlip mImageFlip = null; @@ -140,7 +130,8 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, mImageBorders = (ImageBorder) findViewById(R.id.imageBorder); mImageStraighten = (ImageStraighten) findViewById(R.id.imageStraighten); mImageZoom = (ImageZoom) findViewById(R.id.imageZoom); - mImageCrop = (ImageCrop) findViewById(R.id.imageCrop); + // TODO: implement crop + // mImageCrop = (ImageCrop) findViewById(R.id.imageCrop); mImageRotate = (ImageRotate) findViewById(R.id.imageRotate); mImageFlip = (ImageFlip) findViewById(R.id.imageFlip); @@ -149,7 +140,8 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, mImageViews.add(mImageBorders); mImageViews.add(mImageStraighten); mImageViews.add(mImageZoom); - mImageViews.add(mImageCrop); + // TODO: implement crop + // mImageViews.add(mImageCrop); mImageViews.add(mImageRotate); mImageViews.add(mImageFlip); @@ -178,8 +170,9 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, mImageStraighten.setMaster(mImageShow); mImageZoom.setImageLoader(mImageLoader); mImageZoom.setMaster(mImageShow); - mImageCrop.setImageLoader(mImageLoader); - mImageCrop.setMaster(mImageShow); + // TODO: implement crop + // mImageCrop.setImageLoader(mImageLoader); + // mImageCrop.setMaster(mImageShow); mImageRotate.setImageLoader(mImageLoader); mImageRotate.setMaster(mImageShow); mImageFlip.setImageLoader(mImageLoader); @@ -189,7 +182,8 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, mPanelController.addImageView(findViewById(R.id.imageCurves)); mPanelController.addImageView(findViewById(R.id.imageBorder)); mPanelController.addImageView(findViewById(R.id.imageStraighten)); - mPanelController.addImageView(findViewById(R.id.imageCrop)); + // TODO: implement crop + // mPanelController.addImageView(findViewById(R.id.imageCrop)); mPanelController.addImageView(findViewById(R.id.imageRotate)); mPanelController.addImageView(findViewById(R.id.imageFlip)); mPanelController.addImageView(findViewById(R.id.imageZoom)); @@ -199,7 +193,8 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, mPanelController.addPanel(mGeometryButton, mListGeometry, 2); mPanelController.addComponent(mGeometryButton, findViewById(R.id.straightenButton)); - mPanelController.addComponent(mGeometryButton, findViewById(R.id.cropButton)); + // TODO: implement crop +// mPanelController.addComponent(mGeometryButton, findViewById(R.id.cropButton)); mPanelController.addComponent(mGeometryButton, findViewById(R.id.rotateButton)); mPanelController.addComponent(mGeometryButton, findViewById(R.id.flipButton)); diff --git a/src/com/android/gallery3d/filtershow/PanelController.java b/src/com/android/gallery3d/filtershow/PanelController.java index 723f1ba45..fe2be563f 100644 --- a/src/com/android/gallery3d/filtershow/PanelController.java +++ b/src/com/android/gallery3d/filtershow/PanelController.java @@ -390,6 +390,8 @@ public class PanelController implements OnClickListener { mUtilityPanel.setEffectName(ename); break; } + /* + // TODO: implement crop case R.id.cropButton: { mCurrentImage = showImageView(R.id.imageCrop); String ename = mCurrentImage.getContext().getString(R.string.crop); @@ -397,6 +399,7 @@ public class PanelController implements OnClickListener { mUtilityPanel.showParameter(false); break; } + */ case R.id.rotateButton: { mCurrentImage = showImageView(R.id.imageRotate); String ename = mCurrentImage.getContext().getString(R.string.rotate); diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterGeometry.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterGeometry.java index 311ae6310..08c09fb8e 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterGeometry.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterGeometry.java @@ -18,14 +18,10 @@ package com.android.gallery3d.filtershow.filters; import android.graphics.Bitmap; import android.graphics.Canvas; +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.imageshow.GeometryMetadata; -import com.android.gallery3d.filtershow.imageshow.GeometryMetadata.FLIP; -import com.android.gallery3d.filtershow.imageshow.ImageGeometry; public class ImageFilterGeometry extends ImageFilter { private final Bitmap.Config mConfig = Bitmap.Config.ARGB_8888; @@ -65,99 +61,45 @@ public class ImageFilterGeometry extends ImageFilter { native protected void nativeApplyFilterStraighten(Bitmap src, int srcWidth, int srcHeight, Bitmap dst, int dstWidth, int dstHeight, float straightenAngle); - @Override - public Bitmap apply(Bitmap originalBitmap, float scaleFactor, boolean highQuality) { - Rect cropBounds = new Rect(); - Rect originalBounds = new Rect(); - FLIP flipType = mGeometry.getFlipType(); - float rAngle = mGeometry.getRotation(); - float sAngle = mGeometry.getStraightenRotation(); - mGeometry.getCropBounds().roundOut(cropBounds); - mGeometry.getPhotoBounds().roundOut(originalBounds); - boolean flip = flipType != FLIP.NONE; - boolean rotate = rAngle != 0; - boolean crop = !cropBounds.equals(originalBounds); - boolean straighten = sAngle != 0; - - int jniFlipType = 0; - switch (flipType) { - case BOTH: - jniFlipType = BOTH; - break; - case VERTICAL: - jniFlipType = VERTICAL; - break; - case HORIZONTAL: - jniFlipType = HORIZONTAL; - break; - default: - jniFlipType = 0; - break; - } - int bmWidth = originalBitmap.getWidth(); - int bmHeight = originalBitmap.getHeight(); - if (!(flip || rotate || crop || straighten)) { - return originalBitmap; - } - if (originalBounds.width() != bmWidth || originalBounds.height() != bmHeight) { - if (LOGV) - Log.v(LOGTAG, "PHOTOBOUNDS WIDTH/HEIGHT NOT SAME AS BITMAP WIDTH/HEIGHT"); - return originalBitmap; - } - Bitmap modBitmap = originalBitmap; - Rect modifiedBounds = new Rect(originalBounds); - if (flip) { - modBitmap = originalBitmap.copy(mConfig, true); - nativeApplyFilterFlip(originalBitmap, bmWidth, bmHeight, modBitmap, - bmWidth, bmHeight, jniFlipType); - } - if (rotate) { - // Fails for non-90 degree rotations - Bitmap modBitmapRotate = null; - rAngle %= 360; - int deg = (int) (rAngle / 90); - deg = -deg; // Make CCW positive - if (deg < 0) - deg += 4; - // Now deg is in [1, 3] as required by native rotate - if (deg == ONE_EIGHTY) { - modBitmapRotate = Bitmap.createBitmap(bmWidth, bmHeight, mConfig); - nativeApplyFilterRotate(modBitmap, bmWidth, bmHeight, modBitmapRotate, - bmWidth, bmHeight, deg); - modifiedBounds = new Rect(0, 0, bmWidth, bmHeight); - } else if (deg == TWO_SEVENTY || deg == NINETY) { - modBitmapRotate = Bitmap.createBitmap(bmHeight, bmWidth, mConfig); - nativeApplyFilterRotate(modBitmap, bmWidth, bmHeight, modBitmapRotate, - bmHeight, bmWidth, deg); - modifiedBounds = new Rect(0, 0, bmHeight, bmWidth); - } - modBitmap = modBitmapRotate; - } - if (straighten) { - Rect straightenBounds = new Rect(); - ImageGeometry.getUntranslatedStraightenCropBounds(new RectF(modifiedBounds), sAngle) - .roundOut(straightenBounds); - Bitmap modBitmapStraighten = Bitmap.createBitmap(straightenBounds.width(), - straightenBounds.height(), mConfig); - nativeApplyFilterStraighten(modBitmap, modifiedBounds.width(), modifiedBounds.height(), - modBitmapStraighten, - straightenBounds.width(), straightenBounds.height(), - mGeometry.getStraightenRotation()); - modifiedBounds = straightenBounds; - modBitmap = modBitmapStraighten; + public Matrix buildMatrix(Bitmap bitmap, boolean rotated) { + Matrix drawMatrix = new Matrix(); + float dx = bitmap.getWidth() / 2.0f; + float dy = bitmap.getHeight() / 2.0f; + + Matrix flipper = mGeometry.getFlipMatrix(bitmap.getWidth(), bitmap.getHeight()); + drawMatrix.postConcat(flipper); + drawMatrix.postTranslate(-dx, -dy); + drawMatrix.postScale(1.0f / mGeometry.getScaleFactor(), 1.0f / mGeometry.getScaleFactor()); + float angle = (mGeometry.getRotation() + mGeometry.getStraightenRotation()); + drawMatrix.postRotate(angle); + if (rotated) { + drawMatrix.postTranslate(dy, dx); + } else { + drawMatrix.postTranslate(dx, dy); } - if (crop) { - Bitmap modBitmapCrop = Bitmap.createBitmap(cropBounds.width(), cropBounds.height(), - mConfig); - // Force crop bounds to be within straighten bounds. - if (!modifiedBounds.intersect(cropBounds)) { - return modBitmap; - } - nativeApplyFilterCrop(modBitmap, bmWidth, bmHeight, modBitmapCrop, - cropBounds.width(), cropBounds.height(), cropBounds.left, cropBounds.top); - modBitmap = modBitmapCrop; + return drawMatrix; + } + + @Override + public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) { + // TODO: implement bilinear or bicubic here... for now, just use + // canvas to do a simple implementation... + // TODO: and be more memory efficient! (do it in native?) + + Bitmap temp = null; + float rotation = mGeometry.getRotation(); + boolean rotated = false; + if (rotation == 0 || rotation % 180 == 0) { + temp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), mConfig); + } else { + temp = Bitmap.createBitmap(bitmap.getHeight(), bitmap.getWidth(), mConfig); + rotated = true; } - return modBitmap; + + Matrix drawMatrix = buildMatrix(bitmap, rotated); + Canvas canvas = new Canvas(temp); + canvas.drawBitmap(bitmap, drawMatrix, new Paint()); + return temp; } } diff --git a/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java b/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java index 4f172285d..0eb2e22aa 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java +++ b/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java @@ -17,6 +17,7 @@ package com.android.gallery3d.filtershow.imageshow; import android.graphics.Bitmap; +import android.graphics.Matrix; import android.graphics.RectF; import com.android.gallery3d.filtershow.filters.ImageFilterGeometry; @@ -32,7 +33,7 @@ public class GeometryMetadata { // Applied in order: rotate, crop, scale. // Do not scale saved image (presumably?). private static final ImageFilterGeometry mImageFilter = new ImageFilterGeometry(); - private float mScaleFactor = 0; + private float mScaleFactor = 1.0f; private float mRotation = 0; private float mStraightenRotation = 0; private final RectF mCropBounds = new RectF(); @@ -40,6 +41,10 @@ public class GeometryMetadata { private FLIP mFlip = FLIP.NONE; private boolean mSafe = false; + private Matrix mMatrix = new Matrix(); + + private RectF mBounds = new RectF(); + public enum FLIP { NONE, VERTICAL, HORIZONTAL, BOTH } @@ -54,27 +59,9 @@ public class GeometryMetadata { public Bitmap apply(Bitmap original, float scaleFactor, boolean highQuality){ mImageFilter.setGeometryMetadata(this); Bitmap m = mImageFilter.apply(original, scaleFactor, highQuality); - mPhotoBounds.set(0,0, m.getWidth(), m.getHeight()); - mCropBounds.set(mPhotoBounds); - mScaleFactor = 0; - mRotation = 0; - mStraightenRotation = 0; - mFlip = FLIP.NONE; - mSafe = false; return m; } - public GeometryMetadata(float scale, float rotation, float straighten, RectF cropBounds, - RectF photoBounds, FLIP flipType) { - mScaleFactor = scale; - mRotation = rotation; - mStraightenRotation = straighten; - mCropBounds.set(cropBounds); - mPhotoBounds.set(photoBounds); - mFlip = flipType; - mSafe = cropFitsInPhoto(mCropBounds); - } - // Safe as long as invariant holds. public void set(GeometryMetadata g) { mScaleFactor = g.mScaleFactor; @@ -84,34 +71,8 @@ public class GeometryMetadata { mPhotoBounds.set(g.mPhotoBounds); mFlip = g.mFlip; mSafe = g.mSafe; - } - - public void safeSet(GeometryMetadata g) { - if (g.safe()) { - set(g); - return; - } - - mScaleFactor = g.mScaleFactor; - mRotation = g.mRotation; - mStraightenRotation = g.mStraightenRotation; - mCropBounds.set(g.mCropBounds); - safeSetPhotoBounds(g.mPhotoBounds); - mFlip = g.mFlip; - } - - public void safeSet(float scale, - float rotation, - float straighten, - RectF cropBounds, - RectF photoBounds, - FLIP flipType) { - mScaleFactor = scale; - mStraightenRotation = straighten; - mRotation = rotation; - mCropBounds.set(cropBounds); - safeSetPhotoBounds(photoBounds); - mFlip = flipType; + mMatrix = g.mMatrix; + mBounds = g.mBounds; } public float getScaleFactor() { @@ -236,4 +197,38 @@ public class GeometryMetadata { + ",photoRect=" + mPhotoBounds.toShortString() + "]"; } + protected Matrix getHorizontalMatrix(float width) { + Matrix flipHorizontalMatrix = new Matrix(); + flipHorizontalMatrix.setScale(-1, 1); + flipHorizontalMatrix.postTranslate(width, 0); + return flipHorizontalMatrix; + } + + protected Matrix getVerticalMatrix(float height) { + Matrix flipVerticalMatrix = new Matrix(); + flipVerticalMatrix.setScale(1, -1); + flipVerticalMatrix.postTranslate(0, height); + return flipVerticalMatrix; + } + + public Matrix getFlipMatrix(float width, float height) { + FLIP type = getFlipType(); + if (type == FLIP.HORIZONTAL) { + return getHorizontalMatrix(width); + } else if (type == FLIP.VERTICAL) { + return getVerticalMatrix(height); + } else if (type == FLIP.BOTH) { + Matrix flipper = getVerticalMatrix(height); + flipper.postConcat(getHorizontalMatrix(width)); + return flipper; + } else { + Matrix m = new Matrix(); + m.reset(); // identity + return m; + } + } + + public Matrix getMatrix() { + return mMatrix; + } } diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageCrop.java b/src/com/android/gallery3d/filtershow/imageshow/ImageCrop.java index 836ec82f8..90d36e942 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageCrop.java +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageCrop.java @@ -23,15 +23,12 @@ import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Path; -import android.graphics.PointF; import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.Log; -import android.view.MotionEvent; -import com.android.gallery3d.R; -import com.android.gallery3d.filtershow.presets.ImagePreset; +import com.android.gallery3d.R; public class ImageCrop extends ImageGeometry { private static final boolean LOGV = false; @@ -45,9 +42,9 @@ public class ImageCrop extends ImageGeometry { private static final int TOUCH_TOLERANCE = 30; private static final int SHADOW_ALPHA = 160; - private float mAspectWidth = 4; - private float mAspectHeight = 3; - private boolean mFixAspectRatio = false; // not working yet + private final float mAspectWidth = 4; + private final float mAspectHeight = 3; + private final boolean mFixAspectRatio = false; // not working yet private final Paint borderPaint; @@ -104,6 +101,7 @@ public class ImageCrop extends ImageGeometry { return m; } + @Override protected RectF getCropBoundsDisplayed() { RectF bounds = getLocalCropBounds(); RectF crop = new RectF(bounds); @@ -168,6 +166,11 @@ public class ImageCrop extends ImageGeometry { cbounds.set(cbounds.left, cbounds.top, cbounds.left + newWidth, cbounds.top + newHeight); RectF snappedCrop = findCropBoundForRotatedImg(cbounds, pbounds, getLocalStraighten(), mCenterX - mXOffset, mCenterY - mYOffset); + + RectF straightenBounds = getUntranslatedStraightenCropBounds(getLocalPhotoBounds(), getLocalStraighten()); + snappedCrop.intersect(straightenBounds); + + if (mFixAspectRatio) { // TODO: add aspect ratio stuff fixAspectRatio(snappedCrop, mAspectWidth, mAspectHeight); @@ -259,13 +262,6 @@ public class ImageCrop extends ImageGeometry { } } - private void drawShadow(Canvas canvas, float left, float top, float right, float bottom) { - canvas.save(); - canvas.clipRect(left, top, right, bottom); - canvas.drawARGB(SHADOW_ALPHA, 0, 0, 0); - canvas.restore(); - } - private void drawIndicator(Canvas canvas, Drawable indicator, float centerX, float centerY) { int left = (int) centerX - indicatorSize / 2; int top = (int) centerY - indicatorSize / 2; @@ -299,10 +295,29 @@ public class ImageCrop extends ImageGeometry { @Override protected void gainedVisibility() { setCropBounds(getLocalCropBounds()); + super.gainedVisibility(); } - @Override - protected void lostVisibility() { + protected RectF drawCrop(Canvas canvas, Paint p, RectF cropBounds, float scale, + float rotation, float centerX, float centerY, float offsetX, float offsetY) { + RectF crop = new RectF(cropBounds); + Matrix m = new Matrix(); + m.preTranslate(offsetX, offsetY); + m.mapRect(crop); + + m.setRotate(rotation, centerX, centerY); + if (!m.rectStaysRect()) { + float[] corners = getCornersFromRect(crop); + m.mapPoints(corners); + drawClosedPath(canvas, p, corners); + } else { + RectF crop2 = new RectF(crop); + m.mapRect(crop2); + Path path = new Path(); + path.addRect(crop2, Path.Direction.CCW); + canvas.drawPath(path, p); + } + return crop; } @Override @@ -311,43 +326,27 @@ public class ImageCrop extends ImageGeometry { gPaint.setFilterBitmap(true); gPaint.setDither(true); gPaint.setARGB(255, 255, 255, 255); + drawTransformedBitmap(canvas, image, gPaint, false); - drawRegularFlippedBitmap(canvas, image, gPaint); - - RectF displayRect = getLocalDisplayBounds(); - float dWidth = displayRect.width(); - float dHeight = displayRect.height(); - RectF boundsRect = getCropBoundsDisplayed(); - gPaint.setARGB(128, 0, 0, 0); - gPaint.setStyle(Paint.Style.FILL); - // TODO: move this to style when refactoring - canvas.drawRect(0, 0, dWidth, boundsRect.top, gPaint); - canvas.drawRect(0, boundsRect.bottom, dWidth, dHeight, gPaint); - canvas.drawRect(0, boundsRect.top, boundsRect.left, boundsRect.bottom, - gPaint); - canvas.drawRect(boundsRect.right, boundsRect.top, dWidth, - boundsRect.bottom, gPaint); - - Path path = new Path(); - path.addRect(boundsRect, Path.Direction.CCW); - gPaint.setARGB(255, 255, 255, 255); - gPaint.setStrokeWidth(3); - gPaint.setStyle(Paint.Style.STROKE); + float scale = getLocalScale(); + float rotation = getLocalRotation(); - canvas.drawPath(path, gPaint); + RectF scaledCrop = drawCrop(canvas, gPaint, getLocalCropBounds(), scale, + rotation, mCenterX, mCenterY, mXOffset, + mYOffset); boolean notMoving = movingEdges == 0; if (((movingEdges & MOVE_TOP) != 0) || notMoving) { - drawIndicator(canvas, cropIndicator, boundsRect.centerX(), boundsRect.top); + drawIndicator(canvas, cropIndicator, scaledCrop.centerX(), scaledCrop.top); } if (((movingEdges & MOVE_BOTTOM) != 0) || notMoving) { - drawIndicator(canvas, cropIndicator, boundsRect.centerX(), boundsRect.bottom); + drawIndicator(canvas, cropIndicator, scaledCrop.centerX(), scaledCrop.bottom); } if (((movingEdges & MOVE_LEFT) != 0) || notMoving) { - drawIndicator(canvas, cropIndicator, boundsRect.left, boundsRect.centerY()); + drawIndicator(canvas, cropIndicator, scaledCrop.left, scaledCrop.centerY()); } if (((movingEdges & MOVE_RIGHT) != 0) || notMoving) { - drawIndicator(canvas, cropIndicator, boundsRect.right, boundsRect.centerY()); + drawIndicator(canvas, cropIndicator, scaledCrop.right, scaledCrop.centerY()); } } diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageFlip.java b/src/com/android/gallery3d/filtershow/imageshow/ImageFlip.java index ba01d888a..3408405dc 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageFlip.java +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageFlip.java @@ -19,9 +19,7 @@ package com.android.gallery3d.filtershow.imageshow; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; -import android.graphics.Matrix; import android.graphics.Paint; -import android.graphics.Path; import android.graphics.RectF; import android.util.AttributeSet; @@ -125,55 +123,7 @@ public class ImageFlip extends ImageGeometry { gPaint.setFilterBitmap(true); gPaint.setDither(true); gPaint.setARGB(255, 255, 255, 255); - - FLIP flip = mNextFlip; - canvas.save(); - float zoom = getLocalScale(); - canvas.rotate(getTotalLocalRotation(), mCenterX, mCenterY); - canvas.scale(zoom, zoom, mCenterX, mCenterY); - canvas.translate(mXOffset, mYOffset); - if (flip == FLIP.HORIZONTAL) { - Matrix flipper = getHorizontalMatrix(image.getWidth()); - canvas.drawBitmap(image, flipper, gPaint); - } else if (flip == FLIP.VERTICAL) { - Matrix flipper = getVerticalMatrix(image.getHeight()); - canvas.drawBitmap(image, flipper, gPaint); - } else if (flip == FLIP.BOTH) { - Matrix flipper = getVerticalMatrix(image.getHeight()); - flipper.postConcat(getHorizontalMatrix(image.getWidth())); - canvas.drawBitmap(image, flipper, gPaint); - } else { - canvas.drawBitmap(image, 0, 0, gPaint); - } - canvas.restore(); - - RectF cropBounds = getCropBoundsDisplayed(getLocalCropBounds()); - - Matrix m0 = new Matrix(); - m0.setRotate(getLocalRotation(), mCenterX, mCenterY); - float[] corners = getCornersFromRect(cropBounds); - m0.mapPoints(corners); - gPaint.setARGB(255, 255, 255, 255); - // TODO: pull out style to xml - gPaint.setStrokeWidth(3); - gPaint.setStyle(Paint.Style.STROKE); - drawClosedPath(canvas, gPaint, corners); - - canvas.save(); - canvas.rotate(getLocalRotation(), mCenterX, mCenterY); - RectF displayRect = getLocalDisplayBounds(); - float dWidth = displayRect.width(); - float dHeight = displayRect.height(); - RectF boundsRect = cropBounds; - gPaint.setARGB(128, 0, 0, 0); - gPaint.setStyle(Paint.Style.FILL); - canvas.drawRect(0, 0, dWidth, boundsRect.top, gPaint); - canvas.drawRect(0, boundsRect.bottom, dWidth, dHeight, gPaint); - canvas.drawRect(0, boundsRect.top, boundsRect.left, boundsRect.bottom, - gPaint); - canvas.drawRect(boundsRect.right, boundsRect.top, dWidth, - boundsRect.bottom, gPaint); - canvas.rotate(-getLocalRotation(), mCenterX, mCenterY); - canvas.restore(); + drawTransformedBitmap(canvas, image, gPaint, false); } + } diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageGeometry.java b/src/com/android/gallery3d/filtershow/imageshow/ImageGeometry.java index 606e4770c..98f892e8c 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageGeometry.java +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageGeometry.java @@ -19,8 +19,10 @@ package com.android.gallery3d.filtershow.imageshow; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; +import android.graphics.Paint.Style; import android.graphics.Path; import android.graphics.RectF; import android.util.AttributeSet; @@ -46,6 +48,8 @@ public abstract class ImageGeometry extends ImageSlave { protected float mTouchCenterX; protected float mTouchCenterY; + private Matrix mLocalMatrix = null; + // Local geometry data private GeometryMetadata mLocalGeoMetadata = null; private RectF mLocalDisplayBounds = null; @@ -73,6 +77,16 @@ public abstract class ImageGeometry extends ImageSlave { calculateLocalScalingFactorAndOffset(); } + private float computeScale(float width, float height) { + float imageWidth = mLocalGeoMetadata.getPhotoBounds().width(); + float imageHeight = mLocalGeoMetadata.getPhotoBounds().height(); + float zoom = width / imageWidth; + if (imageHeight > imageWidth) { + zoom = height / imageHeight; + } + return zoom; + } + private void calculateLocalScalingFactorAndOffset() { if (mLocalGeoMetadata == null || mLocalDisplayBounds == null) return; @@ -84,12 +98,10 @@ public abstract class ImageGeometry extends ImageSlave { mCenterX = displayWidth / 2; mCenterY = displayHeight / 2; - float zoom = displayWidth / imageWidth; - if (imageHeight > imageWidth) { - zoom = displayHeight / imageHeight; - } mYOffset = (displayHeight - imageHeight) / 2.0f; mXOffset = (displayWidth - imageWidth) / 2.0f; + + float zoom = computeScale(mLocalDisplayBounds.width(), mLocalDisplayBounds.height()); mLocalGeoMetadata.setScaleFactor(zoom); } @@ -104,14 +116,15 @@ public abstract class ImageGeometry extends ImageSlave { invalidate(); } - private GeometryMetadata getMasterImageGeometryMetadataCopy() { - return getMaster().getGeometry(); - } - // Overwrites local with master protected void syncLocalToMasterGeometry() { - mLocalGeoMetadata = getMasterImageGeometryMetadataCopy(); + mLocalGeoMetadata = getMaster().getGeometry(); calculateLocalScalingFactorAndOffset(); + mLocalMatrix = mLocalGeoMetadata.getMatrix(); + } + + public Matrix getLocalMatrix() { + return mLocalMatrix; } protected RectF getLocalPhotoBounds() { @@ -142,12 +155,31 @@ public abstract class ImageGeometry extends ImageSlave { mLocalGeoMetadata.setScaleFactor(s); } + protected void updateMatrix() { + RectF bounds = getUntranslatedStraightenCropBounds(mLocalGeoMetadata.getPhotoBounds(), + getLocalStraighten()); + float zoom = computeScale(bounds.width(), bounds.height()); + setLocalScale(zoom); + float w = mLocalGeoMetadata.getPhotoBounds().width(); + float h = mLocalGeoMetadata.getPhotoBounds().height(); + float ratio = h / w; + float rcenterx = 0.5f; + float rcentery = 0.5f * ratio; + Matrix flipper = mLocalGeoMetadata.getFlipMatrix(1.0f, ratio); + mLocalMatrix.reset(); + mLocalMatrix.postConcat(flipper); + mLocalMatrix.postRotate(getTotalLocalRotation(), rcenterx, rcentery); + invalidate(); + } + protected void setLocalRotation(float r) { mLocalGeoMetadata.setRotation(r); + updateMatrix(); } protected void setLocalStraighten(float r) { mLocalGeoMetadata.setStraightenRotation(r); + updateMatrix(); } protected void setLocalCropBounds(RectF c) { @@ -160,6 +192,7 @@ public abstract class ImageGeometry extends ImageSlave { protected void setLocalFlip(FLIP flip) { mLocalGeoMetadata.setFlipType(flip); + updateMatrix(); } protected float getTotalLocalRotation() { @@ -172,40 +205,6 @@ public abstract class ImageGeometry extends ImageSlave { return getMaster().mForegroundImage; } - protected static Matrix getHorizontalMatrix(int width) { - Matrix flipHorizontalMatrix = new Matrix(); - flipHorizontalMatrix.setScale(-1, 1); - flipHorizontalMatrix.postTranslate(width, 0); - return flipHorizontalMatrix; - } - - protected static Matrix getVerticalMatrix(int height) { - Matrix flipVerticalMatrix = new Matrix(); - flipVerticalMatrix.setScale(1, -1); - flipVerticalMatrix.postTranslate(0, height); - return flipVerticalMatrix; - } - - protected static Matrix getFlipMatrix(FLIP type, int width, int height) { - if (type == FLIP.HORIZONTAL) { - return getHorizontalMatrix(width); - } else if (type == FLIP.VERTICAL) { - return getVerticalMatrix(height); - } else if (type == FLIP.BOTH) { - Matrix flipper = getVerticalMatrix(height); - flipper.postConcat(getHorizontalMatrix(width)); - return flipper; - } else { - Matrix m = new Matrix(); - m.reset(); // identity - return m; - } - } - - protected static float clamp(float i, float low, float high) { - return Math.max(Math.min(i, high), low); - } - protected static float[] getCornersFromRect(RectF r) { // Order is: // 0------->1 @@ -217,7 +216,8 @@ public abstract class ImageGeometry extends ImageSlave { r.right, r.top, // 1 r.right, r.bottom,// 2 r.left, r.bottom - };// 3 + // 3 + }; return corners; } @@ -310,6 +310,10 @@ public abstract class ImageGeometry extends ImageSlave { return height * w / h; } + protected void logMasterGeo() { + Log.v(LOGTAG, getMaster().getGeometry().toString()); + } + @Override protected void onVisibilityChanged(View changedView, int visibility) { super.onVisibilityChanged(changedView, visibility); @@ -317,9 +321,11 @@ public abstract class ImageGeometry extends ImageSlave { mVisibilityGained = true; syncLocalToMasterGeometry(); gainedVisibility(); + logMasterGeo(); } else { if (mVisibilityGained == true && mHasDrawn == true) { lostVisibility(); + logMasterGeo(); } mVisibilityGained = false; mHasDrawn = false; @@ -328,6 +334,7 @@ public abstract class ImageGeometry extends ImageSlave { protected void gainedVisibility() { // TODO: Override this stub. + updateMatrix(); } protected void lostVisibility() { @@ -349,6 +356,8 @@ public abstract class ImageGeometry extends ImageSlave { case (MotionEvent.ACTION_UP): setActionUp(); saveAndSetPreset(); + Log.v(LOGTAG, "up action"); + logMasterGeo(); break; case (MotionEvent.ACTION_MOVE): setActionMove(event.getX(), event.getY()); @@ -357,7 +366,7 @@ public abstract class ImageGeometry extends ImageSlave { setNoAction(); } if (getPanelController() != null) { - getPanelController().onNewValue((int) getLocalValue()); + getPanelController().onNewValue(getLocalValue()); } invalidate(); return true; @@ -397,115 +406,14 @@ public abstract class ImageGeometry extends ImageSlave { protected void saveAndSetPreset() { ImagePreset copy = new ImagePreset(getImagePreset()); copy.setGeometry(mLocalGeoMetadata); + copy.setHistoryName("Geometry"); + copy.setIsFx(false); setImagePreset(copy); } - @Override - public void updateImage() { - } - - protected void drawRegularFlippedBitmap(Canvas canvas, Bitmap image, Paint p) { - float zoom = getLocalScale(); - canvas.save(); - canvas.rotate(getTotalLocalRotation(), mCenterX, mCenterY); - canvas.scale(zoom, zoom, mCenterX, mCenterY); - canvas.translate(mXOffset, mYOffset); - Matrix flipper = getFlipMatrix(getLocalFlip(), image.getWidth(), image.getHeight()); - canvas.drawBitmap(image, flipper, p); - canvas.restore(); - } - - protected void drawRegularBitmap(Canvas canvas, Bitmap image, Paint p) { - float zoom = getLocalScale(); - canvas.save(); - canvas.rotate(getTotalLocalRotation(), mCenterX, mCenterY); - canvas.scale(zoom, zoom, mCenterX, mCenterY); - canvas.translate(mXOffset, mYOffset); - canvas.drawBitmap(image, 0, 0, p); - canvas.restore(); - } - - protected RectF getCropBoundsDisplayed() { - return getCropBoundsDisplayed(getLocalCropBounds()); - } - - protected RectF getCropBoundsDisplayed(RectF bounds) { - RectF crop = new RectF(bounds); - Matrix m = new Matrix(); - float zoom = getLocalScale(); - m.setScale(zoom, zoom, mCenterX, mCenterY); - m.preTranslate(mXOffset, mYOffset); - m.mapRect(crop); - return crop; - } - - protected static float[] correctAngles(float rotation, float straighten) { - float[] ret = { - rotation, straighten - }; - if (straighten >= MIN_STRAIGHTEN_ANGLE && straighten <= MAX_STRAIGHTEN_ANGLE - && (rotation % 90 == 0)) { - return ret; - } - float remainder = rotation % 90; - float newRot = (int) (rotation / 90); - float tempStraighten = straighten + remainder; - newRot += (int) (tempStraighten / 90); - tempStraighten %= 90; - if (tempStraighten > MAX_STRAIGHTEN_ANGLE) { - tempStraighten -= 90; - newRot += 1; - } else if (tempStraighten < MIN_STRAIGHTEN_ANGLE) { - tempStraighten += 90; - newRot -= 1; - } - ret[0] = newRot * 90; - ret[1] = tempStraighten; - return ret; - } - - protected void correctStraightenRotateAngles() { - float straighten = getLocalStraighten(); - float rotation = getLocalRotation(); - float[] angles = correctAngles(rotation, straighten); - setLocalStraighten(angles[1]); - setLocalRotation(angles[0]); - } - - protected static Matrix getCropRotationMatrix(float rotation) { - Matrix m = new Matrix(); - m.setRotate(rotation); - if (!m.rectStaysRect()) { - return null; - } - return m; - } - - protected RectF getStraightenCropBounds() { - RectF imageRect = getLocalPhotoBounds(); - Matrix m = new Matrix(); - float lRot = getLocalRotation(); - m.setRotate(lRot); - if (!m.rectStaysRect()) { - correctStraightenRotateAngles(); - m.setRotate(getLocalRotation()); - } - RectF crop = getStraightenCropBounds(imageRect, getLocalStraighten()); - setLocalCropBounds(crop); - if (!m.mapRect(crop)) { - return null; - } - return crop; - } - - protected RectF getStraightenCropBounds(RectF imageRect, float straightenAngle) { - RectF boundsRect = getUntranslatedStraightenCropBounds(imageRect, straightenAngle); - RectF nonRotateImage = getLocalPhotoBounds(); - Matrix m1 = new Matrix(); - m1.setTranslate(nonRotateImage.centerX() - boundsRect.centerX(), nonRotateImage.centerY() - - boundsRect.centerY()); - m1.mapRect(boundsRect); - return boundsRect; + // + protected static float clamp(float i, float low, float high) { + return Math.max(Math.min(i, high), low); } public static RectF getUntranslatedStraightenCropBounds(RectF imageRect, float straightenAngle) { @@ -532,9 +440,94 @@ public abstract class ImageGeometry extends ImageSlave { return new RectF(left, top, right, bottom); } + protected static void drawShadows(Canvas canvas, Paint p, RectF innerBounds, RectF outerBounds, + float rotation, float centerX, float centerY) { + canvas.save(); + canvas.rotate(rotation, centerX, centerY); + float dWidth = outerBounds.width(); + float dHeight = outerBounds.height(); + canvas.drawRect(0, 0, dWidth, innerBounds.top, p); + canvas.drawRect(0, innerBounds.bottom, dWidth, dHeight, p); + canvas.drawRect(0, innerBounds.top, innerBounds.left, innerBounds.bottom, + p); + canvas.drawRect(innerBounds.right, innerBounds.top, dWidth, + innerBounds.bottom, p); + canvas.rotate(-rotation, centerX, centerY); + canvas.restore(); + } + + public Matrix computeBoundsMatrix(Bitmap bitmap) { + Matrix boundsMatrix = new Matrix(); + boundsMatrix.setTranslate((getWidth() - bitmap.getWidth()) / 2.0f, + (getHeight() - bitmap.getHeight()) / 2.0f); + boundsMatrix.postRotate(getLocalRotation(), getWidth() / 2.0f, getHeight() / 2.0f); + return boundsMatrix; + } + + public RectF cropBounds(Bitmap bitmap) { + Matrix boundsMatrix = computeBoundsMatrix(bitmap); + RectF bounds = getUntranslatedStraightenCropBounds(getLocalPhotoBounds(), + getLocalStraighten()); + RectF transformedBounds = new RectF(bounds); + boundsMatrix.mapRect(transformedBounds); + return transformedBounds; + } + + protected void drawTransformedBitmap(Canvas canvas, Bitmap bitmap, Paint paint, boolean clip) { + Matrix boundsMatrix = computeBoundsMatrix(bitmap); + RectF bounds = getUntranslatedStraightenCropBounds(getLocalPhotoBounds(), + getLocalStraighten()); + RectF transformedBounds = new RectF(bounds); + boundsMatrix.mapRect(transformedBounds); + + canvas.save(); + Matrix matrix = getLocalMatrix(); + canvas.translate((getWidth() - bitmap.getWidth()) / 2.0f, + (getHeight() - bitmap.getHeight()) / 2.0f); + paint.setARGB(255, 0, 0, 0); + Matrix drawMatrix = new Matrix(); + float w = bitmap.getWidth(); + drawMatrix.preScale(1.0f/w, 1.0f/w); + drawMatrix.postConcat(matrix); + drawMatrix.postScale(w, w); + canvas.drawBitmap(bitmap, drawMatrix, paint); + canvas.restore(); + + canvas.save(); + canvas.setMatrix(boundsMatrix); + paint.setColor(Color.WHITE); + paint.setStyle(Style.STROKE); + paint.setStrokeWidth(2); + canvas.drawRect(bounds, paint); + canvas.restore(); + + if (!clip) { // we display the rest of the bitmap grayed-out + drawShadows(canvas, transformedBounds, new RectF(0, 0, getWidth(), getHeight()), paint); + } + } + + protected RectF getCropBoundsDisplayed() { + return getCropBoundsDisplayed(getLocalCropBounds()); + } + + protected RectF getCropBoundsDisplayed(RectF bounds) { + RectF crop = new RectF(bounds); + Matrix m = new Matrix(); + float zoom = getLocalScale(); + m.setScale(zoom, zoom, mCenterX, mCenterY); + m.preTranslate(mXOffset, mYOffset); + m.mapRect(crop); + return crop; + } + protected void drawShadows(Canvas canvas, RectF innerBounds, RectF outerBounds, Paint p) { float dWidth = outerBounds.width(); float dHeight = outerBounds.height(); + + // TODO: move style to xml + p.setARGB(128, 0, 0, 0); + p.setStyle(Paint.Style.FILL); + canvas.drawRect(0, 0, dWidth, innerBounds.top, p); canvas.drawRect(0, innerBounds.bottom, dWidth, dHeight, p); canvas.drawRect(0, innerBounds.top, innerBounds.left, innerBounds.bottom, diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageRotate.java b/src/com/android/gallery3d/filtershow/imageshow/ImageRotate.java index c0999e3d0..089e11732 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageRotate.java +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageRotate.java @@ -19,12 +19,8 @@ package com.android.gallery3d.filtershow.imageshow; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; -import android.graphics.Matrix; import android.graphics.Paint; -import android.graphics.Path; -import android.graphics.RectF; import android.util.AttributeSet; -import android.util.Log; public class ImageRotate extends ImageGeometry { private static final float MATH_PI = (float) Math.PI; @@ -32,8 +28,7 @@ public class ImageRotate extends ImageGeometry { private float mBaseAngle = 0; private float mAngle = 0; - private RectF mLocalBoundsCopy = null; - private boolean mSnapToNinety = true; + private final boolean mSnapToNinety = true; private static final String LOGTAG = "ImageRotate"; public ImageRotate(Context context, AttributeSet attrs) { @@ -97,21 +92,6 @@ public class ImageRotate extends ImageGeometry { } } - @Override - public void resetParameter() { - super.resetParameter(); - mLocalBoundsCopy = getLocalCropBounds(); - } - - @Override - protected void gainedVisibility() { - mLocalBoundsCopy = getLocalCropBounds(); - } - - @Override - protected void lostVisibility() { - } - @Override protected int getLocalValue() { return (int) getLocalRotation(); @@ -123,39 +103,6 @@ public class ImageRotate extends ImageGeometry { gPaint.setFilterBitmap(true); gPaint.setDither(true); gPaint.setARGB(255, 255, 255, 255); - - drawRegularFlippedBitmap(canvas, image, gPaint); - - RectF cropBounds = getCropBoundsDisplayed(mLocalBoundsCopy); - - Matrix m0 = new Matrix(); - m0.setRotate(getLocalRotation(), mCenterX, mCenterY); - float[] corners = getCornersFromRect(cropBounds); - m0.mapPoints(corners); - - gPaint.setARGB(255, 255, 255, 255); - gPaint.setStrokeWidth(3); - gPaint.setStyle(Paint.Style.STROKE); - drawClosedPath(canvas, gPaint, corners); - - canvas.save(); - canvas.rotate(getLocalRotation(), mCenterX, mCenterY); - RectF displayRect = getLocalDisplayBounds(); - float dWidth = displayRect.width(); - float dHeight = displayRect.height(); - RectF boundsRect = cropBounds; - gPaint.setARGB(128, 0, 0, 0); - // TODO: move style to xml - gPaint.setStyle(Paint.Style.FILL); - canvas.drawRect(0, 0, dWidth, boundsRect.top, gPaint); - canvas.drawRect(0, boundsRect.bottom, dWidth, dHeight, gPaint); - canvas.drawRect(0, boundsRect.top, boundsRect.left, boundsRect.bottom, - gPaint); - canvas.drawRect(boundsRect.right, boundsRect.top, dWidth, - boundsRect.bottom, gPaint); - canvas.rotate(-getLocalRotation(), mCenterX, mCenterY); - canvas.restore(); - + drawTransformedBitmap(canvas, image, gPaint, true); } - } diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java b/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java index aba731293..f4a218472 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java @@ -57,6 +57,7 @@ public class ImageShow extends View implements SliderListener, OnSeekBarChangeLi private boolean mDirtyGeometry = true; private Bitmap mBackgroundImage = null; + // TODO: remove protected here, it should be private protected Bitmap mForegroundImage = null; protected Bitmap mFilteredImage = null; @@ -232,7 +233,7 @@ public class ImageShow extends View implements SliderListener, OnSeekBarChangeLi return mImagePreset; } - public Bitmap getOriginalFrontBitmap() { + protected Bitmap getOriginalFrontBitmap() { if (mImageLoader != null) { return mImageLoader.getOriginalBitmapLarge(); } @@ -393,7 +394,7 @@ public class ImageShow extends View implements SliderListener, OnSeekBarChangeLi } } - protected void setDirtyGeometryFlag() { + private void setDirtyGeometryFlag() { mDirtyGeometry = true; } @@ -410,6 +411,11 @@ public class ImageShow extends View implements SliderListener, OnSeekBarChangeLi return; float w = image.getWidth(); float h = image.getHeight(); + GeometryMetadata geo = getImagePreset().mGeoData; + RectF pb = geo.getPhotoBounds(); + if (w == pb.width() && h == pb.height()) { + return; + } RectF r = new RectF(0, 0, w, h); getImagePreset().mGeoData.setPhotoBounds(r); getImagePreset().mGeoData.setCropBounds(r); @@ -419,6 +425,7 @@ public class ImageShow extends View implements SliderListener, OnSeekBarChangeLi public void updateImage() { mForegroundImage = getOriginalFrontBitmap(); imageSizeChanged(mForegroundImage); // TODO: should change to filtered + setDirtyGeometryFlag(); } public void updateFilteredImage(Bitmap bitmap) { diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageSmallFilter.java b/src/com/android/gallery3d/filtershow/imageshow/ImageSmallFilter.java index 78d877df9..a358e0c9b 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageSmallFilter.java +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageSmallFilter.java @@ -100,7 +100,14 @@ public class ImageSmallFilter extends ImageShow implements View.OnClickListener } @Override - public Bitmap getOriginalFrontBitmap() { + public void updateImage() { + // We don't want to warn listeners here that the image size has changed, because + // we'll be working with the small image... + mForegroundImage = getOriginalFrontBitmap(); + } + + @Override + protected Bitmap getOriginalFrontBitmap() { if (mImageLoader == null) { return null; } diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageStraighten.java b/src/com/android/gallery3d/filtershow/imageshow/ImageStraighten.java index 2b15bf373..a94d6292f 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageStraighten.java +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageStraighten.java @@ -19,14 +19,10 @@ package com.android.gallery3d.filtershow.imageshow; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; -import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Path; import android.graphics.RectF; import android.util.AttributeSet; -import android.view.MotionEvent; - -import com.android.gallery3d.filtershow.presets.ImagePreset; public class ImageStraighten extends ImageGeometry { @@ -78,11 +74,6 @@ public class ImageStraighten extends ImageGeometry { mAngle = Math.min(MAX_STRAIGHTEN_ANGLE, mAngle); } - @Override - protected void gainedVisibility() { - correctStraightenRotateAngles(); - } - @Override protected void lostVisibility() { saveAndSetPreset(); @@ -104,53 +95,24 @@ public class ImageStraighten extends ImageGeometry { @Override protected void drawShape(Canvas canvas, Bitmap image) { - gPaint.setAntiAlias(true); - gPaint.setFilterBitmap(true); - gPaint.setDither(true); - gPaint.setARGB(255, 255, 255, 255); + drawTransformedBitmap(canvas, image, gPaint, false); - // Draw fully rotated image. - drawRegularFlippedBitmap(canvas, image, gPaint); - - // Get cropping frame - RectF boundsRect = getStraightenCropBounds(); - - Matrix m1 = new Matrix(); - float zoom = getLocalScale(); - // Center and scale - m1.setScale(zoom, zoom, mCenterX, mCenterY); - m1.preTranslate(mCenterX - boundsRect.centerX(), mCenterY - boundsRect.centerY()); - m1.mapRect(boundsRect); - RectF displayRect = getLocalDisplayBounds(); - float dWidth = displayRect.width(); - float dHeight = displayRect.height(); - - // Draw shadows - gPaint.setARGB(128, 0, 0, 0); - gPaint.setStyle(Paint.Style.FILL); - - // TODO: move to xml file - canvas.drawRect(0, 0, dWidth, boundsRect.top, gPaint); - canvas.drawRect(0, boundsRect.bottom, dWidth, dHeight, gPaint); - canvas.drawRect(0, boundsRect.top, boundsRect.left, boundsRect.bottom, - gPaint); - canvas.drawRect(boundsRect.right, boundsRect.top, dWidth, - boundsRect.bottom, gPaint); - - // Draw crop frame + // Draw the grid + RectF bounds = cropBounds(image); Path path = new Path(); - path.addRect(boundsRect, Path.Direction.CCW); + path.addRect(bounds, Path.Direction.CCW); gPaint.setARGB(255, 255, 255, 255); gPaint.setStrokeWidth(3); - gPaint.setStyle(Paint.Style.STROKE); - canvas.drawPath(path, gPaint); - gPaint.setStyle(Paint.Style.FILL_AND_STROKE); - // Draw grid + RectF display = getLocalDisplayBounds(); + float dWidth = display.width(); + float dHeight = display.height(); + if (mMode == MODES.MOVE) { canvas.save(); canvas.clipPath(path); + int n = 16; float step = dWidth / n; float p = 0; diff --git a/src/com/android/gallery3d/filtershow/presets/ImagePreset.java b/src/com/android/gallery3d/filtershow/presets/ImagePreset.java index 18aa1fb1d..42dbcb90e 100644 --- a/src/com/android/gallery3d/filtershow/presets/ImagePreset.java +++ b/src/com/android/gallery3d/filtershow/presets/ImagePreset.java @@ -79,7 +79,7 @@ public class ImagePreset { mHistoryName = name; } - private void setHistoryName(String name) { + public void setHistoryName(String name) { mHistoryName = name; } -- cgit v1.2.3