Skip to content

Commit

Permalink
IMG_png.c: minor simplification.
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Jan 27, 2024
1 parent df14efe commit 44823bc
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/IMG_png.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,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;
Expand Down Expand Up @@ -456,15 +456,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,
Expand Down Expand Up @@ -590,18 +590,14 @@ 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;
int png_color_type;

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");
Expand Down Expand Up @@ -701,8 +697,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);
Expand Down

0 comments on commit 44823bc

Please sign in to comment.