# Bitmap Image Loading and Other Noobish Questions

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

## Recommended Posts

So I've had the "Windows Game Programming For Dummies" book by Andre LaMothe for a while, and have already completed a couple games. However until now I've simply copied and pasted his code for loading and displaying bitmaps/sprites. I decided that I should really dig into the code so that I can learn more about images. For the most part it is all making sense but I've got a few questions that I'm hoping someone can help me out with. My first question is this. In his bitmap loading function he handles 8 bpp and 16 bpp bitmaps, but if the file is 24 bpp he converts it to 16 bpp. I'm not sure why this is done. Is it just a personal preference to only use 16 bpp images? Or is it because MS Paint seems to only allow you to save as 24 bit, 256 color, or 16 color bitmaps? On to the second question. When creating the sprite object he uses a variable called width_fill. The comment next to it says "// Internal, used to force 8*x wide surfaces" In the implementation it has this:
if(width%8 != 0)
width_fill = 0;
else
width_fill = (8 - width%8);

When I create bitmap files, their width has to be a multiple of 8, otherwise they appear all distorted, and it appears that this code is the reason. As this is the only time the variable appears in the code (aside from the declaration) and all that happens is it is assigned a value I don't quite understand how this affects anything. Also I think the width variable contains the width of the sprite, not the width of the entire spritesheet bitmap. What advantage does forcing the spritesheet to have a width that is a multiple of 8 pixels have? I hope that makes sense. It's making my brain hurt.

##### Share on other sites
Ciao
If I remember correctly Windows Bitmaps File have a sort of "padding" when the width is not multiple of 8.
Now I've not the code in which the "mistery" is explained (years ago I've spent hours on the same "bug") but you could open a test bitmap in a hex editor (for example you can create a simple black bitmap with a white pixel at the beginning of the second row and see youself the padding used for different widths).

My suggestion:

you have implemented your own routine: this is good because probably you have learned something usefull!
But you may prefer to use an image library to perform I/O operations: there is a lot of libraries to use!

For example you can try Devil: it supports a huge amount of image formats. It's so simple to use to be... embarrassing :-D
And it is stable (most important) and portable on Windows, *nix and Mac OS (for "free").

I'm not saying you are not a skilled programmer but if you do not intend to write another image library: why reinvent the wheel? :-D

You know that windows bitmaps are inefficient, obsolete and not portable: why not use gif, tga or png? If you want you could create an abstract image loading class and use Devil (or a different library) to perform this nasty low level operations.

##### Share on other sites
Quote:
 Original post by Max PianoCiao If I remember correctly Windows Bitmaps File have a sort of "padding" when the width is not multiple of 8.Now I've not the code in which the "mistery" is explained (years ago I've spent hours on the same "bug") but you could open a test bitmap in a hex editor (for example you can create a simple black bitmap with a white pixel at the beginning of the second row and see youself the padding used for different widths).My suggestion:you have implemented your own routine: this is good because probably you have learned something usefull!But you may prefer to use an image library to perform I/O operations: there is a lot of libraries to use!For example you can try Devil: it supports a huge amount of image formats. It's so simple to use to be... embarrassing :-D And it is stable (most important) and portable on Windows, *nix and Mac OS (for "free").I'm not saying you are not a skilled programmer but if you do not intend to write another image library: why reinvent the wheel? :-DYou know that windows bitmaps are inefficient, obsolete and not portable: why not use gif, tga or png? If you want you could create an abstract image loading class and use Devil (or a different library) to perform this nasty low level operations.

Thank you. I was planning on getting more into other image file formats and this sounds like a good place to start.

##### Share on other sites

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

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account