5 uniform float in_slope;
6 uniform float out_slope;
7 uniform float tolerance;
8 uniform float tolerance_in;
9 uniform float tolerance_out;
12 uniform float min_s_in;
13 uniform float min_s_out;
15 uniform float min_v_in;
16 uniform float min_v_out;
18 uniform float max_v_in;
19 uniform float max_v_out;
20 uniform float spill_threshold;
21 uniform float spill_amount;
22 uniform float alpha_offset;
23 uniform float hue_key;
24 uniform float saturation_key;
25 uniform float value_key;
29 vec4 color = texture2D(tex, gl_TexCoord[0].st);
30 /* Contribution to alpha from each component */
31 float alpha_value = 1.0;
32 float alpha_value_max = 1.0;
33 float alpha_hue = 1.0;
34 float alpha_saturation = 1.0;
35 bool has_match = true;
39 color2 = yuv_to_rgb(color);
40 color2 = rgb_to_hsv(color2);
42 /* Hue is completely out of range */
46 if (abs(color2.r - hue_key) < tolerance_in * 180.0)
49 if ((out_slope != 0.0 ) && (abs(color2.r - hue_key) < tolerance * 180.0))
50 /* If using slope, scale alpha between 0 and 1 / 2 */
51 alpha_hue = abs(color2.r - hue_key) / tolerance / 360.0;
53 if (abs(color2.r - hue_key) < tolerance_out * 180.0)
54 /* If no slope, scale alpha between 1/2 and 1 */
55 alpha_hue = abs(color2.r - hue_key) / tolerance_out / 360.0;
63 alpha_saturation = 0.0;
65 if ( color2.g - sat >= min_s_in )
66 alpha_saturation = 0.0;
68 if ((out_slope != 0.0) && ( color2.g - sat > min_s ) )
69 alpha_saturation = (color2.g - sat - min_s) / (min_s * 2.0);
71 if ( color2.g - sat > min_s_out )
72 alpha_saturation = (color2.g - sat - min_s_out) / (min_s_out * 2.0);
77 /* Test value over minimum */
83 if ( color2.b >= min_v_in )
86 if ((out_slope != 0.0) && ( color2.b > min_v ) )
87 alpha_value = (color2.b - min_v) / (min_v * 2.0);
89 if ( color2.b > min_v_out )
90 alpha_value = (color2.b - min_v_out) / (min_v_out * 2.0);
95 /* Test value under maximum */
99 alpha_value_max = 1.0;
101 if (color2.b <= max_v_in)
102 alpha_value_max = 0.0;
104 if ((out_slope != 0.0) && (color2.b < max_v))
105 alpha_value_max = (color2.b - max_v) / (max_v * 2.0);
107 if (color2.b < max_v_out)
108 alpha_value_max = (color2.b - max_v_out) / (max_v_out * 2.0);
113 /* Take largest component as the alpha */
115 color2.a = max (max (alpha_hue, alpha_value), max (alpha_saturation, alpha_value_max));
117 /* Spill light processing */
118 if ((abs(color2.r - hue_key) < spill_threshold * 180.0) ||
119 ((abs(color2.r - hue_key) > 360.0) &&
120 (abs(color2.r - hue_key) - 360.0 < spill_threshold * 180.0)))
122 /* Modify saturation based on hue contribution */
123 color2.g = color2.g *
125 abs(color2.r - hue_key) /
126 (spill_threshold * 180.0);
128 /* convert back to native colormodel */
129 color2 = hsv_to_rgb(color2);
130 color.rgb = rgb_to_yuv(color2).rgb;
134 /* Convert mask into image */
135 gl_FragColor = show_mask(color, color2);