nothings / stb

stb single-file public domain libraries for C/C++
https://twitter.com/nothings
Other
25.99k stars 7.67k forks source link

stb_image.h: compute correct palette entry count for 12 byte BMP headers #1494

Open mackyle opened 1 year ago

mackyle commented 1 year ago

When the old format 12-byte BMP header is used, palette entries are 3 bytes each rather than 4 bytes each.

When computing the number of entries, the size of the header must be subtracted before dividing by 3.

The size of the header in this case is 12 which may also be found in the info.hsz field.

Replace the incorrect hard-coded value of 24 with info.hsz (which will be 12 in this case) otherwise the last 12 bytes of the palette ends up being ignored (12 / 3 => the last 4 palette entries) and any references to them read garbage.