use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by DirtyUnicorns.
the class ToGrayValuesFilter method onProcess.
@Override
protected void onProcess() {
OutputPort outPort = getConnectedOutputPort("image");
FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
int[] dim = inputImage.getDimensions();
FrameBuffer2D outputFrame;
ByteBuffer grayBuffer;
if (isOpenGLSupported()) {
// crop out the portion of inputImage that will be used to generate outputFrame.
int modular = dim[0] % 4;
int[] outDim = new int[] { dim[0] - modular, dim[1] };
outputFrame = outPort.fetchAvailableFrame(outDim).asFrameBuffer2D();
grayBuffer = outputFrame.lockBytes(Frame.MODE_WRITE);
int[] targetDims = new int[] { outDim[0] / 4, outDim[1] };
FrameImage2D targetFrame = Frame.create(mImageInType, targetDims).asFrameImage2D();
mShader.setSourceQuad(Quad.fromRect(0f, 0f, ((float) outDim[0]) / dim[0], 1f));
mShader.setUniformValue("pix_stride", 1f / outDim[0]);
mShader.process(inputImage, targetFrame);
RenderTarget grayTarget = targetFrame.lockRenderTarget();
grayTarget.readPixelData(grayBuffer, targetDims[0], targetDims[1]);
targetFrame.unlock();
targetFrame.release();
} else {
outputFrame = outPort.fetchAvailableFrame(dim).asFrameBuffer2D();
grayBuffer = outputFrame.lockBytes(Frame.MODE_WRITE);
ByteBuffer inputBuffer = inputImage.lockBytes(Frame.MODE_READ);
if (!toGrayValues(inputBuffer, grayBuffer)) {
throw new RuntimeException("Native implementation encountered an error during processing!");
}
inputImage.unlock();
}
outputFrame.unlock();
outPort.pushFrame(outputFrame);
}
use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by DirtyUnicorns.
the class BrightnessFilter method onProcess.
@Override
protected void onProcess() {
OutputPort outPort = getConnectedOutputPort("image");
FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
int[] dim = inputImage.getDimensions();
FrameImage2D outputImage = outPort.fetchAvailableFrame(dim).asFrameImage2D();
mShader.setUniformValue("brightness", mBrightness);
mShader.process(inputImage, outputImage);
outPort.pushFrame(outputImage);
}
use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by DirtyUnicorns.
the class CropFilter method onProcess.
@Override
protected void onProcess() {
OutputPort outPort = getConnectedOutputPort("image");
// Pull input frame
FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
int[] inDims = inputImage.getDimensions();
int[] croppedDims = { (int) Math.ceil(mCropRect.xEdge().length() * inDims[0]), (int) Math.ceil(mCropRect.yEdge().length() * inDims[1]) };
int[] outDims = { getOutputWidth(croppedDims[0], croppedDims[1]), getOutputHeight(croppedDims[0], croppedDims[1]) };
FrameImage2D outputImage = outPort.fetchAvailableFrame(outDims).asFrameImage2D();
if (isOpenGLSupported()) {
FrameImage2D sourceFrame;
Quad sourceQuad = null;
boolean scaleDown = (outDims[0] < croppedDims[0]) || (outDims[1] < croppedDims[1]);
if (scaleDown && mUseMipmaps) {
mPow2Frame = TransformUtils.makeMipMappedFrame(mPow2Frame, croppedDims);
int[] extDims = mPow2Frame.getDimensions();
float targetWidth = croppedDims[0] / (float) extDims[0];
float targetHeight = croppedDims[1] / (float) extDims[1];
Quad targetQuad = Quad.fromRect(0f, 0f, targetWidth, targetHeight);
mShader.setSourceQuad(mCropRect);
mShader.setTargetQuad(targetQuad);
mShader.process(inputImage, mPow2Frame);
TransformUtils.generateMipMaps(mPow2Frame);
sourceFrame = mPow2Frame;
sourceQuad = targetQuad;
} else {
sourceFrame = inputImage;
sourceQuad = mCropRect;
}
mShader.setSourceQuad(sourceQuad);
mShader.setTargetRect(0f, 0f, 1f, 1f);
mShader.process(sourceFrame, outputImage);
} else {
// Convert quads to canvas coordinate space
Quad sourceQuad = mCropRect.scale2(inDims[0], inDims[1]);
Quad targetQuad = Quad.fromRect(0f, 0f, inDims[0], inDims[1]);
// Calculate transform for crop
Matrix transform = Quad.getTransform(sourceQuad, targetQuad);
transform.postScale(outDims[0] / (float) inDims[0], outDims[1] / (float) inDims[1]);
// Create target canvas
Bitmap.Config config = Bitmap.Config.ARGB_8888;
Bitmap cropped = Bitmap.createBitmap(outDims[0], outDims[1], config);
Canvas canvas = new Canvas(cropped);
// Draw source bitmap into target canvas
Paint paint = new Paint();
paint.setFilterBitmap(true);
Bitmap sourceBitmap = inputImage.toBitmap();
canvas.drawBitmap(sourceBitmap, transform, paint);
// Assign bitmap to output frame
outputImage.setBitmap(cropped);
}
outPort.pushFrame(outputImage);
}
use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by ResurrectionRemix.
the class ToGrayValuesFilter method onProcess.
@Override
protected void onProcess() {
OutputPort outPort = getConnectedOutputPort("image");
FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
int[] dim = inputImage.getDimensions();
FrameBuffer2D outputFrame;
ByteBuffer grayBuffer;
if (isOpenGLSupported()) {
// crop out the portion of inputImage that will be used to generate outputFrame.
int modular = dim[0] % 4;
int[] outDim = new int[] { dim[0] - modular, dim[1] };
outputFrame = outPort.fetchAvailableFrame(outDim).asFrameBuffer2D();
grayBuffer = outputFrame.lockBytes(Frame.MODE_WRITE);
int[] targetDims = new int[] { outDim[0] / 4, outDim[1] };
FrameImage2D targetFrame = Frame.create(mImageInType, targetDims).asFrameImage2D();
mShader.setSourceQuad(Quad.fromRect(0f, 0f, ((float) outDim[0]) / dim[0], 1f));
mShader.setUniformValue("pix_stride", 1f / outDim[0]);
mShader.process(inputImage, targetFrame);
RenderTarget grayTarget = targetFrame.lockRenderTarget();
grayTarget.readPixelData(grayBuffer, targetDims[0], targetDims[1]);
targetFrame.unlock();
targetFrame.release();
} else {
outputFrame = outPort.fetchAvailableFrame(dim).asFrameBuffer2D();
grayBuffer = outputFrame.lockBytes(Frame.MODE_WRITE);
ByteBuffer inputBuffer = inputImage.lockBytes(Frame.MODE_READ);
if (!toGrayValues(inputBuffer, grayBuffer)) {
throw new RuntimeException("Native implementation encountered an error during processing!");
}
inputImage.unlock();
}
outputFrame.unlock();
outPort.pushFrame(outputFrame);
}
use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by ResurrectionRemix.
the class ContrastRatioFilter method onProcess.
@Override
protected void onProcess() {
FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
float contrastRatio;
ByteBuffer inputBuffer = inputImage.lockBytes(Frame.MODE_READ);
contrastRatio = contrastOperator(inputImage.getWidth(), inputImage.getHeight(), inputBuffer);
inputImage.unlock();
if (mLogVerbose)
Log.v(TAG, "contrastRatio: " + contrastRatio);
OutputPort contrastToGoodnessPort = getConnectedOutputPort("contrastRatingToGoodness");
FrameValue contrastOutFrame2 = contrastToGoodnessPort.fetchAvailableFrame(null).asFrameValue();
contrastOutFrame2.setValue(contrastRatio);
contrastToGoodnessPort.pushFrame(contrastOutFrame2);
}
Aggregations