# SDL\_image: c89 compatibility after commit aa19bc897ddc. uniform whitespace style. (d40ec)

**URL:** <https://discourse.libsdl.org/t/sdl-image-c89-compatibility-after-commit-aa19bc897ddc-uniform-whitespace-style-d40ec/41571>\
**Category:** SDL Commits\
**Created:** [January 4, 2023, 6:32pm UTC](https://discourse.libsdl.org/t/sdl-image-c89-compatibility-after-commit-aa19bc897ddc-uniform-whitespace-style-d40ec/41571 "2023-01-04T18:32:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [January 4, 2023, 6:32pm UTC](https://discourse.libsdl.org/t/sdl-image-c89-compatibility-after-commit-aa19bc897ddc-uniform-whitespace-style-d40ec/41571/1 "2023-01-04T18:32:02Z")

</div>

> <https://github.com/libsdl-org/SDL_image/commit/d40ec19bea800a2f1b89e621f8ffe6567c8a8457>

```diff
From d40ec19bea800a2f1b89e621f8ffe6567c8a8457 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Tue, 1 Nov 2022 17:45:28 +0300
Subject: [PATCH] c89 compatibility after commit aa19bc897ddc. uniform
 whitespace style.

---
 IMG_webp.c | 142 ++++++++++++++++++++++++++---------------------------
 1 file changed, 71 insertions(+), 71 deletions(-)

diff --git a/IMG_webp.c b/IMG_webp.c
index 15ac54e8..a0876e56 100644
--- a/IMG_webp.c
+++ b/IMG_webp.c
@@ -72,10 +72,10 @@ static struct {
 
 int IMG_InitWEBP()
 {
- if ( lib.loaded == 0 ) {
+ if (lib.loaded == 0) {
 #ifdef LOAD_WEBP_DYNAMIC
         lib.handle = SDL_LoadObject(LOAD_WEBP_DYNAMIC);
- if ( lib.handle == NULL ) {
+ if (lib.handle == NULL) {
             return -1;
         }
 #endif
@@ -99,10 +99,10 @@ int IMG_InitWEBP()
 }
 void IMG_QuitWEBP()
 {
- if ( lib.loaded == 0 ) {
+ if (lib.loaded == 0) {
         return;
     }
- if ( lib.loaded == 1 ) {
+ if (lib.loaded == 1) {
 #ifdef LOAD_WEBP_DYNAMIC
         SDL_UnloadObject(lib.handle);
 #endif
@@ -110,28 +110,28 @@ void IMG_QuitWEBP()
     --lib.loaded;
 }
 
-static int webp_getinfo( SDL_RWops *src, int *datasize ) {
+static int webp_getinfo (SDL_RWops *src, int *datasize) {
     Sint64 start;
     int is_WEBP;
     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' &&
+ 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' &&
          /* old versions don't support VP8X and VP8L */
          #if (WEBP_DECODER_ABI_VERSION < 0x0003)
              magic[15] == ' '
@@ -140,7 +140,7 @@ static int webp_getinfo( SDL_RWops *src, int *datasize ) {
          #endif
            ) {
             is_WEBP = 1;
- if ( datasize ) {
+ if (datasize) {
                 *datasize = (int)(SDL_RWseek(src, 0, RW_SEEK_END) - start);
             }
         }
@@ -152,7 +152,7 @@ static int webp_getinfo( SDL_RWops *src, int *datasize ) {
 /* See if an image is contained in a data source */
 int IMG_isWEBP(SDL_RWops *src)
 {
- return webp_getinfo( src, NULL );
+ return webp_getinfo(src, NULL);
 }
 
 SDL_Surface *IMG_LoadWEBP_RW(SDL_RWops *src)
@@ -170,45 +170,45 @@ SDL_Surface *IMG_LoadWEBP_RW(SDL_RWops *src)
     int r;
     uint8_t *ret;
 
- if ( !src ) {
+ if (!src) {
         /* The error message has been set in SDL_RWFromFile */
         return NULL;
     }
 
     start = SDL_RWtell(src);
 
- if ( (IMG_Init(IMG_INIT_WEBP) & IMG_INIT_WEBP) == 0 ) {
+ if ((IMG_Init(IMG_INIT_WEBP) & IMG_INIT_WEBP) == 0) {
         goto error;
     }
 
     raw_data_size = -1;
- if ( !webp_getinfo( src, &raw_data_size ) ) {
+ if (!webp_getinfo(src, &raw_data_size)) {
         error = "Invalid WEBP";
         goto error;
     }
 
- raw_data = (uint8_t*) SDL_malloc( raw_data_size );
- if ( raw_data == NULL ) {
+ raw_data = (uint8_t*) SDL_malloc(raw_data_size);
+ if (raw_data == NULL) {
         error = "Failed to allocate enough buffer for WEBP";
         goto error;
     }
 
- r = (int)SDL_RWread(src, raw_data, 1, raw_data_size );
- if ( r != raw_data_size ) {
+ r = (int)SDL_RWread(src, raw_data, 1, raw_data_size);
+ if (r != raw_data_size) {
         error = "Failed to read WEBP";
         goto error;
     }
 
 #if 0
- // extract size of picture, not interesting since we don't know about alpha channel
- int width = -1, height = -1;
- if ( !WebPGetInfo( raw_data, raw_data_size, &width, &height ) ) {
- printf("WebPGetInfo has failed\n" );
- return NULL;
- }
+ {/* extract size of picture, not interesting since we don't know about alpha channel */
+ int width = -1, height = -1;
+ if (!WebPGetInfo(raw_data, raw_data_size, &width, &height)) {
+ printf("WebPGetInfo has failed\n");
+ return NULL;
+ } }
 #endif
 
- if ( lib.WebPGetFeaturesInternal( raw_data, raw_data_size, &features, WEBP_DECODER_ABI_VERSION ) != VP8_STATUS_OK ) {
+ if (lib.WebPGetFeaturesInternal(raw_data, raw_data_size, &features, WEBP_DECODER_ABI_VERSION) != VP8_STATUS_OK) {
         error = "WebPGetFeatures has failed";
         goto error;
     }
@@ -233,45 +233,44 @@ SDL_Surface *IMG_LoadWEBP_RW(SDL_RWops *src)
             features.width, features.height,
             features.has_alpha?32:24, Rmask,Gmask,Bmask,Amask);
 
- if ( surface == NULL ) {
+ if (surface == NULL) {
         error = "Failed to allocate SDL_Surface";
         goto error;
     }
 
- if ( features.has_alpha ) {
- ret = lib.WebPDecodeRGBAInto( raw_data, raw_data_size, (uint8_t *)surface->pixels, surface->pitch * surface->h, surface->pitch );
+ if (features.has_alpha) {
+ ret = lib.WebPDecodeRGBAInto(raw_data, raw_data_size, (uint8_t *)surface->pixels, surface->pitch * surface->h, surface->pitch);
     } else {
- ret = lib.WebPDecodeRGBInto( raw_data, raw_data_size, (uint8_t *)surface->pixels, surface->pitch * surface->h, surface->pitch );
+ ret = lib.WebPDecodeRGBInto(raw_data, raw_data_size, (uint8_t *)surface->pixels, surface->pitch * surface->h, surface->pitch);
     }
 
- if ( !ret ) {
+ if (!ret) {
         error = "Failed to decode WEBP";
         goto error;
     }
 
- if ( raw_data ) {
- SDL_free( raw_data );
+ if (raw_data) {
+ SDL_free(raw_data);
     }
 
     return surface;
 
 
 error:
-
- if ( raw_data ) {
- SDL_free( raw_data );
+ if (raw_data) {
+ SDL_free(raw_data);
     }
 
- if ( surface ) {
- SDL_FreeSurface( surface );
+ if (surface) {
+ SDL_FreeSurface(surface);
     }
 
- if ( error ) {
- IMG_SetError( "%s", error );
+ if (error) {
+ IMG_SetError("%s", error);
     }
 
     SDL_RWseek(src, start, RW_SEEK_SET);
- return(NULL);
+ return NULL;
 }
 
 IMG_Animation *IMG_LoadWEBPAnimation_RW(SDL_RWops *src)
@@ -288,39 +287,39 @@ IMG_Animation *IMG_LoadWEBPAnimation_RW(SDL_RWops *src)
     IMG_Animation *anim = NULL;
     int raw_data_size;
     uint8_t *raw_data = NULL;
- int r;
     uint8_t *ret;
+ int frame_idx;
+ WebPData wd;
 
- if ( !src ) {
+ if (!src) {
         /* The error message has been set in SDL_RWFromFile */
         return NULL;
     }
 
     start = SDL_RWtell(src);
 
- if ( (IMG_Init(IMG_INIT_WEBP) & IMG_INIT_WEBP) == 0 ) {
+ if ((IMG_Init(IMG_INIT_WEBP) & IMG_INIT_WEBP) == 0) {
         goto error;
     }
 
     raw_data_size = -1;
- if ( !webp_getinfo( src, &raw_data_size ) ) {
+ if (!webp_getinfo(src, &raw_data_size)) {
         error = "Invalid WEBP Animation";
         goto error;
     }
 
- raw_data = (uint8_t*) SDL_malloc( raw_data_size );
- if ( raw_data == NULL ) {
+ raw_data = (uint8_t*) SDL_malloc(raw_data_size);
+ if (raw_data == NULL) {
         error = "Failed to allocate enough buffer for WEBP Animation";
         goto error;
     }
 
- r = (int)SDL_RWread(src, raw_data, 1, raw_data_size );
- if ( r != raw_data_size ) {
+ if ((int)SDL_RWread(src, raw_data, 1, raw_data_size) != raw_data_size) {
         error = "Failed to read WEBP Animation";
         goto error;
     }
 
- if ( lib.WebPGetFeaturesInternal( raw_data, raw_data_size, &features, WEBP_DECODER_ABI_VERSION ) != VP8_STATUS_OK ) {
+ if (lib.WebPGetFeaturesInternal(raw_data, raw_data_size, &features, WEBP_DECODER_ABI_VERSION) != VP8_STATUS_OK) {
         error = "WebPGetFeatures has failed";
         goto error;
     }
@@ -341,7 +340,8 @@ IMG_Animation *IMG_LoadWEBPAnimation_RW(SDL_RWops *src)
     }
 #endif
 
- WebPData wd = { raw_data , raw_data_size};
+ wd.size = raw_data_size;
+ wd.bytes = raw_data;
     dmuxer = lib.WebPDemux(&wd);
     anim = (IMG_Animation *)SDL_malloc(sizeof(IMG_Animation));
     anim->w = features.width;
@@ -349,20 +349,20 @@ IMG_Animation *IMG_LoadWEBPAnimation_RW(SDL_RWops *src)
     anim->count = lib.WebPDemuxGetI(dmuxer, WEBP_FF_FRAME_COUNT);
     anim->frames = (SDL_Surface **)SDL_calloc(anim->count, sizeof(*anim->frames));
     anim->delays = (int *)SDL_calloc(anim->count, sizeof(*anim->delays));
- for (int frame_idx = 0; frame_idx < (anim->count); frame_idx++) {
+ for (frame_idx = 0; frame_idx < (anim->count); frame_idx++) {
         if (lib.WebPDemuxGetFrame(dmuxer, frame_idx, &iter) == 0) {
             break;
         }
         SDL_Surface* curr = SDL_CreateRGBSurface(SDL_SWSURFACE,
             features.width, features.height,
             features.has_alpha?32:24, Rmask,Gmask,Bmask,Amask);
- if ( curr == NULL ) {
+ if (curr == NULL) {
             error = "Failed to allocate SDL_Surface";
             goto error;
         }
         anim->frames[frame_idx] = curr;
         anim->delays[frame_idx] = iter.duration;
- if ( features.has_alpha ) {
+ if (features.has_alpha) {
             ret = lib.WebPDecodeRGBAInto(
                 iter.fragment.bytes,
                 iter.fragment.size,
@@ -384,8 +384,8 @@ IMG_Animation *IMG_LoadWEBPAnimation_RW(SDL_RWops *src)
         lib.WebPDemuxDelete(dmuxer);
     }
 
- if ( raw_data ) {
- SDL_free( raw_data );
+ if (raw_data) {
+ SDL_free(raw_data);
     }
     return anim;
 error:
@@ -396,14 +396,14 @@ IMG_Animation *IMG_LoadWEBPAnimation_RW(SDL_RWops *src)
         lib.WebPDemuxDelete(dmuxer);
     }
     if (raw_data) {
- SDL_free( raw_data );
+ SDL_free(raw_data);
     }
 
     if (error) {
- IMG_SetError( "%s", error );
+ IMG_SetError("%s", error);
     }
     SDL_RWseek(src, start, RW_SEEK_SET);
- return(NULL);
+ return NULL;
 }
 
 #else
@@ -414,7 +414,7 @@ IMG_Animation *IMG_LoadWEBPAnimation_RW(SDL_RWops *src)
 int IMG_InitWEBP()
 {
     IMG_SetError("WEBP images are not supported");
- return(-1);
+ return -1;
 }
 
 void IMG_QuitWEBP()
@@ -424,17 +424,17 @@ void IMG_QuitWEBP()
 /* See if an image is contained in a data source */
 int IMG_isWEBP(SDL_RWops *src)
 {
- return(0);
+ return 0;
 }
 
 /* Load a WEBP type image from an SDL datasource */
 SDL_Surface *IMG_LoadWEBP_RW(SDL_RWops *src)
 {
- return(NULL);
+ return NULL;
 }
 
 IMG_Animation *IMG_LoadWEBPAnimation_RW(SDL_RWops *src) {
- return(NULL);
+ return NULL;
 }
 
 #endif /* LOAD_WEBP */

```
