]>
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
,
323 ErrorStatus
= MSWGetImagePixels(display
, image
, width
, height
, &pmap
,
325 /* calling convention all messed up OS/2 -- figure out later */
330 if (ErrorStatus
!= XpmSuccess
)
335 * get rgb values and a string of char, and possibly a name for each
339 colorTable
= (XpmColor
*) XpmCalloc(pmap
.ncolors
, sizeof(XpmColor
));
343 /* compute the minimal cpp */
344 for (cppm
= 1, c
= MAXPRINTABLE
; pmap
.ncolors
> c
; cppm
++)
349 if (pmap
.mask_pixel
) {
350 ErrorStatus
= ScanTransparentColor(colorTable
, cpp
, attributes
);
351 if (ErrorStatus
!= XpmSuccess
)
355 ErrorStatus
= ScanOtherColors(display
, colorTable
, pmap
.ncolors
,
356 pmap
.pixels
, pmap
.mask_pixel
, cpp
,
358 if (ErrorStatus
!= XpmSuccess
)
362 * store found informations in the XpmImage structure
364 xpmimage
->width
= width
;
365 xpmimage
->height
= height
;
367 xpmimage
->ncolors
= pmap
.ncolors
;
368 xpmimage
->colorTable
= colorTable
;
369 xpmimage
->data
= pmap
.pixelindex
;
371 XpmFree(pmap
.pixels
);
374 /* exit point in case of error, free only locally allocated variables */
377 XpmFree(pmap
.pixelindex
);
379 XpmFree(pmap
.pixels
);
381 xpmFreeColorTable(colorTable
, pmap
.ncolors
);
383 return (ErrorStatus
);
387 /* Visual Age cannot deal with old, non-ansi, code */
388 static int ScanTransparentColor(XpmColor
* color
, unsigned int cpp
, XpmAttributes
* attributes
)
391 ScanTransparentColor(color
, cpp
, attributes
)
394 XpmAttributes
*attributes
;
398 unsigned int a
, b
, c
;
400 /* first get a character string */
402 if (!(s
= color
->string
= (char *) XpmMalloc(cpp
+ 1)))
403 return (XpmNoMemory
);
404 *s
++ = printable
[c
= a
% MAXPRINTABLE
];
405 for (b
= 1; b
< cpp
; b
++, s
++)
406 *s
= printable
[c
= ((a
- c
) / MAXPRINTABLE
) % MAXPRINTABLE
];
409 /* then retreive related info from the attributes if any */
410 if (attributes
&& (attributes
->valuemask
& XpmColorTable
411 /* 3.2 backward compatibility code */
412 || attributes
->valuemask
& XpmInfos
)
414 && attributes
->mask_pixel
!= XpmUndefPixel
) {
417 char **defaults
= (char **) color
;
418 char **mask_defaults
;
420 /* 3.2 backward compatibility code */
421 if (attributes
->valuemask
& XpmColorTable
)
423 mask_defaults
= (char **) (
424 attributes
->colorTable
+ attributes
->mask_pixel
);
425 /* 3.2 backward compatibility code */
427 mask_defaults
= (char **)
428 ((XpmColor
**) attributes
->colorTable
)[attributes
->mask_pixel
];
430 for (key
= 1; key
<= NKEYS
; key
++) {
431 if (s
= mask_defaults
[key
]) {
432 defaults
[key
] = (char *) xpmstrdup(s
);
434 return (XpmNoMemory
);
438 color
->c_color
= (char *) xpmstrdup(TRANSPARENT_COLOR
);
440 return (XpmNoMemory
);
446 /* Visual Age cannot deal with old, non-ansi, code */
447 static int ScanOtherColors(
454 , XpmAttributes
* attributes
458 ScanOtherColors(display
, colors
, ncolors
, pixels
, mask
, cpp
, attributes
)
465 XpmAttributes
*attributes
;
468 /* variables stored in the XpmAttributes structure */
473 xpmRgbName rgbn
[MAX_RGBNAMES
];
475 xpmRgbName
*rgbn
= NULL
;
478 unsigned int i
, j
, c
, i2
;
480 XColor
*xcolors
= NULL
, *xcolor
;
482 XpmColor
*colorTable
, **oldColorTable
= NULL
;
483 unsigned int ancolors
= 0;
485 unsigned int mask_pixel
;
488 /* retrieve information from the XpmAttributes */
489 if (attributes
&& (attributes
->valuemask
& XpmColormap
))
490 colormap
= attributes
->colormap
;
492 colormap
= XDefaultColormap(display
, XDefaultScreen(display
));
493 if (attributes
&& (attributes
->valuemask
& XpmRgbFilename
))
494 rgb_fname
= attributes
->rgb_fname
;
498 /* start from the right element */
505 /* first get character strings and rgb values */
506 xcolors
= (XColor
*) XpmMalloc(sizeof(XColor
) * ncolors
);
508 return (XpmNoMemory
);
510 for (i
= 0, i2
= mask
, color
= colors
, xcolor
= xcolors
;
511 i
< ncolors
; i
++, i2
++, color
++, xcolor
++, pixels
++) {
513 if (!(s
= color
->string
= (char *) XpmMalloc(cpp
+ 1))) {
515 return (XpmNoMemory
);
517 *s
++ = printable
[c
= i2
% MAXPRINTABLE
];
518 for (j
= 1; j
< cpp
; j
++, s
++)
519 *s
= printable
[c
= ((i2
- c
) / MAXPRINTABLE
) % MAXPRINTABLE
];
522 xcolor
->pixel
= *pixels
;
525 XQueryColors(display
, &colormap
, xcolors
, ncolors
);
527 XQueryColors(display
, colormap
, xcolors
, ncolors
);
531 /* read the rgb file if any was specified */
533 rgbn_max
= xpmReadRgbNames(attributes
->rgb_fname
, rgbn
);
535 /* FOR_MSW: rgb names and values are hardcoded in rgbtab.h */
536 rgbn_max
= xpmReadRgbNames(NULL
, NULL
);
539 if (attributes
&& attributes
->valuemask
& XpmColorTable
) {
540 colorTable
= attributes
->colorTable
;
541 ancolors
= attributes
->ncolors
;
542 apixels
= attributes
->pixels
;
543 mask_pixel
= attributes
->mask_pixel
;
545 /* 3.2 backward compatibility code */
546 else if (attributes
&& attributes
->valuemask
& XpmInfos
) {
547 oldColorTable
= (XpmColor
**) attributes
->colorTable
;
548 ancolors
= attributes
->ncolors
;
549 apixels
= attributes
->pixels
;
550 mask_pixel
= attributes
->mask_pixel
;
554 for (i
= 0, color
= colors
, xcolor
= xcolors
; i
< ncolors
;
555 i
++, color
++, xcolor
++) {
557 /* look for related info from the attributes if any */
560 unsigned int offset
= 0;
562 for (j
= 0; j
< ancolors
; j
++) {
563 if (j
== mask_pixel
) {
567 if (apixels
[j
- offset
] == xcolor
->pixel
)
572 char **defaults
= (char **) color
;
575 /* 3.2 backward compatibility code */
577 adefaults
= (char **) oldColorTable
[j
];
580 adefaults
= (char **) (colorTable
+ j
);
583 for (key
= 1; key
<= NKEYS
; key
++) {
584 if (s
= adefaults
[key
])
585 defaults
[key
] = (char *) xpmstrdup(s
);
590 /* if nothing found look for a color name */
593 colorname
= xpmGetRgbName(rgbn
, rgbn_max
, xcolor
->red
,
594 xcolor
->green
, xcolor
->blue
);
596 color
->c_color
= (char *) xpmstrdup(colorname
);
598 /* at last store the rgb value */
601 sprintf(buf
, "#%04X%04X%04X",
602 xcolor
->red
, xcolor
->green
, xcolor
->blue
);
604 sprintf(buf
, "#%02x%02x%02x",
605 xcolor
->red
, xcolor
->green
, xcolor
->blue
);
607 color
->c_color
= (char *) xpmstrdup(buf
);
609 if (!color
->c_color
) {
611 xpmFreeRgbNames(rgbn
, rgbn_max
);
612 return (XpmNoMemory
);
618 xpmFreeRgbNames(rgbn
, rgbn_max
);
625 * The functions below are written from X11R5 MIT's code (XImUtil.c)
627 * The idea is to have faster functions than the standard XGetPixel function
628 * to scan the image data. Indeed we can speed up things by suppressing tests
629 * performed for each pixel. We do exactly the same tests but at the image
633 static unsigned long Const low_bits_table
[] = {
634 0x00000000, 0x00000001, 0x00000003, 0x00000007,
635 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
636 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
637 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
638 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
639 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
640 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
641 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
646 * Default method to scan pixels of an image data structure.
647 * The algorithm used is:
649 * copy the source bitmap_unit or Zpixel into temp
650 * normalize temp if needed
651 * extract the pixel bits into return value
656 GetImagePixels(image
, width
, height
, pmap
)
667 int bits
, depth
, ibu
, ibpp
, offset
;
672 iptr
= pmap
->pixelindex
;
673 depth
= image
->depth
;
674 lbt
= low_bits_table
[depth
];
675 ibpp
= image
->bits_per_pixel
;
676 offset
= image
->xoffset
;
678 if ((image
->bits_per_pixel
| image
->depth
) == 1) {
679 ibu
= image
->bitmap_unit
;
680 for (y
= 0; y
< height
; y
++)
681 for (x
= 0; x
< width
; x
++, iptr
++) {
682 src
= &data
[XYINDEX(x
, y
, image
)];
683 dst
= (char *) &pixel
;
685 for (i
= ibu
>> 3; --i
>= 0;)
687 XYNORMALIZE(&pixel
, image
);
688 bits
= (x
+ offset
) % ibu
;
689 pixel
= ((((char *) &pixel
)[bits
>> 3]) >> (bits
& 7)) & 1;
692 if (storePixel(pixel
, pmap
, iptr
))
693 return (XpmNoMemory
);
695 } else if (image
->format
== XYPixmap
) {
698 ibu
= image
->bitmap_unit
;
700 bpl
= image
->bytes_per_line
;
701 for (y
= 0; y
< height
; y
++)
702 for (x
= 0; x
< width
; x
++, iptr
++) {
705 for (i
= depth
; --i
>= 0;) {
706 src
= &data
[XYINDEX(x
, y
, image
) + plane
];
709 for (j
= nbytes
; --j
>= 0;)
711 XYNORMALIZE(&px
, image
);
712 bits
= (x
+ offset
) % ibu
;
713 pixel
= (pixel
<< 1) |
714 (((((char *) &px
)[bits
>> 3]) >> (bits
& 7)) & 1);
715 plane
= plane
+ (bpl
* height
);
719 if (storePixel(pixel
, pmap
, iptr
))
720 return (XpmNoMemory
);
722 } else if (image
->format
== ZPixmap
) {
723 for (y
= 0; y
< height
; y
++)
724 for (x
= 0; x
< width
; x
++, iptr
++) {
725 src
= &data
[ZINDEX(x
, y
, image
)];
728 for (i
= (ibpp
+ 7) >> 3; --i
>= 0;)
730 ZNORMALIZE(&px
, image
);
732 for (i
= sizeof(unsigned long); --i
>= 0;)
733 pixel
= (pixel
<< 8) | ((unsigned char *) &px
)[i
];
742 if (storePixel(pixel
, pmap
, iptr
))
743 return (XpmNoMemory
);
746 return (XpmColorError
); /* actually a bad image */
751 * scan pixels of a 32-bits Z image data structure
754 #if !defined(WORD64) && !defined(LONG64)
755 static unsigned long byteorderpixel
= MSBFirst
<< 24;
759 GetImagePixels32(image
, width
, height
, pmap
)
773 data
= (unsigned char *) image
->data
;
774 iptr
= pmap
->pixelindex
;
775 depth
= image
->depth
;
776 lbt
= low_bits_table
[depth
];
777 #if !defined(WORD64) && !defined(LONG64)
778 if (*((char *) &byteorderpixel
) == image
->byte_order
) {
779 for (y
= 0; y
< height
; y
++)
780 for (x
= 0; x
< width
; x
++, iptr
++) {
781 addr
= &data
[ZINDEX32(x
, y
, image
)];
782 pixel
= *((unsigned long *) addr
);
785 if (storePixel(pixel
, pmap
, iptr
))
786 return (XpmNoMemory
);
790 if (image
->byte_order
== MSBFirst
)
791 for (y
= 0; y
< height
; y
++)
792 for (x
= 0; x
< width
; x
++, iptr
++) {
793 addr
= &data
[ZINDEX32(x
, y
, image
)];
794 pixel
= ((unsigned long) addr
[0] << 24 |
795 (unsigned long) addr
[1] << 16 |
796 (unsigned long) addr
[2] << 8 |
800 if (storePixel(pixel
, pmap
, iptr
))
801 return (XpmNoMemory
);
804 for (y
= 0; y
< height
; y
++)
805 for (x
= 0; x
< width
; x
++, iptr
++) {
806 addr
= &data
[ZINDEX32(x
, y
, image
)];
808 (unsigned long) addr
[1] << 8 |
809 (unsigned long) addr
[2] << 16 |
810 (unsigned long) addr
[3] << 24);
813 if (storePixel(pixel
, pmap
, iptr
))
814 return (XpmNoMemory
);
820 * scan pixels of a 16-bits Z image data structure
824 GetImagePixels16(image
, width
, height
, pmap
)
838 data
= (unsigned char *) image
->data
;
839 iptr
= pmap
->pixelindex
;
840 depth
= image
->depth
;
841 lbt
= low_bits_table
[depth
];
842 if (image
->byte_order
== MSBFirst
)
843 for (y
= 0; y
< height
; y
++)
844 for (x
= 0; x
< width
; x
++, iptr
++) {
845 addr
= &data
[ZINDEX16(x
, y
, image
)];
846 pixel
= addr
[0] << 8 | addr
[1];
849 if (storePixel(pixel
, pmap
, iptr
))
850 return (XpmNoMemory
);
853 for (y
= 0; y
< height
; y
++)
854 for (x
= 0; x
< width
; x
++, iptr
++) {
855 addr
= &data
[ZINDEX16(x
, y
, image
)];
856 pixel
= addr
[0] | addr
[1] << 8;
859 if (storePixel(pixel
, pmap
, iptr
))
860 return (XpmNoMemory
);
866 * scan pixels of a 8-bits Z image data structure
870 GetImagePixels8(image
, width
, height
, pmap
)
883 data
= (unsigned char *) image
->data
;
884 iptr
= pmap
->pixelindex
;
885 depth
= image
->depth
;
886 lbt
= low_bits_table
[depth
];
887 for (y
= 0; y
< height
; y
++)
888 for (x
= 0; x
< width
; x
++, iptr
++) {
889 pixel
= data
[ZINDEX8(x
, y
, image
)];
892 if (storePixel(pixel
, pmap
, iptr
))
893 return (XpmNoMemory
);
899 * scan pixels of a 1-bit depth Z image data structure
903 GetImagePixels1(image
, width
, height
, pmap
, storeFunc
)
914 int xoff
, yoff
, offset
, bpl
;
917 iptr
= pmap
->pixelindex
;
918 offset
= image
->xoffset
;
919 bpl
= image
->bytes_per_line
;
921 if (image
->bitmap_bit_order
== MSBFirst
)
922 for (y
= 0; y
< height
; y
++)
923 for (x
= 0; x
< width
; x
++, iptr
++) {
925 yoff
= y
* bpl
+ (xoff
>> 3);
927 pixel
= (data
[yoff
] & (0x80 >> xoff
)) ? 1 : 0;
928 if ((*storeFunc
) (pixel
, pmap
, iptr
))
929 return (XpmNoMemory
);
932 for (y
= 0; y
< height
; y
++)
933 for (x
= 0; x
< width
; x
++, iptr
++) {
935 yoff
= y
* bpl
+ (xoff
>> 3);
937 pixel
= (data
[yoff
] & (1 << xoff
)) ? 1 : 0;
938 if ((*storeFunc
) (pixel
, pmap
, iptr
))
939 return (XpmNoMemory
);
946 #define CLEAN_UP(status) \
948 if (pixels) XpmFree (pixels);\
949 if (tmp_img) FreeXImage (tmp_img);\
963 unsigned char *pixels
;
966 pixels
= XpmMalloc ((((width
+15)>>4)<<4)*sizeof (*pixels
));
970 tmp_img
= AllocXImage ((((width
+15)>>4)<<4), 1, image
->rp
->BitMap
->Depth
);
972 CLEAN_UP (XpmNoMemory
)
974 iptr
= pmap
->pixelindex
;
975 for (y
= 0; y
< height
; ++y
)
977 ReadPixelLine8 (image
->rp
, 0, y
, width
, pixels
, tmp_img
->rp
);
978 for (x
= 0; x
< width
; ++x
, ++iptr
)
980 if ((*storeFunc
) (pixels
[x
], pmap
, iptr
))
981 CLEAN_UP (XpmNoMemory
)
985 CLEAN_UP (XpmSuccess
)
991 #else /* ndef FOR_MSW */
994 /* Visual Age cannot deal with old, non-ansi, code */
1000 , unsigned int height
1002 , int (*storeFunc
) ()
1006 MSWGetImagePixels(display
, image
, width
, height
, pmap
, storeFunc
)
1010 unsigned int height
;
1012 int (*storeFunc
) ();
1021 DEVOPENSTRUC dop
= {NULL
, "DISPLAY", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
};
1022 SIZEL sizl
= {0, 0};
1026 iptr
= pmap
->pixelindex
;
1029 hps
= GpiCreatePS(hab
, *display
, &sizl
, GPIA_ASSOC
| PU_PELS
);
1030 GpiSetBitmap(hps
, image
->bitmap
);
1032 SelectObject(*display
, image
->bitmap
);
1035 for (y
= 0; y
< height
; y
++) {
1036 for (x
= 0; x
< width
; x
++, iptr
++) {
1040 pixel
= GpiQueryPel(hps
, &point
);
1042 pixel
= GetPixel(*display
, x
, y
);
1046 /* calling convention all messed up under OS/2 */
1047 if ((*storeFunc
) (pixel
, pmap
, iptr
))
1048 return (XpmNoMemory
);
1052 return (XpmSuccess
);
1060 XpmCreateXpmImageFromPixmap(display
, pixmap
, shapemask
,
1061 xpmimage
, attributes
)
1066 XpmAttributes
*attributes
;
1068 XImage
*ximage
= NULL
;
1069 XImage
*shapeimage
= NULL
;
1070 unsigned int width
= 0;
1071 unsigned int height
= 0;
1075 if (attributes
&& attributes
->valuemask
& XpmSize
) {
1076 width
= attributes
->width
;
1077 height
= attributes
->height
;
1079 /* get the ximages */
1081 xpmCreateImageFromPixmap(display
, pixmap
, &ximage
, &width
, &height
);
1083 xpmCreateImageFromPixmap(display
, shapemask
, &shapeimage
,
1086 /* create the related XpmImage */
1087 ErrorStatus
= XpmCreateXpmImageFromImage(display
, ximage
, shapeimage
,
1088 xpmimage
, attributes
);
1090 /* destroy the ximages */
1092 XDestroyImage(ximage
);
1094 XDestroyImage(shapeimage
);
1096 return (ErrorStatus
);
1099 # endif/* not AMIGA */
1100 #endif /* ndef FOR_MSW */