Search in sources :

Example 56 with OutputPort

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

the class Camera2Source method onProcess.

@Override
protected void onProcess() {
    Log.v(TAG, "on Process");
    if (nextFrame()) {
        OutputPort outPort = getConnectedOutputPort("video");
        // Create a 2D frame that will hold the output
        int[] dims = new int[] { mWidth, mHeight };
        FrameImage2D outputFrame = Frame.create(mOutputType, dims).asFrameImage2D();
        rgbConverter.forEach(mAllocationOut);
        mAllocationOut.copyTo(mBitmap);
        outputFrame.setBitmap(mBitmap);
        outPort.pushFrame(outputFrame);
        outputFrame.release();
        OutputPort orientationPort = getConnectedOutputPort("orientation");
        FrameValue orientationFrame = orientationPort.fetchAvailableFrame(null).asFrameValue();
        // FIXME: Hardcoded value because ORIENTATION returns null, Qualcomm
        // bug
        Integer orientation = mProperties.get(CameraCharacteristics.SENSOR_ORIENTATION);
        float temp;
        if (orientation != null) {
            temp = orientation.floatValue();
        } else {
            temp = 90.0f;
        }
        orientationFrame.setValue(temp);
        orientationPort.pushFrame(orientationFrame);
    }
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameImage2D(androidx.media.filterfw.FrameImage2D) FrameValue(androidx.media.filterfw.FrameValue)

Example 57 with OutputPort

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

the class ContrastRatioFilter method onProcess.

@Override
protected void onProcess() {
    FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
    float contrastRatio;
    ByteBuffer inputBuffer = inputImage.lockBytes(Frame.MODE_READ);
    contrastRatio = contrastOperator(inputImage.getWidth(), inputImage.getHeight(), inputBuffer);
    inputImage.unlock();
    if (mLogVerbose)
        Log.v(TAG, "contrastRatio: " + contrastRatio);
    OutputPort contrastToGoodnessPort = getConnectedOutputPort("contrastRatingToGoodness");
    FrameValue contrastOutFrame2 = contrastToGoodnessPort.fetchAvailableFrame(null).asFrameValue();
    contrastOutFrame2.setValue(contrastRatio);
    contrastToGoodnessPort.pushFrame(contrastOutFrame2);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameImage2D(androidx.media.filterfw.FrameImage2D) ByteBuffer(java.nio.ByteBuffer) FrameValue(androidx.media.filterfw.FrameValue)

Example 58 with OutputPort

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

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

Example 59 with OutputPort

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

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);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameValues(androidx.media.filterfw.FrameValues) FrameImage2D(androidx.media.filterfw.FrameImage2D) Face(android.hardware.Camera.Face) ByteBuffer(java.nio.ByteBuffer)

Example 60 with OutputPort

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

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)

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