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);
43 if(color2.r <= hue_key - tolerance_in * 180.0)
46 if(color2.r >= hue_key + tolerance_in * 180.0)
49 /* Hue is completely out of range */
53 if (abs(color2.r - hue_key) < tolerance_in * 180.0)
56 if ((out_slope != 0.0 ) && (abs(color2.r - hue_key) < tolerance * 180.0))
57 /* If using slope, scale alpha between 0 and 1 / 2 */
58 alpha_hue = abs(color2.r - hue_key) / tolerance / 360.0;
60 if (abs(color2.r - hue_key) < tolerance_out * 180.0)
61 /* If no slope, scale alpha between 1/2 and 1 */
62 alpha_hue = abs(color2.r - hue_key) / tolerance_out / 360.0;
70 alpha_saturation = 0.0;
72 if ( color2.g - sat >= min_s_in )
73 alpha_saturation = 0.0;
75 if ((out_slope != 0.0) && ( color2.g - sat > min_s ) )
76 alpha_saturation = (color2.g - sat - min_s) / (min_s * 2.0);
78 if ( color2.g - sat > min_s_out )
79 alpha_saturation = (color2.g - sat - min_s_out) / (min_s_out * 2.0);
84 /* Test value over minimum */
90 if ( color2.b >= min_v_in )
93 if ((out_slope != 0.0) && ( color2.b > min_v ) )
94 alpha_value = (color2.b - min_v) / (min_v * 2.0);
96 if ( color2.b > min_v_out )
97 alpha_value = (color2.b - min_v_out) / (min_v_out * 2.0);
102 /* Test value under maximum */
106 alpha_value_max = 1.0;
108 if (color2.b <= max_v_in)
109 alpha_value_max = 0.0;
111 if ((out_slope != 0.0) && (color2.b < max_v))
112 alpha_value_max = (color2.b - max_v) / (max_v * 2.0);
114 if (color2.b < max_v_out)
115 alpha_value_max = (color2.b - max_v_out) / (max_v_out * 2.0);
120 /* Take largest component as the alpha */
122 color2.a = max (max (alpha_hue, alpha_value), max (alpha_saturation, alpha_value_max));
124 /* Spill light processing */
125 if ((abs(color2.r - hue_key) < spill_threshold * 180.0) ||
126 ((abs(color2.r - hue_key) > 360.0) &&
127 (abs(color2.r - hue_key) - 360.0 < spill_threshold * 180.0)))
129 /* Modify saturation based on hue contribution */
130 color2.g = color2.g *
132 abs(color2.r - hue_key) /
133 (spill_threshold * 180.0);
135 /* convert back to native colormodel */
136 color2 = hsv_to_rgb(color2);
137 color.rgb = rgb_to_yuv(color2).rgb;
141 /* Convert mask into image */
142 gl_FragColor = show_mask(color, color2);