This code fragment takes the following RGB values (.85, .75, .65) that make a light pea green and passes them to the TGrayColor class. These values are equalized to the closest gray scale values. The conversion formula is gray level = (0.3)Red + (0.596)Green + (0.11)Blue. In the example, the gray level is 0.769.
In this case, the values (56.7210, 55.3082, 72.4083) are used in the XYZ color space to reproduce the red fill that is obtained in the RGB color space with the values TRGBColor( .75, .5, .5 ).
The same red fill is obtained in the HSV color space with the following values:
You can work in one color space and easily transform to any other color space. The following code fragments show how you can start in RGB and transform to XYZ and HSV. All color classes have Get functions for retrieving color values.
Gray scale
You can also create a gray scale color by supplying a single value that represents the percent of gray. The code line below makes 77 percent gray. TRGBColor grayRGBColor( .85, .75, .65 );
TColorPaint* grayFill = new TColorPaint( TGrayColor( grayRGBColor ) );
TGrafBundle polyBundle( grayFill, TAttributeState::kFill );
TColorPaint* grayFill = new TColorPaint( TGrayColor( 0.77 ) );
XYZ color space
TFillBundle polyBundle( TXYZColor( 56.7210, 5.3082, 72.4083 ) );
HSV color space
TFillBundle polyBundle( THSVColor( 0, .3333, .75 ) );
Transforming color spaces
TRGBColor redFill( .75, .5, .5 );
TXYZColor xyzColor( redFill );
TFillBundle polyBundle( redFill );
TRGBColor redFill( .75, .5, .5 );
THSVColor hsvColor( redFill );
TFillBundle polyBundle( redFill );
[Contents]
[Previous]
[Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.