summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java')
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java
index c2a7b7bfd..5404cd149 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java
@@ -16,15 +16,27 @@
package com.android.gallery3d.filtershow.filters;
+import android.content.res.Resources;
import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import com.android.gallery3d.app.Log;
public class ImageFilterFx extends ImageFilter {
- private static final String TAG = "ImageFilterFx";
+ private static final String LOGTAG = "ImageFilterFx";
private FilterFxRepresentation mParameters = null;
+ private Bitmap mFxBitmap = null;
+ private Resources mResources = null;
+ private int mFxBitmapId = -1;
public ImageFilterFx() {
}
+ @Override
+ public void freeResources() {
+ if (mFxBitmap != null) mFxBitmap.recycle();
+ mFxBitmap = null;
+ }
+
public void useRepresentation(FilterRepresentation representation) {
FilterFxRepresentation parameters = (FilterFxRepresentation) representation;
mParameters = parameters;
@@ -38,17 +50,32 @@ public class ImageFilterFx extends ImageFilter {
@Override
public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- if (getParameters() == null || getParameters().getFxBitmap() ==null) {
+ if (getParameters() == null || mResources == null) {
return bitmap;
}
int w = bitmap.getWidth();
int h = bitmap.getHeight();
- int fxw = getParameters().getFxBitmap().getWidth();
- int fxh = getParameters().getFxBitmap().getHeight();
+ if (mFxBitmap == null || mFxBitmapId != getParameters().getBitmapResource()) {
+ BitmapFactory.Options o = new BitmapFactory.Options();
+ o.inScaled = false;
+ mFxBitmapId = getParameters().getBitmapResource();
+ mFxBitmap = BitmapFactory.decodeResource(mResources, mFxBitmapId, o);
+ }
+
+ if (mFxBitmap == null) {
+ return bitmap;
+ }
+
+ int fxw = mFxBitmap.getWidth();
+ int fxh = mFxBitmap.getHeight();
- nativeApplyFilter(bitmap, w, h, getParameters().getFxBitmap(), fxw, fxh);
+ nativeApplyFilter(bitmap, w, h, mFxBitmap, fxw, fxh);
return bitmap;
}
+
+ public void setResources(Resources resources) {
+ mResources = resources;
+ }
}