00001
00002
00003 #include <iostream>
00004
00005
00006 #include <vcg/space/color4.h>
00007 #include <vcg/space/colorspace.h>
00008
00009 using namespace std;
00010
00011 typedef vcg::ColorSpace<double> ColorSpace;
00012
00013 int main(int argc,char ** argv)
00014 {
00015
00016
00017 cout << endl;
00018
00019 if (argc != 4)
00020 {
00021 cout << " Usage: colorspace <r> <g> <b>" << endl << endl;
00022 cout << " <r> <g> <b> : RGB triplet (0-255)" << endl << endl;
00023 cout << " Note: The RGB triplet is assumed in the sRGB space (D65 illuminant).";
00024 cout << endl << endl;
00025 exit(-2);
00026 }
00027
00028 double r = static_cast<double>(atof(argv[1]));
00029 double g = static_cast<double>(atof(argv[2]));
00030 double b = static_cast<double>(atof(argv[3]));
00031
00032
00033 vcg::Color4<double> color(r/255.0, g/255.0, b/255.0, 0.0);
00034
00035
00036
00038
00039 cout << " * RGB --> RGB conversion" << endl << endl;
00040
00041 vcg::Color4<double> rgb = ColorSpace::RGBtoRGB(color, ColorSpace::SRGB, ColorSpace::PAL_RGB);
00042 rgb *= 255.0;
00043 cout << " RGB (PAL/SECAM): " << rgb[0] << " " << rgb[1] << " " << rgb[2] << endl;
00044
00045 rgb = ColorSpace::RGBtoRGB(color, ColorSpace::SRGB, ColorSpace::WIDE_GAMUT);
00046 rgb *= 255.0;
00047 cout << " RGB (Wide Gamut): " << rgb[0] << " " << rgb[1] << " " << rgb[2] << endl << endl;
00048
00049
00050
00052
00053 cout << " * RGB <--> HSL conversion" << endl << endl;
00054
00055 vcg::Color4<double> hsl = ColorSpace::RGBtoHSL(color);
00056 cout << " RGB --> HSL: " << hsl[0]*360.0 << "° " << hsl[1]*100.0 << "% " << hsl[2]*100.0 << "% " << endl;
00057
00058 rgb = ColorSpace::HSLtoRGB(hsl);
00059 rgb *= 255.0;
00060 cout << " HSL --> RGB: " << rgb[0] << " " << rgb[1] << " " << rgb[2] << endl << endl;
00061
00062
00063
00065
00066 cout << " * RGB <--> HSV conversion" << endl << endl;
00067
00068 vcg::Color4<double> hsv = ColorSpace::RGBtoHSV(color);
00069 cout << " RGB --> HSV: " << hsv[0]*360.0 << "° " << hsv[1]*100.0 << "% " << hsv[2]*100.0 << "% " << endl;
00070
00071 rgb = ColorSpace::HSVtoRGB(hsv);
00072 rgb *= 255.0;
00073 cout << " HSV --> RGB: " << rgb[0] << " " << rgb[1] << " " << rgb[2] << endl << endl;
00074
00075
00076
00078
00079 cout << " * RGB <--> Lab conversion" << endl << endl;
00080
00081 vcg::Color4<double> xyzD65 = ColorSpace::RGBtoXYZ(color, ColorSpace::SRGB, ColorSpace::ILLUMINANT_D65);
00082 vcg::Color4<double> lab = ColorSpace::XYZtoCIELab(xyzD65, ColorSpace::refIlluminant(ColorSpace::SRGB));
00083 cout << " RGB --> CIELab: " << lab[0] << " " << lab[1] << " " << lab[2] << endl;
00084
00085 vcg::Color4<double> xyz = ColorSpace::CIELabtoXYZ(lab, ColorSpace::refIlluminant(ColorSpace::SRGB));
00086 rgb = ColorSpace::XYZtoRGB(xyz, ColorSpace::refIlluminant(ColorSpace::SRGB), ColorSpace::SRGB);
00087 rgb *= 255.0;
00088 cout << " CIELab --> RGB: " << rgb[0] << " " << rgb[1] << " " << rgb[2] << endl << endl;
00089
00090
00091
00092
00094
00095 cout << " * RGB <--> XYZ conversion" << endl << endl;
00096
00097
00098 cout << " RGB --> XYZ (D65): " << xyzD65[0] << " " << xyzD65[1] << " " << xyzD65[2] << endl;
00099
00100
00101 rgb = ColorSpace::XYZtoRGB(xyzD65, ColorSpace::ILLUMINANT_D65, ColorSpace::SRGB);
00102 rgb *= 255.0;
00103 cout << " XYZ (D65) --> RGB: " << rgb[0] << " " << rgb[1] << " " << rgb[2] << endl;
00104
00105
00106 vcg::Color4<double> xyzD50 = ColorSpace::RGBtoXYZ(color, ColorSpace::SRGB, ColorSpace::ILLUMINANT_D50);
00107 cout << " RGB --> XYZ (D50): " << xyzD50[0] << " " << xyzD50[1] << " " << xyzD50[2] << endl;
00108
00109
00110 rgb = ColorSpace::XYZtoRGB(xyzD50, ColorSpace::ILLUMINANT_D50, ColorSpace::SRGB);
00111 rgb *= 255.0;
00112 cout << " XYZ (D50) --> RGB: " << rgb[0] << " " << rgb[1] << " " << rgb[2] << endl;
00113
00114
00115 xyz = ColorSpace::chromaticAdaptation(xyzD65, ColorSpace::ILLUMINANT_D65, ColorSpace::ILLUMINANT_D50);
00116 cout << " XYZ (D65 --> D50): " << xyz[0] << " " << xyz[1] << " " << xyz[2] << endl << endl;
00117
00118 return 0;
00119 }
00120