FileDocCategorySizeDatePackage
ToRGBFilter.javaAPI DocAndroid 5.1 API3156Thu Mar 12 22:22:30 GMT 2015android.filterpacks.imageproc

ToRGBFilter

public class ToRGBFilter 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 ToRGBFilter(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_rgb");
                break;
            case 4:
                mProgram = new NativeProgram("filterpack_imageproc", "rgba_to_rgb");
                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_RGB);
        result.setBytesPerSample(3);
        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");