use of androidx.media.filterfw.FrameBuffer2D in project platform_frameworks_base by android.
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.FrameBuffer2D in project android_frameworks_base by ResurrectionRemix.
the class StatsFilter method onProcess.
/**
* @see androidx.media.filterfw.Filter#onProcess()
*/
@Override
protected void onProcess() {
FrameBuffer2D inputFrame = getConnectedInputPort("buffer").pullFrame().asFrameImage2D();
ByteBuffer pixelBuffer = inputFrame.lockBytes(Frame.MODE_READ);
calcMeanAndStd(pixelBuffer, inputFrame.getWidth(), inputFrame.getHeight(), mCropRect);
inputFrame.unlock();
OutputPort outPort = getConnectedOutputPort("mean");
FrameValue outFrame = outPort.fetchAvailableFrame(null).asFrameValue();
outFrame.setValue(mStats[MEAN_INDEX]);
outPort.pushFrame(outFrame);
OutputPort outPortStdev = getConnectedOutputPort("stdev");
FrameValue outFrameStdev = outPortStdev.fetchAvailableFrame(null).asFrameValue();
outFrameStdev.setValue(mStats[STDEV_INDEX]);
outPortStdev.pushFrame(outFrameStdev);
}
use of androidx.media.filterfw.FrameBuffer2D in project android_frameworks_base by ResurrectionRemix.
the class IfElseFilter method onProcess.
@Override
protected void onProcess() {
OutputPort outPort = getConnectedOutputPort("output");
FrameImage2D trueFrame = getConnectedInputPort("trueResult").pullFrame().asFrameImage2D();
FrameImage2D falseFrame = getConnectedInputPort("falseResult").pullFrame().asFrameImage2D();
FrameValue boolFrameValue = getConnectedInputPort("condition").pullFrame().asFrameValue();
boolean condition = (Boolean) boolFrameValue.getValue();
FrameBuffer2D outputFrame;
// If the condition is true, then we want to use the camera, else use the gallery
if (condition) {
outputFrame = trueFrame;
} else {
outputFrame = falseFrame;
}
outPort.pushFrame(outputFrame);
}
use of androidx.media.filterfw.FrameBuffer2D in project android_frameworks_base by crdroidandroid.
the class NewChromaHistogramFilter method onProcess.
@Override
protected void onProcess() {
FrameBuffer2D imageFrame = getConnectedInputPort("image").pullFrame().asFrameImage2D();
OutputPort outPort = getConnectedOutputPort("histogram");
mValueBins = mHueBins;
int[] outDims = new int[] { mHueBins, mSaturationBins + 1 };
FrameBuffer2D histogramFrame = outPort.fetchAvailableFrame(outDims).asFrameBuffer2D();
ByteBuffer imageBuffer = imageFrame.lockBytes(Frame.MODE_READ);
ByteBuffer histogramBuffer = histogramFrame.lockBytes(Frame.MODE_READ);
histogramBuffer.order(ByteOrder.nativeOrder());
FloatBuffer floatHistogram = histogramBuffer.asFloatBuffer();
// Run native method
extractChromaHistogram(imageBuffer, floatHistogram, mHueBins, mSaturationBins, mValueBins, mSaturationThreshold, mValueThreshold);
imageFrame.unlock();
histogramFrame.unlock();
outPort.pushFrame(histogramFrame);
}
use of androidx.media.filterfw.FrameBuffer2D in project android_frameworks_base by crdroidandroid.
the class StatsFilter method onProcess.
/**
* @see androidx.media.filterfw.Filter#onProcess()
*/
@Override
protected void onProcess() {
FrameBuffer2D inputFrame = getConnectedInputPort("buffer").pullFrame().asFrameImage2D();
ByteBuffer pixelBuffer = inputFrame.lockBytes(Frame.MODE_READ);
calcMeanAndStd(pixelBuffer, inputFrame.getWidth(), inputFrame.getHeight(), mCropRect);
inputFrame.unlock();
OutputPort outPort = getConnectedOutputPort("mean");
FrameValue outFrame = outPort.fetchAvailableFrame(null).asFrameValue();
outFrame.setValue(mStats[MEAN_INDEX]);
outPort.pushFrame(outFrame);
OutputPort outPortStdev = getConnectedOutputPort("stdev");
FrameValue outFrameStdev = outPortStdev.fetchAvailableFrame(null).asFrameValue();
outFrameStdev.setValue(mStats[STDEV_INDEX]);
outPortStdev.pushFrame(outFrameStdev);
}
Aggregations