Search in sources :

Example 31 with Quad

use of android.filterfw.geometry.Quad in project platform_frameworks_base by android.

the class CropFilter method process.

@Override
public void process(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();
}
Also used : Quad(android.filterfw.geometry.Quad) Frame(android.filterfw.core.Frame) ShaderProgram(android.filterfw.core.ShaderProgram) MutableFrameFormat(android.filterfw.core.MutableFrameFormat)

Example 32 with Quad

use of android.filterfw.geometry.Quad in project platform_frameworks_base by android.

the class RotateFilter method updateParameters.

private void updateParameters() {
    float sinTheta;
    float cosTheta;
    if (mAngle % 90 == 0) {
        if (mAngle % 180 == 0) {
            sinTheta = 0f;
            cosTheta = (mAngle % 360 == 0) ? 1f : -1f;
        } else {
            cosTheta = 0f;
            sinTheta = ((mAngle + 90) % 360 == 0) ? -1f : 1f;
            mOutputWidth = mHeight;
            mOutputHeight = mWidth;
        }
    } else {
        throw new RuntimeException("degree has to be multiply of 90.");
    }
    Point x0 = new Point(0.5f * (-cosTheta + sinTheta + 1f), 0.5f * (-sinTheta - cosTheta + 1f));
    Point x1 = new Point(0.5f * (cosTheta + sinTheta + 1f), 0.5f * (sinTheta - cosTheta + 1f));
    Point x2 = new Point(0.5f * (-cosTheta - sinTheta + 1f), 0.5f * (-sinTheta + cosTheta + 1f));
    Point x3 = new Point(0.5f * (cosTheta - sinTheta + 1f), 0.5f * (sinTheta + cosTheta + 1f));
    Quad quad = new Quad(x0, x1, x2, x3);
    ((ShaderProgram) mProgram).setTargetRegion(quad);
}
Also used : Quad(android.filterfw.geometry.Quad) ShaderProgram(android.filterfw.core.ShaderProgram) Point(android.filterfw.geometry.Point)

Example 33 with Quad

use of android.filterfw.geometry.Quad in project platform_frameworks_base by android.

the class DrawOverlayFilter method process.

@Override
public void process(FilterContext env) {
    // Get input frame
    Frame sourceFrame = pullInput("source");
    Frame overlayFrame = pullInput("overlay");
    Frame boxFrame = pullInput("box");
    // Get the box
    Quad box = (Quad) boxFrame.getObjectValue();
    box = box.translated(1.0f, 1.0f).scaled(2.0f);
    mProgram.setTargetRegion(box);
    // Create output frame with copy of input
    Frame output = env.getFrameManager().newFrame(sourceFrame.getFormat());
    output.setDataFromFrame(sourceFrame);
    // Draw onto output
    mProgram.process(overlayFrame, output);
    // Push output
    pushOutput("image", output);
    // Release pushed frame
    output.release();
}
Also used : Quad(android.filterfw.geometry.Quad) Frame(android.filterfw.core.Frame)

Example 34 with Quad

use of android.filterfw.geometry.Quad in project android_frameworks_base by AOSPA.

the class CropFilter method process.

@Override
public void process(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();
}
Also used : Quad(android.filterfw.geometry.Quad) Frame(android.filterfw.core.Frame) ShaderProgram(android.filterfw.core.ShaderProgram) MutableFrameFormat(android.filterfw.core.MutableFrameFormat)

Example 35 with Quad

use of android.filterfw.geometry.Quad in project android_frameworks_base by AOSPA.

the class DrawOverlayFilter method process.

@Override
public void process(FilterContext env) {
    // Get input frame
    Frame sourceFrame = pullInput("source");
    Frame overlayFrame = pullInput("overlay");
    Frame boxFrame = pullInput("box");
    // Get the box
    Quad box = (Quad) boxFrame.getObjectValue();
    box = box.translated(1.0f, 1.0f).scaled(2.0f);
    mProgram.setTargetRegion(box);
    // Create output frame with copy of input
    Frame output = env.getFrameManager().newFrame(sourceFrame.getFormat());
    output.setDataFromFrame(sourceFrame);
    // Draw onto output
    mProgram.process(overlayFrame, output);
    // Push output
    pushOutput("image", output);
    // Release pushed frame
    output.release();
}
Also used : Quad(android.filterfw.geometry.Quad) Frame(android.filterfw.core.Frame)

Aggregations

Quad (android.filterfw.geometry.Quad)42 Frame (android.filterfw.core.Frame)24 ShaderProgram (android.filterfw.core.ShaderProgram)18 Point (android.filterfw.geometry.Point)18 MutableFrameFormat (android.filterfw.core.MutableFrameFormat)12 GLFrame (android.filterfw.core.GLFrame)7 FrameFormat (android.filterfw.core.FrameFormat)6 NativeFrame (android.filterfw.core.NativeFrame)3