FileDocCategorySizeDatePackage
ToRGBAFilter.javaAPI DocAndroid 5.1 API3160Thu Mar 12 22:22:30 GMT 2015android.filterpacks.imageproc

ToRGBAFilter

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

Fields Summary
private int
mInputBPP
private android.filterfw.core.Program
mProgram
private android.filterfw.core.FrameFormat
mLastFormat
Constructors Summary
public ToRGBAFilter(String name)


       
        super(name);
    
Methods Summary
public voidcreateProgram(android.filterfw.core.FilterContext context, android.filterfw.core.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");
                break;
            case 3:
                mProgram = new NativeProgram("filterpack_imageproc", "rgb_to_rgba");
                break;
            default:
                throw new RuntimeException("Unsupported BytesPerPixel: " + mInputBPP + "!");
        }
    
public android.filterfw.core.FrameFormatgetConvertedFormat(android.filterfw.core.FrameFormat format)

        MutableFrameFormat result = format.mutableCopy();
        result.setMetaValue(ImageFormat.COLORSPACE_KEY, ImageFormat.COLORSPACE_RGBA);
        result.setBytesPerSample(4);
        return result;
    
public android.filterfw.core.FrameFormatgetOutputFormat(java.lang.String portName, android.filterfw.core.FrameFormat inputFormat)

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

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

        // Create output frame
        Frame output = context.getFrameManager().newFrame(getConvertedFormat(input.getFormat()));

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

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

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

        MutableFrameFormat mask = new MutableFrameFormat(FrameFormat.TYPE_BYTE,
                                                         FrameFormat.TARGET_NATIVE);
        mask.setDimensionCount(2);
        addMaskedInputPort("image", mask);
        addOutputBasedOnInput("image", "image");