美圖秀秀濾鏡之色溫(白平衡),秀秀色溫

來源:互聯網
上載者:User

美圖秀秀濾鏡之色溫(白平衡),秀秀色溫

  色溫色溫是表示光源光譜品質最通用的指標。

  GPUImage中我們通過GPUImageWhiteBalanceFilter來實現

  頂點著色

uniform sampler2D inputImageTexture;varying highp vec2 textureCoordinate; uniform lowp float temperature;uniform lowp float tint;const lowp vec3 warmFilter = vec3(0.93, 0.54, 0.0);const mediump mat3 RGBtoYIQ = mat3(0.299, 0.587, 0.114, 0.596, -0.274, -0.322, 0.212, -0.523, 0.311);const mediump mat3 YIQtoRGB = mat3(1.0, 0.956, 0.621, 1.0, -0.272, -0.647, 1.0, -1.105, 1.702);void main(){    lowp vec4 source = texture2D(inputImageTexture, textureCoordinate);        mediump vec3 yiq = RGBtoYIQ * source.rgb; //adjusting tint    yiq.b = clamp(yiq.b + tint*0.5226*0.1, -0.5226, 0.5226);    lowp vec3 rgb = YIQtoRGB * yiq;    lowp vec3 processed = vec3(        (rgb.r < 0.5 ? (2.0 * rgb.r * warmFilter.r) : (1.0 - 2.0 * (1.0 - rgb.r) * (1.0 - warmFilter.r))), //adjusting temperature        (rgb.g < 0.5 ? (2.0 * rgb.g * warmFilter.g) : (1.0 - 2.0 * (1.0 - rgb.g) * (1.0 - warmFilter.g))),         (rgb.b < 0.5 ? (2.0 * rgb.b * warmFilter.b) : (1.0 - 2.0 * (1.0 - rgb.b) * (1.0 - warmFilter.b))));    gl_FragColor = vec4(mix(rgb, processed, temperature), source.a);}

 

 色溫演算法較複雜,它與溫度有關

 

具體應用

+ (UIImage *)changeValueForWhiteBalanceFilter:(float)value image:(UIImage *)image{    GPUImageWhiteBalanceFilter *filter = [[GPUImageWhiteBalanceFilter alloc] init];    filter.temperature = value;    filter.tint = 0.0;    [filter forceProcessingAtSize:image.size];    GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:image];    [pic addTarget:filter];        [pic processImage];    [filter useNextFrameForImageCapture];    return [filter imageFromCurrentFramebuffer];}

 

 

效果

  

          高溫度                           低溫度

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.