use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by DirtyUnicorns.
the class IfElseFilterTest method testIfElseFilterTrue.
public void testIfElseFilterTrue() throws Exception {
FrameImage2D image = createFrame(FrameType.image2D(FrameType.ELEMENT_RGBA8888, FrameType.READ_CPU), new int[] { BIG_INPUT_WIDTH, BIG_INPUT_HEIGHT }).asFrameImage2D();
FrameImage2D video = createFrame(FrameType.image2D(FrameType.ELEMENT_RGBA8888, FrameType.READ_CPU), new int[] { SMALL_INPUT_WIDTH, SMALL_INPUT_HEIGHT }).asFrameImage2D();
// Image of legs
Bitmap videoBitmap = BitmapFactory.decodeStream(assetMgr.open("0002_000390.jpg"));
// Image of a face
Bitmap imageBitmap = BitmapFactory.decodeStream(assetMgr.open("XZZ019.jpg"));
image.setBitmap(imageBitmap);
injectInputFrame("falseResult", image);
video.setBitmap(videoBitmap);
injectInputFrame("trueResult", video);
FrameValue conditionFrame = createFrame(FrameType.single(boolean.class), new int[] { 1 }).asFrameValue();
conditionFrame.setValue(true);
injectInputFrame("condition", conditionFrame);
process();
// Ensure that for true, we use the video input
FrameImage2D outputImage = getOutputFrame("output").asFrameImage2D();
assertEquals(outputImage, video);
}
use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by DirtyUnicorns.
the class AvgBrightnessFilter method onProcess.
@Override
protected void onProcess() {
FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
float brightness;
ByteBuffer inputBuffer = inputImage.lockBytes(Frame.MODE_READ);
brightness = brightnessOperator(inputImage.getWidth(), inputImage.getHeight(), inputBuffer);
inputImage.unlock();
if (mLogVerbose)
Log.v(TAG, "contrastRatio: " + brightness);
OutputPort brightnessPort = getConnectedOutputPort("brightnessRating");
FrameValue brightnessOutFrame = brightnessPort.fetchAvailableFrame(null).asFrameValue();
brightnessOutFrame.setValue(brightness);
brightnessPort.pushFrame(brightnessOutFrame);
}
use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by DirtyUnicorns.
the class RotateFilter method onProcess.
@Override
protected void onProcess() {
OutputPort outPort = getConnectedOutputPort("image");
FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
int[] inDims = inputImage.getDimensions();
FrameImage2D outputImage = outPort.fetchAvailableFrame(inDims).asFrameImage2D();
mShader.setSourceQuad(mSourceRect);
Quad targetQuad = mSourceRect.rotated((float) (mRotateAngle / 180 * Math.PI));
mShader.setTargetQuad(targetQuad);
mShader.process(inputImage, outputImage);
outPort.pushFrame(outputImage);
}
use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by ResurrectionRemix.
the class SobelFilter method onProcess.
@Override
protected void onProcess() {
OutputPort magnitudePort = getConnectedOutputPort("magnitude");
OutputPort directionPort = getConnectedOutputPort("direction");
FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
int[] inputDims = inputImage.getDimensions();
FrameImage2D magImage = (magnitudePort != null) ? magnitudePort.fetchAvailableFrame(inputDims).asFrameImage2D() : null;
FrameImage2D dirImage = (directionPort != null) ? directionPort.fetchAvailableFrame(inputDims).asFrameImage2D() : null;
if (isOpenGLSupported()) {
FrameImage2D gxFrame = Frame.create(mImageType, inputDims).asFrameImage2D();
FrameImage2D gyFrame = Frame.create(mImageType, inputDims).asFrameImage2D();
mGradientXShader.setUniformValue("pix", new float[] { 1f / inputDims[0], 1f / inputDims[1] });
mGradientYShader.setUniformValue("pix", new float[] { 1f / inputDims[0], 1f / inputDims[1] });
mGradientXShader.process(inputImage, gxFrame);
mGradientYShader.process(inputImage, gyFrame);
FrameImage2D[] gradientFrames = new FrameImage2D[] { gxFrame, gyFrame };
if (magnitudePort != null) {
mMagnitudeShader.processMulti(gradientFrames, magImage);
}
if (directionPort != null) {
mDirectionShader.processMulti(gradientFrames, dirImage);
}
gxFrame.release();
gyFrame.release();
} else {
ByteBuffer inputBuffer = inputImage.lockBytes(Frame.MODE_READ);
ByteBuffer magBuffer = (magImage != null) ? magImage.lockBytes(Frame.MODE_WRITE) : null;
ByteBuffer dirBuffer = (dirImage != null) ? dirImage.lockBytes(Frame.MODE_WRITE) : null;
sobelOperator(inputImage.getWidth(), inputImage.getHeight(), inputBuffer, magBuffer, dirBuffer);
inputImage.unlock();
if (magImage != null) {
magImage.unlock();
}
if (dirImage != null) {
dirImage.unlock();
}
}
if (magImage != null) {
magnitudePort.pushFrame(magImage);
}
if (dirImage != null) {
directionPort.pushFrame(dirImage);
}
}
use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by ResurrectionRemix.
the class RotateFilter method onProcess.
@Override
protected void onProcess() {
OutputPort outPort = getConnectedOutputPort("image");
FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
int[] inDims = inputImage.getDimensions();
FrameImage2D outputImage = outPort.fetchAvailableFrame(inDims).asFrameImage2D();
mShader.setSourceQuad(mSourceRect);
Quad targetQuad = mSourceRect.rotated((float) (mRotateAngle / 180 * Math.PI));
mShader.setTargetQuad(targetQuad);
mShader.process(inputImage, outputImage);
outPort.pushFrame(outputImage);
}
Aggregations