The contrast of the meitu filter and the contrast of the filter
Contrast refers to the measurement of different brightness levels between the brightest white and the darkest black areas in an image, that is, the gray contrast size of an image.
Use GPUImageContrastFilter in GPUImage to implement
Fragment shader
varying highp vec2 textureCoordinate; uniform sampler2D inputImageTexture; uniform lowp float contrast; void main() { lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); gl_FragColor = vec4(((textureColor.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColor.w); }
The RGB value of each pixel is-0.5 multiplied by the contrast value and then + 0.5 is used to generate a new Pixel RGB
+ (UIImage *)changeValueForContrastFilter:(float)value image:(UIImage *)image;{ GPUImageContrastFilter *filter = [[GPUImageContrastFilter alloc] init]; filter.contrast = value; [filter forceProcessingAtSize:image.size]; GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:image]; [pic addTarget:filter]; [pic processImage]; [filter useNextFrameForImageCapture]; return [filter imageFromCurrentFramebuffer];}
Effect
Low Contrast, high contrast