RedEyeFilterpublic class RedEyeFilter extends android.filterfw.core.Filter
Fields Summary |
---|
private static final float | RADIUS_RATIO | private static final float | MIN_RADIUS | private static final float | DEFAULT_RED_INTENSITY | private float[] | mCenters | private int | mTileSize | private android.filterfw.core.Frame | mRedEyeFrame | private android.graphics.Bitmap | mRedEyeBitmap | private final android.graphics.Canvas | mCanvas | private final android.graphics.Paint | mPaint | private float | mRadius | private int | mWidth | private int | mHeight | private android.filterfw.core.Program | mProgram | private int | mTarget | private final String | mRedEyeShader |
Constructors Summary |
---|
public RedEyeFilter(String name)
super(name);
|
Methods Summary |
---|
private void | createRedEyeFrame(android.filterfw.core.FilterContext context)
int bitmapWidth = mWidth / 2;
int bitmapHeight = mHeight / 2;
Bitmap redEyeBitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
mCanvas.setBitmap(redEyeBitmap);
mPaint.setColor(Color.WHITE);
mRadius = Math.max(MIN_RADIUS, RADIUS_RATIO * Math.min(bitmapWidth, bitmapHeight));
for (int i = 0; i < mCenters.length; i += 2) {
mCanvas.drawCircle(mCenters[i] * bitmapWidth, mCenters[i + 1] * bitmapHeight,
mRadius, mPaint);
}
FrameFormat format = ImageFormat.create(bitmapWidth, bitmapHeight,
ImageFormat.COLORSPACE_RGBA,
FrameFormat.TARGET_GPU);
mRedEyeFrame = context.getFrameManager().newFrame(format);
mRedEyeFrame.setBitmap(redEyeBitmap);
redEyeBitmap.recycle();
| public void | fieldPortValueUpdated(java.lang.String name, android.filterfw.core.FilterContext context)
if (mProgram != null) {
updateProgramParams();
}
| public android.filterfw.core.FrameFormat | getOutputFormat(java.lang.String portName, android.filterfw.core.FrameFormat inputFormat)
return inputFormat;
| public void | initProgram(android.filterfw.core.FilterContext context, int target)
switch (target) {
case FrameFormat.TARGET_GPU:
ShaderProgram shaderProgram = new ShaderProgram(context, mRedEyeShader);
shaderProgram.setMaximumTileSize(mTileSize);
mProgram = shaderProgram;
mProgram.setHostValue("intensity", DEFAULT_RED_INTENSITY);
break;
default:
throw new RuntimeException("Filter RedEye does not support frames of " +
"target " + target + "!");
}
mTarget = target;
| public void | process(android.filterfw.core.FilterContext context)
// Get input frame
Frame input = pullInput("image");
FrameFormat inputFormat = input.getFormat();
// Create output frame
Frame output = context.getFrameManager().newFrame(inputFormat);
// Create program if not created already
if (mProgram == null || inputFormat.getTarget() != mTarget) {
initProgram(context, inputFormat.getTarget());
}
// Check if the frame size has changed
if (inputFormat.getWidth() != mWidth || inputFormat.getHeight() != mHeight) {
mWidth = inputFormat.getWidth();
mHeight = inputFormat.getHeight();
}
createRedEyeFrame(context);
// Process
Frame[] inputs = {input, mRedEyeFrame};
mProgram.process(inputs, output);
// Push output
pushOutput("image", output);
// Release pushed frame
output.release();
// Release unused frame
mRedEyeFrame.release();
mRedEyeFrame = null;
| public void | setupPorts()
addMaskedInputPort("image", ImageFormat.create(ImageFormat.COLORSPACE_RGBA));
addOutputBasedOnInput("image", "image");
| private void | updateProgramParams()
if ( mCenters.length % 2 == 1) {
throw new RuntimeException("The size of center array must be even.");
}
|
|