如何使用GPUImage框架实现那些过滤器链接? [英] How to achieve those filter chaining with GPUImage framework?

查看:66
本文介绍了如何使用GPUImage框架实现那些过滤器链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试链接混合图层并过滤它

I'm trying to chaining blended layer and filter it


(原点 - >纹理1(不透明度30%)/ HardLight - > Texture2 / SoftLight)=>
等级(45,0.95,238)+饱和度(-100)+色调(+42)

(Origin -> Texture1(opacity 30%)/HardLight -> Texture2/SoftLight) => level(45, 0.95, 238) + saturation(-100) + hue(+42)

以下是我尝试的内容:

编辑:此代码适用于以下内容,感谢您的回答

Edited: This code works below, thanks for answer

// 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];


推荐答案

我看到了一些问题:

1)可能有拼写错误的text1过滤器:

1) There's probably a typo chaining text1's filters:

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

应改为

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

2)您将过滤器链接到 text1 text2 GPUImagePictures但忘了处理它们:

2) You're chaining filters to text1 and text2 GPUImagePictures but forgot to process them:

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

3) UIImage * output = [blendFilter2 imageFromCurrentlyProcessedOutput];

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

You should call imageFromCurrentlyProcessedOutput on the last filter of the chain which in your case is the group filter. I wouldn't necessary use the GPUImageFilterGroup here which is usually used to create filter subclasses that use existing filters, but instead I simply would chain the last 3 filters to blendFilter2 like this:

...
// 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] / 

编辑:

注意这里设置min和max的整数除法:

Watch out with those integer divisions setting min and max here:

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

min和max为0!

min and max are 0!

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

这篇关于如何使用GPUImage框架实现那些过滤器链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