Strange bitmap loading error

When I was loading the bitmap CAMPNOSC.BMP which has a resolution of 238x143 the created SDL_Surface gets loaded with the size 240x143. So why is the width of the image now 2px wider? That’s really strange. The additional 2px are filled with black. That means at the right side of the image there is a 2px border.

Could anyone test this problem? Thanks. I’ve fixed that problem when I setted the width correctly afterwards at the created SDL_Surface object.

For some reason all images during loading are aligned to have width being a multiple of 4. It’s true for both static images and sprites. I remember I tried to remove this constrain but then I got broken images. Probably I just did something wrong but everything worked correctly with it until now…

When an 8bpp image is loaded, those pixels are filled with the first (or rather 0th) color in palette (see SDL_Surface * CPCXConv::getSurface() const ). It should be transparent, not black. If removing those additional column of pixels fixes your problem and it doesn’t break anything, you can fix it this way.

BTW, SDL 1.2 does not support blitting of 8bpp images with per-pixel alpha onto 24/32bpp images.

All campaign button images and the let’s say the “no campaign placeholder” image are 24-bit images. I’ve extracted all images of the h3bitmap.lod and saw that mostly every image is an 8-bit image except of the ones I mentioned. The campaign buttons have a width which is a power of 4. So to that point everything is fine. But the “no campaign placeholder” image has a width of 238 which isn’t a power of 4. SDL adds 2px to increase width to 240. For a 24bit image it’s black because of missing alpha information.

Thanks for the clue & info, now I know where the problem is. =)

Actually it’s not SDL, we do it in image decompression functions because we saw it in certain decompression algorithm… anyway now I really doubt it’s necessary.

SDL have 4-pixel alignment as well - I’ve found this when worked with def’s.
Call to SDL_CreateRGBSurface(15, 15, …) produces surface with surf->width == 15 but will allocate 16 pixels for each line. Field surf->scanline can be used to determine allocated size. This was the cause of problems with 1366x768 resolution.

Interesting, I didn’t know that… but SDL alignment shouldn’t cause problems with blitting.