diff options
author | Ruei-sung Lin <rslin@google.com> | 2012-05-02 15:13:42 -0700 |
---|---|---|
committer | Ruei-sung Lin <rslin@google.com> | 2012-05-02 15:16:57 -0700 |
commit | f4b403159f8a89eb2158bbb6c314de3bc90fee73 (patch) | |
tree | 0752567e9c8ea334e18ff3c641eec39a7638d8ee /media | |
parent | 6f28f9ef315e3b5190259a943be91ecfafc69103 (diff) | |
download | frameworks_base-f4b403159f8a89eb2158bbb6c314de3bc90fee73.zip frameworks_base-f4b403159f8a89eb2158bbb6c314de3bc90fee73.tar.gz frameworks_base-f4b403159f8a89eb2158bbb6c314de3bc90fee73.tar.bz2 |
Fix b/5974247
Change-Id: I8c5cf035f195142607875739604d163c7a43e305
Diffstat (limited to 'media')
3 files changed, 15 insertions, 110 deletions
diff --git a/media/mca/filterpacks/java/android/filterpacks/imageproc/BlackWhiteFilter.java b/media/mca/filterpacks/java/android/filterpacks/imageproc/BlackWhiteFilter.java index a1cec01..9e40d37 100644 --- a/media/mca/filterpacks/java/android/filterpacks/imageproc/BlackWhiteFilter.java +++ b/media/mca/filterpacks/java/android/filterpacks/imageproc/BlackWhiteFilter.java @@ -47,20 +47,19 @@ public class BlackWhiteFilter extends Filter { private int mHeight = 0; private int mTarget = FrameFormat.TARGET_UNSPECIFIED; - private Frame mNoiseFrame = null; - private Random mRandom; - private final String mBlackWhiteShader = "precision mediump float;\n" + "uniform sampler2D tex_sampler_0;\n" + - "uniform sampler2D tex_sampler_1;\n" + "uniform float black;\n" + "uniform float scale;\n" + "uniform float stepsize;\n" + "varying vec2 v_texcoord;\n" + + "float rand(vec2 loc) {\n" + + " return fract(sin(dot(loc, vec2(12.9898, 78.233))) * 43758.5453);\n" + + "}\n" + "void main() {\n" + " vec4 color = texture2D(tex_sampler_0, v_texcoord);\n" + - " float dither = texture2D(tex_sampler_1, v_texcoord).r;\n" + + " float dither = rand(v_texcoord);\n" + " vec3 xform = clamp((color.rgb - black) * scale, 0.0, 1.0);\n" + " vec3 temp = clamp((color.rgb + stepsize - black) * scale, 0.0, 1.0);\n" + " vec3 new_color = clamp(xform + (temp - xform) * (dither - 0.5), 0.0, 1.0);\n" + @@ -69,8 +68,6 @@ public class BlackWhiteFilter extends Filter { public BlackWhiteFilter(String name) { super(name); - - mRandom = new Random(); } @Override @@ -84,14 +81,6 @@ public class BlackWhiteFilter extends Filter { return inputFormat; } - @Override - public void tearDown(FilterContext context) { - if (mNoiseFrame != null) { - mNoiseFrame.release(); - mNoiseFrame = null; - } - } - public void initProgram(FilterContext context, int target) { switch (target) { case FrameFormat.TARGET_GPU: @@ -139,33 +128,13 @@ public class BlackWhiteFilter extends Filter { if (inputFormat.getWidth() != mWidth || inputFormat.getHeight() != mHeight) { mWidth = inputFormat.getWidth(); mHeight = inputFormat.getHeight(); - - if (mNoiseFrame != null) { - mNoiseFrame.release(); - } - - int[] buffer = new int[mWidth * mHeight]; - for (int i = 0; i < mWidth * mHeight; ++i) { - buffer[i] = mRandom.nextInt(255); - } - FrameFormat format = ImageFormat.create(mWidth, mHeight, - ImageFormat.COLORSPACE_RGBA, - FrameFormat.TARGET_GPU); - mNoiseFrame = context.getFrameManager().newFrame(format); - mNoiseFrame.setInts(buffer); - } - - if (mNoiseFrame != null && (mNoiseFrame.getFormat().getWidth() != mWidth || - mNoiseFrame.getFormat().getHeight() != mHeight)) { - throw new RuntimeException("Random map and imput image size mismatch!"); } // Create output frame Frame output = context.getFrameManager().newFrame(inputFormat); // Process - Frame[] inputs = {input, mNoiseFrame}; - mProgram.process(inputs, output); + mProgram.process(input, output); // Push output pushOutput("image", output); diff --git a/media/mca/filterpacks/java/android/filterpacks/imageproc/DocumentaryFilter.java b/media/mca/filterpacks/java/android/filterpacks/imageproc/DocumentaryFilter.java index 3c7b846..0144d4e 100644 --- a/media/mca/filterpacks/java/android/filterpacks/imageproc/DocumentaryFilter.java +++ b/media/mca/filterpacks/java/android/filterpacks/imageproc/DocumentaryFilter.java @@ -41,21 +41,20 @@ public class DocumentaryFilter extends Filter { private int mHeight = 0; private int mTarget = FrameFormat.TARGET_UNSPECIFIED; - private Frame mNoiseFrame; - private Random mRandom; - private final String mDocumentaryShader = "precision mediump float;\n" + "uniform sampler2D tex_sampler_0;\n" + - "uniform sampler2D tex_sampler_1;\n" + "uniform float stepsize;\n" + "uniform float inv_max_dist;\n" + "uniform vec2 center;\n" + "varying vec2 v_texcoord;\n" + + "float rand(vec2 loc) {\n" + + " return fract(sin(dot(loc, vec2(12.9898, 78.233))) * 43758.5453);\n" + + "}\n" + "void main() {\n" + // black white " vec4 color = texture2D(tex_sampler_0, v_texcoord);\n" + - " float dither = texture2D(tex_sampler_1, v_texcoord).r;\n" + + " float dither = rand(v_texcoord);\n" + " vec3 xform = clamp(2.0 * color.rgb, 0.0, 1.0);\n" + " vec3 temp = clamp(2.0 * (color.rgb + stepsize), 0.0, 1.0);\n" + " vec3 new_color = clamp(xform + (temp - xform) * (dither - 0.5), 0.0, 1.0);\n" + @@ -70,8 +69,6 @@ public class DocumentaryFilter extends Filter { public DocumentaryFilter(String name) { super(name); - - mRandom = new Random(); } @Override @@ -85,14 +82,6 @@ public class DocumentaryFilter extends Filter { return inputFormat; } - @Override - public void tearDown(FilterContext context) { - if (mNoiseFrame != null) { - mNoiseFrame.release(); - mNoiseFrame = null; - } - } - public void initProgram(FilterContext context, int target) { switch (target) { case FrameFormat.TARGET_GPU: @@ -123,34 +112,14 @@ public class DocumentaryFilter extends Filter { if (inputFormat.getWidth() != mWidth || inputFormat.getHeight() != mHeight) { mWidth = inputFormat.getWidth(); mHeight = inputFormat.getHeight(); - - int[] buffer = new int[mWidth * mHeight]; - for (int i = 0; i < mWidth * mHeight; ++i) { - buffer[i] = mRandom.nextInt(255); - } - FrameFormat format = ImageFormat.create(mWidth, mHeight, - ImageFormat.COLORSPACE_RGBA, - FrameFormat.TARGET_GPU); - if (mNoiseFrame != null) { - mNoiseFrame.release(); - } - mNoiseFrame = context.getFrameManager().newFrame(format); - mNoiseFrame.setInts(buffer); - initParameters(); } - if (mNoiseFrame != null && (mNoiseFrame.getFormat().getWidth() != mWidth || - mNoiseFrame.getFormat().getHeight() != mHeight)) { - throw new RuntimeException("Random map and imput image size mismatch!"); - } - // Create output frame Frame output = context.getFrameManager().newFrame(inputFormat); // Process - Frame[] inputs = {input, mNoiseFrame}; - mProgram.process(inputs, output); + mProgram.process(input, output); // Push output pushOutput("image", output); diff --git a/media/mca/filterpacks/java/android/filterpacks/imageproc/LomoishFilter.java b/media/mca/filterpacks/java/android/filterpacks/imageproc/LomoishFilter.java index 452a833..0814ba5 100644 --- a/media/mca/filterpacks/java/android/filterpacks/imageproc/LomoishFilter.java +++ b/media/mca/filterpacks/java/android/filterpacks/imageproc/LomoishFilter.java @@ -28,8 +28,6 @@ import android.filterfw.core.Program; import android.filterfw.core.ShaderProgram; import android.filterfw.format.ImageFormat; -import java.util.Random; - public class LomoishFilter extends Filter { @GenerateFieldPort(name = "tile_size", hasDefault = true) @@ -41,19 +39,18 @@ public class LomoishFilter extends Filter { private int mHeight = 0; private int mTarget = FrameFormat.TARGET_UNSPECIFIED; - private Frame mNoiseFrame; - private Random mRandom; - private final String mLomoishShader = "precision mediump float;\n" + "uniform sampler2D tex_sampler_0;\n" + - "uniform sampler2D tex_sampler_1;\n" + "uniform float stepsizeX;\n" + "uniform float stepsizeY;\n" + "uniform float stepsize;\n" + "uniform vec2 center;\n" + "uniform float inv_max_dist;\n" + "varying vec2 v_texcoord;\n" + + "float rand(vec2 loc) {\n" + + " return fract(sin(dot(loc, vec2(12.9898, 78.233))) * 43758.5453);\n" + + "}\n" + "void main() {\n" + // sharpen " vec3 nbr_color = vec3(0.0, 0.0, 0.0);\n" + @@ -99,7 +96,7 @@ public class LomoishFilter extends Filter { " }\n" + " c_color.b = s_color.b * 0.5 + 0.25;\n" + // blackwhite - " float dither = texture2D(tex_sampler_1, v_texcoord).r;\n" + + " float dither = rand(v_texcoord);\n" + " vec3 xform = clamp((c_color.rgb - 0.15) * 1.53846, 0.0, 1.0);\n" + " vec3 temp = clamp((color.rgb + stepsize - 0.15) * 1.53846, 0.0, 1.0);\n" + " vec3 bw_color = clamp(xform + (temp - xform) * (dither - 0.5), 0.0, 1.0);\n" + @@ -111,8 +108,6 @@ public class LomoishFilter extends Filter { public LomoishFilter(String name) { super(name); - - mRandom = new Random(); } @Override @@ -126,14 +121,6 @@ public class LomoishFilter extends Filter { return inputFormat; } - @Override - public void tearDown(FilterContext context) { - if (mNoiseFrame != null) { - mNoiseFrame.release(); - mNoiseFrame = null; - } - } - public void initProgram(FilterContext context, int target) { switch (target) { case FrameFormat.TARGET_GPU: @@ -180,34 +167,14 @@ public class LomoishFilter extends Filter { if (inputFormat.getWidth() != mWidth || inputFormat.getHeight() != mHeight) { mWidth = inputFormat.getWidth(); mHeight = inputFormat.getHeight(); - - int[] buffer = new int[mWidth * mHeight]; - for (int i = 0; i < mWidth * mHeight; ++i) { - buffer[i] = mRandom.nextInt(255); - } - FrameFormat format = ImageFormat.create(mWidth, mHeight, - ImageFormat.COLORSPACE_RGBA, - FrameFormat.TARGET_GPU); - if (mNoiseFrame != null) { - mNoiseFrame.release(); - } - mNoiseFrame = context.getFrameManager().newFrame(format); - mNoiseFrame.setInts(buffer); - initParameters(); } - if (mNoiseFrame != null && (mNoiseFrame.getFormat().getWidth() != mWidth || - mNoiseFrame.getFormat().getHeight() != mHeight)) { - throw new RuntimeException("Random map and imput image size mismatch!"); - } - // Create output frame Frame output = context.getFrameManager().newFrame(inputFormat); // Process - Frame[] inputs = {input, mNoiseFrame}; - mProgram.process(inputs, output); + mProgram.process(input, output); // Push output pushOutput("image", output); |