PDA

View Full Version : Junk Data in a .bmp file?



ngill
06-28-2001, 02:09 PM
Hi, a while back for some practice I wrote a .bmp file reader... it worked perfectly or so i thought. The thing is it works when it's reading height=2^n width=2^n, but when width=height=some odd number... it doesn't load them up right.

After some debugging I found out that

bitsPerPixel*Width*Height != (image size defined in the file)

[my 5x5 picture's size was 80 bytes, instead of 75]

but it's supposed to be!! And when I displayed the contents of the file byte by byte, i found a bunch of 0s in places... but there seemed to be a pattern for zeros... any ideas? Is there junk data in bmp image?

(I created my .bmp files using GIMP)

DFrey
06-28-2001, 02:18 PM
That kind of filler data is common in many types of files. It just requires you to be strict about reading in the files as precisely as the header indicates.

Tron
06-28-2001, 11:14 PM
every line has to be doubleword-aligned (4 byte), so u get 0 till 3 'junk-bytes'

example 1:
5x7 24bit rgb
needed line size: 5 * 3 = 15 bytes ( * 7 = 105)
real size: 16 bytes (1 junk byte) ( * 7 = 112)

example 2:
5x7 8bit indexed
needed line size: 5 * 1 = 5 bytes ( * 7 = 35)
real size: 8 bytes (3 junk bytes) (* 7 = 56)

speaking of palette indexed pictures: every palette entry is 4 bytes in size, not 3!
order: BLUE, GREEN, RED, UNUSED

hope that helps (: