use of android.filterfw.geometry.Quad in project android_frameworks_base by DirtyUnicorns.
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();
}
use of android.filterfw.geometry.Quad in project android_frameworks_base by AOSPA.
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);
}
use of android.filterfw.geometry.Quad in project android_frameworks_base by AOSPA.
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);
}
use of android.filterfw.geometry.Quad in project android_frameworks_base by crdroidandroid.
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);
}
use of android.filterfw.geometry.Quad in project android_frameworks_base by crdroidandroid.
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);
}
Aggregations