From 135bec7c30a00703b3c1a6aab04743ab522262fe Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sat, 27 Jan 2024 11:15:00 +0300 Subject: [PATCH] IMG_png.c: minor simplification. --- src/IMG_png.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/IMG_png.c b/src/IMG_png.c index 6b318b08..41620084 100644 --- a/src/IMG_png.c +++ b/src/IMG_png.c @@ -242,7 +242,7 @@ struct loadpng_vars { png_bytep *row_pointers; }; -static void IMG_LoadPNG_RW_impl(SDL_RWops *src, struct loadpng_vars *vars) +static void LIBPNG_LoadPNG_RW(SDL_RWops *src, struct loadpng_vars *vars) { png_uint_32 width, height; int bit_depth, color_type, interlace_type, num_channels; @@ -457,15 +457,15 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src) /* The error message has been set in SDL_RWFromFile */ return NULL; } - start = SDL_RWtell(src); if ( (IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) == 0 ) { return NULL; } + start = SDL_RWtell(src); SDL_zero(vars); - IMG_LoadPNG_RW_impl(src, &vars); + LIBPNG_LoadPNG_RW(src, &vars); if (vars.png_ptr) { lib.png_destroy_read_struct(&vars.png_ptr, @@ -591,7 +591,7 @@ struct savepng_vars { SDL_Surface *source; }; -static int IMG_SavePNG_RW_libpng_impl(struct savepng_vars *vars, SDL_Surface *surface, SDL_RWops *dst) +static int LIBPNG_SavePNG_RW(struct savepng_vars *vars, SDL_Surface *surface, SDL_RWops *dst) { Uint8 transparent_table[256]; SDL_Palette *palette; @@ -599,10 +599,6 @@ static int IMG_SavePNG_RW_libpng_impl(struct savepng_vars *vars, SDL_Surface *su vars->source = surface; - if (!IMG_Init(IMG_INIT_PNG)) { - return -1; - } - vars->png_ptr = lib.png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (vars->png_ptr == NULL) { return IMG_SetError("Couldn't allocate memory for PNG file or incompatible PNG dll"); @@ -702,8 +698,12 @@ static int IMG_SavePNG_RW_libpng(SDL_Surface *surface, SDL_RWops *dst) struct savepng_vars vars; int ret; + if (!IMG_Init(IMG_INIT_PNG)) { + return -1; + } + SDL_zero(vars); - ret = IMG_SavePNG_RW_libpng_impl(&vars, surface, dst); + ret = LIBPNG_SavePNG_RW(&vars, surface, dst); if (vars.png_ptr) { lib.png_destroy_write_struct(&vars.png_ptr, &vars.info_ptr);