uniform sampler2DRect tex;
uniform float norm_white_cutoff;
uniform float norm_black_cutoff;

void main()
{
	vec4 		now			= texture2DRect( tex, gl_TexCoord[0].st);
	vec4		edge_prv	= texture2DRect( tex, gl_TexCoord[1].st);
	vec4		edge_nxt	= texture2DRect( tex, gl_TexCoord[2].st);

	vec4		nxt			= texture2DRect( tex, gl_TexCoord[3].st);
	vec4		prv			= texture2DRect( tex, gl_TexCoord[4].st);
	
	/* alpha avging cleans  up a *lot* of garbage, espcially in YUV */ 
	now.a = (now.a + nxt.a + prv.a) / 3.0;
	
	/* cut off black / white */
	if (now.r > norm_white_cutoff
	||	now.r < norm_black_cutoff) {
		now.a = 1.0;
	}
	
	/* 
	 *	pull the next /prev pixel when on an edge.
	 *	this gets rid of most of the bleeding of background color.
	 *
	 *	THIS HAS BEEN TEMPORARILY REMOVED AS WE HAVE IMPLEMENTED NEW ANTI-BLEED CODE
	if (edge_prv.a > edge_nxt.a) {
		now.g = edge_prv.g;
		now.b = edge_prv.b;
	}
	if (edge_prv.a < edge_nxt.a) {
		now.g = edge_nxt.g;
		now.b = edge_nxt.b;
	}
	 */
					
	const vec4 rgb_norm = vec4(	16.0/255.0,	128.0/255.0,	128.0/255.0, 	0);
	const vec3 r_values = vec3(  1.1643,		 0.00000,	 1.5958);
	const vec3 g_values = vec3(  1.1643,		-0.39173,	-0.81290);
	const vec3 b_values = vec3(  1.1643,		 2.01700,	 0.0000);
	
	now		-= rgb_norm;	/* start convert to RGB */
	
	now.rgb	*= now.a;		/* pre-multiply */
	
	/* finish convert back to RGB */
	float	r	= dot(now.xyz, r_values);
	float	g	= dot(now.xyz, g_values);
	float	b	= dot(now.xyz, b_values);
	
	gl_FragColor 	= 	vec4(r,g,b,now.a);
}
