[comp.windows.x] XImage slowness

rbd@lamont.ldgo.columbia.edu (roger davis) (08/22/89)

Thanks to all who responded to my request for help
in speeding up XImage pixel operations. The answer
(provided by rws) is (a) wait for R4, which promises
major speedups in XImage pixel ops, or (b) access
pixels directly, rather than using XPutPixel().

Being impetuous, I did (b). The following code, when
executing the newly-added #ifdefs, decreases the processing
time of a 512x512 8-bit color image on a Sun 4/280
from ~8 minutes to ~8 **seconds**.

extern Display *dpy;
extern Visual visual;
extern int width, height;

create_image()
{
	int line, col;
	char *pix;
	unsigned long pixel;
	XImage *image;

	image= XCreateImage(dpy, &visual, 8, ZPixmap, 0, (char *) NULL, width, height, 8, 0);
	image->data= calloc((unsigned) (image->bytes_per_line*height), sizeof(char));

	for (line= 0; line < height; line++) {

#ifdef sun
		pix= image->data+(line*image->bytes_per_line);
#endif

		for (col= 0; col < width; col++) {

			pixel= (unsigned long) ... whatever you want
#ifdef sun
			*pix= (char) pixel;
			pix++;
#else
			XPutPixel(image, col, line, pixel);
#endif
		}
	}
}
-- 
Roger Davis
Lamont-Doherty Geological Observatory
rbd@lamont.ldgo.columbia.edu