]>
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
267 ErrorStatus
= GetImagePixels1(shapeimage
, width
, height
, &pmap
,
270 ErrorStatus
= AGetImagePixels(shapeimage
, width
, height
, &pmap
,
276 ErrorStatus
= MSWGetImagePixels(display
, shapeimage
, width
, height
,
277 &pmap
, storeMaskPixel
);
278 /* calling convention all messed up OS/2 -- figure out later */
282 if (ErrorStatus
!= XpmSuccess
)
287 * scan the image data
289 * In case depth is 1 or bits_per_pixel is 4, 6, 8, 24 or 32 use optimized
290 * 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
) {
302 if (image
->bits_per_pixel
== 8)
303 ErrorStatus
= GetImagePixels8(image
, width
, height
, &pmap
);
304 else if (image
->bits_per_pixel
== 16)
305 ErrorStatus
= GetImagePixels16(image
, width
, height
, &pmap
);
306 else if (image
->bits_per_pixel
== 32)
307 ErrorStatus
= GetImagePixels32(image
, width
, height
, &pmap
);
309 ErrorStatus
= GetImagePixels(image
, width
, height
, &pmap
);
311 ErrorStatus
= AGetImagePixels(image
, width
, height
, &pmap
,
317 ErrorStatus
= MSWGetImagePixels(display
, image
, width
, height
, &pmap
,
322 if (ErrorStatus
!= XpmSuccess
)
327 * get rgb values and a string of char, and possibly a name for each
331 colorTable
= (XpmColor
*) XpmCalloc(pmap
.ncolors
, sizeof(XpmColor
));
335 /* compute the minimal cpp */
336 for (cppm
= 1, c
= MAXPRINTABLE
; pmap
.ncolors
> c
; cppm
++)
341 if (pmap
.mask_pixel
) {
342 ErrorStatus
= ScanTransparentColor(colorTable
, cpp
, attributes
);
343 if (ErrorStatus
!= XpmSuccess
)
347 ErrorStatus
= ScanOtherColors(display
, colorTable
, pmap
.ncolors
,
348 pmap
.pixels
, pmap
.mask_pixel
, cpp
,
350 if (ErrorStatus
!= XpmSuccess
)
354 * store found informations in the XpmImage structure
356 xpmimage
->width
= width
;
357 xpmimage
->height
= height
;
359 xpmimage
->ncolors
= pmap
.ncolors
;
360 xpmimage
->colorTable
= colorTable
;
361 xpmimage
->data
= pmap
.pixelindex
;
363 XpmFree(pmap
.pixels
);
366 /* exit point in case of error, free only locally allocated variables */
369 XpmFree(pmap
.pixelindex
);
371 XpmFree(pmap
.pixels
);
373 xpmFreeColorTable(colorTable
, pmap
.ncolors
);
375 return (ErrorStatus
);
379 /* Visual Age cannot deal with old, non-ansi, code */
380 static int ScanTransparentColor(XpmColor
* color
, unsigned int cpp
, XpmAttributes
* attributes
)
383 ScanTransparentColor(color
, cpp
, attributes
)
386 XpmAttributes
*attributes
;
390 unsigned int a
, b
, c
;
392 /* first get a character string */
394 if (!(s
= color
->string
= (char *) XpmMalloc(cpp
+ 1)))
395 return (XpmNoMemory
);
396 *s
++ = printable
[c
= a
% MAXPRINTABLE
];
397 for (b
= 1; b
< cpp
; b
++, s
++)
398 *s
= printable
[c
= ((a
- c
) / MAXPRINTABLE
) % MAXPRINTABLE
];
401 /* then retreive related info from the attributes if any */
402 if (attributes
&& (attributes
->valuemask
& XpmColorTable
403 /* 3.2 backward compatibility code */
404 || attributes
->valuemask
& XpmInfos
)
406 && attributes
->mask_pixel
!= XpmUndefPixel
) {
409 char **defaults
= (char **) color
;
410 char **mask_defaults
;
412 /* 3.2 backward compatibility code */
413 if (attributes
->valuemask
& XpmColorTable
)
415 mask_defaults
= (char **) (
416 attributes
->colorTable
+ attributes
->mask_pixel
);
417 /* 3.2 backward compatibility code */
419 mask_defaults
= (char **)
420 ((XpmColor
**) attributes
->colorTable
)[attributes
->mask_pixel
];
422 for (key
= 1; key
<= NKEYS
; key
++) {
423 if (s
= mask_defaults
[key
]) {
424 defaults
[key
] = (char *) xpmstrdup(s
);
426 return (XpmNoMemory
);
430 color
->c_color
= (char *) xpmstrdup(TRANSPARENT_COLOR
);
432 return (XpmNoMemory
);
438 /* Visual Age cannot deal with old, non-ansi, code */
439 static int ScanOtherColors(
446 , XpmAttributes
* attributes
450 ScanOtherColors(display
, colors
, ncolors
, pixels
, mask
, cpp
, attributes
)
457 XpmAttributes
*attributes
;
460 /* variables stored in the XpmAttributes structure */
465 xpmRgbName rgbn
[MAX_RGBNAMES
];
467 xpmRgbName
*rgbn
= NULL
;
470 unsigned int i
, j
, c
, i2
;
472 XColor
*xcolors
= NULL
, *xcolor
;
474 XpmColor
*colorTable
, **oldColorTable
= NULL
;
475 unsigned int ancolors
= 0;
477 unsigned int mask_pixel
;
480 /* retrieve information from the XpmAttributes */
481 if (attributes
&& (attributes
->valuemask
& XpmColormap
))
482 colormap
= attributes
->colormap
;
484 colormap
= XDefaultColormap(display
, XDefaultScreen(display
));
485 if (attributes
&& (attributes
->valuemask
& XpmRgbFilename
))
486 rgb_fname
= attributes
->rgb_fname
;
490 /* start from the right element */
497 /* first get character strings and rgb values */
498 xcolors
= (XColor
*) XpmMalloc(sizeof(XColor
) * ncolors
);
500 return (XpmNoMemory
);
502 for (i
= 0, i2
= mask
, color
= colors
, xcolor
= xcolors
;
503 i
< ncolors
; i
++, i2
++, color
++, xcolor
++, pixels
++) {
505 if (!(s
= color
->string
= (char *) XpmMalloc(cpp
+ 1))) {
507 return (XpmNoMemory
);
509 *s
++ = printable
[c
= i2
% MAXPRINTABLE
];
510 for (j
= 1; j
< cpp
; j
++, s
++)
511 *s
= printable
[c
= ((i2
- c
) / MAXPRINTABLE
) % MAXPRINTABLE
];
514 xcolor
->pixel
= *pixels
;
517 XQueryColors(display
, &colormap
, xcolors
, ncolors
);
519 XQueryColors(display
, colormap
, xcolors
, ncolors
);
523 /* read the rgb file if any was specified */
525 rgbn_max
= xpmReadRgbNames(attributes
->rgb_fname
, rgbn
);
527 /* FOR_MSW: rgb names and values are hardcoded in rgbtab.h */
528 rgbn_max
= xpmReadRgbNames(NULL
, NULL
);
531 if (attributes
&& attributes
->valuemask
& XpmColorTable
) {
532 colorTable
= attributes
->colorTable
;
533 ancolors
= attributes
->ncolors
;
534 apixels
= attributes
->pixels
;
535 mask_pixel
= attributes
->mask_pixel
;
537 /* 3.2 backward compatibility code */
538 else if (attributes
&& attributes
->valuemask
& XpmInfos
) {
539 oldColorTable
= (XpmColor
**) attributes
->colorTable
;
540 ancolors
= attributes
->ncolors
;
541 apixels
= attributes
->pixels
;
542 mask_pixel
= attributes
->mask_pixel
;
546 for (i
= 0, color
= colors
, xcolor
= xcolors
; i
< ncolors
;
547 i
++, color
++, xcolor
++) {
549 /* look for related info from the attributes if any */
552 unsigned int offset
= 0;
554 for (j
= 0; j
< ancolors
; j
++) {
555 if (j
== mask_pixel
) {
559 if (apixels
[j
- offset
] == xcolor
->pixel
)
564 char **defaults
= (char **) color
;
567 /* 3.2 backward compatibility code */
569 adefaults
= (char **) oldColorTable
[j
];
572 adefaults
= (char **) (colorTable
+ j
);
575 for (key
= 1; key
<= NKEYS
; key
++) {
576 if (s
= adefaults
[key
])
577 defaults
[key
] = (char *) xpmstrdup(s
);
582 /* if nothing found look for a color name */
585 colorname
= xpmGetRgbName(rgbn
, rgbn_max
, xcolor
->red
,
586 xcolor
->green
, xcolor
->blue
);
588 color
->c_color
= (char *) xpmstrdup(colorname
);
590 /* at last store the rgb value */
593 sprintf(buf
, "#%04X%04X%04X",
594 xcolor
->red
, xcolor
->green
, xcolor
->blue
);
596 sprintf(buf
, "#%02x%02x%02x",
597 xcolor
->red
, xcolor
->green
, xcolor
->blue
);
599 color
->c_color
= (char *) xpmstrdup(buf
);
601 if (!color
->c_color
) {
603 xpmFreeRgbNames(rgbn
, rgbn_max
);
604 return (XpmNoMemory
);
610 xpmFreeRgbNames(rgbn
, rgbn_max
);
617 * The functions below are written from X11R5 MIT's code (XImUtil.c)
619 * The idea is to have faster functions than the standard XGetPixel function
620 * to scan the image data. Indeed we can speed up things by suppressing tests
621 * performed for each pixel. We do exactly the same tests but at the image
625 static unsigned long Const low_bits_table
[] = {
626 0x00000000, 0x00000001, 0x00000003, 0x00000007,
627 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
628 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
629 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
630 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
631 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
632 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
633 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
638 * Default method to scan pixels of an image data structure.
639 * The algorithm used is:
641 * copy the source bitmap_unit or Zpixel into temp
642 * normalize temp if needed
643 * extract the pixel bits into return value
648 /* Visual Age cannot deal with old, non-ansi, code */
649 static int GetImagePixels(
652 , unsigned int height
657 GetImagePixels(image
, width
, height
, pmap
)
669 int bits
, depth
, ibu
, ibpp
, offset
;
674 iptr
= pmap
->pixelindex
;
675 depth
= image
->depth
;
676 lbt
= low_bits_table
[depth
];
677 ibpp
= image
->bits_per_pixel
;
678 offset
= image
->xoffset
;
680 if ((image
->bits_per_pixel
| image
->depth
) == 1) {
681 ibu
= image
->bitmap_unit
;
682 for (y
= 0; y
< height
; y
++)
683 for (x
= 0; x
< width
; x
++, iptr
++) {
684 src
= &data
[XYINDEX(x
, y
, image
)];
685 dst
= (char *) &pixel
;
687 for (i
= ibu
>> 3; --i
>= 0;)
689 XYNORMALIZE(&pixel
, image
);
690 bits
= (x
+ offset
) % ibu
;
691 pixel
= ((((char *) &pixel
)[bits
>> 3]) >> (bits
& 7)) & 1;
694 if (storePixel(pixel
, pmap
, iptr
))
695 return (XpmNoMemory
);
697 } else if (image
->format
== XYPixmap
) {
700 ibu
= image
->bitmap_unit
;
702 bpl
= image
->bytes_per_line
;
703 for (y
= 0; y
< height
; y
++)
704 for (x
= 0; x
< width
; x
++, iptr
++) {
707 for (i
= depth
; --i
>= 0;) {
708 src
= &data
[XYINDEX(x
, y
, image
) + plane
];
711 for (j
= nbytes
; --j
>= 0;)
713 XYNORMALIZE(&px
, image
);
714 bits
= (x
+ offset
) % ibu
;
715 pixel
= (pixel
<< 1) |
716 (((((char *) &px
)[bits
>> 3]) >> (bits
& 7)) & 1);
717 plane
= plane
+ (bpl
* height
);
721 if (storePixel(pixel
, pmap
, iptr
))
722 return (XpmNoMemory
);
724 } else if (image
->format
== ZPixmap
) {
725 for (y
= 0; y
< height
; y
++)
726 for (x
= 0; x
< width
; x
++, iptr
++) {
727 src
= &data
[ZINDEX(x
, y
, image
)];
730 for (i
= (ibpp
+ 7) >> 3; --i
>= 0;)
732 ZNORMALIZE(&px
, image
);
734 for (i
= sizeof(unsigned long); --i
>= 0;)
735 pixel
= (pixel
<< 8) | ((unsigned char *) &px
)[i
];
744 if (storePixel(pixel
, pmap
, iptr
))
745 return (XpmNoMemory
);
748 return (XpmColorError
); /* actually a bad image */
753 * scan pixels of a 32-bits Z image data structure
756 #if !defined(WORD64) && !defined(LONG64)
757 static unsigned long byteorderpixel
= MSBFirst
<< 24;
761 /* Visual Age cannot deal with old, non-ansi, code */
762 static int GetImagePixels32(
765 , unsigned int height
770 GetImagePixels32(image
, width
, height
, pmap
)
785 data
= (unsigned char *) image
->data
;
786 iptr
= pmap
->pixelindex
;
787 depth
= image
->depth
;
788 lbt
= low_bits_table
[depth
];
789 #if !defined(WORD64) && !defined(LONG64)
790 if (*((char *) &byteorderpixel
) == image
->byte_order
) {
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
);
797 if (storePixel(pixel
, pmap
, iptr
))
798 return (XpmNoMemory
);
802 if (image
->byte_order
== MSBFirst
)
803 for (y
= 0; y
< height
; y
++)
804 for (x
= 0; x
< width
; x
++, iptr
++) {
805 addr
= &data
[ZINDEX32(x
, y
, image
)];
806 pixel
= ((unsigned long) addr
[0] << 24 |
807 (unsigned long) addr
[1] << 16 |
808 (unsigned long) addr
[2] << 8 |
812 if (storePixel(pixel
, pmap
, iptr
))
813 return (XpmNoMemory
);
816 for (y
= 0; y
< height
; y
++)
817 for (x
= 0; x
< width
; x
++, iptr
++) {
818 addr
= &data
[ZINDEX32(x
, y
, image
)];
820 (unsigned long) addr
[1] << 8 |
821 (unsigned long) addr
[2] << 16 |
822 (unsigned long) addr
[3] << 24);
825 if (storePixel(pixel
, pmap
, iptr
))
826 return (XpmNoMemory
);
832 * scan pixels of a 16-bits Z image data structure
836 /* Visual Age cannot deal with old, non-ansi, code */
837 static int GetImagePixels16(
840 , unsigned int height
845 GetImagePixels16(image
, width
, height
, pmap
)
860 data
= (unsigned char *) image
->data
;
861 iptr
= pmap
->pixelindex
;
862 depth
= image
->depth
;
863 lbt
= low_bits_table
[depth
];
864 if (image
->byte_order
== MSBFirst
)
865 for (y
= 0; y
< height
; y
++)
866 for (x
= 0; x
< width
; x
++, iptr
++) {
867 addr
= &data
[ZINDEX16(x
, y
, image
)];
868 pixel
= addr
[0] << 8 | addr
[1];
871 if (storePixel(pixel
, pmap
, iptr
))
872 return (XpmNoMemory
);
875 for (y
= 0; y
< height
; y
++)
876 for (x
= 0; x
< width
; x
++, iptr
++) {
877 addr
= &data
[ZINDEX16(x
, y
, image
)];
878 pixel
= addr
[0] | addr
[1] << 8;
881 if (storePixel(pixel
, pmap
, iptr
))
882 return (XpmNoMemory
);
888 * scan pixels of a 8-bits Z image data structure
892 /* Visual Age cannot deal with old, non-ansi, code */
894 GetImagePixels8(image
, width
, height
, pmap
)
897 , unsigned int height
902 GetImagePixels8(image
, width
, height
, pmap
)
916 data
= (unsigned char *) image
->data
;
917 iptr
= pmap
->pixelindex
;
918 depth
= image
->depth
;
919 lbt
= low_bits_table
[depth
];
920 for (y
= 0; y
< height
; y
++)
921 for (x
= 0; x
< width
; x
++, iptr
++) {
922 pixel
= data
[ZINDEX8(x
, y
, image
)];
925 if (storePixel(pixel
, pmap
, iptr
))
926 return (XpmNoMemory
);
932 * scan pixels of a 1-bit depth Z image data structure
936 /* Visual Age cannot deal with old, non-ansi, code */
941 , unsigned int height
943 , int (*storeFunc
) ()
947 GetImagePixels1(image
, width
, height
, pmap
, storeFunc
)
959 int xoff
, yoff
, offset
, bpl
;
962 iptr
= pmap
->pixelindex
;
963 offset
= image
->xoffset
;
964 bpl
= image
->bytes_per_line
;
966 if (image
->bitmap_bit_order
== MSBFirst
)
967 for (y
= 0; y
< height
; y
++)
968 for (x
= 0; x
< width
; x
++, iptr
++) {
970 yoff
= y
* bpl
+ (xoff
>> 3);
972 pixel
= (data
[yoff
] & (0x80 >> xoff
)) ? 1 : 0;
973 if ((*storeFunc
) (pixel
, pmap
, iptr
))
974 return (XpmNoMemory
);
977 for (y
= 0; y
< height
; y
++)
978 for (x
= 0; x
< width
; x
++, iptr
++) {
980 yoff
= y
* bpl
+ (xoff
>> 3);
982 pixel
= (data
[yoff
] & (1 << xoff
)) ? 1 : 0;
983 if ((*storeFunc
) (pixel
, pmap
, iptr
))
984 return (XpmNoMemory
);
991 #define CLEAN_UP(status) \
993 if (pixels) XpmFree (pixels);\
994 if (tmp_img) FreeXImage (tmp_img);\
1002 unsigned int height
,
1004 int (*storeFunc
) ())
1008 unsigned char *pixels
;
1011 pixels
= XpmMalloc ((((width
+15)>>4)<<4)*sizeof (*pixels
));
1015 tmp_img
= AllocXImage ((((width
+15)>>4)<<4), 1, image
->rp
->BitMap
->Depth
);
1016 if (tmp_img
== NULL
)
1017 CLEAN_UP (XpmNoMemory
)
1019 iptr
= pmap
->pixelindex
;
1020 for (y
= 0; y
< height
; ++y
)
1022 ReadPixelLine8 (image
->rp
, 0, y
, width
, pixels
, tmp_img
->rp
);
1023 for (x
= 0; x
< width
; ++x
, ++iptr
)
1025 if ((*storeFunc
) (pixels
[x
], pmap
, iptr
))
1026 CLEAN_UP (XpmNoMemory
)
1030 CLEAN_UP (XpmSuccess
)
1036 #else /* ndef FOR_MSW */
1038 /* Visual Age cannot deal with old, non-ansi, code */
1043 , unsigned int width
1044 , unsigned int height
1046 , int (*storeFunc
) ()
1050 MSWGetImagePixels(display
, image
, width
, height
, pmap
, storeFunc
)
1054 unsigned int height
;
1056 int (*storeFunc
) ();
1065 DEVOPENSTRUC dop
= {NULL
, "DISPLAY", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
};
1066 SIZEL sizl
= {0, 0};
1070 iptr
= pmap
->pixelindex
;
1073 hps
= GpiCreatePS(hab
, *display
, &sizl
, GPIA_ASSOC
| PU_PELS
);
1074 GpiSetBitmap(hps
, image
->bitmap
);
1076 SelectObject(*display
, image
->bitmap
);
1079 for (y
= 0; y
< height
; y
++) {
1080 for (x
= 0; x
< width
; x
++, iptr
++) {
1084 pixel
= GpiQueryPel(hps
, &point
);
1086 pixel
= GetPixel(*display
, x
, y
);
1089 /* calling convention all messed up under OS/2 */
1090 if ((*storeFunc
) (pixel
, pmap
, iptr
))
1091 return (XpmNoMemory
);
1095 return (XpmSuccess
);
1103 XpmCreateXpmImageFromPixmap(display
, pixmap
, shapemask
,
1104 xpmimage
, attributes
)
1109 XpmAttributes
*attributes
;
1111 XImage
*ximage
= NULL
;
1112 XImage
*shapeimage
= NULL
;
1113 unsigned int width
= 0;
1114 unsigned int height
= 0;
1118 if (attributes
&& attributes
->valuemask
& XpmSize
) {
1119 width
= attributes
->width
;
1120 height
= attributes
->height
;
1122 /* get the ximages */
1124 xpmCreateImageFromPixmap(display
, pixmap
, &ximage
, &width
, &height
);
1126 xpmCreateImageFromPixmap(display
, shapemask
, &shapeimage
,
1129 /* create the related XpmImage */
1130 ErrorStatus
= XpmCreateXpmImageFromImage(display
, ximage
, shapeimage
,
1131 xpmimage
, attributes
);
1133 /* destroy the ximages */
1135 XDestroyImage(ximage
);
1137 XDestroyImage(shapeimage
);
1139 return (ErrorStatus
);
1142 # endif/* not AMIGA */
1143 #endif /* ndef FOR_MSW */