Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#65 Callbacks support

open
nobody
None
5
2013-03-29
2010-12-07
Mihail Naydenov
No

Supplied here is:
- Callbacks implementation;
- Full implemetation of callbacks for FIF_TIFF, FIF_JPEG Loading and FreeImage_Rotate utility function.
- Helper class (wraps the callback struct) for easy adding callbacks to any loading or utility function inside FreeImage.

Discussion

  • Forgot to mention the Rotate function also has improved performance because the use of AssignPixel instead of memcpy and for loops.

    The gain is considerable mainly for big, higher depth images (up to 40%).

     
  • Added modules enumeration. (In future it can, together with callbacks, be used for better error report)

    Added Load and Save callback to TGA, Save callback for JPEG and TIFF.
    (As it is evident form the code, it is extremely easy thing to do.)

    For now I put development on hold, until some feedback is given.

     
  • A quick note:
    CallbackHelper::reportStepProgress()

    should check for _cb first, not after the % check, otherwise if _gran == 0 it will crash.

     
  • Another quick note after using the patch for a while.

    The loading functions is probably better to return NULL instead of partially loaded dib. There is nothing wrong in current impl, and is a bit easier, but in the real world it is hard to track if the dib returned is a result of loading or cancellation.
    It is not impossible to workaround this, but, considering the dib will be discarded in 99.99% of the cases, it is better and simpler to just return null (we need to unload first of course).

     
  • PluginTARGA : line: 857 are missing the brackets for CB.reportStepProgress.

     
  • a stupid bug in PluginJPEG jpeg_output_message:

    cb->onMessage must also be checked for NULL, not only the cb object itself.

     
  • aaand the same goes for the Plugin.cpp FreeImage_LoadCB* functions...

    Very sloppy on my part.

     
  • Updated to 3.15.3

    The path is more or less feature-complete, and I am not advancing it any further for now, but I will keep it updated.

     

  • Anonymous
    2013-02-02

    file: PluginTARGA.cpp line 1067:

    before "read in the bitmap bits" add:

        if(!CB.reportProgress(0.05)) {
                    FreeImage_Unload(dib);
                    return NULL;
                }
                else
                    CB.setupStepProgress(header.is_height, 0.99);
    

    to initialize the step progress, otherwise the app may crash on reportStepProgress!

    I will update the patch to current version soon.

     

  • Anonymous
    2013-03-29

    OK, after years of using this patch I hit a significant drawback.

    The fact that the dib can not be shared between workers if both need progress reports and/or cancellation. This is, you cant use one dib as a (read only) source of multiple operations.

    So, the only possible clean solution is to break the API and separate callbacks from the dib itself.

    This implementation is trivial to modify to workaround the said limitation - just dont store FreeImageCB object in the dib, but pass it every time into the functions.

    Drolon, any thoughts on the topic in general?

    Any specific wishes/concerns?
    Sooner or later we have to implement a solution and this one is very feature rich and also trivial to expand without breaking the API again (all callbacks and options to them are passed as one struct, which can be extended).

     


Anonymous


Cancel   Add attachments