Imported from libpng-1.0.11rc1.tar

This commit is contained in:
Glenn Randers-Pehrson
2001-04-20 10:32:10 -05:00
parent e1eff58f87
commit 82ae383331
54 changed files with 396 additions and 739 deletions

130
pngset.c
View File

@@ -1,7 +1,7 @@
/* pngset.c - storage of image information into info struct
*
* libpng 1.0.11beta3 - April 15, 2001
* libpng 1.0.11rc1 - April 20, 2001
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -154,11 +154,6 @@ png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
#endif
png_ptr->hist = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)(info_ptr->num_palette * sizeof (png_uint_16)));
if (png_ptr->hist == (png_uint_16p)NULL)
{
png_warning (png_ptr, "Could not allocate memory for histogram");
return;
}
for (i = 0; i < info_ptr->num_palette; i++)
png_ptr->hist[i] = hist[i];
@@ -300,11 +295,6 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
length = png_strlen(purpose) + 1;
png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
info_ptr->pcal_purpose = (png_charp)png_malloc(png_ptr, length);
if (info_ptr->pcal_purpose == (png_charp)NULL)
{
png_warning (png_ptr, "Could not allocate memory for pCAL");
return;
}
png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
png_debug(3, "storing X0, X1, type, and nparams in info\n");
@@ -316,23 +306,10 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
length = png_strlen(units) + 1;
png_debug1(3, "allocating units for info (%lu bytes)\n", length);
info_ptr->pcal_units = (png_charp)png_malloc(png_ptr, length);
if (info_ptr->pcal_units == (png_charp)NULL)
{
png_free (png_ptr, info_ptr->pcal_purpose);
png_warning (png_ptr, "Could not allocate memory for pCAL units");
return;
}
png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
info_ptr->pcal_params = (png_charpp)png_malloc(png_ptr,
(png_uint_32)((nparams + 1) * sizeof(png_charp)));
if (info_ptr->pcal_params == (png_charpp)NULL)
{
png_free (png_ptr, info_ptr->pcal_purpose);
png_free (png_ptr, info_ptr->pcal_units);
png_warning (png_ptr, "Could not allocate memory for pCAL params");
return;
}
info_ptr->pcal_params[nparams] = NULL;
@@ -341,13 +318,7 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
length = png_strlen(params[i]) + 1;
png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
info_ptr->pcal_params[i] = (png_charp)png_malloc(png_ptr, length);
if (info_ptr->pcal_params[i] == (png_charp)NULL)
{
nparams=i;
png_warning (png_ptr, "Could not allocate memory for pCAL params");
}
else
png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
}
info_ptr->valid |= PNG_INFO_pCAL;
@@ -390,14 +361,12 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
length = png_strlen(swidth) + 1;
png_debug1(3, "allocating unit for info (%d bytes)\n", length);
info_ptr->scal_s_width = (png_charp)png_malloc(png_ptr, length);
if (info_ptr->scal_s_width != (png_charp)NULL)
png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
length = png_strlen(sheight) + 1;
png_debug1(3, "allocating unit for info (%d bytes)\n", length);
info_ptr->scal_s_height = (png_charp)png_malloc(png_ptr, length);
if (info_ptr->scal_s_height != (png_charp)NULL)
png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
info_ptr->valid |= PNG_INFO_sCAL;
#ifdef PNG_FREE_ME_SUPPORTED
@@ -443,11 +412,6 @@ png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
#endif
png_ptr->palette = (png_colorp)png_zalloc(png_ptr, (uInt)num_palette,
sizeof (png_color));
if (png_ptr->palette == (png_colorp)NULL)
{
png_warning(png_ptr, "Unable to allocate palette");
return;
}
png_memcpy(png_ptr->palette, palette, num_palette * sizeof (png_color));
info_ptr->palette = png_ptr->palette;
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
@@ -572,19 +536,8 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
return;
new_iccp_name = (png_charp)png_malloc(png_ptr, png_strlen(name)+1);
if (new_iccp_name == (png_charp)NULL)
{
png_warning (png_ptr, "Could not allocate memory for ICC profile name");
return;
}
png_strcpy(new_iccp_name, name);
new_iccp_profile = (png_charp)png_malloc(png_ptr, proflen);
if (new_iccp_profile == (png_charp)NULL)
{
png_warning (png_ptr, "Could not allocate memory for ICC profile");
png_free (png_ptr, new_iccp_name);
return;
}
png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
@@ -630,12 +583,6 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
old_text = info_ptr->text;
info_ptr->text = (png_textp)png_malloc(png_ptr,
(png_uint_32)(info_ptr->max_text * sizeof (png_text)));
if (info_ptr->text == (png_textp)NULL)
{
png_warning (png_ptr, "Could not allocate memory for text");
info_ptr->text = old_text;
return;
}
png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
sizeof(png_text)));
png_free(png_ptr, old_text);
@@ -646,11 +593,6 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
info_ptr->num_text = 0;
info_ptr->text = (png_textp)png_malloc(png_ptr,
(png_uint_32)(info_ptr->max_text * sizeof (png_text)));
if (info_ptr->text == (png_textp)NULL)
{
png_warning (png_ptr, "Could not allocate memory for text");
return;
}
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_TEXT;
#endif
@@ -664,7 +606,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
png_size_t lang_len,lang_key_len;
png_textp textp = &(info_ptr->text[info_ptr->num_text]);
if (text_ptr[i].key == (png_charp)NULL)
if (text_ptr[i].key == NULL)
continue;
key_len = png_strlen(text_ptr[i].key);
@@ -678,11 +620,11 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
#ifdef PNG_iTXt_SUPPORTED
{
/* set iTXt data */
if (text_ptr[i].key != (png_charp)NULL)
if (text_ptr[i].key != NULL)
lang_len = png_strlen(text_ptr[i].lang);
else
lang_len = 0;
if (text_ptr[i].lang_key != (png_charp)NULL)
if (text_ptr[i].lang_key != NULL)
lang_key_len = png_strlen(text_ptr[i].lang_key);
else
lang_key_len = 0;
@@ -694,7 +636,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
}
#endif
if (text_ptr[i].text == (png_charp)NULL || text_ptr[i].text[0] == '\0')
if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
{
text_length = 0;
#ifdef PNG_iTXt_SUPPORTED
@@ -712,11 +654,6 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
textp->key = (png_charp)png_malloc(png_ptr,
(png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
if (textp->key == (png_charp)NULL)
{
png_warning (png_ptr, "Could not allocate memory for text pointer");
return;
}
png_debug2(2, "Allocated %d bytes at %x in png_set_text\n",
key_len + lang_len + lang_key_len + text_length + 4, (int)textp->key);
@@ -804,11 +741,6 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
#endif
png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
num_trans);
if (png_ptr->trans == (png_bytep)NULL)
{
png_warning (png_ptr, "Could not allocate memory for tRNS array");
return;
}
png_memcpy(info_ptr->trans, trans, num_trans);
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_TRNS;
@@ -839,11 +771,6 @@ png_set_sPLT(png_structp png_ptr,
np = (png_sPLT_tp)png_malloc(png_ptr,
(info_ptr->splt_palettes_num + nentries) * sizeof(png_sPLT_t));
if (np == (png_sPLT_tp)NULL)
{
png_warning (png_ptr, "Could not allocate memory for sPLT");
return;
}
png_memcpy(np, info_ptr->splt_palettes,
info_ptr->splt_palettes_num * sizeof(png_sPLT_t));
@@ -860,18 +787,10 @@ png_set_sPLT(png_structp png_ptr,
png_strcpy(to->name, from->name);
to->entries = (png_sPLT_entryp)png_malloc(png_ptr,
from->nentries * sizeof(png_sPLT_t));
if (to->entries == (png_sPLT_entryp)NULL)
{
png_warning(png_ptr, "Could not allocate memory for sPLT entry");
nentries=i;
}
else
{
png_memcpy(to->entries, from->entries,
from->nentries * sizeof(png_sPLT_t));
to->nentries = from->nentries;
to->depth = from->depth;
}
png_memcpy(to->entries, from->entries,
from->nentries * sizeof(png_sPLT_t));
to->nentries = from->nentries;
to->depth = from->depth;
}
info_ptr->splt_palettes = np;
@@ -897,11 +816,6 @@ png_set_unknown_chunks(png_structp png_ptr,
np = (png_unknown_chunkp)png_malloc(png_ptr,
(info_ptr->unknown_chunks_num + num_unknowns) *
sizeof(png_unknown_chunk));
if (np == (png_unknown_chunkp)NULL)
{
png_warning (png_ptr, "Could not allocate memory for unknown chunk");
return;
}
png_memcpy(np, info_ptr->unknown_chunks,
info_ptr->unknown_chunks_num * sizeof(png_unknown_chunk));
@@ -915,19 +829,11 @@ png_set_unknown_chunks(png_structp png_ptr,
png_strcpy((png_charp)to->name, (png_charp)from->name);
to->data = (png_bytep)png_malloc(png_ptr, from->size);
if (to->data == (png_bytep)NULL)
{
png_warning(png_ptr, "Could not allocate memory for unknown entry");
num_unknowns=i;
}
else
{
png_memcpy(to->data, from->data, from->size);
to->size = from->size;
png_memcpy(to->data, from->data, from->size);
to->size = from->size;
/* note our location in the read or write sequence */
to->location = (png_byte)(png_ptr->mode & 0xff);
}
/* note our location in the read or write sequence */
to->location = (png_byte)(png_ptr->mode & 0xff);
}
info_ptr->unknown_chunks = np;
@@ -999,7 +905,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,5*(num_chunks+old_num_chunks));
if(png_ptr->chunk_list != (png_bytep)NULL)
if(png_ptr->chunk_list != NULL)
{
png_memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks);
png_free(png_ptr, png_ptr->chunk_list);
@@ -1051,8 +957,6 @@ png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
png_free(png_ptr, png_ptr->zbuf);
png_ptr->zbuf_size = (png_size_t)size;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
if(!png_ptr->zbuf)
png_error(png_ptr,"Unable to malloc zbuf");
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
}