Loading res/values/crop_colors.xml +1 −1 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,6 @@ --> --> <resources> <resources> <color name="crop_shadow_color">#CF000000</color> <color name="crop_shadow_color">#CF000000</color> <color name="crop_shadow_wp_color">#5F000000</color> <color name="crop_shadow_wp_color">#4F000000</color> <color name="crop_wp_markers">#7FFFFFFF</color> <color name="crop_wp_markers">#7FFFFFFF</color> </resources> </resources> res/values/crop_dimens.xml +2 −0 Original line number Original line Diff line number Diff line Loading @@ -18,4 +18,6 @@ <dimen name="shadow_margin">5dp</dimen> <dimen name="shadow_margin">5dp</dimen> <dimen name="crop_min_side">45dp</dimen> <dimen name="crop_min_side">45dp</dimen> <dimen name="crop_touch_tolerance">20dp</dimen> <dimen name="crop_touch_tolerance">20dp</dimen> <dimen name="wp_selector_dash_length">4dp</dimen> <dimen name="wp_selector_off_length">4dp</dimen> </resources> </resources> src/com/android/gallery3d/filtershow/crop/CropActivity.java +37 −9 Original line number Original line Diff line number Diff line Loading @@ -26,7 +26,9 @@ import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; import android.graphics.BitmapFactory; import android.graphics.BitmapRegionDecoder; import android.graphics.BitmapRegionDecoder; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.RectF; import android.net.Uri; import android.net.Uri; Loading Loading @@ -58,6 +60,8 @@ public class CropActivity extends Activity { private CropExtras mCropExtras = null; private CropExtras mCropExtras = null; private LoadBitmapTask mLoadBitmapTask = null; private LoadBitmapTask mLoadBitmapTask = null; private int mOutputX = 0; private int mOutputY = 0; private Bitmap mOriginalBitmap = null; private Bitmap mOriginalBitmap = null; private RectF mOriginalBounds = null; private RectF mOriginalBounds = null; private int mOriginalRotation = 0; private int mOriginalRotation = 0; Loading Loading @@ -194,16 +198,20 @@ public class CropActivity extends Activity { if (mCropExtras != null) { if (mCropExtras != null) { int aspectX = mCropExtras.getAspectX(); int aspectX = mCropExtras.getAspectX(); int aspectY = mCropExtras.getAspectY(); int aspectY = mCropExtras.getAspectY(); int outputX = mCropExtras.getOutputX(); mOutputX = mCropExtras.getOutputX(); int outputY = mCropExtras.getOutputY(); mOutputY = mCropExtras.getOutputY(); if (outputX > 0 && outputY > 0) { if (mOutputX > 0 && mOutputY > 0) { mCropView.applyAspect(outputX, outputY); mCropView.applyAspect(mOutputX, mOutputY); } float spotX = mCropExtras.getSpotlightX(); float spotY = mCropExtras.getSpotlightY(); if (spotX > 0 && spotY > 0) { mCropView.setWallpaperSpotlight(spotX, spotY); } } if (aspectX > 0 && aspectY > 0) { if (aspectX > 0 && aspectY > 0) { mCropView.applyAspect(aspectX, aspectY); mCropView.applyAspect(aspectX, aspectY); } } mCropView.setWallpaperSpotlight(mCropExtras.getSpotlightX(), mCropExtras.getSpotlightY()); } } enableSave(true); enableSave(true); } else { } else { Loading Loading @@ -318,7 +326,7 @@ public class CropActivity extends Activity { final View loading = findViewById(R.id.loading); final View loading = findViewById(R.id.loading); loading.setVisibility(View.VISIBLE); loading.setVisibility(View.VISIBLE); BitmapIOTask ioTask = new BitmapIOTask(sourceUri, destUri, format, flags, cropBounds, BitmapIOTask ioTask = new BitmapIOTask(sourceUri, destUri, format, flags, cropBounds, photoBounds, currentBitmapBounds, rotation); photoBounds, currentBitmapBounds, rotation, mOutputX, mOutputY); ioTask.execute(currentBitmap); ioTask.execute(currentBitmap); } } Loading Loading @@ -349,7 +357,8 @@ public class CropActivity extends Activity { int mRotation = 0; int mRotation = 0; public BitmapIOTask(Uri sourceUri, Uri destUri, String outputFormat, int flags, public BitmapIOTask(Uri sourceUri, Uri destUri, String outputFormat, int flags, RectF cropBounds, RectF photoBounds, RectF originalBitmapBounds, int rotation) { RectF cropBounds, RectF photoBounds, RectF originalBitmapBounds, int rotation, int outputX, int outputY) { mOutputFormat = outputFormat; mOutputFormat = outputFormat; mOutStream = null; mOutStream = null; mOutUri = destUri; mOutUri = destUri; Loading @@ -363,6 +372,8 @@ public class CropActivity extends Activity { mRotation = (rotation < 0) ? -rotation : rotation; mRotation = (rotation < 0) ? -rotation : rotation; mRotation %= 360; mRotation %= 360; mRotation = 90 * (int) (mRotation / 90); // now mRotation is a multiple of 90 mRotation = 90 * (int) (mRotation / 90); // now mRotation is a multiple of 90 mOutputX = outputX; mOutputY = outputY; if ((flags & DO_EXTRA_OUTPUT) != 0) { if ((flags & DO_EXTRA_OUTPUT) != 0) { if (mOutUri == null) { if (mOutUri == null) { Loading Loading @@ -470,7 +481,24 @@ public class CropActivity extends Activity { failure = true; failure = true; return false; return false; } } if (mOutputX > 0 && mOutputY > 0) { Matrix m = new Matrix(); RectF cropRect = new RectF(0, 0, crop.getWidth(), crop.getHeight()); if (mRotation > 0) { if (mRotation > 0) { m.setRotate(mRotation); m.mapRect(cropRect); } RectF returnRect = new RectF(0, 0, mOutputX, mOutputY); m.setRectToRect(cropRect, returnRect, Matrix.ScaleToFit.FILL); m.preRotate(mRotation); Bitmap tmp = Bitmap.createBitmap((int) returnRect.width(), (int) returnRect.height(), Bitmap.Config.ARGB_8888); if (tmp != null) { Canvas c = new Canvas(tmp); c.drawBitmap(crop, m, new Paint()); crop = tmp; } } else if (mRotation > 0) { Matrix m = new Matrix(); Matrix m = new Matrix(); m.setRotate(mRotation); m.setRotate(mRotation); Bitmap tmp = Bitmap.createBitmap(crop, 0, 0, crop.getWidth(), Bitmap tmp = Bitmap.createBitmap(crop, 0, 0, crop.getWidth(), Loading src/com/android/gallery3d/filtershow/crop/CropDrawingUtils.java +4 −0 Original line number Original line Diff line number Diff line Loading @@ -113,7 +113,11 @@ public abstract class CropDrawingUtils { canvas.restore(); canvas.restore(); Path path = new Path(); Path path = new Path(); path.moveTo(r1.left, r1.top); path.moveTo(r1.left, r1.top); path.lineTo(r1.right, r1.top); path.moveTo(r1.left, r1.top); path.lineTo(r1.left, r1.bottom); path.lineTo(r1.left, r1.bottom); path.moveTo(r1.left, r1.bottom); path.lineTo(r1.right, r1.bottom); path.moveTo(r1.right, r1.top); path.moveTo(r1.right, r1.top); path.lineTo(r1.right, r1.bottom); path.lineTo(r1.right, r1.bottom); path.moveTo(r2.left, r2.top); path.moveTo(r2.left, r2.top); Loading src/com/android/gallery3d/filtershow/crop/CropMath.java +11 −0 Original line number Original line Diff line number Diff line Loading @@ -235,6 +235,17 @@ public class CropMath { return bmap.getRowBytes() * bmap.getHeight(); return bmap.getRowBytes() * bmap.getHeight(); } } /** * Constrains rotation to be in [0, 90, 180, 270] rounding down. * @param rotation any rotation value, in degrees * @return integer rotation in [0, 90, 180, 270] */ public static int constrainedRotation(float rotation) { int r = (int) ((rotation % 360) / 90); r = (r < 0) ? (r + 4) : r; return r * 90; } private static float getUnrotated(float[] rotatedRect, float[] center, RectF unrotated) { private static float getUnrotated(float[] rotatedRect, float[] center, RectF unrotated) { float dy = rotatedRect[1] - rotatedRect[3]; float dy = rotatedRect[1] - rotatedRect[3]; float dx = rotatedRect[0] - rotatedRect[2]; float dx = rotatedRect[0] - rotatedRect[2]; Loading Loading
res/values/crop_colors.xml +1 −1 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,6 @@ --> --> <resources> <resources> <color name="crop_shadow_color">#CF000000</color> <color name="crop_shadow_color">#CF000000</color> <color name="crop_shadow_wp_color">#5F000000</color> <color name="crop_shadow_wp_color">#4F000000</color> <color name="crop_wp_markers">#7FFFFFFF</color> <color name="crop_wp_markers">#7FFFFFFF</color> </resources> </resources>
res/values/crop_dimens.xml +2 −0 Original line number Original line Diff line number Diff line Loading @@ -18,4 +18,6 @@ <dimen name="shadow_margin">5dp</dimen> <dimen name="shadow_margin">5dp</dimen> <dimen name="crop_min_side">45dp</dimen> <dimen name="crop_min_side">45dp</dimen> <dimen name="crop_touch_tolerance">20dp</dimen> <dimen name="crop_touch_tolerance">20dp</dimen> <dimen name="wp_selector_dash_length">4dp</dimen> <dimen name="wp_selector_off_length">4dp</dimen> </resources> </resources>
src/com/android/gallery3d/filtershow/crop/CropActivity.java +37 −9 Original line number Original line Diff line number Diff line Loading @@ -26,7 +26,9 @@ import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; import android.graphics.BitmapFactory; import android.graphics.BitmapRegionDecoder; import android.graphics.BitmapRegionDecoder; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.RectF; import android.net.Uri; import android.net.Uri; Loading Loading @@ -58,6 +60,8 @@ public class CropActivity extends Activity { private CropExtras mCropExtras = null; private CropExtras mCropExtras = null; private LoadBitmapTask mLoadBitmapTask = null; private LoadBitmapTask mLoadBitmapTask = null; private int mOutputX = 0; private int mOutputY = 0; private Bitmap mOriginalBitmap = null; private Bitmap mOriginalBitmap = null; private RectF mOriginalBounds = null; private RectF mOriginalBounds = null; private int mOriginalRotation = 0; private int mOriginalRotation = 0; Loading Loading @@ -194,16 +198,20 @@ public class CropActivity extends Activity { if (mCropExtras != null) { if (mCropExtras != null) { int aspectX = mCropExtras.getAspectX(); int aspectX = mCropExtras.getAspectX(); int aspectY = mCropExtras.getAspectY(); int aspectY = mCropExtras.getAspectY(); int outputX = mCropExtras.getOutputX(); mOutputX = mCropExtras.getOutputX(); int outputY = mCropExtras.getOutputY(); mOutputY = mCropExtras.getOutputY(); if (outputX > 0 && outputY > 0) { if (mOutputX > 0 && mOutputY > 0) { mCropView.applyAspect(outputX, outputY); mCropView.applyAspect(mOutputX, mOutputY); } float spotX = mCropExtras.getSpotlightX(); float spotY = mCropExtras.getSpotlightY(); if (spotX > 0 && spotY > 0) { mCropView.setWallpaperSpotlight(spotX, spotY); } } if (aspectX > 0 && aspectY > 0) { if (aspectX > 0 && aspectY > 0) { mCropView.applyAspect(aspectX, aspectY); mCropView.applyAspect(aspectX, aspectY); } } mCropView.setWallpaperSpotlight(mCropExtras.getSpotlightX(), mCropExtras.getSpotlightY()); } } enableSave(true); enableSave(true); } else { } else { Loading Loading @@ -318,7 +326,7 @@ public class CropActivity extends Activity { final View loading = findViewById(R.id.loading); final View loading = findViewById(R.id.loading); loading.setVisibility(View.VISIBLE); loading.setVisibility(View.VISIBLE); BitmapIOTask ioTask = new BitmapIOTask(sourceUri, destUri, format, flags, cropBounds, BitmapIOTask ioTask = new BitmapIOTask(sourceUri, destUri, format, flags, cropBounds, photoBounds, currentBitmapBounds, rotation); photoBounds, currentBitmapBounds, rotation, mOutputX, mOutputY); ioTask.execute(currentBitmap); ioTask.execute(currentBitmap); } } Loading Loading @@ -349,7 +357,8 @@ public class CropActivity extends Activity { int mRotation = 0; int mRotation = 0; public BitmapIOTask(Uri sourceUri, Uri destUri, String outputFormat, int flags, public BitmapIOTask(Uri sourceUri, Uri destUri, String outputFormat, int flags, RectF cropBounds, RectF photoBounds, RectF originalBitmapBounds, int rotation) { RectF cropBounds, RectF photoBounds, RectF originalBitmapBounds, int rotation, int outputX, int outputY) { mOutputFormat = outputFormat; mOutputFormat = outputFormat; mOutStream = null; mOutStream = null; mOutUri = destUri; mOutUri = destUri; Loading @@ -363,6 +372,8 @@ public class CropActivity extends Activity { mRotation = (rotation < 0) ? -rotation : rotation; mRotation = (rotation < 0) ? -rotation : rotation; mRotation %= 360; mRotation %= 360; mRotation = 90 * (int) (mRotation / 90); // now mRotation is a multiple of 90 mRotation = 90 * (int) (mRotation / 90); // now mRotation is a multiple of 90 mOutputX = outputX; mOutputY = outputY; if ((flags & DO_EXTRA_OUTPUT) != 0) { if ((flags & DO_EXTRA_OUTPUT) != 0) { if (mOutUri == null) { if (mOutUri == null) { Loading Loading @@ -470,7 +481,24 @@ public class CropActivity extends Activity { failure = true; failure = true; return false; return false; } } if (mOutputX > 0 && mOutputY > 0) { Matrix m = new Matrix(); RectF cropRect = new RectF(0, 0, crop.getWidth(), crop.getHeight()); if (mRotation > 0) { if (mRotation > 0) { m.setRotate(mRotation); m.mapRect(cropRect); } RectF returnRect = new RectF(0, 0, mOutputX, mOutputY); m.setRectToRect(cropRect, returnRect, Matrix.ScaleToFit.FILL); m.preRotate(mRotation); Bitmap tmp = Bitmap.createBitmap((int) returnRect.width(), (int) returnRect.height(), Bitmap.Config.ARGB_8888); if (tmp != null) { Canvas c = new Canvas(tmp); c.drawBitmap(crop, m, new Paint()); crop = tmp; } } else if (mRotation > 0) { Matrix m = new Matrix(); Matrix m = new Matrix(); m.setRotate(mRotation); m.setRotate(mRotation); Bitmap tmp = Bitmap.createBitmap(crop, 0, 0, crop.getWidth(), Bitmap tmp = Bitmap.createBitmap(crop, 0, 0, crop.getWidth(), Loading
src/com/android/gallery3d/filtershow/crop/CropDrawingUtils.java +4 −0 Original line number Original line Diff line number Diff line Loading @@ -113,7 +113,11 @@ public abstract class CropDrawingUtils { canvas.restore(); canvas.restore(); Path path = new Path(); Path path = new Path(); path.moveTo(r1.left, r1.top); path.moveTo(r1.left, r1.top); path.lineTo(r1.right, r1.top); path.moveTo(r1.left, r1.top); path.lineTo(r1.left, r1.bottom); path.lineTo(r1.left, r1.bottom); path.moveTo(r1.left, r1.bottom); path.lineTo(r1.right, r1.bottom); path.moveTo(r1.right, r1.top); path.moveTo(r1.right, r1.top); path.lineTo(r1.right, r1.bottom); path.lineTo(r1.right, r1.bottom); path.moveTo(r2.left, r2.top); path.moveTo(r2.left, r2.top); Loading
src/com/android/gallery3d/filtershow/crop/CropMath.java +11 −0 Original line number Original line Diff line number Diff line Loading @@ -235,6 +235,17 @@ public class CropMath { return bmap.getRowBytes() * bmap.getHeight(); return bmap.getRowBytes() * bmap.getHeight(); } } /** * Constrains rotation to be in [0, 90, 180, 270] rounding down. * @param rotation any rotation value, in degrees * @return integer rotation in [0, 90, 180, 270] */ public static int constrainedRotation(float rotation) { int r = (int) ((rotation % 360) / 90); r = (r < 0) ? (r + 4) : r; return r * 90; } private static float getUnrotated(float[] rotatedRect, float[] center, RectF unrotated) { private static float getUnrotated(float[] rotatedRect, float[] center, RectF unrotated) { float dy = rotatedRect[1] - rotatedRect[3]; float dy = rotatedRect[1] - rotatedRect[3]; float dx = rotatedRect[0] - rotatedRect[2]; float dx = rotatedRect[0] - rotatedRect[2]; Loading