Search in sources :

Example 61 with FrameImage2D

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

Example 62 with FrameImage2D

use of androidx.media.filterfw.FrameImage2D 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);
}
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 63 with FrameImage2D

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

the class ContrastRatioFilterTest method testContrastFilter.

public void testContrastFilter() throws Exception {
    final int INPUT_WIDTH = 480;
    final int INPUT_HEIGHT = 640;
    FrameImage2D image = createFrame(FrameType.image2D(FrameType.ELEMENT_RGBA8888, FrameType.READ_CPU), new int[] { INPUT_WIDTH, INPUT_HEIGHT }).asFrameImage2D();
    Bitmap bitmap = BitmapFactory.decodeStream(assetMgr.open("0002_000390.jpg"));
    image.setBitmap(bitmap);
    injectInputFrame("image", image);
    process();
    final float EXPECTED_RESULT = 0.29901487f;
    assertEquals(EXPECTED_RESULT, ((Float) getOutputFrame("contrastRating").asFrameValue().getValue()).floatValue(), 0.001f);
}
Also used : Bitmap(android.graphics.Bitmap) FrameImage2D(androidx.media.filterfw.FrameImage2D)

Example 64 with FrameImage2D

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

Example 65 with FrameImage2D

use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by crdroidandroid.

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)

Aggregations

FrameImage2D (androidx.media.filterfw.FrameImage2D)72 OutputPort (androidx.media.filterfw.OutputPort)48 Bitmap (android.graphics.Bitmap)32 FrameValue (androidx.media.filterfw.FrameValue)32 ByteBuffer (java.nio.ByteBuffer)24 Face (android.hardware.Camera.Face)8 FrameBuffer2D (androidx.media.filterfw.FrameBuffer2D)8 FrameValues (androidx.media.filterfw.FrameValues)8 Quad (androidx.media.filterfw.geometry.Quad)8 Canvas (android.graphics.Canvas)4 Matrix (android.graphics.Matrix)4 Paint (android.graphics.Paint)4 Rect (android.graphics.Rect)4 Camera (android.hardware.Camera)4 RenderTarget (androidx.media.filterfw.RenderTarget)4