Article # 212, added by Geoworks, historical record
| first | previous | index | next | last |

How does RGB color index mapping work?



Q. How does RGB to color index mapping work? When we call GrMapColorRGB,
   passing a created gstate with a null window handle, the value that
   comes back is consistent, but that what gets displayed using that
   index is somewhat random. 

A. There is a bug in GrMapColorRGB (for the OmniGo and Nokia 9000) so it
   only works when the passed gstate is associated with a window and has
   a palette. To work around this, you can use GrMapColorRGB like this:

	WindowHandle window;
	GStateHandle gstate;
	int          index;

	window = @call GeodeGetAppObject( 0 )::MSG_VIS_QUERY_WINDOW();
	gstate = GrCreateState( window );
	GrCreatePalette( gstate );
	GrMapColorRGB( gstate, red, green, blue, (Color*)&index );
	GrDestroyState( gstate );

   The values returned by GrMapColorRGB is based on the default palette 
   for the given device and is independent of the video driver. You can
   change the palette you use by calling GrCreatePalette.

   If you want to have just 16 colors, call GrCreatePalette and then
   GrSetPalette to clear out the last 240 entries.

       gstate = GrCreateState( window );
       GrCreatePalette( gstate );
       memset( nullColors, 0, 240 * sizeof( RGBValue ) );
       GrSetPalette( gstate, nullColors, 16, 240 );
       GrMapColorRGB( ... );