GPUImage中饱和度调整的实现——GPUImageSaturationFilter

饱和度saturation,是指色彩的鲜艳程度,也称色彩的纯度。饱和度取决于该色中含色成分和消色成分(灰色)的比例。含色成分越大,饱和度越大;消色成分越大,饱和度越小。纯的颜色都是高度饱和的,如鲜红,鲜绿。混杂上白色,灰色或其他色调的颜色,是不饱和的颜色,如绛紫,粉红,黄褐等。完全不饱和的颜色根本没有色调,如黑白之间的各种灰色。

注意区分对比度contrast,对比度是指投影图像最亮和最暗之间的区域之间的比率,比值越大,从黑到白的渐变层次就越多,从而色彩表现越丰富。对比度对视觉效果的影响非常关键,一般来说对比度越大,图像越清晰醒目,色彩也越鲜明艳丽;而对比度小,则会让整个画面都灰蒙蒙的。

核心代码:

 1  varying highp vec2 textureCoordinate;
 2  
 3  uniform sampler2D inputImageTexture;
 4  uniform lowp float saturation;
 5  
 6  // Values from "Graphics Shaders: Theory and Practice" by Bailey and Cunningham
 7  const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);
 8  
 9  void main()
10  {
11     lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
12     lowp float luminance = dot(textureColor.rgb, luminanceWeighting);
13     lowp vec3 greyScaleColor = vec3(luminance);
14     
15     gl_FragColor = vec4(mix(greyScaleColor, textureColor.rgb, saturation), textureColor.w);
16      
17  }

其中saturation的取值范围是[0,2]

原文地址:https://www.cnblogs.com/calence/p/6829529.html