1 const byte *subimage;
2 DATA_TYPE *xdata;
3 XImage	*ximage;				// the image
4 int		xwidth,xheight;	// the size of the image
5 
6 	subimage=p->gif->SubImage(id);
7 
8 // create buffer for Image-Data
9 	xdata=new DATA_TYPE[p->sizex*p->sizey];
10 
11 	if (!xdata) {
12 		fprintf(stderr,"not enough memory for XImage-data");
13 		exit(-1);
14 	}
15 
16 // create the XImage
17 	ximage = XCreateImage(display, DefaultVisualOfScreen(p->screen),
18 				DefaultDepthOfScreen(p->screen), ZPixmap, 0,
19 				(char*)xdata, p->sizex, p->sizey, DATA_PAD, p->sizex*sizeof(DATA_TYPE));
20 	xwidth  = ximage->width;
21 	xheight = ximage->height;
22 
23 	if (!ximage) {
24 		fprintf(stderr,"\n*** can't allocate ximage.\n" );
25 		exit(0);
26 	}
27 
28 // copy data from original image and inserting pixel values on the fly
29 	if (p->gif->PicWidth()==xwidth&&p->gif->PicHeight()==xheight) {
30 		register DATA_TYPE	*copy = xdata;
31 		register int	j,i;
32 
33 		for (i=0; i<p->gif->PicHeight(); i++) {
34 			register const byte	*org  = subimage + (i*p->gif->Cols()*p->gif->PicWidth());
35 			for (j=0; j<p->gif->PicWidth(); j++)
36 				*copy++ = (DATA_TYPE)p->gif_cols[*org++];
37 		}
38 	}
39 	else {
40 		for (int y=0;y<xheight;y++) {
41 			register const byte	*org  = subimage + (y*p->gif->PicHeight()/xheight) * p->gif->PicWidth()*p->gif->Cols();
42 			register DATA_TYPE *copy = xdata + y * xwidth;
43 
44 			if (xwidth<p->gif->PicWidth()) {
45 				register int x;
46 				register int delta = p->gif->PicWidth()/2;
47 
48 				for (x=p->gif->PicWidth();x>0;x--) {
49 					delta-=xwidth;
50 					if (delta<0) {
51 						delta+=p->gif->PicWidth();
52 						*copy++ = (DATA_TYPE)p->gif_cols[*org];
53 					}
54 					org++;
55 				}
56 			}
57 			else {
58 				register int x;
59 				register int delta = xwidth/2;
60 
61 				for (x=xwidth;x>0;x--) {
62 					delta-=p->gif->PicWidth();
63 					*copy++ = (DATA_TYPE)p->gif_cols[*org];
64 					if (delta<0) {
65 						delta+=xwidth;
66 						org++;
67 					}
68 				}
69 			}
70 		}
71 	}
72 
73 	ximage->data = (char*)xdata;
74 
75 	XPutImage(display,pixmap,p->gc_all,ximage,0,0,0,0,xwidth,xheight);
76 
77 	delete xdata;
78 	ximage->data = 0L;
79 	XDestroyImage(ximage);
80