I'm not sure if this is the right place to ask this but I couldn't think of anywhere else.
I'm writing an app where I'm wanting to convert raw byte data into bitmaps. I did a bit of reading about the bitmap file format before I attempted writing this and I've created an app which spits out the two headers required, the palette (I'm converting the data into an 8bit image with an indexed palette) and then the data. Because it's 8bpp I can just write the raw data out, with one exception. Every scan line in a bitmap needs to be divisible by 4 bytes (32 bits). So I just mod the width of the image by four and then stick on that many zeros at the end of each line.
This works absolutely perfectly for images whos width is an even number. But as soon as I try and give it an image with an odd numbered width it doesn't work. The image in question is 17 pixels by 9 pixels. So my app sticks a single byte on the end of each row to top it up to 18, which I would imaging was correct. Everything seems to be correct when I read in the converted image in a hex editor. The headers are correct and the data seems correct in that it's exactly the same as the raw data except it has an extra byte after every 17 pixels.
I've spent ages trying to find out what the problem is and in the end I opened the raw data in paint shop pro and saved it out as an 8bpp bitmap with the correct palette and analysed this in my hex editor. Now, it seems that PSP sticks THREE bytes on the end of each row, instead of one. Why on earth does it do this? I've read numerous articles on the BMP file format and I can't find out why this is so but I think this could be part of my problem.
Does anyone have any idea?