Public Group

# Wierd Bitmap Format? (New Question)

This topic is 4905 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am trying to read the first line of a bitmap's data using simple file I/O, and the header information works fine, yet I seem to run into a logical error: When I read the bitmap using a hex editor, I found out it started on the first pixel of the last line... Are the rows being stored in a flipped order? How do I properly access the first row? Bitmap: 1081x9 24-bit EDIT: The new question is in my latest post [Edited by - deadimp on August 13, 2005 7:26:50 PM]

##### Share on other sites
The short answer is, yes, the rows are stored starting with the bottom row first. To read in the image, you just read it one row at a time, copying the first row to the bottom row of your surface and working your way up.

PS - I haven't the slightest idea why Microsoft made Bitmap formats work this way. If someone would enlighten us, I would appreciate it.

##### Share on other sites
Quote:
 Original post by nimrandThe short answer is, yes, the rows are stored starting with the bottom row first. To read in the image, you just read it one row at a time, copying the first row to the bottom row of your surface and working your way up.PS - I haven't the slightest idea why Microsoft made Bitmap formats work this way. If someone would enlighten us, I would appreciate it.

if i remember correctly that was adopted because it was slightly faster to process and has some connection the the OS-2 compatibility era.

##### Share on other sites
The bitmap structure allows data to be stored both ways top to bottom and bottom to top, from what I remember when we covered bitmaps there should be a tag bit somewhere that lets you know which way the data is stored, check the docs on msdn.

##### Share on other sites
The sign of the height of the bitmap determines how whether or not the bitmap is top down or bottom up.

Quote:
 From MSDNIf biHeight is positive, the bitmap is a bottom-up DIB and its origin is the lower-left corner. If biHeight is negative, the bitmap is a top-down DIB and its origin is the upper-left corner.If biHeight is negative, indicating a top-down DIB, biCompression must be either BI_RGB or BI_BITFIELDS. Top-down DIBs cannot be compressed.

##### Share on other sites
New Question: How do I determine the Pitch (Width in bytes) of a bitmap using the data from the bitmap's file? For some reason, I am also getting some padding in the image, around 8 extra pixels on the row... (IMG: 811x9, biHeight is negative)

##### Share on other sites
Bitmap files in Windows NT and later are required to have the lines to be DWORD aligned, i.e. evenly divisible by 4 unless it is RLE encoded.

##### Share on other sites
Thanks for the help. (I'm about to test it)

EDIT: Holy crap... It worked! Thanks for all of y'alls help.
Resulting code:
ULONG Pitch=Width*3;if (Pitch % 4!=0) Pitch=(Pitch/4)*4+4; //Make sure it is aligned

[Edited by - deadimp on August 14, 2005 12:55:16 PM]

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 13
• 9
• 9
• 15
• ### Forum Statistics

• Total Topics
634078
• Total Posts
3015363
×