GPUImage icon indicating copy to clipboard operation
GPUImage copied to clipboard

GPUImageFilterGroup with blend filters

Open peterhwong opened this issue 14 years ago • 2 comments

Hi all, I'm having trouble getting a GPUImageFilterGroup with a blend filter to work. For the FilterShowcase I see that the needsSecondImage does this:

inputImage = [UIImage imageNamed:@"WID-small.jpg"];
    sourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];
    [sourcePicture processImage];            
    [sourcePicture addTarget:filter];

where filter is the group but that doesn't work if change the sepia filter to GPUImageOverlayBlendFilter. If I try calling addTarget using the blended filter instead of the group, all I get is a white image output. What am I missing?

Here's the code I tried in FilterShowcase: case GPUIMAGE_FILTERGROUP: { self.title = @"Filter Group"; self.filterSettingsSlider.hidden = NO;

        [self.filterSettingsSlider setValue:0.05];
        [self.filterSettingsSlider setMinimumValue:0.0];
        [self.filterSettingsSlider setMaximumValue:0.3];

        filter = [[GPUImageFilterGroup alloc] init];

        GPUImageOverlayBlendFilter *sepiaFilter = [[GPUImageOverlayBlendFilter alloc] init];
        [(GPUImageFilterGroup *)filter addFilter:sepiaFilter];
        UIImage *inputImage = [UIImage imageNamed:@"WID-small.jpg"];

        sourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];
        [sourcePicture addTarget:sepiaFilter];

        GPUImagePixellateFilter *pixellateFilter = [[GPUImagePixellateFilter alloc] init];
        [(GPUImageFilterGroup *)filter addFilter:pixellateFilter];

        [sepiaFilter addTarget:pixellateFilter];
        [(GPUImageFilterGroup *)filter setInitialFilters:[NSArray arrayWithObject:sepiaFilter]];
        [(GPUImageFilterGroup *)filter setTerminalFilter:pixellateFilter];

        [sourcePicture processImage];
    }; break;

Thanks

peterhwong avatar Jul 27 '12 20:07 peterhwong

Filter groups that have blend filters as their first filter are tricky, in that the input to the group will always be assigned at the first index of that blend. You need to explicitly set the input for that blend filter to be the second index (1) using something like

[blendFilter addTarget:picture atTextureLocation:1];

look at the code for the GPUImageUnsharpMaskFilter, which has a blend within it, for how this is done in practice.

BradLarson avatar Jul 27 '12 20:07 BradLarson

Gotta it. Thanks Brad!

peterhwong avatar Jul 27 '12 23:07 peterhwong