Personal tools

Views

BrightnessTo3Colors

From Adobe Labs

[edit]

Source

// Filter by David Lollar
// December 2007
// works for Flash

kernel BrightnessTo3Colors
<   nameSpace : "dlollar";
    vendor : "none";
    version : 1;
    description : "this filters breaks up image into highest brightness,
middle brightnessmand lowest brightness, then replaces those with 3 
solid colors. Use the paramters to change the solid colors. Use the other 
2 parameters to adjust the border bands for middle brightness.";
>
{
    parameter float hiEnd 
    <
	minValue: 1.5; 
	maxValue: 3.0; 
	defaultValue: 1.5;
    >;

    parameter float loEnd 
    <
	minValue: 0.0; 
	maxValue: 1.5; 
	defaultValue: 0.0;
    >;
    
    parameter float3 aColor 
    <  
	minValue: float3(0.0, 0.0, 0.0);
        maxValue: float3(1.0, 1.0, 1.0);
	defaultValue: float3(1.0, 0.0, 0.0);
    >;
                                
    parameter float3 bColor 
    <
	minValue: float3(0.0, 0.0, 0.0);
	maxValue: float3(1.0, 1.0, 1.0);
	defaultValue: float3(0.0, 1.0, 0.0);
    >;
                                
    parameter float3 cColor 
    <
	minValue: float3(0.0, 0.0, 0.0);
	maxValue: float3(1.0, 1.0, 1.0);
	defaultValue: float3(0.0, 0.0, 1.0);
    >;


    void
    evaluatePixel(image4 src, out float4 dst)
    // depending on your version of Toolkit, you may need "in" above for evaluatePixel
    {
        dst = sampleNearest(src,outCoord());
        float brightness = dst.r + dst.g + dst.b;
        
        dst.rgb = (brightness < hiEnd) ? cColor : aColor;
        float3 currentColor = dst.rgb;
        dst.rgb = (brightness < loEnd) ? bColor : currentColor;
        
    }
}
Retrieved from "http://labs.adobe.com/wiki/index.php/BrightnessTo3Colors"