OSDN Git Service

Bugfixes to image filters.
authorMarius Renn <renn@google.com>
Fri, 1 Jul 2011 23:20:02 +0000 (16:20 -0700)
committerMarius Renn <renn@google.com>
Fri, 1 Jul 2011 23:20:02 +0000 (16:20 -0700)
Change-Id: I03e124132bdbfbf5aac0ad527c6d9e89fb6130e3

mca/filterfw/java/android/filterfw/core/Filter.java
mca/filterpacks/imageproc/java/FisheyeFilter.java
mca/filterpacks/imageproc/java/ImageCombineFilter.java
mca/filterpacks/imageproc/java/SimpleImageFilter.java
mca/filterpacks/imageproc/java/ToGrayFilter.java

index 87187c9..a11fa25 100644 (file)
@@ -239,6 +239,14 @@ public abstract class Filter {
     }
 
     /**
+     * Transfers any frame from an input port to its destination. This is useful to force a
+     * transfer from a FieldPort or ProgramPort to its connected target (field or program variable).
+     */
+    protected void transferInputPortFrame(String name, FilterContext context) {
+        getInputPort(name).transfer(context);
+    }
+
+    /**
      * Adds an input port to the filter. You should call this from within setupPorts, if your
      * filter has input ports. No type-checking is performed on the input. If you would like to
      * check against a type mask, use
index a313c6b..4d53145 100644 (file)
@@ -103,13 +103,13 @@ public class FisheyeFilter extends SimpleImageFilter {
     }
 
     @Override
-    public void process(FilterContext env) {
+    public void process(FilterContext context) {
         // Get input frame
         Frame input = pullInput("image");
 
         // Create output frame
         // TODO: Use Frame Provider
-        Frame output = env.getFrameManager().newFrame(input.getFormat());
+        Frame output = context.getFrameManager().newFrame(input.getFormat());
 
         Log.e("Fisheye", "width: " + input.getFormat().getWidth() +
               ", height: " + input.getFormat().getHeight());
@@ -122,7 +122,7 @@ public class FisheyeFilter extends SimpleImageFilter {
         Log.e("Fisheye", "( " + center[0] + ", " + center[1] + " )");
 
         // Make sure we have a program
-        updateProgramWithTarget(input.getFormat().getTarget());
+        updateProgramWithTarget(input.getFormat().getTarget(), context);
 
         // set uniforms in shader
         mProgram.setHostValue("center", center);
index a202a4f..a9294f6 100644 (file)
@@ -97,7 +97,7 @@ public abstract class ImageCombineFilter extends Filter {
         Frame output = context.getFrameManager().newFrame(inputs[0].getFormat());
 
         // Make sure we have a program
-        updateProgramWithTarget(inputs[0].getFormat().getTarget());
+        updateProgramWithTarget(inputs[0].getFormat().getTarget(), context);
 
         // Process
         mProgram.process(inputs, output);
@@ -109,7 +109,7 @@ public abstract class ImageCombineFilter extends Filter {
         output.release();
     }
 
-    protected void updateProgramWithTarget(int target) {
+    protected void updateProgramWithTarget(int target, FilterContext context) {
         if (target != mCurrentTarget) {
             switch (target) {
                 case FrameFormat.TARGET_NATIVE:
@@ -128,6 +128,7 @@ public abstract class ImageCombineFilter extends Filter {
                 throw new RuntimeException("Could not create a program for image filter "
                     + this + "!");
             }
+            transferInputPortFrame(mParameterName, context);
             mCurrentTarget = target;
         }
     }
index c612b0a..30c78fa 100644 (file)
@@ -75,7 +75,7 @@ public abstract class SimpleImageFilter extends Filter {
         Frame output = context.getFrameManager().newFrame(inputFormat);
 
         // Create program if not created already
-        updateProgramWithTarget(inputFormat.getTarget());
+        updateProgramWithTarget(inputFormat.getTarget(), context);
 
         // Process
         mProgram.process(input, output);
@@ -87,7 +87,7 @@ public abstract class SimpleImageFilter extends Filter {
         output.release();
     }
 
-    protected void updateProgramWithTarget(int target) {
+    protected void updateProgramWithTarget(int target, FilterContext context) {
         if (target != mCurrentTarget) {
             switch (target) {
                 case FrameFormat.TARGET_NATIVE:
@@ -105,6 +105,7 @@ public abstract class SimpleImageFilter extends Filter {
             if (mProgram == null) {
                 throw new RuntimeException("Could not create a program for image filter " + this + "!");
             }
+            transferInputPortFrame(mParameterName, context);
             mCurrentTarget = target;
         }
     }
index dc3323f..74c7f85 100644 (file)
@@ -102,17 +102,17 @@ public class ToGrayFilter extends SimpleImageFilter {
     }
 
     @Override
-    public void process(FilterContext env) {
+    public void process(FilterContext context) {
         // Get input frame
         Frame input = pullInput("image");
 
         // Create output frame
         MutableFrameFormat outputFormat = input.getFormat().mutableCopy();
         outputFormat.setBytesPerSample(mOutChannels);
-        Frame output = env.getFrameManager().newFrame(outputFormat);
+        Frame output = context.getFrameManager().newFrame(outputFormat);
 
         // Make sure we have a program
-        updateProgramWithTarget(input.getFormat().getTarget());
+        updateProgramWithTarget(input.getFormat().getTarget(), context);
 
         // Process
         mProgram.process(input, output);