GEM Raster

Also Known As: IMG

Type Bitmap
Colors 16,384
Compression RLE, uncompressed
Maximum Image Size 64Kx64K
Multiple Images Per File No
Numerical Format Big-endian
Originator Digital Research, now part of Novell
Platform GEM, MS-DOS, Atari ST
Supporting Applications

DR Paint, DR Doodle, Publishers Paintbrush, and GEM-based applications. Versions of the MS-DOS-based Ventura Publisher were distributed bound to GEM that served mainly to provide GUI services to the application. Many programs on the Atari ST.

See Also None

Primarily useful in GEM-based application environments.

A poorly documented format (in the sense that documentation is hard to come by) in wide use only on the Atari ST platform. It lacks a superior compression scheme and support for included color information. There are at least two versions in existence.

Vendor specifications are available for this format.

Code fragments are available for this format.

Sample images are available for this format.

GEM Raster (also known as IMG) is the native image storage format for the Graphical Environment Manager (GEM), developed and marketed by Digital Research. GEM made its way into the market through OEM bundling deals, special run-time versions bound to products, and as the native operating environment of at least one system, the Atari ST. GEM image files have been important in the PC desktop publishing community due to the bundling deal between Digital Research and the creators of Ventura Publisher, a widely used desktop publishing application.

File Organization
File Details
For Further Information

Although GEM was a contender in the GUI wars some years back, Digital Research's fortunes in this arena declined, and the company was eventually purchased by Novell. Prior to this, however, GEM was distributed by a number of PC hardware manufacturers along with their systems and thus enjoyed a certain currency. GEM raster images may be color, gray scale, or black and white and are always read and written in the big-endian format. Note that several different file formats use the file extension .IMG, a fact that causes confusion in some applications designed to read only GEM raster (IMG) files.

File Organization

Like many other simple bitmap formats, GEM raster files start with a fixed-length header, followed by bitmap data.

File Details

GEM raster files use a 16- or 18-byte header in the following format:

typedef struct _GemRaster
WORD   Version;         /* Image File Version (Always 1h) */
WORD   HeaderLength;    /* Size of Header in WORDs */
WORD   NumberOfPlanes;  /* Number of Planes */
WORD   PatternLength;   /* Pattern Definition Length */
WORD   PixelWidth;      /* Pixel Width in Micros */
WORD   PixelHeight;     /* Pixel Height in Micros */
WORD   ScanLineWidth;   /* Image Width in Pixels */
WORD   NumberOfLines    /* Image Height in Scan Lines */
WORD   BitImageFlag;    /* Multi-plane GrayColor Flag */

Version always has a value of one.

HeaderLength is either 8 or 9; if the value is 8, there is no BitImageFlag field in the header.

NumberOfPlanes contains the number of bits per pixel of the image source device (a scanner, for instance). This value is typically 1.

PatternLength contains a run-count value, which is usually 1. Any pattern code found in the encoded image data is repeated this number of times.

PixelHeight and PixelWidth are the pixel size in microns and are often 85 (55h), corresponding to 1/300 inch, or 300 dpi. The scale of the image may also be determined by using these pixel size values.

ScanLineWidth and NumberOfLines describe the size of the image in lines and pixels.

BitImageFlag indicates whether a multiplane image is color or gray scale. If the BitImageFlag field is present in the header (indicated by a value of 9 in the HeaderLength field) and the image data contains multiple planes (indicated by a value of 2 or greater in the NumberOfPlanes field), a value of 0 indicates color image data and a value of 1 indicates gray-scale image data. If a multiplane image has an 8-field header, then the image is displayed in gray-scale from a fixed, 16-color palette by default. If the image has a 9-field header and only a single plane, the value in the BitImageFlag field is ignored. BitImageFlags was used by GEM-based versions of Ventura Publisher.

The GEM 16-color palette contains the following RGB values:

3f, 3f, 3f
3f, 00, 00
00, 3f, 00
3f, 3f, 00
00, 00, 3f
3f, 00, 3f
00, 3f, 3f
2b, 2b, 2b
15, 15, 15
2b, 00, 00
00, 2b, 00
2b, 2b, 00
00, 00, 2b
2b, 00, 2b
00, 2b, 2b
00, 00, 00

The GEM 8-bit gray-scale standard palette consists of the following values:

