#version 130

uniform sampler2D qt_Texture0;
in vec2 qt_TexCoord0;
uniform vec3 mtf_param;
uniform bool bw;
uniform bool invert;
out vec4 color;

vec4 MTF(vec4 x, vec3 m)
{
    x = (x - m.x) / (m.z - m.x);
    x = clamp(x, vec4(0.0), vec4(1.0));
    return ((m.y - 1) * x) / ((2 * m.y - 1) * x - m.y);
}

void main(void)
{
    color = texture2D(qt_Texture0, qt_TexCoord0);
    if(bw)color = color.rrra;
    color = MTF(color, mtf_param);

    if(invert)color = vec4(1.0) - color;

    if(any(lessThan(qt_TexCoord0, vec2(0.0))) || any(greaterThan(qt_TexCoord0, vec2(1.0))))
        color = vec4(0.0);
}
