PSPixelCanvasColorTable.h
Classes
- PSPixelCanvasColorTable -- Implementation of PixelCanvasColorTable for PostScript device. (full description)
Types
- INDEXBPC = 12
-
- RGBBPC = 10
-
- INDEXCOLORS = (1<
- NUMROCOLORS = 512
-
- BMASK = 0xff,RGBMASK=(RGBCOLORS-1),
-
Interface
- Public Members
- PSPixelCanvasColorTable(PSDriver *ps, const Display::ColorModel = Display::Index)
- virtual ~PSPixelCanvasColorTable()
- virtual Bool resize(uInt newSize)
- 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)
- virtual uInt nColors() const
- virtual void nColors(uInt &n1, uInt &n2, uInt &n3) const
- uInt maxColors()const
- virtual uInt depth() const
- virtual uInt nSpareColors() const
- virtual void mapToColor(const Colormap * map, Array<uChar> & outArray, const Array<uChar> & inArray, Bool rangeCheck = True) const
- 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
- 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)
- 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)
- 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
- 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)
- Display::ColorModel colorModel() const
- uInt numComponents()const
- virtual void setColorModel(const Display::ColorModel)
- PSDriver *getPSDriver()const
- static Bool parseColor(const char *name, float &red, float &green, float &blue)
- static Bool parseColor(const String &name, float &red, float &green, float &blue)
- Bool queryColor(const int index, float &r, float &g, float &b)
- Bool storeColor(const int index, const float r, const float g, const float b)
- Bool allocColor(const float r, const float g, const float b, int &index)
- Bool allocColor(const String &name, int &index)
- Bool allocColor(const char *name, int &index)
- Bool annotate()const
- void annotate(const Bool a)
- friend ostream & operator << (ostream & os, const PSPixelCanvasColorTable & pcc)
- static inline void pixelToComponents( const uLong pixel, uShort &r, uShort &g, uShort &b)
- static inline void componentsToPixel( const uShort r, const uShort g, uShort &b, uLong &pixel)
- Private Members
- PSPixelCanvasColorTable()
- void pspcinit(PSDriver *ps, const Display::ColorModel)
- Bool lookupROColor(const float r, const float g, const float b, int &index)
- 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)
Prerequisite
Etymology
Synopsis
To create a PSPixelCanvasColorTable, just pass the constructor a pointer
to a
PSDriver and, optionally,
supplying a color model. (The default is Index).
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.
Example
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.
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.
Motivation
To Do
Member Description
The last NUMROCOLORS of the table are reserved for RO values.
Amount to shift components when mapping RGB.
virtual Bool resize(uInt newSize)
virtual Bool resize(uInt nReds, uInt nGreens, uInt nBlues)
Resize the map if allowed. Returns True if resize was accepted
virtual Bool installRGBColors(const Vector<Float> & r, const Vector<Float> & g, const Vector<Float> & b, uInt offset = 0)
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].
Thrown Exceptions
virtual uInt nColors() const
Return the number of RW colors in the colormap.
virtual void nColors(uInt &n1, uInt &n2, uInt &n3) const
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).
Maximum number of colors in color table.
virtual uInt depth() const
Return the depth in bits of the colors.
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
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
map [0,N-1] into colorpixels, where N is the current colormap size
The values are returned as unsigned integers in their respective
array.
uChar type doesn't have enough bits
to hold the pixel index.
uChar and uShort don't have enough bits to
hold RGB or HSV values.
virtual void mapToColor(const Colormap * map, Array<uChar> & inOutArray, Bool rangeCheck = True) const
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
Same as above except the matrix is operated on in place. Only unsigned
values make sense here.
virtual void mapToColor3(Array<uLong> & out, const Array<Float> & chan1in, const Array<Float> & chan2in, const Array<Float> & chan3in)
virtual void mapToColor3(Array<uLong> & out, const Array<Double> & chan1in, const Array<Double> & chan2in, const Array<Double> & chan3in)
(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().
virtual void mapToColor3(Array<uLong> & out, const Array<uShort> & chan1in, const Array<uShort> & chan2in, const Array<uShort> & chan3in)
virtual void mapToColor3(Array<uLong> & out, const Array<uInt> & chan1in, const Array<uInt> & chan2in, const Array<uInt> & chan3in)
This one maps values between 0 and the integer
maximum value for each channel into a single
output image suitable for PixelCanvas::drawImage().
void 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 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.
Does nothing if colorModel is Display::Index.
It is assumed that input arrays are in the range of [0,1]
Return the color model for multichannel color
Returns the current # of color components (1 for Indexed, 3 for RGB/HSV).
Changeable at any time.
static Bool parseColor(const char *name, float &red, float &green, float &blue)
static Bool parseColor(const String &name, float &red, float &green, float &blue)
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.
Bool 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.
Bool 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).
Bool 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 allocColor(const char *name, int &index)
Whether to put tracing comments in the output. This may be helpful
when trying to decipher the PostScript file.
void annotate(const Bool a)
friend ostream & operator << (ostream & os, const PSPixelCanvasColorTable & pcc)
print details of class to ostream
static inline void pixelToComponents( const uLong pixel, uShort &r, uShort &g, uShort &b)
Convert a packed pixel (from mapToColor3) to three color components.
static inline void componentsToPixel( const uShort r, const uShort g, uShort &b, uLong &pixel)
Pack RGB or HSV color components into a single unsigned long.
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.
Returns: True if a match is found, else False.
If lookROColor finds a match with a deallocated cell, it reallocates it.
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)
Mark a RO color as unallocated.