0

我正在尝试链接混合图层并对其进行过滤

(Origin -> Texture1(opacity 30%)/HardLight -> Texture2/SoftLight) => level(45, 0.95, 238) + 饱和度(-100) + 色调(+42)

这是我尝试过的:

编辑:此代码在下面有效,感谢您的回答

// Textures
GPUImagePicture *origin = [[GPUImagePicture alloc] initWithImage:originImage smoothlyScaleOutput:NO];
GPUImagePicture *text1 = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:@"filter_landscape_vintage_1.png"] smoothlyScaleOutput:NO];
GPUImagePicture *text2 = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:@"filter_landscape_vintage_2.png"] smoothlyScaleOutput:NO];

// Blend filters
GPUImageHardLightBlendFilter *blendFilter1 = [[GPUImageHardLightBlendFilter alloc] init];
GPUImageSoftLightBlendFilter *blendFilter2 = [[GPUImageSoftLightBlendFilter alloc] init];

// Color filters
GPUImageOpacityFilter *filter1 = [[GPUImageOpacityFilter alloc] init];
[filter1 setOpacity:0.3];
GPUImageLevelsFilter *filter2 = [[GPUImageLevelsFilter alloc] init];
[filter2 setMin:45.0/255.0 gamma:0.95 max:238.0/255.0]; // 45, 0.95, 238
GPUImageSaturationFilter *filter3 = [[GPUImageSaturationFilter alloc] init];
[filter3 setSaturation:0.0];
GPUImageHueFilter *filter4 = [[GPUImageHueFilter alloc] init];
[filter4 setHue:42.0];

// Texture1(opacity 30%)/HardLight
[text1 addTarget:filter1]; // Opacity
[filter1 addTarget:blendFilter1]; // HardLight Blend

// Texture2/SoftLight
[text2 addTarget:blendFilter2]; // SoftLight Blend

// Chain Origin + Texture1 + Texture2
[origin addTarget:blendFilter1];
[blendFilter1 addTarget:blendFilter2];

// Result => level + saturation + hue
[blendFilter2 addTarget:filter2];
[filter2 addTarget:filter3];
[filter3 addTarget:filter4];

// Processing
[origin processImage];
[text1 processImage];
[text2 processImage];

UIImage *output = [filter4 imageFromCurrentlyProcessedOutput];
4

1 回答 1

3

我看到几个问题:

1)可能有一个错字链接 text1 的过滤器:

[text1 addTarget:filter1]; // Opacity
[text1 addTarget:blendFilter1]; // HardLight Blend

应该改为

[text1 addTarget:filter1]; // Opacity
[filter1 addTarget:blendFilter1]; // HardLight Blend

2)您将过滤器链接到text1GPUImagePicturestext2但忘记处理它们:

// Processing
[origin processImage];
[text1 processImage];
[text2 processImage];

3) UIImage *output = [blendFilter2 imageFromCurrentlyProcessedOutput];

您应该调用imageFromCurrentlyProcessedOutput链的最后一个过滤器,在您的情况下是group过滤器。我不需要使用GPUImageFilterGroup通常用于创建使用现有过滤器的过滤器子类的此处,但我只是将最后 3 个过滤器链接到blendFilter2这样:

...
// Result => level + saturation + hue
[blendFilter2 addTarget:filter2];
[filter2 addTarget:filter3];
[filter3 addTarget:filter4];

// Processing
[origin processImage];
[text1 processImage];
[text2 processImage];

UIImage *output = [filter4 imageFromCurrentlyProcessedOutput];

完整的链条将是:

[text1] -> [filter1] \ 
                      +->  [blend1]  \
            [origin] /                +-> [blend2] -> [filter2] -> [filter3] -> [filter4]
                             [text2] / 

编辑:

注意这些整数除法设置最小值和最大值:

[filter2 setMin:45/255 gamma:0.95 max:238/255]; // 45, 0.95, 238

最小值和最大值为 0!

[filter2 setMin:45 / 255.0 gamma:0.95 max:238 / 255.0]; // 45, 0.95, 238
于 2013-08-16T09:13:17.690 回答