FileDocCategorySizeDatePackage
DrawRectFilter.javaAPI DocAndroid 5.1 API3979Thu Mar 12 22:22:30 GMT 2015android.filterpacks.imageproc

DrawRectFilter

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

Fields Summary
private float
mColorRed
private float
mColorGreen
private float
mColorBlue
private final String
mVertexShader
private final String
mFixedColorFragmentShader
private android.filterfw.core.ShaderProgram
mProgram
Constructors Summary
public DrawRectFilter(String name)



       
        super(name);
    
Methods Summary
public android.filterfw.core.FrameFormatgetOutputFormat(java.lang.String portName, android.filterfw.core.FrameFormat inputFormat)

        return inputFormat;
    
public voidprepare(android.filterfw.core.FilterContext context)

        mProgram = new ShaderProgram(context, mVertexShader, mFixedColorFragmentShader);
    
public voidprocess(android.filterfw.core.FilterContext env)

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

        // Get the box
        Quad box = (Quad)boxFrame.getObjectValue();
        box = box.scaled(2.0f).translated(-1.0f, -1.0f);

        // Create output frame with copy of input
        GLFrame output = (GLFrame)env.getFrameManager().duplicateFrame(imageFrame);

        // Draw onto output
        output.focus();
        renderBox(box);

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

        // Release pushed frame
        output.release();
    
private voidrenderBox(android.filterfw.geometry.Quad box)

        final int FLOAT_SIZE = 4;

        // Get current values
        float[] color = {mColorRed, mColorGreen, mColorBlue, 1f};
        float[] vertexValues = { box.p0.x, box.p0.y,
                                 box.p1.x, box.p1.y,
                                 box.p3.x, box.p3.y,
                                 box.p2.x, box.p2.y };

        // Set the program variables
        mProgram.setHostValue("color", color);
        mProgram.setAttributeValues("aPosition", vertexValues, 2);
        mProgram.setVertexCount(4);

        // Draw
        mProgram.beginDrawing();
        GLES20.glLineWidth(1.0f);
        GLES20.glDrawArrays(GLES20.GL_LINE_LOOP, 0, 4);
    
public voidsetupPorts()

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