use of androidx.media.filterfw.OutputPort 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.OutputPort 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.OutputPort in project android_frameworks_base by crdroidandroid.
the class WaveTriggerFilter method onProcess.
@Override
protected synchronized void onProcess() {
// Check if we were triggered
if (mTrigger) {
mInWaveMode = true;
mTrigger = false;
mTime = 0.5f;
}
// Calculate output value
float value = 0.5f;
if (mInWaveMode) {
value = -Math.abs(mTime - 1f) + 1f;
mTime += 0.2f;
if (mTime >= 2f) {
mInWaveMode = false;
}
}
// Push Value
OutputPort outPort = getConnectedOutputPort("value");
FrameValue frame = outPort.fetchAvailableFrame(null).asFrameValue();
frame.setValue(value);
outPort.pushFrame(frame);
}
use of androidx.media.filterfw.OutputPort 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.OutputPort in project android_frameworks_base by crdroidandroid.
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);
}
Aggregations