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.NativeProgram; 25import android.filterfw.core.NativeFrame; 26import android.filterfw.core.Program; 27import android.filterfw.core.ShaderProgram; 28 29/** 30 * @hide 31 */ 32public class Invert extends SimpleImageFilter { 33 34 private static final String mInvertShader = 35 "precision mediump float;\n" + 36 "uniform sampler2D tex_sampler_0;\n" + 37 "varying vec2 v_texcoord;\n" + 38 "void main() {\n" + 39 " vec4 color = texture2D(tex_sampler_0, v_texcoord);\n" + 40 " gl_FragColor.r = 1.0 - color.r;\n" + 41 " gl_FragColor.g = 1.0 - color.g;\n" + 42 " gl_FragColor.b = 1.0 - color.b;\n" + 43 " gl_FragColor.a = color.a;\n" + 44 "}\n"; 45 46 public Invert(String name) { 47 super(name, null); 48 } 49 50 @Override 51 protected Program getNativeProgram(FilterContext context) { 52 return new NativeProgram("filterpack_imageproc", "invert"); 53 } 54 55 @Override 56 protected Program getShaderProgram(FilterContext context) { 57 return new ShaderProgram(context, mInvertShader); 58 } 59 60} 61