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 | /* |
24 | #define TRACE_PUT_RGBPIXEL |
25 | */ |
26 | #endif |
27 | |
28 | /* |
29 | XW_STATUS Xw_put_rgbpixel (aimage,x,y,r,g,b,npixel): |
30 | XW_EXT_IMAGEDATA image *aimage |
31 | int x,y Pixel position |
32 | float r,g,b Pixel color index |
33 | int npixel Pixel number to fill with the same color index |
34 | |
35 | Fill an existing IMAGE created by Xw_open_image with R,G,B values |
36 | |
37 | returns XW_ERROR if Extended Image is not defined |
38 | or VISUAL Image class is not TRUECOLOR |
39 | or Pixel position is wrong (Outside of image) |
40 | returns XW_SUCCESS if successful |
41 | |
42 | */ |
43 | #ifdef XW_PROTOTYPE |
44 | XW_STATUS Xw_put_rgbpixel (void *aimage,int x,int y,float r,float g,float b,int npixel) |
45 | #else |
46 | XW_STATUS Xw_put_rgbpixel (aimage,x,y,r,g,b,npixel) |
47 | void *aimage ; |
48 | int x,y,npixel ; |
49 | float r,g,b ; |
50 | #endif /*XW_PROTOTYPE*/ |
51 | { |
52 | XW_EXT_IMAGEDATA *pimage = (XW_EXT_IMAGEDATA*)aimage; |
53 | XW_EXT_COLORMAP *pcolormap = pimage->pcolormap; |
54 | union { |
55 | char *data ; |
56 | unsigned char *cdata ; |
57 | unsigned short *sdata ; |
58 | unsigned long *ldata ; |
59 | } data ; |
60 | int fpixel,lpixel,simage,index,isapproximate ; |
61 | register int np ; |
62 | unsigned long pixel ; |
63 | XW_STATUS status ; |
64 | XImage *pximage; |
65 | |
66 | if( !Xw_isdefine_image(pimage) ) { |
67 | /*ERROR*Bad EXT_IMAGEDATA Address*/ |
68 | Xw_set_error(25,"Xw_put_rgbpixel",pimage) ; |
69 | return (XW_ERROR) ; |
70 | } |
71 | |
72 | switch ( _CCLASS ) { |
73 | case TrueColor : |
74 | status = Xw_get_color_pixel(_ICOLORMAP,r,g,b,&pixel,&isapproximate) ; |
75 | break ; |
76 | |
77 | case PseudoColor : |
78 | status = Xw_get_color_index(_ICOLORMAP,r,g,b,&index) ; |
79 | pixel = _ICOLORMAP->pixels[index] ; |
80 | break ; |
81 | |
82 | default : |
83 | /*ERROR*Unimplemented Visual class*/ |
84 | Xw_set_error(5,"Xw_put_rgbpixel",&_CCLASS) ; |
85 | return (XW_ERROR) ; |
86 | } |
87 | |
88 | pximage = (_ZIMAGE) ? _ZIMAGE : _IIMAGE; |
89 | simage = pximage->height*pximage->width ; |
90 | fpixel = x*pximage->width + y ; |
91 | lpixel = fpixel + npixel - 1 ; |
92 | |
93 | if( x < 0 || y < 0 || (lpixel >= simage) ) { |
94 | /*WARNING*Bad PIXEL position*/ |
95 | Xw_set_error(47,"Xw_put_rgbpixel",&simage) ; |
96 | return (XW_ERROR) ; |
97 | } |
98 | |
99 | switch (pximage->bitmap_pad) { |
100 | case 8 : |
101 | data.data = pximage->data + (fpixel) ; |
102 | for( np=npixel ; np ; --np ) |
103 | *data.cdata++ = (unsigned char) pixel ; |
104 | break ; |
105 | case 16 : |
106 | data.data = pximage->data + (fpixel<<1) ; |
107 | for( np=npixel ; np ; --np ) |
108 | *data.sdata++ = (unsigned short) pixel ; |
109 | break ; |
110 | case 32 : |
111 | data.data = pximage->data + (fpixel<<2) ; |
112 | for( np=npixel ; np ; --np ) |
113 | *data.ldata++ = (unsigned long) pixel ; |
114 | } |
115 | |
116 | #ifdef TRACE_PUT_RGBPIXEL |
117 | printf (" Xw_put_rgbpixel(%x,%d,%d,%f,%f,%f,%d)\n", |
118 | pimage,x,y,r,g,b,npixel) ; |
119 | #endif |
120 | |
121 | return (XW_SUCCESS); |
122 | } |