This is the personal website of Garthee, who believes it is the perspiration not the perception that brings the success

Search:     All roads lead to ROME !  

Be Miracle!

BMP file data extraction

Following the BMP standard [1], file size, data size and data start, height (in pixels), width (in pixel), depth (bits) and compression were read from the header of the file. An odd behavior was noted. A file may contain extra bits at the end of each line, which is not included in width information. Hence to find offsets it is better to use (size – start) / height to find the actual length of the information of a row.

Another peculiar feature of BMP file is when height is specified in positive figure (which is the most common) the last row of the image is written first and the first row at the end. i.e. an inverted mirror image is stored. Hence to print the first row, it had to be read from (start + ( height -1) row_length )

Further, in order to support both the endiness, a bit reversal operation needed, which was implemented in a macro, instead of a for loop or function to save the additional over head that would have occurred otherwise [2]

BMP file standard [1]

 (from http://atlc.sourceforge.net/bmp.html#_toc381201084 )

offset

field

size

contents

0002h

file size

1 dword

File size in bytes.

000ah

bitmap data offset

1 dword

Offset from beginning of file to
the beginning of the bitmap data. (start)

0012h

width

1 dword

Horizontal width of bitmap in
pixels.

0016h

height

1 dword

vertical height of bitmap in
pixels.

001ah

planes

1 word

Number of planes in this bitmap.

001ch

bits per pixel

1 word

depth

 

001eh

compression

1 dword

compression

0022h

bitmap data size

1 dword

size of the bitmap data

Bit reversal [2]


#define RBIT(val) (((unsigned)(val) & 128) >> 7 \
| ((unsigned)(val) & 64) >> 5 \
| ((unsigned)(val) & 32) >> 3 \
| ((unsigned)(val) & 16) >> 1 \
| ((unsigned)(val) & 8) << 1 \
| ((unsigned)(val) & 4) << 3 \
| ((unsigned)(val) & 2) << 5 \
| ((unsigned)(val) & 1) << 7 )

AttachmentSize
bmp2.zip322.24 KB