Re: [Algorithms] OT: How to read a bitmap of arbitrary size?
Brought to you by:
vexxed72
From: Pai-Hung C. <pa...@ac...> - 2000-08-13 18:36:34
|
Hi, That explains everything! :-) Thanks a lot! But could you explain what's the meaning of ((bytes_per_pixel * pixels_per_row) + 3) & (~3), specifically the ...+ 3) & (~3) part? Thank you, Pai-Hung Chen > For Windows BMP files, the pitch must be a multiple of 4 bytes. 5 pixels * 3 > bytes = 15 bytes is not a multiple of 4! In such cases, the BMP format uses > the next higher value (that is multiple 4) as the pitch. In this specific > case, the next higher value that is a multiple of 4, is 16. Thus the Windows > BMP format uses a pitch of 16 bytes. > So for a 5x5 BMP you have 5 * (((3 * 5) + 3) & (~3)) = 5 * 16 = 80 bytes. > (Note, that the additional byte is unused). > > In order to compute the pitch for a bit-count >= 8, you can use the > following formula: > pitch = ((bytes_per_pixel * pixels_per_row) + 3) & (~3) > > biSizeImage then is: biSizeImage = pitch * num_pixel_rows > > HTH, > Niki > > ----- Original Message ----- > From: Pai-Hung Chen <pa...@ac...> > To: <gda...@li...> > Sent: Sunday, August 13, 2000 6:57 PM > Subject: [Algorithms] OT: How to read a bitmap of arbitrary size? > > > > Hi, > > > > I have been frustratingly bugged for hours and I decide to resort to the > > list. I want to read a 24-bit bitmap heightfield. I can correctly read > it > > as long as the dimension of the bitmap file is in 2's power such as 4x4, > > 8x8, 16x16, etc. (But 2x2 doesn't work?!) In these _normal_ cases, the > > *biSizeImage* field of the BITMAPINFOHEADER structure gives me the correct > > size of image in bytes. However, if I create a bitmap of non-2's-power > > dimension such as 5x5, 6x6, 7x7, etc., the *biSizeImage* field gives me > some > > bogus number. For example, 5x5 yields 80 bytes (5x5x3 = 75 bytes); 6x6 > > yields 120 bytes (6x6x3 = 108 bytes); 7x7 yields 168 bytes (7x7x3 = 147 > > bytes). Could somebody tell me what happened? > > > > Thanks in advance, > > > > Pai-Hung Chen > > > > > > > > _______________________________________________ > > GDAlgorithms-list mailing list > > GDA...@li... > > http://lists.sourceforge.net/mailman/listinfo/gdalgorithms-list > > > > > _______________________________________________ > GDAlgorithms-list mailing list > GDA...@li... > http://lists.sourceforge.net/mailman/listinfo/gdalgorithms-list > > |