Search in sources :

Example 1 with FrameBuffer2D

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);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameBuffer2D(androidx.media.filterfw.FrameBuffer2D) FrameImage2D(androidx.media.filterfw.FrameImage2D) RenderTarget(androidx.media.filterfw.RenderTarget) ByteBuffer(java.nio.ByteBuffer)

Example 2 with FrameBuffer2D

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);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameBuffer2D(androidx.media.filterfw.FrameBuffer2D) ByteBuffer(java.nio.ByteBuffer) FrameValue(androidx.media.filterfw.FrameValue)

Example 3 with FrameBuffer2D

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);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameBuffer2D(androidx.media.filterfw.FrameBuffer2D) FrameImage2D(androidx.media.filterfw.FrameImage2D) FrameValue(androidx.media.filterfw.FrameValue)

Example 4 with FrameBuffer2D

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);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameBuffer2D(androidx.media.filterfw.FrameBuffer2D) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 5 with FrameBuffer2D

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);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameBuffer2D(androidx.media.filterfw.FrameBuffer2D) ByteBuffer(java.nio.ByteBuffer) FrameValue(androidx.media.filterfw.FrameValue)

Aggregations

FrameBuffer2D (androidx.media.filterfw.FrameBuffer2D)20 OutputPort (androidx.media.filterfw.OutputPort)20 ByteBuffer (java.nio.ByteBuffer)16 FrameValue (androidx.media.filterfw.FrameValue)12 FrameImage2D (androidx.media.filterfw.FrameImage2D)8 FloatBuffer (java.nio.FloatBuffer)8 RenderTarget (androidx.media.filterfw.RenderTarget)4