Menu ▾ ▴

#45 FreeImage_ConvertTo32Bits performance hit

closed
None
5
2012-10-31
2010-05-22
Lucian Sabo
No

FreeImage_ConvertTo32Bits() from Conversion32.cpp has an important performance hit by calling the function FreeImage_IsTransparent in loops which causes some overhead.

You can define a boolean variable outside the loops like

BOOL bIsTransparent = FreeImage_IsTransparent(dib);.

then use it instead of calling the function.

The speed gain is 10-20%..

Discussion

  • Lucian Sabo

    Lucian Sabo - 2010-05-23

    Further more, having two loops over each pixels can be avoided.
    Currently there are two separate functions, each looping over the cols for each row
    FreeImage_ConvertLine#To32 - actual conversion
    MapTransparentTableToAlpha# - transparency mapping

    I merged these functions to have a single loop. You can simply modify FreeImage_ConvertLine#To32
    to include two additional parameters for transparency like this

    FreeImage_ConvertLine#To32MapTransparency(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, palette, transparency_table, transparency_count);

    For example instead of

    case 8:
    {
    for (int rows = 0; rows < height; rows++) {
    FreeImage_ConvertLine8To32(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib));

                    if (bIsTransparent) {
                        MapTransparentTableToAlpha8((RGBQUAD *)FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), FreeImage_GetTransparencyTable(dib), FreeImage_GetTransparencyCount(dib), width);
                    }
                }
    

    You can have just:

    case 8:
    {
    for (int rows = 0; rows < height; rows++) {

                    FreeImage_ConvertLine8To32MapTransparency(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, palette, transparency_table, transparency_count);
    
                    }
                }
    

    I am attaching the modified functions.

     
  • Lucian Sabo

    Lucian Sabo - 2010-05-23

    Modified Line conversion functions to handle transparency as well

     
  • Hervé Drolon

    Hervé Drolon - 2010-05-26

    I will add this to my TODO list.
    I see a little problem here : you modified the signature of functions exposed by the FI interface : this would mean an incompatibility with previous FI 3.x versions, unless we also add some deprecated functions ...

     
  • Hervé Drolon

    Hervé Drolon - 2010-05-30

    I've added your patch to the CVS with some little modifications so that the FI Interface is not changed.
    Hervé

     
  • SourceForge Robot

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     

Anonymous
Anonymous

Add attachments
Cancel