Lably
Skip to content

X BitMap

  • 3 min read
  • 2 chapters

Related on Lably

Through Icon (computing), Graphical user interface and Pixel

Format

XBM files differ markedly from most image files in that they take the form of C source files. This means that they can be compiled directly into an application without any preprocessing steps, but it also makes them far larger than their raw pixel data. The image data is encoded as a comma-separated list of byte values, each written in the C hexadecimal notation, '0x13' for example, so that multiple ASCII characters are used to express a single byte of image information.

XBM data consists of a series of static unsigned char arrays containing the monochrome pixel data. When the format was in common use, an XBM typically appeared in headers (.h files) which featured one array per image stored in the header. The following piece of C code exemplifies the XBM file Blarg displayed in the panel at right:

<span id="mwLA"></span><span class="cp" id="mwLQ">#define test_width 16</span> <span class="cp" id="mwLg">#define test_height 7</span> <span class="k" id="mwLw">static</span><span class="w" id="mwMA"> </span><span class="kt" id="mwMQ">unsigned</span><span class="w" id="mwMg"> </span><span class="kt" id="mwMw">char</span><span class="w" id="mwNA"> </span><span class="n" id="mwNQ">test_bits</span><span class="p" id="mwNg">[]</span><span class="w" id="mwNw"> </span><span class="o" id="mwOA">=</span><span class="w" id="mwOQ"> </span><span class="p" id="mwOg">{</span> <span class="mh" id="mwOw">0x13</span><span class="p" id="mwPA">,</span><span class="w" id="mwPQ"> </span><span class="mh" id="mwPg">0x00</span><span class="p" id="mwPw">,</span><span class="w" id="mwQA"> </span><span class="mh" id="mwQQ">0x15</span><span class="p" id="mwQg">,</span><span class="w" id="mwQw"> </span><span class="mh" id="mwRA">0x00</span><span class="p" id="mwRQ">,</span><span class="w" id="mwRg"> </span><span class="mh" id="mwRw">0x93</span><span class="p" id="mwSA">,</span><span class="w" id="mwSQ"> </span><span class="mh" id="mwSg">0xcd</span><span class="p" id="mwSw">,</span><span class="w" id="mwTA"> </span><span class="mh" id="mwTQ">0x55</span><span class="p" id="mwTg">,</span><span class="w" id="mwTw"> </span><span class="mh" id="mwUA">0xa5</span><span class="p" id="mwUQ">,</span><span class="w" id="mwUg"> </span><span class="mh" id="mwUw">0x93</span><span class="p" id="mwVA">,</span><span class="w" id="mwVQ"> </span><span class="mh" id="mwVg">0xc5</span><span class="p" id="mwVw">,</span><span class="w" id="mwWA"> </span><span class="mh" id="mwWQ">0x00</span><span class="p" id="mwWg">,</span><span class="w" id="mwWw"> </span><span class="mh" id="mwXA">0x80</span><span class="p" id="mwXQ">,</span> <span class="mh" id="mwXg">0x00</span><span class="p" id="mwXw">,</span><span class="w" id="mwYA"> </span><span class="mh" id="mwYQ">0x60</span><span class="w" id="mwYg"> </span><span class="p" id="mwYw">};</span>

In place of the usual image-file-format header, XBM files has two or four #define statements. The first two #defines specify the height and width of the bitmap in pixels. The second two, if any, specify the position of any hotspot within the bitmap. (In the case of bitmapped cursors, the "hotspot" refers to the position of the cursor "point", generally at 0,0.)

XBM image data consists of a line of pixel values stored in a static array. Because a single bit represents each pixel (0 for white or 1 for black), each byte in the array contains the information for eight pixels, with the upper left pixel in the bitmap represented by the low bit of the first byte in the array. If the image width does not match a multiple of 8, the extra bits in the last byte of each row are ignored.

Sign in to keep reading

One more chapter is free with a Lably account.

More in Computing and communication