FileDocCategorySizeDatePackage
CropFilter.javaAPI DocAndroid 5.1 API4732Thu Mar 12 22:22:30 GMT 2015android.filterpacks.imageproc

CropFilter

public class CropFilter extends android.filterfw.core.Filter
hide

Fields Summary
private android.filterfw.core.Program
mProgram
private android.filterfw.core.FrameFormat
mLastFormat
private int
mOutputWidth
private int
mOutputHeight
private boolean
mFillBlack
private final String
mFragShader
Constructors Summary
public CropFilter(String name)


       
        super(name);
    
Methods Summary
protected voidcreateProgram(android.filterfw.core.FilterContext context, android.filterfw.core.FrameFormat format)

        // TODO: Add CPU version
        if (mLastFormat != null && mLastFormat.getTarget() == format.getTarget()) return;
        mLastFormat = format;
        mProgram = null;
        switch (format.getTarget()) {
            case FrameFormat.TARGET_GPU:
              if(mFillBlack)
                mProgram = new ShaderProgram(context, mFragShader);
              else
                mProgram = ShaderProgram.createIdentity(context);

                break;
        }
        if (mProgram == null) {
            throw new RuntimeException("Could not create a program for crop filter " + this + "!");
        }
    
public android.filterfw.core.FrameFormatgetOutputFormat(java.lang.String portName, android.filterfw.core.FrameFormat inputFormat)

        // Make sure output size is set to unspecified, as we do not know what we will be resizing
        // to.
        MutableFrameFormat outputFormat = inputFormat.mutableCopy();
        outputFormat.setDimensions(FrameFormat.SIZE_UNSPECIFIED, FrameFormat.SIZE_UNSPECIFIED);
        return outputFormat;
    
public voidprocess(android.filterfw.core.FilterContext env)

        // Get input frame
        Frame imageFrame = pullInput("image");
        Frame boxFrame = pullInput("box");

        createProgram(env, imageFrame.getFormat());

        // Get the box
        Quad box = (Quad)boxFrame.getObjectValue();

        // Create output format
        MutableFrameFormat outputFormat = imageFrame.getFormat().mutableCopy();
        outputFormat.setDimensions(mOutputWidth == -1 ? outputFormat.getWidth() : mOutputWidth,
                                   mOutputHeight == -1 ? outputFormat.getHeight() : mOutputHeight);

        // Create output frame
        Frame output = env.getFrameManager().newFrame(outputFormat);

        // Set the program parameters
        if (mProgram instanceof ShaderProgram) {
            ShaderProgram shaderProgram = (ShaderProgram)mProgram;
            shaderProgram.setSourceRegion(box);
        }

        mProgram.process(imageFrame, output);

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

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


    
       
        addMaskedInputPort("image", ImageFormat.create(ImageFormat.COLORSPACE_RGBA));
        addMaskedInputPort("box", ObjectFormat.fromClass(Quad.class, FrameFormat.TARGET_SIMPLE));
        addOutputBasedOnInput("image", "image");