1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
16 BColor(unsigned int _screen
= ~(0u));
17 BColor(int _r
, int _g
, int _b
, unsigned int _screen
= ~(0u));
18 BColor(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;
43 BColor
&operator=(const BColor
&c
);
44 inline bool operator==(const BColor
&c
) const
45 { return (r
== c
.r
&& b
== c
.b
&& b
== c
.b
); }
46 inline bool operator!=(const BColor
&c
) const
47 { return (! operator==(c
)); }
49 static void cleanupColorCache(void);
52 void parseColorName(void);
54 void deallocate(void);
60 std::string colorname
;
62 // global color allocator/deallocator
67 RGB(void) : screen(~(0u)), r(-1), g(-1), b(-1) { }
68 RGB(const int b
, const int x
, const int y
, const int z
)
69 : screen(b
), r(x
), g(y
), b(z
) {}
71 : screen(x
.screen
), r(x
.r
), g(x
.g
), b(x
.b
) {}
73 inline bool operator==(const RGB
&x
) const {
74 return screen
== x
.screen
&&
75 r
== x
.r
&& g
== x
.g
&& b
== x
.b
;
78 inline bool operator<(const RGB
&x
) const {
80 p1
= (screen
<< 24 | r
<< 16 | g
<< 8 | b
) & 0x00ffffff;
81 p2
= (x
.screen
<< 24 | x
.r
<< 16 | x
.g
<< 8 | x
.b
) & 0x00ffffff;
86 const unsigned long p
;
88 inline PixelRef(void) : p(0), count(0) { }
89 inline PixelRef(const unsigned long x
) : p(x
), count(1) { }
91 typedef std::map
<RGB
,PixelRef
> ColorCache
;
92 typedef ColorCache::value_type ColorCacheItem
;
93 static ColorCache colorcache
;
94 static bool cleancache
;
95 static void doCacheCleanup(void);