opengl 實現 Photoshop 亮度 對比度 調節功能

源碼

VirtualStudio2019的工程。可直接運行

Photoshop的亮度對比度工具

這是photoshop的工具,下面用opengl實現該功能
在這裏插入圖片描述

原理

公式:

y = x - 255.0brightness2\frac{255.0-brightness}{2}* tan(45+44* contrast255\frac{contrast}{255} ) + 255+brightness2\frac{255+brightness}{2}

實現:

    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
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章