uniform sampler2D tex;
uniform float src_factor;
uniform float dst_factor;

void main()
{
	vec4 color = texture2D(tex,gl_TexCoord[0].st);
	ivec4 icolor = ivec4(color[0]*255.0, color[1]*255.0, color[2]*255.0, color[3]*255.0);
	if(icolor.a > 200) {
		if(icolor.r <= 2) { icolor = ivec4(100, 45, 85, 255); }
		else if(icolor.r <= 29) { icolor = ivec4(143, 44, 106, 255); }
		else if(icolor.r <= 50) { icolor = ivec4(168, 85, 0, 255); }
		else if(icolor.r <= 59) { icolor = ivec4(203, 126, 39, 255); }
		else if(icolor.r <= 61) { icolor = ivec4(148, 87, 69, 255); }
		else if(icolor.r <= 85) { icolor = ivec4(52, 28, 66, 255); }
		else if(icolor.r <= 137) { icolor = ivec4(235, 197, 82, 255); }
		else if(icolor.r <= 146) { icolor = ivec4(100, 45, 85, 255); }
		else if(icolor.r <= 158) { icolor = ivec4(112, 154, 209, 255); }
		else if(icolor.r <= 197) { icolor = ivec4(160, 197, 201, 255); }
		else if(icolor.r <= 209) { icolor = ivec4(255, 239, 198, 255); }
		else if(icolor.r <= 233) { icolor = ivec4(208, 230, 230, 255); }
		else if(icolor.r <= 249) { icolor = ivec4(255, 249, 189, 255); }

		color[0] = src_factor*color[0] + dst_factor*float(icolor[0])/255.0;
		color[2] = src_factor*color[2] + dst_factor*float(icolor[2])/255.0;
		color[3] = src_factor*color[3] + dst_factor*float(icolor[3])/255.0;
	}

	color *= gl_Color;

	gl_FragColor = color;
}
