summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow/filters
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/gallery3d/filtershow/filters')
-rw-r--r--src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java24
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java71
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterMirrorRepresentation.java33
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterRotateRepresentation.java27
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterStraightenRepresentation.java16
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilter.java12
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterGeometry.java117
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterStraighten.java89
8 files changed, 116 insertions, 273 deletions
diff --git a/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java b/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java
index 2205b4dbb..4708abb24 100644
--- a/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java
+++ b/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java
@@ -20,7 +20,10 @@ import android.content.res.Resources;
import android.util.Log;
import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.imageshow.GeometryMetadata;
+import com.android.gallery3d.filtershow.editors.EditorCrop;
+import com.android.gallery3d.filtershow.editors.EditorMirror;
+import com.android.gallery3d.filtershow.editors.EditorRotate;
+import com.android.gallery3d.filtershow.editors.EditorStraighten;
import com.android.gallery3d.filtershow.pipeline.ImagePreset;
import java.util.ArrayList;
@@ -138,7 +141,6 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface {
filters.add(ImageFilterFx.class);
filters.add(ImageFilterBorder.class);
filters.add(ImageFilterParametricBorder.class);
- filters.add(ImageFilterGeometry.class);
}
public ArrayList<FilterRepresentation> getLooks() {
@@ -238,8 +240,13 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface {
}
public void addTools(Context context) {
- GeometryMetadata geo = new GeometryMetadata();
- int[] editorsId = geo.getEditorIds();
+
+ int[] editorsId = {
+ EditorCrop.ID,
+ EditorStraighten.ID,
+ EditorRotate.ID,
+ EditorMirror.ID
+ };
int[] textId = {
R.string.crop,
@@ -255,9 +262,16 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface {
R.drawable.filtershow_button_geometry_flip
};
+ FilterRepresentation[] geometryFilters = {
+ new FilterCropRepresentation(),
+ new FilterStraightenRepresentation(),
+ new FilterRotateRepresentation(),
+ new FilterMirrorRepresentation()
+ };
+
for (int i = 0; i < editorsId.length; i++) {
int editorId = editorsId[i];
- GeometryMetadata geometry = new GeometryMetadata(geo);
+ FilterRepresentation geometry = geometryFilters[i];
geometry.setEditorId(editorId);
geometry.setTextId(textId[i]);
geometry.setOverlayId(overlayId[i]);
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java
index fea8b2139..c1bd7b3bb 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java
@@ -28,14 +28,13 @@ import java.io.IOException;
public class FilterCropRepresentation extends FilterRepresentation {
public static final String SERIALIZATION_NAME = "CROP";
public static final String[] BOUNDS = {
- "C0", "C1", "C2", "C3", "I0", "I1", "I2", "I3"
+ "C0", "C1", "C2", "C3"
};
private static final String TAG = FilterCropRepresentation.class.getSimpleName();
- RectF mCrop = new RectF();
- RectF mImage = new RectF();
+ RectF mCrop = getNil();
- public FilterCropRepresentation(RectF crop, RectF image) {
+ public FilterCropRepresentation(RectF crop) {
super(FilterCropRepresentation.class.getSimpleName());
setSerializationName(SERIALIZATION_NAME);
setShowParameterValue(true);
@@ -44,20 +43,18 @@ public class FilterCropRepresentation extends FilterRepresentation {
setTextId(R.string.crop);
setEditorId(EditorCrop.ID);
setCrop(crop);
- setImage(image);
}
public FilterCropRepresentation(FilterCropRepresentation m) {
- this(m.getCrop(), m.getImage());
+ this(m.mCrop);
}
public FilterCropRepresentation() {
- this(new RectF(), new RectF());
+ this(sNilRect);
}
public void set(FilterCropRepresentation r) {
mCrop.set(r.mCrop);
- mImage.set(r.mImage);
}
@Override
@@ -69,11 +66,7 @@ public class FilterCropRepresentation extends FilterRepresentation {
if (mCrop.bottom != crop.mCrop.bottom
|| mCrop.left != crop.mCrop.left
|| mCrop.right != crop.mCrop.right
- || mCrop.top != crop.mCrop.top
- || mImage.bottom != crop.mImage.bottom
- || mImage.left != crop.mImage.left
- || mImage.right != crop.mImage.right
- || mImage.top != crop.mImage.top) {
+ || mCrop.top != crop.mCrop.top) {
return false;
}
return true;
@@ -94,19 +87,26 @@ public class FilterCropRepresentation extends FilterRepresentation {
mCrop.set(crop);
}
- public RectF getImage() {
- return new RectF(mImage);
+ /**
+ * Takes a crop rect contained by [0, 0, 1, 1] and scales it by the height
+ * and width of the image rect.
+ */
+ public static void findScaledCrop(RectF crop, int bitmapWidth, int bitmapHeight) {
+ crop.left *= bitmapWidth;
+ crop.top *= bitmapHeight;
+ crop.right *= bitmapWidth;
+ crop.bottom *= bitmapHeight;
}
- public void getImage(RectF r) {
- r.set(mImage);
- }
-
- public void setImage(RectF image) {
- if (image == null) {
- throw new IllegalArgumentException("Argument to setImage is null");
- }
- mImage.set(image);
+ /**
+ * Takes crop rect and normalizes it by scaling down by the height and width
+ * of the image rect.
+ */
+ public static void findNormalizedCrop(RectF crop, int bitmapWidth, int bitmapHeight) {
+ crop.left /= bitmapWidth;
+ crop.top /= bitmapHeight;
+ crop.right /= bitmapWidth;
+ crop.bottom /= bitmapHeight;
}
@Override
@@ -115,7 +115,7 @@ public class FilterCropRepresentation extends FilterRepresentation {
}
@Override
- public FilterRepresentation copy(){
+ public FilterRepresentation copy() {
return new FilterCropRepresentation(this);
}
@@ -134,12 +134,17 @@ public class FilterCropRepresentation extends FilterRepresentation {
throw new IllegalArgumentException("calling useParametersFrom with incompatible types!");
}
setCrop(((FilterCropRepresentation) a).mCrop);
- setImage(((FilterCropRepresentation) a).mImage);
}
+ private static final RectF sNilRect = new RectF(0, 0, 1, 1);
+
@Override
public boolean isNil() {
- return mCrop.equals(mImage);
+ return mCrop.equals(sNilRect);
+ }
+
+ public static RectF getNil() {
+ return new RectF(sNilRect);
}
@Override
@@ -149,10 +154,6 @@ public class FilterCropRepresentation extends FilterRepresentation {
writer.name(BOUNDS[1]).value(mCrop.top);
writer.name(BOUNDS[2]).value(mCrop.right);
writer.name(BOUNDS[3]).value(mCrop.bottom);
- writer.name(BOUNDS[4]).value(mImage.left);
- writer.name(BOUNDS[5]).value(mImage.top);
- writer.name(BOUNDS[6]).value(mImage.right);
- writer.name(BOUNDS[7]).value(mImage.bottom);
writer.endObject();
}
@@ -169,14 +170,6 @@ public class FilterCropRepresentation extends FilterRepresentation {
mCrop.right = (float) reader.nextDouble();
} else if (BOUNDS[3].equals(name)) {
mCrop.bottom = (float) reader.nextDouble();
- } else if (BOUNDS[4].equals(name)) {
- mImage.left = (float) reader.nextDouble();
- } else if (BOUNDS[5].equals(name)) {
- mImage.top = (float) reader.nextDouble();
- } else if (BOUNDS[6].equals(name)) {
- mImage.right = (float) reader.nextDouble();
- } else if (BOUNDS[7].equals(name)) {
- mImage.bottom = (float) reader.nextDouble();
} else {
reader.skipValue();
}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterMirrorRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterMirrorRepresentation.java
index 22a15f27e..8dcff0d16 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterMirrorRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterMirrorRepresentation.java
@@ -21,7 +21,7 @@ import android.util.JsonWriter;
import android.util.Log;
import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.EditorFlip;
+import com.android.gallery3d.filtershow.editors.EditorMirror;
import java.io.IOException;
@@ -30,7 +30,7 @@ public class FilterMirrorRepresentation extends FilterRepresentation {
private static final String SERIALIZATION_MIRROR_VALUE = "value";
private static final String TAG = FilterMirrorRepresentation.class.getSimpleName();
- Mirror mMirror = Mirror.NONE;
+ Mirror mMirror;
public enum Mirror {
NONE('N'), VERTICAL('V'), HORIZONTAL('H'), BOTH('B');
@@ -67,7 +67,7 @@ public class FilterMirrorRepresentation extends FilterRepresentation {
setFilterClass(FilterMirrorRepresentation.class);
setFilterType(FilterRepresentation.TYPE_GEOMETRY);
setTextId(R.string.mirror);
- setEditorId(EditorFlip.ID);
+ setEditorId(EditorMirror.ID);
setMirror(mirror);
}
@@ -76,7 +76,7 @@ public class FilterMirrorRepresentation extends FilterRepresentation {
}
public FilterMirrorRepresentation() {
- this(Mirror.NONE);
+ this(getNil());
}
@Override
@@ -85,7 +85,7 @@ public class FilterMirrorRepresentation extends FilterRepresentation {
return false;
}
FilterMirrorRepresentation mirror = (FilterMirrorRepresentation) rep;
- if (mirror.mMirror.value() != mirror.mMirror.value()) {
+ if (mMirror != mirror.mMirror) {
return false;
}
return true;
@@ -106,6 +106,23 @@ public class FilterMirrorRepresentation extends FilterRepresentation {
mMirror = mirror;
}
+ public void cycle() {
+ switch (mMirror) {
+ case NONE:
+ mMirror = Mirror.HORIZONTAL;
+ break;
+ case HORIZONTAL:
+ mMirror = Mirror.VERTICAL;
+ break;
+ case VERTICAL:
+ mMirror = Mirror.BOTH;
+ break;
+ case BOTH:
+ mMirror = Mirror.NONE;
+ break;
+ }
+ }
+
@Override
public boolean allowsSingleInstanceOnly() {
return true;
@@ -135,7 +152,11 @@ public class FilterMirrorRepresentation extends FilterRepresentation {
@Override
public boolean isNil() {
- return mMirror == Mirror.NONE;
+ return mMirror == getNil();
+ }
+
+ public static Mirror getNil() {
+ return Mirror.NONE;
}
@Override
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterRotateRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterRotateRepresentation.java
index d5f3a5b40..eb89de036 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterRotateRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterRotateRepresentation.java
@@ -30,7 +30,7 @@ public class FilterRotateRepresentation extends FilterRepresentation {
public static final String SERIALIZATION_ROTATE_VALUE = "value";
private static final String TAG = FilterRotateRepresentation.class.getSimpleName();
- Rotation mRotation = Rotation.ZERO;
+ Rotation mRotation;
public enum Rotation {
ZERO(0), NINETY(90), ONE_EIGHTY(180), TWO_SEVENTY(270);
@@ -76,13 +76,30 @@ public class FilterRotateRepresentation extends FilterRepresentation {
}
public FilterRotateRepresentation() {
- this(Rotation.ZERO);
+ this(getNil());
}
public Rotation getRotation() {
return mRotation;
}
+ public void rotateCW() {
+ switch(mRotation) {
+ case ZERO:
+ mRotation = Rotation.NINETY;
+ break;
+ case NINETY:
+ mRotation = Rotation.ONE_EIGHTY;
+ break;
+ case ONE_EIGHTY:
+ mRotation = Rotation.TWO_SEVENTY;
+ break;
+ case TWO_SEVENTY:
+ mRotation = Rotation.ZERO;
+ break;
+ }
+ }
+
public void set(FilterRotateRepresentation r) {
mRotation = r.mRotation;
}
@@ -123,7 +140,11 @@ public class FilterRotateRepresentation extends FilterRepresentation {
@Override
public boolean isNil() {
- return mRotation == Rotation.ZERO;
+ return mRotation == getNil();
+ }
+
+ public static Rotation getNil() {
+ return Rotation.ZERO;
}
@Override
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterStraightenRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterStraightenRepresentation.java
index 890f1cfd6..94c9497fc 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterStraightenRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterStraightenRepresentation.java
@@ -29,6 +29,8 @@ public class FilterStraightenRepresentation extends FilterRepresentation {
public static final String SERIALIZATION_NAME = "STRAIGHTEN";
public static final String SERIALIZATION_STRAIGHTEN_VALUE = "value";
private static final String TAG = FilterStraightenRepresentation.class.getSimpleName();
+ public static final int MAX_STRAIGHTEN_ANGLE = 45;
+ public static final int MIN_STRAIGHTEN_ANGLE = -45;
float mStraighten;
@@ -48,7 +50,7 @@ public class FilterStraightenRepresentation extends FilterRepresentation {
}
public FilterStraightenRepresentation() {
- this(0);
+ this(getNil());
}
public void set(FilterStraightenRepresentation r) {
@@ -73,7 +75,7 @@ public class FilterStraightenRepresentation extends FilterRepresentation {
public void setStraighten(float straighten) {
if (!rangeCheck(straighten)) {
- straighten = Math.min(Math.max(straighten, -45), 45);
+ straighten = Math.min(Math.max(straighten, MIN_STRAIGHTEN_ANGLE), MAX_STRAIGHTEN_ANGLE);
}
mStraighten = straighten;
}
@@ -107,7 +109,11 @@ public class FilterStraightenRepresentation extends FilterRepresentation {
@Override
public boolean isNil() {
- return mStraighten == 0;
+ return mStraighten == getNil();
+ }
+
+ public static float getNil() {
+ return 0;
}
@Override
@@ -124,7 +130,7 @@ public class FilterStraightenRepresentation extends FilterRepresentation {
while (reader.hasNext()) {
String name = reader.nextName();
if (SERIALIZATION_STRAIGHTEN_VALUE.equals(name)) {
- int s = reader.nextInt();
+ float s = (float) reader.nextDouble();
if (rangeCheck(s)) {
setStraighten(s);
unset = false;
@@ -139,7 +145,7 @@ public class FilterStraightenRepresentation extends FilterRepresentation {
reader.endObject();
}
- private boolean rangeCheck(float s) {
+ private boolean rangeCheck(double s) {
if (s < -45 || s > 45) {
return false;
}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilter.java b/src/com/android/gallery3d/filtershow/filters/ImageFilter.java
index 050dc436b..437137416 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilter.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilter.java
@@ -22,10 +22,9 @@ import android.graphics.Matrix;
import android.support.v8.renderscript.Allocation;
import android.widget.Toast;
-import com.android.gallery3d.filtershow.imageshow.GeometryMetadata;
+import com.android.gallery3d.filtershow.imageshow.GeometryMathUtils;
import com.android.gallery3d.filtershow.imageshow.MasterImage;
import com.android.gallery3d.filtershow.pipeline.FilterEnvironment;
-import com.android.gallery3d.filtershow.pipeline.ImagePreset;
public abstract class ImageFilter implements Cloneable {
private FilterEnvironment mEnvironment = null;
@@ -89,13 +88,8 @@ public abstract class ImageFilter implements Cloneable {
}
protected Matrix getOriginalToScreenMatrix(int w, int h) {
- ImagePreset preset = getEnvironment().getImagePreset();
- GeometryMetadata geo = getEnvironment().getImagePreset().getGeometry();
- Matrix originalToScreen = geo.getOriginalToScreen(true,
- MasterImage.getImage().getOriginalBounds().width(),
- MasterImage.getImage().getOriginalBounds().height(),
- w, h);
- return originalToScreen;
+ return GeometryMathUtils.getImageToScreenMatrix(getEnvironment().getImagePreset()
+ .getGeometryFilters(), true, MasterImage.getImage().getOriginalBounds(), w, h);
}
public void setEnvironment(FilterEnvironment environment) {
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterGeometry.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterGeometry.java
deleted file mode 100644
index 3c323e182..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterGeometry.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-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.crop.CropExtras;
-import com.android.gallery3d.filtershow.imageshow.GeometryMath;
-import com.android.gallery3d.filtershow.imageshow.GeometryMetadata;
-
-public class ImageFilterGeometry extends ImageFilter {
- private final Bitmap.Config mConfig = Bitmap.Config.ARGB_8888;
- private GeometryMetadata mGeometry = null;
- private static final String LOGTAG = "ImageFilterGeometry";
- private static final boolean LOGV = false;
- private static final int BOTH = 3;
- private static final int VERTICAL = 2;
- private static final int HORIZONTAL = 1;
- private static final int NINETY = 1;
- private static final int ONE_EIGHTY = 2;
- private static final int TWO_SEVENTY = 3;
-
- public ImageFilterGeometry() {
- mName = "Geometry";
- }
-
- @Override
- public ImageFilter clone() throws CloneNotSupportedException {
- // FIXME: clone() should not be needed. Remove when we fix geometry.
- ImageFilterGeometry filter = (ImageFilterGeometry) super.clone();
- return filter;
- }
-
- native protected void nativeApplyFilterFlip(Bitmap src, int srcWidth, int srcHeight,
- Bitmap dst, int dstWidth, int dstHeight, int flip);
-
- native protected void nativeApplyFilterRotate(Bitmap src, int srcWidth, int srcHeight,
- Bitmap dst, int dstWidth, int dstHeight, int rotate);
-
- native protected void nativeApplyFilterCrop(Bitmap src, int srcWidth, int srcHeight,
- Bitmap dst, int dstWidth, int dstHeight, int offsetWidth, int offsetHeight);
-
- native protected void nativeApplyFilterStraighten(Bitmap src, int srcWidth, int srcHeight,
- Bitmap dst, int dstWidth, int dstHeight, float straightenAngle);
-
- @Override
- public void useRepresentation(FilterRepresentation representation) {
- mGeometry = (GeometryMetadata) representation;
- }
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- // 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?)
- RectF cb = mGeometry.getPreviewCropBounds();
- RectF pb = mGeometry.getPhotoBounds();
- if (cb.width() == 0 || cb.height() == 0 || pb.width() == 0 || pb.height() == 0) {
- Log.w(LOGTAG, "Cannot apply geometry: geometry metadata has not been initialized");
- return bitmap;
- }
-
- Rect cropBounds = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
- RectF crop = mGeometry.getCropBounds(bitmap);
- if (crop.width() > 0 && crop.height() > 0)
- cropBounds = GeometryMath.roundNearest(crop);
-
- int width = cropBounds.width();
- int height = cropBounds.height();
-
- if (mGeometry.hasSwitchedWidthHeight()){
- int temp = width;
- width = height;
- height = temp;
- }
-
- Bitmap temp = null;
- temp = Bitmap.createBitmap(width, height, mConfig);
-
- float[] displayCenter = {
- temp.getWidth() / 2f, temp.getHeight() / 2f
- };
-
- Matrix m1 = mGeometry.buildTotalXform(bitmap.getWidth(), bitmap.getHeight(), displayCenter);
-
- m1.postScale(1, 1, displayCenter[0], displayCenter[1]);
-
- Canvas canvas = new Canvas(temp);
- Paint paint = new Paint();
- paint.setAntiAlias(true);
- paint.setFilterBitmap(true);
- paint.setDither(true);
- canvas.drawBitmap(bitmap, m1, paint);
- return temp;
- }
-
-}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterStraighten.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterStraighten.java
deleted file mode 100644
index a3bb6f980..000000000
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterStraighten.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.filtershow.filters;
-
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.Rect;
-
-public class ImageFilterStraighten extends ImageFilter {
- private final Bitmap.Config mConfig = Bitmap.Config.ARGB_8888;
- private float mRotation;
- private float mZoomFactor;
-
- public ImageFilterStraighten() {
- mName = "Straighten";
- }
-
- @Override
- public ImageFilter clone() throws CloneNotSupportedException {
- // FIXME: clone() should not be needed. Remove when we fix geometry.
- ImageFilterStraighten filter = (ImageFilterStraighten) super.clone();
- filter.mRotation = mRotation;
- filter.mZoomFactor = mZoomFactor;
- return filter;
- }
-
- public ImageFilterStraighten(float rotation, float zoomFactor) {
- mRotation = rotation;
- mZoomFactor = zoomFactor;
- }
-
- public void setRotation(float rotation) {
- mRotation = rotation;
- }
-
- public void setRotationZoomFactor(float zoomFactor) {
- mZoomFactor = zoomFactor;
- }
-
- @Override
- public void useRepresentation(FilterRepresentation representation) {
-
- }
-
- @Override
- public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- // 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 = bitmap.copy(mConfig, true);
- Canvas canvas = new Canvas(temp);
- canvas.save();
- Rect bounds = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
- float w = temp.getWidth();
- float h = temp.getHeight();
- float mw = temp.getWidth() / 2.0f;
- float mh = temp.getHeight() / 2.0f;
-
- canvas.scale(mZoomFactor, mZoomFactor, mw, mh);
- canvas.rotate(mRotation, mw, mh);
- canvas.drawBitmap(bitmap, bounds, bounds, new Paint());
- canvas.restore();
-
- int[] pixels = new int[(int) (w * h)];
- temp.getPixels(pixels, 0, (int) w, 0, 0, (int) w, (int) h);
- bitmap.setPixels(pixels, 0, (int) w, 0, 0, (int) w, (int) h);
- temp.recycle();
- temp = null;
- pixels = null;
- return bitmap;
- }
-
-}