Skip to content

Commit

Permalink
IMG_webp.c: update to accomodate libwebp abi changes since v0.1.99:
Browse files Browse the repository at this point in the history
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.

This changeset backports three SDL2 commits listed below and copies the
Windows and OSX binaries to match it.  It also adds 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.

Backported SDL2 commits are as follows:
  r360: https://hg.libsdl.org/SDL_image/rev/3d002acf103d
  r378: https://hg.libsdl.org/SDL_image/rev/f83e70f2ec6c
  r531: https://hg.libsdl.org/SDL_image/rev/4491ac456363
  • Loading branch information
sezero committed Oct 16, 2018
1 parent 1c1755e commit abb2c39
Show file tree
Hide file tree
Showing 48 changed files with 1,324 additions and 1,836 deletions.
64 changes: 43 additions & 21 deletions IMG_webp.c
Expand Up @@ -47,9 +47,15 @@
static struct {
int loaded;
void *handle;
#if WEBP_DECODER_ABI_VERSION < 0x0100
int/*VP8StatuCode*/ (*webp_get_features_internal) (const uint8_t *data, uint32_t data_size, WebPBitstreamFeatures* const features, int decoder_abi_version);
uint8_t* (*webp_decode_rgb_into) (const uint8_t* data, uint32_t data_size, uint8_t* output_buffer, int output_buffer_size, int output_stride);
uint8_t* (*webp_decode_rgba_into) (const uint8_t* data, uint32_t data_size, uint8_t* output_buffer, int output_buffer_size, int output_stride);
#else
VP8StatusCode (*webp_get_features_internal) (const uint8_t *data, size_t data_size, WebPBitstreamFeatures* features, int decoder_abi_version);
uint8_t* (*webp_decode_rgb_into) (const uint8_t* data, size_t data_size, uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
uint8_t* (*webp_decode_rgba_into) (const uint8_t* data, size_t data_size, uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
#endif
} lib;

#ifdef LOAD_WEBP_DYNAMIC
Expand All @@ -60,25 +66,38 @@ int IMG_InitWEBP()
if ( lib.handle == NULL ) {
return -1;
}

lib.webp_get_features_internal =
#if WEBP_DECODER_ABI_VERSION < 0x0100
( int (*) (const uint8_t *, uint32_t, WebPBitstreamFeatures* const, int) )
#else
( VP8StatusCode (*) (const uint8_t *, size_t, WebPBitstreamFeatures*, int) )
#endif
SDL_LoadFunction(lib.handle, "WebPGetFeaturesInternal" );
if ( lib.webp_get_features_internal == NULL ) {
SDL_UnloadObject(lib.handle);
return -1;
}

lib.webp_decode_rgb_into =
#if WEBP_DECODER_ABI_VERSION < 0x0100
( uint8_t* (*) (const uint8_t*, uint32_t, uint8_t*, int, int ) )
#else
( uint8_t* (*) (const uint8_t*, size_t, uint8_t*, size_t, int ) )
#endif
SDL_LoadFunction(lib.handle, "WebPDecodeRGBInto" );
if ( lib.webp_decode_rgb_into == NULL ) {
SDL_UnloadObject(lib.handle);
return -1;
}

lib.webp_decode_rgba_into =
#if WEBP_DECODER_ABI_VERSION < 0x0100
( uint8_t* (*) (const uint8_t*, uint32_t, uint8_t*, int, int ) )
SDL_LoadFunction(lib.handle, "WebPDecodeRGBInto" );
#else
( uint8_t* (*) (const uint8_t*, size_t, uint8_t*, size_t, int ) )
#endif
SDL_LoadFunction(lib.handle, "WebPDecodeRGBAInto" );
if ( lib.webp_decode_rgba_into == NULL ) {
SDL_UnloadObject(lib.handle);
return -1;
Expand Down Expand Up @@ -124,30 +143,36 @@ void IMG_QuitWEBP()
static int webp_getinfo( SDL_RWops *src, int *datasize ) {
int start;
int is_WEBP;
int data;
Uint8 magic[20];

if ( !src )
if ( !src ) {
return 0;
}
start = SDL_RWtell(src);
is_WEBP = 0;
if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
if ( magic[ 0] == 'R' &&
magic[ 1] == 'I' &&
magic[ 2] == 'F' &&
magic[ 3] == 'F' &&
magic[ 8] == 'W' &&
magic[ 9] == 'E' &&
magic[10] == 'B' &&
magic[11] == 'P' &&
magic[12] == 'V' &&
magic[13] == 'P' &&
magic[14] == '8' &&
magic[15] == ' ' ) {
magic[ 1] == 'I' &&
magic[ 2] == 'F' &&
magic[ 3] == 'F' &&
magic[ 8] == 'W' &&
magic[ 9] == 'E' &&
magic[10] == 'B' &&
magic[11] == 'P' &&
magic[12] == 'V' &&
magic[13] == 'P' &&
magic[14] == '8' &&
/* old versions don't support VP8X and VP8L */
#if (WEBP_DECODER_ABI_VERSION < 0x0003)
magic[15] == ' '
#else
(magic[15] == ' ' || magic[15] == 'X' || magic[15] == 'L')
#endif
) {
is_WEBP = 1;
data = magic[16] | magic[17]<<8 | magic[18]<<16 | magic[19]<<24;
if ( datasize )
*datasize = data;
if ( datasize ) {
*datasize = SDL_RWseek(src, 0, RW_SEEK_END) - start;
}
}
}
SDL_RWseek(src, start, RW_SEEK_SET);
Expand Down Expand Up @@ -192,12 +217,9 @@ SDL_Surface *IMG_LoadWEBP_RW(SDL_RWops *src)
goto error;
}

// skip header
SDL_RWseek(src, start+20, RW_SEEK_SET );

raw_data = (uint8_t*) malloc( raw_data_size );
if ( raw_data == NULL ) {
error = "Failed to allocate enought buffer for WEBP";
error = "Failed to allocate enough buffer for WEBP";
goto error;
}

Expand Down
Empty file modified VisualC/SDL_image.sln 100755 → 100644
Empty file.
8 changes: 4 additions & 4 deletions VisualC/SDL_image.vcproj 100755 → 100644
Expand Up @@ -51,7 +51,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="external\include"
PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS;LOAD_BMP;LOAD_GIF;LOAD_JPG;LOAD_JPG_DYNAMIC=\&quot;libjpeg-8.dll\&quot;;LOAD_LBM;LOAD_PCX;LOAD_PNG;LOAD_PNG_DYNAMIC=\&quot;libpng15-15.dll\&quot;;LOAD_PNM;LOAD_TGA;LOAD_TIF;LOAD_TIF_DYNAMIC=\&quot;libtiff-5.dll\&quot;;LOAD_WEBP;LOAD_WEBP_DYNAMIC=\&quot;libwebp-2.dll\&quot;;LOAD_XPM;LOAD_XV;PNG_USE_DLL;ZLIB_DLL"
PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS;LOAD_BMP;LOAD_GIF;LOAD_JPG;LOAD_JPG_DYNAMIC=\&quot;libjpeg-8.dll\&quot;;LOAD_LBM;LOAD_PCX;LOAD_PNG;LOAD_PNG_DYNAMIC=\&quot;libpng15-15.dll\&quot;;LOAD_PNM;LOAD_TGA;LOAD_TIF;LOAD_TIF_DYNAMIC=\&quot;libtiff-5.dll\&quot;;LOAD_WEBP;LOAD_WEBP_DYNAMIC=\&quot;libwebp-7.dll\&quot;;LOAD_XPM;LOAD_XV;PNG_USE_DLL;ZLIB_DLL"
MinimalRebuild="true"
RuntimeLibrary="2"
PrecompiledHeaderFile=".\Debug/SDL_image.pch"
Expand Down Expand Up @@ -138,7 +138,7 @@
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="external\include"
PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;LOAD_BMP;LOAD_GIF;LOAD_JPG;LOAD_JPG_DYNAMIC=\&quot;libjpeg-8.dll\&quot;;LOAD_LBM;LOAD_PCX;LOAD_PNG;LOAD_PNG_DYNAMIC=\&quot;libpng15-15.dll\&quot;;LOAD_PNM;LOAD_TGA;LOAD_TIF;LOAD_TIF_DYNAMIC=\&quot;libtiff-5.dll\&quot;;LOAD_WEBP;LOAD_WEBP_DYNAMIC=\&quot;libwebp-2.dll\&quot;;LOAD_XPM;LOAD_XV;PNG_USE_DLL;ZLIB_DLL"
PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;LOAD_BMP;LOAD_GIF;LOAD_JPG;LOAD_JPG_DYNAMIC=\&quot;libjpeg-8.dll\&quot;;LOAD_LBM;LOAD_PCX;LOAD_PNG;LOAD_PNG_DYNAMIC=\&quot;libpng15-15.dll\&quot;;LOAD_PNM;LOAD_TGA;LOAD_TIF;LOAD_TIF_DYNAMIC=\&quot;libtiff-5.dll\&quot;;LOAD_WEBP;LOAD_WEBP_DYNAMIC=\&quot;libwebp-7.dll\&quot;;LOAD_XPM;LOAD_XV;PNG_USE_DLL;ZLIB_DLL"
StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
Expand Down Expand Up @@ -223,7 +223,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="external\include"
PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS;LOAD_BMP;LOAD_GIF;LOAD_JPG;LOAD_JPG_DYNAMIC=\&quot;libjpeg-8.dll\&quot;;LOAD_LBM;LOAD_PCX;LOAD_PNG;LOAD_PNG_DYNAMIC=\&quot;libpng15-15.dll\&quot;;LOAD_PNM;LOAD_TGA;LOAD_TIF;LOAD_TIF_DYNAMIC=\&quot;libtiff-5.dll\&quot;;LOAD_WEBP;LOAD_WEBP_DYNAMIC=\&quot;libwebp-2.dll\&quot;;LOAD_XPM;LOAD_XV;PNG_USE_DLL;ZLIB_DLL"
PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS;LOAD_BMP;LOAD_GIF;LOAD_JPG;LOAD_JPG_DYNAMIC=\&quot;libjpeg-8.dll\&quot;;LOAD_LBM;LOAD_PCX;LOAD_PNG;LOAD_PNG_DYNAMIC=\&quot;libpng15-15.dll\&quot;;LOAD_PNM;LOAD_TGA;LOAD_TIF;LOAD_TIF_DYNAMIC=\&quot;libtiff-5.dll\&quot;;LOAD_WEBP;LOAD_WEBP_DYNAMIC=\&quot;libwebp-7.dll\&quot;;LOAD_XPM;LOAD_XV;PNG_USE_DLL;ZLIB_DLL"
MinimalRebuild="true"
RuntimeLibrary="2"
PrecompiledHeaderFile=".\Debug/SDL_image.pch"
Expand Down Expand Up @@ -310,7 +310,7 @@
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="external\include"
PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;LOAD_BMP;LOAD_GIF;LOAD_JPG;LOAD_JPG_DYNAMIC=\&quot;libjpeg-8.dll\&quot;;LOAD_LBM;LOAD_PCX;LOAD_PNG;LOAD_PNG_DYNAMIC=\&quot;libpng15-15.dll\&quot;;LOAD_PNM;LOAD_TGA;LOAD_TIF;LOAD_TIF_DYNAMIC=\&quot;libtiff-5.dll\&quot;;LOAD_WEBP;LOAD_WEBP_DYNAMIC=\&quot;libwebp-2.dll\&quot;;LOAD_XPM;LOAD_XV;PNG_USE_DLL;ZLIB_DLL"
PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;LOAD_BMP;LOAD_GIF;LOAD_JPG;LOAD_JPG_DYNAMIC=\&quot;libjpeg-8.dll\&quot;;LOAD_LBM;LOAD_PCX;LOAD_PNG;LOAD_PNG_DYNAMIC=\&quot;libpng15-15.dll\&quot;;LOAD_PNM;LOAD_TGA;LOAD_TIF;LOAD_TIF_DYNAMIC=\&quot;libtiff-5.dll\&quot;;LOAD_WEBP;LOAD_WEBP_DYNAMIC=\&quot;libwebp-7.dll\&quot;;LOAD_XPM;LOAD_XV;PNG_USE_DLL;ZLIB_DLL"
StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
Expand Down
Empty file modified VisualC/Version.rc 100755 → 100644
Empty file.
Empty file modified VisualC/clean.sh 100644 → 100755
Empty file.
Empty file modified VisualC/external/include/jconfig.h 100755 → 100644
Empty file.
Empty file modified VisualC/external/include/jerror.h 100755 → 100644
Empty file.
Empty file modified VisualC/external/include/jmorecfg.h 100755 → 100644
Empty file.
Empty file modified VisualC/external/include/jpeglib.h 100755 → 100644
Empty file.
Empty file modified VisualC/external/include/png.h 100755 → 100644
Empty file.
Empty file modified VisualC/external/include/pngconf.h 100755 → 100644
Empty file.
Empty file modified VisualC/external/include/tiff.h 100755 → 100644
Empty file.
Empty file modified VisualC/external/include/tiffconf.h 100755 → 100644
Empty file.
Empty file modified VisualC/external/include/tiffio.h 100755 → 100644
Empty file.
Empty file modified VisualC/external/include/tiffvers.h 100755 → 100644
Empty file.

0 comments on commit abb2c39

Please sign in to comment.