FileDocCategorySizeDatePackage
BlackWhiteFilter.javaAPI DocAndroid 5.1 API6054Thu Mar 12 22:22:30 GMT 2015android.filterpacks.imageproc

BlackWhiteFilter

public class BlackWhiteFilter extends android.filterfw.core.Filter

Fields Summary
private float
mBlack
private float
mWhite
private int
mTileSize
private android.filterfw.core.Program
mProgram
private Random
mRandom
private int
mTarget
private final String
mBlackWhiteShader
Constructors Summary
public BlackWhiteFilter(String name)


       
        super(name);
        mRandom = new Random(new Date().getTime());
    
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;
    
public voidinitProgram(android.filterfw.core.FilterContext context, int target)

        switch (target) {
            case FrameFormat.TARGET_GPU:
                ShaderProgram shaderProgram = new ShaderProgram(context, mBlackWhiteShader);
                shaderProgram.setMaximumTileSize(mTileSize);
                mProgram = shaderProgram;
                updateParameters();
                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());
        }

        // 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 scale = (mBlack != mWhite) ? 1.0f / (mWhite - mBlack) : 2000f;
        float stepsize = 1.0f / 255.0f;
        mProgram.setHostValue("black", mBlack);
        mProgram.setHostValue("scale", scale);
        mProgram.setHostValue("stepsize", stepsize);

        float seed[] = { mRandom.nextFloat(), mRandom.nextFloat() };
        mProgram.setHostValue("seed", seed);