FileDocCategorySizeDatePackage
ResizeFilter.javaAPI DocAndroid 5.1 API4000Thu Mar 12 22:22:30 GMT 2015android.filterpacks.imageproc

ResizeFilter

public class ResizeFilter extends android.filterfw.core.Filter
hide

Fields Summary
private int
mOWidth
private int
mOHeight
private boolean
mKeepAspectRatio
private boolean
mGenerateMipMap
private android.filterfw.core.Program
mProgram
private android.filterfw.core.FrameFormat
mLastFormat
private android.filterfw.core.MutableFrameFormat
mOutputFormat
private int
mInputChannels
Constructors Summary
public ResizeFilter(String name)


       
        super(name);
    
Methods Summary
protected voidcreateProgram(android.filterfw.core.FilterContext context, android.filterfw.core.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!");


            case FrameFormat.TARGET_GPU:
                ShaderProgram prog = ShaderProgram.createIdentity(context);
                mProgram = prog;
                break;

            default:
                throw new RuntimeException("ResizeFilter could not create suitable program!");
        }
    
public android.filterfw.core.FrameFormatgetOutputFormat(java.lang.String portName, android.filterfw.core.FrameFormat inputFormat)

        return inputFormat;
    
public voidprocess(android.filterfw.core.FilterContext env)

        // Get input frame
        Frame input = pullInput("image");
        createProgram(env, input.getFormat());

        // Create output frame
        MutableFrameFormat outputFormat = input.getFormat().mutableCopy();
        if (mKeepAspectRatio) {
            FrameFormat inputFormat = input.getFormat();
            mOHeight = mOWidth * inputFormat.getHeight() / inputFormat.getWidth();
        }
        outputFormat.setDimensions(mOWidth, mOHeight);
        Frame output = env.getFrameManager().newFrame(outputFormat);

        // Process
        if (mGenerateMipMap) {
            GLFrame mipmapped = (GLFrame)env.getFrameManager().newFrame(input.getFormat());
            mipmapped.setTextureParameter(GLES20.GL_TEXTURE_MIN_FILTER,
                                          GLES20.GL_LINEAR_MIPMAP_NEAREST);
            mipmapped.setDataFromFrame(input);
            mipmapped.generateMipMap();
            mProgram.process(mipmapped, output);
            mipmapped.release();
        } else {
            mProgram.process(input, output);
        }

        // Push output
        pushOutput("image", output);

        // Release pushed frame
        output.release();
    
public voidsetupPorts()

        addMaskedInputPort("image", ImageFormat.create(ImageFormat.COLORSPACE_RGBA));
        addOutputBasedOnInput("image", "image");