FileDocCategorySizeDatePackage
CropRectFilter.javaAPI DocAndroid 5.1 API4468Thu Mar 12 22:22:30 GMT 2015android.filterpacks.imageproc

CropRectFilter

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

Fields Summary
private int
mXorigin
private int
mYorigin
private int
mOutputWidth
private int
mOutputHeight
private int
mTileSize
private android.filterfw.core.Program
mProgram
private int
mWidth
private int
mHeight
private int
mTarget
Constructors Summary
public CropRectFilter(String name)


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

        if (mProgram != null) {
            updateSourceRect(mWidth, mHeight);
        }
    
public voidinitProgram(android.filterfw.core.FilterContext context, int target)

        switch (target) {
            case FrameFormat.TARGET_GPU:
                ShaderProgram shaderProgram = ShaderProgram.createIdentity(context);
                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 output frame
        FrameFormat outputFormat = ImageFormat.create(mOutputWidth, mOutputHeight,
                                                      ImageFormat.COLORSPACE_RGBA,
                                                      FrameFormat.TARGET_GPU);
        Frame output = context.getFrameManager().newFrame(outputFormat);

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

        // Check if the frame size has changed
        if (inputFormat.getWidth() != mWidth || inputFormat.getHeight() != mHeight) {
            updateSourceRect(inputFormat.getWidth(), inputFormat.getHeight());
        }

        // 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");
    
voidupdateSourceRect(int width, int height)

        mWidth = width;
        mHeight = height;

        /*
        Log.e("CropFilter", mWidth + ", " + mHeight + ", " +
                            (float) mXorigin / mWidth + ", " +
                            (float) mYorigin / mHeight + ", " +
                            (float) mOutputWidth / mWidth + ", " +
                            (float) mOutputHeight / mHeight);
        */

        ((ShaderProgram) mProgram).setSourceRect((float) mXorigin / mWidth,
                                                 (float) mYorigin / mHeight,
                                                 (float) mOutputWidth / mWidth,
                                                 (float) mOutputHeight / mHeight);