The ChColorMap 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 ChColorMap class manages to find the closest match available in the system palette for any colour you might want to use.
BScreen's IndexForColor() and ColorForIndex() method tends to do a better job of choosing a color; you'll have to benchmark it against ChColorMap yourself. Remember that BScreen objects need to be short-lived because they lock the display.
#include "Ch/ChColorMap.h" ChColorMap();
Create a new ChColorMap object. This sets up an internal byte-expansion table and fills the color mapping table with the current system palette.
status_t 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 256-color 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 256-color system palette) matching the color specified by the RGB value or the rgb_color.
Please see the libCh Overview for licensing information.
This implementation of an approximate inverse color mapping is © 1996-1998 Chris Herborth (chrish@kagi.com, based on information published in the August 1996 issue of the C/C++ User's Journal ("Approximate Inverse Color Mapping" by Tim Kientzle).
Last modified: $Date: 1998/04/11 19:41:01 $