FileDocCategorySizeDatePackage
TintFilter.javaAPI DocAndroid 5.1 API4185Thu Mar 12 22:22:30 GMT 2015android.filterpacks.imageproc

TintFilter

public class TintFilter extends android.filterfw.core.Filter

Fields Summary
private int
mTint
private int
mTileSize
private android.filterfw.core.Program
mProgram
private int
mTarget
private final String
mTintShader
Constructors Summary
public TintFilter(String name)


       
      super(name);
    
Methods Summary
public voidfieldPortValueUpdated(java.lang.String name, android.filterfw.core.FilterContext context)

        if (mProgram != null) {
            updateParameters();
        }
    
public android.filterfw.core.FrameFormatgetOutputFormat(java.lang.String portName, android.filterfw.core.FrameFormat inputFormat)

        return inputFormat;
    
private voidinitParameters()

        float color_ratio[] = {0.21f, 0.71f, 0.07f};
        mProgram.setHostValue("color_ratio", color_ratio);

        updateParameters();
    
public voidinitProgram(android.filterfw.core.FilterContext context, int target)

        switch (target) {
            case FrameFormat.TARGET_GPU:
                ShaderProgram shaderProgram = new ShaderProgram(context, mTintShader);
                shaderProgram.setMaximumTileSize(mTileSize);
                mProgram = shaderProgram;
                break;

            default:
                throw new RuntimeException("Filter Sharpen does not support frames of " +
                    "target " + target + "!");
        }
        mTarget = target;
    
public voidprocess(android.filterfw.core.FilterContext context)

        // Get input frame
        Frame input = pullInput("image");
        FrameFormat inputFormat = input.getFormat();

        // Create program if not created already
        if (mProgram == null || inputFormat.getTarget() != mTarget) {
            initProgram(context, inputFormat.getTarget());
            initParameters();
        }

        // Create output frame
        Frame output = context.getFrameManager().newFrame(inputFormat);

        // Process
        mProgram.process(input, output);

        // Push output
        pushOutput("image", output);

        // Release pushed frame
        output.release();
    
public voidsetupPorts()

        addMaskedInputPort("image", ImageFormat.create(ImageFormat.COLORSPACE_RGBA));
        addOutputBasedOnInput("image", "image");
    
private voidupdateParameters()

        float tint_color[] = {Color.red(mTint) / 255f,
                              Color.green(mTint) / 255f,
                              Color.blue(mTint) / 255f };

        mProgram.setHostValue("tint", tint_color);