diff options
author | Jorge Ruesga <jorge@ruesga.com> | 2013-08-15 00:29:40 +0200 |
---|---|---|
committer | Jorge Ruesga <jorge@ruesga.com> | 2013-08-15 00:29:40 +0200 |
commit | 77abe3bf3962fe588c9b8730079c30d996fe4aa8 (patch) | |
tree | 00165884fc3565d7eb735ea90db6e4c669c53f07 /src/org/cyanogenmod/wallpapers/photophase/effects | |
parent | 0539d1a6b4425d60b71ebe5d003f09472ae72814 (diff) | |
download | android_packages_wallpapers_PhotoPhase-77abe3bf3962fe588c9b8730079c30d996fe4aa8.tar.gz android_packages_wallpapers_PhotoPhase-77abe3bf3962fe588c9b8730079c30d996fe4aa8.tar.bz2 android_packages_wallpapers_PhotoPhase-77abe3bf3962fe588c9b8730079c30d996fe4aa8.zip |
More effects
* Halftone (redone)
* Blur
* Emboss
* Glow
* Outline
* Pixelate
* PopArt
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Diffstat (limited to 'src/org/cyanogenmod/wallpapers/photophase/effects')
12 files changed, 679 insertions, 34 deletions
diff --git a/src/org/cyanogenmod/wallpapers/photophase/effects/BlurEffect.java b/src/org/cyanogenmod/wallpapers/photophase/effects/BlurEffect.java new file mode 100644 index 0000000..465cb99 --- /dev/null +++ b/src/org/cyanogenmod/wallpapers/photophase/effects/BlurEffect.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2013 The CyanogenMod Project + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// Based on the shaders of kodemongki: +// http://kodemongki.blogspot.com.es/2011/06/kameraku-custom-shader-effects-example.html +// + +package org.cyanogenmod.wallpapers.photophase.effects; + +import android.media.effect.EffectContext; + +/** + * A blur effect<br/> + * <table> + * <tr><td>Parameter name</td><td>Meaning</td><td>Valid values</td></tr> + * </table> + */ +public class BlurEffect extends PhotoPhaseEffect { + + private static final String FRAGMENT_SHADER = + "precision mediump float;\n" + + "uniform sampler2D tex_sampler;\n" + + "varying vec2 v_texcoord;\n" + + "void main(void)\n" + + "{\n" + + " float step = 0.02;\n" + + " vec3 c1 = texture2D(tex_sampler, vec2(v_texcoord.s - step, v_texcoord.t - step)).bgr;\n" + + " vec3 c2 = texture2D(tex_sampler, vec2(v_texcoord.s + step, v_texcoord.t + step)).bgr;\n" + + " vec3 c3 = texture2D(tex_sampler, vec2(v_texcoord.s - step, v_texcoord.t + step)).bgr;\n" + + " vec3 c4 = texture2D(tex_sampler, vec2(v_texcoord.s + step, v_texcoord.t - step)).bgr;\n" + + " gl_FragColor.a = 1.0;\n" + + " gl_FragColor.rgb = (c1 + c2 + c3 + c4) / 4.0;\n" + + "}"; + + /** + * Constructor of <code>BlurEffect</code>. + * + * @param ctx The effect context + * @param name The effect name + */ + public BlurEffect(EffectContext ctx, String name) { + super(ctx, BlurEffect.class.getName()); + init(VERTEX_SHADER, FRAGMENT_SHADER); + } + +} diff --git a/src/org/cyanogenmod/wallpapers/photophase/effects/Effects.java b/src/org/cyanogenmod/wallpapers/photophase/effects/Effects.java index bfee378..4af8307 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/effects/Effects.java +++ b/src/org/cyanogenmod/wallpapers/photophase/effects/Effects.java @@ -44,6 +44,10 @@ public class Effects { */ AUTOFIX, /** + * @see PhotoPhaseEffectFactory#EFFECT_BLUR + */ + BLUR, + /** * @see EffectFactory#EFFECT_CROSSPROCESS */ CROSSPROCESS, @@ -56,10 +60,18 @@ public class Effects { */ DUOTONE, /** + * @see PhotoPhaseEffectFactory#EFFECT_EMBOSS + */ + EMBOSS, + /** * @see EffectFactory#EFFECT_FISHEYE */ FISHEYE, /** + * @see PhotoPhaseEffectFactory#EFFECT_GLOW + */ + GLOW, + /** * @see EffectFactory#EFFECT_GRAIN */ GRAIN, @@ -76,10 +88,26 @@ public class Effects { */ LOMOISH, /** + * @see PhotoPhaseEffectFactory#EFFECT_MIRROR + */ + MIRROR, + /** * @see EffectFactory#EFFECT_NEGATIVE */ NEGATIVE, /** + * @see PhotoPhaseEffectFactory#EFFECT_OUTLINE + */ + OUTLINE, + /** + * @see PhotoPhaseEffectFactory#EFFECT_PIXELATE + */ + PIXELATE, + /** + * @see PhotoPhaseEffectFactory#EFFECT_POPART + */ + POPART, + /** * @see EffectFactory#EFFECT_POSTERIZE */ POSTERIZE, @@ -156,6 +184,10 @@ public class Effects { effect = effectFactory.createEffect(EffectFactory.EFFECT_AUTOFIX); effect.setParameter("scale", 0.5f); } + } else if (nextEffect.compareTo(EFFECTS.BLUR) == 0) { + if (EffectFactory.isEffectSupported(PhotoPhaseEffectFactory.EFFECT_BLUR)) { + effect = effectFactory.createEffect(PhotoPhaseEffectFactory.EFFECT_BLUR); + } } else if (nextEffect.compareTo(EFFECTS.CROSSPROCESS) == 0) { if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_CROSSPROCESS)) { effect = effectFactory.createEffect(EffectFactory.EFFECT_CROSSPROCESS); @@ -170,11 +202,19 @@ public class Effects { effect.setParameter("first_color", Color.parseColor("#FF8CACFF")); effect.setParameter("second_color", Color.WHITE); } + } else if (nextEffect.compareTo(EFFECTS.EMBOSS) == 0) { + if (EffectFactory.isEffectSupported(PhotoPhaseEffectFactory.EFFECT_EMBOSS)) { + effect = effectFactory.createEffect(PhotoPhaseEffectFactory.EFFECT_EMBOSS); + } } else if (nextEffect.compareTo(EFFECTS.FISHEYE) == 0) { if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_FISHEYE)) { effect = effectFactory.createEffect(EffectFactory.EFFECT_FISHEYE); effect.setParameter("scale", 1.0f); } + } else if (nextEffect.compareTo(EFFECTS.GLOW) == 0) { + if (EffectFactory.isEffectSupported(PhotoPhaseEffectFactory.EFFECT_GLOW)) { + effect = effectFactory.createEffect(PhotoPhaseEffectFactory.EFFECT_GLOW); + } } else if (nextEffect.compareTo(EFFECTS.GRAIN) == 0) { if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_GRAIN)) { effect = effectFactory.createEffect(EffectFactory.EFFECT_GRAIN); @@ -187,7 +227,11 @@ public class Effects { } else if (nextEffect.compareTo(EFFECTS.HALFTONE) == 0) { if (EffectFactory.isEffectSupported(PhotoPhaseEffectFactory.EFFECT_HALFTONE)) { effect = effectFactory.createEffect(PhotoPhaseEffectFactory.EFFECT_HALFTONE); - effect.setParameter("strength", 30.0f); + effect.setParameter("strength", 8.0f); + } + } else if (nextEffect.compareTo(EFFECTS.MIRROR) == 0) { + if (EffectFactory.isEffectSupported(PhotoPhaseEffectFactory.EFFECT_MIRROR)) { + effect = effectFactory.createEffect(PhotoPhaseEffectFactory.EFFECT_MIRROR); } } else if (nextEffect.compareTo(EFFECTS.LOMOISH) == 0) { if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_LOMOISH)) { @@ -197,6 +241,19 @@ public class Effects { if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_NEGATIVE)) { effect = effectFactory.createEffect(EffectFactory.EFFECT_NEGATIVE); } + } else if (nextEffect.compareTo(EFFECTS.OUTLINE) == 0) { + if (EffectFactory.isEffectSupported(PhotoPhaseEffectFactory.EFFECT_OUTLINE)) { + effect = effectFactory.createEffect(PhotoPhaseEffectFactory.EFFECT_OUTLINE); + } + } else if (nextEffect.compareTo(EFFECTS.PIXELATE) == 0) { + if (EffectFactory.isEffectSupported(PhotoPhaseEffectFactory.EFFECT_PIXELATE)) { + effect = effectFactory.createEffect(PhotoPhaseEffectFactory.EFFECT_PIXELATE); + effect.setParameter("strength", 8.0f); + } + } else if (nextEffect.compareTo(EFFECTS.POPART) == 0) { + if (EffectFactory.isEffectSupported(PhotoPhaseEffectFactory.EFFECT_POPART)) { + effect = effectFactory.createEffect(PhotoPhaseEffectFactory.EFFECT_POPART); + } } else if (nextEffect.compareTo(EFFECTS.POSTERIZE) == 0) { if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_POSTERIZE)) { effect = effectFactory.createEffect(EffectFactory.EFFECT_POSTERIZE); diff --git a/src/org/cyanogenmod/wallpapers/photophase/effects/EmbossEffect.java b/src/org/cyanogenmod/wallpapers/photophase/effects/EmbossEffect.java new file mode 100644 index 0000000..691ef39 --- /dev/null +++ b/src/org/cyanogenmod/wallpapers/photophase/effects/EmbossEffect.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2013 The CyanogenMod Project + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// Based on the shaders of kodemongki: +// http://kodemongki.blogspot.com.es/2011/06/kameraku-custom-shader-effects-example.html +// + +package org.cyanogenmod.wallpapers.photophase.effects; + +import android.media.effect.EffectContext; + +/** + * An emboss effect<br/> + * <table> + * <tr><td>Parameter name</td><td>Meaning</td><td>Valid values</td></tr> + * </table> + */ +public class EmbossEffect extends PhotoPhaseEffect { + + private static final String FRAGMENT_SHADER = + "precision mediump float;\n" + + "uniform sampler2D tex_sampler;\n" + + "varying vec2 v_texcoord;\n" + + "const float step_w = 0.0015625;\n" + + "const float step_h = 0.0027778;\n" + + "void main(void)\n" + + "{\n" + + " vec3 t1 = texture2D(tex_sampler, vec2(v_texcoord.x - step_w, v_texcoord.y - step_h)).bgr;\n" + + " vec3 t2 = texture2D(tex_sampler, vec2(v_texcoord.x, v_texcoord.y - step_h)).bgr;\n" + + " vec3 t3 = texture2D(tex_sampler, vec2(v_texcoord.x + step_w, v_texcoord.y - step_h)).bgr;\n" + + " vec3 t4 = texture2D(tex_sampler, vec2(v_texcoord.x - step_w, v_texcoord.y)).bgr;\n" + + " vec3 t5 = texture2D(tex_sampler, v_texcoord).bgr;\n" + + " vec3 t6 = texture2D(tex_sampler, vec2(v_texcoord.x + step_w, v_texcoord.y)).bgr;\n" + + " vec3 t7 = texture2D(tex_sampler, vec2(v_texcoord.x - step_w, v_texcoord.y + step_h)).bgr;\n" + + " vec3 t8 = texture2D(tex_sampler, vec2(v_texcoord.x, v_texcoord.y + step_h)).bgr;\n" + + " vec3 t9 = texture2D(tex_sampler, vec2(v_texcoord.x + step_w, v_texcoord.y + step_h)).bgr;\n" + + " vec3 rr = -4.0 * t1 - 4.0 * t2 - 4.0 * t4 + 12.0 * t5;\n" + + " float y = (rr.r + rr.g + rr.b) / 3.0;\n" + + " gl_FragColor.a = 1.0;\n" + + " gl_FragColor.rgb = vec3(y, y, y) + 0.3;\n" + + "}"; + + /** + * Constructor of <code>EmbossEffect</code>. + * + * @param ctx The effect context + * @param name The effect name + */ + public EmbossEffect(EffectContext ctx, String name) { + super(ctx, EmbossEffect.class.getName()); + init(VERTEX_SHADER, FRAGMENT_SHADER); + } + +} diff --git a/src/org/cyanogenmod/wallpapers/photophase/effects/GlowEffect.java b/src/org/cyanogenmod/wallpapers/photophase/effects/GlowEffect.java new file mode 100644 index 0000000..8520e09 --- /dev/null +++ b/src/org/cyanogenmod/wallpapers/photophase/effects/GlowEffect.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2013 The CyanogenMod Project + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// Based on the shaders of kodemongki: +// http://kodemongki.blogspot.com.es/2011/06/kameraku-custom-shader-effects-example.html +// + +package org.cyanogenmod.wallpapers.photophase.effects; + +import android.media.effect.EffectContext; + +/** + * A glow effect<br/> + * <table> + * <tr><td>Parameter name</td><td>Meaning</td><td>Valid values</td></tr> + * </table> + */ +public class GlowEffect extends PhotoPhaseEffect { + + private static final String FRAGMENT_SHADER = + "precision mediump float;\n" + + "uniform sampler2D tex_sampler;\n" + + "varying vec2 v_texcoord;\n" + + "const float step_w = 0.0015625;\n" + + "const float step_h = 0.0027778;\n" + + "void main(void)\n" + + "{\n" + + " vec3 t1 = texture2D(tex_sampler, vec2(v_texcoord.x - step_w, v_texcoord.y - step_h)).bgr;\n" + + " vec3 t2 = texture2D(tex_sampler, vec2(v_texcoord.x, v_texcoord.y - step_h)).bgr;\n" + + " vec3 t3 = texture2D(tex_sampler, vec2(v_texcoord.x + step_w, v_texcoord.y - step_h)).bgr;\n" + + " vec3 t4 = texture2D(tex_sampler, vec2(v_texcoord.x - step_w, v_texcoord.y)).bgr;\n" + + " vec3 t5 = texture2D(tex_sampler, v_texcoord).bgr;\n" + + " vec3 t6 = texture2D(tex_sampler, vec2(v_texcoord.x + step_w, v_texcoord.y)).bgr;\n" + + " vec3 t7 = texture2D(tex_sampler, vec2(v_texcoord.x - step_w, v_texcoord.y + step_h)).bgr;\n" + + " vec3 t8 = texture2D(tex_sampler, vec2(v_texcoord.x, v_texcoord.y + step_h)).bgr;\n" + + " vec3 t9 = texture2D(tex_sampler, vec2(v_texcoord.x + step_w, v_texcoord.y + step_h)).bgr;\n" + + " vec3 xx= t1 + 2.0*t2 + t3 - t7 - 2.0*t8 - t9;\n" + + " vec3 yy = t1 - t3 + 2.0*t4 - 2.0*t6 + t7 - t9;\n" + + " vec3 rr = sqrt(xx * xx + yy * yy);\n" + + " gl_FragColor.a = 1.0;\n" + + " gl_FragColor.rgb = rr * 2.0 * t5;\n" + + "}"; + + /** + * Constructor of <code>GlowEffect</code>. + * + * @param ctx The effect context + * @param name The effect name + */ + public GlowEffect(EffectContext ctx, String name) { + super(ctx, GlowEffect.class.getName()); + init(VERTEX_SHADER, FRAGMENT_SHADER); + } + +} diff --git a/src/org/cyanogenmod/wallpapers/photophase/effects/HalftoneEffect.java b/src/org/cyanogenmod/wallpapers/photophase/effects/HalftoneEffect.java index 3f9c4e7..07da491 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/effects/HalftoneEffect.java +++ b/src/org/cyanogenmod/wallpapers/photophase/effects/HalftoneEffect.java @@ -1,5 +1,4 @@ /* - * Copyright (C) 2008 Max Maischein * Copyright (C) 2013 The CyanogenMod Project * * @@ -16,14 +15,13 @@ * limitations under the License. */ // -// Based in the shaders of Max Maischein of App-VideoMixer: -// http://cpansearch.perl.org/src/CORION/App-VideoMixer-0.02/filters/halftone.glsl +// Based on the shaders of kodemongki: +// http://kodemongki.blogspot.com.es/2011/06/kameraku-custom-shader-effects-example.html // package org.cyanogenmod.wallpapers.photophase.effects; import android.media.effect.EffectContext; -import android.media.effect.EffectFactory; import android.opengl.GLES20; import android.util.Log; @@ -35,8 +33,8 @@ import org.cyanogenmod.wallpapers.photophase.utils.GLESUtil; * <tr><td>Parameter name</td><td>Meaning</td><td>Valid values</td></tr> * <tr> * <td><code>strength</code></td> - * <td>The halftone steps multiplier.</td> - * <td>Positive float (>0). Higher numbers produce smallest points;</td> + * <td>The halftone strength.</td> + * <td>Positive float (>0). Higher numbers produce smallest points.</td> * </tr> * </table> */ @@ -50,26 +48,33 @@ public class HalftoneEffect extends PhotoPhaseEffect { "precision mediump float;\n" + "uniform sampler2D tex_sampler;\n" + "varying vec2 v_texcoord;\n" + - "uniform float steps\n;" + - "float dotsize = 1.0 / steps ;\n" + - "float half_step = dotsize / 2.0;\n" + - "void main() {\n" + - " vec2 center = v_texcoord - vec2(mod(v_texcoord.x, dotsize),mod(v_texcoord.y, dotsize)) + half_step;\n" + - " vec4 pel = texture2D(tex_sampler, center);\n" + - " float size = length(pel);\n" + - " if (distance(v_texcoord,center) <= dotsize*size/4.0) {\n" + - " gl_FragColor = pel;\n" + - " } else {\n" + - " gl_FragColor = vec4(0.0,0.0,0.0,0.0);\n" + - " };\n" + - "}\n"; + "const float step_w = 0.0015625;\n" + + "const float step_h = 0.0027778;\n" + + "uniform float strength;\n" + + "void main(void)\n" + + "{\n" + + " float offx = floor(v_texcoord.s / (strength * step_w));\n" + + " float offy = floor(v_texcoord.t / (strength * step_h));\n" + + " vec3 res = texture2D(tex_sampler, vec2(offx * strength * step_w , offy * strength * step_h)).bgr;\n" + + " vec2 prc = fract(v_texcoord.st / vec2(strength * step_w, strength * step_h));\n" + + " vec2 pw = pow(abs(prc - 0.5), vec2(2.0));\n" + + " float rs = pow(0.45, 2.0);\n" + + " float gr = smoothstep(rs - 0.1, rs + 0.1, pw.x + pw.y);\n" + + " float y = (res.r + res.g + res.b) / 3.0; \n" + + " vec3 ra = res / y;\n" + + " float ls = 0.3;\n" + + " float lb = ceil(y / ls);\n" + + " float lf = ls * lb + 0.3;\n" + + " res = lf * res;\n" + + " gl_FragColor.a = 1.0;\n" + + " gl_FragColor.rgb = mix(res, vec3(0.1, 0.1, 0.1), gr);\n" + + "}"; - private float mStrength = 32.0f; + private float mStrength = 16.0f; private int mStepsHandle; /** - * An abstract constructor of <code>Effect</code> to follow the rules - * defined by {@link EffectFactory}. + * Constructor of <code>HalftoneEffect</code>. * * @param ctx The effect context * @param name The effect name @@ -87,7 +92,7 @@ public class HalftoneEffect extends PhotoPhaseEffect { super.init(vertexShader, fragmentShader); // Parameters - mStepsHandle = GLES20.glGetUniformLocation(mProgram, "steps"); + mStepsHandle = GLES20.glGetUniformLocation(mProgram, "strength"); GLESUtil.glesCheckError("glGetUniformLocation"); } diff --git a/src/org/cyanogenmod/wallpapers/photophase/effects/MirrorEffect.java b/src/org/cyanogenmod/wallpapers/photophase/effects/MirrorEffect.java new file mode 100644 index 0000000..27233d2 --- /dev/null +++ b/src/org/cyanogenmod/wallpapers/photophase/effects/MirrorEffect.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2013 The CyanogenMod Project + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// Based on the shaders of kodemongki: +// http://kodemongki.blogspot.com.es/2011/06/kameraku-custom-shader-effects-example.html +// + +package org.cyanogenmod.wallpapers.photophase.effects; + +import android.media.effect.EffectContext; + +/** + * A mirror effect<br/> + * <table> + * <tr><td>Parameter name</td><td>Meaning</td><td>Valid values</td></tr> + * </table> + */ +public class MirrorEffect extends PhotoPhaseEffect { + + private static final String FRAGMENT_SHADER = + "precision mediump float;\n" + + "uniform sampler2D tex_sampler;\n" + + "varying vec2 v_texcoord;\n" + + "void main(void)\n" + + "{\n" + + " vec2 off = vec2(0.0, 0.0);\n" + + " if (v_texcoord.t > 0.5) {\n" + + " off.t = 1.0 - v_texcoord.t;\n" + + " off.s = v_texcoord.s;\n" + + " } else {\n" + + " off = v_texcoord;\n" + + " }\n" + + " vec3 color = texture2D(tex_sampler, vec2(off)).bgr;\n" + + " gl_FragColor.a = 1.0;\n" + + " gl_FragColor.rgb = color;\n" + + "}"; + + /** + * Constructor of <code>MirrorEffect</code>. + * + * @param ctx The effect context + * @param name The effect name + */ + public MirrorEffect(EffectContext ctx, String name) { + super(ctx, MirrorEffect.class.getName()); + init(VERTEX_SHADER, FRAGMENT_SHADER); + } + +} diff --git a/src/org/cyanogenmod/wallpapers/photophase/effects/OutlineEffect.java b/src/org/cyanogenmod/wallpapers/photophase/effects/OutlineEffect.java new file mode 100644 index 0000000..8dc7854 --- /dev/null +++ b/src/org/cyanogenmod/wallpapers/photophase/effects/OutlineEffect.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2013 The CyanogenMod Project + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// Based on the shaders of kodemongki: +// http://kodemongki.blogspot.com.es/2011/06/kameraku-custom-shader-effects-example.html +// + +package org.cyanogenmod.wallpapers.photophase.effects; + +import android.media.effect.EffectContext; + +/** + * An outline effect (highlight edges)<br/> + * <table> + * <tr><td>Parameter name</td><td>Meaning</td><td>Valid values</td></tr> + * </table> + */ +public class OutlineEffect extends PhotoPhaseEffect { + + private static final String FRAGMENT_SHADER = + "precision mediump float;\n" + + "uniform sampler2D tex_sampler;\n" + + "varying vec2 v_texcoord;\n" + + "const float step_w = 0.0015625;\n" + + "const float step_h = 0.0027778;\n" + + "void main(void)\n" + + "{\n" + + " vec3 t1 = texture2D(tex_sampler, vec2(v_texcoord.x - step_w, v_texcoord.y - step_h)).bgr;\n" + + " vec3 t2 = texture2D(tex_sampler, vec2(v_texcoord.x, v_texcoord.y - step_h)).bgr;\n" + + " vec3 t3 = texture2D(tex_sampler, vec2(v_texcoord.x + step_w, v_texcoord.y - step_h)).bgr;\n" + + " vec3 t4 = texture2D(tex_sampler, vec2(v_texcoord.x - step_w, v_texcoord.y)).bgr;\n" + + " vec3 t5 = texture2D(tex_sampler, v_texcoord).bgr;\n" + + " vec3 t6 = texture2D(tex_sampler, vec2(v_texcoord.x + step_w, v_texcoord.y)).bgr;\n" + + " vec3 t7 = texture2D(tex_sampler, vec2(v_texcoord.x - step_w, v_texcoord.y + step_h)).bgr;\n" + + " vec3 t8 = texture2D(tex_sampler, vec2(v_texcoord.x, v_texcoord.y + step_h)).bgr;\n" + + " vec3 t9 = texture2D(tex_sampler, vec2(v_texcoord.x + step_w, v_texcoord.y + step_h)).bgr;\n" + + " vec3 xx= t1 + 2.0*t2 + t3 - t7 - 2.0*t8 - t9;\n" + + " vec3 yy = t1 - t3 + 2.0*t4 - 2.0*t6 + t7 - t9;\n" + + " vec3 rr = sqrt(xx * xx + yy * yy);\n" + + " float y = (rr.r + rr.g + rr.b) / 3.0;\n" + + " if (y > 0.2)\n" + + " rr = vec3(0.0, 0.0, 0.0);\n" + + " else\n" + + " rr = vec3(1.0, 1.0, 1.0);\n" + + " gl_FragColor.a = 1.0;\n" + + " gl_FragColor.rgb = rr;\n" + + "}"; + + /** + * Constructor of <code>OutlineEffect</code>. + * + * @param ctx The effect context + * @param name The effect name + */ + public OutlineEffect(EffectContext ctx, String name) { + super(ctx, OutlineEffect.class.getName()); + init(VERTEX_SHADER, FRAGMENT_SHADER); + } + +} diff --git a/src/org/cyanogenmod/wallpapers/photophase/effects/PhotoPhaseEffect.java b/src/org/cyanogenmod/wallpapers/photophase/effects/PhotoPhaseEffect.java index b5a6dbf..cdb8b29 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/effects/PhotoPhaseEffect.java +++ b/src/org/cyanogenmod/wallpapers/photophase/effects/PhotoPhaseEffect.java @@ -18,6 +18,7 @@ package org.cyanogenmod.wallpapers.photophase.effects; import android.media.effect.Effect; import android.media.effect.EffectContext; +import android.media.effect.EffectFactory; import android.opengl.GLES20; import android.opengl.GLUtils; @@ -60,8 +61,8 @@ public abstract class PhotoPhaseEffect extends Effect { FloatBuffer mPosVertices; /** - * An abstract contructor of <code>Effect</code> to follow the rules - * defined by {@see EffectFactory}. + * An abstract constructor of <code>Effect</code> to follow the rules + * defined by {@link EffectFactory}. * * @param ctx The effect context * @param name The effect name @@ -171,6 +172,7 @@ public abstract class PhotoPhaseEffect extends Effect { */ @Override public void setParameter(String parameterKey, Object value) { + // Ignore } /** diff --git a/src/org/cyanogenmod/wallpapers/photophase/effects/PhotoPhaseEffectFactory.java b/src/org/cyanogenmod/wallpapers/photophase/effects/PhotoPhaseEffectFactory.java index 2e89236..8755acf 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/effects/PhotoPhaseEffectFactory.java +++ b/src/org/cyanogenmod/wallpapers/photophase/effects/PhotoPhaseEffectFactory.java @@ -23,21 +23,89 @@ package org.cyanogenmod.wallpapers.photophase.effects; public class PhotoPhaseEffectFactory { /** - * <p>Applies halftone effect to the image.</p> + * <p>Applies a blur effect to the image.</p> + * <p>Available parameters:</p> + * <table> + * <tr><td>Parameter name</td><td>Meaning</td><td>Valid values</td></tr> + * </table> + */ + public static final String EFFECT_BLUR = "org.cyanogenmod.wallpapers.photophase.effects.BlurEffect"; + + /** + * <p>Applies an emboss effect to the image.</p> + * <p>Available parameters:</p> + * <table> + * <tr><td>Parameter name</td><td>Meaning</td><td>Valid values</td></tr> + * </table> + */ + public static final String EFFECT_EMBOSS = "org.cyanogenmod.wallpapers.photophase.effects.EmbossEffect"; + + /** + * <p>Applies a glow effect to the image.</p> + * <p>Available parameters:</p> + * <table> + * <tr><td>Parameter name</td><td>Meaning</td><td>Valid values</td></tr> + * </table> + */ + public static final String EFFECT_GLOW = "org.cyanogenmod.wallpapers.photophase.effects.GlowEffect"; + + /** + * <p>Applies a halftone effect to the image.</p> * <p>Available parameters:</p> * <table> * <tr><td>Parameter name</td><td>Meaning</td><td>Valid values</td></tr> * <tr> * <td><code>strength</code></td> * <td>The halftone steps multiplier.</td> - * <td>Positive float (>0). Higher numbers produce smallest points;</td> + * <td>Positive float (>0). Higher numbers produce smallest points</td> * </tr> * </table> */ public static final String EFFECT_HALFTONE = "org.cyanogenmod.wallpapers.photophase.effects.HalftoneEffect"; /** - * <p>Applies a TV scanlines effect to the image.</p> + * <p>Applies a mirror effect to the image.</p> + * <p>Available parameters:</p> + * <table> + * <tr><td>Parameter name</td><td>Meaning</td><td>Valid values</td></tr> + * </table> + */ + public static final String EFFECT_MIRROR = "org.cyanogenmod.wallpapers.photophase.effects.MirrorEffect"; + + /** + * <p>Applies an outline effect to the image.</p> + * <p>Available parameters:</p> + * <table> + * <tr><td>Parameter name</td><td>Meaning</td><td>Valid values</td></tr> + * </table> + */ + public static final String EFFECT_OUTLINE = "org.cyanogenmod.wallpapers.photophase.effects.OutlineEffect"; + + /** + * <p>Applies a pixelate effect to the image.</p> + * <p>Available parameters:</p> + * <table> + * <tr><td>Parameter name</td><td>Meaning</td><td>Valid values</td></tr> + * <tr> + * <td><code>strength</code></td> + * <td>The pixelate steps multiplier.</td> + * <td>Positive float (>0). Higher numbers produce more pixelation.</td> + * </tr> + * </table> + */ + public static final String EFFECT_PIXELATE = "org.cyanogenmod.wallpapers.photophase.effects.PixelateEffect"; + + /** + * <p>Applies a pop art (Warhol) effect to the image.</p> + * <p>Available parameters:</p> + * <table> + * <tr><td>Parameter name</td><td>Meaning</td><td>Valid values</td></tr> + * </table> + */ + public static final String EFFECT_POPART = "org.cyanogenmod.wallpapers.photophase.effects.PopArtEffect"; + + /** + * <p>Applies a TV scan line effect to the image.</p> * <p>Available parameters:</p> * <table> * <tr><td>Parameter name</td><td>Meaning</td><td>Valid values</td></tr> diff --git a/src/org/cyanogenmod/wallpapers/photophase/effects/PixelateEffect.java b/src/org/cyanogenmod/wallpapers/photophase/effects/PixelateEffect.java new file mode 100644 index 0000000..fe37d4c --- /dev/null +++ b/src/org/cyanogenmod/wallpapers/photophase/effects/PixelateEffect.java @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2013 The CyanogenMod Project + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// Based on the shaders of kodemongki: +// http://kodemongki.blogspot.com.es/2011/06/kameraku-custom-shader-effects-example.html +// + +package org.cyanogenmod.wallpapers.photophase.effects; + +import android.media.effect.EffectContext; +import android.opengl.GLES20; +import android.util.Log; + +import org.cyanogenmod.wallpapers.photophase.utils.GLESUtil; + +/** + * A pixelate effect<br/> + * <table> + * <tr><td>Parameter name</td><td>Meaning</td><td>Valid values</td></tr> + * <tr> + * <td><code>strength</code></td> + * <td>The pixelate strength.</td> + * <td>Positive float (>0). Higher numbers produce more pixelation.</td> + * </tr> + * </table> + */ +public class PixelateEffect extends PhotoPhaseEffect { + + private static final String TAG = "PixelateEffect"; + + private static final String STRENGTH_PARAMETER = "strength"; + + private static final String FRAGMENT_SHADER = + "precision mediump float;\n" + + "uniform sampler2D tex_sampler;\n" + + "varying vec2 v_texcoord;\n" + + "const float step_w = 0.0015625;\n" + + "const float step_h = 0.0027778;\n" + + "uniform float strength;\n" + + "void main(void)\n" + + "{\n" + + " float offx = floor(v_texcoord.s / (strength * step_w));\n" + + " float offy = floor(v_texcoord.t / (strength * step_h));\n" + + " vec3 res = texture2D(tex_sampler, vec2(offx * strength * step_w , offy * strength * step_h)).bgr;\n" + + " gl_FragColor.a = 1.0;\n" + + " gl_FragColor.rgb = res;\n" + + "}"; + + private float mStrength = 8.0f; + private int mStepsHandle; + + /** + * Constructor of <code>PixelateEffect</code>. + * + * @param ctx The effect context + * @param name The effect name + */ + public PixelateEffect(EffectContext ctx, String name) { + super(ctx, PixelateEffect.class.getName()); + init(VERTEX_SHADER, FRAGMENT_SHADER); + } + + /** + * {@inheritDoc} + */ + @Override + void init(String vertexShader, String fragmentShader) { + super.init(vertexShader, fragmentShader); + + // Parameters + mStepsHandle = GLES20.glGetUniformLocation(mProgram, "strength"); + GLESUtil.glesCheckError("glGetUniformLocation"); + } + + /** + * {@inheritDoc} + */ + @Override + void applyParameters() { + // Set parameters + GLES20.glUniform1f(mStepsHandle, mStrength); + GLESUtil.glesCheckError("glUniform1f"); + } + + /** + * {@inheritDoc} + */ + @Override + public void setParameter(String parameterKey, Object value) { + if (parameterKey.compareTo(STRENGTH_PARAMETER) == 0) { + try { + float strength = Float.parseFloat(value.toString()); + if (strength <= 0) { + Log.w(TAG, "strength parameter must be >= 0"); + return; + } + mStrength = strength; + } catch (NumberFormatException ex) { + // Ignore + } + } + } + +} diff --git a/src/org/cyanogenmod/wallpapers/photophase/effects/PopArtEffect.java b/src/org/cyanogenmod/wallpapers/photophase/effects/PopArtEffect.java new file mode 100644 index 0000000..df2b18c --- /dev/null +++ b/src/org/cyanogenmod/wallpapers/photophase/effects/PopArtEffect.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2013 The CyanogenMod Project + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// Based on the shaders of kodemongki: +// http://kodemongki.blogspot.com.es/2011/06/kameraku-custom-shader-effects-example.html +// + +package org.cyanogenmod.wallpapers.photophase.effects; + +import android.media.effect.EffectContext; + +/** + * A pop art (Warhol) effect<br/> + * <table> + * <tr><td>Parameter name</td><td>Meaning</td><td>Valid values</td></tr> + * </table> + */ +public class PopArtEffect extends PhotoPhaseEffect { + + private static final String FRAGMENT_SHADER = + "precision mediump float;\n" + + "uniform sampler2D tex_sampler;\n" + + "varying vec2 v_texcoord;\n" + + "void main(void)\n" + + "{\n" + + " vec3 col = texture2D(tex_sampler, v_texcoord).bgr;\n" + + " float y = 0.3 *col.r + 0.59 * col.g + 0.11 * col.b;\n" + + " y = y < 0.3 ? 0.0 : (y < 0.6 ? 0.5 : 1.0);\n" + + " if (y == 0.5)\n" + + " col = vec3(0.8, 0.0, 0.0);\n" + + " else if (y == 1.0)\n" + + " col = vec3(0.9, 0.9, 0.0);\n" + + " else\n" + + " col = vec3(0.0, 0.0, 0.0);\n" + + " gl_FragColor.a = 1.0;\n" + + " gl_FragColor.rgb = col;\n" + + "}"; + + /** + * Constructor of <code>PopArtEffect</code>. + * + * @param ctx The effect context + * @param name The effect name + */ + public PopArtEffect(EffectContext ctx, String name) { + super(ctx, PopArtEffect.class.getName()); + init(VERTEX_SHADER, FRAGMENT_SHADER); + } + +} diff --git a/src/org/cyanogenmod/wallpapers/photophase/effects/ScanlinesEffect.java b/src/org/cyanogenmod/wallpapers/photophase/effects/ScanlinesEffect.java index 183e207..cd78307 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/effects/ScanlinesEffect.java +++ b/src/org/cyanogenmod/wallpapers/photophase/effects/ScanlinesEffect.java @@ -1,5 +1,4 @@ /* - * Copyright (C) 2008 Max Maischein * Copyright (C) 2013 The CyanogenMod Project * * @@ -16,14 +15,13 @@ * limitations under the License. */ // -// Based in the shaders of Max Maischein of App-VideoMixer: +// Based on the shaders of Max Maischein of App-VideoMixer: // http://cpansearch.perl.org/src/CORION/App-VideoMixer-0.02/filters/scanlines.glsl // package org.cyanogenmod.wallpapers.photophase.effects; import android.media.effect.EffectContext; -import android.media.effect.EffectFactory; /** * A TV scanline effect<br/> @@ -48,8 +46,7 @@ public class ScanlinesEffect extends PhotoPhaseEffect { "}"; /** - * An abstract constructor of <code>Effect</code> to follow the rules - * defined by {@link EffectFactory}. + * Constructor of <code>ScanlinesEffect</code>. * * @param ctx The effect context * @param name The effect name |