NULL bitmap palette of the source image

  • Takamasa Mitsuji

    Hi, all.

    When I try to resize this GIF image by using "FreeImage_Rescale",
    my process terminates with an exception 0xc0000005.

    I found that the exception occurred at
    Source\FreeImageToolkit\Resize.cpp Line 883

    r += (weight * (double)entry[FI_RGBA_RED]);

    the access to "entry" seemed to be a cause of problem.
    I believe that the variable "src_pal" is NULL.

    This image is posted by our customer.
    So i can't judge is this a wrong formatted image ?
    Or is this a bug of FreeImage ?

    My environment detailed:

    FreeImage 3.15.4

    compile with
    "Microsoft Visual Studio 2010 Professional SP1"

    execute with
    "Microsoft Windows XP SP3"
    "Microsoft Windows Web Server 2008 SP2"

  • Takamasa Mitsuji

    I have tried to write a patch for this.

    Last edit: Takamasa Mitsuji 2013-03-27
  • Takamasa Mitsuji

    hmm, this shoud be more safe...

  • Carsten Klein

    Carsten Klein - 2013-03-27

    Hi Takamasa,

    this seems like a problem in either the image or in function GetExtendedColorType. This function should return FIC_PALETTE for any image that actually has a palette, which is NOT a linear FIC_MINISBLACK palette. That is the recommended place for fixing this issue.

    Could you please provide me that image? You can send it to my SF mail address.


  • Takamasa Mitsuji

    Hi Carsten,

    Thank you for your reply. I have emailed the image!

  • Carsten Klein

    Carsten Klein - 2013-04-02

    Hi Takamasa,

    actually, there was a bug in FreeImage's new resizing code, which caused a GPF with transparent images of type FIC_MINISBLACK or FIC_MINISWHITE. However, a patch for that is simple and small. Since I have no write permissions for that source file in the CVS, this patch needs to go through Hervé Drolon, one of the project admins.

    In order to give you a quick solution, here is the patch, which actually consists of 6 lines of code only.

    if (dst_bpp == 32) {
        // additionally, for transparent images we always need a
        // palette including transparency information (an RGBA palette)
        // so, set color_type accordingly.
        color_type = FIC_PALETTE;

    Insert these lines into file Resize.cpp after line 255 (so that the first line above gets line 255 in the patched version). After that, your image resizes as expected.


  • Takamasa Mitsuji

    Hi Carsten,

    I inserted the patch you provide after this line.

        dst_bpp = FreeImage_IsTransparent(src) ? 32 : 8;

    It looks so good.

    Special thanks! You are a kind of god.


    Last edit: Takamasa Mitsuji 2013-04-02
  • Hervé Drolon

    Hervé Drolon - 2013-04-28

    Hi Carsten, Takamasa,

    Thanks for the patch, it is now available in the CVS.



Log in to post a comment.