FileDocCategorySizeDatePackage
SimpleImageFilter.javaAPI DocAndroid 5.1 API3525Thu Mar 12 22:22:30 GMT 2015android.filterpacks.imageproc

SimpleImageFilter

public abstract class SimpleImageFilter extends android.filterfw.core.Filter
hide

Fields Summary
protected int
mCurrentTarget
protected android.filterfw.core.Program
mProgram
protected String
mParameterName
Constructors Summary
public SimpleImageFilter(String name, String parameterName)


         
        super(name);
        mParameterName = parameterName;
    
Methods Summary
protected abstract android.filterfw.core.ProgramgetNativeProgram(android.filterfw.core.FilterContext context)

public android.filterfw.core.FrameFormatgetOutputFormat(java.lang.String portName, android.filterfw.core.FrameFormat inputFormat)

        return inputFormat;
    
protected abstract android.filterfw.core.ProgramgetShaderProgram(android.filterfw.core.FilterContext context)

public voidprocess(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
        updateProgramWithTarget(inputFormat.getTarget(), context);

        // Process
        mProgram.process(input, output);

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

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

        if (mParameterName != null) {
            try {
                Field programField = SimpleImageFilter.class.getDeclaredField("mProgram");
                addProgramPort(mParameterName, mParameterName, programField, float.class, false);
            } catch (NoSuchFieldException e) {
                throw new RuntimeException("Internal Error: mProgram field not found!");
            }
        }
        addMaskedInputPort("image", ImageFormat.create(ImageFormat.COLORSPACE_RGBA));
        addOutputBasedOnInput("image", "image");
    
protected voidupdateProgramWithTarget(int target, android.filterfw.core.FilterContext context)

        if (target != mCurrentTarget) {
            switch (target) {
                case FrameFormat.TARGET_NATIVE:
                    mProgram = getNativeProgram(context);
                    break;

                case FrameFormat.TARGET_GPU:
                    mProgram = getShaderProgram(context);
                    break;

                default:
                    mProgram = null;
                    break;
            }
            if (mProgram == null) {
                throw new RuntimeException("Could not create a program for image filter " + this + "!");
            }
            initProgramInputs(mProgram, context);
            mCurrentTarget = target;
        }