1 
2 // This include is meant to be the body of the function ResetXX,
3 // which is implemented exactly the same for different resolutions. For
4 // compatibility reasons this is controlled by Defines instead of templates.
5 // Therefor the following type definitions are set to the required values,
6 // while compiling that function:
7 //
8 // #define DATA_TYPE unsigned char
9 // #define DATA_PAD  1
10 
11 
12 DATA_TYPE	*xdata;
13 
14 // create buffer for Image-Data
15 // there is an optimization in the rotation-routine, which sometimes tries
16 // to access data beyond the allocated image, that might lead to a segmentation
17 // violation. Therefore, it might be good to allocated some additional
18 // rows of data for the image.
19 
20 	extern int scanline_pad;
21 
22 	int byte_pad = scanline_pad / 8;
23 
24 	offset_bytes=xwidth*offset_rows*DATA_BYTES;
25 	// xdata=new DATA_TYPE[xwidth*(xheight+2*offset_rows)];
26 
27 	xdata=(DATA_TYPE*)new char[DATA_BYTES*xwidth*(xheight+2*offset_rows)];
28 	{	DATA_TYPE	*xdata_run=xdata;
29 		unsigned long blk_pixel=BlackPixel(dpy,scr);
30 		for (int i=xwidth*(xheight+2*offset_rows);i>0;i--) {
31 			// *xdata_run++=(DATA_TYPE)blk_pixel;
32 			*xdata_run=(DATA_TYPE)blk_pixel; // align fault
33 			char *my_xdata_run = (char *)xdata_run;
34 			my_xdata_run += DATA_BYTES;
35 		}
36 	}
37 	xdata+=(offset_bytes/DATA_BYTES);
38 
39 	if (!xdata) {
40 		fprintf(stderr,"not enough memory for XImage-data");
41 		exit(-1);
42 	}
43 
44 // create the XImage
45 
46 	ximage = XCreateImage(dpy, DefaultVisual(dpy,scr),
47 			DefaultDepth(dpy,scr), ZPixmap, 0,
48 			(char*)xdata, xwidth, xheight, scanline_pad,
49 			((xwidth*DATA_BYTES + byte_pad - 1)/byte_pad) * byte_pad);
50 
51 	if (!ximage) {
52 		fprintf(stderr,"\n*** can't allocate ximage.\n" );
53 		exit(0);
54 	}
55 
56 // copy data from original image and inserting pixel values on the fly
57 	if (Width()==xwidth&&Height()==xheight) {
58 		register DATA_TYPE	*copy = xdata;
59 		register const byte	*org  = Data();
60 		register int	j,i;
61 
62 		extern int pixmap_depth;
63 
64 		switch(pixmap_depth) {
65 		case 8:		// power of two covered by basic data type
66 		case 16:
67 		case 32:
68 			for (i=0; i<Height(); i++) {
69 				for (j=0; j<Width(); j++)
70 					*copy++ = (DATA_TYPE)gif_cols[*org++];
71 			}
72 			break;
73 		case 24:
74 			for (i=0; i<Height(); i++) {
75 				for (j=0; j<Width(); j++)
76 					XPutPixel(ximage,j,i,gif_cols[*org++]);
77 			}
78 			break;
79 		}
80 	}
81 	else {
82 		for (int y=0;y<xheight;y++) {
83 			register const byte	*org  = Data() + (y*Height()/xheight) * Width();
84 			register DATA_TYPE *copy = xdata + y * xwidth;
85 
86 			if (xwidth<Width()) {
87 				register int x;
88 				register int delta = Width()/2;
89 
90 				for (x=Width();x>0;x--) {
91 					delta-=xwidth;
92 					if (delta<0) {
93 						delta+=Width();
94 						*copy++ = (DATA_TYPE)gif_cols[*org];
95 					}
96 					org++;
97 				}
98 			}
99 			else {
100 				register int x;
101 				register int delta = xwidth/2;
102 
103 				for (x=xwidth;x>0;x--) {
104 					delta-=Width();
105 					*copy++ = (DATA_TYPE)gif_cols[*org];
106 					if (delta<0) {
107 						delta+=xwidth;
108 						org++;
109 					}
110 				}
111 			}
112 		}
113 	}
114 
115 	ximage->data = (char*)xdata;
116 
117 //	XPutImage(dpy,pixmap,p->gc_all,ximage,0,0,0,0,xwidth,xheight);
118