OSDN Git Service

am 202ad881: am 5842f8e9: am 18027792: Fix problem applying the Fx filter Also adds...
authornicolasroard <nicolasroard@google.com>
Fri, 22 Mar 2013 06:38:56 +0000 (06:38 +0000)
committerAndroid Git Automerger <android-git-automerger@android.com>
Fri, 22 Mar 2013 06:38:56 +0000 (06:38 +0000)
* commit '202ad8819ad5bcab95278997afbc7626e7ccd0f0':
  Fix problem applying the Fx filter Also adds some debug info

src/com/android/gallery3d/filtershow/cache/CachingPipeline.java
src/com/android/gallery3d/filtershow/cache/FilteringPipeline.java
src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java
src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
src/com/android/gallery3d/filtershow/tools/SaveCopyTask.java

index 8d7fcd5..1190ea4 100644 (file)
@@ -46,9 +46,11 @@ public class CachingPipeline {
 
     private volatile GeometryMetadata mPreviousGeometry = null;
     private volatile float mPreviewScaleFactor = 1.0f;
+    private volatile String mName = "";
 
-    public CachingPipeline(FiltersManager filtersManager) {
+    public CachingPipeline(FiltersManager filtersManager, String name) {
         mFiltersManager = filtersManager;
+        mName = name;
     }
 
     public synchronized void reset() {
@@ -72,6 +74,9 @@ public class CachingPipeline {
     }
 
     private synchronized void destroyPixelAllocations() {
+        if (DEBUG) {
+            Log.v(LOGTAG, "destroyPixelAllocations in " + getName());
+        }
         if (mInPixelsAllocation != null) {
             mInPixelsAllocation.destroy();
             mInPixelsAllocation = null;
@@ -215,6 +220,14 @@ public class CachingPipeline {
 
     }
 
+    public synchronized Bitmap renderFinalImage(Bitmap bitmap, ImagePreset preset) {
+        setPresetParameters(preset);
+        mFiltersManager.freeFilterResources(preset);
+        bitmap = preset.applyGeometry(bitmap);
+        bitmap = preset.apply(bitmap);
+        return bitmap;
+    }
+
     public synchronized void compute(TripleBufferBitmap buffer, ImagePreset preset, int type) {
         if (DEBUG) {
             Log.v(LOGTAG, "compute preset " + preset);
@@ -291,14 +304,21 @@ public class CachingPipeline {
             mHeight = bitmap.getHeight();
             needsUpdate = true;
         }
+        if (DEBUG) {
+            Log.v(LOGTAG, "prepareRenderscriptAllocations: " + needsUpdate + " in " + getName());
+        }
         return needsUpdate;
     }
 
-    public Allocation getInPixelsAllocation() {
+    public synchronized Allocation getInPixelsAllocation() {
         return mInPixelsAllocation;
     }
 
-    public Allocation getOutPixelsAllocation() {
+    public synchronized Allocation getOutPixelsAllocation() {
         return mOutPixelsAllocation;
     }
+
+    public String getName() {
+        return mName;
+    }
 }
index 20af215..1ba6e95 100644 (file)
@@ -111,8 +111,8 @@ public class FilteringPipeline implements Handler.Callback {
                 Process.THREAD_PRIORITY_FOREGROUND);
         mHandlerThread.start();
         mProcessingHandler = new Handler(mHandlerThread.getLooper(), this);
-        mAccessoryPipeline = new CachingPipeline(FiltersManager.getManager());
-        mPreviewPipeline = new CachingPipeline(FiltersManager.getPreviewManager());
+        mAccessoryPipeline = new CachingPipeline(FiltersManager.getManager(), "Accessory");
+        mPreviewPipeline = new CachingPipeline(FiltersManager.getPreviewManager(), "Preview");
     }
 
     public synchronized static FilteringPipeline getPipeline() {
index 904a601..68e8a7c 100644 (file)
@@ -57,10 +57,15 @@ public class ImageFilterFx extends ImageFilter {
         int w = bitmap.getWidth();
         int h = bitmap.getHeight();
 
-        if (mFxBitmap == null || mFxBitmapId != getParameters().getBitmapResource()) {
+        int bitmapResourceId = getParameters().getBitmapResource();
+        if (bitmapResourceId == 0) { // null filter fx
+            return bitmap;
+        }
+
+        if (mFxBitmap == null || mFxBitmapId != bitmapResourceId) {
             BitmapFactory.Options o = new BitmapFactory.Options();
             o.inScaled = false;
-            mFxBitmapId = getParameters().getBitmapResource();
+            mFxBitmapId = bitmapResourceId;
             if (mFxBitmapId != 0) {
                 mFxBitmap = BitmapFactory.decodeResource(mResources, mFxBitmapId, o);
             } else {
index b91051d..56e848a 100644 (file)
@@ -27,6 +27,7 @@ import com.android.gallery3d.filtershow.cache.CachingPipeline;
 
 public abstract class ImageFilterRS extends ImageFilter {
     private static final String LOGTAG = "ImageFilterRS";
+    private boolean DEBUG = false;
 
     private static volatile RenderScript sRS = null;
     private static volatile Resources sResources = null;
@@ -66,6 +67,9 @@ public abstract class ImageFilterRS extends ImageFilter {
                     return bitmap;
                 }
                 CachingPipeline pipeline = getEnvironment().getCachingPipeline();
+                if (DEBUG) {
+                    Log.v(LOGTAG, "apply filter " + getName() + " in pipeline " + pipeline.getName());
+                }
                 boolean needsUpdate = pipeline.prepareRenderscriptAllocations(bitmap);
                 if (needsUpdate || !isResourcesLoaded()) {
                     // the allocations changed size
@@ -75,6 +79,9 @@ public abstract class ImageFilterRS extends ImageFilter {
                 }
                 runFilter();
                 update(bitmap);
+                if (DEBUG) {
+                    Log.v(LOGTAG, "DONE apply filter " + getName() + " in pipeline " + pipeline.getName());
+                }
             }
         } catch (android.renderscript.RSIllegalArgumentException e) {
             Log.e(LOGTAG, "Illegal argument? " + e);
index aa7e700..35c1553 100644 (file)
@@ -31,7 +31,9 @@ import android.util.Log;
 
 import com.android.gallery3d.common.Utils;
 import com.android.gallery3d.exif.ExifInterface;
+import com.android.gallery3d.filtershow.cache.CachingPipeline;
 import com.android.gallery3d.filtershow.cache.ImageLoader;
+import com.android.gallery3d.filtershow.filters.FiltersManager;
 import com.android.gallery3d.filtershow.presets.ImagePreset;
 import com.android.gallery3d.util.XmpUtilHelper;
 
@@ -182,9 +184,8 @@ public class SaveCopyTask extends AsyncTask<ImagePreset, Void, Uri> {
                 if (bitmap == null) {
                     return null;
                 }
-                preset.setupEnvironment();
-                bitmap = preset.applyGeometry(bitmap);
-                bitmap = preset.apply(bitmap);
+                CachingPipeline pipeline = new CachingPipeline(FiltersManager.getManager(), "Saving");
+                bitmap = pipeline.renderFinalImage(bitmap, preset);
 
                 Object xmp = getPanoramaXMPData(sourceUri, preset);
                 ExifInterface exif = getExifData(sourceUri);