Menu

FreeImage_SwapColors not working on palletized image

Developers
KanedaFr
2014-07-07
2014-07-08
  • KanedaFr

    KanedaFr - 2014-07-07

    Hi,

    I think I found something strange with FreeImage_SwapColors.
    If I have a pallete with these values [blue, red, green, yellow, orange]
    and use FreeImage_SwapColors(dib, &pal[0], &pal[3], TRUE), the result is
    [yellow, red, green, yellow, orange] and not
    [yellow, red, green, blue, orange]

    Looking at FreeImage_ApplyColorMapping source code made me think the swap is similar to
    srccolor = dstcolor
    dstcolor = srccolor
    related to misuse of pointers which, obviously, doesn't work.

    So I had to made the swap myself with

        palette = FreeImage_GetPalette(dib);
        //not working
        //FreeImage_SwapColors(dib, &palette[0], &palette[transparency], TRUE);
        palTmp.rgbBlue = palette[transparency].rgbBlue;
        palTmp.rgbGreen = palette[transparency].rgbGreen;
        palTmp.rgbRed = palette[transparency].rgbRed;
    
        palette[transparency].rgbBlue = palette[0].rgbBlue;
        palette[transparency].rgbGreen = palette[0].rgbGreen;
        palette[transparency].rgbRed = palette[0].rgbRed;
    
        palette[0].rgbBlue = palTmp.rgbBlue;
        palette[0].rgbGreen = palTmp.rgbGreen;
        palette[0].rgbRed = palTmp.rgbRed;
    

    hope this will help to fix this issue

    OF course, if I missed something, just tell me and forgive me ;)

    KanedaFr

     
  • Hervé Drolon

    Hervé Drolon - 2014-07-08

    Hi,

    FreeImage_SwapColors expect 2 RGBQUADs pointers on entry but also expect that these pointers have no link with the palette array (also true for FreeImage_ApplyColorMapping).
    That's why your test case doesn't work.

    We could add a check for pointers and handle your use case, or explicitly document the fact that input RGBQUADs parameters should have no link with the palette array.

    Hervé

     

Log in to post a comment.