FileDocCategorySizeDatePackage
ImageCombineFilter.javaAPI DocAndroid 5.1 API4416Thu Mar 12 22:22:30 GMT 2015android.filterpacks.imageproc

ImageCombineFilter

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

Fields Summary
protected android.filterfw.core.Program
mProgram
protected String[]
mInputNames
protected String
mOutputName
protected String
mParameterName
protected int
mCurrentTarget
Constructors Summary
public ImageCombineFilter(String name, String[] inputNames, String outputName, String parameterName)


      
                               
                               
                                
        super(name);
        mInputNames = inputNames;
        mOutputName = outputName;
        mParameterName = parameterName;
    
Methods Summary
private voidassertAllInputTargetsMatch()

        int target = getInputFormat(mInputNames[0]).getTarget();
        for (String inputName : mInputNames) {
            if (target != getInputFormat(inputName).getTarget()) {
                throw new RuntimeException("Type mismatch of input formats in filter " + this
                    + ". All input frames must have the same target!");
            }
        }
    
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)

        // Pull input frames
        int i = 0;
        Frame[] inputs = new Frame[mInputNames.length];
        for (String inputName : mInputNames) {
            inputs[i++] = pullInput(inputName);
        }

        // Create output frame
        Frame output = context.getFrameManager().newFrame(inputs[0].getFormat());

        // Make sure we have a program
        updateProgramWithTarget(inputs[0].getFormat().getTarget(), context);

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

        // Push output
        pushOutput(mOutputName, output);

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

        if (mParameterName != null) {
            try {
                Field programField = ImageCombineFilter.class.getDeclaredField("mProgram");
                addProgramPort(mParameterName, mParameterName, programField, float.class, false);
            } catch (NoSuchFieldException e) {
                throw new RuntimeException("Internal Error: mProgram field not found!");
            }
        }
        for (String inputName : mInputNames) {
            addMaskedInputPort(inputName, ImageFormat.create(ImageFormat.COLORSPACE_RGBA));
        }
        addOutputBasedOnInput(mOutputName, mInputNames[0]);
    
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;
        }