From 6558c5c3150fe5482dd91475ba04353fac37a1b3 Mon Sep 17 00:00:00 2001 From: artemp Date: Thu, 3 Jan 2013 13:51:16 +0000 Subject: [PATCH] + use uint8_t in get/set methods + update to_string/to_hexstring --- include/mapnik/color.hpp | 24 ++++++++++++------------ src/color.cpp | 29 ++++++++++++++--------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/include/mapnik/color.hpp b/include/mapnik/color.hpp index ff84ecbfe..de35941cf 100644 --- a/include/mapnik/color.hpp +++ b/include/mapnik/color.hpp @@ -53,7 +53,7 @@ public: alpha_(0xff) {} - color(unsigned red, unsigned green, unsigned blue, unsigned alpha = 0xff) + color(boost::uint8_t red, boost::uint8_t green, boost::uint8_t blue, boost::uint8_t alpha = 0xff) : red_(red), green_(green), blue_(blue), @@ -76,14 +76,14 @@ public: color& operator=(color const& rhs) { - if (this==&rhs) + if (this==&rhs) return *this; - + red_ = rhs.red_; green_ = rhs.green_; blue_ = rhs.blue_; alpha_ = rhs.alpha_; - + return *this; } @@ -95,38 +95,38 @@ public: (alpha_ == rhs.alpha()); } - inline unsigned red() const + inline boost::uint8_t red() const { return red_; } - inline unsigned green() const + inline boost::uint8_t green() const { return green_; } - inline unsigned blue() const + inline boost::uint8_t blue() const { return blue_; } - inline unsigned alpha() const + inline boost::uint8_t alpha() const { return alpha_; } - inline void set_red(unsigned red) + inline void set_red(boost::uint8_t red) { red_ = red; } - inline void set_green(unsigned green) + inline void set_green(boost::uint8_t green) { green_ = green; } - inline void set_blue(unsigned blue) + inline void set_blue(boost::uint8_t blue) { blue_ = blue; } - inline void set_alpha(unsigned alpha) + inline void set_alpha(boost::uint8_t alpha) { alpha_ = alpha; } diff --git a/src/color.cpp b/src/color.cpp index d22b02d9e..ebc76948f 100644 --- a/src/color.cpp +++ b/src/color.cpp @@ -47,17 +47,17 @@ std::string color::to_string() const if (alpha_ == 255) { ss << "rgb(" - << red() << "," - << green() << "," - << blue() << ")"; + << static_cast(red()) << "," + << static_cast(green()) << "," + << static_cast(blue()) << ")"; } else { ss << "rgba(" - << red() << "," - << green() << "," - << blue() << "," - << alpha()/255.0 << ")"; + << static_cast(red()) << "," + << static_cast(green()) << "," + << static_cast(blue()) << "," + << alpha() / 255.0 << ")"; } return ss.str(); } @@ -67,17 +67,17 @@ std::string color::to_hex_string() const if (alpha_ == 255 ) { return (boost::format("#%1$02x%2$02x%3$02x") - % red() - % green() - % blue() ).str(); + % static_cast(red()) + % static_cast(green()) + % static_cast(blue())).str(); } else { return (boost::format("#%1$02x%2$02x%3$02x%4$02x") - % red() - % green() - % blue() - % alpha()).str(); + % static_cast(red()) + % static_cast(green()) + % static_cast(blue()) + % static_cast(alpha())).str(); } } @@ -101,4 +101,3 @@ void color::demultiply() } } -