]>
git.saurik.com Git - wxWidgets.git/blob - src/xpm/scan.c
4390a0d6123dcbd2e6c2e3a72c92cbba09cf1aa3
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
,
276 ErrorStatus
= MSWGetImagePixels(display
, shapeimage
, width
, height
,
277 &pmap
, storeMaskPixel
);
279 #endif /* ndef for FOR_MSW */
281 if (ErrorStatus
!= XpmSuccess
)
286 * scan the image data
288 * In case depth is 1 or bits_per_pixel is 4, 6, 8, 24 or 32 use optimized
289 * functions, otherwise use slower but sure general one.
297 if (((image
->bits_per_pixel
| image
->depth
) == 1) &&
298 (image
->byte_order
== image
->bitmap_bit_order
))
299 ErrorStatus
= GetImagePixels1(image
, width
, height
, &pmap
,
301 else if (image
->format
== ZPixmap
)
303 if (image
->bits_per_pixel
== 8)
304 ErrorStatus
= GetImagePixels8(image
, width
, height
, &pmap
);
305 else if (image
->bits_per_pixel
== 16)
306 ErrorStatus
= GetImagePixels16(image
, width
, height
, &pmap
);
307 else if (image
->bits_per_pixel
== 32)
308 ErrorStatus
= GetImagePixels32(image
, width
, height
, &pmap
);
311 ErrorStatus
= GetImagePixels(image
, width
, height
, &pmap
);
313 ErrorStatus
= AGetImagePixels(image
, width
, height
, &pmap
,
318 ErrorStatus
= MSWGetImagePixels(display
, image
, width
, height
, &pmap
,
323 if (ErrorStatus
!= XpmSuccess
)
328 * get rgb values and a string of char, and possibly a name for each
332 colorTable
= (XpmColor
*) XpmCalloc(pmap
.ncolors
, sizeof(XpmColor
));
336 /* compute the minimal cpp */
337 for (cppm
= 1, c
= MAXPRINTABLE
; pmap
.ncolors
> c
; cppm
++)
342 if (pmap
.mask_pixel
) {
343 ErrorStatus
= ScanTransparentColor(colorTable
, cpp
, attributes
);
344 if (ErrorStatus
!= XpmSuccess
)
348 ErrorStatus
= ScanOtherColors(display
, colorTable
, pmap
.ncolors
,
349 pmap
.pixels
, pmap
.mask_pixel
, cpp
,
351 if (ErrorStatus
!= XpmSuccess
)
355 * store found informations in the XpmImage structure
357 xpmimage
->width
= width
;
358 xpmimage
->height
= height
;
360 xpmimage
->ncolors
= pmap
.ncolors
;
361 xpmimage
->colorTable
= colorTable
;
362 xpmimage
->data
= pmap
.pixelindex
;
364 XpmFree(pmap
.pixels
);
367 /* exit point in case of error, free only locally allocated variables */
370 XpmFree(pmap
.pixelindex
);
372 XpmFree(pmap
.pixels
);
374 xpmFreeColorTable(colorTable
, pmap
.ncolors
);
376 return (ErrorStatus
);
380 /* Visual Age cannot deal with old, non-ansi, code */
381 static int ScanTransparentColor(XpmColor
* color
, unsigned int cpp
, XpmAttributes
* attributes
)
384 ScanTransparentColor(color
, cpp
, attributes
)
387 XpmAttributes
*attributes
;
391 unsigned int a
, b
, c
;
393 /* first get a character string */
395 if (!(s
= color
->string
= (char *) XpmMalloc(cpp
+ 1)))
396 return (XpmNoMemory
);
397 *s
++ = printable
[c
= a
% MAXPRINTABLE
];
398 for (b
= 1; b
< cpp
; b
++, s
++)
399 *s
= printable
[c
= ((a
- c
) / MAXPRINTABLE
) % MAXPRINTABLE
];
402 /* then retreive related info from the attributes if any */
403 if (attributes
&& (attributes
->valuemask
& XpmColorTable
404 /* 3.2 backward compatibility code */
405 || attributes
->valuemask
& XpmInfos
)
407 && attributes
->mask_pixel
!= XpmUndefPixel
) {
410 char **defaults
= (char **) color
;
411 char **mask_defaults
;
413 /* 3.2 backward compatibility code */
414 if (attributes
->valuemask
& XpmColorTable
)
416 mask_defaults
= (char **) (
417 attributes
->colorTable
+ attributes
->mask_pixel
);
418 /* 3.2 backward compatibility code */
420 mask_defaults
= (char **)
421 ((XpmColor
**) attributes
->colorTable
)[attributes
->mask_pixel
];
423 for (key
= 1; key
<= NKEYS
; key
++) {
424 if (s
= mask_defaults
[key
]) {
425 defaults
[key
] = (char *) xpmstrdup(s
);
427 return (XpmNoMemory
);
431 color
->c_color
= (char *) xpmstrdup(TRANSPARENT_COLOR
);
433 return (XpmNoMemory
);
439 /* Visual Age cannot deal with old, non-ansi, code */
440 static int ScanOtherColors(
447 , XpmAttributes
* attributes
451 ScanOtherColors(display
, colors
, ncolors
, pixels
, mask
, cpp
, attributes
)
458 XpmAttributes
*attributes
;
461 /* variables stored in the XpmAttributes structure */
466 xpmRgbName rgbn
[MAX_RGBNAMES
];
468 xpmRgbName
*rgbn
= NULL
;
471 unsigned int i
, j
, c
, i2
;
473 XColor
*xcolors
= NULL
, *xcolor
;
475 XpmColor
*colorTable
, **oldColorTable
= NULL
;
476 unsigned int ancolors
= 0;
478 unsigned int mask_pixel
;
481 /* retrieve information from the XpmAttributes */
482 if (attributes
&& (attributes
->valuemask
& XpmColormap
))
483 colormap
= attributes
->colormap
;
485 colormap
= XDefaultColormap(display
, XDefaultScreen(display
));
486 if (attributes
&& (attributes
->valuemask
& XpmRgbFilename
))
487 rgb_fname
= attributes
->rgb_fname
;
491 /* start from the right element */
498 /* first get character strings and rgb values */
499 xcolors
= (XColor
*) XpmMalloc(sizeof(XColor
) * ncolors
);
501 return (XpmNoMemory
);
503 for (i
= 0, i2
= mask
, color
= colors
, xcolor
= xcolors
;
504 i
< (unsigned)ncolors
; i
++, i2
++, color
++, xcolor
++, pixels
++) {
506 if (!(s
= color
->string
= (char *) XpmMalloc(cpp
+ 1))) {
508 return (XpmNoMemory
);
510 *s
++ = printable
[c
= i2
% MAXPRINTABLE
];
511 for (j
= 1; j
< cpp
; j
++, s
++)
512 *s
= printable
[c
= ((i2
- c
) / MAXPRINTABLE
) % MAXPRINTABLE
];
515 xcolor
->pixel
= *pixels
;
518 XQueryColors(display
, &colormap
, xcolors
, ncolors
);
520 XQueryColors(display
, colormap
, xcolors
, ncolors
);
524 /* read the rgb file if any was specified */
526 rgbn_max
= xpmReadRgbNames(attributes
->rgb_fname
, rgbn
);
528 /* FOR_MSW: rgb names and values are hardcoded in rgbtab.h */
529 rgbn_max
= xpmReadRgbNames(NULL
, NULL
);
532 if (attributes
&& attributes
->valuemask
& XpmColorTable
) {
533 colorTable
= attributes
->colorTable
;
534 ancolors
= attributes
->ncolors
;
535 apixels
= attributes
->pixels
;
536 mask_pixel
= attributes
->mask_pixel
;
538 /* 3.2 backward compatibility code */
539 else if (attributes
&& attributes
->valuemask
& XpmInfos
) {
540 oldColorTable
= (XpmColor
**) attributes
->colorTable
;
541 ancolors
= attributes
->ncolors
;
542 apixels
= attributes
->pixels
;
543 mask_pixel
= attributes
->mask_pixel
;
547 for (i
= 0, color
= colors
, xcolor
= xcolors
; i
< (unsigned)ncolors
;
548 i
++, color
++, xcolor
++) {
550 /* look for related info from the attributes if any */
553 unsigned int offset
= 0;
555 for (j
= 0; j
< ancolors
; j
++) {
556 if (j
== mask_pixel
) {
560 if (apixels
[j
- offset
] == xcolor
->pixel
)
565 char **defaults
= (char **) color
;
568 /* 3.2 backward compatibility code */
570 adefaults
= (char **) oldColorTable
[j
];
573 adefaults
= (char **) (colorTable
+ j
);
576 for (key
= 1; key
<= NKEYS
; key
++) {
577 if (s
= adefaults
[key
])
578 defaults
[key
] = (char *) xpmstrdup(s
);
583 /* if nothing found look for a color name */
586 colorname
= xpmGetRgbName(rgbn
, rgbn_max
, xcolor
->red
,
587 xcolor
->green
, xcolor
->blue
);
589 color
->c_color
= (char *) xpmstrdup(colorname
);
591 /* at last store the rgb value */
594 sprintf(buf
, "#%04X%04X%04X",
595 xcolor
->red
, xcolor
->green
, xcolor
->blue
);
597 sprintf(buf
, "#%02x%02x%02x",
598 xcolor
->red
, xcolor
->green
, xcolor
->blue
);
600 color
->c_color
= (char *) xpmstrdup(buf
);
602 if (!color
->c_color
) {
604 xpmFreeRgbNames(rgbn
, rgbn_max
);
605 return (XpmNoMemory
);
611 xpmFreeRgbNames(rgbn
, rgbn_max
);
618 * The functions below are written from X11R5 MIT's code (XImUtil.c)
620 * The idea is to have faster functions than the standard XGetPixel function
621 * to scan the image data. Indeed we can speed up things by suppressing tests
622 * performed for each pixel. We do exactly the same tests but at the image
626 static unsigned long Const low_bits_table
[] = {
627 0x00000000, 0x00000001, 0x00000003, 0x00000007,
628 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
629 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
630 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
631 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
632 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
633 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
634 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
639 * Default method to scan pixels of an image data structure.
640 * The algorithm used is:
642 * copy the source bitmap_unit or Zpixel into temp
643 * normalize temp if needed
644 * extract the pixel bits into return value
649 GetImagePixels(image
, width
, height
, pmap
)
660 int bits
, depth
, ibu
, ibpp
, offset
;
665 iptr
= pmap
->pixelindex
;
666 depth
= image
->depth
;
667 lbt
= low_bits_table
[depth
];
668 ibpp
= image
->bits_per_pixel
;
669 offset
= image
->xoffset
;
671 if ((image
->bits_per_pixel
| image
->depth
) == 1) {
672 ibu
= image
->bitmap_unit
;
673 for (y
= 0; y
< height
; y
++)
674 for (x
= 0; x
< width
; x
++, iptr
++) {
675 src
= &data
[XYINDEX(x
, y
, image
)];
676 dst
= (char *) &pixel
;
678 for (i
= ibu
>> 3; --i
>= 0;)
680 XYNORMALIZE(&pixel
, image
);
681 bits
= (x
+ offset
) % ibu
;
682 pixel
= ((((char *) &pixel
)[bits
>> 3]) >> (bits
& 7)) & 1;
685 if (storePixel(pixel
, pmap
, iptr
))
686 return (XpmNoMemory
);
688 } else if (image
->format
== XYPixmap
) {
691 ibu
= image
->bitmap_unit
;
693 bpl
= image
->bytes_per_line
;
694 for (y
= 0; y
< height
; y
++)
695 for (x
= 0; x
< width
; x
++, iptr
++) {
698 for (i
= depth
; --i
>= 0;) {
699 src
= &data
[XYINDEX(x
, y
, image
) + plane
];
702 for (j
= nbytes
; --j
>= 0;)
704 XYNORMALIZE(&px
, image
);
705 bits
= (x
+ offset
) % ibu
;
706 pixel
= (pixel
<< 1) |
707 (((((char *) &px
)[bits
>> 3]) >> (bits
& 7)) & 1);
708 plane
= plane
+ (bpl
* height
);
712 if (storePixel(pixel
, pmap
, iptr
))
713 return (XpmNoMemory
);
715 } else if (image
->format
== ZPixmap
) {
716 for (y
= 0; y
< height
; y
++)
717 for (x
= 0; x
< width
; x
++, iptr
++) {
718 src
= &data
[ZINDEX(x
, y
, image
)];
721 for (i
= (ibpp
+ 7) >> 3; --i
>= 0;)
723 ZNORMALIZE(&px
, image
);
725 for (i
= sizeof(unsigned long); --i
>= 0;)
726 pixel
= (pixel
<< 8) | ((unsigned char *) &px
)[i
];
735 if (storePixel(pixel
, pmap
, iptr
))
736 return (XpmNoMemory
);
739 return (XpmColorError
); /* actually a bad image */
744 * scan pixels of a 32-bits Z image data structure
747 #if !defined(WORD64) && !defined(LONG64)
748 static unsigned long byteorderpixel
= MSBFirst
<< 24;
752 GetImagePixels32(image
, width
, height
, pmap
)
766 data
= (unsigned char *) image
->data
;
767 iptr
= pmap
->pixelindex
;
768 depth
= image
->depth
;
769 lbt
= low_bits_table
[depth
];
770 #if !defined(WORD64) && !defined(LONG64)
771 if (*((char *) &byteorderpixel
) == image
->byte_order
) {
772 for (y
= 0; y
< height
; y
++)
773 for (x
= 0; x
< width
; x
++, iptr
++) {
774 addr
= &data
[ZINDEX32(x
, y
, image
)];
775 pixel
= *((unsigned long *) addr
);
778 if (storePixel(pixel
, pmap
, iptr
))
779 return (XpmNoMemory
);
783 if (image
->byte_order
== MSBFirst
)
784 for (y
= 0; y
< height
; y
++)
785 for (x
= 0; x
< width
; x
++, iptr
++) {
786 addr
= &data
[ZINDEX32(x
, y
, image
)];
787 pixel
= ((unsigned long) addr
[0] << 24 |
788 (unsigned long) addr
[1] << 16 |
789 (unsigned long) addr
[2] << 8 |
793 if (storePixel(pixel
, pmap
, iptr
))
794 return (XpmNoMemory
);
797 for (y
= 0; y
< height
; y
++)
798 for (x
= 0; x
< width
; x
++, iptr
++) {
799 addr
= &data
[ZINDEX32(x
, y
, image
)];
801 (unsigned long) addr
[1] << 8 |
802 (unsigned long) addr
[2] << 16 |
803 (unsigned long) addr
[3] << 24);
806 if (storePixel(pixel
, pmap
, iptr
))
807 return (XpmNoMemory
);
813 * scan pixels of a 16-bits Z image data structure
817 GetImagePixels16(image
, width
, height
, pmap
)
831 data
= (unsigned char *) image
->data
;
832 iptr
= pmap
->pixelindex
;
833 depth
= image
->depth
;
834 lbt
= low_bits_table
[depth
];
835 if (image
->byte_order
== MSBFirst
)
836 for (y
= 0; y
< height
; y
++)
837 for (x
= 0; x
< width
; x
++, iptr
++) {
838 addr
= &data
[ZINDEX16(x
, y
, image
)];
839 pixel
= addr
[0] << 8 | addr
[1];
842 if (storePixel(pixel
, pmap
, iptr
))
843 return (XpmNoMemory
);
846 for (y
= 0; y
< height
; y
++)
847 for (x
= 0; x
< width
; x
++, iptr
++) {
848 addr
= &data
[ZINDEX16(x
, y
, image
)];
849 pixel
= addr
[0] | addr
[1] << 8;
852 if (storePixel(pixel
, pmap
, iptr
))
853 return (XpmNoMemory
);
859 * scan pixels of a 8-bits Z image data structure
863 GetImagePixels8(image
, width
, height
, pmap
)
876 data
= (unsigned char *) image
->data
;
877 iptr
= pmap
->pixelindex
;
878 depth
= image
->depth
;
879 lbt
= low_bits_table
[depth
];
880 for (y
= 0; y
< height
; y
++)
881 for (x
= 0; x
< width
; x
++, iptr
++) {
882 pixel
= data
[ZINDEX8(x
, y
, image
)];
885 if (storePixel(pixel
, pmap
, iptr
))
886 return (XpmNoMemory
);
892 * scan pixels of a 1-bit depth Z image data structure
896 GetImagePixels1(image
, width
, height
, pmap
, storeFunc
)
907 int xoff
, yoff
, offset
, bpl
;
910 iptr
= pmap
->pixelindex
;
911 offset
= image
->xoffset
;
912 bpl
= image
->bytes_per_line
;
914 if (image
->bitmap_bit_order
== MSBFirst
)
915 for (y
= 0; y
< height
; y
++)
916 for (x
= 0; x
< width
; x
++, iptr
++) {
918 yoff
= y
* bpl
+ (xoff
>> 3);
920 pixel
= (data
[yoff
] & (0x80 >> xoff
)) ? 1 : 0;
921 if ((*storeFunc
) (pixel
, pmap
, iptr
))
922 return (XpmNoMemory
);
925 for (y
= 0; y
< height
; y
++)
926 for (x
= 0; x
< width
; x
++, iptr
++) {
928 yoff
= y
* bpl
+ (xoff
>> 3);
930 pixel
= (data
[yoff
] & (1 << xoff
)) ? 1 : 0;
931 if ((*storeFunc
) (pixel
, pmap
, iptr
))
932 return (XpmNoMemory
);
939 #define CLEAN_UP(status) \
941 if (pixels) XpmFree (pixels);\
942 if (tmp_img) FreeXImage (tmp_img);\
956 unsigned char *pixels
;
959 pixels
= XpmMalloc ((((width
+15)>>4)<<4)*sizeof (*pixels
));
963 tmp_img
= AllocXImage ((((width
+15)>>4)<<4), 1, image
->rp
->BitMap
->Depth
);
965 CLEAN_UP (XpmNoMemory
)
967 iptr
= pmap
->pixelindex
;
968 for (y
= 0; y
< height
; ++y
)
970 ReadPixelLine8 (image
->rp
, 0, y
, width
, pixels
, tmp_img
->rp
);
971 for (x
= 0; x
< width
; ++x
, ++iptr
)
973 if ((*storeFunc
) (pixels
[x
], pmap
, iptr
))
974 CLEAN_UP (XpmNoMemory
)
978 CLEAN_UP (XpmSuccess
)
984 #else /* ndef FOR_MSW */
988 #ifdef __VISAGECPP30__
989 static int MSWGetImagePixels(
993 , unsigned int height
995 , int (*storeFunc
) (Pixel
, PixelsMap
*, unsigned int*)
998 static int MSWGetImagePixels(
1001 , unsigned int width
1002 , unsigned int height
1004 , int (*storeFunc
) ()
1010 MSWGetImagePixels(display
, image
, width
, height
, pmap
, storeFunc
)
1014 unsigned int height
;
1016 int (*storeFunc
) ();
1025 DEVOPENSTRUC dop
= {NULL
, "DISPLAY", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
};
1026 SIZEL sizl
= {0, 0};
1030 iptr
= pmap
->pixelindex
;
1033 shapedc
= DevOpenDC(hab
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&dop
, NULLHANDLE
);
1034 *display
= GpiCreatePS(hab
, shapedc
, &sizl
, GPIA_ASSOC
| PU_PELS
);
1035 GpiSetBitmap(*display
, image
->bitmap
);
1037 SelectObject(*display
, image
->bitmap
);
1040 for (y
= 0; y
< height
; y
++) {
1041 for (x
= 0; x
< width
; x
++, iptr
++) {
1045 pixel
= GpiQueryPel(*display
, &point
);
1047 pixel
= GetPixel(*display
, x
, y
);
1050 if ((*storeFunc
) (pixel
, pmap
, iptr
))
1051 return (XpmNoMemory
);
1054 return (XpmSuccess
);
1062 XpmCreateXpmImageFromPixmap(display
, pixmap
, shapemask
,
1063 xpmimage
, attributes
)
1068 XpmAttributes
*attributes
;
1070 XImage
*ximage
= NULL
;
1071 XImage
*shapeimage
= NULL
;
1072 unsigned int width
= 0;
1073 unsigned int height
= 0;
1077 if (attributes
&& attributes
->valuemask
& XpmSize
) {
1078 width
= attributes
->width
;
1079 height
= attributes
->height
;
1081 /* get the ximages */
1083 xpmCreateImageFromPixmap(display
, pixmap
, &ximage
, &width
, &height
);
1085 xpmCreateImageFromPixmap(display
, shapemask
, &shapeimage
,
1088 /* create the related XpmImage */
1089 ErrorStatus
= XpmCreateXpmImageFromImage(display
, ximage
, shapeimage
,
1090 xpmimage
, attributes
);
1092 /* destroy the ximages */
1094 XDestroyImage(ximage
);
1096 XDestroyImage(shapeimage
);
1098 return (ErrorStatus
);
1101 # endif/* not AMIGA */
1102 #endif /* ndef FOR_MSW */