Can I configure freeimage to use less plugins

Help
Anonymous
2009-12-17
2012-10-31
  • Anonymous - 2009-12-17

    Hi, I use freeimage as a static library in win32, and the .lib is very large
    (36M in debug, 17M in release).

    I checked the libs it used, and found that openEXR is very large (openEXR.lib
    is 16M). I don't need to support openexr and many not common format.

    So I want to configure the building process to remove the support of such
    libraries to reduce the totala size.

    Does anyone konw how to get it done ? And if there isn't an easy way to do so,
    I think maybe it is a good idea to add the customization for building
    freeimage.lib / dll.

    Thank you :)

     
  • Mihail Naydenov

    Mihail Naydenov - 2009-12-30

    It should be possible, the best advise I can give you is to study the code.

    Every plug-in is in separate .cpp file in the project, it might be as easy as
    removing it from the build!
    Please try it and send feedback. Thank You.

     
  • Frédéric Jaume

    I succeeded in removing plugins from a freeimage build, and minimize lib size
    and dependencies. I mainly needed PNG, JPG and TARGA, and here is what I did:
    - in FreeImage.h, check the FREE_IMAGE_FORMAT enum, remove all formats your are not interested in, renumber the enums, which gives:

    FI_ENUM(FREE_IMAGE_FORMAT) {
        FIF_UNKNOWN = -1,
        FIF_JPEG        = 0,
        FIF_PNG     = 1,
        FIF_TARGA   = 2,
        FIF_TIFF        = 3,
        FIF_RAW     = 4,
        FIF_PSD     = 5
    };
    

    The TIFF, RAW and PSD need to be there otherwise some sourcefiles will not
    compile.

    • in "Plugin.h" remove all internal plugin "void DLL_CALLCONV InitXXX()" declarations that are not needed:

      // ==========================================================
      // Internal plugins
      // ==========================================================
      void DLL_CALLCONV InitJPEG(Plugin plugin, int format_id);
      void DLL_CALLCONV InitPNG(Plugin
      plugin, int format_id);
      void DLL_CALLCONV InitTARGA(Plugin *plugin, int format_id);
      // comment the others

    • Finally, in "Plugin.cpp", remove references to these InitXXX functions, in "FreeImage_Initialize":

      void DLL_CALLCONV
      FreeImage_Initialise(BOOL load_local_plugins_only) {
      if (s_plugin_reference_count++ == 0) {

          // internal plugin initialization
      
          s_plugins = new PluginList;
      
          if (s_plugins) {
              /* NOTE : 
              The order used to initialize internal plugins below MUST BE the same order 
              as the one used to define the FREE_IMAGE_FORMAT enum. 
              */
              s_plugins->AddNode(InitJPEG);
              s_plugins->AddNode(InitPNG);
              s_plugins->AddNode(InitTARGA);
       // comment the others
      
              // external plugin initialization
      

      ...

    as noted in the code, double check that the order of the "AddNode" calls, is
    the same as the order of the FIFs in the FREE_IMAGE_FORMAT enum.

    I also removed all the "PluginXXX.cpp" files that were not needed from the
    build.

    This hack is not that hard, but it would be very cool if FreeImage offered a
    clean and simple functionnality to customize what plugins to build, maybe by
    providing a PreMake
    (http://industriousone.com/premake)
    script with simple variables to edit, instead of a Visual Studio project ?

     
  • Mihail Naydenov

    Mihail Naydenov - 2010-08-03

    Thank you for the feedback.

    The most disturbing part is the TIFF, RAW and PSD dependency part - it clearly
    needs to be fixed.

    I doubt a general solution will emerge anytime soon - there is no high enough
    demand, considering the complications to the environment.

    Still these dependencies (incl. the register order and "renumber the enums")
    probably can be avoided.

    MihailNaydenov

     
  • Mihail Naydenov

    Mihail Naydenov - 2010-08-19

    I created patch that simplifies Plugin removal.

    Now all that is needed is to :
    1. Comment the relevant AddNode() in Plugin.cpp FreeImage_Initialize()
    2. Remove the plugin code (and its lib)
    (You can leave the declarations in Plugin.h, no problem)
    (No need to renumber and comment out FREE_IMAGE_FORMAT)
    (No need to watch for the AddNode() order)

    https://sourceforge.net/tracker/?func=detail&aid=3039243&group_id=11504&atid=
    361504

    BTW, fred78800, I tested your scenario (leave only Jpeg, Png and Targa) it it
    works ok with 3.14.1.
    The only catch is you also have to also remove XTIFF and J2KHelepr from
    compilation. (no need for psd, raw, tif)

    MihailNaydenov

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks