IOS-simple filter effect implemented using GPUImage
GPUImage is an open-source iOS framework based on GPU image and video processing. Because GPU is used to process images and videos, the speed is very fast. in addition to the speed advantages, GPUImage also provides a lot of great image processing filters, but sometimes these basic functions still cannot meet the needs of actual development, GPUImage also supports custom filters.
Simple Filter
GPUImageSepiaFilter *filter = [[GPUImageSepiaFilter alloc] init];_filteredImage = [filter imageByFilteringImage:_originImage];
GPUImage encapsulates most of the filter effects in a similar way. Therefore, it is very easy to use and can be directly searched in GPUImage. h.
Custom Filter
The custom filter of GPUImage must use the OpenGL coloring language (GLSL) to compile the Fragment Shader (Fragment Shader) with the suffix. sh. for the GLSL syntax and other content, we will not describe it much for the time being and will add it separately in the future.
GPUImageFilter *customFilter = [[GPUImageFilter alloc] initWithFragmentShaderFromFile:@GPUImageCustomFilter];_filteredImage = [customFilter imageByFilteringImage:_originImage];
The GLSL script file (GPUImageCustomFilter. fsh) is as follows:
varying highp vec2 textureCoordinate;uniform sampler2D inputImageTexture;void main(){ lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); lowp vec4 outputColor; outputColor.r = (textureColor.r * 0.393) + (textureColor.g * 0.769) + (textureColor.b * 0.189); outputColor.g = (textureColor.r * 0.349) + (textureColor.g * 0.686) + (textureColor.b * 0.168); outputColor.b = (textureColor.r * 0.872) + (textureColor.g * 0.534) + (textureColor.b * 0.131); outputColor.a = 1.0; gl_FragColor = outputColor;}