/* * DEC XIE 2.3 client built against DEC's own libXie sources. * * XieCreateImage -> XieCreatePhoto -> XiePutTile -> XieExport * * Usage: decclient */ #include #include #include #include #include #include #include /* the client never calls the DDX dispatch table; satisfy the linker */ unsigned long (*xieDdxProc[1])() = { 0 }; /* Read a drawable back from the SERVER (not from the framebuffer) and report * how many pixels are set. This is server-side truth: if the tile is there, * the server drew it and the remaining problem is only the framebuffer mapping; * if it is zero, the export produced nothing at all. */ static void readback(Display *dpy, Drawable d, int w, int h, const char *label) { XImage *im; int x, y, ones = 0, total = 0; im = XGetImage(dpy, d, 0, 0, w, h, AllPlanes, ZPixmap); if (!im) { printf(" %s: XGetImage FAILED\n", label); fflush(stdout); return; } for (y = 0; y < h; y++) for (x = 0; x < w; x++) { total++; if (XGetPixel(im, x, y) != 0) ones++; } printf(" %s: %d/%d pixels set (first row bits: ", label, ones, total); for (x = 0; x < 8 && x < w; x++) printf("%ld", XGetPixel(im, x, 0) ? 1L : 0L); printf(")\n"); fflush(stdout); XDestroyImage(im); } int main(int argc, char **argv) { Display *dpy; Window win; GC gc; XSetWindowAttributes swa; XieImage img; XiePhotomap pm; unsigned long lvl[3]; unsigned int fill; int w = 64, h = 64, nbytes, org; if (argc < 3) { fprintf(stderr, "usage: %s \n", argv[0]); return 2; } fill = (unsigned int) strtoul(argv[2], NULL, 16); org = argc > 3 ? atoi(argv[3]) : XieK_BandByPlane; dpy = XOpenDisplay(argv[1]); if (!dpy) { fprintf(stderr, "cannot open %s\n", argv[1]); return 1; } printf("display %s opened (root depth %d)\n", argv[1], DefaultDepth(dpy, DefaultScreen(dpy))); lvl[0] = lvl[1] = lvl[2] = 2; img = XieCreateImage((unsigned long) w, (unsigned long) h, XieK_PCM, (unsigned char) org, XieK_Bitonal, 1, lvl, XieK_PP0, XieK_LP270); if (!img) { fprintf(stderr, "XieCreateImage failed\n"); return 1; } printf("image: org=%d w=%lu h=%lu levels=%lu,%lu,%lu arSize=%d\n", org, Width_(img), Height_(img), CmpLvl_(img,0), CmpLvl_(img,1), CmpLvl_(img,2), (int) uArSize_(img, 0)); if (!uBase_(img, 0)) { nbytes = (int) uArSize_(img, 0); if (nbytes <= 0) nbytes = (w + 7) / 8 * h; uBase_(img, 0) = (unsigned char *) calloc(1, nbytes); uArSize_(img, 0) = nbytes; OwnData_(img) = 1; } nbytes = (int) uArSize_(img, 0); printf("filling %d bytes with %02X\n", nbytes, fill); memset(uBase_(img, 0), fill, nbytes); pm = XieCreatePhoto(dpy, XieK_Photomap, (unsigned long) w, (unsigned long) h, XieK_Bitonal, 1, lvl, XieK_ZeroDark, 1.0, XieK_BandByPlane, XieK_BandByPlane); if (!pm) { fprintf(stderr, "XieCreatePhoto failed\n"); return 1; } printf("photomap created\n"); XSync(dpy, False); XiePutTile(pm, img, XieK_AllPlanes, 0, 0, 0, 0, (unsigned long) w, (unsigned long) h); XSync(dpy, False); printf("put tile sent\n"); fflush(stdout); swa.background_pixel = 0; swa.event_mask = ExposureMask; win = XCreateWindow(dpy, DefaultRootWindow(dpy), 150, 200, w, h, 0, CopyFromParent, InputOutput, CopyFromParent, CWBackPixel | CWEventMask, &swa); XMapWindow(dpy, win); XSync(dpy, False); gc = XCreateGC(dpy, win, 0, NULL); XSync(dpy, False); if (argc > 4 && atoi(argv[4]) == 9) { /* control run: window mapped, NO export at all */ printf("NO EXPORT (baseline)\n"); fflush(stdout); readback(dpy, win, w, h, "window (no export)"); } else if (argc > 4 && atoi(argv[4]) == 2) { /* DEC's IDS pattern: crop element on the photomap, tap it, export the tap * into a pixmap (ids_build_xie_pipe.c: XieTapFlo(XieCrop(Photo_,0),True)) */ /* The photoflo must exist and the photomap be bound to it before the * element chain can be built (crash without it: XieTapFlo derefs a * flo link that XieCrop never set). */ XiePhoto flo = XieCreatePhoto(dpy, XieK_Photoflo, (unsigned long) w, (unsigned long) h, XieK_Bitonal, 1, lvl, XieK_ZeroDark, 1.0, XieK_BandByPlane, XieK_BandByPlane); printf("photoflo=%lx\n", (unsigned long) flo); fflush(stdout); XieBindMapToFlo(flo, pm); XSync(dpy, False); printf("bound map to flo\n"); fflush(stdout); XiePhoto crop = XieCrop(flo, 0); printf("crop=%lx\n", (unsigned long) crop); fflush(stdout); XiePhoto tap = XieTapFlo(crop, 1); printf("tap=%lx\n", (unsigned long) tap); fflush(stdout); Pixmap px = XCreatePixmap(dpy, win, w, h, 1); GC pgc = XCreateGC(dpy, px, 0, NULL); XSync(dpy, False); printf("crop=%lx tap=%lx\n", (unsigned long) crop, (unsigned long) tap); fflush(stdout); XieExport(tap, px, pgc, 0, 0, 0, 0, w, h, 0, 0, 0.0, 0.0); XSync(dpy, False); printf("export sent (tap->pixmap)\n"); fflush(stdout); XCopyArea(dpy, px, win, gc, 0, 0, w, h, 0, 0); XSync(dpy, False); printf("copyarea sent\n"); fflush(stdout); } else if (argc > 4 && atoi(argv[4]) == 1) { Pixmap pmap = XCreatePixmap(dpy, win, w, h, 1); XSync(dpy, False); printf("exporting to PIXMAP depth 1\n"); fflush(stdout); /* Clear the pixmap to a known value so the readback is unambiguous. */ XSetForeground(dpy, gc, 0L); XFillRectangle(dpy, pmap, gc, 0, 0, w, h); XSync(dpy, False); readback(dpy, pmap, w, h, "pixmap after clear(=0)"); XieExport(pm, pmap, gc, 0, 0, 0, 0, w, h, 0, DefaultColormap(dpy, DefaultScreen(dpy)), 0.0, 0.0); XSync(dpy, False); printf("export sent (pixmap)\n"); fflush(stdout); readback(dpy, pmap, w, h, "pixmap after export"); readback(dpy, win, w, h, "window before copy"); XCopyArea(dpy, pmap, win, gc, 0, 0, w, h, 0, 0); XSync(dpy, False); printf("copyarea sent\n"); fflush(stdout); readback(dpy, win, w, h, "window after copy"); } else { XieExport(pm, win, gc, 0, 0, 0, 0, w, h, 0, DefaultColormap(dpy, DefaultScreen(dpy)), 0.0, 0.0); XSync(dpy, False); printf("export sent (with colormap)\n"); readback(dpy, win, w, h, "window after direct export"); } fflush(stdout); sleep(6); XCloseDisplay(dpy); return 0; }