Search in sources :

Example 71 with OutputPort

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

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

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

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

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

the class AverageFilter method onProcess.

@Override
protected void onProcess() {
    FrameValue inFrameValue = getConnectedInputPort("sharpness").pullFrame().asFrameValue();
    if (counter < NUM_FRAMES && counter >= 0) {
        temp[counter] = ((Float) inFrameValue.getValue()).floatValue();
    }
    counter = (counter + 1) % NUM_FRAMES;
    float output = (temp[0] + temp[1] + temp[2] + temp[3] + temp[4]) / NUM_FRAMES;
    if (mLogVerbose)
        Log.v(TAG, "Avg= " + output + "temp1= " + temp[0] + "temp2= " + temp[1] + "temp3= " + temp[2] + "temp4=" + temp[3] + "temp5=" + temp[4]);
    OutputPort outPort = getConnectedOutputPort("avg");
    FrameValue outFrame = outPort.fetchAvailableFrame(null).asFrameValue();
    outFrame.setValue(output);
    outPort.pushFrame(outFrame);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameValue(androidx.media.filterfw.FrameValue)

Example 74 with OutputPort

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

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)

Example 75 with OutputPort

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

the class ToStringFilter method onProcess.

@Override
protected void onProcess() {
    FrameValue objectFrame = getConnectedInputPort("object").pullFrame().asFrameValue();
    String outStr = objectFrame.getValue().toString();
    OutputPort outPort = getConnectedOutputPort("string");
    FrameValue stringFrame = outPort.fetchAvailableFrame(null).asFrameValue();
    stringFrame.setValue(outStr);
    outPort.pushFrame(stringFrame);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) 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