This patch:
* Adds set_alpha() * Reorders the get/set color functions to be red() green() blue() alpha() (code tidyness) * Changes the internal color variable to be named abgr_ instead of rgba_ since that is the order the colors are stored in it. Thanks to Dave Leaver.
This commit is contained in:
parent
2f360a6549
commit
2d04ce0360
1 changed files with 29 additions and 28 deletions
|
@ -34,70 +34,71 @@ namespace mapnik {
|
|||
class MAPNIK_DECL Color
|
||||
{
|
||||
private:
|
||||
unsigned int rgba_;
|
||||
unsigned int abgr_;
|
||||
public:
|
||||
Color()
|
||||
:rgba_(0xffffffff) {}
|
||||
:abgr_(0xffffffff) {}
|
||||
|
||||
Color(int red,int green,int blue,int alpha=0xff)
|
||||
: rgba_((alpha&0xff) << 24 | (blue&0xff) << 16 | (green&0xff) << 8 | red&0xff) {}
|
||||
: abgr_((alpha&0xff) << 24 | (blue&0xff) << 16 | (green&0xff) << 8 | red&0xff) {}
|
||||
|
||||
explicit Color(int rgba)
|
||||
: rgba_(rgba) {}
|
||||
: abgr_(rgba) {}
|
||||
|
||||
Color(const Color& rhs)
|
||||
: rgba_(rhs.rgba_) {}
|
||||
: abgr_(rhs.abgr_) {}
|
||||
|
||||
Color& operator=(const Color& rhs)
|
||||
{
|
||||
if (this==&rhs) return *this;
|
||||
rgba_=rhs.rgba_;
|
||||
abgr_=rhs.abgr_;
|
||||
return *this;
|
||||
}
|
||||
inline unsigned int blue() const
|
||||
{
|
||||
return (rgba_>>16)&0xff;
|
||||
}
|
||||
inline unsigned int green() const
|
||||
{
|
||||
return (rgba_>>8)&0xff;
|
||||
}
|
||||
inline unsigned int red() const
|
||||
{
|
||||
return rgba_&0xff;
|
||||
return abgr_&0xff;
|
||||
}
|
||||
inline unsigned int green() const
|
||||
{
|
||||
return (abgr_>>8)&0xff;
|
||||
}
|
||||
inline unsigned int blue() const
|
||||
{
|
||||
return (abgr_>>16)&0xff;
|
||||
}
|
||||
inline unsigned int alpha() const
|
||||
{
|
||||
return (abgr_>>24)&0xff;
|
||||
}
|
||||
|
||||
inline void set_red(unsigned int r)
|
||||
{
|
||||
rgba_ = (rgba_ & 0xffffff00) | (r&0xff);
|
||||
abgr_ = (abgr_ & 0xffffff00) | (r&0xff);
|
||||
}
|
||||
|
||||
inline void set_green(unsigned int g)
|
||||
{
|
||||
rgba_ = (rgba_ & 0xffff00ff) | ((g&0xff) << 8);
|
||||
abgr_ = (abgr_ & 0xffff00ff) | ((g&0xff) << 8);
|
||||
}
|
||||
|
||||
inline void set_blue(unsigned int b)
|
||||
{
|
||||
rgba_ = (rgba_ & 0xff00ffff) | ((b&0xff) << 16);
|
||||
abgr_ = (abgr_ & 0xff00ffff) | ((b&0xff) << 16);
|
||||
}
|
||||
inline void set_alpha(unsigned int a)
|
||||
{
|
||||
abgr_ = (abgr_ & 0x00ffffff | (a&0xff) << 24);
|
||||
}
|
||||
|
||||
inline unsigned int alpha() const
|
||||
{
|
||||
return (rgba_>>24)&0xff;
|
||||
}
|
||||
|
||||
inline unsigned int rgba() const
|
||||
{
|
||||
return rgba_;
|
||||
return abgr_;
|
||||
}
|
||||
inline void set_bgr(unsigned bgr)
|
||||
{
|
||||
rgba_ = (rgba_ & 0xff000000) | (bgr & 0xffffff);
|
||||
abgr_ = (abgr_ & 0xff000000) | (bgr & 0xffffff);
|
||||
}
|
||||
inline bool operator==(Color const& other) const
|
||||
{
|
||||
return rgba_ == other.rgba_;
|
||||
return abgr_ == other.abgr_;
|
||||
}
|
||||
|
||||
inline std::string to_string() const
|
||||
|
|
Loading…
Reference in a new issue