Search code examples
bitmapcustomizationnotepad++file-format

What bitmap format does Notepad++ use for its icons (so I can change them)?


I'm using Notepad++ to do most of my coding currently. However, I'd like to change its icons, just for customization sake really.

So what I did was to open the .exe with Resource Hacker, and see where the icons were. They seem to be in bitmap format, which is weird because they have transparency, and replacing them with any "Bitmap" (BM header, "Windows Bitmap") format I know of doesn't work (the icon isn't shown).

So I'd like to ask, which format are these files in, and how can I produce them?

Sample of the bitmaps can be found in the Notepad++ repository:
newFile http://sourceforge.net/p/notepad-plus/code/735/tree/trunk/PowerEditor/src/icons/newFile.bmp?format=raw openFile http://sourceforge.net/p/notepad-plus/code/735/tree/trunk/PowerEditor/src/icons/openFile.bmp?format=raw saveFile http://sourceforge.net/p/notepad-plus/code/735/tree/trunk/PowerEditor/src/icons/saveFile.bmp?format=raw saveAll http://sourceforge.net/p/notepad-plus/code/735/tree/trunk/PowerEditor/src/icons/saveAll.bmp?format=raw closeFile http://sourceforge.net/p/notepad-plus/code/735/tree/trunk/PowerEditor/src/icons/closeFile.bmp?format=raw closeAll http://sourceforge.net/p/notepad-plus/code/735/tree/trunk/PowerEditor/src/icons/closeAll.bmp?format=raw

As you can see, they have a grey matte, which makes me think the alpha channel is stored in the format in some non-standard way. (or, it has binary transparency, and #C0C0C0 means transparent).

It is also fairly large, having more than 5 bytes per each pixel represented (!).

This is how the header of the first bitmap above looks:

Hex Workshop

Any idea? Just knowing what format this is would be enough.


Solution

  • This is an 8BPP (8 bits per pixel) indexed bitmap. After the "BM" there is a 52-byte header, a palette of 256 colours, and the indexed pixel data. Each colour is 4 bytes, in BGR_ format (the fourth byte isn't used; if it was an alpha channel, you would see FF instead of 00).

    The indexed pixel data starts at 0x436. It's simple: one byte represents one index in the palette. For example, the first few bytes are 07 07 18 18. The 0x07 will make that pixel use the 8th colour in the palette, which is #C0C0C0; and the 0x18 will make that pixel use the 25th colour in the palette, which is #CECECE.

    I'm guessing that transparency is handled as you guessed. I see 07 wherever a transparent pixel would be, and the corresponding colour in the palette is #C0C0C0.

    Note that the pixel data is stored upside-down. That is, the first 16 bytes at offset 0x436 represent the bottom row of pixels.

    It's explained in more detail here: http://en.wikipedia.org/wiki/BMP_file_format#File_structure

    EDIT: As for how to produce them, just ask your favourite image editing software to export the image as a 256-colour bitmap (or an 8BPP bitmap, whichever is available). Note that Microsoft Paint will mangle the colours if you save it after drawing it, so save it before you actually draw anything.