1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * ©1995 Artsoft Development *
6 * 33659 Bielefeld-Senne *
7 * Telefon: (0521) 493245 *
8 * eMail: aeglos@valinor.owl.de *
9 * aeglos@uni-paderborn.de *
10 * q99492@pbhrzx.uni-paderborn.de *
11 *----------------------------------------------------------*
13 ***********************************************************/
15 #include "gfxloader.h"
23 extern void Delay(long);
37 struct IFF_ILBM_FORM_big_endian
40 unsigned char chunk_size[4];
44 struct IFF_ILBM_BMHD_big_endian
46 char Width[2], Height[2];
47 char LeftEdge[2], TopEdge[2];
52 char transparentColor[2];
53 char xAspect, yAspect;
54 char pageWidth[2], pageHeight[2];
59 unsigned int Width, Height;
60 int LeftEdge, TopEdge;
63 unsigned int Compression;
65 unsigned int transparentColor;
66 unsigned int xAspect, yAspect;
67 int pageWidth, pageHeight;
70 static int ConvertXImageDepth(Display *, XImage **);
71 static int Read_GIF_to_Pixmap_or_Bitmap(Display *, char *, Pixmap *, int);
73 #define READ_GIF_TO_BITMAP 0
74 #define READ_GIF_TO_PIXMAP 1
77 int Read_GIF_to_Bitmap(Display *display, char *filename, Pixmap *pixmap)
79 printf("Read_GIF_to_Bitmap\n");
84 return(Read_GIF_to_Pixmap_or_Bitmap(display, filename,
85 pixmap, READ_GIF_TO_BITMAP));
88 int Read_GIF_to_Pixmap(Display *display, char *filename, Pixmap *pixmap)
90 printf("Read_GIF_to_Pixmap\n");
95 return(Read_GIF_to_Pixmap_or_Bitmap(display, filename,
96 pixmap, READ_GIF_TO_PIXMAP));
99 int Read_GIF_to_Pixmap_or_Bitmap(Display *display, char *filename,
100 Pixmap *pixmap, int mode)
102 XImage *image = NULL;
103 Pixmap new_pixmap = 0;
107 return_code = Read_GIF_to_XImage(display, filename, &image);
108 if (return_code != GIF_Success)
113 int screen = DefaultScreen(display);
114 Drawable root = RootWindow(display,screen);
115 int depth = DefaultDepth(display, screen);
116 int width = image->width;
117 int height = image->height;
119 if (mode == READ_GIF_TO_BITMAP)
122 unsigned long black_pixel = BlackPixel(display,screen);
123 int bytes_per_line = (width+7) / 8;
124 int size = bytes_per_line * height;
127 data = (char *)malloc(size);
129 return(GIF_NoMemory);
135 for(y=0;y<height;y++)
139 if (XGetPixel(image,x,y) == black_pixel)
140 data[y * bytes_per_line + x/8] |= (1 << (x%8));
144 new_pixmap = XCreateBitmapFromData(display,root,data,width,height);
148 return(GIF_NoMemory);
155 if (ConvertXImageDepth(display, &image) != GIF_Success)
156 return(GIF_ColorFailed);
158 new_pixmap = XCreatePixmap(display,root,width,height,depth);
161 return(GIF_NoMemory);
163 gcv.foreground = BlackPixel(display,screen);
164 gcv.background = WhitePixel(display,screen);
165 gc = XCreateGC(display, root, GCForeground | GCBackground, &gcv);
166 XPutImage(display,new_pixmap,gc,image,0,0,0,0,width,height);
175 XPutImage(display,window,gc,image,0,0,0,0,width,height);
183 XFreeGC(display, gc);
186 XDestroyImage(image);
189 *pixmap = new_pixmap;
195 * Read_GIF_to_XImage() - based strongly on...
197 * xgifload.c - based strongly on...
199 * gif2ras.c - Converts from a Compuserve GIF (tm) image to a Sun Raster image.
201 * Copyright (c) 1988, 1989 by Patrick J. Naughton
203 * Author: Patrick J. Naughton
204 * naughton@wind.sun.com
206 * Permission to use, copy, modify, and distribute this software and its
207 * documentation for any purpose and without fee is hereby granted,
208 * provided that the above copyright notice appear in all copies and that
209 * both that copyright notice and this permission notice appear in
210 * supporting documentation.
212 * This file is provided AS IS with no warranties of any kind. The author
213 * shall have no liability with respect to the infringement of copyrights,
214 * trade secrets or any patents by this file or any part thereof. In no
215 * event will the author be liable for any lost revenue or profits or
216 * other special, indirect and consequential damages.
221 typedef unsigned char byte;
223 static int ReadCode(void);
224 static void AddToPixel(byte);
225 static int ColorDicking(Display *);
227 #define NEXTBYTE (*ptr++)
228 #define IMAGESEP 0x2c
229 #define INTERLACEMASK 0x40
230 #define COLORMAPMASK 0x80
233 int BitOffset, /* Bit Offset of next code */
234 XC, YC, /* Output X and Y coords of current pixel */
235 Pass, /* Used by output routine if interlaced pic */
236 OutCount, /* Decompressor output 'stack count' */
237 RWidth, RHeight, /* screen dimensions */
238 Width, Height, /* image dimensions */
239 LeftOfs, TopOfs, /* image offset */
240 BitsPerPixel, /* Bits per pixel, read from GIF header */
241 BytesPerScanline, /* bytes per scanline in output raster */
242 ColorMapSize, /* number of colors */
243 Background, /* background color */
244 CodeSize, /* Code size, read from GIF header */
245 InitCodeSize, /* Starting code size, used during Clear */
246 Code, /* Value returned by ReadCode */
247 MaxCode, /* limiting value for current code size */
248 ClearCode, /* GIF clear code */
249 EOFCode, /* GIF end-of-information code */
250 CurCode, OldCode, InCode, /* Decompressor variables */
251 FirstFree, /* First free code, generated per GIF spec */
252 FreeCode, /* Decompressor, next free slot in hash table*/
253 FinChar, /* Decompressor variable */
254 BitMask, /* AND mask for data size */
255 ReadMask; /* Code AND mask for current code size */
257 static boolean Interlace, HasColormap;
259 static byte *ImageData; /* The result array */
260 static byte *RawGIF; /* The heap array to hold it, raw */
261 static byte *Raster; /* The raster data stream, unblocked */
263 /* The color map, read from the GIF header */
264 static byte Red[256], Green[256], Blue[256], used[256];
267 extern char *progname;
270 static unsigned long cols[256];
271 static XColor defs[256];
273 int Read_GIF_to_XImage(Display *display, char *filename, XImage **image)
276 register byte ch, ch1;
277 register byte *ptr, *ptr1;
279 int screen = DefaultScreen(display);
280 Visual *visual = DefaultVisual(display,screen);
281 XImage *new_image = NULL;
284 int Prefix[4096]; /* The hash table used by the decompressor */
286 int OutCode[1025]; /* An output array used by the decompressor */
288 BitOffset = XC = YC = Pass = OutCount = 0;
291 if (strcmp(filename,"-")==0)
294 filename = "<stdin>";
297 file = fopen(filename,"r");
300 return(GIF_OpenFailed);
302 /* find the size of the file */
304 filesize = ftell(file);
307 if (!(ptr = RawGIF = (byte *) malloc(filesize)))
308 return(GIF_NoMemory);
310 if (!(Raster = (byte *) malloc(filesize)))
311 return(GIF_NoMemory);
313 if (fread(ptr, filesize, 1, file) != 1)
314 return(GIF_ReadFailed);
316 if (strncmp(ptr, id, 6))
317 return(GIF_FileInvalid);
321 /* Get variables from the GIF screen descriptor */
324 RWidth = ch + 0x100 * NEXTBYTE; /* screen dimensions... not used. */
326 RHeight = ch + 0x100 * NEXTBYTE;
329 HasColormap = ((ch & COLORMAPMASK) ? True : False);
331 BitsPerPixel = (ch & 7) + 1;
332 numcols = ColorMapSize = 1 << BitsPerPixel;
333 BitMask = ColorMapSize - 1;
335 Background = NEXTBYTE; /* background color... not used. */
337 if (NEXTBYTE) /* supposed to be NULL */
338 return(GIF_FileInvalid);
340 /* Read in global colormap. */
344 for (i = 0; i < ColorMapSize; i++)
355 /* no colormap in GIF file */
356 fprintf(stderr,"%s: warning! no colortable in this file. Winging it.\n",
360 for (i=0; i<numcols; i++)
361 cols[i] = (unsigned long) i;
364 /* Check for image seperator */
366 if (NEXTBYTE != IMAGESEP)
367 return(GIF_FileInvalid);
369 /* Now read in values from the image descriptor */
372 LeftOfs = ch + 0x100 * NEXTBYTE;
374 TopOfs = ch + 0x100 * NEXTBYTE;
376 Width = ch + 0x100 * NEXTBYTE;
378 Height = ch + 0x100 * NEXTBYTE;
379 Interlace = ((NEXTBYTE & INTERLACEMASK) ? True : False);
382 fprintf(stderr, "%s:\n", filename);
383 fprintf(stderr, " %dx%d, %d bpp / %d colors, %sinterlaced\n",
384 Width,Height, BitsPerPixel,ColorMapSize,(Interlace ? "" : "non-"));
385 fprintf(stderr, " Reading file... ");
388 /* Note that I ignore the possible existence of a local color map.
389 * I'm told there aren't many files around that use them, and the spec
390 * says it's defined for future use. This could lead to an error
391 * reading some files.
394 /* Start reading the raster data. First we get the intial code size
395 * and compute decompressor constant values, based on this code size.
399 ClearCode = (1 << CodeSize);
400 EOFCode = ClearCode + 1;
401 FreeCode = FirstFree = ClearCode + 2;
403 /* The GIF spec has it that the code size is the code size used to
404 * compute the above values is the code size given in the file, but the
405 * code size used in compression/decompression is the code size given in
406 * the file plus one. (thus the ++).
410 InitCodeSize = CodeSize;
411 MaxCode = (1 << CodeSize);
412 ReadMask = MaxCode - 1;
414 /* Read the raster data. Here we just transpose it from the GIF array
415 * to the Raster array, turning it from a series of blocks into one long
416 * data stream, which makes life much easier for ReadCode().
423 while (ch--) *ptr1++ = NEXTBYTE;
424 if ((Raster - ptr1) > filesize)
425 return(GIF_FileInvalid);
429 free(RawGIF); /* We're done with the raw data now... */
432 fprintf(stderr, "done\n");
433 fprintf(stderr, " Decompressing... ");
436 /* Allocate the X Image */
437 ImageData = (byte *) malloc(Width*Height);
439 return(GIF_NoMemory);
441 new_image = XCreateImage(display,visual,8,ZPixmap,0,ImageData,
442 Width,Height,8,Width);
444 return(GIF_NoMemory);
446 BytesPerScanline = Width;
449 /* Decompress the file, continuing until you see the GIF EOF code.
450 * One obvious enhancement is to add checking for corrupt files here.
454 while (Code != EOFCode)
456 /* Clear code sets everything back to its initial value, then reads the
457 * immediately subsequent code as uncompressed data.
460 if (Code == ClearCode)
462 CodeSize = InitCodeSize;
463 MaxCode = (1 << CodeSize);
464 ReadMask = MaxCode - 1;
465 FreeCode = FirstFree;
466 CurCode = OldCode = Code = ReadCode();
467 FinChar = CurCode & BitMask;
472 /* If not a clear code, then must be data:
473 * save same as CurCode and InCode
476 CurCode = InCode = Code;
478 /* If greater or equal to FreeCode, not in the hash table yet;
479 * repeat the last character decoded
482 if (CurCode >= FreeCode)
485 OutCode[OutCount++] = FinChar;
488 /* Unless this code is raw data, pursue the chain pointed to by CurCode
489 * through the hash table to its end; each code in the chain puts its
490 * associated output code on the output queue.
493 while (CurCode > BitMask)
496 return(GIF_FileInvalid);
498 OutCode[OutCount++] = Suffix[CurCode];
499 CurCode = Prefix[CurCode];
502 /* The last code in the chain is treated as raw data. */
504 FinChar = CurCode & BitMask;
505 OutCode[OutCount++] = FinChar;
507 /* Now we put the data out to the Output routine.
508 * It's been stacked LIFO, so deal with it that way...
511 for (i = OutCount - 1; i >= 0; i--)
512 AddToPixel(OutCode[i]);
515 /* Build the hash table on-the-fly. No table is stored in the file. */
517 Prefix[FreeCode] = OldCode;
518 Suffix[FreeCode] = FinChar;
521 /* Point to the next slot in the table. If we exceed the current
522 * MaxCode value, increment the code size unless it's already 12. If it
523 * is, do nothing: the next code decompressed better be CLEAR
527 if (FreeCode >= MaxCode)
533 ReadMask = (1 << CodeSize) - 1;
543 fprintf(stderr, "done\n");
544 fprintf(stderr," %d colors used\n",numused);
550 if (ColorDicking(display) != GIF_Success)
551 return(GIF_ColorFailed);
558 /* Fetch the next code from the raster data stream. The codes can be
559 * any length from 3 to 12 bits, packed into 8-bit bytes, so we have to
560 * maintain our location in the Raster array as a BIT Offset. We compute
561 * the byte Offset into the raster array by dividing this by 8, pick up
562 * three bytes, compute the bit Offset into our 24-bit chunk, shift to
563 * bring the desired code to the bottom, then mask it off and return it.
566 static int ReadCode()
568 int RawCode, ByteOffset;
570 ByteOffset = BitOffset / 8;
571 RawCode = Raster[ByteOffset] + (0x100 * Raster[ByteOffset + 1]);
573 RawCode += (0x10000 * Raster[ByteOffset + 2]);
574 RawCode >>= (BitOffset % 8);
575 BitOffset += CodeSize;
576 return(RawCode & ReadMask);
580 static void AddToPixel(byte Index)
583 *(ImageData + YC * BytesPerScanline + XC) = Index;
591 /* Update the X-coordinate, and if it overflows, update the Y-coordinate */
595 /* If a non-interlaced picture, just increment YC to the next scan line.
596 * If it's interlaced, deal with the interlace as described in the GIF
597 * spec. Put the decoded scan line out to the screen if we haven't gone
598 * past the bottom of it
647 static int ColorDicking(Display *display)
649 /* we've got the picture loaded, we know what colors are needed. get 'em */
652 static byte lmasks[8] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80};
654 int screen = DefaultScreen(display);
655 Colormap cmap = DefaultColormap(display,screen);
656 int dispcells = DisplayCells(display,screen);
663 /* no need to allocate any colors if no colormap in GIF file */
665 /* Allocate the X colors for this picture */
669 /* nostrip was set. try REAL hard to do it */
670 for (i=j=0; i<numcols; i++)
674 defs[i].red = Red[i]<<8;
675 defs[i].green = Green[i]<<8;
676 defs[i].blue = Blue[i]<<8;
677 defs[i].flags = DoRed | DoGreen | DoBlue;
678 if (!XAllocColor(display,cmap,&defs[i]))
681 defs[i].pixel = 0xffff;
683 cols[i] = defs[i].pixel;
689 /* failed to pull it off */
694 dc = (dispcells<256) ? dispcells : 256;
697 "failed to allocate %d out of %d colors. Trying extra hard.\n",
700 /* read in the color table */
703 XQueryColors(display,cmap,ctab,dc);
705 /* run through the used colors. any used color that has a pixel
706 value of 0xffff wasn't allocated. for such colors, run through
707 the entire X colormap and pick the closest color */
709 for (i=0; i<numcols; i++)
710 if (used[i] && cols[i]==0xffff)
712 /* an unallocated pixel */
717 mdist = 100000; close = -1;
723 d = abs(r - (ctab[j].red>>8)) +
724 abs(g - (ctab[j].green>>8)) +
725 abs(b - (ctab[j].blue>>8));
734 return(GIF_ColorFailed);
736 bcopy(&defs[close],&defs[i],sizeof(XColor));
737 cols[i] = ctab[close].pixel;
739 } /* end 'failed to pull it off' */
743 /* strip wasn't set, do the best auto-strip */
748 lmask = lmasks[strip];
749 for (i=0; i<numcols; i++)
753 defs[i].red = (Red[i] &lmask)<<8;
754 defs[i].green = (Green[i]&lmask)<<8;
755 defs[i].blue = (Blue[i] &lmask)<<8;
756 defs[i].flags = DoRed | DoGreen | DoBlue;
757 if (!XAllocColor(display,cmap,&defs[i]))
759 cols[i] = defs[i].pixel;
770 XFreeColors(display,cmap,cols+i,1,0L);
778 fprintf(stderr,"%s: stripped %d bits\n",progname,strip);
783 fprintf(stderr,"UTTERLY failed to allocate the desired colors.\n");
784 for (i=0; i<numcols; i++) cols[i]=i;
789 for (i=0; i<Height; i++)
790 for (j=0; j<Width; j++,ptr++)
791 *ptr = (byte) cols[*ptr];
797 /******************************************************************************
798 * This makes sure the display's depth is the same as the
799 * depth of the default 8 bit image. If not, we build a new image
800 * that has the correct depth. This works on the fact that
801 * the color mapper has already changed every pixel value in the
802 * image into the proper number of bits (to fit into the pallet)
803 * so we can just chop down the number of bits.
804 * This changes the global variable 'expImage' if necessary.
807 static int ConvertXImageDepth(Display *display, XImage **image)
809 int screen = DefaultScreen(display);
810 int depth = DefaultDepth(display, screen);
817 printf("ConvertXImageDepth:\n");
818 printf("(*image)->depth == %d\n",
820 printf("DefaultDepth(display, screen) == %d\n",
821 DefaultDepth(display, screen));
826 if ((*image)->depth != depth)
828 XImage *old_image, *new_image;
830 Visual *visual = DefaultVisual(display,screen);
832 int width = (*image)->width;
833 int height = (*image)->height;
834 register int dwx, dwy;
841 printf("ConvertXImageDepth: ---------> CONVERTING...\n");
848 data = (byte *)malloc(width * height * depth);
852 new_image = XCreateImage(display,visual,depth,
853 ZPixmap,0,data,width,height,8,0);
856 new_image = XGetImage(display,RootWindow(display,screen),
857 0,0,width,height,0xffffffff,ZPixmap);
861 return(GIF_NoMemory);
863 if (old_image->depth == 8 && new_image->depth == 4)
865 /* speedup for the most common format change */
867 register byte *sptr = (byte *)old_image->data;
868 register byte *dptr = (byte *)new_image->data;
870 for (dwy=1; dwy<=height; dwy++)
872 for (dwx=1; dwx<width; dwx+=2)
874 *dptr = (*sptr) | (*(sptr+1)<<4);
880 /* if extra pixal at end of line, just move it */
886 else /* other format change than 8 bit -> 4 bit */
888 unsigned long pixel_value;
890 for (dwx=0; dwx<width; dwx++)
892 for (dwy=0; dwy<height; dwy++)
894 pixel_value = XGetPixel(old_image, dwx, dwy);
896 if (pixel_value > 0xff)
897 printf("pixel = %lx", pixel_value);
899 XPutPixel(new_image, dwx, dwy, pixel_value);
904 free(old_image->data);
905 old_image->data = NULL;
906 XDestroyImage(old_image);
915 static unsigned long be2long(unsigned char *be) /* big-endian -> long int */
917 return((be[0]<<24) | (be[1]<<16) | (be[2]<<8) | be[3]);
920 static unsigned short be2short(unsigned char *be) /* big-endian -> short int */
922 return((be[0]<<8) | be[1]);
925 static struct IFF_ILBM_BMHD *ConvertBMHD(unsigned char *header_data)
927 struct IFF_ILBM_BMHD_big_endian *bmhd_be;
928 struct IFF_ILBM_BMHD *bmhd;
930 bmhd_be = (struct IFF_ILBM_BMHD_big_endian *)header_data;
931 bmhd = (struct IFF_ILBM_BMHD *)malloc(sizeof(struct IFF_ILBM_BMHD));
935 bmhd->Width = be2short(bmhd_be->Width);
936 bmhd->Height = be2short(bmhd_be->Height);
937 bmhd->LeftEdge = be2short(bmhd_be->LeftEdge);
938 bmhd->TopEdge = be2short(bmhd_be->TopEdge);
939 bmhd->Depth = (int)bmhd_be->Depth;
940 bmhd->Mask = (int)bmhd_be->Mask;
941 bmhd->Compression = (int)bmhd_be->Compression;
942 bmhd->pad1 = bmhd_be->pad1;
943 bmhd->transparentColor = be2short(bmhd_be->transparentColor);
944 bmhd->xAspect = (int)bmhd_be->xAspect;
945 bmhd->yAspect = (int)bmhd_be->yAspect;
946 bmhd->pageWidth = be2short(bmhd_be->pageWidth);
947 bmhd->pageHeight = be2short(bmhd_be->pageHeight);
952 static unsigned char MSBitFirst2LSBitFirst(unsigned char msb_byte)
954 unsigned char lsb_byte = 0;
959 lsb_byte |= (msb_byte & 1) << i;
966 int Read_ILBM_to_Bitmap(Display *display, char *filename, Pixmap *pixmap)
968 Pixmap new_pixmap = 0;
969 int screen = DefaultScreen(display);
970 Drawable root = RootWindow(display,screen);
971 struct IFF_ILBM_FORM_big_endian *form_header;
972 struct IFF_ILBM_BMHD *bitmap_header;
973 unsigned long file_len, body_len;
974 unsigned char *file_data, *bitmap_data;
975 unsigned char *file_ptr, *bitmap_ptr, *body_ptr;
976 unsigned char byte_count, byte_value;
978 int width, height, depth;
979 int bytes_per_line, bitmap_size;
986 printf("Read_ILBM_to_Bitmap\n");
991 if (!(file = fopen(filename,"r")))
992 return(ILBM_OpenFailed);
994 if (fseek(file,0,SEEK_END) < 0)
997 return(ILBM_ReadFailed);
1000 file_len = ftell(file);
1003 if (!(file_data = (unsigned char *)malloc(file_len)))
1006 return(ILBM_NoMemory);
1009 if (fread(file_data,1,file_len,file) != file_len)
1013 return(ILBM_ReadFailed);
1018 form_header = (struct IFF_ILBM_FORM_big_endian *)file_data;
1020 if (strncmp(form_header->magic_FORM,"FORM",4) ||
1021 file_len != be2long(form_header->chunk_size)+8 ||
1022 strncmp(form_header->magic_ILBM,"ILBM",4))
1025 printf("%s: IFF chunk 'FORM' and/or 'ILBM' not found.\n",filename);
1028 return(ILBM_FileInvalid);
1031 bitmap_header = NULL;
1033 file_ptr = file_data + 12;
1035 while(file_ptr < (unsigned char *)(file_data + file_len))
1037 if (!strncmp(file_ptr,"BMHD",4))
1040 printf("%s: IFF chunk 'BMHD' found.\n",filename);
1042 bitmap_header = ConvertBMHD(file_ptr + 8);
1043 file_ptr += be2long(file_ptr + 4) + 8;
1046 else if (!strncmp(file_ptr,"BODY",4))
1049 printf("%s: IFF chunk 'BODY' found.\n",filename);
1051 body_ptr = file_ptr + 8;
1052 body_len = be2long(file_ptr + 4);
1053 file_ptr += be2long(file_ptr + 4) + 8;
1059 printf("%s: IFF chunk '%c%c%c%c' found (but not used).\n",filename,
1060 file_ptr[0],file_ptr[1],file_ptr[2],file_ptr[3]);
1062 /* other chunk not recognized here */
1063 file_ptr += be2long(file_ptr + 4) + 8;
1068 if (!bitmap_header || !body_ptr)
1071 printf("%s: IFF chunk 'BMHD' and/or 'BODY' not found.\n",filename);
1074 return(ILBM_FileInvalid);
1077 width = bitmap_header->Width;
1078 height = bitmap_header->Height;
1079 depth = bitmap_header->Depth;
1083 printf("%s: %d bitplanes found; using only the first plane.\n",
1087 bytes_per_line = ((width + 15) / 16) * 2;
1088 bitmap_size = bytes_per_line * height;
1090 bitmap_data = (char *)malloc(bitmap_size);
1094 free(bitmap_header);
1095 return(ILBM_NoMemory);
1098 bitmap_ptr = bitmap_data;
1099 for(i=0;i<bitmap_size;i++)
1102 for(y=0;y<height;y++)
1104 /* we only read the first bitplane here to create a black/white bitmap */
1106 for(z=0;z<depth;z++)
1108 bitmap_ptr = bitmap_data + y * bytes_per_line;
1111 if (!bitmap_header->Compression)
1113 while(x++ < bytes_per_line)
1114 *bitmap_ptr++ |= MSBitFirst2LSBitFirst(*body_ptr++);
1118 while(x < bytes_per_line)
1120 byte_count = *body_ptr++;
1122 if (byte_count <= 128)
1124 for(i=0;i<byte_count+1;i++)
1125 *bitmap_ptr++ |= MSBitFirst2LSBitFirst(*body_ptr++);
1126 x += byte_count + 1;
1130 byte_value = *body_ptr++;
1131 for(i=0;i<257-byte_count;i++)
1132 *bitmap_ptr++ |= MSBitFirst2LSBitFirst(byte_value);
1133 x += 257 - byte_count;
1140 bitmap_ptr = bitmap_data;
1141 for(i=0;i<bitmap_size;i++)
1142 *bitmap_ptr++ ^= 0xff;
1144 new_pixmap = XCreateBitmapFromData(display,root,bitmap_data,width,height);
1148 free(bitmap_header);
1151 return(ILBM_NoMemory);
1153 *pixmap = new_pixmap;
1154 return(ILBM_Success);