FileDocCategorySizeDatePackage
LomoishFilter.javaAPI DocAndroid 5.1 API8032Thu Mar 12 22:22:30 GMT 2015android.filterpacks.imageproc

LomoishFilter

public class LomoishFilter extends android.filterfw.core.Filter

Fields Summary
private int
mTileSize
private android.filterfw.core.Program
mProgram
private Random
mRandom
private int
mWidth
private int
mHeight
private int
mTarget
private final String
mLomoishShader
Constructors Summary
public LomoishFilter(String name)


       
        super(name);
        mRandom = new Random(new Date().getTime());
    
Methods Summary
public android.filterfw.core.FrameFormatgetOutputFormat(java.lang.String portName, android.filterfw.core.FrameFormat inputFormat)

        return inputFormat;
    
private voidinitParameters()

        if (mProgram !=null) {
            float scale[] = new float[2];
            if (mWidth > mHeight) {
                scale[0] = 1f;
                scale[1] = ((float) mHeight) / mWidth;
            } else {
                scale[0] = ((float) mWidth) / mHeight;
                scale[1] = 1f;
            }
            float max_dist = ((float) Math.sqrt(scale[0] * scale[0] + scale[1] * scale[1])) * 0.5f;

            mProgram.setHostValue("scale", scale);
            mProgram.setHostValue("inv_max_dist", 1.0f / max_dist);

            mProgram.setHostValue("stepsize", 1.0f / 255.0f);
            mProgram.setHostValue("stepsizeX", 1.0f / mWidth);
            mProgram.setHostValue("stepsizeY", 1.0f / mHeight);

            float seed[] = { mRandom.nextFloat(), mRandom.nextFloat() };
            mProgram.setHostValue("seed", seed);
        }
    
public voidinitProgram(android.filterfw.core.FilterContext context, int target)

        switch (target) {
            case FrameFormat.TARGET_GPU:
                ShaderProgram shaderProgram = new ShaderProgram(context, mLomoishShader);
                shaderProgram.setMaximumTileSize(mTileSize);
                mProgram = shaderProgram;
                break;

            default:
                throw new RuntimeException("Filter Sharpen does not support frames of " +
                    "target " + target + "!");
        }
        mTarget = target;
    
public voidprocess(android.filterfw.core.FilterContext context)

        // Get input frame
        Frame input = pullInput("image");
        FrameFormat inputFormat = input.getFormat();

        // Create program if not created already
        if (mProgram == null || inputFormat.getTarget() != mTarget) {
            initProgram(context, inputFormat.getTarget());
        }

        // Check if the frame size has changed
        if (inputFormat.getWidth() != mWidth || inputFormat.getHeight() != mHeight) {
            mWidth = inputFormat.getWidth();
            mHeight = inputFormat.getHeight();
            initParameters();
        }

        // Create output frame
        Frame output = context.getFrameManager().newFrame(inputFormat);

        // Process
        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");