28 #include <vcg/space/color4.h>
29 #include <vcg/space/colorspace.h>
33 typedef vcg::ColorSpace<double> ColorSpace;
35 int main(
int argc,
char ** argv)
43 cout <<
" Usage: colorspace <r> <g> <b>" << endl << endl;
44 cout <<
" <r> <g> <b> : RGB triplet (0-255)" << endl << endl;
45 cout <<
" Note: The RGB triplet is assumed in the sRGB space (D65 illuminant).";
50 double r =
static_cast<double>(atof(argv[1]));
51 double g =
static_cast<double>(atof(argv[2]));
52 double b =
static_cast<double>(atof(argv[3]));
55 vcg::Color4<double> color(r/255.0, g/255.0, b/255.0, 0.0);
61 cout <<
" * RGB --> RGB conversion" << endl << endl;
63 vcg::Color4<double> rgb = ColorSpace::RGBtoRGB(color, ColorSpace::SRGB, ColorSpace::PAL_RGB);
65 cout <<
" RGB (PAL/SECAM): " << rgb[0] <<
" " << rgb[1] <<
" " << rgb[2] << endl;
67 rgb = ColorSpace::RGBtoRGB(color, ColorSpace::SRGB, ColorSpace::WIDE_GAMUT);
69 cout <<
" RGB (Wide Gamut): " << rgb[0] <<
" " << rgb[1] <<
" " << rgb[2] << endl << endl;
75 cout <<
" * RGB <--> HSL conversion" << endl << endl;
77 vcg::Color4<double> hsl = ColorSpace::RGBtoHSL(color);
78 cout <<
" RGB --> HSL: " << hsl[0]*360.0 <<
"° " << hsl[1]*100.0 <<
"% " << hsl[2]*100.0 <<
"% " << endl;
80 rgb = ColorSpace::HSLtoRGB(hsl);
82 cout <<
" HSL --> RGB: " << rgb[0] <<
" " << rgb[1] <<
" " << rgb[2] << endl << endl;
88 cout <<
" * RGB <--> HSV conversion" << endl << endl;
90 vcg::Color4<double> hsv = ColorSpace::RGBtoHSV(color);
91 cout <<
" RGB --> HSV: " << hsv[0]*360.0 <<
"° " << hsv[1]*100.0 <<
"% " << hsv[2]*100.0 <<
"% " << endl;
93 rgb = ColorSpace::HSVtoRGB(hsv);
95 cout <<
" HSV --> RGB: " << rgb[0] <<
" " << rgb[1] <<
" " << rgb[2] << endl << endl;
101 cout <<
" * RGB <--> Lab conversion" << endl << endl;
103 vcg::Color4<double> xyzD65 = ColorSpace::RGBtoXYZ(color, ColorSpace::SRGB, ColorSpace::VCG_ILLUMINANT_D65);
104 vcg::Color4<double> lab = ColorSpace::XYZtoCIELab(xyzD65, ColorSpace::refIlluminant(ColorSpace::SRGB));
105 cout <<
" RGB --> CIELab: " << lab[0] <<
" " << lab[1] <<
" " << lab[2] << endl;
107 vcg::Color4<double> xyz = ColorSpace::CIELabtoXYZ(lab, ColorSpace::refIlluminant(ColorSpace::SRGB));
108 rgb = ColorSpace::XYZtoRGB(xyz, ColorSpace::refIlluminant(ColorSpace::SRGB), ColorSpace::SRGB);
110 cout <<
" CIELab --> RGB: " << rgb[0] <<
" " << rgb[1] <<
" " << rgb[2] << endl << endl;
117 cout <<
" * RGB <--> XYZ conversion" << endl << endl;
120 cout <<
" RGB --> XYZ (D65): " << xyzD65[0] <<
" " << xyzD65[1] <<
" " << xyzD65[2] << endl;
123 rgb = ColorSpace::XYZtoRGB(xyzD65, ColorSpace::VCG_ILLUMINANT_D65, ColorSpace::SRGB);
125 cout <<
" XYZ (D65) --> RGB: " << rgb[0] <<
" " << rgb[1] <<
" " << rgb[2] << endl;
128 vcg::Color4<double> xyzD50 = ColorSpace::RGBtoXYZ(color, ColorSpace::SRGB, ColorSpace::VCG_ILLUMINANT_D50);
129 cout <<
" RGB --> XYZ (D50): " << xyzD50[0] <<
" " << xyzD50[1] <<
" " << xyzD50[2] << endl;
132 rgb = ColorSpace::XYZtoRGB(xyzD50, ColorSpace::VCG_ILLUMINANT_D50, ColorSpace::SRGB);
134 cout <<
" XYZ (D50) --> RGB: " << rgb[0] <<
" " << rgb[1] <<
" " << rgb[2] << endl;
137 xyz = ColorSpace::chromaticAdaptation(xyzD65, ColorSpace::VCG_ILLUMINANT_D65, ColorSpace::VCG_ILLUMINANT_D50);
138 cout <<
" XYZ (D65 --> D50): " << xyz[0] <<
" " << xyz[1] <<
" " << xyz[2] << endl << endl;