casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GLPixelCanvasColorTable.h
Go to the documentation of this file.
1 //# GLPixelCanvasColorTable.h: color table provision for X11 devices
2 //# Copyright (C) 2001
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef TRIALDISPLAY_GLPIXELCANVASCOLORTABLE_H
29 #define TRIALDISPLAY_GLPIXELCANVASCOLORTABLE_H
30 
31 #include <casa/aips.h>
32 #include <graphics/X11/X11Util.h>
33 
34 #include <graphics/X11/X_enter.h>
35 #include <X11/Xlib.h>
36 #include <X11/Xutil.h>
37 #include <graphics/X11/X_exit.h>
38 
39 #include <casa/Arrays/Vector.h>
42 
43 
44 namespace casa { //# NAMESPACE CASA - BEGIN
45 
46 // <summary>
47 // Implementation of PixelCanvasColorTable for OpenGL.
48 // </summary>
49 // <synopsis>
50 // GLPixelCanvasColorTable is an X11PixelCanvasColorTable that has been
51 // modified to work within the constraints of the GLPixelCanvas. (e.g. Not
52 // assuming the default visual).
53 //
54 // Colormap values are written to a virtual colortable (an internal array).
55 // For Indexed (PseudoColor) windows, the values are sent to the hardware
56 // colormap. For RGB (trueColor) windows, the virtual colortable is used
57 // to emulate a hardware lookup table.
58 // </synopsis>
59 //
60 // <prerequisite>
61 // <li> <linkto class="PixelCanvasColorTable">PixelCanvasColorTable</linkto>
62 // <li> How to get the X Screen pointer.
63 // </prerequisite>
64 //
65 // <etymology>
66 // </etymology>
67 //
68 // <thrown>
69 // AipsError
70 // </thrown>
71 // <use visibility=export>
72 
73 // Colormap entry for the virtual colormap.
75  public:
77 
78  void operator=(const GLVColorTableEntry &);
79 
80  // Store/get the values.
81  void put(const float red, const float green, const float blue) {
82  red_ = red;
83  green_ = green;
84  blue_ = blue;
85  }
86 
87  void get(float &red, float &green, float &blue)const {
88  red = red_;
89  green = green_;
90  blue = blue_;
91  }
92 
94  return index_;
95  }
96  void setIndex(const casacore::uInt i) {
97  index_ = i;
98  }
99 
101  return pixel_;
102  }
103  void setPixel(const unsigned long p) {
104  pixel_ = p;
105  }
106 
107  friend ostream &operator<<(ostream &s, const GLVColorTableEntry &x);
108 
109  private:
110  casacore::uInt index_; // Index into map for this entry.
111  casacore::uLong pixel_; // Real index or color value.
112  float red_, green_, blue_; // Color component values. (0..1).
113  };
114 
116  public:
117 
118  // <group>
120 
122 
123  GLPixelCanvasColorTable(::XDisplay *dpy,
125  casacore::Float percent=90.0,
126  XVisualInfo *visInfo=NULL);
127  // </group>
128 
129  // allocate cells for colormaps
131 
132  // deallocate cells for colormaps
134 
135  // Allocate the best color cube given the map
137  // Allocate a color cube of a specific size
139  // Allocate a color cube within the ranges of sizes
141  casacore::uInt n1max, casacore::uInt n2max, casacore::uInt n3max);
142  // Copy color cube info from the mapRef
143  void copyColorCube(const GLPixelCanvasColorTable & mapRef);
144  // Fill a color cube with an RGB spectrum
145  void fillColorCubeRGB();
147  static void colorFillRGB(
150  FILLMODE mode = FILLRGB);
151 
152  static void colorFillRGB(
154  casacore::uInt ncolors, FILLMODE mode= FILLRGB);
155  // Fill a color cube with an HSV spectrum
156  void fillColorCubeHSV();
157 
158  // Merge separate channel data into an output image.
159  // This function maps floating values between 0 and 1
160  // into a output image suitable for PixelCanvas::drawImage().
161  // <group>
163  const casacore::Array<casacore::Float> & chan1in,
164  const casacore::Array<casacore::Float> & chan2in,
165  const casacore::Array<casacore::Float> & chan3in);
167  const casacore::Array<casacore::Double> & chan1in,
168  const casacore::Array<casacore::Double> & chan2in,
169  const casacore::Array<casacore::Double> & chan3in);
170  // </group>
171 
172  // This one maps values between 0 and the integer
173  // maximum value for each channel into a single
174  // output image suitable for PixelCanvas::drawImage().
175  // <group>
177  const casacore::Array<casacore::uShort> & chan1in,
178  const casacore::Array<casacore::uShort> & chan2in,
179  const casacore::Array<casacore::uShort> & chan3in);
181  const casacore::Array<casacore::uInt> & chan1in,
182  const casacore::Array<casacore::uInt> & chan2in,
183  const casacore::Array<casacore::uInt> & chan3in);
184  // </group>
185 
186  // (Multichannel Color)
187  // Transform arrays from the passed color model into
188  // the colormodel of the XPCCT.
189  // Does nothing if colorModel is Display::Index.
190  // It is assumed that input arrays are in the range of [0,1]
192  const casacore::Array<casacore::Float> & chan1in,
193  const casacore::Array<casacore::Float> & chan2in,
194  const casacore::Array<casacore::Float> & chan3in,
198 
199  // map [0,N-1] into colorpixels, where N is the current colormap size
200  // The values are returned as unsigned integers in their respective
201  // array.
202  // <note role="warning">casacore::uChar type may not have enough bits
203  // to hold the pixel index on some high-end graphics systems </note>
204  // <note role="warning">casacore::uShort type may not have enough bits
205  // to hold the pixel index on some high-end graphics systems </note>
206  // <group>
207  void mapToColor(const Colormap * map, casacore::Array<casacore::uChar> & outArray,
208  const casacore::Array<casacore::uChar> & inArray, casacore::Bool rangeCheck = true) const;
209  void mapToColor(const Colormap * map, casacore::Array<casacore::uShort> & outArray,
210  const casacore::Array<casacore::uShort> & inArray, casacore::Bool rangeCheck = true) const;
211  void mapToColor(const Colormap * map, casacore::Array<casacore::uInt> & outArray,
212  const casacore::Array<casacore::uInt> & inArray, casacore::Bool rangeCheck = true) const;
213  void mapToColor(const Colormap * map, casacore::Array<casacore::uLong> & outArray,
214  const casacore::Array<casacore::uLong> & inArray, casacore::Bool rangeCheck = true) const;
215  // </group>
216 
217  // same as above except the matrix is operated on in place. Only unsigned
218  // values make sense here.
219  // <group>
220  void mapToColor(const Colormap * map, casacore::Array<casacore::uChar> & inOutArray,
221  casacore::Bool rangeCheck = true) const;
222  void mapToColor(const Colormap * map, casacore::Array<casacore::uShort> & inOutArray,
223  casacore::Bool rangeCheck = true) const;
224  void mapToColor(const Colormap * map, casacore::Array<casacore::uInt> & inOutArray,
225  casacore::Bool rangeCheck = true) const;
226  void mapToColor(const Colormap * map, casacore::Array<casacore::uLong> & inOutArray,
227  casacore::Bool rangeCheck = true) const;
228  // </group>
229 
230  // print details of class to ostream
231  friend ostream & operator << (ostream & os, const GLPixelCanvasColorTable & pcc);
232 
233  // Is the hardware colormap resizeable? ie. is it write-only?
235  return (readOnly_ && decomposedIndex_);
236  }
237 
238  // resize the map if allowed. Returns true if resize was accepted
239  // <group>
242  // </group>
243 
244  // Install colors into the color table. Offset is zero-based. Colors
245  // are installed into the PixelCanvasColorTable until the Arrays run out
246  // or until the end of the colortable is reached. This only has an
247  // effect if the ColorModel is Index. Values are clamped to [0.0,1.0].
249  const casacore::Vector<casacore::Float> & b, casacore::uInt offset = 0);
250 
251  // Return the total number of RW colors currently in use.
252  casacore::uInt nColors() const;
253 
254  // Return the number of colors per component in the map. Throws
255  // an exception if this is not an HSV or RGB ColorTable.
256  virtual void nColors(casacore::uInt &n1, casacore::uInt &n2, casacore::uInt &n3) const;
257 
258  // Return the depth in bits of the colors
259  casacore::uInt depth() const;
260 
261  // Return the number of colors that are still unallocated
263 
264  // Return pointer to display that is being used
265  ::XDisplay * display() const;
266  // Return pointer to screen that is being used
267  Screen * screen() const;
268  // Return pointer to visual that is being used
269  Visual * visual() const;
270  // Return pointer to visual info that is being used
271  XVisualInfo *visualInfo() const {
272  return visualInfo_;
273  }
274  // Return XID of X "virtual colormap" being used
275  XColormap xcmap() const;
276 
277  // Return true if the table is in colorIndex mode
279  return (colorModel_ == Display::Index);
280  }
281  // Return true if the table is in RGB mode
283  return (colorModel_ == Display::RGB);
284  }
285  // Return true if the table is in HSV mode
287  return (colorModel_ == Display::HSV);
288  }
289 
290  // Return true if the colortable can be resized.
292  return rigid_;
293  }
294 
295  // Return the color model for multichannel color
297  return colorModel_;
298  }
300  return readOnly_;
301  }
303  return decomposedIndex_;
304  }
305  // Return the number of currently unallocated cells that can be allocated RW.
307  virtual casacore::uInt QueryHWColorsAvailable(const casacore::Bool contig)const;
308  // Convert a virtual index to a physical pixel.
309  casacore::Bool virtualToPhysical(const unsigned long vindex,
310  unsigned long &pindex)const;
311  // Store an RGB value at index. For RGV visuals, only the virtual colormap
312  // is updated.
313  void storeColor(const casacore::uInt index,
314  const float r, const float g, const float b);
315  // Convert a pixel to color components. If decomposed index (eg TC),
316  // the pixel contains the color information. Otherwise, (eg. PseudoColor),
317  // The information is looked up in the virtual colormap.
319  // Return a GL capable visual that supports the colormodel or NULL.
320  static XVisualInfo *getVisualInfo(::XDisplay *dpy,
321  const Display::ColorModel colormodel);
322  // Returns the color values for the index. (Inverse of installRGBColors()).
323  void indexToRGB(const casacore::uInt index, float &r, float &g, float &b);
324  private:
325 
326  // Return the log power 2 of n and return true if n is
327  // a power of two. Otherwise return false.
329 
330  // (Multi-Channel)
333  // (Multi-Channel)
334  void setupStandardMapping(const XStandardColormap * mapInfo);
335 
336  casacore::Bool initVisual(XVisualInfo *vi=NULL);
337  // A pointer to the XDisplay
338  ::XDisplay * display_;
339  // A pointer the the X Screen
340  Screen * screen_;
341  // A pointer to the X Visual
342  Visual * visual_;
343  XVisualInfo *visualInfo_;
344  // A pointer to the XColormap (X Hardware colormap)
345  XColormap xcmap_;
346 
347  // (Valid Always) number of bits of depth
349  // (Valid Always) number of total colors available for RW.
351  // (Valid only when implementation uses a PseudoColor or a
352  // StaticColor visual). casacore::Table of color indices available.
353  casacore::uLong * colors_; // converts pixel index into vcmap index. Always valid.
354  casacore::uShort vcmapLength_; // Length of virtual colormap.
355  // (& HW map if it exists)
357  // (Valid Always)
358  // true if the table may not be resized, such as when a
359  // standard XColormap is used. Generally this is set to true
360  // unless the visual is PseudoColor/StaticColor and the color
361  // model is Display::Index.
364  // true if the colormap is read only.
366  // true if trueColor or DirectColor.
368  void checkVisual();
369  // Write an RGB value to hardware colormap at physical index.
370  // (Called by storeColor()).
371  virtual void storeHWColor(const casacore::uLong pindex,
372  const float r, const float g, const float b);
373  // Shift counts, masks, and max values used to build pixels for
374  // decomposed index colormaps.
376  unsigned short red_max_, green_max_, blue_max_;
378  // Convert from integer HSV components to RGB pixel components.
379  void HSV2RGB(const casacore::uLong H, const casacore::uLong S, const casacore::uLong V,
381  casacore::uInt HSV2Index(float h, float s, float v);
382 
384  // (Valid only for multi-channel color modes (RGB, HSV, etc))
385  // If true, then the color cube's sides are powers of two,
386  // making indexing possible with shift/add using the values of
387  // <nBits1_, nBits2_, nBits3_>. If not true, indexing
388  // using <n1_,n2_,n3_> and multiplication is required.
389  casacore::Bool pow2Mapping_;
390 
391  // (Valid Always)
392  // The colormodel that this GLPixelCanvasColorTable has been
393  // configured as.
395 
396  // (Valid only for multi-channel color modes (RGB, HSV, etc))
397  // Represents the first cell used for the color cube.
398  // baseColor_ is zero for PseudoColor/StaticColor implementations
399  // because they use a table.
401 
402  // (Valid only for multi-channel color modes (RGB, HSV, etc))
403  // Specifies the color resolution for each side of the
404  // color cube.
405  // index = n1Mult_*R + n2Mult_*G + n3Mult_*B for RGB in
406  // the range of <[0,n1_-1],[0,n2_-1],[0,n3_-1]>
407  // <group>
411 
415  // </group>
416 
417  // (Valid only for multi-channel color modes (RGB, HSV, etc))
418  // and when pow2Mapping is true.
419  // index = (R << n1Shift_) | (G << n2Shift_) | (B << n3Shift_)
420  // for RGB the range of <[0,n1_-1],[0,n2_-1],[0,n3_-1]>
421  // <group>
425  // </group>
426  };
427 
428 
429 } //# NAMESPACE CASA - END
430 #ifndef AIPS_NO_TEMPLATE_SRC
431 #include <display/Display/GLPCColTblTemplates.tcc>
432 #endif
433 #endif
casacore::Bool decomposedIndex() const
casacore::uInt depth_
(Valid Always) number of bits of depth
::XDisplay * display_
A pointer to the XDisplay.
GLVColorTableEntry * vcmap_
(&amp; HW map if it exists)
Abstract interface to underlying graphics library&#39;s colortable.
casacore::Bool virtualToPhysical(const unsigned long vindex, unsigned long &pindex) const
Convert a virtual index to a physical pixel.
casacore::uInt HSV2Index(float h, float s, float v)
casacore::Bool allocColorCubeMinMax(casacore::uInt n1min, casacore::uInt n2min, casacore::uInt n3min, casacore::uInt n1max, casacore::uInt n2max, casacore::uInt n3max)
Allocate a color cube within the ranges of sizes.
void mapToColor3(casacore::Array< casacore::uLong > &out, const casacore::Array< casacore::Float > &chan1in, const casacore::Array< casacore::Float > &chan2in, const casacore::Array< casacore::Float > &chan3in)
Merge separate channel data into an output image.
void storeColor(const casacore::uInt index, const float r, const float g, const float b)
Store an RGB value at index.
casacore::uLong * colors_
(Valid only when implementation uses a PseudoColor or a StaticColor visual).
void setPixel(const unsigned long p)
casacore::uInt QueryColorsAvailable(const casacore::Bool contig) const
Return the number of currently unallocated cells that can be allocated RW.
casacore::Bool installRGBColors(const casacore::Vector< casacore::Float > &r, const casacore::Vector< casacore::Float > &g, const casacore::Vector< casacore::Float > &b, casacore::uInt offset=0)
Install colors into the color table.
Display::ColorModel colorModel_
(Valid Always) The colormodel that this GLPixelCanvasColorTable has been configured as...
void operator=(const GLVColorTableEntry &)
XColormap xcmap() const
Return XID of X &quot;virtual colormap&quot; being used.
void setIndex(const casacore::uInt i)
casacore::Bool indexMode() const
Return true if the table is in colorIndex mode.
casacore::Bool decomposedIndex_
true if trueColor or DirectColor.
casacore::uInt nColors() const
Return the total number of RW colors currently in use.
Visual * visual() const
Return pointer to visual that is being used.
casacore::Bool hsvMode() const
Return true if the table is in HSV mode.
casacore::Bool rigid_
(Valid Always) true if the table may not be resized, such as when a standard XColormap is used...
Visual * visual_
A pointer to the X Visual.
virtual casacore::Bool staticSize()
Is the hardware colormap resizeable? ie.
casacore::Bool isPow2(casacore::uInt n, casacore::uInt &log2n)
Return the log power 2 of n and return true if n is a power of two.
casacore::uInt nColors_
(Valid Always) number of total colors available for RW.
::XDisplay * display() const
Return pointer to display that is being used.
casacore::uInt nSpareColors() const
Return the number of colors that are still unallocated.
void copyColorCube(const GLPixelCanvasColorTable &mapRef)
Copy color cube info from the mapRef.
static XVisualInfo * getVisualInfo(::XDisplay *dpy, const Display::ColorModel colormodel)
Return a GL capable visual that supports the colormodel or NULL.
static void colorFillRGB(casacore::Vector< casacore::Float > &r, casacore::Vector< casacore::Float > &g, casacore::Vector< casacore::Float > &b, casacore::uInt nr, casacore::uInt ng, casacore::uInt nb, FILLMODE mode=FILLRGB)
friend ostream & operator<<(ostream &os, const GLPixelCanvasColorTable &pcc)
print details of class to ostream
casacore::uInt depth() const
Return the depth in bits of the colors.
casacore::Bool allocCells(casacore::uInt nCells)
allocate cells for colormaps
Screen * screen() const
Return pointer to screen that is being used.
casacore::Bool resize(casacore::uInt newSize)
resize the map if allowed.
void mapToColor(const Colormap *map, casacore::Array< casacore::uChar > &outArray, const casacore::Array< casacore::uChar > &inArray, casacore::Bool rangeCheck=true) const
map [0,N-1] into colorpixels, where N is the current colormap size The values are returned as unsigne...
void pixelToComponents(const casacore::uLong pixel, casacore::Float &r, casacore::Float &g, casacore::Float &b)
Convert a pixel to color components.
void fillColorCubeRGB()
Fill a color cube with an RGB spectrum.
casacore::Bool allocColorCube()
Allocate the best color cube given the map.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
float Float
Definition: aipstype.h:54
unsigned short red_shift_
Shift counts, masks, and max values used to build pixels for decomposed index colormaps.
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
casacore::uInt n1_
(Valid only for multi-channel color modes (RGB, HSV, etc)) Specifies the color resolution for each si...
unsigned long uLong
Definition: aipstype.h:53
Display::ColorModel colorModel() const
Return the color model for multichannel color.
Screen * screen_
A pointer the the X Screen.
casacore::uLong baseColor_
(Valid only for multi-channel color modes (RGB, HSV, etc)) Represents the first cell used for the col...
virtual void storeHWColor(const casacore::uLong pindex, const float r, const float g, const float b)
Write an RGB value to hardware colormap at physical index.
casacore::Bool initVisual(XVisualInfo *vi=NULL)
casacore::Bool deallocCells()
deallocate cells for colormaps
void setupStandardMapping(const XStandardColormap *mapInfo)
(Multi-Channel)
casacore::uInt getIndex() const
Describes a method of generating a table of colors.
Definition: Colormap.h:104
void indexToRGB(const casacore::uInt index, float &r, float &g, float &b)
Returns the color values for the index.
casacore::Bool rgbMode() const
Return true if the table is in RGB mode.
casacore::Bool colorSpaceMap(Display::ColorModel, const casacore::Array< casacore::Float > &chan1in, const casacore::Array< casacore::Float > &chan2in, const casacore::Array< casacore::Float > &chan3in, casacore::Array< casacore::Float > &chan1out, casacore::Array< casacore::Float > &chan2out, casacore::Array< casacore::Float > &chan3out)
(Multichannel Color) Transform arrays from the passed color model into the colormodel of the XPCCT...
Implementation of PixelCanvasColorTable for OpenGL.
void fillColorCubeHSV()
Fill a color cube with an HSV spectrum.
casacore::uLong getPixel() const
ColorIndex mode.
Definition: DisplayEnums.h:76
void put(const float red, const float green, const float blue)
Store/get the values.
casacore::Bool rigid() const
Return true if the colortable can be resized.
XVisualInfo * visualInfo() const
Return pointer to visual info that is being used.
true if the colormap is read only *casacore::Bool readOnly_
XColormap xcmap_
A pointer to the XColormap (X Hardware colormap)
void setupColorCube(casacore::uLong n1, casacore::uLong n2, casacore::uLong n3, casacore::uLong n1m, casacore::uLong n2m, casacore::uLong n3m)
(Multi-Channel)
void HSV2RGB(const casacore::uLong H, const casacore::uLong S, const casacore::uLong V, casacore::uLong &R, casacore::uLong &G, casacore::uLong &B)
Convert from integer HSV components to RGB pixel components.
friend ostream & operator<<(ostream &s, const GLVColorTableEntry &x)
casacore::uInt n1Shift_
(Valid only for multi-channel color modes (RGB, HSV, etc)) and when pow2Mapping is true...
ColorModel
Different ways of handling color on the display.
Definition: DisplayEnums.h:74
unsigned int uInt
Definition: aipstype.h:51
virtual casacore::uInt QueryHWColorsAvailable(const casacore::Bool contig) const
unsigned short uShort
Definition: aipstype.h:49