VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gxcolourmap.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file gxcolourmap.h
19 ///
20 
21 #ifndef GX_COLOURMAP_H
22 #define GX_COLOURMAP_H
23 
24 #include "gdef.h"
25 #include "gxdef.h"
26 #include "gxdrawable.h"
27 #include <vector>
28 
29 namespace GX
30 {
31  class ColourMap ;
32  class Display ;
33  class Window ;
34 }
35 
36 /// \class GX::ColourMap
37 /// A colourmap class that provides pixel values for a set of mapped colours.
38 /// The map can be for 16 colours or 256 greys. The first colour (0) is black,
39 /// and the last (15/255) is white.
40 ///
42 {
43 public:
44  explicit ColourMap( Display & , bool greyscale256 = false ) ;
45  ///< Constructor for a colourmap for the default visual
46  ///< providing 16 colours or 256 grey levels. The
47  ///< implementation creates a temporary window.
48 
49  ColourMap( Display & , GX::Window & w , ::Visual * v ) ;
50  ///< Constructor for a colourmap for a specific visual.
51  ///< The display reference is kept. The window is only
52  ///< used to determine the screen.
53 
54  ~ColourMap() ;
55  ///< Destructor.
56 
57  ::Colormap x() ;
58  ///< Returns the X colourmap id. See XCreateColormap(3).
59 
60  unsigned long get( int index ) const ;
61  ///< Gets the pixel value for the given index value.
62 
63  unsigned int size() const ;
64  ///< Returns 16 for colours or 256 for greyscale.
65 
66  int find( unsigned long ) const ;
67  ///< Does a reverse lookup to return the index value
68  ///< for the given pixel value.
69 
70 private:
71  ColourMap( const ColourMap & ) ;
72  void operator=( const ColourMap & ) ;
73  void create( Display & , ::Window , ::Visual * v , bool ) ;
74  void setGrey256() ;
75  void setColour16() ;
76  void addColour16(int,int,int) ;
77 
78 private:
79  Display & m_display ;
80  ::Colormap m_x ;
81  std::vector<unsigned long> m_map ;
82  unsigned int m_size ;
83 } ;
84 
85 inline
86 unsigned long GX::ColourMap::get( int index ) const
87 {
88  //index = index % m_size ;
89  return m_map[static_cast<size_t>(index)] ;
90 }
91 
92 #endif
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.
Definition: gxwindow.h:47
unsigned long get(int index) const
Gets the pixel value for the given index value.
Definition: gxcolourmap.h:86
An Xlib Display wrapper.
Definition: gxdisplay.h:38
A colourmap class that provides pixel values for a set of mapped colours.
Definition: gxcolourmap.h:41
~ColourMap()
Destructor.
Definition: gxcolourmap.cpp:97
An Xlib XVisual wrapper.
Definition: gxvisual.h:38
unsigned int size() const
Returns 16 for colours or 256 for greyscale.
Definition: gxcolourmap.cpp:56
ColourMap(Display &, bool greyscale256=false)
Constructor for a colourmap for the default visual providing 16 colours or 256 grey levels...
Definition: gxcolourmap.cpp:31
::Colormap x()
Returns the X colourmap id. See XCreateColormap(3).