自然飽和度”是影像整體的明亮程度,“飽和度”是影像顏色的鮮豔程度。
“飽和度”與“色相/飽和度”命令中的“飽和度”選項效果相同,可以增加整個畫面的“飽和度”,但如調節到較高數值,影像會產生色彩過飽和從而引起影像失真。
在GPUImage中使用GPUImageVibranceFilter來實現調整影像的自然飽和度
片段著色
varying highp vec2 textureCoordinate; uniform sampler2D inputImageTexture; uniform lowp float vibrance; void main() { lowp vec4 color = texture2D(inputImageTexture, textureCoordinate); lowp float average = (color.r + color.g + color.b) / 3.0; lowp float mx = max(color.r, max(color.g, color.b)); lowp float amt = (mx - average) * (-vibrance * 3.0); color.rgb = mix(color.rgb, vec3(mx), amt); gl_FragColor = color; }
具體應用
+ (UIImage *)changeValueForVibranceFilter:(float)value image:(UIImage *)image { GPUImageVibranceFilter *filter = [[GPUImageVibranceFilter alloc] init]; filter.vibrance = value; [filter forceProcessingAtSize:image.size]; GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:image]; [pic addTarget:filter]; [pic processImage]; [filter useNextFrameForImageCapture]; return [filter imageFromCurrentFramebuffer]; }
效果