/* "Analysis of Color Blindness" by Onur Fidaner, Poliang Lin and Nevran Ozguven. http://scien.stanford.edu/pages/labsite/2005/psych221/projects/05/ofidaner/colorblindness_project.htm "Digital Video Colourmaps for Checking the Legibility of Displays by Dichromats" by Fran�oise Vi�not, Hans Brettel and John D. Mollon http://vision.psychol.cam.ac.uk/jdmollon/papers/colourmaps.pdf */ kernel Color_Vision_Daltonize < namespace : "Color Vision Daltonize"; vendor : "http://www.daltonize.org/"; version : 1; description : "Daltonization is a technique of exposing details to color blind computer users, allowing them to see a spectrum of detail they have been excluded from perceiving."; > { input image4 src; output pixel4 dst; parameter int type < minValue: 0; maxValue: 3; defaultValue: 0; >; const float3x3 Deuteranope = float3x3( // Deuteranope: greens are greatly reduced (1% men) 1.0, 0.0, 0.0, 0.494207, 0.0, 1.24827, 0.0, 0.0, 1.0 ); const float3x3 Protanope = float3x3( // Protanope: reds are greatly reduced (1% men) 0.0, 2.02344, -2.52581, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 ); const float3x3 Tritanope = float3x3( // Tritanope: blues are greatly reduced (0.003% population) 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, -0.395913, 0.801109, 0.0 ); const float3x3 RGB_to_LMS = float3x3( // Convert from RGB to LMS 17.8824, 43.5161, 4.11935, 3.45565, 27.1554, 3.86714, 0.0299566, 0.184309, 1.46709 ); const float3x3 LMS_to_RGB = float3x3( // Convert from LMS to RGB 0.0809444479, -0.130504409, 0.116721066, -0.0102485335, 0.0540193266, -0.113614708, -0.000365296938, -0.00412161469, 0.693511405 ); const float3x3 ERR_to_MOD = float3x3( // Error modifications 0.0, 0.0, 0.0, 0.7, 1.0, 0.0, 0.7, 0.0, 1.0 ); void evaluatePixel() { float4 pixel = sampleNearest(src, outCoord()); // source pixel float3 RGB = float3(pixel.r, pixel.g, pixel.b); // source color // RGB to LMS matrix conversion float3 z = RGB * RGB_to_LMS; if(type == 0) { dst.r = pixel.r; dst.g = pixel.g; dst.b = pixel.b; dst.a = pixel.a; } else { // Simulate color blindness if(type == 1) z = z * Protanope; else if(type == 2) z = z * Deuteranope; else if(type == 3) z = z * Tritanope; // LMS to RGB matrix conversion z = z * LMS_to_RGB; // Isolate invisible colors to color vision deficiency (calculate error matrix) // Shift colors towards visible spectrum (apply error modifications) z = (RGB - z) * ERR_to_MOD; // Add compensation to original values // Clamp values z = clamp(z + RGB, 0.0, 1.0); // Record color dst.r = z.r; dst.g = z.g; dst.b = z.b; dst.a = pixel.a; } } }