FileDocCategorySizeDatePackage
SaturateFilter.javaAPI DocAndroid 5.1 API5612Thu Mar 12 22:22:30 GMT 2015android.filterpacks.imageproc

SaturateFilter

public class SaturateFilter extends android.filterfw.core.Filter

Fields Summary
private float
mScale
private int
mTileSize
private android.filterfw.core.Program
mBenProgram
private android.filterfw.core.Program
mHerfProgram
private int
mTarget
private final String
mBenSaturateShader
private final String
mHerfSaturateShader
Constructors Summary
public SaturateFilter(String name)



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

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

        return inputFormat;
    
private voidinitParameters()

        float shift = 1.0f / 255.0f;
        float weights[] = { 2f/8f, 5f/8f, 1f/8f};

        mBenProgram.setHostValue("weights", weights);
        mBenProgram.setHostValue("shift", shift);

        mHerfProgram.setHostValue("weights", weights);

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

        switch (target) {
            case FrameFormat.TARGET_GPU:
                ShaderProgram shaderProgram = new ShaderProgram(context, mBenSaturateShader);
                shaderProgram.setMaximumTileSize(mTileSize);
                mBenProgram = shaderProgram;

                shaderProgram = new ShaderProgram(context, mHerfSaturateShader);
                shaderProgram.setMaximumTileSize(mTileSize);
                mHerfProgram = 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 (mBenProgram == null || inputFormat.getTarget() != mTarget) {
            initProgram(context, inputFormat.getTarget());
            initParameters();
        }

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

        // Process
        if (mScale > 0.0f) {
            mHerfProgram.process(input, output);
        } else {
            mBenProgram.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()


        if (mScale > 0.0f) {
            float exponents[] = new float[3];

            exponents[0] = (0.9f * mScale) + 1.0f;
            exponents[1] = (2.1f * mScale) + 1.0f;
            exponents[2] = (2.7f * mScale) + 1.0f;

            mHerfProgram.setHostValue("exponents", exponents);
        } else {
            mBenProgram.setHostValue("scale", 1.0f + mScale);
        }