AlphaBlendFilter.java revision 21d0ac7403b836e32e2bdbdc8dc98f42b2dfa4e5
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18package android.filterpacks.imageproc;
19
20import android.filterfw.core.Filter;
21import android.filterfw.core.FilterContext;
22import android.filterfw.core.Frame;
23import android.filterfw.core.FrameFormat;
24import android.filterfw.core.KeyValueMap;
25import android.filterfw.core.NativeProgram;
26import android.filterfw.core.NativeFrame;
27import android.filterfw.core.Program;
28import android.filterfw.core.ShaderProgram;
29import android.filterfw.format.ImageFormat;
30
31import java.util.Set;
32
33public class AlphaBlendFilter extends ImageCombineFilter {
34
35    private final String mAlphaBlendShader =
36            "precision mediump float;\n" +
37            "uniform sampler2D tex_sampler_0;\n" +
38            "uniform sampler2D tex_sampler_1;\n" +
39            "uniform sampler2D tex_sampler_2;\n" +
40            "uniform float weight;\n" +
41            "varying vec2 v_texcoord;\n" +
42            "void main() {\n" +
43            "  vec4 colorL = texture2D(tex_sampler_0, v_texcoord);\n" +
44            "  vec4 colorR = texture2D(tex_sampler_1, v_texcoord);\n" +
45            "  float blend = texture2D(tex_sampler_2, v_texcoord).r * weight;\n" +
46            "  gl_FragColor = colorL * (1.0 - blend) + colorR * blend;\n" +
47            "}\n";
48
49    public AlphaBlendFilter(String name) {
50        super(name, new String[] { "source", "overlay", "mask" }, "blended", "weight");
51    }
52
53    @Override
54    protected Program getNativeProgram() {
55        throw new RuntimeException("TODO: Write native implementation for AlphaBlend!");
56    }
57
58    @Override
59    protected Program getShaderProgram() {
60        return new ShaderProgram(mAlphaBlendShader);
61    }
62
63}
64