+ store individial colour components internally

This commit is contained in:
Artem Pavlenko 2009-07-08 11:52:13 +00:00
parent 6c846d77a6
commit 155e490c33

View file

@ -29,6 +29,8 @@
#include <mapnik/config.hpp>
//boost
#include <boost/format.hpp>
#include <boost/cstdint.hpp>
// stl
#include <sstream>
@ -37,80 +39,98 @@ namespace mapnik {
class MAPNIK_DECL color
{
private:
unsigned int abgr_;
boost::uint8_t red_;
boost::uint8_t green_;
boost::uint8_t blue_;
boost::uint8_t alpha_;
public:
color()
:abgr_(0xffffffff) {}
: red_(0xff),
green_(0xff),
blue_(0xff),
alpha_(0xff)
{}
color(int red,int green,int blue,int alpha=0xff)
: abgr_(((alpha&0xff) << 24) |
((blue&0xff) << 16) |
((green&0xff) << 8) |
(red&0xff)) {}
: red_(red),
green_(green),
blue_(blue),
alpha_(alpha)
{}
color( std::string const& css_string);
explicit color(int rgba)
: abgr_(rgba) {}
color(const color& rhs)
: abgr_(rhs.abgr_) {}
: red_(rhs.red_),
green_(rhs.green_),
blue_(rhs.blue_),
alpha_(rhs.alpha_)
{}
color& operator=(const color& rhs)
{
if (this==&rhs) return *this;
abgr_=rhs.abgr_;
red_=rhs.red_;
green_=rhs.green_;
blue_=rhs.blue_;
alpha_=rhs.alpha_;
return *this;
}
inline unsigned int red() const
inline unsigned red() const
{
return abgr_&0xff;
return red_;
}
inline unsigned int green() const
{
return (abgr_>>8)&0xff;
return green_;
}
inline unsigned int blue() const
{
return (abgr_>>16)&0xff;
return blue_;
}
inline unsigned int alpha() const
{
return (abgr_>>24)&0xff;
return alpha_;
}
inline void set_red(unsigned int r)
inline void set_red(unsigned red)
{
abgr_ = (abgr_ & 0xffffff00) | (r&0xff);
red_ = red;
}
inline void set_green(unsigned int g)
inline void set_green(unsigned green)
{
abgr_ = (abgr_ & 0xffff00ff) | ((g&0xff) << 8);
green_ = green;
}
inline void set_blue(unsigned int b)
inline void set_blue(unsigned blue)
{
abgr_ = (abgr_ & 0xff00ffff) | ((b&0xff) << 16);
blue_ = blue;
}
inline void set_alpha(unsigned int a)
inline void set_alpha(unsigned int alpha)
{
abgr_ = (abgr_ & 0x00ffffff) | ((a&0xff) << 24);
alpha_ = alpha;
}
inline unsigned int rgba() const
{
return abgr_;
}
inline void set_bgr(unsigned bgr)
{
abgr_ = (abgr_ & 0xff000000) | (bgr & 0xffffff);
#ifdef MAPNIK_BIG_ENDIAN
return (alpha_) | (blue_ << 8) | (green_ << 16) | (red_ << 24) ;
#else
return (alpha_ << 24) | (blue_ << 16) | (green_ << 8) | (red_) ;
#endif
}
inline bool operator==(color const& other) const
{
return abgr_ == other.abgr_;
return rgba() == other.rgba();
}
inline bool operator!=(color const& other) const
{
return abgr_ != other.abgr_;
return rgba() != other.rgba();
}
std::string to_string() const;