]>
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 storePixel(pixel
, pmap
, index_return
)
118 unsigned int *index_return
;
122 unsigned int ncolors
;
124 if (*index_return
) { /* this is a transparent pixel! */
128 ncolors
= pmap
->ncolors
;
129 p
= pmap
->pixels
+ pmap
->mask_pixel
;
130 for (i
= pmap
->mask_pixel
; i
< ncolors
; i
++, p
++)
134 if (ncolors
>= pmap
->size
) {
136 p
= (Pixel
*) XpmRealloc(pmap
->pixels
, sizeof(Pixel
) * pmap
->size
);
142 (pmap
->pixels
)[ncolors
] = pixel
;
150 storeMaskPixel(pixel
, pmap
, index_return
)
153 unsigned int *index_return
;
156 if (!pmap
->ncolors
) {
158 (pmap
->pixels
)[0] = 0;
159 pmap
->mask_pixel
= 1;
167 /* function call in case of error */
169 #define RETURN(status) \
171 ErrorStatus = status; \
176 * This function scans the given image and stores the found informations in
177 * the given XpmImage structure.
180 XpmCreateXpmImageFromImage(display
, image
, shapeimage
,
181 xpmimage
, attributes
)
186 XpmAttributes
*attributes
;
188 /* variables stored in the XpmAttributes structure */
191 /* variables to return */
193 XpmColor
*colorTable
= NULL
;
196 /* calculation variables */
197 unsigned int width
= 0;
198 unsigned int height
= 0;
199 unsigned int cppm
; /* minimum chars per pixel */
202 /* initialize pmap */
204 pmap
.pixelindex
= NULL
;
205 pmap
.size
= 256; /* should be enough most of the time */
213 width
= image
->width
;
214 height
= image
->height
;
215 } else if (shapeimage
) {
216 width
= shapeimage
->width
;
217 height
= shapeimage
->height
;
221 * retrieve information from the XpmAttributes
223 if (attributes
&& (attributes
->valuemask
& XpmCharsPerPixel
224 /* 3.2 backward compatibility code */
225 || attributes
->valuemask
& XpmInfos
))
227 cpp
= attributes
->cpp
;
232 (unsigned int *) XpmCalloc(width
* height
, sizeof(unsigned int));
233 if (!pmap
.pixelindex
)
236 pmap
.pixels
= (Pixel
*) XpmMalloc(sizeof(Pixel
) * pmap
.size
);
241 * scan shape mask if any
246 ErrorStatus
= GetImagePixels1(shapeimage
, width
, height
, &pmap
,
249 ErrorStatus
= AGetImagePixels(shapeimage
, width
, height
, &pmap
,
253 ErrorStatus
= MSWGetImagePixels(display
, shapeimage
, width
, height
,
254 &pmap
, storeMaskPixel
);
256 if (ErrorStatus
!= XpmSuccess
)
261 * scan the image data
263 * In case depth is 1 or bits_per_pixel is 4, 6, 8, 24 or 32 use optimized
264 * functions, otherwise use slower but sure general one.
271 if (((image
->bits_per_pixel
| image
->depth
) == 1) &&
272 (image
->byte_order
== image
->bitmap_bit_order
))
273 ErrorStatus
= GetImagePixels1(image
, width
, height
, &pmap
,
275 else if (image
->format
== ZPixmap
) {
276 if (image
->bits_per_pixel
== 8)
277 ErrorStatus
= GetImagePixels8(image
, width
, height
, &pmap
);
278 else if (image
->bits_per_pixel
== 16)
279 ErrorStatus
= GetImagePixels16(image
, width
, height
, &pmap
);
280 else if (image
->bits_per_pixel
== 32)
281 ErrorStatus
= GetImagePixels32(image
, width
, height
, &pmap
);
283 ErrorStatus
= GetImagePixels(image
, width
, height
, &pmap
);
285 ErrorStatus
= AGetImagePixels(image
, width
, height
, &pmap
,
289 ErrorStatus
= MSWGetImagePixels(display
, image
, width
, height
, &pmap
,
292 if (ErrorStatus
!= XpmSuccess
)
297 * get rgb values and a string of char, and possibly a name for each
301 colorTable
= (XpmColor
*) XpmCalloc(pmap
.ncolors
, sizeof(XpmColor
));
305 /* compute the minimal cpp */
306 for (cppm
= 1, c
= MAXPRINTABLE
; pmap
.ncolors
> c
; cppm
++)
311 if (pmap
.mask_pixel
) {
312 ErrorStatus
= ScanTransparentColor(colorTable
, cpp
, attributes
);
313 if (ErrorStatus
!= XpmSuccess
)
317 ErrorStatus
= ScanOtherColors(display
, colorTable
, pmap
.ncolors
,
318 pmap
.pixels
, pmap
.mask_pixel
, cpp
,
320 if (ErrorStatus
!= XpmSuccess
)
324 * store found informations in the XpmImage structure
326 xpmimage
->width
= width
;
327 xpmimage
->height
= height
;
329 xpmimage
->ncolors
= pmap
.ncolors
;
330 xpmimage
->colorTable
= colorTable
;
331 xpmimage
->data
= pmap
.pixelindex
;
333 XpmFree(pmap
.pixels
);
336 /* exit point in case of error, free only locally allocated variables */
339 XpmFree(pmap
.pixelindex
);
341 XpmFree(pmap
.pixels
);
343 xpmFreeColorTable(colorTable
, pmap
.ncolors
);
345 return (ErrorStatus
);
349 ScanTransparentColor(color
, cpp
, attributes
)
352 XpmAttributes
*attributes
;
355 unsigned int a
, b
, c
;
357 /* first get a character string */
359 if (!(s
= color
->string
= (char *) XpmMalloc(cpp
+ 1)))
360 return (XpmNoMemory
);
361 *s
++ = printable
[c
= a
% MAXPRINTABLE
];
362 for (b
= 1; b
< cpp
; b
++, s
++)
363 *s
= printable
[c
= ((a
- c
) / MAXPRINTABLE
) % MAXPRINTABLE
];
366 /* then retreive related info from the attributes if any */
367 if (attributes
&& (attributes
->valuemask
& XpmColorTable
368 /* 3.2 backward compatibility code */
369 || attributes
->valuemask
& XpmInfos
)
371 && attributes
->mask_pixel
!= XpmUndefPixel
) {
374 char **defaults
= (char **) color
;
375 char **mask_defaults
;
377 /* 3.2 backward compatibility code */
378 if (attributes
->valuemask
& XpmColorTable
)
380 mask_defaults
= (char **) (
381 attributes
->colorTable
+ attributes
->mask_pixel
);
382 /* 3.2 backward compatibility code */
384 mask_defaults
= (char **)
385 ((XpmColor
**) attributes
->colorTable
)[attributes
->mask_pixel
];
387 for (key
= 1; key
<= NKEYS
; key
++) {
388 if (s
= mask_defaults
[key
]) {
389 defaults
[key
] = (char *) xpmstrdup(s
);
391 return (XpmNoMemory
);
395 color
->c_color
= (char *) xpmstrdup(TRANSPARENT_COLOR
);
397 return (XpmNoMemory
);
403 ScanOtherColors(display
, colors
, ncolors
, pixels
, mask
, cpp
, attributes
)
410 XpmAttributes
*attributes
;
412 /* variables stored in the XpmAttributes structure */
417 xpmRgbName rgbn
[MAX_RGBNAMES
];
419 xpmRgbName
*rgbn
= NULL
;
422 unsigned int i
, j
, c
, i2
;
424 XColor
*xcolors
= NULL
, *xcolor
;
426 XpmColor
*colorTable
, **oldColorTable
= NULL
;
427 unsigned int ancolors
= 0;
429 unsigned int mask_pixel
;
432 /* retrieve information from the XpmAttributes */
433 if (attributes
&& (attributes
->valuemask
& XpmColormap
))
434 colormap
= attributes
->colormap
;
436 colormap
= XDefaultColormap(display
, XDefaultScreen(display
));
437 if (attributes
&& (attributes
->valuemask
& XpmRgbFilename
))
438 rgb_fname
= attributes
->rgb_fname
;
442 /* start from the right element */
449 /* first get character strings and rgb values */
450 xcolors
= (XColor
*) XpmMalloc(sizeof(XColor
) * ncolors
);
452 return (XpmNoMemory
);
454 for (i
= 0, i2
= mask
, color
= colors
, xcolor
= xcolors
;
455 i
< ncolors
; i
++, i2
++, color
++, xcolor
++, pixels
++) {
457 if (!(s
= color
->string
= (char *) XpmMalloc(cpp
+ 1))) {
459 return (XpmNoMemory
);
461 *s
++ = printable
[c
= i2
% MAXPRINTABLE
];
462 for (j
= 1; j
< cpp
; j
++, s
++)
463 *s
= printable
[c
= ((i2
- c
) / MAXPRINTABLE
) % MAXPRINTABLE
];
466 xcolor
->pixel
= *pixels
;
468 XQueryColors(display
, colormap
, xcolors
, ncolors
);
471 /* read the rgb file if any was specified */
473 rgbn_max
= xpmReadRgbNames(attributes
->rgb_fname
, rgbn
);
475 /* FOR_MSW: rgb names and values are hardcoded in rgbtab.h */
476 rgbn_max
= xpmReadRgbNames(NULL
, NULL
);
479 if (attributes
&& attributes
->valuemask
& XpmColorTable
) {
480 colorTable
= attributes
->colorTable
;
481 ancolors
= attributes
->ncolors
;
482 apixels
= attributes
->pixels
;
483 mask_pixel
= attributes
->mask_pixel
;
485 /* 3.2 backward compatibility code */
486 else if (attributes
&& attributes
->valuemask
& XpmInfos
) {
487 oldColorTable
= (XpmColor
**) attributes
->colorTable
;
488 ancolors
= attributes
->ncolors
;
489 apixels
= attributes
->pixels
;
490 mask_pixel
= attributes
->mask_pixel
;
494 for (i
= 0, color
= colors
, xcolor
= xcolors
; i
< ncolors
;
495 i
++, color
++, xcolor
++) {
497 /* look for related info from the attributes if any */
500 unsigned int offset
= 0;
502 for (j
= 0; j
< ancolors
; j
++) {
503 if (j
== mask_pixel
) {
507 if (apixels
[j
- offset
] == xcolor
->pixel
)
512 char **defaults
= (char **) color
;
515 /* 3.2 backward compatibility code */
517 adefaults
= (char **) oldColorTable
[j
];
520 adefaults
= (char **) (colorTable
+ j
);
523 for (key
= 1; key
<= NKEYS
; key
++) {
524 if (s
= adefaults
[key
])
525 defaults
[key
] = (char *) xpmstrdup(s
);
530 /* if nothing found look for a color name */
533 colorname
= xpmGetRgbName(rgbn
, rgbn_max
, xcolor
->red
,
534 xcolor
->green
, xcolor
->blue
);
536 color
->c_color
= (char *) xpmstrdup(colorname
);
538 /* at last store the rgb value */
541 sprintf(buf
, "#%04X%04X%04X",
542 xcolor
->red
, xcolor
->green
, xcolor
->blue
);
544 sprintf(buf
, "#%02x%02x%02x",
545 xcolor
->red
, xcolor
->green
, xcolor
->blue
);
547 color
->c_color
= (char *) xpmstrdup(buf
);
549 if (!color
->c_color
) {
551 xpmFreeRgbNames(rgbn
, rgbn_max
);
552 return (XpmNoMemory
);
558 xpmFreeRgbNames(rgbn
, rgbn_max
);
565 * The functions below are written from X11R5 MIT's code (XImUtil.c)
567 * The idea is to have faster functions than the standard XGetPixel function
568 * to scan the image data. Indeed we can speed up things by suppressing tests
569 * performed for each pixel. We do exactly the same tests but at the image
573 static unsigned long Const low_bits_table
[] = {
574 0x00000000, 0x00000001, 0x00000003, 0x00000007,
575 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
576 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
577 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
578 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
579 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
580 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
581 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
586 * Default method to scan pixels of an image data structure.
587 * The algorithm used is:
589 * copy the source bitmap_unit or Zpixel into temp
590 * normalize temp if needed
591 * extract the pixel bits into return value
596 GetImagePixels(image
, width
, height
, pmap
)
607 int bits
, depth
, ibu
, ibpp
, offset
;
612 iptr
= pmap
->pixelindex
;
613 depth
= image
->depth
;
614 lbt
= low_bits_table
[depth
];
615 ibpp
= image
->bits_per_pixel
;
616 offset
= image
->xoffset
;
618 if ((image
->bits_per_pixel
| image
->depth
) == 1) {
619 ibu
= image
->bitmap_unit
;
620 for (y
= 0; y
< height
; y
++)
621 for (x
= 0; x
< width
; x
++, iptr
++) {
622 src
= &data
[XYINDEX(x
, y
, image
)];
623 dst
= (char *) &pixel
;
625 for (i
= ibu
>> 3; --i
>= 0;)
627 XYNORMALIZE(&pixel
, image
);
628 bits
= (x
+ offset
) % ibu
;
629 pixel
= ((((char *) &pixel
)[bits
>> 3]) >> (bits
& 7)) & 1;
632 if (storePixel(pixel
, pmap
, iptr
))
633 return (XpmNoMemory
);
635 } else if (image
->format
== XYPixmap
) {
638 ibu
= image
->bitmap_unit
;
640 bpl
= image
->bytes_per_line
;
641 for (y
= 0; y
< height
; y
++)
642 for (x
= 0; x
< width
; x
++, iptr
++) {
645 for (i
= depth
; --i
>= 0;) {
646 src
= &data
[XYINDEX(x
, y
, image
) + plane
];
649 for (j
= nbytes
; --j
>= 0;)
651 XYNORMALIZE(&px
, image
);
652 bits
= (x
+ offset
) % ibu
;
653 pixel
= (pixel
<< 1) |
654 (((((char *) &px
)[bits
>> 3]) >> (bits
& 7)) & 1);
655 plane
= plane
+ (bpl
* height
);
659 if (storePixel(pixel
, pmap
, iptr
))
660 return (XpmNoMemory
);
662 } else if (image
->format
== ZPixmap
) {
663 for (y
= 0; y
< height
; y
++)
664 for (x
= 0; x
< width
; x
++, iptr
++) {
665 src
= &data
[ZINDEX(x
, y
, image
)];
668 for (i
= (ibpp
+ 7) >> 3; --i
>= 0;)
670 ZNORMALIZE(&px
, image
);
672 for (i
= sizeof(unsigned long); --i
>= 0;)
673 pixel
= (pixel
<< 8) | ((unsigned char *) &px
)[i
];
682 if (storePixel(pixel
, pmap
, iptr
))
683 return (XpmNoMemory
);
686 return (XpmColorError
); /* actually a bad image */
691 * scan pixels of a 32-bits Z image data structure
694 #if !defined(WORD64) && !defined(LONG64)
695 static unsigned long byteorderpixel
= MSBFirst
<< 24;
699 GetImagePixels32(image
, width
, height
, pmap
)
713 data
= (unsigned char *) image
->data
;
714 iptr
= pmap
->pixelindex
;
715 depth
= image
->depth
;
716 lbt
= low_bits_table
[depth
];
717 #if !defined(WORD64) && !defined(LONG64)
718 if (*((char *) &byteorderpixel
) == image
->byte_order
) {
719 for (y
= 0; y
< height
; y
++)
720 for (x
= 0; x
< width
; x
++, iptr
++) {
721 addr
= &data
[ZINDEX32(x
, y
, image
)];
722 pixel
= *((unsigned long *) addr
);
725 if (storePixel(pixel
, pmap
, iptr
))
726 return (XpmNoMemory
);
730 if (image
->byte_order
== MSBFirst
)
731 for (y
= 0; y
< height
; y
++)
732 for (x
= 0; x
< width
; x
++, iptr
++) {
733 addr
= &data
[ZINDEX32(x
, y
, image
)];
734 pixel
= ((unsigned long) addr
[0] << 24 |
735 (unsigned long) addr
[1] << 16 |
736 (unsigned long) addr
[2] << 8 |
740 if (storePixel(pixel
, pmap
, iptr
))
741 return (XpmNoMemory
);
744 for (y
= 0; y
< height
; y
++)
745 for (x
= 0; x
< width
; x
++, iptr
++) {
746 addr
= &data
[ZINDEX32(x
, y
, image
)];
748 (unsigned long) addr
[1] << 8 |
749 (unsigned long) addr
[2] << 16 |
750 (unsigned long) addr
[3] << 24);
753 if (storePixel(pixel
, pmap
, iptr
))
754 return (XpmNoMemory
);
760 * scan pixels of a 16-bits Z image data structure
764 GetImagePixels16(image
, width
, height
, pmap
)
778 data
= (unsigned char *) image
->data
;
779 iptr
= pmap
->pixelindex
;
780 depth
= image
->depth
;
781 lbt
= low_bits_table
[depth
];
782 if (image
->byte_order
== MSBFirst
)
783 for (y
= 0; y
< height
; y
++)
784 for (x
= 0; x
< width
; x
++, iptr
++) {
785 addr
= &data
[ZINDEX16(x
, y
, image
)];
786 pixel
= addr
[0] << 8 | addr
[1];
789 if (storePixel(pixel
, pmap
, iptr
))
790 return (XpmNoMemory
);
793 for (y
= 0; y
< height
; y
++)
794 for (x
= 0; x
< width
; x
++, iptr
++) {
795 addr
= &data
[ZINDEX16(x
, y
, image
)];
796 pixel
= addr
[0] | addr
[1] << 8;
799 if (storePixel(pixel
, pmap
, iptr
))
800 return (XpmNoMemory
);
806 * scan pixels of a 8-bits Z image data structure
810 GetImagePixels8(image
, width
, height
, pmap
)
823 data
= (unsigned char *) image
->data
;
824 iptr
= pmap
->pixelindex
;
825 depth
= image
->depth
;
826 lbt
= low_bits_table
[depth
];
827 for (y
= 0; y
< height
; y
++)
828 for (x
= 0; x
< width
; x
++, iptr
++) {
829 pixel
= data
[ZINDEX8(x
, y
, image
)];
832 if (storePixel(pixel
, pmap
, iptr
))
833 return (XpmNoMemory
);
839 * scan pixels of a 1-bit depth Z image data structure
843 GetImagePixels1(image
, width
, height
, pmap
, storeFunc
)
854 int xoff
, yoff
, offset
, bpl
;
857 iptr
= pmap
->pixelindex
;
858 offset
= image
->xoffset
;
859 bpl
= image
->bytes_per_line
;
861 if (image
->bitmap_bit_order
== MSBFirst
)
862 for (y
= 0; y
< height
; y
++)
863 for (x
= 0; x
< width
; x
++, iptr
++) {
865 yoff
= y
* bpl
+ (xoff
>> 3);
867 pixel
= (data
[yoff
] & (0x80 >> xoff
)) ? 1 : 0;
868 if ((*storeFunc
) (pixel
, pmap
, iptr
))
869 return (XpmNoMemory
);
872 for (y
= 0; y
< height
; y
++)
873 for (x
= 0; x
< width
; x
++, iptr
++) {
875 yoff
= y
* bpl
+ (xoff
>> 3);
877 pixel
= (data
[yoff
] & (1 << xoff
)) ? 1 : 0;
878 if ((*storeFunc
) (pixel
, pmap
, iptr
))
879 return (XpmNoMemory
);
886 #define CLEAN_UP(status) \
888 if (pixels) XpmFree (pixels);\
889 if (tmp_img) FreeXImage (tmp_img);\
903 unsigned char *pixels
;
906 pixels
= XpmMalloc ((((width
+15)>>4)<<4)*sizeof (*pixels
));
910 tmp_img
= AllocXImage ((((width
+15)>>4)<<4), 1, image
->rp
->BitMap
->Depth
);
912 CLEAN_UP (XpmNoMemory
)
914 iptr
= pmap
->pixelindex
;
915 for (y
= 0; y
< height
; ++y
)
917 ReadPixelLine8 (image
->rp
, 0, y
, width
, pixels
, tmp_img
->rp
);
918 for (x
= 0; x
< width
; ++x
, ++iptr
)
920 if ((*storeFunc
) (pixels
[x
], pmap
, iptr
))
921 CLEAN_UP (XpmNoMemory
)
925 CLEAN_UP (XpmSuccess
)
931 #else /* ndef FOR_MSW */
933 MSWGetImagePixels(display
, image
, width
, height
, pmap
, storeFunc
)
945 iptr
= pmap
->pixelindex
;
947 SelectObject(*display
, image
->bitmap
);
948 for (y
= 0; y
< height
; y
++) {
949 for (x
= 0; x
< width
; x
++, iptr
++) {
950 pixel
= GetPixel(*display
, x
, y
);
951 if ((*storeFunc
) (pixel
, pmap
, iptr
))
952 return (XpmNoMemory
);
963 XpmCreateXpmImageFromPixmap(display
, pixmap
, shapemask
,
964 xpmimage
, attributes
)
969 XpmAttributes
*attributes
;
971 XImage
*ximage
= NULL
;
972 XImage
*shapeimage
= NULL
;
973 unsigned int width
= 0;
974 unsigned int height
= 0;
978 if (attributes
&& attributes
->valuemask
& XpmSize
) {
979 width
= attributes
->width
;
980 height
= attributes
->height
;
982 /* get the ximages */
984 xpmCreateImageFromPixmap(display
, pixmap
, &ximage
, &width
, &height
);
986 xpmCreateImageFromPixmap(display
, shapemask
, &shapeimage
,
989 /* create the related XpmImage */
990 ErrorStatus
= XpmCreateXpmImageFromImage(display
, ximage
, shapeimage
,
991 xpmimage
, attributes
);
993 /* destroy the ximages */
995 XDestroyImage(ximage
);
997 XDestroyImage(shapeimage
);
999 return (ErrorStatus
);
1002 # endif/* not AMIGA */
1003 #endif /* ndef FOR_MSW */