diff --git a/modules/gfx/pymod/export_color.cc b/modules/gfx/pymod/export_color.cc index 006331174f56347499be724dd7f2dcdb9f797cd2..5eb1b7777ba6590d914ba67f6ecd3a6c1fd4c2e6 100644 --- a/modules/gfx/pymod/export_color.cc +++ b/modules/gfx/pymod/export_color.cc @@ -46,17 +46,13 @@ namespace { return m.str(); } - Color rgb1(float r, float g, float b) {return RGB(r,g,b);} - Color rgb2(uchar r, uchar g, uchar b) {return RGB(r,g,b);} - Color rgb3(uint rgb) {return RGB(static_cast<uchar>((rgb>>16)&0xff), - static_cast<uchar>((rgb>>8)&0xff), - static_cast<uchar>((rgb)&0xff));} - Color rgba1(float r, float g, float b, float a) {return RGBA(r,g,b,a);} - Color rgba2(uchar r, uchar g, uchar b, uchar a) {return RGBA(r,g,b,a);} - Color rgba3(uint rgba) {return RGBA(static_cast<uchar>((rgba>>24)&0xff), - static_cast<uchar>((rgba>>16)&0xff), - static_cast<uchar>((rgba>>8)&0xff), - static_cast<uchar>((rgba)&0xff));} + Color rgbh(uint rgb) {return RGB(static_cast<uchar>((rgb>>16)&0xff), + static_cast<uchar>((rgb>>8)&0xff), + static_cast<uchar>((rgb)&0xff));} + Color rgbah(uint rgba) {return RGBA(static_cast<uchar>((rgba>>24)&0xff), + static_cast<uchar>((rgba>>16)&0xff), + static_cast<uchar>((rgba>>8)&0xff), + static_cast<uchar>((rgba)&0xff));} tuple get_rgb(const Color& c) {return make_tuple(c.GetRed(),c.GetGreen(),c.GetBlue());} void set_rgb(Color& c, object rgb) { @@ -152,13 +148,12 @@ void export_color() .def("FromRGBA",&Color::FromRGB) ; - def("RGB",rgb3); - def("RGB",rgb2); - def("RGB",rgb1); - def("RGBA",rgba3); - def("RGBA",rgba2); - def("RGBA",rgba1); + def("RGB",RGB); + def("RGBh",rgbh); + def("RGBb",RGBb); + def("RGBi",RGBi); def("HSV",HSV); + def("HSVi",HSVi); def("HSVA",HSVA); - + def("HSVAi",HSVAi); } diff --git a/modules/gfx/src/color.cc b/modules/gfx/src/color.cc index 124d7aabcef3894d4a8fe1b155b77bb6e88bef9e..43316f51c455e0643c7660274d10a5177177652b 100644 --- a/modules/gfx/src/color.cc +++ b/modules/gfx/src/color.cc @@ -361,7 +361,7 @@ Color RGB(float r, float g, float b) return nrvo; } -Color RGB(uchar r, uchar g, uchar b) +Color RGBb(uchar r, uchar g, uchar b) { static float f=1.0/255.0; Color nrvo; @@ -369,6 +369,14 @@ Color RGB(uchar r, uchar g, uchar b) return nrvo; } +Color RGBi(unsigned int r, unsigned int g, unsigned int b) +{ + static float f=1.0/65535.0; + Color nrvo; + nrvo.SetRGB(static_cast<float>(r)*f,static_cast<float>(g)*f,static_cast<float>(b)*f); + return nrvo; +} + Color RGBA(float r, float g, float b, float a) { Color nrvo; @@ -377,7 +385,7 @@ Color RGBA(float r, float g, float b, float a) return nrvo; } -Color RGBA(uchar r, uchar g, uchar b, uchar a) +Color RGBAb(uchar r, uchar g, uchar b, uchar a) { static float f=1.0/255.0; Color nrvo; @@ -386,6 +394,15 @@ Color RGBA(uchar r, uchar g, uchar b, uchar a) return nrvo; } +Color RGBAi(unsigned int r, unsigned int g, unsigned int b, unsigned a) +{ + static float f=1.0/65535.0; + Color nrvo; + nrvo.SetRGB(static_cast<float>(r)*f,static_cast<float>(g)*f,static_cast<float>(b)*f); + nrvo.SetAlpha(static_cast<float>(a)*f); + return nrvo; +} + Color HSV(float h, float s, float v) { Color nrvo; @@ -393,7 +410,15 @@ Color HSV(float h, float s, float v) return nrvo; } - Color HSVA(float h, float s, float v, float a) +Color HSVi(int r, int g, int b) +{ + static float f=1.0/65535.0; + Color nrvo; + nrvo.SetHSV(static_cast<float>(r)*f,static_cast<float>(g)*f,static_cast<float>(b)*f); + return nrvo; +} + +Color HSVA(float h, float s, float v, float a) { Color nrvo; nrvo.SetHSV(h,s,v); @@ -401,6 +426,14 @@ Color HSV(float h, float s, float v) return nrvo; } +Color HSVAi(int r, int g, int b, int a) +{ + static float f=1.0/65535.0; + Color nrvo; + nrvo.SetHSV(static_cast<float>(r)*f,static_cast<float>(g)*f,static_cast<float>(b)*f); + return nrvo; +} + std::ostream& operator<<(std::ostream& s, const Color& c) { s << "Color(r=" << c.GetRed() << ",g=" <<c.GetGreen() << ",b=" << c.GetBlue() << ",h=" << c.GetHue() << ",s=" << c.GetSat() << ",v=" << c.GetVal() << ",a=" << c.GetAlpha() << ")"; diff --git a/modules/gfx/src/color.hh b/modules/gfx/src/color.hh index e97b085dc8968bf9178bed508c8b8e7585ad339b..6f0220bc2d2863c2744b502fee8c96dad21424ac 100644 --- a/modules/gfx/src/color.hh +++ b/modules/gfx/src/color.hh @@ -159,40 +159,78 @@ private: mutable bool hsv_dirty_; }; -/* - \brief RGB color spec from floats (0.0-1.0) -*/ + +/// \brief RGB color spec from floats (0.0-1.0) Color DLLEXPORT_OST_GFX RGB(float r, float g, float b); -/* - \brief RGB color spec from bytes (0-255) -*/ -Color DLLEXPORT_OST_GFX RGB(uchar r, uchar g, uchar b); +/// \brief RGB color spec from bytes (0-255) +Color DLLEXPORT_OST_GFX RGBb(uchar r, uchar g, uchar b); -/* - \brief RGBA color spec from floats (0.0-1.0) -*/ +/// \brief RGB color spec from integers (0-65535) +Color DLLEXPORT_OST_GFX RGBi(unsigned int r, unsigned int g, unsigned int b); + +/// \brief RGBA color spec from floats (0.0-1.0) Color DLLEXPORT_OST_GFX RGBA(float r, float g, float b, float a); -/* - \brief RGBA color spec from bytes (0-255) -*/ -Color DLLEXPORT_OST_GFX RGBA(uchar r, uchar g, uchar b, uchar a); +/// \brief RGBA color spec from bytes (0-255) +Color DLLEXPORT_OST_GFX RGBAb(uchar r, uchar g, uchar b, uchar a); + +/// \brief RGBA color spec from integers (0-65535) +Color DLLEXPORT_OST_GFX RGBAi(unsigned int r, unsigned int g, unsigned int b, unsigned int a); + /*! - \brief HSV color spec + \brief HSV color spec from floats h: Hue from 0 to 1 (0=red, 2/6=green, 4/6=blue) + outside values are modulus 1, not clamped s: Saturation from 0 (no color) to 1 (full color) + outside values are clamped v: Value from 0 (no light, black) to 1 (full light) + outside values are clamped + + out-of-bounds values are perfectly fine, as they are + sometimes needed in hsv gradients, e.g. + + g1=gfx.Gradient([gfx.HSV(-60.0/360.0,1,1),gfx.HSV(60.0/360.0,1,1)]) + g1.hsv_mode=True + g2=gfx.Gradient([gfx.HSV(300.0/360.0,1,1),gfx.HSV(420.0/360.0,1,1)]) + g2.hsv_mode=True + + both will blend from purple to yellow via red */ Color DLLEXPORT_OST_GFX HSV(float h, float s, float v); /*! - \brief HSVA color spec + \brief HSV color spec from integers + + h: Hue from 0 to 359 (0=red, 120=green, 240=blue) + outside values are modulus 360, not clamped + s: Saturation from 0 (no color) to 100 (full color) + outside values are clamped + v: Value from 0 (no light, black) to 100 (full light) + outside values are clamped + + signed integers on purpose, allows negative values to be + used for hsv gradients, see comments for HSV(float,float,float) +*/ + Color DLLEXPORT_OST_GFX HSVi(int h, int s, int v); + +/*! + \brief HSVA color spec from floats + + see HSV(float,float,float); alpha from 0 to 1 */ Color DLLEXPORT_OST_GFX HSVA(float h, float s, float v, float a); +/*! + \brief HSVA color spec from integers + + see HSVi(int, int, int); alpha from 0 to 100 +*/ +Color DLLEXPORT_OST_GFX HSVAi(int h, int s, int v, int a); + + //! \brief string form DLLEXPORT_OST_GFX std::ostream& operator<<(std::ostream&, const Color& c); diff --git a/modules/gfx/tests/test_color.cc b/modules/gfx/tests/test_color.cc index 0f827802318f2779cb6c5da4afb95d132b79787e..e24c68f9a6a23c814c1e30bdba2cbe25d7c635bb 100644 --- a/modules/gfx/tests/test_color.cc +++ b/modules/gfx/tests/test_color.cc @@ -49,136 +49,142 @@ BOOST_AUTO_TEST_SUITE(gfx) BOOST_AUTO_TEST_CASE(default_color) { Color c; - BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetAlpha(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetHue(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-6); + BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetAlpha(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetHue(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetSat(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); } BOOST_AUTO_TEST_CASE(set_rgb) { Color c; c = RGB(1.0,0.0,0.0); // red - BOOST_CHECK_CLOSE(c.GetAlpha(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetHue(),0.0/6.0,1e-6); - BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-6); + BOOST_CHECK_CLOSE(c.GetAlpha(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetHue(),0.0/6.0,1e-4); + BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); c = RGB(1.0,1.0,0.0); // yellow - BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetHue(),1.0/6.0,1e-6); - BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-6); + BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetHue(),1.0/6.0,1e-4); + BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); c = RGB(0.0,1.0,0.0); // green - BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetHue(),2.0/6.0,1e-6); - BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-6); + BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetHue(),2.0/6.0,1e-4); + BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); c = RGB(0.0,1.0,1.0); // cyan - BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetHue(),3.0/6.0,1e-6); - BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-6); + BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetHue(),3.0/6.0,1e-4); + BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); c = RGB(0.0,0.0,1.0); // blue - BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetHue(),4.0/6.0,1e-6); - BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-6); + BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetHue(),4.0/6.0,1e-4); + BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); c = RGB(1.0,0.0,1.0); // purple - BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetHue(),5.0/6.0,1e-6); - BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-6); + BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetHue(),5.0/6.0,1e-4); + BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); } BOOST_AUTO_TEST_CASE(set_hsv) { Color c; c = HSV(0.0/6.0,1.0,1.0); // red - BOOST_CHECK_CLOSE(c.GetAlpha(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetHue(),0.0/6.0,1e-6); - BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-6); + BOOST_CHECK_CLOSE(c.GetAlpha(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetHue(),0.0/6.0,1e-4); + BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); c = HSV(0.0/6.0,0.5,1.0); // light red - BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetGreen(),0.5,1e-6); - BOOST_CHECK_CLOSE(c.GetBlue(),0.5,1e-6); - BOOST_CHECK_CLOSE(c.GetHue(),0.0/6.0,1e-6); - BOOST_CHECK_CLOSE(c.GetSat(),0.5,1e-6); - BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-6); + BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetGreen(),0.5,1e-4); + BOOST_CHECK_CLOSE(c.GetBlue(),0.5,1e-4); + BOOST_CHECK_CLOSE(c.GetHue(),0.0/6.0,1e-4); + BOOST_CHECK_CLOSE(c.GetSat(),0.5,1e-4); + BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); c = HSV(1.0/6.0,1.0,1.0); // yellow - BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetHue(),1.0/6.0,1e-6); - BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-6); + BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetHue(),1.0/6.0,1e-4); + BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); c = HSV(2.0/6.0,1.0,1.0); // green - BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetHue(),2.0/6.0,1e-6); - BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-6); + BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetHue(),2.0/6.0,1e-4); + BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); c = HSV(2.0/6.0,0.5,1.0); // light green - BOOST_CHECK_CLOSE(c.GetRed(),0.5,1e-6); - BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetBlue(),0.5,1e-6); - BOOST_CHECK_CLOSE(c.GetHue(),2.0/6.0,1e-6); - BOOST_CHECK_CLOSE(c.GetSat(),0.5,1e-6); - BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-6); + BOOST_CHECK_CLOSE(c.GetRed(),0.5,1e-4); + BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetBlue(),0.5,1e-4); + BOOST_CHECK_CLOSE(c.GetHue(),2.0/6.0,1e-4); + BOOST_CHECK_CLOSE(c.GetSat(),0.5,1e-4); + BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); c = HSV(3.0/6.0,1.0,1.0); // cyan - BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetHue(),3.0/6.0,1e-6); - BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-6); + BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetHue(),3.0/6.0,1e-4); + BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); c = HSV(4.0/6.0,1.0,1.0); // blue - BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetHue(),4.0/6.0,1e-6); - BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-6); + BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetHue(),4.0/6.0,1e-4); + BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); c = HSV(4.0/6.0,0.5,1.0); // light blue - BOOST_CHECK_CLOSE(c.GetRed(),0.5,1e-6); - BOOST_CHECK_CLOSE(c.GetGreen(),0.5,1e-6); - BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetHue(),4.0/6.0,1e-6); - BOOST_CHECK_CLOSE(c.GetSat(),0.5,1e-6); - BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-6); + BOOST_CHECK_CLOSE(c.GetRed(),0.5,1e-4); + BOOST_CHECK_CLOSE(c.GetGreen(),0.5,1e-4); + BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetHue(),4.0/6.0,1e-4); + BOOST_CHECK_CLOSE(c.GetSat(),0.5,1e-4); + BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); c = HSV(5.0/6.0,1.0,1.0); // purple - BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-6); - BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetHue(),5.0/6.0,1e-6); - BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-6); - BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-6); + BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-4); + BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetHue(),5.0/6.0,1e-4); + BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); + BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); } BOOST_AUTO_TEST_CASE(set_char) { - BOOST_CHECK(compare_colors(RGB(255,0,0),RGB(1.0,0.0,0.0))); - BOOST_CHECK(compare_colors(RGBA(0,127,0,127),RGBA(0.0,0.5,0.0,0.5))); + BOOST_CHECK(compare_colors(RGBb(255,0,0),RGB(1.0,0.0,0.0))); + BOOST_CHECK(compare_colors(RGBAb(0,127,0,127),RGBA(0.0,0.5,0.0,0.5))); +} + +BOOST_AUTO_TEST_CASE(set_int) +{ + BOOST_CHECK(compare_colors(RGBi(65535,65535,0),RGB(1.0,1.0,0.0))); + BOOST_CHECK(compare_colors(RGBAi(0,32767,0,32767),RGBA(0.0,0.5,0.0,0.5))); } BOOST_AUTO_TEST_SUITE_END() diff --git a/modules/gui/pymod/__init__.py b/modules/gui/pymod/__init__.py index a63b91820c28a4eeb9b03a7c0eb916b99fcc84b9..0d430feefbcd33586d821b1bdf98c61b65391a32 100644 --- a/modules/gui/pymod/__init__.py +++ b/modules/gui/pymod/__init__.py @@ -59,8 +59,7 @@ def PickColor(default=gfx.WHITE): qt_color=dialog.getColor(qt_color) if not qt_color.isValid(): return None - return gfx.Color(qt_color.red()/256.0, qt_color.green()/256.0, - qt_color.blue()/256.0) + return gfx.RGBAb(qt_color.red(), qt_color.green(),qt_color.blue()) def GetMenu(menu_name, create=False): persp=GostyApp.Instance().perspective diff --git a/modules/gui/pymod/scene/color_select_widget.py b/modules/gui/pymod/scene/color_select_widget.py index 160842a54d3b5c4e36f2abf020b30d7c9383a9d0..110108e6340c1078268169fa369e3f9c7364e152 100644 --- a/modules/gui/pymod/scene/color_select_widget.py +++ b/modules/gui/pymod/scene/color_select_widget.py @@ -61,7 +61,7 @@ class ColorSelectWidget(QtGui.QWidget): def GetGfxColor(self): color = self.GetColor() - return gfx.Color(color.redF(), color.greenF(), color.blueF()) + return gfx.RGB(color.redF(), color.greenF(), color.blueF()) def SetColor(self, color): if(self.color_ != color): diff --git a/modules/gui/pymod/scene/gradient_editor_widget.py b/modules/gui/pymod/scene/gradient_editor_widget.py index ee61e2721ab80a2f5c80692f91d8be861356fb81..d4b93071b3e6b0b4085dfb0672ee00baf235e09c 100644 --- a/modules/gui/pymod/scene/gradient_editor_widget.py +++ b/modules/gui/pymod/scene/gradient_editor_widget.py @@ -200,7 +200,7 @@ class GradientEdit(QtGui.QWidget): gradient = gfx.Gradient() for s in self.stops: c=s.GetColor(); - gradient.SetColorAt(s.GetRel(), gfx.Color(c.redF(), c.greenF(), c.blueF())); + gradient.SetColorAt(s.GetRel(), gfx.RGB(c.redF(), c.greenF(), c.blueF())); return gradient; def GetGradient(self): diff --git a/modules/gui/pymod/scene/immutable_gradient_info_handler.py b/modules/gui/pymod/scene/immutable_gradient_info_handler.py index 9998820b6e06506e23b40e5173f29b5b475d02ca..c70b041e9bfa3818a2c8df552f7cde9b241029dd 100644 --- a/modules/gui/pymod/scene/immutable_gradient_info_handler.py +++ b/modules/gui/pymod/scene/immutable_gradient_info_handler.py @@ -78,5 +78,5 @@ class ImmutableGradientInfoHandler: for s in gradient.stops(): rel=s[0] color=s[1] - gfx_gradient.SetColorAt(s[0], gfx.Color(s[1].redF(), s[1].greenF(), s[1].blueF())); + gfx_gradient.SetColorAt(s[0], gfx.RGB(s[1].redF(), s[1].greenF(), s[1].blueF())); return gfx_gradient; diff --git a/modules/gui/pymod/scene/immutable_info_handler.py b/modules/gui/pymod/scene/immutable_info_handler.py index b85a1103917bd64cfe1833ff78f8e80b09852bce..600fd393dbec78da4d28a3f2c8718dda9d1adf89 100644 --- a/modules/gui/pymod/scene/immutable_info_handler.py +++ b/modules/gui/pymod/scene/immutable_info_handler.py @@ -65,7 +65,7 @@ class ImmutableInfoHandler: for s in gradient.stops(): rel=s[0] color=s[1] - gfxgradient.SetColorAt(s[0], gfx.Color(s[1].redF(), s[1].greenF(), s[1].blueF())); + gfxgradient.SetColorAt(s[0], gfx.RGB(s[1].redF(), s[1].greenF(), s[1].blueF())); return gfxgradient; def GetQGradients(self): diff --git a/modules/gui/pymod/scene/preset_editor_widget.py b/modules/gui/pymod/scene/preset_editor_widget.py index d5348e918890ed0ef8666e500d7e3559e571f370..97d7e7723d07284033826560317ae7f17f6657c5 100644 --- a/modules/gui/pymod/scene/preset_editor_widget.py +++ b/modules/gui/pymod/scene/preset_editor_widget.py @@ -218,12 +218,12 @@ class UniformColorOpWidget(QtGui.QDialog): def GetOp(self): qv=mol.QueryViewWrapper(self.query_editor_.GetQuery(),self.query_editor_.GetQueryFlags()) - ufco = UniformColorOp(qv,gfx.Color(1,1,1,1)) + ufco = UniformColorOp(qv,gfx.RGBA(1,1,1,1)) detail = self.detail_selection_cb_.itemData(self.detail_selection_cb_.currentIndex()).toPyObject() ufco.SetMask(detail) qcolor = self.color_select_widget_.GetColor() - color=gfx.Color(qcolor.red()/255.0,qcolor.green()/255.0,qcolor.blue()/255.0,qcolor.alpha()/255.0) + color=gfx.RGBAb(qcolor.red(),qcolor.green(),qcolor.blue(),qcolor.alpha()) ufco.SetColor(color) return ufco