FileDocCategorySizeDatePackage
FixedRotationFilter.javaAPI DocAndroid 5.1 API3614Thu Mar 12 22:22:30 GMT 2015android.filterpacks.imageproc

FixedRotationFilter

public class FixedRotationFilter extends android.filterfw.core.Filter
The FixedRotationFilter rotates the input image clockwise, it only accepts 4 rotation angles: 0, 90, 180, 270
hide

Fields Summary
private int
mRotation
private android.filterfw.core.ShaderProgram
mProgram
Constructors Summary
public FixedRotationFilter(String name)


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

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

        Frame input = pullInput("image");
        if (mRotation == 0) {
            pushOutput("image", input);
            return;
        }
        FrameFormat inputFormat = input.getFormat();

        // Create program if not created already
        if (mProgram == null) {
            mProgram = ShaderProgram.createIdentity(context);
        }
        MutableFrameFormat outputFormat = inputFormat.mutableCopy();
        int width = inputFormat.getWidth();
        int height = inputFormat.getHeight();
        Point p1 = new Point(0.0f, 0.0f);
        Point p2 = new Point(1.0f, 0.0f);
        Point p3 = new Point(0.0f, 1.0f);
        Point p4 = new Point(1.0f, 1.0f);
        Quad sourceRegion;
        switch (((int)Math.round(mRotation / 90f)) % 4) {
            case 1:
                sourceRegion = new Quad(p3,p1,p4,p2);
                outputFormat.setDimensions(height, width);
                break;
            case 2:
                sourceRegion = new Quad(p4,p3,p2,p1);
                break;
            case 3:
                sourceRegion = new Quad(p2,p4,p1,p3);
                outputFormat.setDimensions(height, width);
                break;
            case 0:
            default:
                sourceRegion = new Quad(p1,p2,p3,p4);
                break;
        }
        // Create output frame
        Frame output = context.getFrameManager().newFrame(outputFormat);

        // Set the source region
        mProgram.setSourceRegion(sourceRegion);

        // Process
        mProgram.process(input, output);

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

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

        addMaskedInputPort("image", ImageFormat.create(ImageFormat.COLORSPACE_RGBA,
                                                       FrameFormat.TARGET_GPU));
        addOutputBasedOnInput("image", "image");