The ColorMap class implements the approximate inverse color mapping discussed in the August 1996 issue of the C/C++ User's Journal ("Approximate Inverse Color Mapping" by Tim Kientzle).
The idea is to avoid the slow speed and memory hit of an exact color mapping table, and the complexity of a sparse array or some other data structure. The ColorMap class manages to find the closest match available in the system palette for any colour you might want to use.
ColorMap();
Create a new ColorMap object. This sets up an internal byte-expansion table and fills the color mapping table with the system palette.
int Refresh( void );
Refreshes the internal table used for mapping colors to the system palette. Returns B_NO_ERROR if successful, or B_NO_MEMORY if it couldn't allocate a new buffer.
You should never need to call this yourself, unless BeOS starts providing a way to change the system palette. If it becomes possible for an application to override the system palette, you should Refresh() before attempting to use the color mapping after every palette change.
uint getIndex( const rgb_color color ); uint getIndex( const uint r, const uint g, const uint b );
Return the index (into the system palette) of the color closest to the color specified by the RGB value in r, g, b or the rgb_color in color.
rgb_color getColor( const rgb_color color ); rgb_color getColor( const uint r, const uint g, const uint b );
Return the closest color (from the system palette) matching the color specified by the RGB value or the rgb_color.
This implementation of an approximate inverse color mapping is © 1996 Chris Herborth (chrish@qnx.com, based on information published in the August 1996 issue of the C/C++ User's Journal ("Approximate Inverse Color Mapping" by Tim Kientzle).
The code for ColorMap, and other BeOS-related information, is available on my web site in the Be section.
This code is freely usable by anyone for any purpose, as long as the author (Chris Herborth) is credited (in an application/library/other software product's documentation).
You may not charge for this code in any way. If this code is placed on an online service or CD-ROM, the service provider or CD-ROM publisher may not charge extra for this code or the space it occupies.
This documentation must accompany the source code (ColorMap.h and ColorMap.cpp), but you don't have to include the documentation or the source code with any software product that uses ColorMap objects internally.