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 */
24 #define TRACE_PUT_RGBPIXEL
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
35 Fill an existing IMAGE created by Xw_open_image with R,G,B values
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
44 XW_STATUS Xw_put_rgbpixel (void *aimage,int x,int y,float r,float g,float b,int npixel)
46 XW_STATUS Xw_put_rgbpixel (aimage,x,y,r,g,b,npixel)
50 #endif /*XW_PROTOTYPE*/
52 XW_EXT_IMAGEDATA *pimage = (XW_EXT_IMAGEDATA*)aimage;
53 XW_EXT_COLORMAP *pcolormap = pimage->pcolormap;
56 unsigned char *cdata ;
57 unsigned short *sdata ;
58 unsigned long *ldata ;
60 int fpixel,lpixel,simage,index,isapproximate ;
66 if( !Xw_isdefine_image(pimage) ) {
67 /*ERROR*Bad EXT_IMAGEDATA Address*/
68 Xw_set_error(25,"Xw_put_rgbpixel",pimage) ;
74 status = Xw_get_color_pixel(_ICOLORMAP,r,g,b,&pixel,&isapproximate) ;
78 status = Xw_get_color_index(_ICOLORMAP,r,g,b,&index) ;
79 pixel = _ICOLORMAP->pixels[index] ;
83 /*ERROR*Unimplemented Visual class*/
84 Xw_set_error(5,"Xw_put_rgbpixel",&_CCLASS) ;
88 pximage = (_ZIMAGE) ? _ZIMAGE : _IIMAGE;
89 simage = pximage->height*pximage->width ;
90 fpixel = x*pximage->width + y ;
91 lpixel = fpixel + npixel - 1 ;
93 if( x < 0 || y < 0 || (lpixel >= simage) ) {
94 /*WARNING*Bad PIXEL position*/
95 Xw_set_error(47,"Xw_put_rgbpixel",&simage) ;
99 switch (pximage->bitmap_pad) {
101 data.data = pximage->data + (fpixel) ;
102 for( np=npixel ; np ; --np )
103 *data.cdata++ = (unsigned char) pixel ;
106 data.data = pximage->data + (fpixel<<1) ;
107 for( np=npixel ; np ; --np )
108 *data.sdata++ = (unsigned short) pixel ;
111 data.data = pximage->data + (fpixel<<2) ;
112 for( np=npixel ; np ; --np )
113 *data.ldata++ = (unsigned long) pixel ;
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) ;