Can't read some BMP files that include a palette

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
Jason S
Posts: 103
Joined: 2010-12-14T19:42:12-07:00
Authentication code: 8675308

Can't read some BMP files that include a palette

Post 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)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

This works fine for me on IM 6.8.0.5 Q16 Mac OSX Snow Leopard

convert rgb24pal.bmp PNG24:rgb24pal.png
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

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

Post by glennrp »

Jason, your suggested patch is checked in to SVN revision 10024, and will appear in IM-6.8.0-6. Thanks.
Post Reply