prepare() may not have the complete format.
Change-Id: I2245675df030564e1c652c934cbcdc16c0fc96f2
public class CropFilter extends Filter {
private Program mProgram;
+ private FrameFormat mLastFormat = null;
@GenerateFieldPort(name = "owidth")
private int mOutputWidth = -1;
return outputFormat;
}
- @Override
- public void prepare(FilterContext context) {
+ protected void createProgram(FilterContext context, FrameFormat format) {
// TODO: Add CPU version
- switch (getInputFormat("image").getTarget()) {
+ if (mLastFormat != null && mLastFormat.getTarget() == format.getTarget()) return;
+ mLastFormat = format;
+ mProgram = null;
+ switch (format.getTarget()) {
case FrameFormat.TARGET_GPU:
mProgram = ShaderProgram.createIdentity(context);
break;
Frame imageFrame = pullInput("image");
Frame boxFrame = pullInput("box");
+ createProgram(env, imageFrame.getFormat());
+
// Get the box
Quad box = (Quad)boxFrame.getObjectValue();
private boolean mGenerateMipMap = false;
private Program mProgram;
+ private FrameFormat mLastFormat = null;
+
private MutableFrameFormat mOutputFormat;
private int mInputChannels;
return inputFormat;
}
- @Override
- protected void prepare(FilterContext context) {
- switch (getInputFormat("image").getTarget()) {
+ protected void createProgram(FilterContext context, FrameFormat format) {
+ if (mLastFormat != null && mLastFormat.getTarget() == format.getTarget()) return;
+ mLastFormat = format;
+ switch (format.getTarget()) {
case FrameFormat.TARGET_NATIVE:
throw new RuntimeException("Native ResizeFilter not implemented yet!");
public void process(FilterContext env) {
// Get input frame
Frame input = pullInput("image");
+ createProgram(env, input.getFormat());
// Create output frame
MutableFrameFormat outputFormat = input.getFormat().mutableCopy();
private int mInputBPP;
private Program mProgram;
+ private FrameFormat mLastFormat = null;
public ToRGBAFilter(String name) {
super(name);
return result;
}
- @Override
- public void prepare(FilterContext context) {
- mInputBPP = getInputFormat("image").getBytesPerSample();
+ public void createProgram(FilterContext context, FrameFormat format) {
+ mInputBPP = format.getBytesPerSample();
+ if (mLastFormat != null && mLastFormat.getBytesPerSample() == mInputBPP) return;
+ mLastFormat = format;
switch (mInputBPP) {
case 1:
mProgram = new NativeProgram("filterpack_imageproc", "gray_to_rgba");
public void process(FilterContext context) {
// Get input frame
Frame input = pullInput("image");
+ createProgram(context, input.getFormat());
// Create output frame
Frame output = context.getFrameManager().newFrame(getConvertedFormat(input.getFormat()));
private int mInputBPP;
private Program mProgram;
+ private FrameFormat mLastFormat = null;
public ToRGBFilter(String name) {
super(name);
return result;
}
- @Override
- public void prepare(FilterContext context) {
- mInputBPP = getInputFormat("image").getBytesPerSample();
+ public void createProgram(FilterContext context, FrameFormat format) {
+ mInputBPP = format.getBytesPerSample();
+ if (mLastFormat != null && mLastFormat.getBytesPerSample() == mInputBPP) return;
+ mLastFormat = format;
switch (mInputBPP) {
case 1:
mProgram = new NativeProgram("filterpack_imageproc", "gray_to_rgb");
public void process(FilterContext context) {
// Get input frame
Frame input = pullInput("image");
+ createProgram(context, input.getFormat());
// Create output frame
Frame output = context.getFrameManager().newFrame(getConvertedFormat(input.getFormat()));