Search in sources :

Example 26 with Point

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

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 27 with Point

use of android.filterfw.geometry.Point in project android_frameworks_base by crdroidandroid.

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 28 with Point

use of android.filterfw.geometry.Point in project android_frameworks_base by crdroidandroid.

the class Rectangle method fromCenterVerticalAxis.

public static Rectangle fromCenterVerticalAxis(Point center, Point vAxis, Point size) {
    Point dy = vAxis.scaledTo(size.y / 2.0f);
    Point dx = vAxis.rotated90(1).scaledTo(size.x / 2.0f);
    return new Rectangle(center.minus(dx).minus(dy), center.plus(dx).minus(dy), center.minus(dx).plus(dy), center.plus(dx).plus(dy));
}
Also used : Point(android.filterfw.geometry.Point)

Example 29 with Point

use of android.filterfw.geometry.Point in project android_frameworks_base by crdroidandroid.

the class Rectangle method fromRotatedRect.

public static Rectangle fromRotatedRect(Point center, Point size, float rotation) {
    Point p0 = new Point(center.x - size.x / 2f, center.y - size.y / 2f);
    Point p1 = new Point(center.x + size.x / 2f, center.y - size.y / 2f);
    Point p2 = new Point(center.x - size.x / 2f, center.y + size.y / 2f);
    Point p3 = new Point(center.x + size.x / 2f, center.y + size.y / 2f);
    return new Rectangle(p0.rotatedAround(center, rotation), p1.rotatedAround(center, rotation), p2.rotatedAround(center, rotation), p3.rotatedAround(center, rotation));
}
Also used : Point(android.filterfw.geometry.Point)

Example 30 with Point

use of android.filterfw.geometry.Point in project android_frameworks_base by crdroidandroid.

the class FixedRotationFilter method process.

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

Aggregations

Point (android.filterfw.geometry.Point)30 Quad (android.filterfw.geometry.Quad)18 ShaderProgram (android.filterfw.core.ShaderProgram)12 Frame (android.filterfw.core.Frame)6 FrameFormat (android.filterfw.core.FrameFormat)6 MutableFrameFormat (android.filterfw.core.MutableFrameFormat)6