Can't read some BMP files that include a palette
Posted: 2012-11-21T12:16:50-07:00
Here's a 24-bit BMP image that contains a (suggested) palette: rgb24pal.bmp
Test case: convert rgb24pal.bmp test.png
(tested with version 6.8.0-5)
Expected result: A colorful image.
Actual result: An all-black image.
Not all such images fail. It depends on the bit depth, and the palette size.
Here's a patch that seems to fix it.
Test case: convert rgb24pal.bmp test.png
(tested with version 6.8.0-5)
Expected result: A colorful image.
Actual result: An all-black image.
Not all such images fail. It depends on the bit depth, and the palette size.
Here's a patch that seems to fix it.
Code: Select all
coders/bmp.c:817: Change this:
if (bmp_info.number_colors > (1U << bmp_info.bits_per_pixel))
{
if (bmp_info.bits_per_pixel < 24)
ThrowReaderException(CorruptImageError,"UnrecognizedNumberOfColors");
bmp_info.number_colors=0;
}
To:
if (bmp_info.bits_per_pixel < 16 &&
bmp_info.number_colors > (1U << bmp_info.bits_per_pixel))
{
ThrowReaderException(CorruptImageError,"UnrecognizedNumberOfColors");
}
coders/bmp.c:849: Change this:
if ((bmp_info.number_colors != 0) || (bmp_info.bits_per_pixel < 16))
To:
if (bmp_info.bits_per_pixel < 16)