Path: utzoo!mnetor!uunet!husc6!bloom-beacon!mit-eddie!uw-beaver!apollo!oj
From: oj@apollo.uucp (Ellis Oliver Jones)
Newsgroups: comp.windows.x
Subject: Re: Bitmap File format
Message-ID: <3bf4836f.d5b2@apollo.uucp>
Date: 9 May 88 21:58:00 GMT
References: <9478@sol.ARPA>
Reply-To: oj@canyon.UUCP (Ellis Oliver Jones)
Organization: Apollo Computer, Chelmsford, MA
Lines: 37

In article <9478@sol.ARPA> stuart@cs.rochester.edu writes:
>I have a question about the X11 format of (C-language) bitmap files.
...
>Which is the correct format for encoding N < 8 bits?

Here's how the source for XCreateBitmapFromData (.../lib/X/XCrBFData.c) defines
the format for the bitmap data (the same stuff as in X11 format 
bitmap files, of course).   I've added annotations.

    ximage.height = height;                number of rows
    ximage.width = width;                  number of columns
    ximage.depth = 1;                      number of bits/pixel
    ximage.xoffset = 0;                    unused pixels at beginnings of rows
    ximage.format = ZPixmap;               "pixel-mode" image, not "plane-mode"
    ximage.data = data;                    pointer to user-furnished data
    ximage.byte_order = LSBFirst;          least significant byte first (footnote*)
    ximage.bitmap_unit = 8;                data is byte organized (footnote*)
    ximage.bitmap_bit_order = LSBFirst;    least significant bit in each byte
                                               is leftmost in Drawable (footnote **)
    ximage.bitmap_pad = 8;                 scanlines are padded to ends of bytes)
    ximage.bytes_per_line = (width+7)/8;   offset from scanline to scanline

Footnote*  Because the data is byte-organized, byte_order makes no difference.  Hooray!
footnote** This means the bits (left-->right) are packed from low-order-->high-order
           in each byte.  When a byte is not filled completely with bits 
           from the bitmap, it is (due to the bitmap_pad setting) filled 
           up with padding.

Image-handling is one of the nicest innovations in X11:  you set up your image, and
declare its characteristics (byte-order, bit-order, packing,...) in the Ximage structure.
The bitmap-file handling calls are layered directly on the image calls.

Then, the procedures behind the XGetPixel and XPutPixel macros pay attention
to the characteristics you declare.  So does XPutImage, which draws
the image in a Drawable.

/Ollie Jones