Search in sources :

Example 16 with OutputPort

use of androidx.media.filterfw.OutputPort in project android_frameworks_base by DirtyUnicorns.

the class RotateFilter method onProcess.

@Override
protected void onProcess() {
    OutputPort outPort = getConnectedOutputPort("image");
    FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
    int[] inDims = inputImage.getDimensions();
    FrameImage2D outputImage = outPort.fetchAvailableFrame(inDims).asFrameImage2D();
    mShader.setSourceQuad(mSourceRect);
    Quad targetQuad = mSourceRect.rotated((float) (mRotateAngle / 180 * Math.PI));
    mShader.setTargetQuad(targetQuad);
    mShader.process(inputImage, outputImage);
    outPort.pushFrame(outputImage);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) Quad(androidx.media.filterfw.geometry.Quad) FrameImage2D(androidx.media.filterfw.FrameImage2D)

Example 17 with OutputPort

use of androidx.media.filterfw.OutputPort in project android_frameworks_base by DirtyUnicorns.

the class MotionSensor method onProcess.

@Override
protected void onProcess() {
    OutputPort outPort = getConnectedOutputPort("values");
    FrameValues outFrame = outPort.fetchAvailableFrame(null).asFrameValues();
    synchronized (mValues) {
        outFrame.setValues(mValues);
    }
    outFrame.setTimestamp(System.currentTimeMillis() * 1000000L);
    outPort.pushFrame(outFrame);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameValues(androidx.media.filterfw.FrameValues)

Example 18 with OutputPort

use of androidx.media.filterfw.OutputPort in project android_frameworks_base by ResurrectionRemix.

the class SobelFilter method onProcess.

@Override
protected void onProcess() {
    OutputPort magnitudePort = getConnectedOutputPort("magnitude");
    OutputPort directionPort = getConnectedOutputPort("direction");
    FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
    int[] inputDims = inputImage.getDimensions();
    FrameImage2D magImage = (magnitudePort != null) ? magnitudePort.fetchAvailableFrame(inputDims).asFrameImage2D() : null;
    FrameImage2D dirImage = (directionPort != null) ? directionPort.fetchAvailableFrame(inputDims).asFrameImage2D() : null;
    if (isOpenGLSupported()) {
        FrameImage2D gxFrame = Frame.create(mImageType, inputDims).asFrameImage2D();
        FrameImage2D gyFrame = Frame.create(mImageType, inputDims).asFrameImage2D();
        mGradientXShader.setUniformValue("pix", new float[] { 1f / inputDims[0], 1f / inputDims[1] });
        mGradientYShader.setUniformValue("pix", new float[] { 1f / inputDims[0], 1f / inputDims[1] });
        mGradientXShader.process(inputImage, gxFrame);
        mGradientYShader.process(inputImage, gyFrame);
        FrameImage2D[] gradientFrames = new FrameImage2D[] { gxFrame, gyFrame };
        if (magnitudePort != null) {
            mMagnitudeShader.processMulti(gradientFrames, magImage);
        }
        if (directionPort != null) {
            mDirectionShader.processMulti(gradientFrames, dirImage);
        }
        gxFrame.release();
        gyFrame.release();
    } else {
        ByteBuffer inputBuffer = inputImage.lockBytes(Frame.MODE_READ);
        ByteBuffer magBuffer = (magImage != null) ? magImage.lockBytes(Frame.MODE_WRITE) : null;
        ByteBuffer dirBuffer = (dirImage != null) ? dirImage.lockBytes(Frame.MODE_WRITE) : null;
        sobelOperator(inputImage.getWidth(), inputImage.getHeight(), inputBuffer, magBuffer, dirBuffer);
        inputImage.unlock();
        if (magImage != null) {
            magImage.unlock();
        }
        if (dirImage != null) {
            dirImage.unlock();
        }
    }
    if (magImage != null) {
        magnitudePort.pushFrame(magImage);
    }
    if (dirImage != null) {
        directionPort.pushFrame(dirImage);
    }
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameImage2D(androidx.media.filterfw.FrameImage2D) ByteBuffer(java.nio.ByteBuffer)

Example 19 with OutputPort

use of androidx.media.filterfw.OutputPort 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 20 with OutputPort

use of androidx.media.filterfw.OutputPort in project android_frameworks_base by ResurrectionRemix.

the class RotateFilter method onProcess.

@Override
protected void onProcess() {
    OutputPort outPort = getConnectedOutputPort("image");
    FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
    int[] inDims = inputImage.getDimensions();
    FrameImage2D outputImage = outPort.fetchAvailableFrame(inDims).asFrameImage2D();
    mShader.setSourceQuad(mSourceRect);
    Quad targetQuad = mSourceRect.rotated((float) (mRotateAngle / 180 * Math.PI));
    mShader.setTargetQuad(targetQuad);
    mShader.process(inputImage, outputImage);
    outPort.pushFrame(outputImage);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) Quad(androidx.media.filterfw.geometry.Quad) FrameImage2D(androidx.media.filterfw.FrameImage2D)

Aggregations

OutputPort (androidx.media.filterfw.OutputPort)92 FrameValue (androidx.media.filterfw.FrameValue)60 FrameImage2D (androidx.media.filterfw.FrameImage2D)48 ByteBuffer (java.nio.ByteBuffer)36 FrameBuffer2D (androidx.media.filterfw.FrameBuffer2D)20 FrameValues (androidx.media.filterfw.FrameValues)12 Bitmap (android.graphics.Bitmap)8 Quad (androidx.media.filterfw.geometry.Quad)8 FloatBuffer (java.nio.FloatBuffer)8 Canvas (android.graphics.Canvas)4 Matrix (android.graphics.Matrix)4 Paint (android.graphics.Paint)4 Face (android.hardware.Camera.Face)4 RenderTarget (androidx.media.filterfw.RenderTarget)4