源碼
Photoshop的亮度對比度工具
這是photoshop的工具,下面用opengl實現該功能
原理
公式:
y = x - * tan(45+44* ) +
實現:
float B = brightness / 255.0;
float c = contrast / 255.0;
float k = tan((45 + 44 * c) / 180.0 * PI);
colorrbg = ((colorrbg*255.0 - 127.5 * (1.0 - B)) * k + 127.5 * (1.0 + B)) / 255.0;
shader
#version 330 core
precision mediump float;
in vec2 TexCoord;
out vec4 outColor;
uniform sampler2D inputTexture;
uniform int brightness;
uniform int contrast;
vec4 tmp(vec3 colorrbg){
float PI = 3.1415926;
float B = brightness / 255.0;
float c = contrast / 255.0;
float k = tan((45 + 44 * c) / 180.0 * PI);
colorrbg = ((colorrbg*255.0 - 127.5 * (1.0 - B)) * k + 127.5 * (1.0 + B)) / 255.0;
return vec4(colorrbg,1.0);
}
void main(){
vec3 tmpColor = texture(inputTexture, TexCoord).rgb;
outColor = tmp(tmpColor);
}
效果
原圖:
亮度+50
亮度-50
對比度-50
對比度+50