Skip to main content
gamedev.net
🔒 Locked

Another Bitmap File Format ?...

Started by RegularKid 1 reply 200+ views
Original Post
RegularKid
RegularKid
Ok. One more bitmap file format question. I can load everything in fine (including loading in the palette). However, I am having trouble loading in 16 color images. In a 256 color image I do this:
  
fseek(pFileIn, 0x436, SEEK_SET);
for(int i = 0; i < imageSize; i++)
{
    imageData[i] = fgetc(pFileIn);
}

for(i = 0; i < imageSize; i++)
{
    cout << imageData[i] << ", ";
}
  
The 0x436 is the data offset in a 256 color image. This is because the palette starts at 0x36 (54 bytes into the file). There are 4 bytes per color, so 54 + (4 * 256) = 1078 = 0x436. And this all works fine. So I figured I could do this to load a 16 color image:
  
imageSize = imageSize / 2;
fseek(pFileIn, 0x64, SEEK_SET);
for(int i = 0; i < imageSize; i++);
{
    imageData[i] = fgetc(pFileIn);
}

for(i = 0; i < imageSize; i++)
{
    cout << (imageData[i] & 0xF) << ", ";
    cout << ((imageData[i] >> 4) & 0xF) << ", ";
}
  
I cut the image size in half because there are 4 bits per pixel so two pixels can fit in a byte. And the 0x64 is because 54 + (4 * 16) = 118 = 0x64. However, this doesn''t seem to work. Can anyone help?
RegularKid
RegularKid
*bump* Does anyone know what I''m doing wrong?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.