Search in sources :

Example 11 with Quad

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

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 12 with Quad

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

the class MediaEncoderFilter method updateSourceRegion.

private void updateSourceRegion() {
    // Flip source quad to map to OpenGL origin
    Quad flippedRegion = new Quad();
    flippedRegion.p0 = mSourceRegion.p2;
    flippedRegion.p1 = mSourceRegion.p3;
    flippedRegion.p2 = mSourceRegion.p0;
    flippedRegion.p3 = mSourceRegion.p1;
    mProgram.setSourceRegion(flippedRegion);
}
Also used : Quad(android.filterfw.geometry.Quad)

Example 13 with Quad

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

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 14 with Quad

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

the class DrawRectFilter method process.

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

Example 15 with Quad

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

the class StraightenFilter method updateParameters.

private void updateParameters() {
    float cosTheta = (float) Math.cos(mAngle * DEGREE_TO_RADIAN);
    float sinTheta = (float) Math.sin(mAngle * DEGREE_TO_RADIAN);
    if (mMaxAngle <= 0)
        throw new RuntimeException("Max angle is out of range (0-180).");
    mMaxAngle = (mMaxAngle > 90) ? 90 : mMaxAngle;
    Point p0 = new Point(-cosTheta * mWidth + sinTheta * mHeight, -sinTheta * mWidth - cosTheta * mHeight);
    Point p1 = new Point(cosTheta * mWidth + sinTheta * mHeight, sinTheta * mWidth - cosTheta * mHeight);
    Point p2 = new Point(-cosTheta * mWidth - sinTheta * mHeight, -sinTheta * mWidth + cosTheta * mHeight);
    Point p3 = new Point(cosTheta * mWidth - sinTheta * mHeight, sinTheta * mWidth + cosTheta * mHeight);
    float maxWidth = (float) Math.max(Math.abs(p0.x), Math.abs(p1.x));
    float maxHeight = (float) Math.max(Math.abs(p0.y), Math.abs(p1.y));
    float scale = 0.5f * Math.min(mWidth / maxWidth, mHeight / maxHeight);
    p0.set(scale * p0.x / mWidth + 0.5f, scale * p0.y / mHeight + 0.5f);
    p1.set(scale * p1.x / mWidth + 0.5f, scale * p1.y / mHeight + 0.5f);
    p2.set(scale * p2.x / mWidth + 0.5f, scale * p2.y / mHeight + 0.5f);
    p3.set(scale * p3.x / mWidth + 0.5f, scale * p3.y / mHeight + 0.5f);
    Quad quad = new Quad(p0, p1, p2, p3);
    ((ShaderProgram) mProgram).setSourceRegion(quad);
}
Also used : Quad(android.filterfw.geometry.Quad) ShaderProgram(android.filterfw.core.ShaderProgram) Point(android.filterfw.geometry.Point)

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