Search in sources :

Example 36 with FrameImage2D

use of androidx.media.filterfw.FrameImage2D in project platform_frameworks_base by android.

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

use of androidx.media.filterfw.FrameImage2D in project platform_frameworks_base by android.

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

use of androidx.media.filterfw.FrameImage2D in project platform_frameworks_base by android.

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

use of androidx.media.filterfw.FrameImage2D in project platform_frameworks_base by android.

the class AvgBrightnessFilterTest method testBrightnessFilter.

public void testBrightnessFilter() 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.35f;
    assertEquals(EXPECTED_RESULT, ((Float) getOutputFrame("brightnessRating").asFrameValue().getValue()).floatValue(), 0.01f);
}
Also used : Bitmap(android.graphics.Bitmap) FrameImage2D(androidx.media.filterfw.FrameImage2D)

Example 40 with FrameImage2D

use of androidx.media.filterfw.FrameImage2D in project platform_frameworks_base by android.

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