ff 7f bf 3f df 5f 9f 1f ef 6f af 2f cf 4f 8f 0f
f7 77 b7 37 d7 57 97 17 e7 67 a7 27 c7 47 87 07
fb 7b bb 3b db 5b 9b 1b eb 6b ab 2b cb 4b 8b 0b 
f3 73 b3 33 d3 53 93 13 e3 63 a3 23 c3 43 83 03 
fd 7d bd 3d dd 5d 9d 1d ed 6d ad 2d cd 4d 8d 0d
f5 75 b5 35 d5 55 95 15 e5 65 a5 25 c5 45 85 05
f9 79 b9 39 d9 59 99 19 e9 69 a9 29 c9 49 89 09
f1 71 b1 31 d1 51 91 11 e1 61 a1 21 c1 41 81 01 
fe 7e be 3e de 5e 9e 1e ee 6e ae 2e ce 4e 8e 0e 
f6 76 b6 36 d6 56 96 16 e6 66 a6 26 c6 46 86 06
fa 7a ba 3a da 5a 9a 1a ea 6a aa 2a ca 4a 8a 0a
f2 72 b2 32 d2 52 92 12 e2 62 a2 22 c2 42 82 02 
fc 7c bc 3c dc 5c 9c 1c ec 6c ac 2c cc 4c 8c 0c 
f4 74 b4 34 d4 54 94 14 e4 64 a4 24 c4 44 84 04 
f8 78 b8 38 d8 58 98 18 e8 68 a8 28 c8 48 88 08
f0 70 b0 30 d0 50 90 10 e0 60 a0 20 c0 40 80 00

Image data in GEM raster files is always encoded using a simple run-length encoding (RLE) scheme. Data is always encoded and decoded one byte at a time, and there are always eight bits of image data per pixel. For this reason, scan lines are always a multiple of eight pixels in width and are padded when necessary. If the image data contains two or more bits per pixel, then the image will have multiple bit planes.

There are four types of codes in the GEM raster RLE format: vertical replication codes, literal run codes, pattern codes, and encoded run codes. Complicating this RLE scheme is the fact that each of these four codes is a different size, as shown below.

Vertical Replication Code 00 00 FF <Run Count>
Literal Run Code 80 <Run Count 1 to 7F>
<'Run Count' Bytes>
Pattern Code 00 <Pattern Length>
Black Run Code <MSB = 1> <7 LSB = RunCount>
White Run Code <MSB = 0> <7 LSB = RunCount>

A vertical replication code contains the values 00h 00h FFh, followed by a one-byte count. The count is the number of times to repeat the line that is about to be decoded. A count of one indicates two identical, consecutive lines. A vertical replication code may only appear at the beginning of a scan line. If a replication code is not present at the beginning of a scan line, the line is not repeated.

Literal runs are contiguous lines of pixels that are not encoded. They are written to the encoded data stream as they appear in the bitmap. Literal runs usually appear in encoded image data because data compression had little effect on the pixel data, and it was not efficient to encode the pixels as a run. A literal run code begins with the byte value 80h and is followed by a byte that holds the count value. Following the count are a number of bytes equal to the count value that should be copied literally from the encoded data to the decoded data.

A pattern code begins with the byte 00h and is followed by a byte containing the pattern length. That length is followed by the pattern itself, replicated the number of times specified by the Pattern Length field in the header. Pattern codes are similar to literal run codes, in that the data they contain is not actually compressed in the encoded image data.

Encoded run codes contain only runs of either black or white pixels and are by far the most numerous of all the codes in IMG RLE image data. Black-and-white runs are encoded as a 1-byte packets. Encoded run packets are never 00h or 80h in value. These values are reserved to mark the start of vertical replication codes, pattern codes, and literal run codes. If a byte is read and is not equal to 00h or 80h, the most significant bit indicates the color of the run. If the most significant bit is 1, all the pixels in the run are set to 1 (black). If the most significant bit is 0, the pixels in the run are set to 0 (white). The seven least significant bits in the encoded run are the number of bits in the run. The run may contain 1 to 127 bits.

If an image contains multiple planes, each plane is encoded as the next consecutive scan line of data. One scan line of a four-plane image is encoded as four scan lines of data. The order of the planes is red, green, blue, and intensity value.

The following segment of an encoded scan line:

00 00 FF 05  07  8A  02  80 04 2A 14 27 C9  00 03 AB CD EF

represents a vertical replication code of five scan lines, a run of seven white bytes (56 pixels), a run of 10 black bytes, (80 pixels), a run of two white bytes (16 pixels), a literal run of four bytes, and pattern code three bytes in length.

For Further Information

The GEM raster format originated at Digital Research, which is now owned by Novell and is currently being supported by DISCUS Distribution Services, a service organization. Note that DISCUS will provide support only if you have first purchased the GEM Programmers's Toolkit from Digital Research. Contact DISCUS at:

DISCUS Distribution Services, Inc.
8020 San Miguel Canyon Road
Salinas, CA 93907-1208
Voice: 408-663-6966

You may be able to get some information from Novell/Digital Research at:

Novell/Digital Research, Inc.
P.O. Box DRI
Monterey, CA 93942
Voice: 408-649-3896
Voice: 800-848-1498
BBS: 408-649-3896

We have also been able to include information on Atari support of the GEM raster format on the CD-ROM.

Copyright © 1996, 1994 O'Reilly & Associates, Inc. All Rights Reserved.

Hosted by uCoz