iphone - How to achieve those filter chaining with GPUImage framework? -


i'm trying chaining blended layer , filter it

(origin -> texture1(opacity 30%)/hardlight -> texture2/softlight) => level(45, 0.95, 238) + saturation(-100) + hue(+42)

here tried :

edited: code works below, 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]; 

i see couple of problems:

1) there's typo chaining text1's filters:

[text1 addtarget:filter1]; // opacity [text1 addtarget:blendfilter1]; // hardlight blend 

should instead be

[text1 addtarget:filter1]; // opacity [filter1 addtarget:blendfilter1]; // hardlight blend 

2) you're chaining filters text1 , text2 gpuimagepictures forgot process them:

// processing [origin processimage]; [text1 processimage]; [text2 processimage]; 

3) uiimage *output = [blendfilter2 imagefromcurrentlyprocessedoutput];

you should call imagefromcurrentlyprocessedoutput on last filter of chain in case group filter. wouldn't necessary use gpuimagefiltergroup here used create filter subclasses use existing filters, instead chain last 3 filters blendfilter2 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]; 

the full chain be:

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

edit:

watch out integer divisions setting min , max here:

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

min , max 0!

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

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -