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.
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:

Variable | Description
WORD type | The signature of the file format. Must be BM
DWORD size | Size of the file
DWORD reserved | ...
DWORD offset | Offset of the data from this position. Must be 40
DWORD headersize | The size of the rest of the header
DWORD width | Width of the image
DWORD height | Height of the image
WORD planes | Planes of the bitmap
WORD bitsperpixel | number of bits per pixel
DWORD compression | Type of compression used
DWORD sizeimage | Size of the image data
DWORD xpixelpermeter | Number of horizontal pixel per meter
DWORD ypixelpermeter | Number of vertical pixel per meter
DWORD colorsused | Number of colors used
DWORD colorsimportant | Number 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
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:

Variable | Description
BYTE manufacturer | Costant flag 10 = ZSoft .PCX
BYTE version | Version information
BYTE encoding | 1= .PCX run length encoding
BYTE bitsperpixel | Number of bits/pixel per plane
WORD xmin | Picture dimensions
WORD ymin | ...
WORD xmax | ...
WORD ymax | ...
WORD hres | Horizontal resolution of creating device
WORD vres | Vertical resolution of creating device
char colormap[48] | Color palette setting (EGA)
BYTE reserved |
BYTE nplanes | Number of colors planes
WORD bytesperline | Number of bytes per scan line per color plane (always even for .PCX files)
WORD paletteinfo | How 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 Get your own Free Home Page