Search in sources :

Example 21 with OutputPort

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

the class NormFilter method onProcess.

@Override
protected void onProcess() {
    FrameValue xFrameValue = getConnectedInputPort("x").pullFrame().asFrameValue();
    float xValue = ((Float) xFrameValue.getValue()).floatValue();
    FrameValue yFrameValue = getConnectedInputPort("y").pullFrame().asFrameValue();
    float yValue = ((Float) yFrameValue.getValue()).floatValue();
    float norm = (float) Math.hypot(xValue, yValue);
    if (mLogVerbose)
        Log.v(TAG, "Norm = " + norm);
    OutputPort outPort = getConnectedOutputPort("norm");
    FrameValue outFrame = outPort.fetchAvailableFrame(null).asFrameValue();
    outFrame.setValue(norm);
    outPort.pushFrame(outFrame);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameValue(androidx.media.filterfw.FrameValue)

Example 22 with OutputPort

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

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 23 with OutputPort

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

the class CropFilter method onProcess.

@Override
protected void onProcess() {
    OutputPort outPort = getConnectedOutputPort("image");
    // Pull input frame
    FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
    int[] inDims = inputImage.getDimensions();
    int[] croppedDims = { (int) Math.ceil(mCropRect.xEdge().length() * inDims[0]), (int) Math.ceil(mCropRect.yEdge().length() * inDims[1]) };
    int[] outDims = { getOutputWidth(croppedDims[0], croppedDims[1]), getOutputHeight(croppedDims[0], croppedDims[1]) };
    FrameImage2D outputImage = outPort.fetchAvailableFrame(outDims).asFrameImage2D();
    if (isOpenGLSupported()) {
        FrameImage2D sourceFrame;
        Quad sourceQuad = null;
        boolean scaleDown = (outDims[0] < croppedDims[0]) || (outDims[1] < croppedDims[1]);
        if (scaleDown && mUseMipmaps) {
            mPow2Frame = TransformUtils.makeMipMappedFrame(mPow2Frame, croppedDims);
            int[] extDims = mPow2Frame.getDimensions();
            float targetWidth = croppedDims[0] / (float) extDims[0];
            float targetHeight = croppedDims[1] / (float) extDims[1];
            Quad targetQuad = Quad.fromRect(0f, 0f, targetWidth, targetHeight);
            mShader.setSourceQuad(mCropRect);
            mShader.setTargetQuad(targetQuad);
            mShader.process(inputImage, mPow2Frame);
            TransformUtils.generateMipMaps(mPow2Frame);
            sourceFrame = mPow2Frame;
            sourceQuad = targetQuad;
        } else {
            sourceFrame = inputImage;
            sourceQuad = mCropRect;
        }
        mShader.setSourceQuad(sourceQuad);
        mShader.setTargetRect(0f, 0f, 1f, 1f);
        mShader.process(sourceFrame, outputImage);
    } else {
        // Convert quads to canvas coordinate space
        Quad sourceQuad = mCropRect.scale2(inDims[0], inDims[1]);
        Quad targetQuad = Quad.fromRect(0f, 0f, inDims[0], inDims[1]);
        // Calculate transform for crop
        Matrix transform = Quad.getTransform(sourceQuad, targetQuad);
        transform.postScale(outDims[0] / (float) inDims[0], outDims[1] / (float) inDims[1]);
        // Create target canvas
        Bitmap.Config config = Bitmap.Config.ARGB_8888;
        Bitmap cropped = Bitmap.createBitmap(outDims[0], outDims[1], config);
        Canvas canvas = new Canvas(cropped);
        // Draw source bitmap into target canvas
        Paint paint = new Paint();
        paint.setFilterBitmap(true);
        Bitmap sourceBitmap = inputImage.toBitmap();
        canvas.drawBitmap(sourceBitmap, transform, paint);
        // Assign bitmap to output frame
        outputImage.setBitmap(cropped);
    }
    outPort.pushFrame(outputImage);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) Quad(androidx.media.filterfw.geometry.Quad) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) FrameImage2D(androidx.media.filterfw.FrameImage2D) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 24 with OutputPort

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

the class AvgBrightnessFilter method onProcess.

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

Example 25 with OutputPort

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

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)

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