summaryrefslogtreecommitdiff
path: root/src/Xw/Xw_alloc_pixel.cxx
blob: 00ef98b122c941bbac6bd3c9a4a2bcbd5cff8b5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

#include <Xw_Extension.h>

	/* ifdef then trace on */
#ifdef TRACE
#define TRACE_ALLOC_PIXEL
#define TRACE_SET_PIXEL
#define TRACE_FREE_PIXEL
#endif

/*
   XW_STATUS Xw_alloc_pixel(pcolormap,*pixel):
   XW_EXT_COLORMAP *pcolormap
   unsigned long *pixel;

	Allocates a pixel in the colormap and
	returns SUCCESS for a valid pixel value according of the free space of
	the colormap,
	or ERROR if no more room exist in the colormap.

*/

#ifdef XW_PROTOTYPE
XW_STATUS Xw_alloc_pixel (void* acolormap, unsigned long *pixel)
#else
XW_STATUS Xw_alloc_pixel (acolormap,pixel)
void *acolormap;
unsigned long *pixel;
#endif /*XW_PROTOTYPE*/
{
XW_EXT_COLORMAP *pcolormap = (XW_EXT_COLORMAP*) acolormap;
XW_STATUS status = XW_ERROR;

	*pixel = 0;
        if( !Xw_isdefine_colormap(pcolormap) ) {
          /*ERROR*Bad EXT_COLORMAP Address*/
          Xw_set_error(42,"Xw_alloc_pixel",pcolormap) ;
          return (XW_ERROR) ;
        }

        if( _CCLASS == PseudoColor ) {
          if( XAllocColorCells(_CDISPLAY,
                        _CINFO.colormap,False,NULL,0,pixel,1) ) {
	    status = XW_SUCCESS;
	  }
	}

#ifdef TRACE_ALLOC_PIXEL
if( Xw_get_trace() ) {
    printf(" %d = Xw_alloc_pixel(%lx,%ld)\n",status,(long ) pcolormap,*pixel) ;
}
#endif
    return (status);
}

/*
   XW_STATUS Xw_set_pixel(pcolormap,pixel,r,g,b):
   XW_EXT_COLORMAP *pcolormap
   unsigned long pixel;
   float r,g,b;

	Updates a pixel with the color {r,g,b} defined in [0-1] space
	returns SUCCESS for a valid PseudoColor pixel
*/

#ifdef XW_PROTOTYPE
XW_STATUS Xw_set_pixel (void* acolormap, unsigned long pixel, float r, float g, float b)
#else
XW_STATUS Xw_set_pixel (acolormap,pixel,r,g,b)
void *acolormap;
unsigned long pixel;
float r,g,b;
#endif /*XW_PROTOTYPE*/
{
XW_EXT_COLORMAP *pcolormap = (XW_EXT_COLORMAP*) acolormap;
XW_STATUS status = XW_ERROR;

        if( !Xw_isdefine_colormap(pcolormap) ) {
          /*ERROR*Bad EXT_COLORMAP Address*/
          Xw_set_error(42,"Xw_set_pixel",pcolormap) ;
          return (XW_ERROR) ;
        }

        if( _CCLASS == PseudoColor ) {
	  XColor color;
	  int error,gravity;
	  color.pixel = pixel;
          color.red = (unsigned short) (r*65535.);
          color.green = (unsigned short) (g*65535.);
          color.blue = (unsigned short) (b*65535.);
	  color.flags = DoRed | DoGreen | DoBlue;

          Xw_print_error();
          if( !Xw_get_trace() ) Xw_set_synchronize(_CDISPLAY,True);
          XStoreColor(_CDISPLAY,_CINFO.colormap,&color);
          if( !Xw_get_trace() ) Xw_set_synchronize(_CDISPLAY,False);
          Xw_get_error(&error,&gravity);
          if( error < 1000 ) status = XW_SUCCESS;
	}

#ifdef TRACE_SET_PIXEL
if( Xw_get_trace() ) {
    printf(" %d = Xw_set_pixel(%lx,%ld,%f,%f,%f)\n",status,(long ) pcolormap,pixel,r,g,b) ;
}
#endif
    return (status);
}

/*
   XW_STATUS Xw_free_pixel(pcolormap,pixel):
   XW_EXT_COLORMAP *pcolormap
   unsigned long pixel;

	Free a pixel from the colormap 
	returns SUCCESS for a valid PseudoColor pixel
*/

#ifdef XW_PROTOTYPE
XW_STATUS Xw_free_pixel (void* acolormap, unsigned long pixel)
#else
XW_STATUS Xw_free_pixel (acolormap,pixel)
void *acolormap;
unsigned long pixel;
#endif /*XW_PROTOTYPE*/
{
XW_EXT_COLORMAP *pcolormap = (XW_EXT_COLORMAP*) acolormap;
XW_STATUS status = XW_ERROR;

        if( !Xw_isdefine_colormap(pcolormap) ) {
          /*ERROR*Bad EXT_COLORMAP Address*/
          Xw_set_error(42,"Xw_free_pixel",pcolormap) ;
          return (XW_ERROR) ;
        }

        if( _CCLASS == PseudoColor ) {
	  int error,gravity;

          Xw_print_error();
          if( !Xw_get_trace() ) Xw_set_synchronize(_CDISPLAY,True);
          XFreeColors(_CDISPLAY,_CINFO.colormap,&pixel,1,0);
          if( !Xw_get_trace() ) Xw_set_synchronize(_CDISPLAY,False);
          Xw_get_error(&error,&gravity);
          if( error < 1000 ) status = XW_SUCCESS;
	}

#ifdef TRACE_FREE_PIXEL
if( Xw_get_trace() ) {
    printf(" %d = Xw_free_pixel(%lx,%ld)\n",status,(long ) pcolormap,pixel) ;
}
#endif
    return (status);
}