package com.android.gallery3d.filtershow.pipeline;
import android.graphics.Bitmap;
-import android.support.v8.renderscript.Allocation;
+import android.graphics.Canvas;
+import android.renderscript.Allocation;
+import com.android.gallery3d.app.Log;
+import com.android.gallery3d.filtershow.cache.BitmapCache;
import com.android.gallery3d.filtershow.filters.FilterRepresentation;
+import com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation;
import com.android.gallery3d.filtershow.filters.FiltersManagerInterface;
import com.android.gallery3d.filtershow.filters.ImageFilter;
private FiltersManagerInterface mFiltersManager;
private PipelineInterface mPipeline;
private volatile boolean mStop = false;
+ private BitmapCache mBitmapCache;
public static final int QUALITY_ICON = 0;
public static final int QUALITY_PREVIEW = 1;
this.mStop = stop;
}
- private HashMap<Long, WeakReference<Bitmap>>
- bitmapCach = new HashMap<Long, WeakReference<Bitmap>>();
-
private HashMap<Integer, Integer>
generalParameters = new HashMap<Integer, Integer>();
+ public void setBitmapCache(BitmapCache cache) {
+ mBitmapCache = cache;
+ }
+
public void cache(Buffer buffer) {
- if (buffer == null) {
- return;
- }
- Bitmap bitmap = buffer.getBitmap();
- if (bitmap == null) {
- return;
- }
- Long key = calcKey(bitmap.getWidth(), bitmap.getHeight());
- bitmapCach.put(key, new WeakReference<Bitmap>(bitmap));
+ mBitmapCache.cache(buffer);
}
- public Bitmap getBitmap(int w, int h) {
- Long key = calcKey(w, h);
- WeakReference<Bitmap> ref = bitmapCach.remove(key);
- Bitmap bitmap = null;
- if (ref != null) {
- bitmap = ref.get();
- }
- if (bitmap == null) {
- bitmap = Bitmap.createBitmap(
- w, h, Bitmap.Config.ARGB_8888);
- }
- return bitmap;
+ public void cache(Bitmap bitmap) {
+ mBitmapCache.cache(bitmap);
}
- private Long calcKey(long w, long h) {
- return (w << 32) | (h << 32);
+ public Bitmap getBitmap(int w, int h, int type) {
+ return mBitmapCache.getBitmap(w, h, type);
+ }
+
+ public Bitmap getBitmapCopy(Bitmap source, int type) {
+ return mBitmapCache.getBitmapCopy(source, type);
}
public void setImagePreset(ImagePreset imagePreset) {
}
public Bitmap applyRepresentation(FilterRepresentation representation, Bitmap bitmap) {
+ if (representation instanceof FilterUserPresetRepresentation) {
+ // we allow instances of FilterUserPresetRepresentation in a preset only to know if one
+ // has been applied (so we can show this in the UI). But as all the filters in them are
+ // applied directly they do not themselves need to do any kind of filtering.
+ return bitmap;
+ }
ImageFilter filter = mFiltersManager.getFilterForRepresentation(representation);
+ if (filter == null){
+ Log.e(LOGTAG,"No ImageFilter for "+representation.getSerializationName());
+ }
filter.useRepresentation(representation);
filter.setEnvironment(this);
Bitmap ret = filter.apply(bitmap, mScaleFactor, mQuality);
+ if (bitmap != ret) {
+ cache(bitmap);
+ }
filter.setGeneralParameters();
filter.setEnvironment(null);
return ret;
generalParameters.put(id, value);
}
+ public BitmapCache getBimapCache() {
+ return mBitmapCache;
+ }
}