WebP and JPEG-XR support

Developers
2013-12-05
2014-03-23
  • Hervé Drolon

    Hervé Drolon - 2013-12-05

    Hi to all FreeImage developers,

    The CVS now contains two brand new plugins :
    - a WebP loading & saving plugin
    - a JPEG-XR loading & saving plugin

    The WebP format is technically limited to 24- and 32-bit RGB[A] bitmaps (it seems that the format was specified without possible extension beyond these bit depths).
    On the other hand, the JPEG-XR format can handle almost any format you could imagine, with very good compression rates. It can be seen as a modern TIF format.

    Before the next FreeImage release, I would be happy to have some help to test the compilation under Linux/MINGW/MacOS compilers.

    Hervé

     
  • Carsten Klein

    Carsten Klein - 2013-12-06

    Hi Hervé,

    it's great to have these new plugins. I will have a look at how it compiles using the MinGW compiler...

    Carsten

     
  • Carsten Klein

    Carsten Klein - 2013-12-09

    Hi Hervé,

    there is not yet a plugin source file for the JXR plugin in the CVS. Yould you please load your current version into the CVS?

    Carsten

     
  • Carsten Klein

    Carsten Klein - 2013-12-09

    Hi Hervé,

    now, I tried to compile both LibWebP and LibJXR with MinGW 32 Bit and on Linux with GCC. LibWebP seems to compile fine with all these compilers. However, it turns out, that some changes must be applied to the LibJXR sources for MinGW (and optionally for GCC as well).

    Although the JXR code is from Microsoft, it is kind of platform independent. However, MinGW, which stands somewhere between MSVC and GCC, needs some special attendance.

    Basically, we've always tried to use MinGW as a MSVC replacement. That's what we like to keep with LibJXR, too. However, in order to compile properly, for MinGW, the code needs to include stdint.h explicitly, which defines uintptr_t and intptr_t. MSVC does not need that file (it does not even have this file). File "..\x86\x68.h" then defines UINTPTR_T and INTPTR_T being uintptr_t and intptr_t, respectively (the capitalized defines seem to be used in the JXR code).

    So, for MinGW, I recommend adding the following to file "Source/LibJXR/image/sys/strcodec.h", which somehow acts as 'config.h' as well:

    In line 32 (after including stddef.h), add the following:

    #if defined(__MINGW32__)
    #include <stdint.h>
    #endif
    

    After that, when compiling with MinGW, file "..\x86\x68.h" will be included in line 64 (line number already counts the above three lines), which effectively makes MinGW behave like MSVC (including Windows.h, etc)

    The above is not needed for the real GCC (on Linux, for example). With GCC it is better to just include file "ansi.h", which

    1. does not include Windows.h
    2. comes with its own (direct) definition for UINTPTR_T and INTPTR_T (not relying on uintptr_t and intptr_t)

    So, for GCC, there are several options available. Have a look at file "Source/LibJXR/image/sys/strcodec.h", line 76 (still includes the three lines above for MinGW):

    #ifdef __ANSI__
    #define PLATFORM_ANSI
    #include "ansi.h"
    #endif
    

    File "ansi.h" is included, if __ANSI__ is defined.

    Option 1: define __ANSI__ in the Makefile only (MSVC will never use the Makefile)
    cons:
    1. __ANSI__ is likely not the best name for that option (LIB_JXR_NO_MSVC ?)
    2. MinGW also uses the Makefile, so we need to exclude MinGW from the above block:

    #if defined(__ANSI__) && !defined(__MINGW32__)
    #define PLATFORM_ANSI
    #include "ansi.h"
    #endif
    

    However, as a second code modification is required, we could as well auto-select ANSI mode for any non-MSVC compiler (not needing any additional compiler option, actually I recommend this solution):

    #if defined(__ANSI__) || (!defined(_MSC_VER) && !defined(__MINGW32__))
    #define PLATFORM_ANSI
    #include "ansi.h"
    #endif
    

    For now, these two changes seem to be required for MinGW and GCC. However, I was only able to compile some of the source files manually (the Makefile does not work, since PluginJXR is still missing). Also, I was not yet able to link any of the objects.

    Carsten

     
  • Carsten Klein

    Carsten Klein - 2013-12-09

    Hi Hervé,

    additionally, there is something to change in file "Source/LibJXR/image/jxrgluelib/JXRMata.h". The problem here is, that MinGW does define WIN32, but does not support the SAL stuff. So, we need to treat MinGW, as if it has not defined WIN32. That requires the following changes:

    In line 31:

    before: #ifndef WIN32
    after: #if !defined(WIN32) || defined(MINGW32)

    In line 110:

    before: #ifdef WIN32
    after: #if defined(WIN32) && !defined(MINGW32)

    Since GCC (on Linux, for example) does not define WIN32, there is nothing special to be done for GCC.

    Carsten

     
  • Carsten Klein

    Carsten Klein - 2013-12-09

    Hi Hervé,

    oh no... in my last post, the bold printed MINGW32 option (as in defined(MINGW32)), should be __MINGW32__, of course. Two leading or trailing underscores must be escaped to display properly in this SF forum.

    So it should be

    In line 31:

    before: #ifndef WIN32
    after: #if !defined(WIN32) || defined(__MINGW32__)

    In line 110:

    before: #ifdef WIN32
    after: #if defined(WIN32) && !defined(__MINGW32__)

    Carsten

     
  • Hervé Drolon

    Hervé Drolon - 2013-12-10

    Hi Carsten,

    Thanks for your help :)
    I've added PluginJXR to the CVS and updated the Exif reader.
    Your suggested changes are also commited.

    Note that for gcc, I changed the Makefile.gnu like this :

    # LibJXR
    CFLAGS += -DDISABLE_PERF_MEASUREMENT -D__ANSI__
    CXXFLAGS += -D__ANSI__
    

    Hervé

     
    Last edit: Hervé Drolon 2013-12-10
  • Carsten Klein

    Carsten Klein - 2013-12-11

    Hi Hervé,

    the most recent change applied to file Source/OpenEXR/IlmImf/ImfAutoArray.h (revision 1.5 on Sun Oct 20 18:26:59 2013 UTC), re-introduced an already known problem for MinGW. You've changed

    #ifdef __MINGW32__
    

    to

    #ifndef _WIN32
    

    It seems that <string.h> for memset is needed for all compilers expect MSVC. However, since MinGW also defines _WIN32 (that is an internal define), the file is not included with MinGW.

    Likely you should change it to

    #if !defined(_WIN32) || defined(__MINGW32__)
    

    MinGW is hard to control, since it is MSVC and GCC. __MINGW32__ seems to be the only macro usable to distinguish MinGW and MSVC so, we'll likely have it in several places.

    In this moment, more compiling errors are popping up (I was compiling while posting this). These come from the JXR library. However, I'm out of the office from this afternoon till tomorrow, so I can not care for these until Friday.

    Carsten

     
    Last edit: Carsten Klein 2013-12-11
  • Carsten Klein

    Carsten Klein - 2013-12-11

    Hi Hervé,

    ok, it was easy to get rid of the above mentioned errors.

    In file "Source/LibJXR/jxrgluelib/JXRGlue.h", change line 48 from

    #ifdef __ANSI__
    

    to

    #if defined(__ANSI__) || defined(__MINGW32__)
    

    In file "Source/LibJXR/image/sys/strcodec.c", change line 284 from

    #ifdef WIN32
    

    to

    #if defined(WIN32) && !defined(__MINGW32__)
    

    and line 667 from

    #if (defined(WIN32) && !defined(UNDER_CE)) || (defined(UNDER_CE) && defined(_ARM_))
    

    to

    #if (defined(WIN32) && !defined(UNDER_CE) && !defined(__MINGW32__)) || (defined(UNDER_CE) && defined(_ARM_))
    

    That's all. After that, FreeImage happily compiles with MinGW. I'll send you an updated version of Makefile.mingw on Friday.

    Carsten

     
  • Carsten Klein

    Carsten Klein - 2014-02-14

    Hi Hervé,

    did you see the two recent posts? You should actually apply the changes mentioned above to the most recent version of the JXR code to make it compile with MinGW.

    Carsten

     
  • Hervé Drolon

    Hervé Drolon - 2014-03-07

    Hi Carsten,

    Your last bug fixes are now in the CVS.
    Can you send me your updated MINGW makefile ?

    Hervé

     
  • Carsten Klein

    Carsten Klein - 2014-03-10

    Hi Hervé,

    that is good news. I will send you the latest MinGW makefile ASAP. I will also ensure, that the latest VB6 wrapper is up to date and compatible with the 3.16.0 version of FreeImage.

    There is still a bug/warning in file PluginWebP.cpp in line 576: you should return FALSE instead of NULL.

    Carsten

     
  • Hervé Drolon

    Hervé Drolon - 2014-03-23

    WebP and JPEG-XR plugins are now available in FreeImage release 3.16.0

     

Log in to post a comment.