33 m_size(greyscale256?256U:16U)
35 m_map.reserve( m_size ) ;
37 Visual default_visual( display ) ;
38 create( display , window.
x() , default_visual.
x() , greyscale256 ) ;
44 create( display , window.
x() , visual , false ) ;
47 void GX::ColourMap::create(
Display & display , ::
Window window , ::
Visual * visual ,
bool greyscale256 )
49 m_x = XCreateColormap( display.
x() , window , visual , AllocNone ) ;
61 void GX::ColourMap::setGrey256()
64 for(
int i = 0 ; i < 256 ; i++ , n += 257 )
72 Status rc = XAllocColor( m_display.x() , m_x , &xcolour ) ;
73 if( rc == 0 )
throw Error(
"XAllocColor" ) ;
74 m_map.push_back(xcolour.pixel) ;
78 void GX::ColourMap::setColour16()
80 for(
unsigned i = 0U ; i < 16U ; i++ )
81 addColour16( Gr::colour16::r(i) , Gr::colour16::g(i) , Gr::colour16::b(i) ) ;
84 void GX::ColourMap::addColour16(
int r ,
int g ,
int b )
89 xcolour.red = 32761 * r ;
90 xcolour.green = 32761 * g ;
91 xcolour.blue = 32761 * b ;
92 Status rc = XAllocColor( m_display.x() , m_x , &xcolour ) ;
93 if( rc == 0 )
throw Error(
"XAllocColor" ) ;
94 m_map.push_back(xcolour.pixel) ;
101 XFreeColormap( m_display.x() , m_x ) ;
115 int n =
static_cast<int>(size()) ;
116 for(
int i = 0 ; i < n ; i++ )
121 std::ostringstream ss ;
122 ss << p <<
" not in" ;
123 for(
int i = 0U ; i < n ; i++ )
125 ss <<
" " <<
get(i) ;
127 throw Error(
"GX::ColourMap::find: invalid pixel value: " + ss.str() ) ;
int find(unsigned long) const
Does a reverse lookup to return the index value for the given pixel value.
A window class that is-a GX::Drawable and a GX::EventHandler.
::Display * x()
Returns the X object.
An exception class for GX classes.
::Window x()
Returns the X object.
unsigned int size() const
Returns 16 for colours or 256 for greyscale.
::Visual * x()
Returns the X object.
ColourMap(Display &, bool greyscale256=false)
Constructor for a colourmap for the default visual providing 16 colours or 256 grey levels...
::Colormap x()
Returns the X colourmap id. See XCreateColormap(3).