use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by ResurrectionRemix.
the class ExposureFilter method onProcess.
@Override
protected void onProcess() {
FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
float overExposedPixels, underExposedPixels;
ByteBuffer inputBuffer = inputImage.lockBytes(Frame.MODE_READ);
overExposedPixels = overExposureOperator(inputImage.getWidth(), inputImage.getHeight(), inputBuffer);
underExposedPixels = underExposureOperator(inputImage.getWidth(), inputImage.getHeight(), inputBuffer);
inputImage.unlock();
if (mLogVerbose)
Log.v(TAG, "underExposedPixelCount: " + underExposedPixels);
OutputPort underPort = getConnectedOutputPort("underExposedNum");
if (underPort != null) {
FrameValue underOutFrame = underPort.fetchAvailableFrame(null).asFrameValue();
underOutFrame.setValue(underExposedPixels * inputImage.getWidth() * inputImage.getHeight());
underPort.pushFrame(underOutFrame);
}
OutputPort underPort2 = getConnectedOutputPort("underExposureRating");
FrameValue underOutFrame2 = underPort2.fetchAvailableFrame(null).asFrameValue();
underOutFrame2.setValue(underExposedPixels);
underPort2.pushFrame(underOutFrame2);
if (mLogVerbose)
Log.v(TAG, "overExposedPixelCount: " + overExposedPixels);
OutputPort overPort = getConnectedOutputPort("overExposedNum");
if (overPort != null) {
FrameValue overOutFrame = overPort.fetchAvailableFrame(null).asFrameValue();
overOutFrame.setValue(overExposedPixels * inputImage.getWidth() * inputImage.getHeight());
overPort.pushFrame(overOutFrame);
}
OutputPort overPort2 = getConnectedOutputPort("overExposureRating");
FrameValue overOutFrame2 = overPort2.fetchAvailableFrame(null).asFrameValue();
overOutFrame2.setValue(overExposedPixels);
overPort2.pushFrame(overOutFrame2);
}
use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by ResurrectionRemix.
the class FaceSquareFilter method onProcess.
/**
* @see androidx.media.filterfw.Filter#onProcess()
*/
@Override
protected void onProcess() {
// Get inputs
FrameImage2D imageFrame = getConnectedInputPort("image").pullFrame().asFrameImage2D();
FrameValues facesFrame = getConnectedInputPort("faces").pullFrame().asFrameValues();
Face[] faces = (Face[]) facesFrame.getValues();
int[] dims = imageFrame.getDimensions();
ByteBuffer buffer = imageFrame.lockBytes(Frame.MODE_WRITE);
byte[] pixels = buffer.array();
// For every face in faces, draw a white rect around the
// face following the rect member of the Face
drawBoxes(pixels, faces, dims);
imageFrame.unlock();
OutputPort outPort = getConnectedOutputPort("image");
outPort.pushFrame(imageFrame);
}
use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by ResurrectionRemix.
the class ContrastRatioFilterTest method testContrastFilter.
public void testContrastFilter() throws Exception {
final int INPUT_WIDTH = 480;
final int INPUT_HEIGHT = 640;
FrameImage2D image = createFrame(FrameType.image2D(FrameType.ELEMENT_RGBA8888, FrameType.READ_CPU), new int[] { INPUT_WIDTH, INPUT_HEIGHT }).asFrameImage2D();
Bitmap bitmap = BitmapFactory.decodeStream(assetMgr.open("0002_000390.jpg"));
image.setBitmap(bitmap);
injectInputFrame("image", image);
process();
final float EXPECTED_RESULT = 0.29901487f;
assertEquals(EXPECTED_RESULT, ((Float) getOutputFrame("contrastRating").asFrameValue().getValue()).floatValue(), 0.001f);
}
use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by crdroidandroid.
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 crdroidandroid.
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);
}
Aggregations