[devel] Make use of whitespace consistent in pngget.c and pngwutil.c

This commit is contained in:
Glenn Randers-Pehrson
2010-03-06 07:34:28 -06:00
parent da30135c4c
commit 16908a1d78
2 changed files with 298 additions and 291 deletions

193
pngget.c
View File

@@ -125,10 +125,10 @@ png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
png_debug1(1, "in %s retrieval function", "png_get_x_pixels_per_meter"); png_debug1(1, "in %s retrieval function", "png_get_x_pixels_per_meter");
if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER) if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
return (0); return (0);
else else
return (info_ptr->x_pixels_per_unit); return (info_ptr->x_pixels_per_unit);
} }
#else #else
return (0); return (0);
@@ -146,10 +146,10 @@ png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
png_debug1(1, "in %s retrieval function", "png_get_y_pixels_per_meter"); png_debug1(1, "in %s retrieval function", "png_get_y_pixels_per_meter");
if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER) if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
return (0); return (0);
else else
return (info_ptr->y_pixels_per_unit); return (info_ptr->y_pixels_per_unit);
} }
#else #else
return (0); return (0);
@@ -167,11 +167,11 @@ png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter"); png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER || if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit) info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
return (0); return (0);
else else
return (info_ptr->x_pixels_per_unit); return (info_ptr->x_pixels_per_unit);
} }
#else #else
return (0); return (0);
@@ -182,7 +182,7 @@ png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
float PNGAPI float PNGAPI
png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr) png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
#ifdef PNG_pHYs_SUPPORTED #ifdef PNG_pHYs_SUPPORTED
@@ -195,7 +195,7 @@ png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
else else
return ((float)((float)info_ptr->y_pixels_per_unit return ((float)((float)info_ptr->y_pixels_per_unit
/(float)info_ptr->x_pixels_per_unit)); /(float)info_ptr->x_pixels_per_unit));
} }
#else #else
return (0.0); return (0.0);
@@ -215,10 +215,10 @@ png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns"); png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
return (0); return (0);
else else
return (info_ptr->x_offset); return (info_ptr->x_offset);
} }
#else #else
return (0); return (0);
@@ -237,10 +237,10 @@ png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns"); png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
return (0); return (0);
else else
return (info_ptr->y_offset); return (info_ptr->y_offset);
} }
#else #else
return (0); return (0);
@@ -259,10 +259,10 @@ png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns"); png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
return (0); return (0);
else else
return (info_ptr->x_offset); return (info_ptr->x_offset);
} }
#else #else
return (0); return (0);
@@ -281,10 +281,10 @@ png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns"); png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
return (0); return (0);
else else
return (info_ptr->y_offset); return (info_ptr->y_offset);
} }
#else #else
return (0); return (0);
@@ -297,41 +297,41 @@ png_uint_32 PNGAPI
png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{ {
return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr) return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
*.0254 +.5)); *.0254 +.5));
} }
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{ {
return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr) return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
*.0254 +.5)); *.0254 +.5));
} }
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{ {
return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr) return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
*.0254 +.5)); *.0254 +.5));
} }
float PNGAPI float PNGAPI
png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr) png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
{ {
return ((float)png_get_x_offset_microns(png_ptr, info_ptr) return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
*.00003937); *.00003937);
} }
float PNGAPI float PNGAPI
png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr) png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
{ {
return ((float)png_get_y_offset_microns(png_ptr, info_ptr) return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
*.00003937); *.00003937);
} }
#ifdef PNG_pHYs_SUPPORTED #ifdef PNG_pHYs_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr, png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
{ {
png_uint_32 retval = 0; png_uint_32 retval = 0;
@@ -393,7 +393,7 @@ png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
png_color_16p *background) png_color_16p *background)
{ {
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
&& background != NULL) && background != NULL)
{ {
png_debug1(1, "in %s retrieval function", "bKGD"); png_debug1(1, "in %s retrieval function", "bKGD");
@@ -408,8 +408,8 @@ png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_cHRM(png_structp png_ptr, png_infop info_ptr, png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
double *white_x, double *white_y, double *red_x, double *red_y, double *white_x, double *white_y, double *red_x, double *red_y,
double *green_x, double *green_y, double *blue_x, double *blue_y) double *green_x, double *green_y, double *blue_x, double *blue_y)
{ {
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
{ {
@@ -439,9 +439,9 @@ png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x, png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
png_fixed_point *blue_x, png_fixed_point *blue_y) png_fixed_point *blue_x, png_fixed_point *blue_y)
{ {
png_debug1(1, "in %s retrieval function", "cHRM"); png_debug1(1, "in %s retrieval function", "cHRM");
@@ -478,7 +478,7 @@ png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
png_debug1(1, "in %s retrieval function", "gAMA"); png_debug1(1, "in %s retrieval function", "gAMA");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
&& file_gamma != NULL) && file_gamma != NULL)
{ {
*file_gamma = (double)info_ptr->gamma; *file_gamma = (double)info_ptr->gamma;
return (PNG_INFO_gAMA); return (PNG_INFO_gAMA);
@@ -494,7 +494,7 @@ png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
png_debug1(1, "in %s retrieval function", "gAMA"); png_debug1(1, "in %s retrieval function", "gAMA");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
&& int_file_gamma != NULL) && int_file_gamma != NULL)
{ {
*int_file_gamma = info_ptr->int_gamma; *int_file_gamma = info_ptr->int_gamma;
return (PNG_INFO_gAMA); return (PNG_INFO_gAMA);
@@ -511,7 +511,7 @@ png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
png_debug1(1, "in %s retrieval function", "sRGB"); png_debug1(1, "in %s retrieval function", "sRGB");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
&& file_srgb_intent != NULL) && file_srgb_intent != NULL)
{ {
*file_srgb_intent = (int)info_ptr->srgb_intent; *file_srgb_intent = (int)info_ptr->srgb_intent;
return (PNG_INFO_sRGB); return (PNG_INFO_sRGB);
@@ -523,13 +523,13 @@ png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
#ifdef PNG_iCCP_SUPPORTED #ifdef PNG_iCCP_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_iCCP(png_structp png_ptr, png_infop info_ptr, png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
png_charpp name, int *compression_type, png_charpp name, int *compression_type,
png_charpp profile, png_uint_32 *proflen) png_charpp profile, png_uint_32 *proflen)
{ {
png_debug1(1, "in %s retrieval function", "iCCP"); png_debug1(1, "in %s retrieval function", "iCCP");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
&& name != NULL && profile != NULL && proflen != NULL) && name != NULL && profile != NULL && proflen != NULL)
{ {
*name = info_ptr->iccp_name; *name = info_ptr->iccp_name;
*profile = info_ptr->iccp_profile; *profile = info_ptr->iccp_profile;
@@ -547,12 +547,12 @@ png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
#ifdef PNG_sPLT_SUPPORTED #ifdef PNG_sPLT_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_sPLT(png_structp png_ptr, png_infop info_ptr, png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
png_sPLT_tpp spalettes) png_sPLT_tpp spalettes)
{ {
if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
{ {
*spalettes = info_ptr->splt_palettes; *spalettes = info_ptr->splt_palettes;
return ((png_uint_32)info_ptr->splt_palettes_num); return ((png_uint_32)info_ptr->splt_palettes_num);
} }
return (0); return (0);
} }
@@ -565,7 +565,7 @@ png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
png_debug1(1, "in %s retrieval function", "hIST"); png_debug1(1, "in %s retrieval function", "hIST");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
&& hist != NULL) && hist != NULL)
{ {
*hist = info_ptr->hist; *hist = info_ptr->hist;
return (PNG_INFO_hIST); return (PNG_INFO_hIST);
@@ -576,9 +576,9 @@ png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_IHDR(png_structp png_ptr, png_infop info_ptr, png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *width, png_uint_32 *height, int *bit_depth, png_uint_32 *width, png_uint_32 *height, int *bit_depth,
int *color_type, int *interlace_type, int *compression_type, int *color_type, int *interlace_type, int *compression_type,
int *filter_type) int *filter_type)
{ {
png_debug1(1, "in %s retrieval function", "IHDR"); png_debug1(1, "in %s retrieval function", "IHDR");
@@ -616,12 +616,12 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
#ifdef PNG_oFFs_SUPPORTED #ifdef PNG_oFFs_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_oFFs(png_structp png_ptr, png_infop info_ptr, png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
{ {
png_debug1(1, "in %s retrieval function", "oFFs"); png_debug1(1, "in %s retrieval function", "oFFs");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
&& offset_x != NULL && offset_y != NULL && unit_type != NULL) && offset_x != NULL && offset_y != NULL && unit_type != NULL)
{ {
*offset_x = info_ptr->x_offset; *offset_x = info_ptr->x_offset;
*offset_y = info_ptr->y_offset; *offset_y = info_ptr->y_offset;
@@ -635,8 +635,8 @@ png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
#ifdef PNG_pCAL_SUPPORTED #ifdef PNG_pCAL_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_pCAL(png_structp png_ptr, png_infop info_ptr, png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
png_charp *units, png_charpp *params) png_charp *units, png_charpp *params)
{ {
png_debug1(1, "in %s retrieval function", "pCAL"); png_debug1(1, "in %s retrieval function", "pCAL");
@@ -661,17 +661,17 @@ png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_sCAL(png_structp png_ptr, png_infop info_ptr, png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
int *unit, double *width, double *height) int *unit, double *width, double *height)
{ {
if (png_ptr != NULL && info_ptr != NULL && if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_sCAL)) (info_ptr->valid & PNG_INFO_sCAL))
{ {
*unit = info_ptr->scal_unit; *unit = info_ptr->scal_unit;
*width = info_ptr->scal_pixel_width; *width = info_ptr->scal_pixel_width;
*height = info_ptr->scal_pixel_height; *height = info_ptr->scal_pixel_height;
return (PNG_INFO_sCAL); return (PNG_INFO_sCAL);
} }
return(0); return(0);
} }
#else #else
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
@@ -679,15 +679,15 @@ png_uint_32 PNGAPI
png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr, png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
int *unit, png_charpp width, png_charpp height) int *unit, png_charpp width, png_charpp height)
{ {
if (png_ptr != NULL && info_ptr != NULL && if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_sCAL)) (info_ptr->valid & PNG_INFO_sCAL))
{ {
*unit = info_ptr->scal_unit; *unit = info_ptr->scal_unit;
*width = info_ptr->scal_s_width; *width = info_ptr->scal_s_width;
*height = info_ptr->scal_s_height; *height = info_ptr->scal_s_height;
return (PNG_INFO_sCAL); return (PNG_INFO_sCAL);
} }
return(0); return(0);
} }
#endif #endif
#endif #endif
@@ -696,14 +696,14 @@ png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
#ifdef PNG_pHYs_SUPPORTED #ifdef PNG_pHYs_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_pHYs(png_structp png_ptr, png_infop info_ptr, png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
{ {
png_uint_32 retval = 0; png_uint_32 retval = 0;
png_debug1(1, "in %s retrieval function", "pHYs"); png_debug1(1, "in %s retrieval function", "pHYs");
if (png_ptr != NULL && info_ptr != NULL && if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_pHYs)) (info_ptr->valid & PNG_INFO_pHYs))
{ {
if (res_x != NULL) if (res_x != NULL)
{ {
@@ -729,7 +729,7 @@ png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
int *num_palette) int *num_palette)
{ {
png_debug1(1, "in %s retrieval function", "PLTE"); png_debug1(1, "in %s retrieval function", "PLTE");
@@ -751,7 +751,7 @@ png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
png_debug1(1, "in %s retrieval function", "sBIT"); png_debug1(1, "in %s retrieval function", "sBIT");
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
&& sig_bit != NULL) && sig_bit != NULL)
{ {
*sig_bit = &(info_ptr->sig_bit); *sig_bit = &(info_ptr->sig_bit);
return (PNG_INFO_sBIT); return (PNG_INFO_sBIT);
@@ -763,13 +763,13 @@ png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
#ifdef PNG_TEXT_SUPPORTED #ifdef PNG_TEXT_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
int *num_text) int *num_text)
{ {
if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
{ {
png_debug1(1, "in %s retrieval function", png_debug1(1, "in %s retrieval function",
(png_ptr->chunk_name[0] == '\0' ? "text" (png_ptr->chunk_name[0] == '\0' ? "text" :
: (png_const_charp)png_ptr->chunk_name)); (png_const_charp)png_ptr->chunk_name));
if (text_ptr != NULL) if (text_ptr != NULL)
*text_ptr = info_ptr->text; *text_ptr = info_ptr->text;
@@ -780,7 +780,7 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
return ((png_uint_32)info_ptr->num_text); return ((png_uint_32)info_ptr->num_text);
} }
if (num_text != NULL) if (num_text != NULL)
*num_text = 0; *num_text = 0;
return(0); return(0);
} }
#endif #endif
@@ -804,7 +804,7 @@ png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
#ifdef PNG_tRNS_SUPPORTED #ifdef PNG_tRNS_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_tRNS(png_structp png_ptr, png_infop info_ptr, png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color) png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
{ {
png_uint_32 retval = 0; png_uint_32 retval = 0;
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
@@ -813,25 +813,25 @@ png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{ {
if (trans_alpha != NULL) if (trans_alpha != NULL)
{ {
*trans_alpha = info_ptr->trans_alpha; *trans_alpha = info_ptr->trans_alpha;
retval |= PNG_INFO_tRNS; retval |= PNG_INFO_tRNS;
} }
if (trans_color != NULL) if (trans_color != NULL)
*trans_color = &(info_ptr->trans_color); *trans_color = &(info_ptr->trans_color);
} }
else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */ else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
{ {
if (trans_color != NULL) if (trans_color != NULL)
{ {
*trans_color = &(info_ptr->trans_color); *trans_color = &(info_ptr->trans_color);
retval |= PNG_INFO_tRNS; retval |= PNG_INFO_tRNS;
} }
if (trans_alpha != NULL) if (trans_alpha != NULL)
*trans_alpha = NULL; *trans_alpha = NULL;
} }
if (num_trans != NULL) if (num_trans != NULL)
{ {
@@ -846,12 +846,12 @@ png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr, png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
png_unknown_chunkpp unknowns) png_unknown_chunkpp unknowns)
{ {
if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL) if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
{ {
*unknowns = info_ptr->unknown_chunks; *unknowns = info_ptr->unknown_chunks;
return ((png_uint_32)info_ptr->unknown_chunks_num); return ((png_uint_32)info_ptr->unknown_chunks_num);
} }
return (0); return (0);
} }
@@ -886,25 +886,24 @@ png_get_compression_buffer_size(png_structp png_ptr)
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_user_width_max (png_structp png_ptr) png_get_user_width_max (png_structp png_ptr)
{ {
return (png_ptr? png_ptr->user_width_max : 0); return (png_ptr? png_ptr->user_width_max : 0);
} }
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_user_height_max (png_structp png_ptr) png_get_user_height_max (png_structp png_ptr)
{ {
return (png_ptr? png_ptr->user_height_max : 0); return (png_ptr? png_ptr->user_height_max : 0);
} }
/* This function was added to libpng 1.4.0 */ /* This function was added to libpng 1.4.0 */
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_chunk_cache_max (png_structp png_ptr) png_get_chunk_cache_max (png_structp png_ptr)
{ {
return (png_ptr? png_ptr->user_chunk_cache_max : 0); return (png_ptr? png_ptr->user_chunk_cache_max : 0);
} }
/* This function was added to libpng 1.4.1 */ /* This function was added to libpng 1.4.1 */
png_alloc_size_t PNGAPI png_alloc_size_t PNGAPI
png_get_chunk_malloc_max (png_structp png_ptr) png_get_chunk_malloc_max (png_structp png_ptr)
{ {
return (png_ptr? return (png_ptr? png_ptr->user_chunk_malloc_max : 0);
png_ptr->user_chunk_malloc_max : 0);
} }
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
@@ -913,7 +912,7 @@ png_get_chunk_malloc_max (png_structp png_ptr)
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_io_state (png_structp png_ptr) png_get_io_state (png_structp png_ptr)
{ {
return png_ptr->io_state; return png_ptr->io_state;
} }
png_bytep PNGAPI png_bytep PNGAPI

View File

@@ -105,7 +105,7 @@ png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
*/ */
void PNGAPI void PNGAPI
png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name, png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
png_uint_32 length) png_uint_32 length)
{ {
png_byte buf[8]; png_byte buf[8];
@@ -201,8 +201,8 @@ typedef struct
/* Compress given text into storage in the png_ptr structure */ /* Compress given text into storage in the png_ptr structure */
static int /* PRIVATE */ static int /* PRIVATE */
png_text_compress(png_structp png_ptr, png_text_compress(png_structp png_ptr,
png_charp text, png_size_t text_len, int compression, png_charp text, png_size_t text_len, int compression,
compression_state *comp) compression_state *comp)
{ {
int ret; int ret;
@@ -215,9 +215,9 @@ png_text_compress(png_structp png_ptr,
/* We may just want to pass the text right through */ /* We may just want to pass the text right through */
if (compression == PNG_TEXT_COMPRESSION_NONE) if (compression == PNG_TEXT_COMPRESSION_NONE)
{ {
comp->input = text; comp->input = text;
comp->input_len = text_len; comp->input_len = text_len;
return((int)text_len); return((int)text_len);
} }
if (compression >= PNG_TEXT_COMPRESSION_LAST) if (compression >= PNG_TEXT_COMPRESSION_LAST)
@@ -281,24 +281,24 @@ png_text_compress(png_structp png_ptr,
old_ptr = comp->output_ptr; old_ptr = comp->output_ptr;
comp->output_ptr = (png_charpp)png_malloc(png_ptr, comp->output_ptr = (png_charpp)png_malloc(png_ptr,
(png_alloc_size_t) (png_alloc_size_t)
(comp->max_output_ptr * png_sizeof(png_charpp))); (comp->max_output_ptr * png_sizeof(png_charpp)));
png_memcpy(comp->output_ptr, old_ptr, old_max png_memcpy(comp->output_ptr, old_ptr, old_max
* png_sizeof(png_charp)); * png_sizeof(png_charp));
png_free(png_ptr, old_ptr); png_free(png_ptr, old_ptr);
} }
else else
comp->output_ptr = (png_charpp)png_malloc(png_ptr, comp->output_ptr = (png_charpp)png_malloc(png_ptr,
(png_alloc_size_t) (png_alloc_size_t)
(comp->max_output_ptr * png_sizeof(png_charp))); (comp->max_output_ptr * png_sizeof(png_charp)));
} }
/* Save the data */ /* Save the data */
comp->output_ptr[comp->num_output_ptr] = comp->output_ptr[comp->num_output_ptr] =
(png_charp)png_malloc(png_ptr, (png_charp)png_malloc(png_ptr,
(png_alloc_size_t)png_ptr->zbuf_size); (png_alloc_size_t)png_ptr->zbuf_size);
png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
png_ptr->zbuf_size); png_ptr->zbuf_size);
comp->num_output_ptr++; comp->num_output_ptr++;
/* and reset the buffer */ /* and reset the buffer */
@@ -333,24 +333,24 @@ png_text_compress(png_structp png_ptr,
old_ptr = comp->output_ptr; old_ptr = comp->output_ptr;
/* This could be optimized to realloc() */ /* This could be optimized to realloc() */
comp->output_ptr = (png_charpp)png_malloc(png_ptr, comp->output_ptr = (png_charpp)png_malloc(png_ptr,
(png_alloc_size_t)(comp->max_output_ptr * (png_alloc_size_t)(comp->max_output_ptr *
png_sizeof(png_charp))); png_sizeof(png_charp)));
png_memcpy(comp->output_ptr, old_ptr, png_memcpy(comp->output_ptr, old_ptr,
old_max * png_sizeof(png_charp)); old_max * png_sizeof(png_charp));
png_free(png_ptr, old_ptr); png_free(png_ptr, old_ptr);
} }
else else
comp->output_ptr = (png_charpp)png_malloc(png_ptr, comp->output_ptr = (png_charpp)png_malloc(png_ptr,
(png_alloc_size_t)(comp->max_output_ptr * (png_alloc_size_t)(comp->max_output_ptr *
png_sizeof(png_charp))); png_sizeof(png_charp)));
} }
/* Save the data */ /* Save the data */
comp->output_ptr[comp->num_output_ptr] = comp->output_ptr[comp->num_output_ptr] =
(png_charp)png_malloc(png_ptr, (png_charp)png_malloc(png_ptr,
(png_alloc_size_t)png_ptr->zbuf_size); (png_alloc_size_t)png_ptr->zbuf_size);
png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
png_ptr->zbuf_size); png_ptr->zbuf_size);
comp->num_output_ptr++; comp->num_output_ptr++;
/* and reset the buffer pointers */ /* and reset the buffer pointers */
@@ -386,7 +386,7 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
if (comp->input) if (comp->input)
{ {
png_write_chunk_data(png_ptr, (png_bytep)comp->input, png_write_chunk_data(png_ptr, (png_bytep)comp->input,
(png_size_t)comp->input_len); (png_size_t)comp->input_len);
return; return;
} }
@@ -394,7 +394,7 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
for (i = 0; i < comp->num_output_ptr; i++) for (i = 0; i < comp->num_output_ptr; i++)
{ {
png_write_chunk_data(png_ptr, (png_bytep)comp->output_ptr[i], png_write_chunk_data(png_ptr, (png_bytep)comp->output_ptr[i],
(png_size_t)png_ptr->zbuf_size); (png_size_t)png_ptr->zbuf_size);
png_free(png_ptr, comp->output_ptr[i]); png_free(png_ptr, comp->output_ptr[i]);
} }
if (comp->max_output_ptr != 0) if (comp->max_output_ptr != 0)
@@ -402,7 +402,7 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
/* Write anything left in zbuf */ /* Write anything left in zbuf */
if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size) if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
png_write_chunk_data(png_ptr, png_ptr->zbuf, png_write_chunk_data(png_ptr, png_ptr->zbuf,
(png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out)); (png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out));
/* Reset zlib for another zTXt/iTXt or image data */ /* Reset zlib for another zTXt/iTXt or image data */
deflateReset(&png_ptr->zstream); deflateReset(&png_ptr->zstream);
@@ -416,8 +416,8 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
*/ */
void /* PRIVATE */ void /* PRIVATE */
png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
int bit_depth, int color_type, int compression_type, int filter_type, int bit_depth, int color_type, int compression_type, int filter_type,
int interlace_type) int interlace_type)
{ {
PNG_IHDR; PNG_IHDR;
int ret; int ret;
@@ -436,9 +436,11 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
case 2: case 2:
case 4: case 4:
case 8: case 8:
case 16: png_ptr->channels = 1; break; case 16:
default: png_error(png_ptr, png_ptr->channels = 1; break;
"Invalid bit depth for grayscale image"); default:
png_error(png_ptr,
"Invalid bit depth for grayscale image");
} }
break; break;
case PNG_COLOR_TYPE_RGB: case PNG_COLOR_TYPE_RGB:
@@ -452,8 +454,11 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
case 1: case 1:
case 2: case 2:
case 4: case 4:
case 8: png_ptr->channels = 1; break; case 8:
default: png_error(png_ptr, "Invalid bit depth for paletted image"); png_ptr->channels = 1;
break;
default:
png_error(png_ptr, "Invalid bit depth for paletted image");
} }
break; break;
case PNG_COLOR_TYPE_GRAY_ALPHA: case PNG_COLOR_TYPE_GRAY_ALPHA:
@@ -487,13 +492,13 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
*/ */
if ( if (
#ifdef PNG_MNG_FEATURES_SUPPORTED #ifdef PNG_MNG_FEATURES_SUPPORTED
!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
(color_type == PNG_COLOR_TYPE_RGB || (color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_RGB_ALPHA) && color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
(filter_type == PNG_INTRAPIXEL_DIFFERENCING)) && (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
#endif #endif
filter_type != PNG_FILTER_TYPE_BASE) filter_type != PNG_FILTER_TYPE_BASE)
{ {
png_warning(png_ptr, "Invalid filter type specified"); png_warning(png_ptr, "Invalid filter type specified");
filter_type = PNG_FILTER_TYPE_BASE; filter_type = PNG_FILTER_TYPE_BASE;
@@ -547,7 +552,7 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
if (!(png_ptr->do_filter)) if (!(png_ptr->do_filter))
{ {
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE || if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
png_ptr->bit_depth < 8) png_ptr->bit_depth < 8)
png_ptr->do_filter = PNG_FILTER_NONE; png_ptr->do_filter = PNG_FILTER_NONE;
else else
png_ptr->do_filter = PNG_ALL_FILTERS; png_ptr->do_filter = PNG_ALL_FILTERS;
@@ -568,16 +573,19 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD)) if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
png_ptr->zlib_method = 8; png_ptr->zlib_method = 8;
ret = deflateInit2(&png_ptr->zstream, png_ptr->zlib_level, ret = deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
png_ptr->zlib_method, png_ptr->zlib_window_bits, png_ptr->zlib_method, png_ptr->zlib_window_bits,
png_ptr->zlib_mem_level, png_ptr->zlib_strategy); png_ptr->zlib_mem_level, png_ptr->zlib_strategy);
if (ret != Z_OK) if (ret != Z_OK)
{ {
if (ret == Z_VERSION_ERROR) png_error(png_ptr, if (ret == Z_VERSION_ERROR)
"zlib failed to initialize compressor -- version error"); png_error(png_ptr,
if (ret == Z_STREAM_ERROR) png_error(png_ptr, "zlib failed to initialize compressor -- version error");
"zlib failed to initialize compressor -- stream error"); if (ret == Z_STREAM_ERROR)
if (ret == Z_MEM_ERROR) png_error(png_ptr, png_error(png_ptr,
"zlib failed to initialize compressor -- mem error"); "zlib failed to initialize compressor -- stream error");
if (ret == Z_MEM_ERROR)
png_error(png_ptr,
"zlib failed to initialize compressor -- mem error");
png_error(png_ptr, "zlib failed to initialize compressor"); png_error(png_ptr, "zlib failed to initialize compressor");
} }
png_ptr->zstream.next_out = png_ptr->zbuf; png_ptr->zstream.next_out = png_ptr->zbuf;
@@ -605,25 +613,25 @@ png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
if (( if ((
#ifdef PNG_MNG_FEATURES_SUPPORTED #ifdef PNG_MNG_FEATURES_SUPPORTED
!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) && !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
#endif #endif
num_pal == 0) || num_pal > 256) num_pal == 0) || num_pal > 256)
{ {
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{ {
png_error(png_ptr, "Invalid number of colors in palette"); png_error(png_ptr, "Invalid number of colors in palette");
} }
else else
{ {
png_warning(png_ptr, "Invalid number of colors in palette"); png_warning(png_ptr, "Invalid number of colors in palette");
return; return;
} }
} }
if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR)) if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
{ {
png_warning(png_ptr, png_warning(png_ptr,
"Ignoring request to write a PLTE chunk in grayscale PNG"); "Ignoring request to write a PLTE chunk in grayscale PNG");
return; return;
} }
@@ -631,7 +639,7 @@ png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
png_debug1(3, "num_palette = %d", png_ptr->num_palette); png_debug1(3, "num_palette = %d", png_ptr->num_palette);
png_write_chunk_start(png_ptr, (png_bytep)png_PLTE, png_write_chunk_start(png_ptr, (png_bytep)png_PLTE,
(png_uint_32)(num_pal * 3)); (png_uint_32)(num_pal * 3));
#ifdef PNG_POINTER_INDEXING_SUPPORTED #ifdef PNG_POINTER_INDEXING_SUPPORTED
for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++) for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
{ {
@@ -682,12 +690,12 @@ png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
png_ptr->height < 16384 && png_ptr->width < 16384) png_ptr->height < 16384 && png_ptr->width < 16384)
{ {
png_uint_32 uncompressed_idat_size = png_ptr->height * png_uint_32 uncompressed_idat_size = png_ptr->height *
((png_ptr->width * ((png_ptr->width *
png_ptr->channels * png_ptr->bit_depth + 15) >> 3); png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
unsigned int z_cinfo = z_cmf >> 4; unsigned int z_cinfo = z_cmf >> 4;
unsigned int half_z_window_size = 1 << (z_cinfo + 7); unsigned int half_z_window_size = 1 << (z_cinfo + 7);
while (uncompressed_idat_size <= half_z_window_size && while (uncompressed_idat_size <= half_z_window_size &&
half_z_window_size >= 256) half_z_window_size >= 256)
{ {
z_cinfo--; z_cinfo--;
half_z_window_size >>= 1; half_z_window_size >>= 1;
@@ -703,7 +711,7 @@ png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
} }
else else
png_error(png_ptr, png_error(png_ptr,
"Invalid zlib compression method or flags in IDAT"); "Invalid zlib compression method or flags in IDAT");
} }
png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length); png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length);
@@ -719,7 +727,7 @@ png_write_IEND(png_structp png_ptr)
png_debug(1, "in png_write_IEND"); png_debug(1, "in png_write_IEND");
png_write_chunk(png_ptr, (png_bytep)png_IEND, NULL, png_write_chunk(png_ptr, (png_bytep)png_IEND, NULL,
(png_size_t)0); (png_size_t)0);
png_ptr->mode |= PNG_HAVE_IEND; png_ptr->mode |= PNG_HAVE_IEND;
} }
@@ -768,8 +776,8 @@ png_write_sRGB(png_structp png_ptr, int srgb_intent)
png_debug(1, "in png_write_sRGB"); png_debug(1, "in png_write_sRGB");
if (srgb_intent >= PNG_sRGB_INTENT_LAST) if (srgb_intent >= PNG_sRGB_INTENT_LAST)
png_warning(png_ptr, png_warning(png_ptr,
"Invalid sRGB rendering intent specified"); "Invalid sRGB rendering intent specified");
buf[0]=(png_byte)srgb_intent; buf[0]=(png_byte)srgb_intent;
png_write_chunk(png_ptr, (png_bytep)png_sRGB, buf, (png_size_t)1); png_write_chunk(png_ptr, (png_bytep)png_sRGB, buf, (png_size_t)1);
} }
@@ -779,7 +787,7 @@ png_write_sRGB(png_structp png_ptr, int srgb_intent)
/* Write an iCCP chunk */ /* Write an iCCP chunk */
void /* PRIVATE */ void /* PRIVATE */
png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type, png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
png_charp profile, int profile_len) png_charp profile, int profile_len)
{ {
PNG_iCCP; PNG_iCCP;
png_size_t name_len; png_size_t name_len;
@@ -796,7 +804,7 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
comp.input_len = 0; comp.input_len = 0;
if ((name_len = png_check_keyword(png_ptr, name, if ((name_len = png_check_keyword(png_ptr, name,
&new_name)) == 0) &new_name)) == 0)
return; return;
if (compression_type != PNG_COMPRESSION_TYPE_BASE) if (compression_type != PNG_COMPRESSION_TYPE_BASE)
@@ -815,7 +823,7 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
if (embedded_profile_len < 0) if (embedded_profile_len < 0)
{ {
png_warning(png_ptr, png_warning(png_ptr,
"Embedded profile length in iCCP chunk is negative"); "Embedded profile length in iCCP chunk is negative");
png_free(png_ptr, new_name); png_free(png_ptr, new_name);
return; return;
} }
@@ -823,7 +831,7 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
if (profile_len < embedded_profile_len) if (profile_len < embedded_profile_len)
{ {
png_warning(png_ptr, png_warning(png_ptr,
"Embedded profile length too large in iCCP chunk"); "Embedded profile length too large in iCCP chunk");
png_free(png_ptr, new_name); png_free(png_ptr, new_name);
return; return;
} }
@@ -831,20 +839,20 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
if (profile_len > embedded_profile_len) if (profile_len > embedded_profile_len)
{ {
png_warning(png_ptr, png_warning(png_ptr,
"Truncating profile to actual length in iCCP chunk"); "Truncating profile to actual length in iCCP chunk");
profile_len = embedded_profile_len; profile_len = embedded_profile_len;
} }
if (profile_len) if (profile_len)
profile_len = png_text_compress(png_ptr, profile, profile_len = png_text_compress(png_ptr, profile,
(png_size_t)profile_len, PNG_COMPRESSION_TYPE_BASE, &comp); (png_size_t)profile_len, PNG_COMPRESSION_TYPE_BASE, &comp);
/* Make sure we include the NULL after the name and the compression type */ /* Make sure we include the NULL after the name and the compression type */
png_write_chunk_start(png_ptr, (png_bytep)png_iCCP, png_write_chunk_start(png_ptr, (png_bytep)png_iCCP,
(png_uint_32)(name_len + profile_len + 2)); (png_uint_32)(name_len + profile_len + 2));
new_name[name_len + 1] = 0x00; new_name[name_len + 1] = 0x00;
png_write_chunk_data(png_ptr, (png_bytep)new_name, png_write_chunk_data(png_ptr, (png_bytep)new_name,
(png_size_t)(name_len + 2)); (png_size_t)(name_len + 2));
if (profile_len) if (profile_len)
png_write_compressed_data_out(png_ptr, &comp); png_write_compressed_data_out(png_ptr, &comp);
@@ -877,9 +885,9 @@ png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
/* Make sure we include the NULL after the name */ /* Make sure we include the NULL after the name */
png_write_chunk_start(png_ptr, (png_bytep)png_sPLT, png_write_chunk_start(png_ptr, (png_bytep)png_sPLT,
(png_uint_32)(name_len + 2 + palette_size)); (png_uint_32)(name_len + 2 + palette_size));
png_write_chunk_data(png_ptr, (png_bytep)new_name, png_write_chunk_data(png_ptr, (png_bytep)new_name,
(png_size_t)(name_len + 1)); (png_size_t)(name_len + 1));
png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, (png_size_t)1); png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, (png_size_t)1);
/* Loop through each palette entry, writing appropriately */ /* Loop through each palette entry, writing appropriately */
@@ -888,41 +896,41 @@ png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
{ {
if (spalette->depth == 8) if (spalette->depth == 8)
{ {
entrybuf[0] = (png_byte)ep->red; entrybuf[0] = (png_byte)ep->red;
entrybuf[1] = (png_byte)ep->green; entrybuf[1] = (png_byte)ep->green;
entrybuf[2] = (png_byte)ep->blue; entrybuf[2] = (png_byte)ep->blue;
entrybuf[3] = (png_byte)ep->alpha; entrybuf[3] = (png_byte)ep->alpha;
png_save_uint_16(entrybuf + 4, ep->frequency); png_save_uint_16(entrybuf + 4, ep->frequency);
} }
else else
{ {
png_save_uint_16(entrybuf + 0, ep->red); png_save_uint_16(entrybuf + 0, ep->red);
png_save_uint_16(entrybuf + 2, ep->green); png_save_uint_16(entrybuf + 2, ep->green);
png_save_uint_16(entrybuf + 4, ep->blue); png_save_uint_16(entrybuf + 4, ep->blue);
png_save_uint_16(entrybuf + 6, ep->alpha); png_save_uint_16(entrybuf + 6, ep->alpha);
png_save_uint_16(entrybuf + 8, ep->frequency); png_save_uint_16(entrybuf + 8, ep->frequency);
} }
png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size); png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
} }
#else #else
ep=spalette->entries; ep=spalette->entries;
for (i=0; i>spalette->nentries; i++) for (i = 0; i>spalette->nentries; i++)
{ {
if (spalette->depth == 8) if (spalette->depth == 8)
{ {
entrybuf[0] = (png_byte)ep[i].red; entrybuf[0] = (png_byte)ep[i].red;
entrybuf[1] = (png_byte)ep[i].green; entrybuf[1] = (png_byte)ep[i].green;
entrybuf[2] = (png_byte)ep[i].blue; entrybuf[2] = (png_byte)ep[i].blue;
entrybuf[3] = (png_byte)ep[i].alpha; entrybuf[3] = (png_byte)ep[i].alpha;
png_save_uint_16(entrybuf + 4, ep[i].frequency); png_save_uint_16(entrybuf + 4, ep[i].frequency);
} }
else else
{ {
png_save_uint_16(entrybuf + 0, ep[i].red); png_save_uint_16(entrybuf + 0, ep[i].red);
png_save_uint_16(entrybuf + 2, ep[i].green); png_save_uint_16(entrybuf + 2, ep[i].green);
png_save_uint_16(entrybuf + 4, ep[i].blue); png_save_uint_16(entrybuf + 4, ep[i].blue);
png_save_uint_16(entrybuf + 6, ep[i].alpha); png_save_uint_16(entrybuf + 6, ep[i].alpha);
png_save_uint_16(entrybuf + 8, ep[i].frequency); png_save_uint_16(entrybuf + 8, ep[i].frequency);
} }
png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size); png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
} }
@@ -950,7 +958,7 @@ png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
png_byte maxbits; png_byte maxbits;
maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 : maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
png_ptr->usr_bit_depth); png_ptr->usr_bit_depth);
if (sbit->red == 0 || sbit->red > maxbits || if (sbit->red == 0 || sbit->red > maxbits ||
sbit->green == 0 || sbit->green > maxbits || sbit->green == 0 || sbit->green > maxbits ||
sbit->blue == 0 || sbit->blue > maxbits) sbit->blue == 0 || sbit->blue > maxbits)
@@ -993,8 +1001,8 @@ png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_write_cHRM(png_structp png_ptr, double white_x, double white_y, png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
double red_x, double red_y, double green_x, double green_y, double red_x, double red_y, double green_x, double green_y,
double blue_x, double blue_y) double blue_x, double blue_y)
{ {
PNG_cHRM; PNG_cHRM;
png_byte buf[32]; png_byte buf[32];
@@ -1039,9 +1047,9 @@ png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x, png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y, png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x, png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
png_fixed_point blue_y) png_fixed_point blue_y)
{ {
PNG_cHRM; PNG_cHRM;
png_byte buf[32]; png_byte buf[32];
@@ -1051,7 +1059,7 @@ png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
/* Each value is saved in 1/100,000ths */ /* Each value is saved in 1/100,000ths */
#ifdef PNG_CHECK_cHRM_SUPPORTED #ifdef PNG_CHECK_cHRM_SUPPORTED
if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y, if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y,
green_x, green_y, blue_x, blue_y)) green_x, green_y, blue_x, blue_y))
#endif #endif
{ {
png_save_uint_32(buf, (png_uint_32)white_x); png_save_uint_32(buf, (png_uint_32)white_x);
@@ -1076,7 +1084,7 @@ png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
/* Write the tRNS chunk */ /* Write the tRNS chunk */
void /* PRIVATE */ void /* PRIVATE */
png_write_tRNS(png_structp png_ptr, png_bytep trans_alpha, png_color_16p tran, png_write_tRNS(png_structp png_ptr, png_bytep trans_alpha, png_color_16p tran,
int num_trans, int color_type) int num_trans, int color_type)
{ {
PNG_tRNS; PNG_tRNS;
png_byte buf[6]; png_byte buf[6];
@@ -1100,7 +1108,7 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans_alpha, png_color_16p tran,
if (tran->gray >= (1 << png_ptr->bit_depth)) if (tran->gray >= (1 << png_ptr->bit_depth))
{ {
png_warning(png_ptr, png_warning(png_ptr,
"Ignoring attempt to write tRNS chunk out-of-range for bit_depth"); "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
return; return;
} }
png_save_uint_16(buf, tran->gray); png_save_uint_16(buf, tran->gray);
@@ -1160,7 +1168,7 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
{ {
png_warning(png_ptr, png_warning(png_ptr,
"Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8"); "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
return; return;
} }
png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)6); png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)6);
@@ -1170,7 +1178,7 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
if (back->gray >= (1 << png_ptr->bit_depth)) if (back->gray >= (1 << png_ptr->bit_depth))
{ {
png_warning(png_ptr, png_warning(png_ptr,
"Ignoring attempt to write bKGD chunk out-of-range for bit_depth"); "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
return; return;
} }
png_save_uint_16(buf, back->gray); png_save_uint_16(buf, back->gray);
@@ -1193,7 +1201,7 @@ png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
if (num_hist > (int)png_ptr->num_palette) if (num_hist > (int)png_ptr->num_palette)
{ {
png_debug2(3, "num_hist = %d, num_palette = %d", num_hist, png_debug2(3, "num_hist = %d, num_palette = %d", num_hist,
png_ptr->num_palette); png_ptr->num_palette);
png_warning(png_ptr, "Invalid number of histogram entries specified"); png_warning(png_ptr, "Invalid number of histogram entries specified");
return; return;
} }
@@ -1258,7 +1266,7 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
char msg[40]; char msg[40];
png_snprintf(msg, 40, png_snprintf(msg, 40,
"invalid keyword character 0x%02X", (png_byte)*kp); "invalid keyword character 0x%02X", (png_byte)*kp);
png_warning(png_ptr, msg); png_warning(png_ptr, msg);
#else #else
png_warning(png_ptr, "invalid character in keyword"); png_warning(png_ptr, "invalid character in keyword");
@@ -1311,7 +1319,7 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
else if (*kp == ' ') else if (*kp == ' ')
{ {
key_len--; key_len--;
kwarn=1; kwarn = 1;
} }
else else
{ {
@@ -1344,7 +1352,7 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
/* Write a tEXt chunk */ /* Write a tEXt chunk */
void /* PRIVATE */ void /* PRIVATE */
png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text, png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
png_size_t text_len) png_size_t text_len)
{ {
PNG_tEXt; PNG_tEXt;
png_size_t key_len; png_size_t key_len;
@@ -1383,7 +1391,7 @@ png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
/* Write a compressed text chunk */ /* Write a compressed text chunk */
void /* PRIVATE */ void /* PRIVATE */
png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text, png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
png_size_t text_len, int compression) png_size_t text_len, int compression)
{ {
PNG_zTXt; PNG_zTXt;
png_size_t key_len; png_size_t key_len;
@@ -1399,7 +1407,7 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
comp.input = NULL; comp.input = NULL;
comp.input_len = 0; comp.input_len = 0;
if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0) if ((key_len = png_check_keyword(png_ptr, key, &new_key)) == 0)
{ {
png_free(png_ptr, new_key); png_free(png_ptr, new_key);
return; return;
@@ -1420,10 +1428,10 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
/* Write start of chunk */ /* Write start of chunk */
png_write_chunk_start(png_ptr, (png_bytep)png_zTXt, png_write_chunk_start(png_ptr, (png_bytep)png_zTXt,
(png_uint_32)(key_len+text_len + 2)); (png_uint_32)(key_len+text_len + 2));
/* Write key */ /* Write key */
png_write_chunk_data(png_ptr, (png_bytep)new_key, png_write_chunk_data(png_ptr, (png_bytep)new_key,
(png_size_t)(key_len + 1)); (png_size_t)(key_len + 1));
png_free(png_ptr, new_key); png_free(png_ptr, new_key);
buf[0] = (png_byte)compression; buf[0] = (png_byte)compression;
@@ -1457,10 +1465,10 @@ png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
comp.output_ptr = NULL; comp.output_ptr = NULL;
comp.input = NULL; comp.input = NULL;
if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0) if ((key_len = png_check_keyword(png_ptr, key, &new_key)) == 0)
return; return;
if ((lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0) if ((lang_len = png_check_keyword(png_ptr, lang, &new_lang)) == 0)
{ {
png_warning(png_ptr, "Empty language field in iTXt chunk"); png_warning(png_ptr, "Empty language field in iTXt chunk");
new_lang = NULL; new_lang = NULL;
@@ -1478,7 +1486,7 @@ png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
text_len = png_strlen(text); text_len = png_strlen(text);
/* Compute the compressed data; do it now for the length */ /* Compute the compressed data; do it now for the length */
text_len = png_text_compress(png_ptr, text, text_len, compression-2, text_len = png_text_compress(png_ptr, text, text_len, compression - 2,
&comp); &comp);
@@ -1499,10 +1507,10 @@ png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
* The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.
*/ */
png_write_chunk_data(png_ptr, (png_bytep)new_key, png_write_chunk_data(png_ptr, (png_bytep)new_key,
(png_size_t)(key_len + 1)); (png_size_t)(key_len + 1));
/* Set the compression flag */ /* Set the compression flag */
if (compression == PNG_ITXT_COMPRESSION_NONE || \ if (compression == PNG_ITXT_COMPRESSION_NONE ||
compression == PNG_TEXT_COMPRESSION_NONE) compression == PNG_TEXT_COMPRESSION_NONE)
cbuf[0] = 0; cbuf[0] = 0;
else /* compression == PNG_ITXT_COMPRESSION_zTXt */ else /* compression == PNG_ITXT_COMPRESSION_zTXt */
@@ -1528,7 +1536,7 @@ png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
/* Write the oFFs chunk */ /* Write the oFFs chunk */
void /* PRIVATE */ void /* PRIVATE */
png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset, png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
int unit_type) int unit_type)
{ {
PNG_oFFs; PNG_oFFs;
png_byte buf[9]; png_byte buf[9];
@@ -1570,22 +1578,23 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
total_len = purpose_len + units_len + 10; total_len = purpose_len + units_len + 10;
params_len = (png_uint_32p)png_malloc(png_ptr, params_len = (png_uint_32p)png_malloc(png_ptr,
(png_alloc_size_t)(nparams * png_sizeof(png_uint_32))); (png_alloc_size_t)(nparams * png_sizeof(png_uint_32)));
/* Find the length of each parameter, making sure we don't count the /* Find the length of each parameter, making sure we don't count the
null terminator for the last parameter. */ * null terminator for the last parameter.
*/
for (i = 0; i < nparams; i++) for (i = 0; i < nparams; i++)
{ {
params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1); params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
png_debug2(3, "pCAL parameter %d length = %lu", i, png_debug2(3, "pCAL parameter %d length = %lu", i,
(unsigned long) params_len[i]); (unsigned long) params_len[i]);
total_len += (png_size_t)params_len[i]; total_len += (png_size_t)params_len[i];
} }
png_debug1(3, "pCAL total length = %d", (int)total_len); png_debug1(3, "pCAL total length = %d", (int)total_len);
png_write_chunk_start(png_ptr, (png_bytep)png_pCAL, (png_uint_32)total_len); png_write_chunk_start(png_ptr, (png_bytep)png_pCAL, (png_uint_32)total_len);
png_write_chunk_data(png_ptr, (png_bytep)new_purpose, png_write_chunk_data(png_ptr, (png_bytep)new_purpose,
(png_size_t)purpose_len); (png_size_t)purpose_len);
png_save_int_32(buf, X0); png_save_int_32(buf, X0);
png_save_int_32(buf + 4, X1); png_save_int_32(buf + 4, X1);
buf[8] = (png_byte)type; buf[8] = (png_byte)type;
@@ -1598,7 +1607,7 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
for (i = 0; i < nparams; i++) for (i = 0; i < nparams; i++)
{ {
png_write_chunk_data(png_ptr, (png_bytep)params[i], png_write_chunk_data(png_ptr, (png_bytep)params[i],
(png_size_t)params_len[i]); (png_size_t)params_len[i]);
} }
png_free(png_ptr, params_len); png_free(png_ptr, params_len);
@@ -1621,7 +1630,7 @@ png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
buf[0] = (char)unit; buf[0] = (char)unit;
png_snprintf(buf + 1, 63, "%12.12e", width); png_snprintf(buf + 1, 63, "%12.12e", width);
total_len = 1 + png_strlen(buf + 1) + 1; total_len = 1 + png_strlen(buf + 1) + 1;
png_snprintf(buf + total_len, 64-total_len, "%12.12e", height); png_snprintf(buf + total_len, 64 - total_len, "%12.12e", height);
total_len += png_strlen(buf + total_len); total_len += png_strlen(buf + total_len);
png_debug1(3, "sCAL total length = %u", (unsigned int)total_len); png_debug1(3, "sCAL total length = %u", (unsigned int)total_len);
@@ -1631,7 +1640,7 @@ png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
void /* PRIVATE */ void /* PRIVATE */
png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width, png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
png_charp height) png_charp height)
{ {
PNG_sCAL; PNG_sCAL;
png_byte buf[64]; png_byte buf[64];
@@ -1663,8 +1672,8 @@ png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
/* Write the pHYs chunk */ /* Write the pHYs chunk */
void /* PRIVATE */ void /* PRIVATE */
png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit, png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
png_uint_32 y_pixels_per_unit, png_uint_32 y_pixels_per_unit,
int unit_type) int unit_type)
{ {
PNG_pHYs; PNG_pHYs;
png_byte buf[9]; png_byte buf[9];
@@ -1738,11 +1747,11 @@ png_write_start_row(png_structp png_ptr)
png_debug(1, "in png_write_start_row"); png_debug(1, "in png_write_start_row");
buf_size = (png_size_t)(PNG_ROWBYTES( buf_size = (png_size_t)(PNG_ROWBYTES(
png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1); png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1);
/* Set up row buffer */ /* Set up row buffer */
png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, png_ptr->row_buf = (png_bytep)png_malloc(png_ptr,
(png_alloc_size_t)buf_size); (png_alloc_size_t)buf_size);
png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
#ifdef PNG_WRITE_FILTER_SUPPORTED #ifdef PNG_WRITE_FILTER_SUPPORTED
@@ -1750,7 +1759,7 @@ png_write_start_row(png_structp png_ptr)
if (png_ptr->do_filter & PNG_FILTER_SUB) if (png_ptr->do_filter & PNG_FILTER_SUB)
{ {
png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
(png_alloc_size_t)(png_ptr->rowbytes + 1)); (png_alloc_size_t)(png_ptr->rowbytes + 1));
png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
} }
@@ -1759,26 +1768,26 @@ png_write_start_row(png_structp png_ptr)
{ {
/* Set up previous row buffer */ /* Set up previous row buffer */
png_ptr->prev_row = (png_bytep)png_calloc(png_ptr, png_ptr->prev_row = (png_bytep)png_calloc(png_ptr,
(png_alloc_size_t)buf_size); (png_alloc_size_t)buf_size);
if (png_ptr->do_filter & PNG_FILTER_UP) if (png_ptr->do_filter & PNG_FILTER_UP)
{ {
png_ptr->up_row = (png_bytep)png_malloc(png_ptr, png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
(png_size_t)(png_ptr->rowbytes + 1)); (png_size_t)(png_ptr->rowbytes + 1));
png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
} }
if (png_ptr->do_filter & PNG_FILTER_AVG) if (png_ptr->do_filter & PNG_FILTER_AVG)
{ {
png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
(png_alloc_size_t)(png_ptr->rowbytes + 1)); (png_alloc_size_t)(png_ptr->rowbytes + 1));
png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
} }
if (png_ptr->do_filter & PNG_FILTER_PAETH) if (png_ptr->do_filter & PNG_FILTER_PAETH)
{ {
png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
(png_size_t)(png_ptr->rowbytes + 1)); (png_size_t)(png_ptr->rowbytes + 1));
png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
} }
} }
@@ -1791,9 +1800,9 @@ png_write_start_row(png_structp png_ptr)
if (!(png_ptr->transformations & PNG_INTERLACE)) if (!(png_ptr->transformations & PNG_INTERLACE))
{ {
png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
png_pass_ystart[0]) / png_pass_yinc[0]; png_pass_ystart[0]) / png_pass_yinc[0];
png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 - png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
png_pass_start[0]) / png_pass_inc[0]; png_pass_start[0]) / png_pass_inc[0];
} }
else else
{ {
@@ -1878,8 +1887,8 @@ png_write_finish_row(png_structp png_ptr)
{ {
if (png_ptr->prev_row != NULL) if (png_ptr->prev_row != NULL)
png_memset(png_ptr->prev_row, 0, png_memset(png_ptr->prev_row, 0,
(png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels* (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
png_ptr->usr_bit_depth, png_ptr->width)) + 1); png_ptr->usr_bit_depth, png_ptr->width)) + 1);
return; return;
} }
} }
@@ -1915,7 +1924,7 @@ png_write_finish_row(png_structp png_ptr)
if (png_ptr->zstream.avail_out < png_ptr->zbuf_size) if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
{ {
png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size - png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
png_ptr->zstream.avail_out); png_ptr->zstream.avail_out);
} }
deflateReset(&png_ptr->zstream); deflateReset(&png_ptr->zstream);
@@ -2030,7 +2039,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
shift = 4; shift = 4;
d = 0; d = 0;
for (i = png_pass_start[pass]; i < row_width; for (i = png_pass_start[pass]; i < row_width;
i += png_pass_inc[pass]) i += png_pass_inc[pass])
{ {
sp = row + (png_size_t)(i >> 1); sp = row + (png_size_t)(i >> 1);
value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f; value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
@@ -2061,8 +2070,8 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
dp = row; dp = row;
/* Find out how many bytes each pixel takes up */ /* Find out how many bytes each pixel takes up */
pixel_bytes = (row_info->pixel_depth >> 3); pixel_bytes = (row_info->pixel_depth >> 3);
/* Loop through the row, only looking at the pixels that
matter */ /* Loop through the row, only looking at the pixels that matter */
for (i = png_pass_start[pass]; i < row_width; for (i = png_pass_start[pass]; i < row_width;
i += png_pass_inc[pass]) i += png_pass_inc[pass])
{ {
@@ -2079,11 +2088,11 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
} }
/* Set new row width */ /* Set new row width */
row_info->width = (row_info->width + row_info->width = (row_info->width +
png_pass_inc[pass] - 1 - png_pass_inc[pass] - 1 -
png_pass_start[pass]) / png_pass_start[pass]) /
png_pass_inc[pass]; png_pass_inc[pass];
row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
row_info->width); row_info->width);
} }
} }
#endif #endif
@@ -2154,8 +2163,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
/* We don't need to test the 'no filter' case if this is the only filter /* We don't need to test the 'no filter' case if this is the only filter
* that has been chosen, as it doesn't actually do anything to the data. * that has been chosen, as it doesn't actually do anything to the data.
*/ */
if ((filter_to_do & PNG_FILTER_NONE) && if ((filter_to_do & PNG_FILTER_NONE) && filter_to_do != PNG_FILTER_NONE)
filter_to_do != PNG_FILTER_NONE)
{ {
png_bytep rp; png_bytep rp;
png_uint_32 sum = 0; png_uint_32 sum = 0;
@@ -2182,9 +2190,9 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE) if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
{ {
sumlo = (sumlo * png_ptr->filter_weights[j]) >> sumlo = (sumlo * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
sumhi = (sumhi * png_ptr->filter_weights[j]) >> sumhi = (sumhi * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
} }
} }
@@ -2193,9 +2201,9 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
* it has the minimum possible computational cost - none). * it has the minimum possible computational cost - none).
*/ */
sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >> sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >> sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
if (sumhi > PNG_HIMASK) if (sumhi > PNG_HIMASK)
sum = PNG_MAXSUM; sum = PNG_MAXSUM;
@@ -2256,9 +2264,9 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
} }
lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
if (lmhi > PNG_HIMASK) if (lmhi > PNG_HIMASK)
lmins = PNG_MAXSUM; lmins = PNG_MAXSUM;
@@ -2298,16 +2306,16 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB) if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
{ {
sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >> sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >> sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
} }
} }
sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
if (sumhi > PNG_HIMASK) if (sumhi > PNG_HIMASK)
sum = PNG_MAXSUM; sum = PNG_MAXSUM;
@@ -2330,8 +2338,8 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
png_uint_32 i; png_uint_32 i;
for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1, for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
pp = prev_row + 1; i < row_bytes; pp = prev_row + 1; i < row_bytes;
i++, rp++, pp++, dp++) i++, rp++, pp++, dp++)
{ {
*dp = (png_byte)(((int)*rp - (int)*pp) & 0xff); *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
} }
@@ -2359,16 +2367,16 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP) if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
{ {
lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
} }
} }
lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >> lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >> lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
if (lmhi > PNG_HIMASK) if (lmhi > PNG_HIMASK)
lmins = PNG_MAXSUM; lmins = PNG_MAXSUM;
@@ -2378,7 +2386,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
#endif #endif
for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1, for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
pp = prev_row + 1; i < row_bytes; i++) pp = prev_row + 1; i < row_bytes; i++)
{ {
v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
@@ -2401,16 +2409,16 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP) if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
{ {
sumlo = (sumlo * png_ptr->filter_weights[j]) >> sumlo = (sumlo * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
sumhi = (sumhi * png_ptr->filter_weights[j]) >> sumhi = (sumhi * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
} }
} }
sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >> sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >> sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
if (sumhi > PNG_HIMASK) if (sumhi > PNG_HIMASK)
sum = PNG_MAXSUM; sum = PNG_MAXSUM;
@@ -2464,16 +2472,16 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG) if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
{ {
lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
} }
} }
lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >> lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >> lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
if (lmhi > PNG_HIMASK) if (lmhi > PNG_HIMASK)
lmins = PNG_MAXSUM; lmins = PNG_MAXSUM;
@@ -2492,7 +2500,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
for (lp = row_buf + 1; i < row_bytes; i++) for (lp = row_buf + 1; i < row_bytes; i++)
{ {
v = *dp++ = v = *dp++ =
(png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff); (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
sum += (v < 128) ? v : 256 - v; sum += (v < 128) ? v : 256 - v;
@@ -2513,16 +2521,16 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE) if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
{ {
sumlo = (sumlo * png_ptr->filter_weights[j]) >> sumlo = (sumlo * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
sumhi = (sumhi * png_ptr->filter_weights[j]) >> sumhi = (sumhi * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
} }
} }
sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >> sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >> sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
if (sumhi > PNG_HIMASK) if (sumhi > PNG_HIMASK)
sum = PNG_MAXSUM; sum = PNG_MAXSUM;
@@ -2544,7 +2552,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
png_bytep rp, dp, pp, cp, lp; png_bytep rp, dp, pp, cp, lp;
png_uint_32 i; png_uint_32 i;
for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1, for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
pp = prev_row + 1; i < bpp; i++) pp = prev_row + 1; i < bpp; i++)
{ {
*dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
} }
@@ -2597,16 +2605,16 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH) if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
{ {
lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
} }
} }
lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >> lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >> lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
if (lmhi > PNG_HIMASK) if (lmhi > PNG_HIMASK)
lmins = PNG_MAXSUM; lmins = PNG_MAXSUM;
@@ -2616,7 +2624,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
#endif #endif
for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1, for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
pp = prev_row + 1; i < bpp; i++) pp = prev_row + 1; i < bpp; i++)
{ {
v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
@@ -2678,16 +2686,16 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH) if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
{ {
sumlo = (sumlo * png_ptr->filter_weights[j]) >> sumlo = (sumlo * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
sumhi = (sumhi * png_ptr->filter_weights[j]) >> sumhi = (sumhi * png_ptr->filter_weights[j]) >>
PNG_WEIGHT_SHIFT; PNG_WEIGHT_SHIFT;
} }
} }
sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >> sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >> sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
PNG_COST_SHIFT; PNG_COST_SHIFT;
if (sumhi > PNG_HIMASK) if (sumhi > PNG_HIMASK)
sum = PNG_MAXSUM; sum = PNG_MAXSUM;