]>
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 ErrorStatus
= MSWGetImagePixels(display
, image
, width
, height
, &pmap
,
326 if (ErrorStatus
!= XpmSuccess
)
331 * get rgb values and a string of char, and possibly a name for each
335 colorTable
= (XpmColor
*) XpmCalloc(pmap
.ncolors
, sizeof(XpmColor
));
339 /* compute the minimal cpp */
340 for (cppm
= 1, c
= MAXPRINTABLE
; pmap
.ncolors
> c
; cppm
++)
345 if (pmap
.mask_pixel
) {
346 ErrorStatus
= ScanTransparentColor(colorTable
, cpp
, attributes
);
347 if (ErrorStatus
!= XpmSuccess
)
351 ErrorStatus
= ScanOtherColors(display
, colorTable
, pmap
.ncolors
,
352 pmap
.pixels
, pmap
.mask_pixel
, cpp
,
354 if (ErrorStatus
!= XpmSuccess
)
358 * store found informations in the XpmImage structure
360 xpmimage
->width
= width
;
361 xpmimage
->height
= height
;
363 xpmimage
->ncolors
= pmap
.ncolors
;
364 xpmimage
->colorTable
= colorTable
;
365 xpmimage
->data
= pmap
.pixelindex
;
367 XpmFree(pmap
.pixels
);
370 /* exit point in case of error, free only locally allocated variables */
373 XpmFree(pmap
.pixelindex
);
375 XpmFree(pmap
.pixels
);
377 xpmFreeColorTable(colorTable
, pmap
.ncolors
);
379 return (ErrorStatus
);
383 /* Visual Age cannot deal with old, non-ansi, code */
384 static int ScanTransparentColor(XpmColor
* color
, unsigned int cpp
, XpmAttributes
* attributes
)
387 ScanTransparentColor(color
, cpp
, attributes
)
390 XpmAttributes
*attributes
;
394 unsigned int a
, b
, c
;
396 /* first get a character string */
398 if (!(s
= color
->string
= (char *) XpmMalloc(cpp
+ 1)))
399 return (XpmNoMemory
);
400 *s
++ = printable
[c
= a
% MAXPRINTABLE
];
401 for (b
= 1; b
< cpp
; b
++, s
++)
402 *s
= printable
[c
= ((a
- c
) / MAXPRINTABLE
) % MAXPRINTABLE
];
405 /* then retreive related info from the attributes if any */
406 if (attributes
&& (attributes
->valuemask
& XpmColorTable
407 /* 3.2 backward compatibility code */
408 || attributes
->valuemask
& XpmInfos
)
410 && attributes
->mask_pixel
!= XpmUndefPixel
) {
413 char **defaults
= (char **) color
;
414 char **mask_defaults
;
416 /* 3.2 backward compatibility code */
417 if (attributes
->valuemask
& XpmColorTable
)
419 mask_defaults
= (char **) (
420 attributes
->colorTable
+ attributes
->mask_pixel
);
421 /* 3.2 backward compatibility code */
423 mask_defaults
= (char **)
424 ((XpmColor
**) attributes
->colorTable
)[attributes
->mask_pixel
];
426 for (key
= 1; key
<= NKEYS
; key
++) {
427 if (s
= mask_defaults
[key
]) {
428 defaults
[key
] = (char *) xpmstrdup(s
);
430 return (XpmNoMemory
);
434 color
->c_color
= (char *) xpmstrdup(TRANSPARENT_COLOR
);
436 return (XpmNoMemory
);
442 /* Visual Age cannot deal with old, non-ansi, code */
443 static int ScanOtherColors(
450 , XpmAttributes
* attributes
454 ScanOtherColors(display
, colors
, ncolors
, pixels
, mask
, cpp
, attributes
)
461 XpmAttributes
*attributes
;
464 /* variables stored in the XpmAttributes structure */
469 xpmRgbName rgbn
[MAX_RGBNAMES
];
471 xpmRgbName
*rgbn
= NULL
;
474 unsigned int i
, j
, c
, i2
;
476 XColor
*xcolors
= NULL
, *xcolor
;
478 XpmColor
*colorTable
, **oldColorTable
= NULL
;
479 unsigned int ancolors
= 0;
481 unsigned int mask_pixel
;
484 /* retrieve information from the XpmAttributes */
485 if (attributes
&& (attributes
->valuemask
& XpmColormap
))
486 colormap
= attributes
->colormap
;
488 colormap
= XDefaultColormap(display
, XDefaultScreen(display
));
489 if (attributes
&& (attributes
->valuemask
& XpmRgbFilename
))
490 rgb_fname
= attributes
->rgb_fname
;
494 /* start from the right element */
501 /* first get character strings and rgb values */
502 xcolors
= (XColor
*) XpmMalloc(sizeof(XColor
) * ncolors
);
504 return (XpmNoMemory
);
506 for (i
= 0, i2
= mask
, color
= colors
, xcolor
= xcolors
;
507 i
< ncolors
; i
++, i2
++, color
++, xcolor
++, pixels
++) {
509 if (!(s
= color
->string
= (char *) XpmMalloc(cpp
+ 1))) {
511 return (XpmNoMemory
);
513 *s
++ = printable
[c
= i2
% MAXPRINTABLE
];
514 for (j
= 1; j
< cpp
; j
++, s
++)
515 *s
= printable
[c
= ((i2
- c
) / MAXPRINTABLE
) % MAXPRINTABLE
];
518 xcolor
->pixel
= *pixels
;
521 XQueryColors(display
, &colormap
, xcolors
, ncolors
);
523 XQueryColors(display
, colormap
, xcolors
, ncolors
);
527 /* read the rgb file if any was specified */
529 rgbn_max
= xpmReadRgbNames(attributes
->rgb_fname
, rgbn
);
531 /* FOR_MSW: rgb names and values are hardcoded in rgbtab.h */
532 rgbn_max
= xpmReadRgbNames(NULL
, NULL
);
535 if (attributes
&& attributes
->valuemask
& XpmColorTable
) {
536 colorTable
= attributes
->colorTable
;
537 ancolors
= attributes
->ncolors
;
538 apixels
= attributes
->pixels
;
539 mask_pixel
= attributes
->mask_pixel
;
541 /* 3.2 backward compatibility code */
542 else if (attributes
&& attributes
->valuemask
& XpmInfos
) {
543 oldColorTable
= (XpmColor
**) attributes
->colorTable
;
544 ancolors
= attributes
->ncolors
;
545 apixels
= attributes
->pixels
;
546 mask_pixel
= attributes
->mask_pixel
;
550 for (i
= 0, color
= colors
, xcolor
= xcolors
; i
< ncolors
;
551 i
++, color
++, xcolor
++) {
553 /* look for related info from the attributes if any */
556 unsigned int offset
= 0;
558 for (j
= 0; j
< ancolors
; j
++) {
559 if (j
== mask_pixel
) {
563 if (apixels
[j
- offset
] == xcolor
->pixel
)
568 char **defaults
= (char **) color
;
571 /* 3.2 backward compatibility code */
573 adefaults
= (char **) oldColorTable
[j
];
576 adefaults
= (char **) (colorTable
+ j
);
579 for (key
= 1; key
<= NKEYS
; key
++) {
580 if (s
= adefaults
[key
])
581 defaults
[key
] = (char *) xpmstrdup(s
);
586 /* if nothing found look for a color name */
589 colorname
= xpmGetRgbName(rgbn
, rgbn_max
, xcolor
->red
,
590 xcolor
->green
, xcolor
->blue
);
592 color
->c_color
= (char *) xpmstrdup(colorname
);
594 /* at last store the rgb value */
597 sprintf(buf
, "#%04X%04X%04X",
598 xcolor
->red
, xcolor
->green
, xcolor
->blue
);
600 sprintf(buf
, "#%02x%02x%02x",
601 xcolor
->red
, xcolor
->green
, xcolor
->blue
);
603 color
->c_color
= (char *) xpmstrdup(buf
);
605 if (!color
->c_color
) {
607 xpmFreeRgbNames(rgbn
, rgbn_max
);
608 return (XpmNoMemory
);
614 xpmFreeRgbNames(rgbn
, rgbn_max
);
621 * The functions below are written from X11R5 MIT's code (XImUtil.c)
623 * The idea is to have faster functions than the standard XGetPixel function
624 * to scan the image data. Indeed we can speed up things by suppressing tests
625 * performed for each pixel. We do exactly the same tests but at the image
629 static unsigned long Const low_bits_table
[] = {
630 0x00000000, 0x00000001, 0x00000003, 0x00000007,
631 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
632 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
633 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
634 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
635 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
636 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
637 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
642 * Default method to scan pixels of an image data structure.
643 * The algorithm used is:
645 * copy the source bitmap_unit or Zpixel into temp
646 * normalize temp if needed
647 * extract the pixel bits into return value
652 GetImagePixels(image
, width
, height
, pmap
)
663 int bits
, depth
, ibu
, ibpp
, offset
;
668 iptr
= pmap
->pixelindex
;
669 depth
= image
->depth
;
670 lbt
= low_bits_table
[depth
];
671 ibpp
= image
->bits_per_pixel
;
672 offset
= image
->xoffset
;
674 if ((image
->bits_per_pixel
| image
->depth
) == 1) {
675 ibu
= image
->bitmap_unit
;
676 for (y
= 0; y
< height
; y
++)
677 for (x
= 0; x
< width
; x
++, iptr
++) {
678 src
= &data
[XYINDEX(x
, y
, image
)];
679 dst
= (char *) &pixel
;
681 for (i
= ibu
>> 3; --i
>= 0;)
683 XYNORMALIZE(&pixel
, image
);
684 bits
= (x
+ offset
) % ibu
;
685 pixel
= ((((char *) &pixel
)[bits
>> 3]) >> (bits
& 7)) & 1;
688 if (storePixel(pixel
, pmap
, iptr
))
689 return (XpmNoMemory
);
691 } else if (image
->format
== XYPixmap
) {
694 ibu
= image
->bitmap_unit
;
696 bpl
= image
->bytes_per_line
;
697 for (y
= 0; y
< height
; y
++)
698 for (x
= 0; x
< width
; x
++, iptr
++) {
701 for (i
= depth
; --i
>= 0;) {
702 src
= &data
[XYINDEX(x
, y
, image
) + plane
];
705 for (j
= nbytes
; --j
>= 0;)
707 XYNORMALIZE(&px
, image
);
708 bits
= (x
+ offset
) % ibu
;
709 pixel
= (pixel
<< 1) |
710 (((((char *) &px
)[bits
>> 3]) >> (bits
& 7)) & 1);
711 plane
= plane
+ (bpl
* height
);
715 if (storePixel(pixel
, pmap
, iptr
))
716 return (XpmNoMemory
);
718 } else if (image
->format
== ZPixmap
) {
719 for (y
= 0; y
< height
; y
++)
720 for (x
= 0; x
< width
; x
++, iptr
++) {
721 src
= &data
[ZINDEX(x
, y
, image
)];
724 for (i
= (ibpp
+ 7) >> 3; --i
>= 0;)
726 ZNORMALIZE(&px
, image
);
728 for (i
= sizeof(unsigned long); --i
>= 0;)
729 pixel
= (pixel
<< 8) | ((unsigned char *) &px
)[i
];
738 if (storePixel(pixel
, pmap
, iptr
))
739 return (XpmNoMemory
);
742 return (XpmColorError
); /* actually a bad image */
747 * scan pixels of a 32-bits Z image data structure
750 #if !defined(WORD64) && !defined(LONG64)
751 static unsigned long byteorderpixel
= MSBFirst
<< 24;
755 GetImagePixels32(image
, width
, height
, pmap
)
769 data
= (unsigned char *) image
->data
;
770 iptr
= pmap
->pixelindex
;
771 depth
= image
->depth
;
772 lbt
= low_bits_table
[depth
];
773 #if !defined(WORD64) && !defined(LONG64)
774 if (*((char *) &byteorderpixel
) == image
->byte_order
) {
775 for (y
= 0; y
< height
; y
++)
776 for (x
= 0; x
< width
; x
++, iptr
++) {
777 addr
= &data
[ZINDEX32(x
, y
, image
)];
778 pixel
= *((unsigned long *) addr
);
781 if (storePixel(pixel
, pmap
, iptr
))
782 return (XpmNoMemory
);
786 if (image
->byte_order
== MSBFirst
)
787 for (y
= 0; y
< height
; y
++)
788 for (x
= 0; x
< width
; x
++, iptr
++) {
789 addr
= &data
[ZINDEX32(x
, y
, image
)];
790 pixel
= ((unsigned long) addr
[0] << 24 |
791 (unsigned long) addr
[1] << 16 |
792 (unsigned long) addr
[2] << 8 |
796 if (storePixel(pixel
, pmap
, iptr
))
797 return (XpmNoMemory
);
800 for (y
= 0; y
< height
; y
++)
801 for (x
= 0; x
< width
; x
++, iptr
++) {
802 addr
= &data
[ZINDEX32(x
, y
, image
)];
804 (unsigned long) addr
[1] << 8 |
805 (unsigned long) addr
[2] << 16 |
806 (unsigned long) addr
[3] << 24);
809 if (storePixel(pixel
, pmap
, iptr
))
810 return (XpmNoMemory
);
816 * scan pixels of a 16-bits Z image data structure
820 GetImagePixels16(image
, width
, height
, pmap
)
834 data
= (unsigned char *) image
->data
;
835 iptr
= pmap
->pixelindex
;
836 depth
= image
->depth
;
837 lbt
= low_bits_table
[depth
];
838 if (image
->byte_order
== MSBFirst
)
839 for (y
= 0; y
< height
; y
++)
840 for (x
= 0; x
< width
; x
++, iptr
++) {
841 addr
= &data
[ZINDEX16(x
, y
, image
)];
842 pixel
= addr
[0] << 8 | addr
[1];
845 if (storePixel(pixel
, pmap
, iptr
))
846 return (XpmNoMemory
);
849 for (y
= 0; y
< height
; y
++)
850 for (x
= 0; x
< width
; x
++, iptr
++) {
851 addr
= &data
[ZINDEX16(x
, y
, image
)];
852 pixel
= addr
[0] | addr
[1] << 8;
855 if (storePixel(pixel
, pmap
, iptr
))
856 return (XpmNoMemory
);
862 * scan pixels of a 8-bits Z image data structure
866 GetImagePixels8(image
, width
, height
, pmap
)
879 data
= (unsigned char *) image
->data
;
880 iptr
= pmap
->pixelindex
;
881 depth
= image
->depth
;
882 lbt
= low_bits_table
[depth
];
883 for (y
= 0; y
< height
; y
++)
884 for (x
= 0; x
< width
; x
++, iptr
++) {
885 pixel
= data
[ZINDEX8(x
, y
, image
)];
888 if (storePixel(pixel
, pmap
, iptr
))
889 return (XpmNoMemory
);
895 * scan pixels of a 1-bit depth Z image data structure
899 GetImagePixels1(image
, width
, height
, pmap
, storeFunc
)
910 int xoff
, yoff
, offset
, bpl
;
913 iptr
= pmap
->pixelindex
;
914 offset
= image
->xoffset
;
915 bpl
= image
->bytes_per_line
;
917 if (image
->bitmap_bit_order
== MSBFirst
)
918 for (y
= 0; y
< height
; y
++)
919 for (x
= 0; x
< width
; x
++, iptr
++) {
921 yoff
= y
* bpl
+ (xoff
>> 3);
923 pixel
= (data
[yoff
] & (0x80 >> xoff
)) ? 1 : 0;
924 if ((*storeFunc
) (pixel
, pmap
, iptr
))
925 return (XpmNoMemory
);
928 for (y
= 0; y
< height
; y
++)
929 for (x
= 0; x
< width
; x
++, iptr
++) {
931 yoff
= y
* bpl
+ (xoff
>> 3);
933 pixel
= (data
[yoff
] & (1 << xoff
)) ? 1 : 0;
934 if ((*storeFunc
) (pixel
, pmap
, iptr
))
935 return (XpmNoMemory
);
942 #define CLEAN_UP(status) \
944 if (pixels) XpmFree (pixels);\
945 if (tmp_img) FreeXImage (tmp_img);\
959 unsigned char *pixels
;
962 pixels
= XpmMalloc ((((width
+15)>>4)<<4)*sizeof (*pixels
));
966 tmp_img
= AllocXImage ((((width
+15)>>4)<<4), 1, image
->rp
->BitMap
->Depth
);
968 CLEAN_UP (XpmNoMemory
)
970 iptr
= pmap
->pixelindex
;
971 for (y
= 0; y
< height
; ++y
)
973 ReadPixelLine8 (image
->rp
, 0, y
, width
, pixels
, tmp_img
->rp
);
974 for (x
= 0; x
< width
; ++x
, ++iptr
)
976 if ((*storeFunc
) (pixels
[x
], pmap
, iptr
))
977 CLEAN_UP (XpmNoMemory
)
981 CLEAN_UP (XpmSuccess
)
987 #else /* ndef FOR_MSW */
991 #ifdef __VISAGECPP30__
992 static int MSWGetImagePixels(
996 , unsigned int height
998 , int (*storeFunc
) (Pixel
, PixelsMap
*, unsigned int*)
1001 static int MSWGetImagePixels(
1004 , unsigned int width
1005 , unsigned int height
1007 , int (*storeFunc
) ()
1013 MSWGetImagePixels(display
, image
, width
, height
, pmap
, storeFunc
)
1017 unsigned int height
;
1019 int (*storeFunc
) ();
1028 DEVOPENSTRUC dop
= {NULL
, "DISPLAY", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
};
1029 SIZEL sizl
= {0, 0};
1033 iptr
= pmap
->pixelindex
;
1036 hps
= GpiCreatePS(hab
, *display
, &sizl
, GPIA_ASSOC
| PU_PELS
);
1037 GpiSetBitmap(hps
, image
->bitmap
);
1039 SelectObject(*display
, image
->bitmap
);
1042 for (y
= 0; y
< height
; y
++) {
1043 for (x
= 0; x
< width
; x
++, iptr
++) {
1047 pixel
= GpiQueryPel(hps
, &point
);
1049 pixel
= GetPixel(*display
, x
, y
);
1052 if ((*storeFunc
) (pixel
, pmap
, iptr
))
1053 return (XpmNoMemory
);
1056 return (XpmSuccess
);
1064 XpmCreateXpmImageFromPixmap(display
, pixmap
, shapemask
,
1065 xpmimage
, attributes
)
1070 XpmAttributes
*attributes
;
1072 XImage
*ximage
= NULL
;
1073 XImage
*shapeimage
= NULL
;
1074 unsigned int width
= 0;
1075 unsigned int height
= 0;
1079 if (attributes
&& attributes
->valuemask
& XpmSize
) {
1080 width
= attributes
->width
;
1081 height
= attributes
->height
;
1083 /* get the ximages */
1085 xpmCreateImageFromPixmap(display
, pixmap
, &ximage
, &width
, &height
);
1087 xpmCreateImageFromPixmap(display
, shapemask
, &shapeimage
,
1090 /* create the related XpmImage */
1091 ErrorStatus
= XpmCreateXpmImageFromImage(display
, ximage
, shapeimage
,
1092 xpmimage
, attributes
);
1094 /* destroy the ximages */
1096 XDestroyImage(ximage
);
1098 XDestroyImage(shapeimage
);
1100 return (ErrorStatus
);
1103 # endif/* not AMIGA */
1104 #endif /* ndef FOR_MSW */