- Window win = RootWindow (dpy, 0);
- GC gc2 = XCreateGC (dpy, win, 0, &gcv);
- XSetForeground (dpy, gc2, BlackPixel (dpy, 0));
- XSetBackground (dpy, gc2, WhitePixel (dpy, 0));
- XCopyPlane (dpy, p, win, gc2, 0, 0, w, h, 0, 0, 1);
- XFreeGC (dpy, gc2);
- XSync(dpy, False);
- usleep (100000);
+ char file[255];
+ XImage *image;
+ int x, y;
+ FILE *ff;
+ sprintf (file, "/tmp/%02d.pgm", which);
+ image = XGetImage (dpy, p, 0, 0, w, h, ~0L, ZPixmap);
+ ff = fopen (file, "w");
+ fprintf (ff, "P5\n%d %d\n255\n", w, h);
+ for (y = 0; y < h; y++)
+ for (x = 0; x < w; x++) {
+ unsigned long pix = XGetPixel (image, x, y);
+ unsigned long r = (pix & xgwa.visual->red_mask);
+ r = ((r >> 24) | (r >> 16) | (r >> 8) | r);
+ fprintf (ff, "%c", (char) r);
+ }
+ fclose (ff);
+ XDestroyImage (image);
+ fprintf (stderr, "%s: wrote %s (%d x %d)\n", progname, file,
+ f->max_bounds.rbearing - f->min_bounds.lbearing,
+ f->max_bounds.ascent + f->max_bounds.descent);