Black and white color filter
From Adobe Labs
this samples a color from a specified point on the source image then turns everything to black and white except for pixels that are in a specified range of that color.
by Peleg
/*****************************************************************
*
* black and white / color filter
* by peleg tuchman pel6413 <at> gmail.com
* feel free to email me if you have any questions, suggestions, comments or improvements regarding this kernel
*
*****************************************************************/
kernel NewFilter
{
parameter float2 samplePoint
<
minValue:float2(0.0,0.0);
maxValue:float2(500.0,500.0);
defaultValue:float2(200.0,200.0);
>;
parameter float softness
<
minValue:float(0.0);
maxValue:float(3.0);
defaultValue:float(0.01);
>;
parameter bool markSamplePoint;
parameter pixel3 markColor
<
minValue:pixel3(0.0,0.0,0.0);
maxValue:pixel3(1.0,1.0,1.0);
defaultValue:pixel3(1.0,0.0,0.0);
>;
void
evaluatePixel(in image4 src, out pixel4 dst)
{
float4 color;
float3 diff = abs(sampleNearest(src,outCoord()).rgb - sampleNearest(src,samplePoint).rgb);
if((diff.r+diff.g+diff.b) < softness) {
color = sampleNearest(src,outCoord());
} else {
float avr = (sampleNearest(src,outCoord()).r + sampleNearest(src,outCoord()).g + sampleNearest(src,outCoord()).b) / 3.0;
color = pixel4(avr,avr,avr,1.0);
}
if(markSamplePoint){
if(abs(samplePoint.x - outCoord().x) <= 2.0 && abs(samplePoint.y - outCoord().y) <= 2.0){
color.rgb = markColor;
color.a = 1.0;
}
}
dst = color;
}
}
