Page 1 of 1

Can't read some BMP files that include a palette

Posted: 2012-11-21T12:16:50-07:00
by Jason S
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.

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)

Re: Can't read some BMP files that include a palette

Posted: 2012-11-21T12:32:33-07:00
by fmw42
This works fine for me on IM 6.8.0.5 Q16 Mac OSX Snow Leopard

convert rgb24pal.bmp PNG24:rgb24pal.png

Re: Can't read some BMP files that include a palette

Posted: 2012-11-23T10:47:06-07:00
by glennrp
Jason, your suggested patch is checked in to SVN revision 10024, and will appear in IM-6.8.0-6. Thanks.