Sunday, January 30, 2011

Reading a bmp image directly in C++ : Part 1

For this we need to first understand the bmp file format

As illustrated by the figure below:

The bitmap image consists of 3 main parts:


1) Header ( Including the signature and the image info data)

2) Colour Profile

3) Image data


Image source: http://en.wikipedia.org/wiki/BMP_file_format

The header data is of size 54 bytes. This can be observed by adding up the size requirements of the individual entries as written below. Also mentioned is the offset value for individual entries. An interesting observation is that the total size is not a multiple of 4 which might create several problems as in most compilers memory is read in chunks of 4 bytes.



offset size description
0 &nbsp&nbsp&nbsp 2 &nbsp&nbsp&nbsp&nbsp&nbspsignature, must be 4D42 hex
2 &nbsp&nbsp&nbsp 4 &nbsp&nbsp&nbsp&nbsp&nbsp size of BMP file in bytes (not very reliable)
6 &nbsp&nbsp&nbsp 2 &nbsp&nbsp&nbsp&nbsp&nbsp reserved, must be zero
8 &nbsp&nbsp&nbsp 2 &nbsp&nbsp&nbsp&nbsp&nbsp reserved, must be zero
10 &nbsp&nbsp 4 &nbsp&nbsp&nbsp&nbsp&nbsp offset to start of image data in bytes
14 &nbsp&nbsp 4 &nbsp&nbsp&nbsp&nbsp&nbsp size of BITMAPINFOHEADER structure, must be 40
18 &nbsp&nbsp 4 &nbsp&nbsp&nbsp&nbsp&nbsp image width in pixels
22 &nbsp&nbsp4 &nbsp&nbsp&nbsp&nbsp&nbsp image height in pixels
26 &nbsp&nbsp2 &nbsp&nbsp&nbsp&nbsp&nbsp number of planes in the image, must be 1
28 &nbsp&nbsp2 &nbsp&nbsp&nbsp&nbsp&nbsp number of bits per pixel (1, 4, 8, or 24)
30 &nbsp&nbsp4 &nbsp&nbsp&nbsp&nbsp&nbsp compression type (0=none, 1=Run Length Encoding (RLE)-8, 2=RLE-4)
34 &nbsp&nbsp4 &nbsp&nbsp&nbsp&nbsp&nbsp size of image data in bytes (including padding, to make it a multiple of 4)
38 &nbsp&nbsp4 &nbsp&nbsp&nbsp&nbsp&nbsp horizontal resolution in pixels per meter
42 &nbsp&nbsp4 &nbsp&nbsp&nbsp&nbsp&nbsp vertical resolution in pixels per meter
46 &nbsp&nbsp4 &nbsp&nbsp&nbsp&nbsp&nbsp number of colours in image, or zero
50 &nbsp&nbsp4 &nbsp&nbsp&nbsp&nbsp&nbsp number of important colours, or zero



(To be continued in next post)

Friday, January 21, 2011

Increasing RAM using a USB drive

A disk cache component called ReadyBoost has been introduced by Microsoft in its two latest offerings Windows Vista and also Windows 7.

Although it is best to physical add new RAM to your system, it is possible to improve the performance by using an external hard drive by about 5-10% using flash memory, a USB flash drive, SD card, CompactFlash or any kind of portable flash mass storage system as a cache.

How to enable Ready Boost in your external disk:

1)Go to My Computer
2)Right click on your device
3)Select Properties
4)Click on the ReadyBoost tab
5)You can select various options/space allotment from there.

How to enable/disable Ready Boost in your system:

1)Go to the Control Panel menu option.
2)Click on Performance Information and Tools
3)Click on Advanced Tools in the left hand navigation bar.
4)Click on Configure my Windows ReadyBoost device
5) Select the options you want.

You can even check the performance imporvement by :


1) Go to Control Panel menu option. Change to classic view options

2) Click on the Administrative Tools icon.

3) Click on Reliability and Performance Monitor icon.

Under the monitoring tools category, click on performance monitor