diff --git a/pngset.c b/pngset.c index 84ef8386..a4052b8e 100644 --- a/pngset.c +++ b/pngset.c @@ -1,7 +1,7 @@ /* pngset.c - storage of image information into info struct * - * Last changed in libpng 1.2.38 [June 12, 2009] + * Last changed in libpng 1.4.0 [June 16, 2009] * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2009 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -13,9 +13,9 @@ * info struct and allows us to change the structure in the future. */ -#define PNG_INTERNAL #include "png.h" #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +#include "pngpriv.h" #if defined(PNG_bKGD_SUPPORTED) void PNGAPI @@ -180,7 +180,7 @@ png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) > PNG_MAX_PALETTE_LENGTH) { png_warning(png_ptr, - "Invalid palette size, hIST allocation skipped."); + "Invalid palette size, hIST allocation skipped"); return; } @@ -191,10 +191,10 @@ png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) * version 1.2.1 */ png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr, - (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16))); + PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16)); if (png_ptr->hist == NULL) { - png_warning(png_ptr, "Insufficient memory for hIST chunk data."); + png_warning(png_ptr, "Insufficient memory for hIST chunk data"); return; } @@ -314,7 +314,7 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr, - 1 /* filter byte */ - 7*8 /* rounding of width to multiple of 8 pixels */ - 8) /* extra max_pixel_depth pad */ - info_ptr->rowbytes = (png_size_t)0; + info_ptr->rowbytes = 0; else info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); } @@ -341,7 +341,7 @@ png_set_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 units, png_charpp params) { - png_uint_32 length; + png_size_t length; int i; png_debug1(1, "in %s storage function", "pCAL"); @@ -354,10 +354,10 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length); if (info_ptr->pcal_purpose == NULL) { - png_warning(png_ptr, "Insufficient memory for pCAL purpose."); + png_warning(png_ptr, "Insufficient memory for pCAL purpose"); return; } - png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length); + png_memcpy(info_ptr->pcal_purpose, purpose, length); png_debug(3, "storing X0, X1, type, and nparams in info"); info_ptr->pcal_X0 = X0; @@ -371,16 +371,16 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length); if (info_ptr->pcal_units == NULL) { - png_warning(png_ptr, "Insufficient memory for pCAL units."); + png_warning(png_ptr, "Insufficient memory for pCAL units"); return; } - png_memcpy(info_ptr->pcal_units, units, (png_size_t)length); + png_memcpy(info_ptr->pcal_units, units, length); info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr, - (png_uint_32)((nparams + 1) * png_sizeof(png_charp))); + (png_size_t)((nparams + 1) * png_sizeof(png_charp))); if (info_ptr->pcal_params == NULL) { - png_warning(png_ptr, "Insufficient memory for pCAL params."); + png_warning(png_ptr, "Insufficient memory for pCAL params"); return; } @@ -394,10 +394,10 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr, info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length); if (info_ptr->pcal_params[i] == NULL) { - png_warning(png_ptr, "Insufficient memory for pCAL parameter."); + png_warning(png_ptr, "Insufficient memory for pCAL parameter"); return; } - png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length); + png_memcpy(info_ptr->pcal_params[i], params[i], length); } info_ptr->valid |= PNG_INFO_pCAL; @@ -429,7 +429,7 @@ void PNGAPI png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, int unit, png_charp swidth, png_charp sheight) { - png_uint_32 length; + png_size_t length; png_debug1(1, "in %s storage function", "sCAL"); if (png_ptr == NULL || info_ptr == NULL) @@ -444,10 +444,10 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, if (info_ptr->scal_s_width == NULL) { png_warning(png_ptr, - "Memory allocation failed while processing sCAL."); + "Memory allocation failed while processing sCAL"); return; } - png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length); + png_memcpy(info_ptr->scal_s_width, swidth, length); length = png_strlen(sheight) + 1; png_debug1(3, "allocating unit for info (%u bytes)", @@ -458,10 +458,10 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, png_free (png_ptr, info_ptr->scal_s_width); info_ptr->scal_s_width = NULL; png_warning(png_ptr, - "Memory allocation failed while processing sCAL."); + "Memory allocation failed while processing sCAL"); return; } - png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length); + png_memcpy(info_ptr->scal_s_height, sheight, length); info_ptr->valid |= PNG_INFO_sCAL; #ifdef PNG_FREE_ME_SUPPORTED info_ptr->free_me |= PNG_FREE_SCAL; @@ -520,10 +520,15 @@ png_set_PLTE(png_structp png_ptr, png_infop info_ptr, * of num_palette entries, in case of an invalid PNG file that has * too-large sample values. */ +#ifdef PNG_CALLOC_SUPPORTED + png_ptr->palette = (png_colorp)png_calloc(png_ptr, + PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color)); +#else png_ptr->palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color)); png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color)); +#endif png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color)); info_ptr->palette = png_ptr->palette; info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; @@ -659,7 +664,7 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr, new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length); if (new_iccp_name == NULL) { - png_warning(png_ptr, "Insufficient memory to process iCCP chunk."); + png_warning(png_ptr, "Insufficient memory to process iCCP chunk"); return; } png_memcpy(new_iccp_name, name, length); @@ -668,7 +673,7 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr, { png_free (png_ptr, new_iccp_name); png_warning(png_ptr, - "Insufficient memory to process iCCP profile."); + "Insufficient memory to process iCCP profile"); return; } png_memcpy(new_iccp_profile, profile, (png_size_t)proflen); @@ -725,7 +730,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, info_ptr->max_text = info_ptr->num_text + num_text + 8; old_text = info_ptr->text; info_ptr->text = (png_textp)png_malloc_warn(png_ptr, - (png_uint_32)(info_ptr->max_text * png_sizeof(png_text))); + (png_size_t)(info_ptr->max_text * png_sizeof(png_text))); if (info_ptr->text == NULL) { png_free(png_ptr, old_text); @@ -740,7 +745,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, info_ptr->max_text = num_text + 8; info_ptr->num_text = 0; info_ptr->text = (png_textp)png_malloc_warn(png_ptr, - (png_uint_32)(info_ptr->max_text * png_sizeof(png_text))); + (png_size_t)(info_ptr->max_text * png_sizeof(png_text))); if (info_ptr->text == NULL) return(1); #ifdef PNG_FREE_ME_SUPPORTED @@ -781,7 +786,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, } #else { - png_warning(png_ptr, "iTXt chunk not supported."); + png_warning(png_ptr, "iTXt chunk not supported"); continue; } #endif @@ -803,12 +808,12 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, } textp->key = (png_charp)png_malloc_warn(png_ptr, - (png_uint_32) + (png_size_t) (key_len + text_length + lang_len + lang_key_len + 4)); if (textp->key == NULL) return(1); png_debug2(2, "Allocated %lu bytes at %x in png_set_text", - (png_uint_32) + (unsigned long)(png_uint_32) (key_len + lang_len + lang_key_len + text_length + 4), (int)textp->key); @@ -877,7 +882,7 @@ png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time) #if defined(PNG_tRNS_SUPPORTED) void PNGAPI png_set_tRNS(png_structp png_ptr, png_infop info_ptr, - png_bytep trans, int num_trans, png_color_16p trans_values) + png_bytep trans, int num_trans, png_color_16p trans_color) { png_debug1(1, "in %s storage function", "tRNS"); if (png_ptr == NULL || info_ptr == NULL) @@ -897,23 +902,23 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr, /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */ png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr, - (png_uint_32)PNG_MAX_PALETTE_LENGTH); + (png_size_t)PNG_MAX_PALETTE_LENGTH); if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH) png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans); } - if (trans_values != NULL) + if (trans_color != NULL) { int sample_max = (1 << info_ptr->bit_depth); if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY && - (int)trans_values->gray > sample_max) || + (int)trans_color->gray > sample_max) || (info_ptr->color_type == PNG_COLOR_TYPE_RGB && - ((int)trans_values->red > sample_max || - (int)trans_values->green > sample_max || - (int)trans_values->blue > sample_max))) + ((int)trans_color->red > sample_max || + (int)trans_color->green > sample_max || + (int)trans_color->blue > sample_max))) png_warning(png_ptr, "tRNS chunk has out-of-range samples for bit_depth"); - png_memcpy(&(info_ptr->trans_values), trans_values, + png_memcpy(&(info_ptr->trans_color), trans_color, png_sizeof(png_color_16)); if (num_trans == 0) num_trans = 1; @@ -952,10 +957,10 @@ png_set_sPLT(png_structp png_ptr, np = (png_sPLT_tp)png_malloc_warn(png_ptr, (info_ptr->splt_palettes_num + nentries) * - (png_uint_32)png_sizeof(png_sPLT_t)); + (png_size_t)png_sizeof(png_sPLT_t)); if (np == NULL) { - png_warning(png_ptr, "No memory for sPLT palettes."); + png_warning(png_ptr, "No memory for sPLT palettes"); return; } @@ -971,7 +976,7 @@ png_set_sPLT(png_structp png_ptr, png_uint_32 length; length = png_strlen(from->name) + 1; - to->name = (png_charp)png_malloc_warn(png_ptr, length); + to->name = (png_charp)png_malloc_warn(png_ptr, (png_size_t)length); if (to->name == NULL) { png_warning(png_ptr, @@ -980,7 +985,7 @@ png_set_sPLT(png_structp png_ptr, } png_memcpy(to->name, from->name, length); to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr, - (png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry))); + (png_size_t)(from->nentries * png_sizeof(png_sPLT_entry))); if (to->entries == NULL) { png_warning(png_ptr, @@ -1004,7 +1009,7 @@ png_set_sPLT(png_structp png_ptr, } #endif /* PNG_sPLT_SUPPORTED */ -#if defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) void PNGAPI png_set_unknown_chunks(png_structp png_ptr, png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns) @@ -1016,19 +1021,18 @@ png_set_unknown_chunks(png_structp png_ptr, return; np = (png_unknown_chunkp)png_malloc_warn(png_ptr, - (png_uint_32)((info_ptr->unknown_chunks_num + num_unknowns) * + (png_size_t)((info_ptr->unknown_chunks_num + num_unknowns) * png_sizeof(png_unknown_chunk))); if (np == NULL) { png_warning(png_ptr, - "Out of memory while processing unknown chunk."); + "Out of memory while processing unknown chunk"); return; } png_memcpy(np, info_ptr->unknown_chunks, info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk)); png_free(png_ptr, info_ptr->unknown_chunks); - info_ptr->unknown_chunks=NULL; for (i = 0; i < num_unknowns; i++) { @@ -1048,11 +1052,11 @@ png_set_unknown_chunks(png_structp png_ptr, else { to->data = (png_bytep)png_malloc_warn(png_ptr, - (png_uint_32)from->size); + (png_size_t)from->size); if (to->data == NULL) { png_warning(png_ptr, - "Out of memory while processing unknown chunk."); + "Out of memory while processing unknown chunk"); to->size = 0; } else @@ -1076,23 +1080,6 @@ png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr, } #endif -#if defined(PNG_1_0_X) || defined(PNG_1_2_X) -#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ - defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) -void PNGAPI -png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted) -{ - /* This function is deprecated in favor of png_permit_mng_features() - and will be removed from libpng-1.3.0 */ - png_debug(1, "in png_permit_empty_plte, DEPRECATED."); - if (png_ptr == NULL) - return; - png_ptr->mng_features_permitted = (png_byte) - ((png_ptr->mng_features_permitted & (~PNG_FLAG_MNG_EMPTY_PLTE)) | - ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE))); -} -#endif -#endif #if defined(PNG_MNG_FEATURES_SUPPORTED) png_uint_32 PNGAPI @@ -1133,7 +1120,7 @@ png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep return; old_num_chunks = png_ptr->num_chunk_list; new_list=(png_bytep)png_malloc(png_ptr, - (png_uint_32) + (png_size_t) (5*(num_chunks + old_num_chunks))); if (png_ptr->chunk_list != NULL) { @@ -1187,12 +1174,12 @@ png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers) #ifdef PNG_WRITE_SUPPORTED void PNGAPI png_set_compression_buffer_size(png_structp png_ptr, - png_uint_32 size) + png_size_t size) { if (png_ptr == NULL) return; png_free(png_ptr, png_ptr->zbuf); - png_ptr->zbuf_size = (png_size_t)size; + png_ptr->zbuf_size = size; png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size); png_ptr->zstream.next_out = png_ptr->zbuf; png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; @@ -1207,32 +1194,6 @@ png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask) } -#ifndef PNG_1_0_X -#ifdef PNG_ASSEMBLER_CODE_SUPPORTED -/* Function was added to libpng 1.2.0 and should always exist by default */ -void PNGAPI -png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags) -{ -/* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */ - if (png_ptr != NULL) - png_ptr->asm_flags = 0; - asm_flags = asm_flags; /* Quiet the compiler */ -} - -/* This function was added to libpng 1.2.0 */ -void PNGAPI -png_set_mmx_thresholds (png_structp png_ptr, - png_byte mmx_bitdepth_threshold, - png_uint_32 mmx_rowbytes_threshold) -{ -/* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */ - if (png_ptr == NULL) - return; - /* Quiet the compiler */ - mmx_bitdepth_threshold = mmx_bitdepth_threshold; - mmx_rowbytes_threshold = mmx_rowbytes_threshold; -} -#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ #ifdef PNG_SET_USER_LIMITS_SUPPORTED /* This function was added to libpng 1.2.6 */ @@ -1249,7 +1210,31 @@ png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max, png_ptr->user_width_max = user_width_max; png_ptr->user_height_max = user_height_max; } +/* This function was added to libpng 1.4.0 */ +void PNGAPI +png_set_chunk_cache_max (png_structp png_ptr, + png_uint_32 user_chunk_cache_max) +{ + if (png_ptr == NULL) + return; + png_ptr->user_chunk_cache_max = user_chunk_cache_max; + if (user_chunk_cache_max == 0x7fffffffL) /* Unlimited */ + png_ptr->user_chunk_cache_max = 0; + else + png_ptr->user_chunk_cache_max = user_chunk_cache_max + 1; +} #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ -#endif /* ?PNG_1_0_X */ + +#if defined(PNG_BENIGN_ERRORS_SUPPORTED) +void PNGAPI +png_set_benign_errors(png_structp png_ptr, int allowed) +{ + png_debug(1, "in png_set_benign_errors"); + if (allowed) + png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN; + else + png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN; +} +#endif /* PNG_BENIGN_ERRORS_SUPPORTED */ #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */