1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
16 Color(unsigned int _screen = ~(0u));
17 Color(int _r, int _g, int _b, unsigned int _screen = ~(0u));
18 Color(const std::string &_name, unsigned int _screen = ~(0u));
21 inline const std::string &name(void) const { return colorname; }
23 inline int red(void) const { return r; }
24 inline int green(void) const { return g; }
25 inline int blue(void) const { return b; }
26 void setRGB(int _r, int _g, int _b) {
33 inline unsigned int screen(void) const { return scrn; }
34 void setScreen(unsigned int _screen = ~(0u));
36 inline bool isAllocated(void) const { return allocated; }
38 inline bool isValid(void) const { return r != -1 && g != -1 && b != -1; }
40 unsigned long pixel(void) const;
44 Color &operator=(const Color &c);
46 inline bool operator==(const Color &c) const
47 { return (r == c.r && b == c.b && b == c.b); }
48 inline bool operator!=(const Color &c) const
49 { return (! operator==(c)); }
51 static void cleanupColorCache(void);
54 void parseColorName(void);
56 void deallocate(void);
62 std::string colorname;
64 // global color allocator/deallocator
69 RGB(void) : screen(~(0u)), r(-1), g(-1), b(-1) { }
70 RGB(const int b, const int x, const int y, const int z)
71 : screen(b), r(x), g(y), b(z) {}
73 : screen(x.screen), r(x.r), g(x.g), b(x.b) {}
75 inline bool operator==(const RGB &x) const {
76 return screen == x.screen &&
77 r == x.r && g == x.g && b == x.b;
80 inline bool operator<(const RGB &x) const {
82 p1 = (screen << 24 | r << 16 | g << 8 | b) & 0x00ffffff;
83 p2 = (x.screen << 24 | x.r << 16 | x.g << 8 | x.b) & 0x00ffffff;
88 const unsigned long p;
90 inline PixelRef(void) : p(0), count(0) { }
91 inline PixelRef(const unsigned long x) : p(x), count(1) { }
93 typedef std::map<RGB,PixelRef> ColorCache;
94 typedef ColorCache::value_type ColorCacheItem;
95 static ColorCache colorcache;
96 static bool cleancache;
97 static void doCacheCleanup(void);