/* Shader for color clamping of RGB textures.
 *
 * Clamps all color or intensity values to lie in the range given
 * by [ ICMClampToColorRange[0]; ICMClampToColorRange[1] ].
 *
 * (w)2008 by Mario Kleiner. Licensed under MIT license.
*/

/* Allowable range: To be initialized by PsychColorCorrection() typically: */
uniform vec2    ICMClampToColorRange;

vec4 icmTransformColor(vec4 incolor)
{
    vec4 outcolor;

    /* Return alpha component unmodified: */
    outcolor.a = incolor.a;

    /* Clamp outcolor to range given by ICMClampToColorRange: */
    outcolor.rgb = clamp(incolor.rgb, vec3(ICMClampToColorRange[0]), vec3(ICMClampToColorRange[1]));

    return(outcolor);
}

float icmTransformColor1(float incolor)
{
    float outcolor;

    /* Clamp outcolor to range given by ICMClampToColorRange: */
    outcolor = clamp(incolor, ICMClampToColorRange[0], ICMClampToColorRange[1]);

    return(outcolor);
}
