color.C

00001 /*
00002  * This file is part of the "Archon" framework.
00003  * (http://files3d.sourceforge.net)
00004  *
00005  * Copyright © 2002 by Kristian Spangsege and Brian Kristiansen.
00006  *
00007  * Permission to use, copy, modify, and distribute this software and
00008  * its documentation under the terms of the GNU General Public License is
00009  * hereby granted. No representations are made about the suitability of
00010  * this software for any purpose. It is provided "as is" without express
00011  * or implied warranty. See the GNU General Public License
00012  * (http://www.gnu.org/copyleft/gpl.html) for more details.
00013  *
00014  * The characters in this file are ISO8859-1 encoded.
00015  *
00016  * The documentation in this file is in "Doxygen" style
00017  * (http://www.doxygen.org).
00018  */
00019 
00020 #include <iostream>
00021 
00022 #include <archon/math/functions.H>
00023 
00024 #include <archon/util/color.H>
00025 
00026 namespace Archon
00027 {
00028   namespace Utilities
00029   {
00030     namespace Color
00031     {
00032       Vector3 convertRGBtoHSV(Vector3 c)
00033       {
00034         double v = c.max();
00035         double d = v - c.min();
00036         if(d == 0) return Vector3(0, 0, v); // Achromatic
00037         double h =
00038           (v == c[0] ? (c[1] - c[2]) / d :
00039            v == c[1] ? 2 + (c[2] - c[0]) / d :
00040            4 + (c[0] - c[1]) / d) * 60;
00041         if(h<0) h += 360;
00042         return Vector3(h, d/v, v);
00043       }
00044 
00045       Vector3 convertHSVtoRGB(Vector3 c)
00046       {
00047         if(c[1] == 0)
00048           return Vector3(c[2], c[2], c[2]); // Achromatic
00049 
00050         double h = modulo<double>(c[0], 360)/60;
00051         int i = static_cast<int>(h);
00052         double f = h - i;
00053         double c0 = c[2] * (1 - c[1]);
00054         double c1 = c[2] * (1 - (c[1] * f));
00055         double c2 = c[2] * (1 - (c[1] * (1 - f)));
00056         switch(i)
00057         {
00058         case 0: return Vector3(c[2], c2, c0);
00059         case 1: return Vector3(c1, c[2], c0);
00060         case 2: return Vector3(c0, c[2], c2);
00061         case 3: return Vector3(c0, c1, c[2]);
00062         case 4: return Vector3(c2, c0, c[2]);
00063         default: return Vector3(c[2], c0, c1);
00064         }
00065       }
00066 
00070       Vector3 interp(double x, double x1, double x2, Vector3 y1, Vector3 y2)
00071       {
00072         Vector3 z1 = convertRGBtoHSV(y1);
00073         Vector3 z2 = convertRGBtoHSV(y2);
00074 
00075         // Pick a sensible value for hue when it is arbitrary/undefined
00076         if(z1[1] == 0) z1[0] = z2[0];
00077         else if(z2[1] == 0) z2[0] = z1[0];
00078 
00079         // Pick a sensible value for saturation when it is arbitrary/undefined
00080         if(z1[2] == 0) z1[1] = z2[1];
00081         else if(z2[2] == 0) z2[1] = z1[1];
00082 
00083         // Pick the shortest hue arc
00084         double d = z2[0] - z1[0];
00085         if(d < -180) z2[0] += 360;
00086         else if(d > 180) z1[0] += 360;
00087 
00088         return convertHSVtoRGB(linInterp(x, x1, x2, z1, z2));
00089       }
00090 
00091       const Vector3 aliceblue(240/255.0, 248/255.0, 255/255.0);
00092       const Vector3 antiquewhite(250/255.0, 235/255.0, 215/255.0);
00093       const Vector3 aqua(0/255.0, 255/255.0, 255/255.0);
00094       const Vector3 aquamarine(127/255.0, 255/255.0, 212/255.0);
00095       const Vector3 azure(240/255.0, 255/255.0, 255/255.0);
00096       const Vector3 beige(245/255.0, 245/255.0, 220/255.0);
00097       const Vector3 bisque(255/255.0, 228/255.0, 196/255.0);
00098       const Vector3 black(0/255.0, 0/255.0, 0/255.0);
00099       const Vector3 blanchedalmond(255/255.0, 235/255.0, 205/255.0);
00100       const Vector3 blue(0/255.0, 0/255.0, 255/255.0);
00101       const Vector3 blueviolet(138/255.0, 43/255.0, 226/255.0);
00102       const Vector3 brown(165/255.0, 42/255.0, 42/255.0);
00103       const Vector3 burlywood(222/255.0, 184/255.0, 135/255.0);
00104       const Vector3 cadetblue(95/255.0, 158/255.0, 160/255.0);
00105       const Vector3 chartreuse(127/255.0, 255/255.0, 0/255.0);
00106       const Vector3 chocolate(210/255.0, 105/255.0, 30/255.0);
00107       const Vector3 coral(255/255.0, 127/255.0, 80/255.0);
00108       const Vector3 cornflowerblue(100/255.0, 149/255.0, 237/255.0);
00109       const Vector3 cornsilk(255/255.0, 248/255.0, 220/255.0);
00110       const Vector3 crimson(220/255.0, 20/255.0, 54/255.0);
00111       const Vector3 cyan(0/255.0, 255/255.0, 255/255.0);
00112       const Vector3 darkblue(0/255.0, 0/255.0, 139/255.0);
00113       const Vector3 darkcyan(0/255.0, 139/255.0, 139/255.0);
00114       const Vector3 darkgoldenrod(184/255.0, 134/255.0, 11/255.0);
00115       const Vector3 darkgray(169/255.0, 169/255.0, 169/255.0);
00116       const Vector3 darkgreen(0/255.0, 100/255.0, 0/255.0);
00117       const Vector3 darkkhaki(189/255.0, 183/255.0, 107/255.0);
00118       const Vector3 darkmagenta(139/255.0, 0/255.0, 139/255.0);
00119       const Vector3 darkolivegreen(85/255.0, 107/255.0, 47/255.0);
00120       const Vector3 darkorange(255/255.0, 140/255.0, 0/255.0);
00121       const Vector3 darkorchid(153/255.0, 50/255.0, 204/255.0);
00122       const Vector3 darkred(139/255.0, 0/255.0, 0/255.0);
00123       const Vector3 darksalmon(233/255.0, 150/255.0, 122/255.0);
00124       const Vector3 darkseagreen(143/255.0, 188/255.0, 143/255.0);
00125       const Vector3 darkslateblue(72/255.0, 61/255.0, 139/255.0);
00126       const Vector3 darkslategray(47/255.0, 79/255.0, 79/255.0);
00127       const Vector3 darkturquoise(0/255.0, 206/255.0, 209/255.0);
00128       const Vector3 darkviolet(148/255.0, 0/255.0, 211/255.0);
00129       const Vector3 deeppink(255/255.0, 20/255.0, 147/255.0);
00130       const Vector3 deepskyblue(0/255.0, 191/255.0, 255/255.0);
00131       const Vector3 dimgray(105/255.0, 105/255.0, 105/255.0);
00132       const Vector3 dodgerblue(30/255.0, 144/255.0, 255/255.0);
00133       const Vector3 firebrick(178/255.0, 34/255.0, 34/255.0);
00134       const Vector3 floralwhite(255/255.0, 250/255.0, 240/255.0);
00135       const Vector3 forestgreen(34/255.0, 139/255.0, 34/255.0);
00136       const Vector3 fuchsia(255/255.0, 0/255.0, 255/255.0);
00137       const Vector3 gainsboro(220/255.0, 220/255.0, 220/255.0);
00138       const Vector3 ghostwhite(248/255.0, 248/255.0, 255/255.0);
00139       const Vector3 gold(255/255.0, 215/255.0, 0/255.0);
00140       const Vector3 goldenrod(218/255.0, 165/255.0, 32/255.0);
00141       const Vector3 gray(128/255.0, 128/255.0, 128/255.0);
00142       const Vector3 green(0/255.0, 128/255.0, 0/255.0);
00143       const Vector3 greenyellow(173/255.0, 255/255.0, 47/255.0);
00144       const Vector3 honeydew(240/255.0, 255/255.0, 240/255.0);
00145       const Vector3 hotpink(255/255.0, 105/255.0, 180/255.0);
00146       const Vector3 indianred(205/255.0, 92/255.0, 92/255.0);
00147       const Vector3 indigo(75/255.0, 0/255.0, 130/255.0);
00148       const Vector3 ivory(255/255.0, 255/255.0, 240/255.0);
00149       const Vector3 khaki(240/255.0, 230/255.0, 140/255.0);
00150       const Vector3 lavender(230/255.0, 230/255.0, 250/255.0);
00151       const Vector3 lavenderblush(255/255.0, 240/255.0, 245/255.0);
00152       const Vector3 lawngreen(124/255.0, 252/255.0, 0/255.0);
00153       const Vector3 lemonchiffon(255/255.0, 250/255.0, 205/255.0);
00154       const Vector3 lightblue(173/255.0, 216/255.0, 230/255.0);
00155       const Vector3 lightcoral(240/255.0, 128/255.0, 128/255.0);
00156       const Vector3 lightcyan(224/255.0, 255/255.0, 255/255.0);
00157       const Vector3 lightgoldenrodyellow(250/255.0, 250/255.0, 210/255.0);
00158       const Vector3 lightgreen(144/255.0, 238/255.0, 144/255.0);
00159       const Vector3 lightgrey(211/255.0, 211/255.0, 211/255.0);
00160       const Vector3 lightpink(255/255.0, 182/255.0, 193/255.0);
00161       const Vector3 lightsalmon(255/255.0, 160/255.0, 122/255.0);
00162       const Vector3 lightseagreen(32/255.0, 178/255.0, 170/255.0);
00163       const Vector3 lightskyblue(135/255.0, 206/255.0, 250/255.0);
00164       const Vector3 lightslategray(119/255.0, 136/255.0, 153/255.0);
00165       const Vector3 lightsteelblue(176/255.0, 196/255.0, 222/255.0);
00166       const Vector3 lightyellow(255/255.0, 255/255.0, 224/255.0);
00167       const Vector3 lime(0/255.0, 255/255.0, 0/255.0);
00168       const Vector3 limegreen(50/255.0, 205/255.0, 50/255.0);
00169       const Vector3 linen(250/255.0, 240/255.0, 230/255.0);
00170       const Vector3 magenta(255/255.0, 0/255.0, 255/255.0);
00171       const Vector3 maroon(128/255.0, 0/255.0, 0/255.0);
00172       const Vector3 mediumaquamarine(102/255.0, 205/255.0, 170/255.0);
00173       const Vector3 mediumblue(0/255.0, 0/255.0, 205/255.0);
00174       const Vector3 mediumorchid(186/255.0, 85/255.0, 211/255.0);
00175       const Vector3 mediumpurple(147/255.0, 112/255.0, 219/255.0);
00176       const Vector3 mediumseagreen(60/255.0, 179/255.0, 113/255.0);
00177       const Vector3 mediumslateblue(123/255.0, 104/255.0, 238/255.0);
00178       const Vector3 mediumspringgreen(0/255.0, 250/255.0, 154/255.0);
00179       const Vector3 mediumturquoise(72/255.0, 209/255.0, 204/255.0);
00180       const Vector3 mediumvioletred(199/255.0, 21/255.0, 133/255.0);
00181       const Vector3 midnightblue(25/255.0, 25/255.0, 112/255.0);
00182       const Vector3 mintcream(245/255.0, 255/255.0, 250/255.0);
00183       const Vector3 mistyrose(255/255.0, 228/255.0, 225/255.0);
00184       const Vector3 moccasin(255/255.0, 228/255.0, 181/255.0);
00185       const Vector3 navajowhite(255/255.0, 222/255.0, 173/255.0);
00186       const Vector3 navy(0/255.0, 0/255.0, 128/255.0);
00187       const Vector3 oldlace(253/255.0, 245/255.0, 230/255.0);
00188       const Vector3 olive(128/255.0, 128/255.0, 0/255.0);
00189       const Vector3 olivedrab(107/255.0, 142/255.0, 35/255.0);
00190       const Vector3 orange(255/255.0, 165/255.0, 0/255.0);
00191       const Vector3 orangered(255/255.0, 69/255.0, 0/255.0);
00192       const Vector3 orchid(218/255.0, 112/255.0, 214/255.0);
00193       const Vector3 palegoldenrod(238/255.0, 232/255.0, 170/255.0);
00194       const Vector3 palegreen(152/255.0, 251/255.0, 152/255.0);
00195       const Vector3 paleturquoise(175/255.0, 238/255.0, 238/255.0);
00196       const Vector3 palevioletred(219/255.0, 112/255.0, 147/255.0);
00197       const Vector3 papayawhip(255/255.0, 239/255.0, 213/255.0);
00198       const Vector3 peachpuff(255/255.0, 218/255.0, 185/255.0);
00199       const Vector3 peru(205/255.0, 133/255.0, 63/255.0);
00200       const Vector3 pink(255/255.0, 192/255.0, 203/255.0);
00201       const Vector3 plum(221/255.0, 160/255.0, 221/255.0);
00202       const Vector3 powderblue(176/255.0, 224/255.0, 230/255.0);
00203       const Vector3 purple(128/255.0, 0/255.0, 128/255.0);
00204       const Vector3 red(255/255.0, 0/255.0, 0/255.0);
00205       const Vector3 rosybrown(188/255.0, 143/255.0, 143/255.0);
00206       const Vector3 royalblue(65/255.0, 105/255.0, 225/255.0);
00207       const Vector3 saddlebrown(139/255.0, 69/255.0, 19/255.0);
00208       const Vector3 salmon(250/255.0, 128/255.0, 114/255.0);
00209       const Vector3 sandybrown(244/255.0, 164/255.0, 96/255.0);
00210       const Vector3 seagreen(46/255.0, 139/255.0, 87/255.0);
00211       const Vector3 seashell(255/255.0, 245/255.0, 238/255.0);
00212       const Vector3 sienna(160/255.0, 82/255.0, 45/255.0);
00213       const Vector3 silver(192/255.0, 192/255.0, 192/255.0);
00214       const Vector3 skyblue(135/255.0, 206/255.0, 235/255.0);
00215       const Vector3 slateblue(106/255.0, 90/255.0, 205/255.0);
00216       const Vector3 slategray(112/255.0, 128/255.0, 144/255.0);
00217       const Vector3 snow(255/255.0, 250/255.0, 250/255.0);
00218       const Vector3 springgreen(0/255.0, 255/255.0, 127/255.0);
00219       const Vector3 steelblue(70/255.0, 130/255.0, 180/255.0);
00220       const Vector3 tan(210/255.0, 180/255.0, 140/255.0);
00221       const Vector3 teal(0/255.0, 128/255.0, 128/255.0);
00222       const Vector3 thistle(216/255.0, 191/255.0, 216/255.0);
00223       const Vector3 tomato(255/255.0, 99/255.0, 71/255.0);
00224       const Vector3 turquoise(64/255.0, 224/255.0, 208/255.0);
00225       const Vector3 violet(238/255.0, 130/255.0, 238/255.0);
00226       const Vector3 wheat(245/255.0, 222/255.0, 179/255.0);
00227       const Vector3 white(255/255.0, 255/255.0, 255/255.0);
00228       const Vector3 whitesmoke(245/255.0, 245/255.0, 245/255.0);
00229       const Vector3 yellow(255/255.0, 255/255.0, 0/255.0);
00230       const Vector3 yellowgreen(154/255.0, 205/255.0, 50/255.0);
00231     }
00232   }
00233 }

Generated on Sun Jul 30 22:55:44 2006 for Archon by  doxygen 1.4.4