Search in sources :

Example 26 with FrameImage2D

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

the class IfElseFilterTest method testIfElseFilterFalse.

public void testIfElseFilterFalse() throws Exception {
    FrameImage2D image = createFrame(FrameType.image2D(FrameType.ELEMENT_RGBA8888, FrameType.READ_CPU), new int[] { BIG_INPUT_WIDTH, BIG_INPUT_HEIGHT }).asFrameImage2D();
    FrameImage2D video = createFrame(FrameType.image2D(FrameType.ELEMENT_RGBA8888, FrameType.READ_CPU), new int[] { SMALL_INPUT_WIDTH, SMALL_INPUT_HEIGHT }).asFrameImage2D();
    // Image of legs
    Bitmap videoBitmap = BitmapFactory.decodeStream(assetMgr.open("0002_000390.jpg"));
    // Image of a face
    Bitmap imageBitmap = BitmapFactory.decodeStream(assetMgr.open("XZZ019.jpg"));
    image.setBitmap(imageBitmap);
    injectInputFrame("falseResult", image);
    video.setBitmap(videoBitmap);
    injectInputFrame("trueResult", video);
    FrameValue conditionFrame = createFrame(FrameType.single(boolean.class), new int[] { 1 }).asFrameValue();
    conditionFrame.setValue(false);
    injectInputFrame("condition", conditionFrame);
    process();
    // Ensure that for true, we use the video input
    FrameImage2D outputImage = getOutputFrame("output").asFrameImage2D();
    assertEquals(outputImage, image);
}
Also used : Bitmap(android.graphics.Bitmap) FrameImage2D(androidx.media.filterfw.FrameImage2D) FrameValue(androidx.media.filterfw.FrameValue)

Example 27 with FrameImage2D

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

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 28 with FrameImage2D

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

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 29 with FrameImage2D

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

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 30 with FrameImage2D

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

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)

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