IOS-simple filter effect implemented using GPUImage

Source: Internet
Author: User

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;}

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.