Lets start off this category with the simplest of formats possible. The most basic, uncompressed form of an image, is the Bitmap. As the name indicates, its a simple map of bits (read as a pixels since we are talking of images). We shall first understand the concept of an image here.
An image, is nothing but a certain number of bits dedicated to indicate information for each pixel. We see the available formats being 8-bit, 16-bit, 24-bit, etc. Generally, the three layers that form any colour image, Red, Green and Blue each use 8-bits i.e. 1 byte of colour information ranging from 0 to 255.
Most colour images, are thus use 24 bits per pixel. The image data is stored in memory in the order of pixels labeled below:
09 10 11 12
05 06 07 08
01 02 03 04
i.e. the first 3 bytes (1 pixel information) that one sees in the bit-stream are of the lower left corner pixel, and it proceeds from left to right, and then row by row from the bottom to the top. The byte sized information of each plane is written to the bit-stream as: Blue – Green – Red, Blue – Green – Red, and so on for each pixel.
The above is information when the data-stream actually starts after completion of the header. Files have a header to uniquely identify them and give them the “Open With” software. This is the part that tells your OS to open audio files in audio players and images in image viewers. The BMP File Header Format is well explained at the Wiki page and hence doesn’t need to be discussed in detail here.
Its important to note that we read the header properly. Say, we have at 0022h the starting address of the image data, lasting 4 bytes, and is seen as 50 B5 09 00, this is read as 0009B550h = 636240 bytes in decimal. This is the Little-Endian format of representation. This is a concept that the LSB (Least Significant Byte) is located at the lower address and MSB at the higher address position.
Further, in case of .bmp files, there is a convention that every fresh row, data starts at a multiple of 4 bytes. Thus a padding is inserted (if required) of junk data (generally 00h) at the end of each row. This padding can take any values. In case our image width is 439 pixels = 1317 bytes, this row is appended with a padding of 3 bytes to complete the row size to 1320 bytes, a multiple of 4.
The standard Bitmap files, thus provide absolutely NO compression. This makes it very easy for anyone with basic information about file handling to code a BMP reader / writer.
For further file-type posts, I shall split the post into 2 whenever required, one part dealing with the signal processing and the other with the arrangement of the bit-stream information.