ImageStitcherpublic class ImageStitcher extends android.filterfw.core.Filter
Fields Summary |
---|
private int | mXSlices | private int | mYSlices | private int | mPadSize | private android.filterfw.core.Program | mProgram | private android.filterfw.core.Frame | mOutputFrame | private int | mInputWidth | private int | mInputHeight | private int | mImageWidth | private int | mImageHeight | private int | mSliceWidth | private int | mSliceHeight | private int | mSliceIndex |
Constructors Summary |
---|
public ImageStitcher(String name)
super(name);
mSliceIndex = 0;
|
Methods Summary |
---|
private android.filterfw.core.FrameFormat | calcOutputFormatForInput(android.filterfw.core.FrameFormat format)
MutableFrameFormat outputFormat = format.mutableCopy();
mInputWidth = format.getWidth();
mInputHeight = format.getHeight();
mSliceWidth = mInputWidth - 2 * mPadSize;
mSliceHeight = mInputHeight - 2 * mPadSize;
mImageWidth = mSliceWidth * mXSlices;
mImageHeight = mSliceHeight * mYSlices;
outputFormat.setDimensions(mImageWidth, mImageHeight);
return outputFormat;
| public android.filterfw.core.FrameFormat | getOutputFormat(java.lang.String portName, android.filterfw.core.FrameFormat inputFormat)
return inputFormat;
| public void | process(android.filterfw.core.FilterContext context)
// Get input frame
Frame input = pullInput("image");
FrameFormat format = input.getFormat();
// Create output frame
if (mSliceIndex == 0) {
mOutputFrame = context.getFrameManager().newFrame(calcOutputFormatForInput(format));
} else {
if ((format.getWidth() != mInputWidth) ||
(format.getHeight() != mInputHeight)) {
// CHECK input format here
throw new RuntimeException("Image size should not change.");
}
}
// Create the program if not created already
if (mProgram == null) {
mProgram = ShaderProgram.createIdentity(context);
}
// TODO(rslin) : not sure shifting by 0.5 is needed.
float x0 = ((float) mPadSize) / mInputWidth;
float y0 = ((float) mPadSize) / mInputHeight;
int outputOffsetX = (mSliceIndex % mXSlices) * mSliceWidth;
int outputOffsetY = (mSliceIndex / mXSlices) * mSliceHeight;
float outputWidth = (float) Math.min(mSliceWidth, mImageWidth - outputOffsetX);
float outputHeight = (float) Math.min(mSliceHeight, mImageHeight - outputOffsetY);
// We need to set the source rect as well because the input are padded images.
((ShaderProgram) mProgram).setSourceRect(x0, y0,
outputWidth / mInputWidth,
outputHeight / mInputHeight);
((ShaderProgram) mProgram).setTargetRect(((float) outputOffsetX)/ mImageWidth,
((float) outputOffsetY) / mImageHeight,
outputWidth / mImageWidth,
outputHeight / mImageHeight);
// Process this tile
mProgram.process(input, mOutputFrame);
mSliceIndex++;
// Push output
if (mSliceIndex == mXSlices * mYSlices) {
pushOutput("image", mOutputFrame);
mOutputFrame.release();
mSliceIndex = 0;
}
| public void | setupPorts()
addMaskedInputPort("image", ImageFormat.create(ImageFormat.COLORSPACE_RGBA,
FrameFormat.TARGET_GPU));
addOutputBasedOnInput("image", "image");
|
|