use of androidx.media.filterfw.OutputPort in project android_frameworks_base by crdroidandroid.
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);
}
}
use of androidx.media.filterfw.OutputPort in project android_frameworks_base by crdroidandroid.
the class StatsFilter method onProcess.
/**
* @see androidx.media.filterfw.Filter#onProcess()
*/
@Override
protected void onProcess() {
FrameBuffer2D inputFrame = getConnectedInputPort("buffer").pullFrame().asFrameImage2D();
ByteBuffer pixelBuffer = inputFrame.lockBytes(Frame.MODE_READ);
calcMeanAndStd(pixelBuffer, inputFrame.getWidth(), inputFrame.getHeight(), mCropRect);
inputFrame.unlock();
OutputPort outPort = getConnectedOutputPort("mean");
FrameValue outFrame = outPort.fetchAvailableFrame(null).asFrameValue();
outFrame.setValue(mStats[MEAN_INDEX]);
outPort.pushFrame(outFrame);
OutputPort outPortStdev = getConnectedOutputPort("stdev");
FrameValue outFrameStdev = outPortStdev.fetchAvailableFrame(null).asFrameValue();
outFrameStdev.setValue(mStats[STDEV_INDEX]);
outPortStdev.pushFrame(outFrameStdev);
}
use of androidx.media.filterfw.OutputPort 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);
}
}
use of androidx.media.filterfw.OutputPort 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);
}
use of androidx.media.filterfw.OutputPort 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);
}
Aggregations