chrisbatt / AndroidFastImageProcessing

A framework for speeding up image processing on android devices by taking advantage of shaders on the GPU.
MIT License
285 stars 118 forks source link

GroupFilter does not work #4

Closed kdemczuk closed 10 years ago

kdemczuk commented 10 years ago

I've noticed that GroupFilter doesn't work or maybe I use it in a wrong way. I want to process image from ImageView that is set in RelativeLayout.

My GroupFilter class:

class MyGroupFilter extends GroupFilter {

    public void register(BasicFilter filter) {
        super.registerFilter(filter);
    }

    public void registerInitial(BasicFilter filter) {
        super.registerInitialFilter(filter);
    }

    public void registerTerminal(BasicFilter filter) {
        super.registerTerminalFilter(filter);
    }
}

MyGroupFilter groupFilter = new MyGroupFilter();

Here is my init code:

            view = new FastImageProcessingView(this);
    pipeline = new FastImageProcessingPipeline();
    view.setPipeline(pipeline);
    imageIn = new ImageResourceInput(view, this, R.drawable.penguins2);
    screen = new ScreenEndpoint(pipeline);
    imageIn.addTarget(screen);
    pipeline.addRootRenderer(imageIn);
    pipeline.startRendering();

    relativeLayout.addView(view);

I have two buttons (plus and minus) for controlling brightness level and also two buttons for controlling saturation level. Every time I push any button, my filter method is invoked with appropriate value of brighnessLevelF and saturationLevelF (which are floats and represent levels of brightness and saturation). Method body:

    pipeline.pauseRendering();
    imageIn.removeTarget(groupFilter);
    pipeline.addFilterToDestroy(groupFilter);

    BrightnessFilter brightnessFilter = new BrightnessFilter(brighnessLevelF);
    brightnessFilter.addTarget(screen);
    SaturationFilter saturationFilter = new SaturationFilter(saturationLevelF);
    saturationFilter.addTarget(screen);

    groupFilter.registerInitial(brightnessFilter);
    groupFilter.registerTerminal(saturationFilter);
    imageIn.addTarget(groupFilter);

    pipeline.startRendering();
    view.requestRender();

It works but only brightness level is changing. Am I doing something wrong?

chrisbatt commented 10 years ago

Yes, you are missing one important thing. The brightnessFilter needs to pass its output data into the saturationFilter so that both the brightness and saturation filters are applied. There are two ways you can do this: a group filter or just simply chaining the filters. The group filter was more meant for situations where a single image process involves multiple filters (SmoothToonFilter, in the source, is a good example of when a group filter should be used). I would recommend just chaining the filters like this:

    pipeline.pauseRendering();
    imageIn.removeTarget(brightnessFilter);
    pipeline.addFilterToDestroy(brightnessFilter);
    pipeline.addFilterToDestroy(saturationFilter);

    brightnessFilter = new BrightnessFilter(brighnessLevelF);
    saturationFilter = new SaturationFilter(saturationLevelF);

    imageIn.addTarget(brightnessFilter);
    brightnessFilter.addTarget(saturationFilter);
    saturationFilter.addTarget(screen);

    pipeline.startRendering();
    view.requestRender();
kdemczuk commented 10 years ago

Thanks a lot for explaining it to me. I have one more question. Can I use Your library in commercial product? I haven't found anything about license in docs. Using it would be really helpful for me.

chrisbatt commented 10 years ago

Sorry for the late response. I had to check with the company that contributed to this framework. It sounds like they are OK with anyone using it in a commericial project as long as there is a mention in the README. Just send an email to bruce@insatiablegenius.com to confirm. Thanks!