]>
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
,
320 ErrorStatus
= MSWGetImagePixels(display
, image
, width
, height
, &pmap
,
325 if (ErrorStatus
!= XpmSuccess
)
330 * get rgb values and a string of char, and possibly a name for each
334 colorTable
= (XpmColor
*) XpmCalloc(pmap
.ncolors
, sizeof(XpmColor
));
338 /* compute the minimal cpp */
339 for (cppm
= 1, c
= MAXPRINTABLE
; pmap
.ncolors
> c
; cppm
++)
344 if (pmap
.mask_pixel
) {
345 ErrorStatus
= ScanTransparentColor(colorTable
, cpp
, attributes
);
346 if (ErrorStatus
!= XpmSuccess
)
350 ErrorStatus
= ScanOtherColors(display
, colorTable
, pmap
.ncolors
,
351 pmap
.pixels
, pmap
.mask_pixel
, cpp
,
353 if (ErrorStatus
!= XpmSuccess
)
357 * store found informations in the XpmImage structure
359 xpmimage
->width
= width
;
360 xpmimage
->height
= height
;
362 xpmimage
->ncolors
= pmap
.ncolors
;
363 xpmimage
->colorTable
= colorTable
;
364 xpmimage
->data
= pmap
.pixelindex
;
366 XpmFree(pmap
.pixels
);
369 /* exit point in case of error, free only locally allocated variables */
372 XpmFree(pmap
.pixelindex
);
374 XpmFree(pmap
.pixels
);
376 xpmFreeColorTable(colorTable
, pmap
.ncolors
);
378 return (ErrorStatus
);
382 /* Visual Age cannot deal with old, non-ansi, code */
383 static int ScanTransparentColor(XpmColor
* color
, unsigned int cpp
, XpmAttributes
* attributes
)
386 ScanTransparentColor(color
, cpp
, attributes
)
389 XpmAttributes
*attributes
;
393 unsigned int a
, b
, c
;
395 /* first get a character string */
397 if (!(s
= color
->string
= (char *) XpmMalloc(cpp
+ 1)))
398 return (XpmNoMemory
);
399 *s
++ = printable
[c
= a
% MAXPRINTABLE
];
400 for (b
= 1; b
< cpp
; b
++, s
++)
401 *s
= printable
[c
= ((a
- c
) / MAXPRINTABLE
) % MAXPRINTABLE
];
404 /* then retreive related info from the attributes if any */
405 if (attributes
&& (attributes
->valuemask
& XpmColorTable
406 /* 3.2 backward compatibility code */
407 || attributes
->valuemask
& XpmInfos
)
409 && attributes
->mask_pixel
!= XpmUndefPixel
) {
412 char **defaults
= (char **) color
;
413 char **mask_defaults
;
415 /* 3.2 backward compatibility code */
416 if (attributes
->valuemask
& XpmColorTable
)
418 mask_defaults
= (char **) (
419 attributes
->colorTable
+ attributes
->mask_pixel
);
420 /* 3.2 backward compatibility code */
422 mask_defaults
= (char **)
423 ((XpmColor
**) attributes
->colorTable
)[attributes
->mask_pixel
];
425 for (key
= 1; key
<= NKEYS
; key
++) {
426 if (s
= mask_defaults
[key
]) {
427 defaults
[key
] = (char *) xpmstrdup(s
);
429 return (XpmNoMemory
);
433 color
->c_color
= (char *) xpmstrdup(TRANSPARENT_COLOR
);
435 return (XpmNoMemory
);
441 /* Visual Age cannot deal with old, non-ansi, code */
442 static int ScanOtherColors(
449 , XpmAttributes
* attributes
453 ScanOtherColors(display
, colors
, ncolors
, pixels
, mask
, cpp
, attributes
)
460 XpmAttributes
*attributes
;
463 /* variables stored in the XpmAttributes structure */
468 xpmRgbName rgbn
[MAX_RGBNAMES
];
470 xpmRgbName
*rgbn
= NULL
;
473 unsigned int i
, j
, c
, i2
;
475 XColor
*xcolors
= NULL
, *xcolor
;
477 XpmColor
*colorTable
, **oldColorTable
= NULL
;
478 unsigned int ancolors
= 0;
480 unsigned int mask_pixel
;
483 /* retrieve information from the XpmAttributes */
484 if (attributes
&& (attributes
->valuemask
& XpmColormap
))
485 colormap
= attributes
->colormap
;
487 colormap
= XDefaultColormap(display
, XDefaultScreen(display
));
488 if (attributes
&& (attributes
->valuemask
& XpmRgbFilename
))
489 rgb_fname
= attributes
->rgb_fname
;
493 /* start from the right element */
500 /* first get character strings and rgb values */
501 xcolors
= (XColor
*) XpmMalloc(sizeof(XColor
) * ncolors
);
503 return (XpmNoMemory
);
505 for (i
= 0, i2
= mask
, color
= colors
, xcolor
= xcolors
;
506 i
< ncolors
; i
++, i2
++, color
++, xcolor
++, pixels
++) {
508 if (!(s
= color
->string
= (char *) XpmMalloc(cpp
+ 1))) {
510 return (XpmNoMemory
);
512 *s
++ = printable
[c
= i2
% MAXPRINTABLE
];
513 for (j
= 1; j
< cpp
; j
++, s
++)
514 *s
= printable
[c
= ((i2
- c
) / MAXPRINTABLE
) % MAXPRINTABLE
];
517 xcolor
->pixel
= *pixels
;
520 XQueryColors(display
, &colormap
, xcolors
, ncolors
);
522 XQueryColors(display
, colormap
, xcolors
, ncolors
);
526 /* read the rgb file if any was specified */
528 rgbn_max
= xpmReadRgbNames(attributes
->rgb_fname
, rgbn
);
530 /* FOR_MSW: rgb names and values are hardcoded in rgbtab.h */
531 rgbn_max
= xpmReadRgbNames(NULL
, NULL
);
534 if (attributes
&& attributes
->valuemask
& XpmColorTable
) {
535 colorTable
= attributes
->colorTable
;
536 ancolors
= attributes
->ncolors
;
537 apixels
= attributes
->pixels
;
538 mask_pixel
= attributes
->mask_pixel
;
540 /* 3.2 backward compatibility code */
541 else if (attributes
&& attributes
->valuemask
& XpmInfos
) {
542 oldColorTable
= (XpmColor
**) attributes
->colorTable
;
543 ancolors
= attributes
->ncolors
;
544 apixels
= attributes
->pixels
;
545 mask_pixel
= attributes
->mask_pixel
;
549 for (i
= 0, color
= colors
, xcolor
= xcolors
; i
< ncolors
;
550 i
++, color
++, xcolor
++) {
552 /* look for related info from the attributes if any */
555 unsigned int offset
= 0;
557 for (j
= 0; j
< ancolors
; j
++) {
558 if (j
== mask_pixel
) {
562 if (apixels
[j
- offset
] == xcolor
->pixel
)
567 char **defaults
= (char **) color
;
570 /* 3.2 backward compatibility code */
572 adefaults
= (char **) oldColorTable
[j
];
575 adefaults
= (char **) (colorTable
+ j
);
578 for (key
= 1; key
<= NKEYS
; key
++) {
579 if (s
= adefaults
[key
])
580 defaults
[key
] = (char *) xpmstrdup(s
);
585 /* if nothing found look for a color name */
588 colorname
= xpmGetRgbName(rgbn
, rgbn_max
, xcolor
->red
,
589 xcolor
->green
, xcolor
->blue
);
591 color
->c_color
= (char *) xpmstrdup(colorname
);
593 /* at last store the rgb value */
596 sprintf(buf
, "#%04X%04X%04X",
597 xcolor
->red
, xcolor
->green
, xcolor
->blue
);
599 sprintf(buf
, "#%02x%02x%02x",
600 xcolor
->red
, xcolor
->green
, xcolor
->blue
);
602 color
->c_color
= (char *) xpmstrdup(buf
);
604 if (!color
->c_color
) {
606 xpmFreeRgbNames(rgbn
, rgbn_max
);
607 return (XpmNoMemory
);
613 xpmFreeRgbNames(rgbn
, rgbn_max
);
620 * The functions below are written from X11R5 MIT's code (XImUtil.c)
622 * The idea is to have faster functions than the standard XGetPixel function
623 * to scan the image data. Indeed we can speed up things by suppressing tests
624 * performed for each pixel. We do exactly the same tests but at the image
628 static unsigned long Const low_bits_table
[] = {
629 0x00000000, 0x00000001, 0x00000003, 0x00000007,
630 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
631 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
632 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
633 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
634 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
635 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
636 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
641 * Default method to scan pixels of an image data structure.
642 * The algorithm used is:
644 * copy the source bitmap_unit or Zpixel into temp
645 * normalize temp if needed
646 * extract the pixel bits into return value
651 GetImagePixels(image
, width
, height
, pmap
)
662 int bits
, depth
, ibu
, ibpp
, offset
;
667 iptr
= pmap
->pixelindex
;
668 depth
= image
->depth
;
669 lbt
= low_bits_table
[depth
];
670 ibpp
= image
->bits_per_pixel
;
671 offset
= image
->xoffset
;
673 if ((image
->bits_per_pixel
| image
->depth
) == 1) {
674 ibu
= image
->bitmap_unit
;
675 for (y
= 0; y
< height
; y
++)
676 for (x
= 0; x
< width
; x
++, iptr
++) {
677 src
= &data
[XYINDEX(x
, y
, image
)];
678 dst
= (char *) &pixel
;
680 for (i
= ibu
>> 3; --i
>= 0;)
682 XYNORMALIZE(&pixel
, image
);
683 bits
= (x
+ offset
) % ibu
;
684 pixel
= ((((char *) &pixel
)[bits
>> 3]) >> (bits
& 7)) & 1;
687 if (storePixel(pixel
, pmap
, iptr
))
688 return (XpmNoMemory
);
690 } else if (image
->format
== XYPixmap
) {
693 ibu
= image
->bitmap_unit
;
695 bpl
= image
->bytes_per_line
;
696 for (y
= 0; y
< height
; y
++)
697 for (x
= 0; x
< width
; x
++, iptr
++) {
700 for (i
= depth
; --i
>= 0;) {
701 src
= &data
[XYINDEX(x
, y
, image
) + plane
];
704 for (j
= nbytes
; --j
>= 0;)
706 XYNORMALIZE(&px
, image
);
707 bits
= (x
+ offset
) % ibu
;
708 pixel
= (pixel
<< 1) |
709 (((((char *) &px
)[bits
>> 3]) >> (bits
& 7)) & 1);
710 plane
= plane
+ (bpl
* height
);
714 if (storePixel(pixel
, pmap
, iptr
))
715 return (XpmNoMemory
);
717 } else if (image
->format
== ZPixmap
) {
718 for (y
= 0; y
< height
; y
++)
719 for (x
= 0; x
< width
; x
++, iptr
++) {
720 src
= &data
[ZINDEX(x
, y
, image
)];
723 for (i
= (ibpp
+ 7) >> 3; --i
>= 0;)
725 ZNORMALIZE(&px
, image
);
727 for (i
= sizeof(unsigned long); --i
>= 0;)
728 pixel
= (pixel
<< 8) | ((unsigned char *) &px
)[i
];
737 if (storePixel(pixel
, pmap
, iptr
))
738 return (XpmNoMemory
);
741 return (XpmColorError
); /* actually a bad image */
746 * scan pixels of a 32-bits Z image data structure
749 #if !defined(WORD64) && !defined(LONG64)
750 static unsigned long byteorderpixel
= MSBFirst
<< 24;
754 GetImagePixels32(image
, width
, height
, pmap
)
768 data
= (unsigned char *) image
->data
;
769 iptr
= pmap
->pixelindex
;
770 depth
= image
->depth
;
771 lbt
= low_bits_table
[depth
];
772 #if !defined(WORD64) && !defined(LONG64)
773 if (*((char *) &byteorderpixel
) == image
->byte_order
) {
774 for (y
= 0; y
< height
; y
++)
775 for (x
= 0; x
< width
; x
++, iptr
++) {
776 addr
= &data
[ZINDEX32(x
, y
, image
)];
777 pixel
= *((unsigned long *) addr
);
780 if (storePixel(pixel
, pmap
, iptr
))
781 return (XpmNoMemory
);
785 if (image
->byte_order
== MSBFirst
)
786 for (y
= 0; y
< height
; y
++)
787 for (x
= 0; x
< width
; x
++, iptr
++) {
788 addr
= &data
[ZINDEX32(x
, y
, image
)];
789 pixel
= ((unsigned long) addr
[0] << 24 |
790 (unsigned long) addr
[1] << 16 |
791 (unsigned long) addr
[2] << 8 |
795 if (storePixel(pixel
, pmap
, iptr
))
796 return (XpmNoMemory
);
799 for (y
= 0; y
< height
; y
++)
800 for (x
= 0; x
< width
; x
++, iptr
++) {
801 addr
= &data
[ZINDEX32(x
, y
, image
)];
803 (unsigned long) addr
[1] << 8 |
804 (unsigned long) addr
[2] << 16 |
805 (unsigned long) addr
[3] << 24);
808 if (storePixel(pixel
, pmap
, iptr
))
809 return (XpmNoMemory
);
815 * scan pixels of a 16-bits Z image data structure
819 GetImagePixels16(image
, width
, height
, pmap
)
833 data
= (unsigned char *) image
->data
;
834 iptr
= pmap
->pixelindex
;
835 depth
= image
->depth
;
836 lbt
= low_bits_table
[depth
];
837 if (image
->byte_order
== MSBFirst
)
838 for (y
= 0; y
< height
; y
++)
839 for (x
= 0; x
< width
; x
++, iptr
++) {
840 addr
= &data
[ZINDEX16(x
, y
, image
)];
841 pixel
= addr
[0] << 8 | addr
[1];
844 if (storePixel(pixel
, pmap
, iptr
))
845 return (XpmNoMemory
);
848 for (y
= 0; y
< height
; y
++)
849 for (x
= 0; x
< width
; x
++, iptr
++) {
850 addr
= &data
[ZINDEX16(x
, y
, image
)];
851 pixel
= addr
[0] | addr
[1] << 8;
854 if (storePixel(pixel
, pmap
, iptr
))
855 return (XpmNoMemory
);
861 * scan pixels of a 8-bits Z image data structure
865 GetImagePixels8(image
, width
, height
, pmap
)
878 data
= (unsigned char *) image
->data
;
879 iptr
= pmap
->pixelindex
;
880 depth
= image
->depth
;
881 lbt
= low_bits_table
[depth
];
882 for (y
= 0; y
< height
; y
++)
883 for (x
= 0; x
< width
; x
++, iptr
++) {
884 pixel
= data
[ZINDEX8(x
, y
, image
)];
887 if (storePixel(pixel
, pmap
, iptr
))
888 return (XpmNoMemory
);
894 * scan pixels of a 1-bit depth Z image data structure
898 GetImagePixels1(image
, width
, height
, pmap
, storeFunc
)
909 int xoff
, yoff
, offset
, bpl
;
912 iptr
= pmap
->pixelindex
;
913 offset
= image
->xoffset
;
914 bpl
= image
->bytes_per_line
;
916 if (image
->bitmap_bit_order
== MSBFirst
)
917 for (y
= 0; y
< height
; y
++)
918 for (x
= 0; x
< width
; x
++, iptr
++) {
920 yoff
= y
* bpl
+ (xoff
>> 3);
922 pixel
= (data
[yoff
] & (0x80 >> xoff
)) ? 1 : 0;
923 if ((*storeFunc
) (pixel
, pmap
, iptr
))
924 return (XpmNoMemory
);
927 for (y
= 0; y
< height
; y
++)
928 for (x
= 0; x
< width
; x
++, iptr
++) {
930 yoff
= y
* bpl
+ (xoff
>> 3);
932 pixel
= (data
[yoff
] & (1 << xoff
)) ? 1 : 0;
933 if ((*storeFunc
) (pixel
, pmap
, iptr
))
934 return (XpmNoMemory
);
941 #define CLEAN_UP(status) \
943 if (pixels) XpmFree (pixels);\
944 if (tmp_img) FreeXImage (tmp_img);\
958 unsigned char *pixels
;
961 pixels
= XpmMalloc ((((width
+15)>>4)<<4)*sizeof (*pixels
));
965 tmp_img
= AllocXImage ((((width
+15)>>4)<<4), 1, image
->rp
->BitMap
->Depth
);
967 CLEAN_UP (XpmNoMemory
)
969 iptr
= pmap
->pixelindex
;
970 for (y
= 0; y
< height
; ++y
)
972 ReadPixelLine8 (image
->rp
, 0, y
, width
, pixels
, tmp_img
->rp
);
973 for (x
= 0; x
< width
; ++x
, ++iptr
)
975 if ((*storeFunc
) (pixels
[x
], pmap
, iptr
))
976 CLEAN_UP (XpmNoMemory
)
980 CLEAN_UP (XpmSuccess
)
986 #else /* ndef FOR_MSW */
990 #ifdef __VISAGECPP30__
991 static int MSWGetImagePixels(
995 , unsigned int height
997 , int (*storeFunc
) (Pixel
, PixelsMap
*, unsigned int*)
1000 static int MSWGetImagePixels(
1003 , unsigned int width
1004 , unsigned int height
1006 , int (*storeFunc
) ()
1012 MSWGetImagePixels(display
, image
, width
, height
, pmap
, storeFunc
)
1016 unsigned int height
;
1018 int (*storeFunc
) ();
1027 DEVOPENSTRUC dop
= {NULL
, "DISPLAY", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
};
1028 SIZEL sizl
= {0, 0};
1032 iptr
= pmap
->pixelindex
;
1035 hps
= GpiCreatePS(hab
, *display
, &sizl
, GPIA_ASSOC
| PU_PELS
);
1036 GpiSetBitmap(hps
, image
->bitmap
);
1038 SelectObject(*display
, image
->bitmap
);
1041 for (y
= 0; y
< height
; y
++) {
1042 for (x
= 0; x
< width
; x
++, iptr
++) {
1046 pixel
= GpiQueryPel(hps
, &point
);
1048 pixel
= GetPixel(*display
, x
, y
);
1051 if ((*storeFunc
) (pixel
, pmap
, iptr
))
1052 return (XpmNoMemory
);
1055 return (XpmSuccess
);
1063 XpmCreateXpmImageFromPixmap(display
, pixmap
, shapemask
,
1064 xpmimage
, attributes
)
1069 XpmAttributes
*attributes
;
1071 XImage
*ximage
= NULL
;
1072 XImage
*shapeimage
= NULL
;
1073 unsigned int width
= 0;
1074 unsigned int height
= 0;
1078 if (attributes
&& attributes
->valuemask
& XpmSize
) {
1079 width
= attributes
->width
;
1080 height
= attributes
->height
;
1082 /* get the ximages */
1084 xpmCreateImageFromPixmap(display
, pixmap
, &ximage
, &width
, &height
);
1086 xpmCreateImageFromPixmap(display
, shapemask
, &shapeimage
,
1089 /* create the related XpmImage */
1090 ErrorStatus
= XpmCreateXpmImageFromImage(display
, ximage
, shapeimage
,
1091 xpmimage
, attributes
);
1093 /* destroy the ximages */
1095 XDestroyImage(ximage
);
1097 XDestroyImage(shapeimage
);
1099 return (ErrorStatus
);
1102 # endif/* not AMIGA */
1103 #endif /* ndef FOR_MSW */