Methods Summary |
---|
private void | checkOutputDimensions(int outputWidth, int outputHeight)
if (outputWidth <= 0 || outputHeight <= 0) {
throw new RuntimeException("Invalid output dimensions: " +
outputWidth + " " + outputHeight);
}
|
private android.filterfw.core.FrameFormat | convertInputFormat(android.filterfw.core.FrameFormat inputFormat)
int ow = mOWidth;
int oh = mOHeight;
int w = inputFormat.getWidth();
int h = inputFormat.getHeight();
if (mOWidth == FrameFormat.SIZE_UNSPECIFIED) {
ow = w;
}
if (mOHeight == FrameFormat.SIZE_UNSPECIFIED) {
oh = h;
}
if (mKeepAspectRatio) {
// if keep aspect ratio, use the bigger dimension to determine the
// final output size
if (w > h) {
ow = Math.max(ow, oh);
oh = ow * h / w;
} else {
oh = Math.max(ow, oh);
ow = oh * w / h;
}
}
ow = (ow > 0 && ow < 4) ? 4 : (ow / 4) * 4; // ensure width is multiple of 4
return ImageFormat.create(ow, oh,
ImageFormat.COLORSPACE_GRAY,
FrameFormat.TARGET_NATIVE);
|
public android.filterfw.core.FrameFormat | getOutputFormat(java.lang.String portName, android.filterfw.core.FrameFormat inputFormat)
return convertInputFormat(inputFormat);
|
public void | prepare(android.filterfw.core.FilterContext context)
mProgram = new ShaderProgram(context, mColorToPackedGrayShader);
|
public void | process(android.filterfw.core.FilterContext context)
Frame input = pullInput("image");
FrameFormat inputFormat = input.getFormat();
FrameFormat outputFormat = convertInputFormat(inputFormat);
int ow = outputFormat.getWidth();
int oh = outputFormat.getHeight();
checkOutputDimensions(ow, oh);
mProgram.setHostValue("pix_stride", 1.0f / ow);
// Do the RGBA to luminance conversion.
MutableFrameFormat tempFrameFormat = inputFormat.mutableCopy();
tempFrameFormat.setDimensions(ow / 4, oh);
Frame temp = context.getFrameManager().newFrame(tempFrameFormat);
mProgram.process(input, temp);
// Read frame from GPU to CPU.
Frame output = context.getFrameManager().newFrame(outputFormat);
output.setDataFromFrame(temp);
temp.release();
// Push output and yield ownership.
pushOutput("image", output);
output.release();
|
public void | setupPorts()
addMaskedInputPort("image", ImageFormat.create(ImageFormat.COLORSPACE_RGBA,
FrameFormat.TARGET_GPU));
addOutputBasedOnInput("image", "image");
|