Search in sources :

Example 46 with OutputPort

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

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

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

the class IfElseFilter method onProcess.

@Override
protected void onProcess() {
    OutputPort outPort = getConnectedOutputPort("output");
    FrameImage2D trueFrame = getConnectedInputPort("trueResult").pullFrame().asFrameImage2D();
    FrameImage2D falseFrame = getConnectedInputPort("falseResult").pullFrame().asFrameImage2D();
    FrameValue boolFrameValue = getConnectedInputPort("condition").pullFrame().asFrameValue();
    boolean condition = (Boolean) boolFrameValue.getValue();
    FrameBuffer2D outputFrame;
    // If the condition is true, then we want to use the camera, else use the gallery
    if (condition) {
        outputFrame = trueFrame;
    } else {
        outputFrame = falseFrame;
    }
    outPort.pushFrame(outputFrame);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameBuffer2D(androidx.media.filterfw.FrameBuffer2D) FrameImage2D(androidx.media.filterfw.FrameImage2D) FrameValue(androidx.media.filterfw.FrameValue)

Example 48 with OutputPort

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

the class ColorfulnessFilter method onProcess.

@Override
protected void onProcess() {
    FrameBuffer2D histogramFrame = getConnectedInputPort("histogram").pullFrame().asFrameBuffer2D();
    ByteBuffer byteBuffer = histogramFrame.lockBytes(Frame.MODE_READ);
    byteBuffer.order(ByteOrder.nativeOrder());
    FloatBuffer histogramBuffer = byteBuffer.asFloatBuffer();
    histogramBuffer.rewind();
    // Create a hue histogram from hue-saturation histogram
    int hueBins = histogramFrame.getWidth();
    int saturationBins = histogramFrame.getHeight() - 1;
    float[] hueHistogram = new float[hueBins];
    float total = 0;
    for (int r = 0; r < saturationBins; ++r) {
        float weight = (float) Math.pow(2, r);
        for (int c = 0; c < hueBins; c++) {
            float value = histogramBuffer.get() * weight;
            hueHistogram[c] += value;
            total += value;
        }
    }
    float colorful = 0f;
    for (int c = 0; c < hueBins; ++c) {
        float value = hueHistogram[c] / total;
        if (value > 0f) {
            colorful -= value * ((float) Math.log(value));
        }
    }
    colorful /= Math.log(2);
    histogramFrame.unlock();
    OutputPort outPort = getConnectedOutputPort("score");
    FrameValue frameValue = outPort.fetchAvailableFrame(null).asFrameValue();
    frameValue.setValue(colorful);
    outPort.pushFrame(frameValue);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameBuffer2D(androidx.media.filterfw.FrameBuffer2D) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) FrameValue(androidx.media.filterfw.FrameValue)

Example 49 with OutputPort

use of androidx.media.filterfw.OutputPort 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 50 with OutputPort

use of androidx.media.filterfw.OutputPort 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)

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