Game Programming with DGJPP
Graphics by The Dark Angel

The Graphics Files Format
The Bitmap Files
Under Windows is very famous the bitmap graphics format (the .BMP files). All the graphics editor support this format for storing images because is simple to use. The only defect is that use a lot of space.
Bitmap header The figure shows the format of the bitmap file: we can see that we have a 54 bytes header, 1024 bytes for the palette and last the image data. This image data is large than the size of the image; so if we have an 800x600x256 image, the data use nearly 500Kb! Here are the description of the header:

VariableDescription
WORD typeThe signature of the file format. Must be BM
DWORD sizeSize of the file
DWORD reserved...
DWORD offsetOffset of the data from this position. Must be 40
DWORD headersizeThe size of the rest of the header
DWORD widthWidth of the image
DWORD heightHeight of the image
WORD planesPlanes of the bitmap
WORD bitsperpixelnumber of bits per pixel
DWORD compressionType of compression used
DWORD sizeimageSize of the image data
DWORD xpixelpermeterNumber of horizontal pixel per meter
DWORD ypixelpermeterNumber of vertical pixel per meter
DWORD colorsusedNumber of colors used
DWORD colorsimportantNumber of colors considered important


The palette information is stored in RGB format, but, instead a sequence of Red, Green and Blue is stored in a sequence of Blue, Green and Red (BGR). So we must read the palette byte per byte and divide each value by 4 because Windows use a range of 0..255 instead of 0..63. The image is stored in a sequence of lines, but the first line is the last stored, and the last line is the first in the file. Each line is longer than the width of the image plus some bytes for round the length in a multiple of 4. For example if we have an image of 53 pixel of width each line is long 56 bytes. So we must remember to read and ignore the last 4 - (width % 4) bytes of each lines. See the demo program for the code.

The PCX Files
PCX header Another file format is the ZSoft .PCX, simple to use and a bit compressed. The file start with a header of 128 bytes that contains all the necessary informations for using the images, comprised the palette for the EGA. After the header we have the image, compressed with the method called run length encoded, where instead of storing a sequence of equals byte is stored the count of repetitions and next the value of the byte. At least there are the VGA palette, stored with the RGB format. For more informations email me and I'll send you a more detailed description. There are the format of the header:

VariableDescription
BYTE manufacturerCostant flag 10 = ZSoft .PCX
BYTE versionVersion information
BYTE encoding1= .PCX run length encoding
BYTE bitsperpixelNumber of bits/pixel per plane
WORD xminPicture dimensions
WORD ymin...
WORD xmax...
WORD ymax...
WORD hresHorizontal resolution of creating device
WORD vresVertical resolution of creating device
char colormap[48]Color palette setting (EGA)
BYTE reserved 
BYTE nplanesNumber of colors planes
WORD bytesperlineNumber of bytes per scan line per
color plane (always even for .PCX files)
WORD paletteinfoHow to interpret palette 1=color/BW 2=grayscale
char filler[58]Blank to fill out 128 bytes header


See the demo program for the source code of the algorithm that load and decode a pcx file.


[main] [prec] [next] [email]

Site Made and Maintained by The Dark Angel <DarkAngel@tin.it>
My ICQ Number is 2063026
You Visited This Page times


This page hosted by Geocities Icon Get your own Free Home Page