X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fcom%2Fandroid%2Fgallery3d%2Ffiltershow%2Fpipeline%2FFilterEnvironment.java;h=0b84f5203a90de9e4b9a82870cd9b2f6a12451b0;hb=c5a49d22a4b4f94eead77fe5f2d14095c12500e8;hp=f97dc757ad0a9aded16c82467c1c18397424f137;hpb=ce9ceff5776a9b0479c30cbeb2a9388b44df1865;p=android-x86%2Fpackages-apps-Gallery2.git diff --git a/src/com/android/gallery3d/filtershow/pipeline/FilterEnvironment.java b/src/com/android/gallery3d/filtershow/pipeline/FilterEnvironment.java index f97dc757a..0b84f5203 100644 --- a/src/com/android/gallery3d/filtershow/pipeline/FilterEnvironment.java +++ b/src/com/android/gallery3d/filtershow/pipeline/FilterEnvironment.java @@ -17,9 +17,13 @@ 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; @@ -34,6 +38,7 @@ public class FilterEnvironment { 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; @@ -47,40 +52,27 @@ public class FilterEnvironment { this.mStop = stop; } - private HashMap> - bitmapCach = new HashMap>(); - private HashMap generalParameters = new HashMap(); + 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)); + mBitmapCache.cache(buffer); } - public Bitmap getBitmap(int w, int h) { - Long key = calcKey(w, h); - WeakReference 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) { @@ -128,10 +120,22 @@ public class FilterEnvironment { } 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; @@ -164,4 +168,7 @@ public class FilterEnvironment { generalParameters.put(id, value); } + public BitmapCache getBimapCache() { + return mBitmapCache; + } }