0023533: Unitialized variables used, IntTools_TopolTool.cxx
[occt.git] / src / Xw / Xw_get_color.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
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.
7//
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.
10//
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.
17
7fd59977 18
19#include <Xw_Extension.h>
20
b311480e 21/* ifdef then trace on */
7fd59977 22#ifdef TRACE
23#define TRACE_GET_COLOR
24#endif
25
26/*
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 ;
32
33 Get R,G,B Color values from index .
34
35 Returns ERROR if BadColor Index or color is not defined
36 Returns SUCCESS if Successful
37
38*/
39
40#ifdef XW_PROTOTYPE
41XW_STATUS Xw_get_color (void* acolormap,int index,float* r,float* g,float* b,unsigned long *pixel)
42#else
43XW_STATUS Xw_get_color (acolormap,index,r,g,b,pixel)
44void *acolormap;
45int index ;
46float *r,*g,*b ;
47unsigned long *pixel ;
48#endif /*XW_PROTOTYPE*/
49{
50XW_EXT_COLORMAP *pcolormap = (XW_EXT_COLORMAP*)acolormap;
51XColor color ;
52
53 *pixel = 0;
54 *r = *g = *b = 0.;
55
56 if ( !Xw_isdefine_colorindex(pcolormap,index) ) {
57 /*ERROR*Bad color Index*/
58 Xw_set_error(1,"Xw_get_color",&index) ;
59 return (XW_ERROR) ;
60 }
61
62
63 switch ( _CCLASS ) {
64
65 case PseudoColor :
66 case StaticColor :
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 ;
72 break ;
73
74 case TrueColor :
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 ;
80
81 color.pixel = pcolormap->pixels[index] ;
82 red = color.pixel & rmask ;
83 while ( !(rmask & 0x01) ) { rmask >>= 1; red >>= 1; }
84
85 green = color.pixel & gmask ;
86 while ( !(gmask & 0x01) ) { gmask >>= 1; green >>= 1; }
87
88 blue = color.pixel & bmask ;
89 while ( !(bmask & 0x01) ) { bmask >>= 1; blue >>= 1; }
90
91 *r = (float)red/mask ;
92 *g = (float)green/mask ;
93 *b = (float)blue/mask ;
94 }
95 break ;
96
97 default :
98 /*Unmatchable Visual class*/
99 Xw_set_error(67,"Xw_get_color",&_CCLASS) ;
100 return (XW_ERROR) ;
101 }
102
103 *pixel = color.pixel ;
104
105
106#ifdef TRACE_GET_COLOR
107if( Xw_get_trace() > 1 ) {
108 printf(" Xw_get_color(%lx,%d,%f,%f,%f,%lx)\n",(long ) pcolormap,index,*r,*g,*b,*pixel) ;
109}
110#endif
111
112 return (XW_SUCCESS);
113}