# Monocolor/8bit BMPs

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

## Recommended Posts

I'm having problems loading 1bit and 8bit bmps. The colors don't load correctly. With 1 bit images, I get big black vertical lines down the image. For example I use this image: It comes out like this when i load it: For 8 bit it comes out as a monochrome image, usingblack and whatever color. I used this image: I comes out like this: The code I used was this: >
if (image.bpp == 1) {
palette = new unsigned char[2*4];
for (int j=7;j>=0;j--) {
int set = ((int)imaged & (2^j)) >> j;
image.image[(i*24)+((7-j)*3)] = palette[(set*4)+2];
image.image[(i*24)+((7-j)*3)+1] = palette[(set*4)+1];
image.image[(i*24)+((7-j)*3)+2] = palette[set*4];
}
}
} else if (image.bpp == 8) {
palette = new unsigned char[256*4];
else
for (int j=i*3;j<i*3+3;j++) {
image.image[j] = palette[(int)imaged*4+(j-(i*3))];
}
}
}


Anyone know what I'm doing wrong, and how i can fix it? By the way, I'm reading the data into 24 bit data. Thanks in advance

##### Share on other sites
2^j does not what you think it does. ^ is the binary XOR operator. You want to do this: 1 << j

For the 8 bit BMP, this looks like it takes only one byte of the rgb-value from the palette instead of all three. You need to assign all three bytes as in the monochrome case.

##### Share on other sites
Wow, how did I forget that? I guess a 2 month break wasn't a good idea lol. Anyway that fixed the problem with 1bits, thanks, but I still can't get the 8bits working, I'm pretty sure it's getting all 3 bytes, but I'll work on it.

##### Share on other sites
Urgh, i think i spot the error now for 8bit:

You're right, you're using all the 3 bytes. Your j for loop just seems awkwardly formulated, actually it is doing from 0 to 2.

The problem is the palette reading:

You correctly interpret the infoheader.numcolors == 0 case and allocate a full 256 entry palette. But then you go ahead and call fread(palette, 1, infoheader.numcolors * 4, file); when infoheader.numcolors is still zero.

• ### What is your GameDev Story?

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

• 16
• 15
• 28
• 12
• 14
• ### Forum Statistics

• Total Topics
634805
• Total Posts
3019365
×