00001 #include "std/config.H"
00002 #include "disp/colors.H"
00003
00004
00005 CCOLOR COLOR::black(0.0,0.0,0.0);
00006 CCOLOR COLOR::white(1.0,1.0,1.0);
00007
00008 CCOLOR COLOR::red (1.0,0.0,0.0);
00009 CCOLOR COLOR::green(0.0,1.0,0.0);
00010 CCOLOR COLOR::blue (0.0,0.0,1.0);
00011
00012
00013
00014
00015 COLOR::COLOR(CHSVCOLOR &c)
00016 {
00017 double h = (c[0] == 1.0) ? 0.0 : (c[0] * 6.0);
00018 double hf = h - (int)h;
00019
00020 double p1 = c[2] * (1.0 - (c[1]) );
00021 double p2 = c[2] * (1.0 - (c[1] * ( hf) ));
00022 double p3 = c[2] * (1.0 - (c[1] * (1.0-hf) ));
00023
00024 switch((int)h){
00025 case 0 :
00026 _x = c[2] ; _y = p3; _z = p1;
00027 break;
00028 case 1 :
00029 _x = p2; _y = c[2] ; _z = p1;
00030 break;
00031 case 2 :
00032 _x = p1; _y = c[2] ; _z = p3;
00033 break;
00034 case 3 :
00035 _x = p1; _y = p2; _z = c[2] ;
00036 break;
00037 case 4 :
00038 _x = p3; _y = p1; _z = c[2] ;
00039 break;
00040 case 5 :
00041 _x = c[2] ; _y = p1; _z = p2;
00042 break;
00043 default:
00044 cerr << "Bad HSVCOLOR used in COLOR constructor!!!" << endl;
00045 _x = _y = _z = -1.0;
00046 }
00047
00048 }
00049
00050 HSVCOLOR::HSVCOLOR(CCOLOR &c)
00051 {
00052
00053
00054 double m = min(min(c[0],c[1]),c[2]);
00055 _z = max(max(c[0],c[1]),c[2]);
00056 _y = (_z!=0.0)?(_z-m)/_z:0.0;
00057
00058 if ((m < 0.0) || (_z > 1.0))
00059 {
00060 cerr << "Bad COLOR used in HSVCOLOR constructor!!!" << endl;
00061 _x = _y = _z = -1.0;
00062 return;
00063 }
00064
00065 if (_y != 0.0) {
00066
00067 double r1 = (_z - c[0]) / (_z - m);
00068 double g1 = (_z - c[1]) / (_z - m);
00069 double b1 = (_z - c[2]) / (_z - m);
00070
00071 if (_z == c[0])
00072 {
00073 _x = (m == c[1]) ? 5.0 + b1 : 1.0 - g1;
00074 }
00075 else if (_z == c[1])
00076 {
00077 _x = (m == c[2]) ? 1.0 + r1 : 3.0 - b1;
00078 }
00079 else
00080 {
00081 _x = (m == c[0]) ? 3.0 + g1 : 5.0 - r1;
00082 }
00083
00084 _x /= 6.0;
00085
00086 }
00087 else
00088 {
00089 _x = 0.0;
00090 }
00091
00092 }
00093
00094