Index: modules/color/color.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/color/color.module,v
retrieving revision 1.68
diff -u -p -r1.68 color.module
--- modules/color/color.module	25 Aug 2009 21:16:31 -0000	1.68
+++ modules/color/color.module	26 Aug 2009 13:10:31 -0000
@@ -40,6 +40,7 @@ function color_form_system_theme_setting
       '#theme' => 'color_scheme_form',
     );
     $form['color'] += color_scheme_form($form_state, arg(4));
+    $form['#validate'][] = 'color_scheme_form_validate';
     $form['#submit'][] = 'color_scheme_form_submit';
   }
 }
@@ -368,6 +369,22 @@ function color_scheme_form_submit($form,
 }
 
 /**
+ * Validator for color change form. Checks contrast ratio- text and link color vs. background color, informs user.
+ */
+function color_scheme_form_validate($form, &$form_state) {
+  $palette = $form_state['values']['palette'];
+  
+  //Checks to see if text is readable on white background
+  $test = _color_luminositytest('#ffffff', $palette['text']); 
+  drupal_set_message(t("The selected text color, when used with a white background, has a luminosity ratio of %result. The W3C WCAG 2.0 accessibility standard suggests this ratio must be a minimum of 4.5 and optimally at least 7.0 for the text to be readable by all.", array('%result' => $test)), $test >= 4.5 ? 'status': 'warning');
+  
+  //Checks to see if links are readable on white background
+  $test = _color_luminositytest('#ffffff', $palette['link']);
+  drupal_set_message(t("The selected link color, when used with a white background, has a luminosity ratio of %result. The W3C WCAG 2.0 accessibility standard suggests this ratio must be a minimum of 4.5 and optimally at least 7.0 for the links to be readable by all.", array('%result' => $test)), $test >= 4.5 ? 'status': 'warning');
+  
+}
+
+/**
  * Rewrite the stylesheet to match the colors in the palette.
  */
 function _color_rewrite_stylesheet($theme, &$info, &$paths, $palette, $style) {
@@ -679,3 +696,30 @@ function _color_rgb2hsl($rgb) {
 
   return array($h, $s, $l);
 }
+
+/**
+ * Calculate luminosity ratio, should be higher than 4.5 to meet with WCAG 2.0 color contrast standard - http://www.w3.org/TR/WCAG20/
+ */
+function _color_luminositytest($color1, $color2) {
+  $color1 = _color_unpack($color1);
+  $color2 = _color_unpack($color2);  
+  
+  //PHP Algorithm from http://www.splitbrain.org/blog/2008-09/18-calculating_color_contrast_with_php
+  $luminosity1 = 0.2126 * pow($color1[0]/255, 2.2) +
+        0.7152 * pow($color1[1]/255, 2.2) +
+        0.0722 * pow($color1[2]/255, 2.2);
+ 
+  $luminosity2 = 0.2126 * pow($color2[0]/255, 2.2) +
+        0.7152 * pow($color2[1]/255, 2.2) +
+        0.0722 * pow($color2[2]/255, 2.2);
+ 
+  if ($luminosity1 > $luminosity2) {
+    return round(($luminosity1 + 0.05) / ($luminosity2 + 0.05), 1);
+  }
+  else {
+    return round(($luminosity2 + 0.05) / ($luminosity1 + 0.05), 1);
+  }
+}
+
+
+
