#include version.txt

float PI = 3.14159265358979323846264;
	
vec4 brightnessContrast(vec4 color, float brightness, float contrast) {
	if (brightness < 0.0)  {
		color *= 1.0 + brightness;
	}
     else {
		color += (1.0 - color) * brightness;
	}

	color = (color - 0.5) * (tan((contrast + 1.0) * PI / 4.0)) + 0.5;
	
    return color;
}

vec4 screen(vec4 color0, vec4 color1) {
    vec4 white = vec4(1.0, 1.0, 1.0, 1.0);
    return white - ((white - color0) * (white - color1));
}

vec4 overlay(vec4 color0, vec4 color1) {
    
    vec4 result;
    vec4 lumCoeff = vec4(0.2125, 0.7154, 0.0721, 1.0);
    vec4 white = vec4(1.0, 1.0, 1.0, 1.0);
    
    float luminance = dot(color0, lumCoeff);
    
    if(luminance < 0.45) {
        result = 2.0 * color1 * color0;
    }
    else if (luminance > 0.55) {
        result = white - 2.0 * (white - color1) * (white - color0);
    }
    else {
        vec4 result1 = 2.0 * color1 * color0;
        vec4 result2 = white - 2.0 * (white - color1) * (white - color0);        
        result = mix(result1, result2, (luminance - 0.45) * 10.0);
    }
    
    return result;
}

