Search in sources :

Example 56 with FrameValue

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

the class MotionSensorWTime method onProcess.

@Override
protected void onProcess() {
    OutputPort outPort = getConnectedOutputPort("values");
    FrameValues outFrame = outPort.fetchAvailableFrame(null).asFrameValues();
    synchronized (mValues) {
        if (mCounter < 3 && mCounter >= 0) {
            mTemp[0][mCounter] = mValues[0];
            mTemp[1][mCounter] = mValues[1];
            mTemp[2][mCounter] = mValues[2];
        }
        mCounter = (mCounter + 1) % 3;
        mAvgValues[0] = (mTemp[0][0] + mTemp[0][1] + mTemp[0][2]) / 3;
        mAvgValues[1] = (mTemp[1][0] + mTemp[1][1] + mTemp[1][2]) / 3;
        mAvgValues[2] = (mTemp[2][0] + mTemp[2][1] + mTemp[2][2]) / 3;
        outFrame.setValues(mAvgValues);
    }
    outFrame.setTimestamp(System.currentTimeMillis() * 1000000L);
    outPort.pushFrame(outFrame);
    OutputPort timeOutPort = getConnectedOutputPort("timestamp");
    if (timeOutPort != null) {
        long timestamp = System.nanoTime();
        Log.v("MotionSensor", "Timestamp is: " + timestamp);
        FrameValue timeStampFrame = timeOutPort.fetchAvailableFrame(null).asFrameValue();
        timeStampFrame.setValue(timestamp);
        timeOutPort.pushFrame(timeStampFrame);
    }
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameValues(androidx.media.filterfw.FrameValues) FrameValue(androidx.media.filterfw.FrameValue)

Example 57 with FrameValue

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

the class WaveTriggerFilter method onProcess.

@Override
protected synchronized void onProcess() {
    // Check if we were triggered
    if (mTrigger) {
        mInWaveMode = true;
        mTrigger = false;
        mTime = 0.5f;
    }
    // Calculate output value
    float value = 0.5f;
    if (mInWaveMode) {
        value = -Math.abs(mTime - 1f) + 1f;
        mTime += 0.2f;
        if (mTime >= 2f) {
            mInWaveMode = false;
        }
    }
    // Push Value
    OutputPort outPort = getConnectedOutputPort("value");
    FrameValue frame = outPort.fetchAvailableFrame(null).asFrameValue();
    frame.setValue(value);
    outPort.pushFrame(frame);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameValue(androidx.media.filterfw.FrameValue)

Example 58 with FrameValue

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

the class AverageFilterTest method testAverageFilter.

public void testAverageFilter() throws Exception {
    FrameValue frame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue();
    frame.setValue(5f);
    injectInputFrame("sharpness", frame);
    process();
    assertEquals(1f, ((Float) getOutputFrame("avg").asFrameValue().getValue()).floatValue(), 0.001f);
}
Also used : FrameValue(androidx.media.filterfw.FrameValue)

Example 59 with FrameValue

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

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 60 with FrameValue

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

Aggregations

FrameValue (androidx.media.filterfw.FrameValue)112 OutputPort (androidx.media.filterfw.OutputPort)60 FrameImage2D (androidx.media.filterfw.FrameImage2D)32 ByteBuffer (java.nio.ByteBuffer)20 Bitmap (android.graphics.Bitmap)12 FrameBuffer2D (androidx.media.filterfw.FrameBuffer2D)12 FrameValues (androidx.media.filterfw.FrameValues)4 BufferedWriter (java.io.BufferedWriter)4 FileWriter (java.io.FileWriter)4 IOException (java.io.IOException)4 FloatBuffer (java.nio.FloatBuffer)4