Search code examples
windowsimagebmpimage-editingdib

Modifying BMP color palette and saving as correct format


An old abandonware game uses an image's color palette as the game's color palette https://ufile.io/su465 <- Here is said file

Windows 10 does not recognize it as having a file type, but using online file-type checkers suggests its a Windows 3.x BMP file having a DIB file header. I would appreciate assistance in figuring out how to go about modifying this file's color palette and being able to save it in the (same) correct format, so that it is still readable by the game.

Initial experiments show that it can be opened with an editor such as GIMP, the palette changed, and saved as a .bmp image, but I cannot find any settings which produce a .bmp of the same format as the original and thus it is read incorrectly.


Solution

  • It's a 23x23 bitmap using 1-byte per pixel.

    The first 14 bytes of the file are the BITMAP header itself. (yellow)

    The subsequent 40 bytes are the DIB header representing a serialized BITMAPINFOHEADER struct that identifies the images as a 23x23 image using no compression and 8 bit per pixel. (red underline)

    The next 1024 bytes is the color palette. 256 entries. Each entry takes 4 bytes. That is an RGB (or is it BGR?) followed by zero byte. (Blue)

    Then the image bytes, which is 23 rows of 24 bytes each. Rows have to align on 4 byte boundaries. (Black)

    So if you want to replace the image palette, fill in the 1024 bytes starting at offset 0x36 with your own pallete data.