[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    www/sites/accessibility
From:       Olaf Schmidt <ojschmidt () kde ! org>
Date:       2007-07-07 11:19:20
Message-ID: 1183807160.589088.30675.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 684846 by ojschmidt:

Improve tint2

 M  +73 -49    oxygen.php  


--- trunk/www/sites/accessibility/oxygen.php #684845:684846
@@ -83,7 +83,7 @@
   echo '<div>"<a href="?color=' . urlencode ($name) . '">' . $name . '</a>"';
   echo ' contrasts sufficiently with ' . $contrastSufficient . ' ' . $tablename . ' \
colors.</div>';  }
-function computeColor (&$color) {
+function computeColorFromRGB (&$color) {
     $color ["redL"] = round (pow ($color ["red256"]/255, 2.2), 10);
     $color ["greenL"] = round (pow ($color ["green256"]/255, 2.2), 10);
     $color ["blueL"] = round (pow ($color ["blue256"]/255, 2.2), 10);
@@ -129,17 +129,10 @@
     }
 }
 
-function toRGBHex ($r, $g, $b) {
-    $hexR = substr ("00".strtoupper (dechex (round (pow ($r, 1/2.2)*255))), -2);
-    $hexG = substr ("00".strtoupper (dechex (round (pow ($g, 1/2.2)*255))), -2);
-    $hexB = substr ("00".strtoupper (dechex (round (pow ($b, 1/2.2)*255))), -2);
-    return "#".$hexR.$hexG.$hexB;
-}
-
-function toRGB ($hue, $saturation, $luminosity) {
+function computeColorFromHSL (&$color) {
     // ported from Matthew's implementation in kdelibs
     // calculate some needed variables
-    $hs = $hue * 6.0;
+    $hs = $color ["hue"] * 6.0;
     if ($hs < 1.0) {
         $th = $hs;
         $tm = 0.2126 + 0.7152 * $th;
@@ -166,51 +159,79 @@
     }
 
     // calculate RGB channels in sorted order
-    if ($tm >= $luminosity) {
-        $tp = $luminosity + $luminosity * $saturation * (1.0 - $tm) / $tm;
-        $to = $luminosity + $luminosity * $saturation * ($th - $tm) / $tm;
-        $tn = $luminosity - ($luminosity * $saturation);
+    if ($tm >= $color ["luminosity"]) {
+        $tp = $color ["luminosity"] + $color ["luminosity"] * $color ["saturation"] \
* (1.0 - $tm) / $tm; +        $to = $color ["luminosity"] + $color ["luminosity"] * \
$color ["saturation"] * ($th - $tm) / $tm; +        $tn = $color ["luminosity"] - \
($color ["luminosity"] * $color ["saturation"]);  }
     else {
-        $tp = $luminosity + (1.0 - $luminosity) * $saturation;
-        $to = $luminosity + (1.0 - $luminosity) * $saturation * ($th - $tm) / (1.0 - \
                $tm);
-        $tn = $luminosity - (1.0 - $luminosity) * $saturation * $tm / (1.0 - $tm);
+        $tp = $color ["luminosity"] + (1.0 - $color ["luminosity"]) * $color \
["saturation"]; +        $to = $color ["luminosity"] + (1.0 - $color ["luminosity"]) \
* $color ["saturation"] * ($th - $tm) / (1.0 - $tm); +        $tn = $color \
["luminosity"] - (1.0 - $color ["luminosity"]) * $color ["saturation"] * $tm / (1.0 - \
$tm);  }
 
     // return RGB channels in appropriate order
-    if ($hs < 1.0)
-        return toRGBHex ($tp, $to, $tn);
-    else if ($hs < 2.0)
-        return toRGBHex ($to, $tp, $tn);
-    else if ($hs < 3.0)
-        return toRGBHex ($tn, $tp, $to);
-    else if ($hs < 4.0)
-        return toRGBHex ($tn, $to, $tp);
-    else if ($hs < 5.0)
-        return toRGBHex ($to, $tn, $tp);
+    if ($hs < 1.0) {
+        $color ["redL"] = $tp; $color ["greenL"] = $to; $color ["blueL"] = $tn;
+    } else if ($hs < 2.0) {
+        $color ["redL"] = $to; $color ["greenL"] = $tp; $color ["blueL"] = $tn;
+    } else if ($hs < 3.0) {
+        $color ["redL"] = $tn; $color ["greenL"] = $tp; $color ["blueL"] = $to;
+    } else if ($hs < 4.0) {
+        $color ["redL"] = $tn; $color ["greenL"] = $to; $color ["blueL"] = $tp;
+    } else if ($hs < 5.0) {
+        $color ["redL"] = $to; $color ["greenL"] = $tn; $color ["blueL"] = $tp;
+    } else {
+        $color ["redL"] = $tp; $color ["greenL"] = $tn; $color ["blueL"] = $to;
+    }
+
+    $color ["red256"] = round (pow ($color ["redL"], 1/2.2)*255);
+    $color ["green256"] = round (pow ($color ["greenL"], 1/2.2)*255);
+    $color ["blue256"] = round (pow ($color ["blueL"], 1/2.2)*255);
+    $color ["hex"] = sprintf ("#%'02X%'02X%'02X", $color ["red256"], $color \
["green256"], $color ["blue256"]); +
+    $color ["brightness"] = (299 * $color ["red256"] + 587 * $color ["green256"] + \
114 * $color ["blue256"]) / 1000; +
+    $max = max ($color ["redL"], $color ["greenL"], $color ["blueL"]);
+    $min = min ($color ["redL"], $color ["greenL"], $color ["blueL"]);
+    if ($max == $min)
+        $color ["chroma"] = 0;
     else
-        return toRGBHex ($tp, $tn, $to);
+        $color ["chroma"] = round (max (($max-$min)*0.0722/$color ["luminosity"], \
($max-$min)*0.0722/(1-$color ["luminosity"])), 10); +
 }
 
-function tint1 (const $basecolor, const $tintcolor, $amount, &$luminosity) {
+function tint1 (const $basecolor, const $tintcolor, $amount) {
     // ported from Matthew's implementation in kdelibs
     $newcolor = array ();
+
     $newcolor ["red256"] = round ($basecolor ["red256"] + pow ($amount, 0.5) * \
                ($tintcolor ["red256"] - $basecolor ["red256"]));
     $newcolor ["green256"] = round ($basecolor ["green256"] + pow ($amount, 0.5) * \
                ($tintcolor ["green256"] - $basecolor ["green256"]));
     $newcolor ["blue256"] = round ($basecolor ["blue256"] + pow ($amount, 0.5) * \
                ($tintcolor ["blue256"] - $basecolor ["blue256"]));
-    computeColor ($newcolor);
-    $luminosity = $basecolor ["luminosity"] + $amount * ($newcolor ["luminosity"] - \
                $basecolor ["luminosity"]);
-    return toRGB ($newcolor ["hue"], $newcolor ["saturation"], $luminosity);
+    computeColorFromRGB ($newcolor);
+
+    $newcolor ["luminosity"] = $basecolor ["luminosity"] + $amount * ($newcolor \
["luminosity"] - $basecolor ["luminosity"]); +    computeColorFromHSL ($newcolor);
+
+    return $newcolor;
 }
 
-function tint2 (const $basecolor, const $tintcolor, $amount, &$luminosity) {
-    $luminosity = $basecolor ["luminosity"];
-    if ($luminosity < 0.07)  $luminosity = $tintcolor ["luminosity"] < 0.07 ? \
                $tintcolor ["luminosity"] : 0.07;
-    if ($luminosity > 0.65)  $luminosity = $tintcolor ["luminosity"] > 0.65 ? \
                $tintcolor ["luminosity"] : 0.65;
-    $luminosity = $basecolor ["luminosity"] + $amount*($luminosity - $basecolor \
                ["luminosity"]);
-    $hue = $tintcolor ["hue"];
-    $saturation = $basecolor ["saturation"] + $amount*($tintcolor ["saturation"] - \
                $basecolor ["saturation"]);
-    return toRGB ($hue, $saturation, $luminosity);
+function tint2 (const $basecolor, const $tintcolor, $amount) {
+    $newcolor = array ();
+
+    $color ["hue"] = $tintcolor ["hue"];
+    $color ["saturation"] = $tintcolor ["saturation"];
+    $color ["luminosity"] = $basecolor ["luminosity"];
+    if ($color ["luminosity"] < 0.07)  $color ["luminosity"] = $tintcolor \
["luminosity"] < 0.07 ? $tintcolor ["luminosity"] : 0.07; +    if ($color \
["luminosity"] > 0.65)  $color ["luminosity"] = $tintcolor ["luminosity"] > 0.65 ? \
$tintcolor ["luminosity"] : 0.65; +    computeColorFromHSL ($newcolor);
+
+    $newcolor ["red256"] = round ($basecolor ["red256"] + pow ($amount, 0.5) * \
($newcolor ["red256"] - $basecolor ["red256"])); +    $newcolor ["green256"] = round \
($basecolor ["green256"] + pow ($amount, 0.5) * ($newcolor ["green256"] - $basecolor \
["green256"])); +    $newcolor ["blue256"] = round ($basecolor ["blue256"] + pow \
($amount, 0.5) * ($newcolor ["blue256"] - $basecolor ["blue256"])); +    \
computeColorFromRGB ($newcolor); +
+    return $newcolor;
 }
 
 function printTableLine (const $colors, const $color, const $name, const $tablename) \
{ @@ -255,10 +276,11 @@
         echo '</div>';
         echo '<div>';
         echo 'Tint1: ';
-        $luminosity = 0;
         for ($amount = 0; $amount <= 10; $amount++) {
-            echo '<span style="background-color:'.tint1 ($extracolor, $color, \
                $amount/10, $luminosity).';color:';
-            echo ($luminosity <= 0.09) ? "#FFFFFF" : (($luminosity >= 0.55) ? \
"#000000" : "#800000"); +            echo '<span style="background-color:';
+            $newcolor = tint1 ($extracolor, $color, $amount/10);
+            echo $newcolor ["hex"].';color:';
+            echo ($newcolor ["luminosity"] <= 0.09) ? "#FFFFFF" : (($newcolor \
["luminosity"] >= 0.55) ? "#000000" : "#800000");  echo '">';
             printf ('%.1f ', $amount/10);
             echo '</span>';
@@ -267,8 +289,10 @@
         echo '<div>';
         echo 'Tint2: ';
         for ($amount = 0; $amount <= 10; $amount++) {
-            echo '<span style="background-color:'.tint2 ($extracolor, $color, \
                $amount/10, $luminosity).';color:';
-            echo ($luminosity <= 0.09) ? "#FFFFFF" : (($luminosity >= 0.55) ? \
"#000000" : "#800000"); +            echo '<span style="background-color:';
+            $newcolor = tint2 ($extracolor, $color, $amount/10);
+            echo $newcolor ["hex"].';color:';
+            echo ($newcolor ["luminosity"] <= 0.09) ? "#FFFFFF" : (($newcolor \
["luminosity"] >= 0.55) ? "#000000" : "#800000");  echo '">';
             printf ('%.1f ', $amount/10);
             echo '</span>';
@@ -533,13 +557,13 @@
 $luminosities = array();
 
 foreach ($oxygencolors as $oxygenname=>$oxygencolor)
-    computeColor ($oxygencolors [$oxygenname]);
+    computeColorFromRGB ($oxygencolors [$oxygenname]);
 foreach ($cigcolors as $cigname=>$cigcolor)
-    computeColor ($cigcolors [$cigname]);
+    computeColorFromRGB ($cigcolors [$cigname]);
 foreach ($defaultcolors as $defaultname=>$defaultcolor)
-    computeColor ($defaultcolors [$defaultname]);
+    computeColorFromRGB ($defaultcolors [$defaultname]);
 foreach ($extracolors as $extraname=>$extracolor)
-    computeColor ($extracolors [$extraname]);
+    computeColorFromRGB ($extracolors [$extraname]);
 
 if ($_GET ["sortby"] == "name") {
   ksort ($defaultcolors);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic