Home | History | Annotate | Download | only in imageproc
      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 package android.filterpacks.imageproc;
     18 
     19 import android.filterfw.core.FilterContext;
     20 import android.filterfw.core.Program;
     21 import android.filterfw.core.ShaderProgram;
     22 
     23 /**
     24  * The filter linearly blends "left" and "right" frames. The blending weight is
     25  * the multiplication of parameter "blend" and the alpha value in "right" frame.
     26  * @hide
     27  */
     28 public class BlendFilter extends ImageCombineFilter {
     29 
     30     private final String mBlendShader =
     31             "precision mediump float;\n" +
     32             "uniform sampler2D tex_sampler_0;\n" +
     33             "uniform sampler2D tex_sampler_1;\n" +
     34             "uniform float blend;\n" +
     35             "varying vec2 v_texcoord;\n" +
     36             "void main() {\n" +
     37             "  vec4 colorL = texture2D(tex_sampler_0, v_texcoord);\n" +
     38             "  vec4 colorR = texture2D(tex_sampler_1, v_texcoord);\n" +
     39             "  float weight = colorR.a * blend;\n" +
     40             "  gl_FragColor = mix(colorL, colorR, weight);\n" +
     41             "}\n";
     42 
     43     public BlendFilter(String name) {
     44         super(name, new String[] { "left", "right" }, "blended", "blend");
     45     }
     46 
     47     @Override
     48     protected Program getNativeProgram(FilterContext context) {
     49         throw new RuntimeException("TODO: Write native implementation for Blend!");
     50     }
     51 
     52     @Override
     53     protected Program getShaderProgram(FilterContext context) {
     54         return new ShaderProgram(context, mBlendShader);
     55     }
     56 }
     57