]>
git.saurik.com Git - wxWidgets.git/blob - src/xpm/scan.c
2 * Copyright (C) 1989-95 GROUPE BULL
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 * Except as contained in this notice, the name of GROUPE BULL shall not be
22 * used in advertising or otherwise to promote the sale, use or other dealings
23 * in this Software without prior written authorization from GROUPE BULL.
26 /*****************************************************************************\
30 * Scanning utility for XPM file format *
32 * Developed by Arnaud Le Hors *
33 \*****************************************************************************/
36 * The code related to FOR_MSW has been added by
37 * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
41 * The code related to AMIGA has been added by
42 * Lorens Younes (d93-hyo@nada.kth.se) 4/96
47 #define MAXPRINTABLE 92 /* number of printable ascii chars
48 * minus \ and " for string compat
49 * and ? to avoid ANSI trigraphs. */
51 static char *printable
=
52 " .XoO+@#$%&*=-;:>,<1234567890qwertyuipasdfghjklzxcvbnmMNBVCZ\
53 ASDFGHJKLPIUYTREWQ!~^/()_`'][{}|";
56 * printable begin with a space, so in most case, due to my algorithm, when
57 * the number of different colors is less than MAXPRINTABLE, it will give a
58 * char follow by "nothing" (a space) in the readable xpm file
64 unsigned int *pixelindex
;
67 unsigned int mask_pixel
; /* whether there is or not */
70 LFUNC(storePixel
, int, (Pixel pixel
, PixelsMap
*pmap
,
71 unsigned int *index_return
));
73 LFUNC(storeMaskPixel
, int, (Pixel pixel
, PixelsMap
*pmap
,
74 unsigned int *index_return
));
78 LFUNC(GetImagePixels
, int, (XImage
*image
, unsigned int width
,
79 unsigned int height
, PixelsMap
*pmap
));
81 LFUNC(GetImagePixels32
, int, (XImage
*image
, unsigned int width
,
82 unsigned int height
, PixelsMap
*pmap
));
84 LFUNC(GetImagePixels16
, int, (XImage
*image
, unsigned int width
,
85 unsigned int height
, PixelsMap
*pmap
));
87 LFUNC(GetImagePixels8
, int, (XImage
*image
, unsigned int width
,
88 unsigned int height
, PixelsMap
*pmap
));
90 LFUNC(GetImagePixels1
, int, (XImage
*image
, unsigned int width
,
91 unsigned int height
, PixelsMap
*pmap
,
92 int (*storeFunc
) ()));
94 LFUNC(AGetImagePixels
, int, (XImage
*image
, unsigned int width
,
95 unsigned int height
, PixelsMap
*pmap
,
96 int (*storeFunc
) ()));
98 #else /* ndef FOR_MSW */
99 LFUNC(MSWGetImagePixels
, int, (Display
*d
, XImage
*image
, unsigned int width
,
100 unsigned int height
, PixelsMap
*pmap
,
101 int (*storeFunc
) ()));
103 LFUNC(ScanTransparentColor
, int, (XpmColor
*color
, unsigned int cpp
,
104 XpmAttributes
*attributes
));
106 LFUNC(ScanOtherColors
, int, (Display
*display
, XpmColor
*colors
, int ncolors
,
107 Pixel
*pixels
, unsigned int mask
,
108 unsigned int cpp
, XpmAttributes
*attributes
));
111 * This function stores the given pixel in the given arrays which are grown
112 * if not large enough.
115 /* Visual Age cannot deal with old, non-ansi, code */
116 static int storePixel(Pixel pixel
, PixelsMap
* pmap
, unsigned int* index_return
)
119 storePixel(pixel
, pmap
, index_return
)
122 unsigned int *index_return
;
127 unsigned int ncolors
;
129 if (*index_return
) { /* this is a transparent pixel! */
133 ncolors
= pmap
->ncolors
;
134 p
= pmap
->pixels
+ pmap
->mask_pixel
;
135 for (i
= pmap
->mask_pixel
; i
< ncolors
; i
++, p
++)
139 if (ncolors
>= pmap
->size
) {
141 p
= (Pixel
*) XpmRealloc(pmap
->pixels
, sizeof(Pixel
) * pmap
->size
);
147 (pmap
->pixels
)[ncolors
] = pixel
;
155 /* Visual Age cannot deal with old, non-ansi, code */
156 static int storeMaskPixel(Pixel pixel
, PixelsMap
* pmap
, unsigned int* index_return
)
159 storeMaskPixel(pixel
, pmap
, index_return
)
162 unsigned int *index_return
;
166 if (!pmap
->ncolors
) {
168 (pmap
->pixels
)[0] = 0;
169 pmap
->mask_pixel
= 1;
177 /* function call in case of error */
179 #define RETURN(status) \
181 ErrorStatus = status; \
186 * This function scans the given image and stores the found informations in
187 * the given XpmImage structure.
190 /* Visual Age cannot deal with old, non-ansi, code */
191 int XpmCreateXpmImageFromImage(
196 , XpmAttributes
* attributes
200 XpmCreateXpmImageFromImage(display
, image
, shapeimage
,
201 xpmimage
, attributes
)
206 XpmAttributes
*attributes
;
209 /* variables stored in the XpmAttributes structure */
212 /* variables to return */
214 XpmColor
*colorTable
= NULL
;
217 /* calculation variables */
218 unsigned int width
= 0;
219 unsigned int height
= 0;
220 unsigned int cppm
; /* minimum chars per pixel */
223 /* initialize pmap */
225 pmap
.pixelindex
= NULL
;
226 pmap
.size
= 256; /* should be enough most of the time */
234 width
= image
->width
;
235 height
= image
->height
;
236 } else if (shapeimage
) {
237 width
= shapeimage
->width
;
238 height
= shapeimage
->height
;
242 * retrieve information from the XpmAttributes
244 if (attributes
&& (attributes
->valuemask
& XpmCharsPerPixel
245 /* 3.2 backward compatibility code */
246 || attributes
->valuemask
& XpmInfos
))
248 cpp
= attributes
->cpp
;
253 (unsigned int *) XpmCalloc(width
* height
, sizeof(unsigned int));
254 if (!pmap
.pixelindex
)
257 pmap
.pixels
= (Pixel
*) XpmMalloc(sizeof(Pixel
) * pmap
.size
);
262 * scan shape mask if any
268 ErrorStatus
= GetImagePixels1(shapeimage
, width
, height
, &pmap
,
271 ErrorStatus
= AGetImagePixels(shapeimage
, width
, height
, &pmap
,
277 ErrorStatus
= MSWGetImagePixels(display
, shapeimage
, width
, height
,
278 &pmap
, storeMaskPixel
);
279 /* calling convention all messed up OS/2 -- figure out later */
282 #endif /* ndef for FOR_MSW */
284 if (ErrorStatus
!= XpmSuccess
)
289 * scan the image data
291 * In case depth is 1 or bits_per_pixel is 4, 6, 8, 24 or 32 use optimized
292 * functions, otherwise use slower but sure general one.
300 if (((image
->bits_per_pixel
| image
->depth
) == 1) &&
301 (image
->byte_order
== image
->bitmap_bit_order
))
302 ErrorStatus
= GetImagePixels1(image
, width
, height
, &pmap
,
304 else if (image
->format
== ZPixmap
)
306 if (image
->bits_per_pixel
== 8)
307 ErrorStatus
= GetImagePixels8(image
, width
, height
, &pmap
);
308 else if (image
->bits_per_pixel
== 16)
309 ErrorStatus
= GetImagePixels16(image
, width
, height
, &pmap
);
310 else if (image
->bits_per_pixel
== 32)
311 ErrorStatus
= GetImagePixels32(image
, width
, height
, &pmap
);
314 ErrorStatus
= GetImagePixels(image
, width
, height
, &pmap
);
316 ErrorStatus
= AGetImagePixels(image
, width
, height
, &pmap
,
321 #ifndef __VISAGECPP30__
322 ErrorStatus
= MSWGetImagePixels(display
, image
, width
, height
, &pmap
,
328 if (ErrorStatus
!= XpmSuccess
)
333 * get rgb values and a string of char, and possibly a name for each
337 colorTable
= (XpmColor
*) XpmCalloc(pmap
.ncolors
, sizeof(XpmColor
));
341 /* compute the minimal cpp */
342 for (cppm
= 1, c
= MAXPRINTABLE
; pmap
.ncolors
> c
; cppm
++)
347 if (pmap
.mask_pixel
) {
348 ErrorStatus
= ScanTransparentColor(colorTable
, cpp
, attributes
);
349 if (ErrorStatus
!= XpmSuccess
)
353 ErrorStatus
= ScanOtherColors(display
, colorTable
, pmap
.ncolors
,
354 pmap
.pixels
, pmap
.mask_pixel
, cpp
,
356 if (ErrorStatus
!= XpmSuccess
)
360 * store found informations in the XpmImage structure
362 xpmimage
->width
= width
;
363 xpmimage
->height
= height
;
365 xpmimage
->ncolors
= pmap
.ncolors
;
366 xpmimage
->colorTable
= colorTable
;
367 xpmimage
->data
= pmap
.pixelindex
;
369 XpmFree(pmap
.pixels
);
372 /* exit point in case of error, free only locally allocated variables */
375 XpmFree(pmap
.pixelindex
);
377 XpmFree(pmap
.pixels
);
379 xpmFreeColorTable(colorTable
, pmap
.ncolors
);
381 return (ErrorStatus
);
385 /* Visual Age cannot deal with old, non-ansi, code */
386 static int ScanTransparentColor(XpmColor
* color
, unsigned int cpp
, XpmAttributes
* attributes
)
389 ScanTransparentColor(color
, cpp
, attributes
)
392 XpmAttributes
*attributes
;
396 unsigned int a
, b
, c
;
398 /* first get a character string */
400 if (!(s
= color
->string
= (char *) XpmMalloc(cpp
+ 1)))
401 return (XpmNoMemory
);
402 *s
++ = printable
[c
= a
% MAXPRINTABLE
];
403 for (b
= 1; b
< cpp
; b
++, s
++)
404 *s
= printable
[c
= ((a
- c
) / MAXPRINTABLE
) % MAXPRINTABLE
];
407 /* then retreive related info from the attributes if any */
408 if (attributes
&& (attributes
->valuemask
& XpmColorTable
409 /* 3.2 backward compatibility code */
410 || attributes
->valuemask
& XpmInfos
)
412 && attributes
->mask_pixel
!= XpmUndefPixel
) {
415 char **defaults
= (char **) color
;
416 char **mask_defaults
;
418 /* 3.2 backward compatibility code */
419 if (attributes
->valuemask
& XpmColorTable
)
421 mask_defaults
= (char **) (
422 attributes
->colorTable
+ attributes
->mask_pixel
);
423 /* 3.2 backward compatibility code */
425 mask_defaults
= (char **)
426 ((XpmColor
**) attributes
->colorTable
)[attributes
->mask_pixel
];
428 for (key
= 1; key
<= NKEYS
; key
++) {
429 if (s
= mask_defaults
[key
]) {
430 defaults
[key
] = (char *) xpmstrdup(s
);
432 return (XpmNoMemory
);
436 color
->c_color
= (char *) xpmstrdup(TRANSPARENT_COLOR
);
438 return (XpmNoMemory
);
444 /* Visual Age cannot deal with old, non-ansi, code */
445 static int ScanOtherColors(
452 , XpmAttributes
* attributes
456 ScanOtherColors(display
, colors
, ncolors
, pixels
, mask
, cpp
, attributes
)
463 XpmAttributes
*attributes
;
466 /* variables stored in the XpmAttributes structure */
471 xpmRgbName rgbn
[MAX_RGBNAMES
];
473 xpmRgbName
*rgbn
= NULL
;
476 unsigned int i
, j
, c
, i2
;
478 XColor
*xcolors
= NULL
, *xcolor
;
480 XpmColor
*colorTable
, **oldColorTable
= NULL
;
481 unsigned int ancolors
= 0;
483 unsigned int mask_pixel
;
486 /* retrieve information from the XpmAttributes */
487 if (attributes
&& (attributes
->valuemask
& XpmColormap
))
488 colormap
= attributes
->colormap
;
490 colormap
= XDefaultColormap(display
, XDefaultScreen(display
));
491 if (attributes
&& (attributes
->valuemask
& XpmRgbFilename
))
492 rgb_fname
= attributes
->rgb_fname
;
496 /* start from the right element */
503 /* first get character strings and rgb values */
504 xcolors
= (XColor
*) XpmMalloc(sizeof(XColor
) * ncolors
);
506 return (XpmNoMemory
);
508 for (i
= 0, i2
= mask
, color
= colors
, xcolor
= xcolors
;
509 i
< (unsigned)ncolors
; i
++, i2
++, color
++, xcolor
++, pixels
++) {
511 if (!(s
= color
->string
= (char *) XpmMalloc(cpp
+ 1))) {
513 return (XpmNoMemory
);
515 *s
++ = printable
[c
= i2
% MAXPRINTABLE
];
516 for (j
= 1; j
< cpp
; j
++, s
++)
517 *s
= printable
[c
= ((i2
- c
) / MAXPRINTABLE
) % MAXPRINTABLE
];
520 xcolor
->pixel
= *pixels
;
523 XQueryColors(display
, &colormap
, xcolors
, ncolors
);
525 XQueryColors(display
, colormap
, xcolors
, ncolors
);
529 /* read the rgb file if any was specified */
531 rgbn_max
= xpmReadRgbNames(attributes
->rgb_fname
, rgbn
);
533 /* FOR_MSW: rgb names and values are hardcoded in rgbtab.h */
534 rgbn_max
= xpmReadRgbNames(NULL
, NULL
);
537 if (attributes
&& attributes
->valuemask
& XpmColorTable
) {
538 colorTable
= attributes
->colorTable
;
539 ancolors
= attributes
->ncolors
;
540 apixels
= attributes
->pixels
;
541 mask_pixel
= attributes
->mask_pixel
;
543 /* 3.2 backward compatibility code */
544 else if (attributes
&& attributes
->valuemask
& XpmInfos
) {
545 oldColorTable
= (XpmColor
**) attributes
->colorTable
;
546 ancolors
= attributes
->ncolors
;
547 apixels
= attributes
->pixels
;
548 mask_pixel
= attributes
->mask_pixel
;
552 for (i
= 0, color
= colors
, xcolor
= xcolors
; i
< (unsigned)ncolors
;
553 i
++, color
++, xcolor
++) {
555 /* look for related info from the attributes if any */
558 unsigned int offset
= 0;
560 for (j
= 0; j
< ancolors
; j
++) {
561 if (j
== mask_pixel
) {
565 if (apixels
[j
- offset
] == xcolor
->pixel
)
570 char **defaults
= (char **) color
;
573 /* 3.2 backward compatibility code */
575 adefaults
= (char **) oldColorTable
[j
];
578 adefaults
= (char **) (colorTable
+ j
);
581 for (key
= 1; key
<= NKEYS
; key
++) {
582 if (s
= adefaults
[key
])
583 defaults
[key
] = (char *) xpmstrdup(s
);
588 /* if nothing found look for a color name */
591 colorname
= xpmGetRgbName(rgbn
, rgbn_max
, xcolor
->red
,
592 xcolor
->green
, xcolor
->blue
);
594 color
->c_color
= (char *) xpmstrdup(colorname
);
596 /* at last store the rgb value */
599 sprintf(buf
, "#%04X%04X%04X",
600 xcolor
->red
, xcolor
->green
, xcolor
->blue
);
602 sprintf(buf
, "#%02x%02x%02x",
603 xcolor
->red
, xcolor
->green
, xcolor
->blue
);
605 color
->c_color
= (char *) xpmstrdup(buf
);
607 if (!color
->c_color
) {
609 xpmFreeRgbNames(rgbn
, rgbn_max
);
610 return (XpmNoMemory
);
616 xpmFreeRgbNames(rgbn
, rgbn_max
);
623 * The functions below are written from X11R5 MIT's code (XImUtil.c)
625 * The idea is to have faster functions than the standard XGetPixel function
626 * to scan the image data. Indeed we can speed up things by suppressing tests
627 * performed for each pixel. We do exactly the same tests but at the image
631 static unsigned long Const low_bits_table
[] = {
632 0x00000000, 0x00000001, 0x00000003, 0x00000007,
633 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
634 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
635 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
636 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
637 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
638 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
639 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
644 * Default method to scan pixels of an image data structure.
645 * The algorithm used is:
647 * copy the source bitmap_unit or Zpixel into temp
648 * normalize temp if needed
649 * extract the pixel bits into return value
654 GetImagePixels(image
, width
, height
, pmap
)
665 int bits
, depth
, ibu
, ibpp
, offset
;
670 iptr
= pmap
->pixelindex
;
671 depth
= image
->depth
;
672 lbt
= low_bits_table
[depth
];
673 ibpp
= image
->bits_per_pixel
;
674 offset
= image
->xoffset
;
676 if ((image
->bits_per_pixel
| image
->depth
) == 1) {
677 ibu
= image
->bitmap_unit
;
678 for (y
= 0; y
< height
; y
++)
679 for (x
= 0; x
< width
; x
++, iptr
++) {
680 src
= &data
[XYINDEX(x
, y
, image
)];
681 dst
= (char *) &pixel
;
683 for (i
= ibu
>> 3; --i
>= 0;)
685 XYNORMALIZE(&pixel
, image
);
686 bits
= (x
+ offset
) % ibu
;
687 pixel
= ((((char *) &pixel
)[bits
>> 3]) >> (bits
& 7)) & 1;
690 if (storePixel(pixel
, pmap
, iptr
))
691 return (XpmNoMemory
);
693 } else if (image
->format
== XYPixmap
) {
696 ibu
= image
->bitmap_unit
;
698 bpl
= image
->bytes_per_line
;
699 for (y
= 0; y
< height
; y
++)
700 for (x
= 0; x
< width
; x
++, iptr
++) {
703 for (i
= depth
; --i
>= 0;) {
704 src
= &data
[XYINDEX(x
, y
, image
) + plane
];
707 for (j
= nbytes
; --j
>= 0;)
709 XYNORMALIZE(&px
, image
);
710 bits
= (x
+ offset
) % ibu
;
711 pixel
= (pixel
<< 1) |
712 (((((char *) &px
)[bits
>> 3]) >> (bits
& 7)) & 1);
713 plane
= plane
+ (bpl
* height
);
717 if (storePixel(pixel
, pmap
, iptr
))
718 return (XpmNoMemory
);
720 } else if (image
->format
== ZPixmap
) {
721 for (y
= 0; y
< height
; y
++)
722 for (x
= 0; x
< width
; x
++, iptr
++) {
723 src
= &data
[ZINDEX(x
, y
, image
)];
726 for (i
= (ibpp
+ 7) >> 3; --i
>= 0;)
728 ZNORMALIZE(&px
, image
);
730 for (i
= sizeof(unsigned long); --i
>= 0;)
731 pixel
= (pixel
<< 8) | ((unsigned char *) &px
)[i
];
740 if (storePixel(pixel
, pmap
, iptr
))
741 return (XpmNoMemory
);
744 return (XpmColorError
); /* actually a bad image */
749 * scan pixels of a 32-bits Z image data structure
752 #if !defined(WORD64) && !defined(LONG64)
753 static unsigned long byteorderpixel
= MSBFirst
<< 24;
757 GetImagePixels32(image
, width
, height
, pmap
)
771 data
= (unsigned char *) image
->data
;
772 iptr
= pmap
->pixelindex
;
773 depth
= image
->depth
;
774 lbt
= low_bits_table
[depth
];
775 #if !defined(WORD64) && !defined(LONG64)
776 if (*((char *) &byteorderpixel
) == image
->byte_order
) {
777 for (y
= 0; y
< height
; y
++)
778 for (x
= 0; x
< width
; x
++, iptr
++) {
779 addr
= &data
[ZINDEX32(x
, y
, image
)];
780 pixel
= *((unsigned long *) addr
);
783 if (storePixel(pixel
, pmap
, iptr
))
784 return (XpmNoMemory
);
788 if (image
->byte_order
== MSBFirst
)
789 for (y
= 0; y
< height
; y
++)
790 for (x
= 0; x
< width
; x
++, iptr
++) {
791 addr
= &data
[ZINDEX32(x
, y
, image
)];
792 pixel
= ((unsigned long) addr
[0] << 24 |
793 (unsigned long) addr
[1] << 16 |
794 (unsigned long) addr
[2] << 8 |
798 if (storePixel(pixel
, pmap
, iptr
))
799 return (XpmNoMemory
);
802 for (y
= 0; y
< height
; y
++)
803 for (x
= 0; x
< width
; x
++, iptr
++) {
804 addr
= &data
[ZINDEX32(x
, y
, image
)];
806 (unsigned long) addr
[1] << 8 |
807 (unsigned long) addr
[2] << 16 |
808 (unsigned long) addr
[3] << 24);
811 if (storePixel(pixel
, pmap
, iptr
))
812 return (XpmNoMemory
);
818 * scan pixels of a 16-bits Z image data structure
822 GetImagePixels16(image
, width
, height
, pmap
)
836 data
= (unsigned char *) image
->data
;
837 iptr
= pmap
->pixelindex
;
838 depth
= image
->depth
;
839 lbt
= low_bits_table
[depth
];
840 if (image
->byte_order
== MSBFirst
)
841 for (y
= 0; y
< height
; y
++)
842 for (x
= 0; x
< width
; x
++, iptr
++) {
843 addr
= &data
[ZINDEX16(x
, y
, image
)];
844 pixel
= addr
[0] << 8 | addr
[1];
847 if (storePixel(pixel
, pmap
, iptr
))
848 return (XpmNoMemory
);
851 for (y
= 0; y
< height
; y
++)
852 for (x
= 0; x
< width
; x
++, iptr
++) {
853 addr
= &data
[ZINDEX16(x
, y
, image
)];
854 pixel
= addr
[0] | addr
[1] << 8;
857 if (storePixel(pixel
, pmap
, iptr
))
858 return (XpmNoMemory
);
864 * scan pixels of a 8-bits Z image data structure
868 GetImagePixels8(image
, width
, height
, pmap
)
881 data
= (unsigned char *) image
->data
;
882 iptr
= pmap
->pixelindex
;
883 depth
= image
->depth
;
884 lbt
= low_bits_table
[depth
];
885 for (y
= 0; y
< height
; y
++)
886 for (x
= 0; x
< width
; x
++, iptr
++) {
887 pixel
= data
[ZINDEX8(x
, y
, image
)];
890 if (storePixel(pixel
, pmap
, iptr
))
891 return (XpmNoMemory
);
897 * scan pixels of a 1-bit depth Z image data structure
901 GetImagePixels1(image
, width
, height
, pmap
, storeFunc
)
912 int xoff
, yoff
, offset
, bpl
;
915 iptr
= pmap
->pixelindex
;
916 offset
= image
->xoffset
;
917 bpl
= image
->bytes_per_line
;
919 if (image
->bitmap_bit_order
== MSBFirst
)
920 for (y
= 0; y
< height
; y
++)
921 for (x
= 0; x
< width
; x
++, iptr
++) {
923 yoff
= y
* bpl
+ (xoff
>> 3);
925 pixel
= (data
[yoff
] & (0x80 >> xoff
)) ? 1 : 0;
926 if ((*storeFunc
) (pixel
, pmap
, iptr
))
927 return (XpmNoMemory
);
930 for (y
= 0; y
< height
; y
++)
931 for (x
= 0; x
< width
; x
++, iptr
++) {
933 yoff
= y
* bpl
+ (xoff
>> 3);
935 pixel
= (data
[yoff
] & (1 << xoff
)) ? 1 : 0;
936 if ((*storeFunc
) (pixel
, pmap
, iptr
))
937 return (XpmNoMemory
);
944 #define CLEAN_UP(status) \
946 if (pixels) XpmFree (pixels);\
947 if (tmp_img) FreeXImage (tmp_img);\
961 unsigned char *pixels
;
964 pixels
= XpmMalloc ((((width
+15)>>4)<<4)*sizeof (*pixels
));
968 tmp_img
= AllocXImage ((((width
+15)>>4)<<4), 1, image
->rp
->BitMap
->Depth
);
970 CLEAN_UP (XpmNoMemory
)
972 iptr
= pmap
->pixelindex
;
973 for (y
= 0; y
< height
; ++y
)
975 ReadPixelLine8 (image
->rp
, 0, y
, width
, pixels
, tmp_img
->rp
);
976 for (x
= 0; x
< width
; ++x
, ++iptr
)
978 if ((*storeFunc
) (pixels
[x
], pmap
, iptr
))
979 CLEAN_UP (XpmNoMemory
)
983 CLEAN_UP (XpmSuccess
)
989 #else /* ndef FOR_MSW */
993 #ifdef __VISAGECPP30__
994 static int MSWGetImagePixels(
998 , unsigned int height
1000 , int (*storeFunc
) (Pixel
, PixelsMap
*, unsigned int*)
1003 static int MSWGetImagePixels(
1006 , unsigned int width
1007 , unsigned int height
1009 , int (*storeFunc
) ()
1015 MSWGetImagePixels(display
, image
, width
, height
, pmap
, storeFunc
)
1019 unsigned int height
;
1021 int (*storeFunc
) ();
1030 DEVOPENSTRUC dop
= {NULL
, "DISPLAY", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
};
1031 SIZEL sizl
= {0, 0};
1035 iptr
= pmap
->pixelindex
;
1038 hps
= GpiCreatePS(hab
, *display
, &sizl
, GPIA_ASSOC
| PU_PELS
);
1039 GpiSetBitmap(hps
, image
->bitmap
);
1041 SelectObject(*display
, image
->bitmap
);
1044 for (y
= 0; y
< height
; y
++) {
1045 for (x
= 0; x
< width
; x
++, iptr
++) {
1049 pixel
= GpiQueryPel(hps
, &point
);
1051 pixel
= GetPixel(*display
, x
, y
);
1054 if ((*storeFunc
) (pixel
, pmap
, iptr
))
1055 return (XpmNoMemory
);
1058 return (XpmSuccess
);
1066 XpmCreateXpmImageFromPixmap(display
, pixmap
, shapemask
,
1067 xpmimage
, attributes
)
1072 XpmAttributes
*attributes
;
1074 XImage
*ximage
= NULL
;
1075 XImage
*shapeimage
= NULL
;
1076 unsigned int width
= 0;
1077 unsigned int height
= 0;
1081 if (attributes
&& attributes
->valuemask
& XpmSize
) {
1082 width
= attributes
->width
;
1083 height
= attributes
->height
;
1085 /* get the ximages */
1087 xpmCreateImageFromPixmap(display
, pixmap
, &ximage
, &width
, &height
);
1089 xpmCreateImageFromPixmap(display
, shapemask
, &shapeimage
,
1092 /* create the related XpmImage */
1093 ErrorStatus
= XpmCreateXpmImageFromImage(display
, ximage
, shapeimage
,
1094 xpmimage
, attributes
);
1096 /* destroy the ximages */
1098 XDestroyImage(ximage
);
1100 XDestroyImage(shapeimage
);
1102 return (ErrorStatus
);
1105 # endif/* not AMIGA */
1106 #endif /* ndef FOR_MSW */