[alt.graphics.pixutils] SOLUTION: ability to capture color X display and convert to greyscale Postscript

jnelson@gauche.zko.dec.com (Jeff E. Nelson) (12/15/90)

On 6 December 1990, I wrote:
|>I want to capture a Xwindows screen display in color and convert it to
|>greyscale
|>Postscript. It appears that the pbmplus tools can do this:
|>
|>	xwdtoppm file.xwd | ppmtopgm | pgmtops > file.ps
|>
|>The problem is that I can't seem to locate an xwd that xwdtoppm likes.
|>I did
|>find one, but when I ran it's output through xwdtoppm, I get the
|>message:
|>
|>	xwdtoppm: unknown XWD file version: 117440512
[...]
|>In case it matters: this is on a DECstation 3100 running Ultrix 4.0
|>and the
|>DECwindows session and window managers.

I received a few helpful replies. Ian MacPhedran
<macphed@dvinci.USask.CA> said that my environment *does* matter, that
the problem was most likely a byte-ordering one, and that I could either
look around for a patch or use the DECwindows screen-capture facility.
Unfortunately, the DECwindows screen capture did not suit my purposes.

Jim West <west@widgit.enet.dec.com> offered a pointer to an internal
tool called xtops. This worked, but still wasn't quite what I was
looking for.

Finally, I found a set of instructions to patch xwdtoppm.c, which solved
my problem. I have included the patches below, but realize that these
are UNOFFICIAL PATCHES. Apply them at your own risk.

Lesson learned: You can never give too much information when asking for
help. I've always known this, having dealt with problem reports all of
my professional life, but it was reaffirmed here.

The lesson manifested itself in two different ways. First, I added the
environment information almost as an afterthought. This turned out to be
the key to understanding what the real problem was, which lead directly
to the solution.

Second, although two alternatives were offered, none met my needs. My
fault of omission was that I never fully explained what those needs
were: an accurate-as-possible screen capture and transformation that
preserves the 3D shading effect of Motif windows, and correct color to
greyscale conversion.

Here's the patch. Even though it conditionalizes the changes with
"#ifdef mips", I make no claim that it won't break anything that already
works, nor do I claim it will fix anything that's broken. I do claim
that it worked for me.

--------cut here for patch--------
*** xwdtoppm.c.orig     Fri Dec 14 12:14:57 1990
--- xwdtoppm.c  Fri Dec 14 12:16:00 1990
***************
*** 184,190 ****
--- 184,194 ----
            pm_error( "couldn't read X11 XWD file header", 0,0,0,0,0 );
        if ( h11P->file_version != X11WD_FILE_VERSION )
            {
+ #ifdef mips
+           byte_swap = 0;
+ #else
            byte_swap = 1;
+ #endif /*mips*/
            h11P->header_size = bs_long( h11P->header_size );
            h11P->file_version = bs_long( h11P->file_version );
            h11P->pixmap_format = bs_long( h11P->pixmap_format );
***************
*** 242,247 ****
--- 246,257 ----
            {
            if ( fread( &x11col, sizeof(X11XColor), 1, file ) != 1 )
                pm_error( "couldn't read X11 XWD colormap", 0,0,0,0,0 );
+ #ifdef mips
+               x11col.pixel = (x11col.pixel >> 24) |
+                              ((x11col.pixel >> 8) & 0x0000ff00) |
+                              ((x11col.pixel << 8) & 0x00ff0000) |
+                              (x11col.pixel << 24);
+ #else
            if ( *maxvalP != 65535 )
                {
                x11col.red = (long) x11col.red * *maxvalP / 65535;
***************
*** 248,253 ****
--- 258,264 ----
                x11col.green = (long) x11col.green * *maxvalP / 65535;
                x11col.blue = (long) x11col.blue * *maxvalP / 65535;
                }
+ #endif /*mips*/
            PPM_ASSIGN(
                colors[x11col.pixel], x11col.red, x11col.green, x11col.blue );
            }
--------cut here for patch--------

Thanks to everyone who helped, including Jef Poskanzer, author of the
pbmplus utilities, without which none of this would have been possible.

-Jeff E. Nelson
-Digital Equipment Corporation
-Internet: jnelson@tle.enet.dec.com
-Affiliation given for identification purposes only.
-Opinions are mine alone, and are not official
-positions of Digital Equipment Corporation.