PNG saver: Avoid potential clobber warning
Also remove some unnecessary png cleanup function calls. All is done by png_destroy_write_struct(), which was even called twice.
This commit is contained in:
parent
2ad8d7d785
commit
5352caecb3
|
@ -591,6 +591,10 @@ _load(ImlibImage * im, int load_data)
|
|||
return rc;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
png_bytep data;
|
||||
} misc_data_t;
|
||||
|
||||
static int
|
||||
_save(ImlibImage * im)
|
||||
{
|
||||
|
@ -598,9 +602,10 @@ _save(ImlibImage * im)
|
|||
FILE *f = im->fi->fp;
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
misc_data_t misc;
|
||||
uint32_t *ptr;
|
||||
int x, y, j, interlace;
|
||||
png_bytep row_ptr, data;
|
||||
png_bytep row_ptr;
|
||||
png_color_8 sig_bit;
|
||||
ImlibImageTag *tag;
|
||||
int quality = 75, compression = 3;
|
||||
|
@ -609,18 +614,18 @@ _save(ImlibImage * im)
|
|||
|
||||
rc = LOAD_FAIL;
|
||||
info_ptr = NULL;
|
||||
data = NULL;
|
||||
misc.data = NULL;
|
||||
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!png_ptr)
|
||||
goto quit;
|
||||
return LOAD_FAIL;
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr)
|
||||
goto quit;
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
goto quit;
|
||||
QUIT_WITH_RC(LOAD_FAIL);
|
||||
|
||||
/* check whether we should use interlacing */
|
||||
interlace = PNG_INTERLACE_NONE;
|
||||
|
@ -649,7 +654,7 @@ _save(ImlibImage * im)
|
|||
png_set_IHDR(png_ptr, info_ptr, im->w, im->h, 8, PNG_COLOR_TYPE_RGB,
|
||||
interlace, PNG_COMPRESSION_TYPE_BASE,
|
||||
PNG_FILTER_TYPE_BASE);
|
||||
data = malloc(im->w * 3 * sizeof(png_byte));
|
||||
misc.data = malloc(im->w * 3 * sizeof(png_byte));
|
||||
}
|
||||
sig_bit.red = 8;
|
||||
sig_bit.green = 8;
|
||||
|
@ -720,11 +725,11 @@ _save(ImlibImage * im)
|
|||
{
|
||||
uint32_t pixel = ptr[x];
|
||||
|
||||
data[j++] = PIXEL_R(pixel);
|
||||
data[j++] = PIXEL_G(pixel);
|
||||
data[j++] = PIXEL_B(pixel);
|
||||
misc.data[j++] = PIXEL_R(pixel);
|
||||
misc.data[j++] = PIXEL_G(pixel);
|
||||
misc.data[j++] = PIXEL_B(pixel);
|
||||
}
|
||||
row_ptr = (png_bytep) data;
|
||||
row_ptr = misc.data;
|
||||
}
|
||||
png_write_rows(png_ptr, &row_ptr, 1);
|
||||
|
||||
|
@ -738,13 +743,9 @@ _save(ImlibImage * im)
|
|||
rc = LOAD_SUCCESS;
|
||||
|
||||
quit:
|
||||
free(data);
|
||||
free(misc.data);
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp) & info_ptr);
|
||||
if (info_ptr)
|
||||
png_destroy_info_struct(png_ptr, (png_infopp) & info_ptr);
|
||||
if (png_ptr)
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue