casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PSPixelCanvasColorTable.h
Go to the documentation of this file.
1 //# PSPixelCanvasColorTable.cc: PostScript version of PixelCanvasColorTable
2 //# Copyright (C) 1999,2000
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_PSPIXELCANVASCOLORTABLE_H
29 #define TRIALDISPLAY_PSPIXELCANVASCOLORTABLE_H
30 
31 
32 
33 
34 #include <casa/aips.h>
35 
36 #include <casa/Arrays/Vector.h>
40 
41 
42 namespace casa { //# NAMESPACE CASA - BEGIN
43 
44 // <summary>
45 // Implementation of PixelCanvasColorTable for PostScript device.
46 // </summary>
47 //
48 // <prerequisite>
49 // <li> <linkto class="PixelCanvasColorTable">PixelCanvasColorTable</linkto>
50 // <li> <linkto class="PSDriver">PSDriver</linkto>
51 // </prerequisite>
52 //
53 // <etymology>
54 // </etymology>
55 //
56 // <synopsis>
57 // To create a PSPixelCanvasColorTable, just pass the constructor a pointer
58 // to a
59 // <linkto class="PSDriver">PSDriver</linkto> and, optionally,
60 // supplying a color model. (The default is Index).
61 //<note role=tip> Unlike the <em>X11PixelCanvasColorTable</em>,
62 // PSPixelCanvasColorTable allows changing the color model on the fly.
63 //</note>
64 // PSPixelCanvasColorTable is not likely to be explicitly used by other
65 // than Display Library developers, particularly those creating
66 // "WorldCanvasApp"s. One exception is using PSPixelCanvasColorTable in non
67 // Index mode. Since
68 // <linkto class="PSWorldCanvasApp">PSWorldCanvasApp</linkto>
69 // creates its PSPixelCanvasColorTable in
70 // Index mode, it will be necessary to get a pointer to the object and
71 // explicitly change to different color modes.
72 //<example>
73 //<srcblock>
74 // psapp = new PSWorldCanvasApp(psdriver);
75 // wCanvas = psapp->worldCanvas();
76 // pCanvas = (PSPixelCanvas *)wCanvas->pixelCanvas();
77 // PSPixelCanvasColorTable *psctbl = pCanvas->PSpcctbl();
78 // psctbl->setColorModel(Display::RGB);
79 //</srcblock>
80 // See Display/test/dMultichannelRaster.cc for an example.
81 //</example>
82 // </synopsis>
83 //
84 //<note role=tip> PostScript supports a 4096 entry color table for
85 // indexed color. PSPixelCanvasColorTable logically breaks this into two
86 // parts. One part is used for the changable colors. The other part is
87 // reserved for read only colors. (Those allocated by name). The number
88 // of read only colors is 512.
89 //</note>
90 //
91 // <motivation>
92 // </motivation>
93 //
94 // <todo>
95 // </todo>
96 //<use visibility=local>
97 
99  public:
100 
101  //# PostScript Level 2 definition allows 12 bits/component, we
102  //# use 10 in RGB mode due to limitations in the DL spec.
103  enum { INDEXBPC = 12, RGBBPC=10, INDEXCOLORS = (1<<INDEXBPC),
105  };
106  // The last NUMROCOLORS of the table are reserved for RO values.
107 //# NUMROCOLORS could be changed as long as enough RO slots remained.
109  enum { BMASK = 0xff, RGBMASK= (RGBCOLORS-1) ,
111  };
112  // Amount to shift components when mapping RGB.
114  // <group>
117  // </group>
118  virtual ~PSPixelCanvasColorTable();
119 
120  // Resize the map if allowed. Returns true if resize was accepted
121  // <group>
122  virtual casacore::Bool resize(casacore::uInt newSize);
123  virtual casacore::Bool resize(casacore::uInt nReds, casacore::uInt nGreens, casacore::uInt nBlues);
124  // </group>
125 
126  // Install colors into the color table. Offset is zero-based. Colors
127  // are installed into the PixelCanvasColorTable until the Arrays run out
128  // or until the end of the colortable is reached. Can be called in any
129  // mode, but only affects graphics drawn in Index mode.
130  // Values are clamped to [0.0,1.0].
131 //<thrown><li> casacore::AipsError </thrown>
135  const casacore::Vector<casacore::Float> & alpha,
136  casacore::uInt offset = 0);
137 
138  // Return the number of RW colors in the colormap.
139  virtual casacore::uInt nColors() const;
140 
141  // Return the number of colors per component.
142  // For RGB/HSV, returns the number of colors/component supported by PostScript.
143  // For Index, returns the number of colors/component for the lookup table.
144  // (Limited by D.L. spec).
145  virtual void nColors(casacore::uInt &n1, casacore::uInt &n2, casacore::uInt &n3) const;
146 
147  // Maximum number of colors in color table.
148  casacore::uInt maxColors()const;
149  // Return the depth in bits of the colors.
150  virtual casacore::uInt depth() const;
151 
152  // Return the number of colors that are still unallocated.
153  virtual casacore::uInt nSpareColors() const;
154 
155  // map [0,N-1] into colorpixels, where N is the current colormap size
156  // The values are returned as unsigned integers in their respective
157  // array.
158  //
159  // <note role="Warning">casacore::uChar type doesn't have enough bits
160  // to hold the pixel index. </note>
161  // <note role="Warning">casacore::uChar and casacore::uShort don't have enough bits to
162  // hold RGB or HSV values.</note>
163  // <group>
164  virtual void mapToColor(const Colormap * map, casacore::Array<casacore::uChar> & outArray,
165  const casacore::Array<casacore::uChar> & inArray, casacore::Bool rangeCheck = true) const;
166  virtual void mapToColor(const Colormap * map, casacore::Array<casacore::uShort> & outArray,
167  const casacore::Array<casacore::uShort> & inArray, casacore::Bool rangeCheck = true) const;
168  virtual void mapToColor(const Colormap * map, casacore::Array<casacore::uInt> & outArray,
169  const casacore::Array<casacore::uInt> & inArray, casacore::Bool rangeCheck = true) const;
170  virtual void mapToColor(const Colormap * map, casacore::Array<casacore::uLong> & outArray,
171  const casacore::Array<casacore::uLong> & inArray, casacore::Bool rangeCheck = true) const;
172  // </group>
173 
174  // Same as above except the matrix is operated on in place. Only unsigned
175  // values make sense here.
176  // <group>
177  virtual void mapToColor(const Colormap * map, casacore::Array<casacore::uChar> & inOutArray,
178  casacore::Bool rangeCheck = true) const;
179  virtual void mapToColor(const Colormap * map, casacore::Array<casacore::uShort> & inOutArray,
180  casacore::Bool rangeCheck = true) const;
181  virtual void mapToColor(const Colormap * map, casacore::Array<casacore::uInt> & inOutArray,
182  casacore::Bool rangeCheck = true) const;
183  virtual void mapToColor(const Colormap * map, casacore::Array<casacore::uLong> & inOutArray,
184  casacore::Bool rangeCheck = true) const;
185  // </group>
186 
187  // (Multichannel Color)
188  // Merge separate channel data into an output image.
189  // This function maps floating values between 0 and 1
190  // into a output image suitable for PixelCanvas::drawImage().
191  // <group>
193  const casacore::Array<casacore::Float> & chan1in,
194  const casacore::Array<casacore::Float> & chan2in,
195  const casacore::Array<casacore::Float> & chan3in);
197  const casacore::Array<casacore::Double> & chan1in,
198  const casacore::Array<casacore::Double> & chan2in,
199  const casacore::Array<casacore::Double> & chan3in);
200  // </group>
201 
202  // This one maps values between 0 and the integer
203  // maximum value for each channel into a single
204  // output image suitable for PixelCanvas::drawImage().
205  // <group>
207  const casacore::Array<casacore::uShort> & chan1in,
208  const casacore::Array<casacore::uShort> & chan2in,
209  const casacore::Array<casacore::uShort> & chan3in);
211  const casacore::Array<casacore::uInt> & chan1in,
212  const casacore::Array<casacore::uInt> & chan2in,
213  const casacore::Array<casacore::uInt> & chan3in);
214  // </group>
215 
216  // Convert from a packed array of RGB triples to an array of color values.
217  // The output array needs to be 3 times as long as the input array.
218  // Used by PSPixelCanvas to convert from D.L. RGB format to an array
219  // the PostScript driver can use.
220  void mapFromColor3(const casacore::Array<casacore::uLong> & inArray,
221  casacore::Array<casacore::uShort> & outArray) const;
222 
223  // (Multichannel Color)
224  // Transform arrays from the passed color model into
225  // the colormodel of the PSPCCT.
226  // Does nothing if colorModel is Display::Index.
227  // It is assumed that input arrays are in the range of [0,1]
229  const casacore::Array<casacore::Float> & chan1in,
230  const casacore::Array<casacore::Float> & chan2in,
231  const casacore::Array<casacore::Float> & chan3in,
235 
236 
237  // Return the color model for multichannel color
239  // Returns the current # of color components (1 for Indexed, 3 for RGB/HSV).
241  // Changeable at any time.
242  virtual void setColorModel(const Display::ColorModel);
243 
245  return ps;
246  }
247 
248 //# ////////////////////////////////////////////////////////////////
249 // X11 emulation routines
250 //# ////////////////////////////////////////////////////////////////
251 //<srcblock>
252  // Convert a colorname to a color triple. Returns true for success,
253  // false if name can't be found. The color spec can also be in the form:
254  // "#xxxxxx" A '#' character followed by exactly 6 hex digits.
255  // (This form is considered obsolete and is not
256  // completely implemented here).
257  // "rgb:<red>/<green>/<blue>" Where <red>, <green> and <blue> are
258  // Each 1 to 4 hex digits. Each value is divided
259  // by 1.0/(2^n -1) where n is the # of hex chars in
260  // the term. The result is 3 floating point numbers in
261  // the range 0..1.
262  // "rgbi:<red>/<green>/<blue>" Where <red>, <green> and <blue> are
263  // floating point #s in the range 0..1.
264 //</srcblock>
265  // See <em>XParseColor</em> for more information.
266 
267 //<group>
268  static casacore::Bool parseColor(const char *name,
269  float &red, float &green, float &blue);
271  float &red, float &green, float &blue);
272 //</group>
273 
274  // Return contents of colormap at the given index. Returns false if
275  // the index is out of range. The valid range of index is 0..4095.
276  casacore::Bool queryColor(const int index, float &r, float &g, float &b);
277  // Sets the contents of colormap at the given index. Returns false if
278  // the index is out of range. The valid range of index is 0..nColors().
279  // ( Can't change read only values).
280  casacore::Bool storeColor(const int index,
281  const float r, const float g, const float b);
282  // Allocate the color value in the color table. index is set to the
283  // index allocated. Returns true for success, else false.
284  casacore::Bool allocColor(const float r, const float g, const float b, int &index);
285  casacore::Bool allocColor(const casacore::String &name, int &index);
286  casacore::Bool allocColor(const char *name, int &index);
287 
288  // Whether to put tracing comments in the output. This may be helpful
289  // when trying to decipher the PostScript file.
291  return annotate_;
292  }
293  void annotate(const casacore::Bool a) {
294  annotate_ = a;
295  }
296 
297  // print details of class to ostream
298  friend casacore::ostream & operator << (casacore::ostream & os,
299  const PSPixelCanvasColorTable & pcc);
300 
301  // Convert a packed pixel (from mapToColor3) to three color components.
302  static inline void pixelToComponents( const casacore::uLong pixel,
304  r = (pixel >> RSHIFT) & RGBMASK;
305  g = (pixel >> GSHIFT) & RGBMASK;
306  b = (pixel >> BSHIFT) & RGBMASK;
307  }
308  // Pack RGB or HSV color components into a single unsigned long.
309  static inline void componentsToPixel( const casacore::uShort r, const casacore::uShort g,
310  casacore::uShort &b, casacore::uLong &pixel) {
311  pixel = ((r & RGBMASK) << RSHIFT) | ((g & RGBMASK) << GSHIFT)
312  | ((b & RGBMASK) << BSHIFT);
313  }
314 
315  private:
317  void pspcinit(PSDriver *ps, const Display::ColorModel);
318  // Finds the index of a color triple coming 'close' to the RGB args.
319  // Returns: true if a match is found, else false.
320  // If lookROColor finds a match with a deallocated cell, it reallocates it.
321  casacore::Bool lookupROColor(const float r, const float g, const float b, int &index);
322  casacore::Bool lookupRWColor(const float r, const float g, const float b, int &index);
323  int allocColor_(const float r, const float g, const float b, int &index);
324 
325  // Mark a RO color as unallocated.
326  void deallocate(casacore::uLong index);
327 
328  // (Valid Always) number of total colors available. Changed by resize.
330  // Number of bits/per component. Determined by colorModel_.
332 
333  // (Valid Always)
334  // The colormodel that this PSPixelCanvasColorTable is currently
335  // configured as.
337 
338  // PS
340  // Copies of the color table.
344  // true if index has been allocated.
347  };
348 
349 
350 } //# NAMESPACE CASA - END
351 
352 #endif
virtual 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)
(Multichannel Color) Merge separate channel data into an output image.
virtual casacore::Bool installRGBColors(const casacore::Vector< casacore::Float > &r, const casacore::Vector< casacore::Float > &g, const casacore::Vector< casacore::Float > &b, const casacore::Vector< casacore::Float > &alpha, casacore::uInt offset=0)
Install colors into the color table.
Abstract interface to underlying graphics library&#39;s colortable.
casacore::Bool storeColor(const int index, const float r, const float g, const float b)
Sets the contents of colormap at the given index.
casacore::Bool queryColor(const int index, float &r, float &g, float &b)
Return contents of colormap at the given index.
virtual casacore::uInt nSpareColors() const
Return the number of colors that are still unallocated.
Display::ColorModel colorModel() const
Return the color model for multichannel color.
Low level interface between PSPixelCanvas{ColorTable} and PostScript.
Definition: PSDriver.h:109
casacore::uInt bpc_
Number of bits/per component.
casacore::Bool lookupROColor(const float r, const float g, const float b, int &index)
Finds the index of a color triple coming &#39;close&#39; to the RGB args.
casacore::Bool allocated_[NUMROCOLORS]
true if index has been allocated.
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
virtual void setColorModel(const Display::ColorModel)
Changeable at any time.
casacore::Bool annotate() const
Whether to put tracing comments in the output.
void pspcinit(PSDriver *ps, const Display::ColorModel)
virtual casacore::Bool resize(casacore::uInt newSize)
Resize the map if allowed.
void deallocate(casacore::uLong index)
Mark a RO color as unallocated.
virtual casacore::uInt depth() const
Return the depth in bits of the colors.
casacore::uInt maxColors() const
Maximum number of colors in color table.
static void componentsToPixel(const casacore::uShort r, const casacore::uShort g, casacore::uShort &b, casacore::uLong &pixel)
Pack RGB or HSV color components into a single unsigned long.
int allocColor_(const float r, const float g, const float b, int &index)
casacore::uInt nColors_
(Valid Always) number of total colors available.
void annotate(const casacore::Bool a)
float red_[INDEXCOLORS]
Copies of the color table.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Bool allocColor(const float r, const float g, const float b, int &index)
Allocate the color value in the color table.
casacore::Bool lookupRWColor(const float r, const float g, const float b, int &index)
unsigned long uLong
Definition: aipstype.h:53
friend casacore::ostream & operator<<(casacore::ostream &os, const PSPixelCanvasColorTable &pcc)
print details of class to ostream
Display::ColorModel colorModel_
(Valid Always) The colormodel that this PSPixelCanvasColorTable is currently configured as...
casacore::uInt numComponents() const
Returns the current # of color components (1 for Indexed, 3 for RGB/HSV).
Describes a method of generating a table of colors.
Definition: Colormap.h:104
static void pixelToComponents(const casacore::uLong pixel, casacore::uShort &r, casacore::uShort &g, casacore::uShort &b)
Convert a packed pixel (from mapToColor3) to three color components.
virtual 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 PSPCCT...
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual 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 mapFromColor3(const casacore::Array< casacore::uLong > &inArray, casacore::Array< casacore::uShort > &outArray) const
Convert from a packed array of RGB triples to an array of color values.
static casacore::Bool parseColor(const char *name, float &red, float &green, float &blue)
X11 emulation routines.
ColorIndex mode.
Definition: DisplayEnums.h:76
Implementation of PixelCanvasColorTable for PostScript device.
ColorModel
Different ways of handling color on the display.
Definition: DisplayEnums.h:74
unsigned int uInt
Definition: aipstype.h:51
virtual casacore::uInt nColors() const
Return the number of colors used to make the map.
unsigned short uShort
Definition: aipstype.h:49