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_PIXEL
27 STATUS Xw_get_pixel (aimage,x,y,index,npixel):
28 XW_EXT_IMAGEDATA *aimage
29 int x,y Pixel position
30 int *index return Pixel color index
31 int *npixel return Pixel number filled with
34 Extract pixels index from an existing IMAGE created by Xw_get_image
35 or fill with Xw_put_pixel
37 returns ERROR if No image is defined
38 or No pixel color is defined
39 or Pixel position is wrong (Outside of image)
40 returns SUCCESS if successful
45 XW_STATUS Xw_get_pixel (void* aimage,int x,int y,int* index,int* npixel)
47 XW_STATUS Xw_get_pixel (aimage,x,y,index,npixel)
48 XW_EXT_IMAGEDATA *aimage ;
51 #endif /*XW_PROTOTYPE*/
53 XW_EXT_IMAGEDATA *pimage = (XW_EXT_IMAGEDATA*) aimage ;
56 unsigned char *cdata ;
57 unsigned short *sdata ;
58 unsigned long *ldata ;
60 int i=0,fpixel,simage ;
61 unsigned long lpixel=0 ;
64 if( !Xw_isdefine_image(pimage) ) {
65 /*ERROR*Bad EXT_IMAGEDATA Address*/
66 Xw_set_error(25,"Xw_get_pixel",pimage) ;
70 pximage = (_ZIMAGE) ? _ZIMAGE : _IIMAGE;
71 fpixel = x*pximage->width + y ;
72 simage = pximage->height*pximage->width ;
74 if( x < 0 || y < 0 || (fpixel >= simage) ) {
75 /*ERROR*Bad PIXEL position*/
76 Xw_set_error(47,"Xw_get_pixel",&simage) ;
80 switch (pximage->bitmap_pad) {
82 { register unsigned char cpixel ;
83 data.data = pximage->data + (fpixel) ; simage -= fpixel ;
84 cpixel = *data.cdata ;
85 for( i=1 ; i<simage ; i++ ) {
87 if( *data.cdata != cpixel ) break ;
92 { register unsigned short spixel ;
93 data.data = pximage->data + (fpixel<<1) ; simage -= fpixel ;
94 spixel = *data.sdata ;
95 for( i=1 ; i<simage ; i++ ) {
97 if( *data.sdata != spixel ) break ;
102 data.data = pximage->data + (fpixel<<2) ; simage -= fpixel;
103 lpixel = *data.ldata ;
104 for( i=1 ; i<simage ; i++ ) {
106 if( *data.ldata != lpixel ) break ;
112 for( i=0 ; i<_ICOLORMAP->maxcolor ; i++ ) {
113 if( _ICOLORMAP->define[i] &&
114 (lpixel == _ICOLORMAP->pixels[i]) ) break ;
116 if( i < _ICOLORMAP->maxcolor ) {
119 /*ERROR*Bad Defined Color*/
120 Xw_set_error(41,"Xw_get_pixel",&index) ;
124 #ifdef TRACE_GET_PIXEL
125 if( Xw_get_trace() > 2 ) {
126 printf (" Xw_get_pixel(%lx,%d,%d,%ld,%ld)\n",
127 (long ) pimage,x,y,(long ) index,(long ) npixel) ;