use of androidx.media.filterfw.FrameBuffer2D in project platform_frameworks_base by android.
the class ColorfulnessFilter method onProcess.
@Override
protected void onProcess() {
FrameBuffer2D histogramFrame = getConnectedInputPort("histogram").pullFrame().asFrameBuffer2D();
ByteBuffer byteBuffer = histogramFrame.lockBytes(Frame.MODE_READ);
byteBuffer.order(ByteOrder.nativeOrder());
FloatBuffer histogramBuffer = byteBuffer.asFloatBuffer();
histogramBuffer.rewind();
// Create a hue histogram from hue-saturation histogram
int hueBins = histogramFrame.getWidth();
int saturationBins = histogramFrame.getHeight() - 1;
float[] hueHistogram = new float[hueBins];
float total = 0;
for (int r = 0; r < saturationBins; ++r) {
float weight = (float) Math.pow(2, r);
for (int c = 0; c < hueBins; c++) {
float value = histogramBuffer.get() * weight;
hueHistogram[c] += value;
total += value;
}
}
float colorful = 0f;
for (int c = 0; c < hueBins; ++c) {
float value = hueHistogram[c] / total;
if (value > 0f) {
colorful -= value * ((float) Math.log(value));
}
}
colorful /= Math.log(2);
histogramFrame.unlock();
OutputPort outPort = getConnectedOutputPort("score");
FrameValue frameValue = outPort.fetchAvailableFrame(null).asFrameValue();
frameValue.setValue(colorful);
outPort.pushFrame(frameValue);
}
use of androidx.media.filterfw.FrameBuffer2D in project platform_frameworks_base by android.
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 platform_frameworks_base by android.
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 platform_frameworks_base by android.
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 DirtyUnicorns.
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