The header size is always 54.
If there is a Palette, it follows the Header.
From IrfanView: output5.bmp has Palette 255:255:255 , 000:000:000 i.e. WHITE,BLACK
I have some x1 bitmaps e.g. truck.bmp
betty_4.bmp is a 4BPP image i.e. 16 colours.
You should be able to examine the Palette in IrfanView.
Likewise, you can take a 24BPP colour JPG, PNG, BMP and reduce it to 8BPP (256 colours) quite well.
Reducing to 4BPP or 1BPP requires a bit of skill. IrfanView does a pretty good job but 1BPP is very difficult to get the "best" look.
I suggest that you look very carefully at your Palette. I would calculate the Palette once. Then you render each pixel directly from the Palette.
My apologies. I copied output5.bmp to an SD. Then displayed via an ESP8266.
It shows as Yellow graphics on a Red background.
I will check my algorithm.
I changed the Palette in IrfanView to give Blue graphics on a Cyan background.
This renders fine.
I will have to compare the file contents. But this will be later this afternoon.
Why don't I get 255 255 255 and 0 0 0, as I would expect from info of IrfanView?
but 255 0 0 and 0 255 0 instead?
Ah-ha. My display must be GREEN graphics on Red background. Not Yellow.
So the algorithm is correct. I must see why IrfanView is different to ImageMagick.
You can see the colorsimportant field at offset 0x0032 means that the Palette uses a different format. i.e. Palette is @ 0x007A [FF FF FF 00] [00 00 00 00] White-Black
The IrfanView Palette is @ 0x0036 [FF FF 00 00] [FF 00 00 00] Cyan-Blue
Here is a Wikipedia article that describes the BMP file format
I suspect that ImageMagick can generate both formats. I wonder whether it is worth the effort to support the extra
An OS/2 2.x OS22XBITMAPHEADER (BITMAPINFOHEADER2 in IBM's documentation) contains 24 additional bytes
David.
p.s. I have just been listening to an excellent play on the Radio about Nikolai Gogol (my hero)
yes, I once had a look at that Wikipedia article, and decided it is too complicated for my practical use, and I stay with code that is widely used for Arduino libraries, e.g. the one I found in your library.
Do you have a practical suggestion how to deal with this for users of our libraries?
I downloaded ImageMagick, but I still need some time to learn how to use it.
Users like @rlightner and others could profit from a workaround.
The reason why I'm doing it the way I am is that the file encoded this way is only 7 kb, but with the other way, comes out to around 138 kb. I'm trying to minimize the sending over the wire to the device. If at the end of the day I just need to take the hit, I will.
I do appreciate all the work you guys have given to the community. It's a great building block for others to create upon!
You can see the colorsimportant field at offset 0x0032 means that the Palette uses a different format.
i.e. Palette is @ 0x007A [FF FF FF 00] [00 00 00 00] White-Black
The IrfanView Palette is @ 0x0036 [FF FF 00 00] [FF 00 00 00] Cyan-Blue
So you just have to read 0x32 and if 2 you seek to 0x007A instead of 0x0036
It should not be more than two lines. e.g.
if (bmpDepth <= PALETTEDEPTH) { // these modes have separate palette
bmpFile.seek(50); //colorsimportant
bmpFile.seek(read32() ? 122 : 54); //important or regular palette
If there are ImageMagick users out there, please could you try creating BMP with different colour depths.
IrfanView recognises the colorsimportant field but does not seem to generate it.
I will post the patch on the BMP examples on the MCUFRIEND_kbv Beta.
@rlightner,
you can edit the drawBitmapFromSpiffs() function in the sketch:
if (depth <= 8)
{
if (depth < 8) bitmask >>= depth;
//file.seek(54); //palette is always @ 54
file.seek(50); //colorsimportant
file.seek(read32() ? 122 : 54); //important or regular palette
Please test your existing file.
If all works ok, I would appreciate it if you go back to ImageMagick
See if you can start with a colour JPG and reduce colours to 256-colour, 16-colour, 2-colour BMP files.
It would be nice if you posted the result. e.g. attach the files in a ZIP
Woo-Hoo. This Win10 PC defaults to PowerShell which is horrible.
I found cmd.exe and everything works nicely.
I have created some BMP files with different color depth. I get different values in the colorsimportant field e.g. 2, 16, 256
But the result is horrible.
I have a lot of learning to do.
IrfanView tends to do this stuff for you e.g. if you ask it to reduce to 16 colours it makes the "best possible" Palette and the end result looks good.
I have made a safer calculation for MCUFRIEND_kbv examples:
if (bmpDepth <= PALETTEDEPTH) { // these modes have separate palette
bmpFile.seek(bmpImageoffset - (4<<bmpDepth)); //54 for regular, diff for colorsimportant
bitmask = 0xFF;
your edit would be:
if (depth <= 8)
{
if (depth < 8) bitmask >>= depth;
file.seek(imageOffset - (4<<depth)); //54 for regular, diff for colorsimportant
//file.seek(54); //palette is always @ 54
Thanks for your sample command. I am struggling with ImageMagick.
I have created tractor_1.bmp tractor_4.bmp tractor_8.bmp with ImageMagick
and created tractor_11.bmp tractor_44.bmp tractor_88.bmp with IrfanView
ImageMagick creates bigger headers on all 3 files. And creates a RLE bitmap for the 256-colour file.
My programs reject the RLE flag as an unsupported format.
I have attached a ZIP.
David.
Edit. Added output6.bmp to ZIP. This was generated by Irfanview with Blue graphics and Cyan background.
Jean-Marc's program should distinguish between the two colours i.e. Cyan->WHITE and Blue->BLACK