use of androidx.media.filterfw.OutputPort in project android_frameworks_base by DirtyUnicorns.
the class ToStringFilter method onProcess.
@Override
protected void onProcess() {
FrameValue objectFrame = getConnectedInputPort("object").pullFrame().asFrameValue();
String outStr = objectFrame.getValue().toString();
OutputPort outPort = getConnectedOutputPort("string");
FrameValue stringFrame = outPort.fetchAvailableFrame(null).asFrameValue();
stringFrame.setValue(outStr);
outPort.pushFrame(stringFrame);
}
use of androidx.media.filterfw.OutputPort 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.OutputPort in project android_frameworks_base by DirtyUnicorns.
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.OutputPort 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.OutputPort in project android_frameworks_base by DirtyUnicorns.
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);
}
Aggregations