1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
19 #include <Xw_Extension.h>
21 /* ifdef then trace on */
23 #define TRACE_GET_COLOR
27 STATUS Xw_get_color(acolormap,index,r,g,b,pixel):
28 XW_EXT_COLORMAP *acolormap Colormap extension structure
29 int index ; Color index 0 >= x < MAXCOLOR
30 float *r,*g,*b ; Return Red,Green,Blue color value 0. >= x <= 1.
31 unsigned long *pixel ;
33 Get R,G,B Color values from index .
35 Returns ERROR if BadColor Index or color is not defined
36 Returns SUCCESS if Successful
41 XW_STATUS Xw_get_color (void* acolormap,int index,float* r,float* g,float* b,unsigned long *pixel)
43 XW_STATUS Xw_get_color (acolormap,index,r,g,b,pixel)
47 unsigned long *pixel ;
48 #endif /*XW_PROTOTYPE*/
50 XW_EXT_COLORMAP *pcolormap = (XW_EXT_COLORMAP*)acolormap;
56 if ( !Xw_isdefine_colorindex(pcolormap,index) ) {
57 /*ERROR*Bad color Index*/
58 Xw_set_error(1,"Xw_get_color",&index) ;
67 color.pixel = pcolormap->pixels[index] ;
68 XQueryColor(_CDISPLAY,_CINFO.colormap,&color) ;
69 *r = (float)color.red/0xFFFF ;
70 *g = (float)color.green/0xFFFF ;
71 *b = (float)color.blue/0xFFFF ;
75 { unsigned long mask = _CVISUAL->map_entries-1 ;
76 unsigned long red,green,blue ;
77 unsigned long rmask = _CVISUAL->red_mask ;
78 unsigned long gmask = _CVISUAL->green_mask ;
79 unsigned long bmask = _CVISUAL->blue_mask ;
81 color.pixel = pcolormap->pixels[index] ;
82 red = color.pixel & rmask ;
83 while ( !(rmask & 0x01) ) { rmask >>= 1; red >>= 1; }
85 green = color.pixel & gmask ;
86 while ( !(gmask & 0x01) ) { gmask >>= 1; green >>= 1; }
88 blue = color.pixel & bmask ;
89 while ( !(bmask & 0x01) ) { bmask >>= 1; blue >>= 1; }
91 *r = (float)red/mask ;
92 *g = (float)green/mask ;
93 *b = (float)blue/mask ;
98 /*Unmatchable Visual class*/
99 Xw_set_error(67,"Xw_get_color",&_CCLASS) ;
103 *pixel = color.pixel ;
106 #ifdef TRACE_GET_COLOR
107 if( Xw_get_trace() > 1 ) {
108 printf(" Xw_get_color(%lx,%d,%f,%f,%f,%lx)\n",(long ) pcolormap,index,*r,*g,*b,*pixel) ;