IMG_webp.c: update to accomodate libwebp abi changes since v0.1.99:
authorOzkan Sezer <sezeroz@gmail.com>
Wed, 17 Oct 2018 01:02:40 +0300
changeset 610e21b8012c9b4
parent 608 3ba4eff18ffd
child 612 ca95d0e31aec
IMG_webp.c: update to accomodate libwebp abi changes since v0.1.99:

libwebp < v0.1.99 is incompatible with current versions of the library
because the decode function signatures have changed to use size_t over
int/uint32_t.

so, add compile time checks for (WEBP_DECODER_ABI_VERSION < 0x0100) in
order to properly define the function pointers.
WEBP_DECODER_ABI_VERSION values are from decoder.h header, as found in
libwebp git tags at:
https://chromium.googlesource.com/webm/libwebp/+refs
0x0100 corresponds to the abi version in 0.1.99 prerelease version.
IMG_webp.c
     1.1 --- a/IMG_webp.c	Tue Oct 16 20:20:40 2018 +0300
     1.2 +++ b/IMG_webp.c	Wed Oct 17 01:02:40 2018 +0300
     1.3 @@ -44,9 +44,15 @@
     1.4  static struct {
     1.5      int loaded;
     1.6      void *handle;
     1.7 +#if WEBP_DECODER_ABI_VERSION < 0x0100
     1.8 +    VP8StatusCode (*WebPGetFeaturesInternal) (const uint8_t *data, uint32_t data_size, WebPBitstreamFeatures* const features, int decoder_abi_version);
     1.9 +    uint8_t*    (*WebPDecodeRGBInto) (const uint8_t* data, uint32_t data_size, uint8_t* output_buffer, int output_buffer_size, int output_stride);
    1.10 +    uint8_t*    (*WebPDecodeRGBAInto) (const uint8_t* data, uint32_t data_size, uint8_t* output_buffer, int output_buffer_size, int output_stride);
    1.11 +#else
    1.12      VP8StatusCode (*WebPGetFeaturesInternal) (const uint8_t *data, size_t data_size, WebPBitstreamFeatures* features, int decoder_abi_version);
    1.13      uint8_t*    (*WebPDecodeRGBInto) (const uint8_t* data, size_t data_size, uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
    1.14      uint8_t*    (*WebPDecodeRGBAInto) (const uint8_t* data, size_t data_size, uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
    1.15 +#endif
    1.16  } lib;
    1.17  
    1.18  #ifdef LOAD_WEBP_DYNAMIC
    1.19 @@ -67,9 +73,15 @@
    1.20              return -1;
    1.21          }
    1.22  #endif
    1.23 +#if WEBP_DECODER_ABI_VERSION < 0x0100
    1.24 +        FUNCTION_LOADER(WebPGetFeaturesInternal, VP8StatusCode (*) (const uint8_t *data, uint32_t data_size, WebPBitstreamFeatures* const features, int decoder_abi_version))
    1.25 +        FUNCTION_LOADER(WebPDecodeRGBInto, uint8_t * (*) (const uint8_t* data, uint32_t data_size, uint8_t* output_buffer, int output_buffer_size, int output_stride))
    1.26 +        FUNCTION_LOADER(WebPDecodeRGBAInto, uint8_t * (*) (const uint8_t* data, uint32_t data_size, uint8_t* output_buffer, int output_buffer_size, int output_stride))
    1.27 +#else
    1.28          FUNCTION_LOADER(WebPGetFeaturesInternal, VP8StatusCode (*) (const uint8_t *data, size_t data_size, WebPBitstreamFeatures* features, int decoder_abi_version))
    1.29          FUNCTION_LOADER(WebPDecodeRGBInto, uint8_t * (*) (const uint8_t* data, size_t data_size, uint8_t* output_buffer, size_t output_buffer_size, int output_stride))
    1.30          FUNCTION_LOADER(WebPDecodeRGBAInto, uint8_t * (*) (const uint8_t* data, size_t data_size, uint8_t* output_buffer, size_t output_buffer_size, int output_stride))
    1.31 +#endif
    1.32      }
    1.33      ++lib.loaded;
    1.34  
    1.35 @@ -93,8 +105,9 @@
    1.36      int is_WEBP;
    1.37      Uint8 magic[20];
    1.38  
    1.39 -    if ( !src )
    1.40 +    if ( !src ) {
    1.41          return 0;
    1.42 +    }
    1.43      start = SDL_RWtell(src);
    1.44      is_WEBP = 0;
    1.45      if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
    1.46 @@ -109,11 +122,13 @@
    1.47               magic[12] == 'V' &&
    1.48               magic[13] == 'P' &&
    1.49               magic[14] == '8' &&
    1.50 -#if WEBP_DECODER_ABI_VERSION < 0x0003 /* old versions don't support WEBPVP8X and WEBPVP8L */
    1.51 -             magic[15] == ' ') {
    1.52 -#else
    1.53 -             (magic[15] == ' ' || magic[15] == 'X' || magic[15] == 'L')) {
    1.54 -#endif
    1.55 +         /* old versions don't support VP8X and VP8L */
    1.56 +         #if (WEBP_DECODER_ABI_VERSION < 0x0003)
    1.57 +             magic[15] == ' '
    1.58 +         #else
    1.59 +            (magic[15] == ' ' || magic[15] == 'X' || magic[15] == 'L')
    1.60 +         #endif
    1.61 +           ) {
    1.62              is_WEBP = 1;
    1.63              if ( datasize ) {
    1.64                  *datasize = (int)(SDL_RWseek(src, 0, RW_SEEK_END) - start);