casa
$Rev:20696$
|
Implementation of PixelCanvasColorTable for PostScript device. More...
#include <PSPixelCanvasColorTable.h>
Public Types | |
enum | { INDEXBPC, RGBBPC, INDEXCOLORS, RGBCOLORS } |
enum | { NUMROCOLORS, NUMRWCOLORS } |
The last NUMROCOLORS of the table are reserved for RO values. More... | |
enum | { BMASK, RGBMASK, INDEXMASK } |
enum | { RSHIFT, GSHIFT, BSHIFT } |
Amount to shift components when mapping RGB. More... | |
Public Member Functions | |
PSPixelCanvasColorTable (PSDriver *ps, const Display::ColorModel=Display::Index) | |
virtual | ~PSPixelCanvasColorTable () |
virtual Bool | resize (uInt newSize) |
Resize the map if allowed. | |
virtual Bool | resize (uInt nReds, uInt nGreens, uInt nBlues) |
virtual Bool | installRGBColors (const Vector< Float > &r, const Vector< Float > &g, const Vector< Float > &b, uInt offset=0) |
Install colors into the color table. | |
virtual uInt | nColors () const |
Return the number of colors used to make the map. | |
virtual void | nColors (uInt &n1, uInt &n2, uInt &n3) const |
Return the number of colors per component. | |
uInt | maxColors () const |
Maximum number of colors in color table. | |
virtual uInt | depth () const |
Return the depth in bits of the colors. | |
virtual uInt | nSpareColors () const |
Return the number of colors that are still unallocated. | |
virtual void | mapToColor (const Colormap *map, Array< uChar > &outArray, const Array< uChar > &inArray, Bool rangeCheck=True) const |
map [0,N-1] into colorpixels, where N is the current colormap size The values are returned as unsigned integers in their respective array. | |
virtual void | mapToColor (const Colormap *map, Array< uShort > &outArray, const Array< uShort > &inArray, Bool rangeCheck=True) const |
virtual void | mapToColor (const Colormap *map, Array< uInt > &outArray, const Array< uInt > &inArray, Bool rangeCheck=True) const |
virtual void | mapToColor (const Colormap *map, Array< uLong > &outArray, const Array< uLong > &inArray, Bool rangeCheck=True) const |
virtual void | mapToColor (const Colormap *map, Array< uChar > &inOutArray, Bool rangeCheck=True) const |
Same as above except the matrix is operated on in place. | |
virtual void | mapToColor (const Colormap *map, Array< uShort > &inOutArray, Bool rangeCheck=True) const |
virtual void | mapToColor (const Colormap *map, Array< uInt > &inOutArray, Bool rangeCheck=True) const |
virtual void | mapToColor (const Colormap *map, Array< uLong > &inOutArray, Bool rangeCheck=True) const |
virtual void | mapToColor3 (Array< uLong > &out, const Array< Float > &chan1in, const Array< Float > &chan2in, const Array< Float > &chan3in) |
(Multichannel Color) Merge separate channel data into an output image. | |
virtual void | mapToColor3 (Array< uLong > &out, const Array< Double > &chan1in, const Array< Double > &chan2in, const Array< Double > &chan3in) |
virtual void | mapToColor3 (Array< uLong > &out, const Array< uShort > &chan1in, const Array< uShort > &chan2in, const Array< uShort > &chan3in) |
This one maps values between 0 and the integer maximum value for each channel into a single output image suitable for PixelCanvas::drawImage(). | |
virtual void | mapToColor3 (Array< uLong > &out, const Array< uInt > &chan1in, const Array< uInt > &chan2in, const Array< uInt > &chan3in) |
void | mapFromColor3 (const Array< uLong > &inArray, Array< uShort > &outArray) const |
Convert from a packed array of RGB triples to an array of color values. | |
virtual Bool | colorSpaceMap (Display::ColorModel, const Array< Float > &chan1in, const Array< Float > &chan2in, const Array< Float > &chan3in, Array< Float > &chan1out, Array< Float > &chan2out, Array< Float > &chan3out) |
(Multichannel Color) Transform arrays from the passed color model into the colormodel of the PSPCCT. | |
Display::ColorModel | colorModel () const |
Return the color model for multichannel color. | |
uInt | numComponents () const |
Returns the current # of color components (1 for Indexed, 3 for RGB/HSV). | |
virtual void | setColorModel (const Display::ColorModel) |
Changeable at any time. | |
PSDriver * | getPSDriver () const |
Bool | queryColor (const int index, float &r, float &g, float &b) |
Return contents of colormap at the given index. | |
Bool | storeColor (const int index, const float r, const float g, const float b) |
Sets the contents of colormap at the given index. | |
Bool | allocColor (const float r, const float g, const float b, int &index) |
Allocate the color value in the color table. | |
Bool | allocColor (const String &name, int &index) |
Bool | allocColor (const char *name, int &index) |
Bool | annotate () const |
Whether to put tracing comments in the output. | |
void | annotate (const Bool a) |
Static Public Member Functions | |
static Bool | parseColor (const char *name, float &red, float &green, float &blue) |
X11 emulation routines. | |
static Bool | parseColor (const String &name, float &red, float &green, float &blue) |
static void | pixelToComponents (const uLong pixel, uShort &r, uShort &g, uShort &b) |
Convert a packed pixel (from mapToColor3) to three color components. | |
static void | componentsToPixel (const uShort r, const uShort g, uShort &b, uLong &pixel) |
Pack RGB or HSV color components into a single unsigned long. | |
Private Member Functions | |
PSPixelCanvasColorTable () | |
void | pspcinit (PSDriver *ps, const Display::ColorModel) |
Bool | lookupROColor (const float r, const float g, const float b, int &index) |
Finds the index of a color triple coming 'close' to the RGB args. | |
Bool | lookupRWColor (const float r, const float g, const float b, int &index) |
int | allocColor_ (const float r, const float g, const float b, int &index) |
void | deallocate (uLong index) |
Mark a RO color as unallocated. | |
Private Attributes | |
uInt | nColors_ |
(Valid Always) number of total colors available. | |
uInt | bpc_ |
Number of bits/per component. | |
Display::ColorModel | colorModel_ |
(Valid Always) The colormodel that this PSPixelCanvasColorTable is currently configured as. | |
PSDriver * | ps |
PS. | |
float | red_ [INDEXCOLORS] |
Copies of the color table. | |
float | blue_ [INDEXCOLORS] |
float | green_ [INDEXCOLORS] |
Bool | allocated_ [NUMROCOLORS] |
True if index has been allocated. | |
Bool | annotate_ |
Friends | |
ostream & | operator<< (ostream &os, const PSPixelCanvasColorTable &pcc) |
print details of class to ostream |
Implementation of PixelCanvasColorTable for PostScript device.
To create a PSPixelCanvasColorTable, just pass the constructor a pointer to a PSDriver and, optionally, supplying a color model. (The default is Index).
Tip: Unlike the X11PixelCanvasColorTable, PSPixelCanvasColorTable allows changing the color model on the fly;
PSPixelCanvasColorTable is not likely to be explicitly used by other than Display Library developers, particularly those creating "WorldCanvasApp"s. One exception is using PSPixelCanvasColorTable in non Index mode. Since PSWorldCanvasApp creates its PSPixelCanvasColorTable in Index mode, it will be necessary to get a pointer to the object and explicitly change to different color modes.
psapp = new PSWorldCanvasApp(psdriver); wCanvas = psapp->worldCanvas(); pCanvas = (PSPixelCanvas *)wCanvas->pixelCanvas(); PSPixelCanvasColorTable *psctbl = pCanvas->PSpcctbl(); psctbl->setColorModel(Display::RGB);
See Display/test/dMultichannelRaster.cc for an example.
Tip: PostScript supports a 4096 entry color table for indexed color; PSPixelCanvasColorTable logically breaks this into two parts; One part is used for the changable colors; The other part is reserved for read only colors; (Those allocated by name); The number of read only colors is 512;
Internal
Definition at line 98 of file PSPixelCanvasColorTable.h.
anonymous enum |
Definition at line 104 of file PSPixelCanvasColorTable.h.
anonymous enum |
The last NUMROCOLORS of the table are reserved for RO values.
Definition at line 108 of file PSPixelCanvasColorTable.h.
anonymous enum |
Definition at line 109 of file PSPixelCanvasColorTable.h.
anonymous enum |
Amount to shift components when mapping RGB.
Definition at line 112 of file PSPixelCanvasColorTable.h.
casa::PSPixelCanvasColorTable::PSPixelCanvasColorTable | ( | PSDriver * | ps, |
const Display::ColorModel | = Display::Index |
||
) |
virtual casa::PSPixelCanvasColorTable::~PSPixelCanvasColorTable | ( | ) | [virtual] |
casa::PSPixelCanvasColorTable::PSPixelCanvasColorTable | ( | ) | [private] |
Bool casa::PSPixelCanvasColorTable::allocColor | ( | const float | r, |
const float | g, | ||
const float | b, | ||
int & | index | ||
) |
Allocate the color value in the color table.
index is set to the index allocated. Returns True for success, else False.
Bool casa::PSPixelCanvasColorTable::allocColor | ( | const String & | name, |
int & | index | ||
) |
Bool casa::PSPixelCanvasColorTable::allocColor | ( | const char * | name, |
int & | index | ||
) |
int casa::PSPixelCanvasColorTable::allocColor_ | ( | const float | r, |
const float | g, | ||
const float | b, | ||
int & | index | ||
) | [private] |
Bool casa::PSPixelCanvasColorTable::annotate | ( | ) | const [inline] |
Whether to put tracing comments in the output.
This may be helpful when trying to decipher the PostScript file.
Definition at line 285 of file PSPixelCanvasColorTable.h.
References annotate_.
void casa::PSPixelCanvasColorTable::annotate | ( | const Bool | a | ) | [inline] |
Definition at line 286 of file PSPixelCanvasColorTable.h.
References annotate_.
Display::ColorModel casa::PSPixelCanvasColorTable::colorModel | ( | ) | const [virtual] |
Return the color model for multichannel color.
Implements casa::PixelCanvasColorTable.
virtual Bool casa::PSPixelCanvasColorTable::colorSpaceMap | ( | Display::ColorModel | , |
const Array< Float > & | chan1in, | ||
const Array< Float > & | chan2in, | ||
const Array< Float > & | chan3in, | ||
Array< Float > & | chan1out, | ||
Array< Float > & | chan2out, | ||
Array< Float > & | chan3out | ||
) | [virtual] |
(Multichannel Color) Transform arrays from the passed color model into the colormodel of the PSPCCT.
Does nothing if colorModel is Display::Index. It is assumed that input arrays are in the range of [0,1]
Implements casa::PixelCanvasColorTable.
static void casa::PSPixelCanvasColorTable::componentsToPixel | ( | const uShort | r, |
const uShort | g, | ||
uShort & | b, | ||
uLong & | pixel | ||
) | [inline, static] |
void casa::PSPixelCanvasColorTable::deallocate | ( | uLong | index | ) | [private] |
Mark a RO color as unallocated.
virtual uInt casa::PSPixelCanvasColorTable::depth | ( | ) | const [virtual] |
Return the depth in bits of the colors.
Implements casa::PixelCanvasColorTable.
PSDriver* casa::PSPixelCanvasColorTable::getPSDriver | ( | ) | const [inline] |
Definition at line 241 of file PSPixelCanvasColorTable.h.
References ps.
virtual Bool casa::PSPixelCanvasColorTable::installRGBColors | ( | const Vector< Float > & | r, |
const Vector< Float > & | g, | ||
const Vector< Float > & | b, | ||
uInt | offset = 0 |
||
) | [virtual] |
Install colors into the color table.
Offset is zero-based. Colors are installed into the PixelCanvasColorTable until the Arrays run out or until the end of the colortable is reached. Can be called in any mode, but only affects graphics drawn in Index mode. Values are clamped to [0.0,1.0].h3>Thrown Exceptions
the number of RW colors in the colormap.
Implements casa::PixelCanvasColorTable.
Bool casa::PSPixelCanvasColorTable::lookupROColor | ( | const float | r, |
const float | g, | ||
const float | b, | ||
int & | index | ||
) | [private] |
Finds the index of a color triple coming 'close' to the RGB args.
Returns: True if a match is found, else False. If lookROColor finds a match with a deallocated cell, it reallocates it.
Bool casa::PSPixelCanvasColorTable::lookupRWColor | ( | const float | r, |
const float | g, | ||
const float | b, | ||
int & | index | ||
) | [private] |
void casa::PSPixelCanvasColorTable::mapFromColor3 | ( | const Array< uLong > & | inArray, |
Array< uShort > & | outArray | ||
) | const |
Convert from a packed array of RGB triples to an array of color values.
The output array needs to be 3 times as long as the input array. Used by PSPixelCanvas to convert from D.L. RGB format to an array the PostScript driver can use.
virtual void casa::PSPixelCanvasColorTable::mapToColor | ( | const Colormap * | map, |
Array< uChar > & | outArray, | ||
const Array< uChar > & | inArray, | ||
Bool | rangeCheck = True |
||
) | const [virtual] |
map [0,N-1] into colorpixels, where N is the current colormap size The values are returned as unsigned integers in their respective array.
Warning: uChar type doesn't have enough bits to hold the pixel index;
Warning: uChar and uShort don't have enough bits to hold RGB or HSV values;
Implements casa::PixelCanvasColorTable.
virtual void casa::PSPixelCanvasColorTable::mapToColor | ( | const Colormap * | map, |
Array< uShort > & | outArray, | ||
const Array< uShort > & | inArray, | ||
Bool | rangeCheck = True |
||
) | const [virtual] |
Implements casa::PixelCanvasColorTable.
virtual void casa::PSPixelCanvasColorTable::mapToColor | ( | const Colormap * | map, |
Array< uInt > & | outArray, | ||
const Array< uInt > & | inArray, | ||
Bool | rangeCheck = True |
||
) | const [virtual] |
Implements casa::PixelCanvasColorTable.
virtual void casa::PSPixelCanvasColorTable::mapToColor | ( | const Colormap * | map, |
Array< uLong > & | outArray, | ||
const Array< uLong > & | inArray, | ||
Bool | rangeCheck = True |
||
) | const [virtual] |
Implements casa::PixelCanvasColorTable.
virtual void casa::PSPixelCanvasColorTable::mapToColor | ( | const Colormap * | map, |
Array< uChar > & | inOutArray, | ||
Bool | rangeCheck = True |
||
) | const [virtual] |
Same as above except the matrix is operated on in place.
Only unsigned values make sense here.
Implements casa::PixelCanvasColorTable.
virtual void casa::PSPixelCanvasColorTable::mapToColor | ( | const Colormap * | map, |
Array< uShort > & | inOutArray, | ||
Bool | rangeCheck = True |
||
) | const [virtual] |
Implements casa::PixelCanvasColorTable.
virtual void casa::PSPixelCanvasColorTable::mapToColor | ( | const Colormap * | map, |
Array< uInt > & | inOutArray, | ||
Bool | rangeCheck = True |
||
) | const [virtual] |
Implements casa::PixelCanvasColorTable.
virtual void casa::PSPixelCanvasColorTable::mapToColor | ( | const Colormap * | map, |
Array< uLong > & | inOutArray, | ||
Bool | rangeCheck = True |
||
) | const [virtual] |
Implements casa::PixelCanvasColorTable.
virtual void casa::PSPixelCanvasColorTable::mapToColor3 | ( | Array< uLong > & | out, |
const Array< Float > & | chan1in, | ||
const Array< Float > & | chan2in, | ||
const Array< Float > & | chan3in | ||
) | [virtual] |
(Multichannel Color) Merge separate channel data into an output image.
This function maps floating values between 0 and 1 into a output image suitable for PixelCanvas::drawImage().
Implements casa::PixelCanvasColorTable.
virtual void casa::PSPixelCanvasColorTable::mapToColor3 | ( | Array< uLong > & | out, |
const Array< Double > & | chan1in, | ||
const Array< Double > & | chan2in, | ||
const Array< Double > & | chan3in | ||
) | [virtual] |
Implements casa::PixelCanvasColorTable.
virtual void casa::PSPixelCanvasColorTable::mapToColor3 | ( | Array< uLong > & | out, |
const Array< uShort > & | chan1in, | ||
const Array< uShort > & | chan2in, | ||
const Array< uShort > & | chan3in | ||
) | [virtual] |
This one maps values between 0 and the integer maximum value for each channel into a single output image suitable for PixelCanvas::drawImage().
Implements casa::PixelCanvasColorTable.
virtual void casa::PSPixelCanvasColorTable::mapToColor3 | ( | Array< uLong > & | out, |
const Array< uInt > & | chan1in, | ||
const Array< uInt > & | chan2in, | ||
const Array< uInt > & | chan3in | ||
) | [virtual] |
Implements casa::PixelCanvasColorTable.
uInt casa::PSPixelCanvasColorTable::maxColors | ( | ) | const |
Maximum number of colors in color table.
virtual uInt casa::PSPixelCanvasColorTable::nColors | ( | ) | const [virtual] |
Return the number of colors used to make the map.
Implements casa::PixelCanvasColorTable.
virtual void casa::PSPixelCanvasColorTable::nColors | ( | uInt & | n1, |
uInt & | n2, | ||
uInt & | n3 | ||
) | const [virtual] |
Return the number of colors per component.
For RGB/HSV, returns the number of colors/component supported by PostScript. For Index, returns the number of colors/component for the lookup table. (Limited by D.L. spec).
Implements casa::PixelCanvasColorTable.
virtual uInt casa::PSPixelCanvasColorTable::nSpareColors | ( | ) | const [virtual] |
Return the number of colors that are still unallocated.
Implements casa::PixelCanvasColorTable.
Returns the current # of color components (1 for Indexed, 3 for RGB/HSV).
static Bool casa::PSPixelCanvasColorTable::parseColor | ( | const char * | name, |
float & | red, | ||
float & | green, | ||
float & | blue | ||
) | [static] |
X11 emulation routines.
Convert a colorname to a color triple. Returns True for success, False if name can't be found. The color spec can also be in the form: "#xxxxxx" A '#' character followed by exactly 6 hex digits. (This form is considered obsolete and is not completely implemented here). "rgb:<red>/<green>/<blue>" Where <red>, <green> and <blue> are Each 1 to 4 hex digits. Each value is divided by 1.0/(2^n -1) where n is the # of hex chars in the term. The result is 3 floating point numbers in the range 0..1. "rgbi:<red>/<green>/<blue>" Where <red>, <green> and <blue> are floating point \#s in the range 0..1.
See XParseColor for more information.
static Bool casa::PSPixelCanvasColorTable::parseColor | ( | const String & | name, |
float & | red, | ||
float & | green, | ||
float & | blue | ||
) | [static] |
static void casa::PSPixelCanvasColorTable::pixelToComponents | ( | const uLong | pixel, |
uShort & | r, | ||
uShort & | g, | ||
uShort & | b | ||
) | [inline, static] |
void casa::PSPixelCanvasColorTable::pspcinit | ( | PSDriver * | ps, |
const Display::ColorModel | |||
) | [private] |
Bool casa::PSPixelCanvasColorTable::queryColor | ( | const int | index, |
float & | r, | ||
float & | g, | ||
float & | b | ||
) |
Return contents of colormap at the given index.
Returns False if the index is out of range. The valid range of index is 0..4095.
virtual Bool casa::PSPixelCanvasColorTable::resize | ( | uInt | newSize | ) | [virtual] |
Resize the map if allowed.
Returns True if resize was accepted
Implements casa::PixelCanvasColorTable.
virtual Bool casa::PSPixelCanvasColorTable::resize | ( | uInt | nReds, |
uInt | nGreens, | ||
uInt | nBlues | ||
) | [virtual] |
Implements casa::PixelCanvasColorTable.
virtual void casa::PSPixelCanvasColorTable::setColorModel | ( | const Display::ColorModel | ) | [virtual] |
Changeable at any time.
Bool casa::PSPixelCanvasColorTable::storeColor | ( | const int | index, |
const float | r, | ||
const float | g, | ||
const float | b | ||
) |
Sets the contents of colormap at the given index.
Returns False if the index is out of range. The valid range of index is 0..nColors(). ( Can't change read only values).
ostream& operator<< | ( | ostream & | os, |
const PSPixelCanvasColorTable & | pcc | ||
) | [friend] |
print details of class to ostream
True if index has been allocated.
Definition at line 336 of file PSPixelCanvasColorTable.h.
Bool casa::PSPixelCanvasColorTable::annotate_ [private] |
Definition at line 337 of file PSPixelCanvasColorTable.h.
Referenced by annotate().
float casa::PSPixelCanvasColorTable::blue_[INDEXCOLORS] [private] |
Definition at line 332 of file PSPixelCanvasColorTable.h.
uInt casa::PSPixelCanvasColorTable::bpc_ [private] |
Number of bits/per component.
Determined by colorModel_.
Definition at line 322 of file PSPixelCanvasColorTable.h.
(Valid Always) The colormodel that this PSPixelCanvasColorTable is currently configured as.
Definition at line 327 of file PSPixelCanvasColorTable.h.
float casa::PSPixelCanvasColorTable::green_[INDEXCOLORS] [private] |
Definition at line 332 of file PSPixelCanvasColorTable.h.
uInt casa::PSPixelCanvasColorTable::nColors_ [private] |
(Valid Always) number of total colors available.
Changed by resize.
Definition at line 320 of file PSPixelCanvasColorTable.h.
PSDriver* casa::PSPixelCanvasColorTable::ps [private] |
float casa::PSPixelCanvasColorTable::red_[INDEXCOLORS] [private] |
Copies of the color table.
Definition at line 332 of file PSPixelCanvasColorTable.h.