kernel HorizontalLines < namespace: "com.27Bobs"; vendor: "Todd Yard"; version: 1; description: "Draws horizontal lines over darker areas of image."; > { parameter float levelsThreshold < minValue: 0.0; maxValue: 1.0; defaultValue: 0.4; description: "The threshold used to determine the light and dark areas."; >; parameter float4 foregroundColor < minValue: float4(0.0, 0.0, 0.0, 0.0); maxValue: float4(1.0, 1.0, 1.0, 1.0); defaultValue: float4(1.0, 1.0, 1.0, 1.0); description: "the color to use for the lighter areas of the image"; >; parameter float4 backgroundColor < minValue: float4(0.0, 0.0, 0.0, 0.0); maxValue: float4(1.0, 1.0, 1.0, 1.0); defaultValue: float4(0.0, 0.0, 0.0, 1.0); description: "the color to use for the darker areas of the image"; >; input image4 source; output pixel4 result; void evaluatePixel() { float2 coord = outCoord(); pixel4 px = sampleNearest(source, coord); // only perform threshold check on odd lines if (mod(coord.y, 2.0) >= 1.0) { // reduce px to two levels per channel float numLevels = 2.0; px = floor(px*numLevels)/numLevels; float luminance = px.r * 0.3 + px.g * 0.59 + px.b * 0.11; // if luminance of altered pixel is less that or equal // to threshold, use background color for pixel if (luminance <= levelsThreshold) { px = backgroundColor; // else use foreground color for pixel } else { px = foregroundColor; } // event lines all get foreground color } else { px = foregroundColor; } result = px; } }