Imported from libpng-0.87.tar

This commit is contained in:
Guy Schalnat
1996-01-16 01:51:56 -06:00
committed by Glenn Randers-Pehrson
parent 69b1448f19
commit 4ee97b0891
22 changed files with 1210 additions and 863 deletions

View File

@@ -1,15 +1,17 @@
/* pngpread.c - read a png file in push mode
libpng 1.0 beta 2 - version 0.86
libpng 1.0 beta 2 - version 0.87
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
January 10, 1996
January 15, 1996
*/
#define PNG_INTERNAL
#include "png.h"
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
void
png_process_data(png_structp png_ptr, png_infop info,
png_bytep buffer, png_uint_32 buffer_size)
@@ -110,7 +112,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
png_push_fill_buffer(png_ptr, chunk_start, 8);
png_ptr->push_length = png_get_uint_32(chunk_start);
memcpy(png_ptr->push_chunk_name, chunk_start + 4, 4);
png_memcpy(png_ptr->push_chunk_name, (png_voidp)(chunk_start + 4), 4);
png_ptr->have_chunk_header = 1;
png_reset_crc(png_ptr);
png_calculate_crc(png_ptr, chunk_start + 4, 4);
@@ -142,7 +144,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
else
#else
{
png_push_handle_PLTE(png_ptr, info, png_ptr->push_length);
png_push_handle_PLTE(png_ptr, png_ptr->push_length);
}
#endif
png_ptr->mode = PNG_HAVE_PLTE;
@@ -316,7 +318,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
png_ptr->mode == PNG_AFTER_IEND)
png_error(png_ptr, "Out of Place tEXt");
png_push_handle_tEXt(png_ptr, info, png_ptr->push_length);
png_push_handle_tEXt(png_ptr, png_ptr->push_length);
}
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
@@ -326,7 +328,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
png_ptr->mode == PNG_AFTER_IEND)
png_error(png_ptr, "Out of Place zTXt");
png_push_handle_zTXt(png_ptr, info, png_ptr->push_length);
png_push_handle_zTXt(png_ptr, png_ptr->push_length);
}
#endif
else
@@ -376,7 +378,7 @@ png_push_skip(png_structp png_ptr)
png_ptr->skip_length -= save_size;
png_ptr->buffer_size -= save_size;
png_ptr->save_buffer_size -= save_size;
png_ptr->save_buffer_ptr += save_size;
png_ptr->save_buffer_ptr += (png_size_t)save_size;
}
if (png_ptr->skip_length && png_ptr->current_buffer_size)
{
@@ -392,7 +394,7 @@ png_push_skip(png_structp png_ptr)
png_ptr->skip_length -= save_size;
png_ptr->buffer_size -= save_size;
png_ptr->current_buffer_size -= save_size;
png_ptr->current_buffer_ptr += save_size;
png_ptr->current_buffer_ptr += (png_size_t)save_size;
}
if (!png_ptr->skip_length && png_ptr->buffer_size >= 4)
{
@@ -405,7 +407,7 @@ void
png_push_fill_buffer(png_structp png_ptr, png_bytep buffer,
png_uint_32 length)
{
png_byte * ptr;
png_bytep ptr;
ptr = buffer;
if (png_ptr->save_buffer_size)
@@ -417,12 +419,12 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer,
else
save_size = png_ptr->save_buffer_size;
memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
png_memcpy(ptr, png_ptr->save_buffer_ptr, (png_size_t)save_size);
length -= save_size;
ptr += save_size;
ptr += (png_size_t)save_size;
png_ptr->buffer_size -= save_size;
png_ptr->save_buffer_size -= save_size;
png_ptr->save_buffer_ptr += save_size;
png_ptr->save_buffer_ptr += (png_size_t)save_size;
}
if (length && png_ptr->current_buffer_size)
{
@@ -433,10 +435,10 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer,
else
save_size = png_ptr->current_buffer_size;
memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
png_memcpy(ptr, png_ptr->current_buffer_ptr, (png_size_t)save_size);
png_ptr->buffer_size -= save_size;
png_ptr->current_buffer_size -= save_size;
png_ptr->current_buffer_ptr += save_size;
png_ptr->current_buffer_ptr += (png_size_t)save_size;
}
}
@@ -448,8 +450,8 @@ png_push_save_buffer(png_structp png_ptr)
if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
{
int i;
png_byte * sp;
png_byte * dp;
png_bytep sp;
png_bytep dp;
for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
i < png_ptr->save_buffer_size;
@@ -463,22 +465,24 @@ png_push_save_buffer(png_structp png_ptr)
png_ptr->save_buffer_max)
{
int new_max;
png_byte * old_buffer;
png_bytep old_buffer;
new_max = png_ptr->save_buffer_size +
png_ptr->current_buffer_size + 256;
new_max = (int)(png_ptr->save_buffer_size +
png_ptr->current_buffer_size + 256);
old_buffer = png_ptr->save_buffer;
png_ptr->save_buffer = (png_byte *)
png_ptr->save_buffer = (png_bytep)
png_large_malloc(png_ptr, new_max);
memcpy(png_ptr->save_buffer, old_buffer,
png_ptr->save_buffer_size);
png_memcpy(png_ptr->save_buffer, old_buffer,
(png_size_t)png_ptr->save_buffer_size);
png_large_free(png_ptr, old_buffer);
png_ptr->save_buffer_max = new_max;
}
if (png_ptr->current_buffer_size)
{
memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
png_memcpy(png_ptr->save_buffer +
(png_size_t)png_ptr->save_buffer_size,
png_ptr->current_buffer_ptr,
(png_size_t)png_ptr->current_buffer_size);
png_ptr->save_buffer_size += png_ptr->current_buffer_size;
png_ptr->current_buffer_size = 0;
}
@@ -511,7 +515,8 @@ png_push_read_idat(png_structp png_ptr)
png_push_fill_buffer(png_ptr, chunk_start, 8);
png_ptr->push_length = png_get_uint_32(chunk_start);
memcpy(png_ptr->push_chunk_name, chunk_start + 4, 4);
png_memcpy(png_ptr->push_chunk_name,
(png_voidp)(chunk_start + 4), 4);
png_ptr->have_chunk_header = 1;
png_reset_crc(png_ptr);
png_calculate_crc(png_ptr, chunk_start + 4, 4);
@@ -540,7 +545,7 @@ png_push_read_idat(png_structp png_ptr)
png_ptr->idat_size -= save_size;
png_ptr->buffer_size -= save_size;
png_ptr->save_buffer_size -= save_size;
png_ptr->save_buffer_ptr += save_size;
png_ptr->save_buffer_ptr += (png_size_t)save_size;
}
if (png_ptr->idat_size && png_ptr->current_buffer_size)
{
@@ -557,7 +562,7 @@ png_push_read_idat(png_structp png_ptr)
png_ptr->idat_size -= save_size;
png_ptr->buffer_size -= save_size;
png_ptr->current_buffer_size -= save_size;
png_ptr->current_buffer_ptr += save_size;
png_ptr->current_buffer_ptr += (png_size_t)save_size;
}
if (!png_ptr->idat_size && png_ptr->buffer_size >= 4)
{
@@ -785,14 +790,14 @@ png_read_push_finish_row(png_structp png_ptr)
void
png_push_handle_PLTE(png_structp png_ptr, png_infop info, png_uint_32 length)
png_push_handle_PLTE(png_structp png_ptr, png_uint_32 length)
{
if (length % 3)
png_error(png_ptr, "Invalid Palette Chunk");
png_ptr->num_palette = length / 3;
png_ptr->num_palette = (png_uint_16)(length / 3);
png_ptr->cur_palette = 0;
png_ptr->palette = (png_colorp)png_malloc(png_ptr,
png_ptr->palette = (png_colorp)png_large_malloc(png_ptr,
png_ptr->num_palette * sizeof (png_color));
png_ptr->process_mode = PNG_READ_PLTE_MODE;
}
@@ -828,8 +833,7 @@ png_push_read_plte(png_structp png_ptr, png_infop info)
#if defined(PNG_READ_tEXt_SUPPORTED)
void
png_push_handle_tEXt(png_structp png_ptr, png_infop info,
png_uint_32 length)
png_push_handle_tEXt(png_structp png_ptr, png_uint_32 length)
{
png_ptr->current_text = (png_charp)png_large_malloc(png_ptr, length + 1);
png_ptr->current_text[(png_size_t)length] = '\0';
@@ -855,7 +859,7 @@ png_push_read_text(png_structp png_ptr, png_infop info)
png_calculate_crc(png_ptr, (png_bytep)png_ptr->current_text_ptr,
text_size);
png_ptr->current_text_left -= text_size;
png_ptr->current_text_ptr += text_size;
png_ptr->current_text_ptr += (png_size_t)text_size;
}
if (!(png_ptr->current_text_left) && png_ptr->buffer_size >= 4)
{
@@ -882,7 +886,7 @@ png_push_read_text(png_structp png_ptr, png_infop info)
#if defined(PNG_READ_zTXt_SUPPORTED)
void
png_push_handle_zTXt(png_structp png_ptr, png_infop info,
png_push_handle_zTXt(png_structp png_ptr,
png_uint_32 length)
{
png_ptr->current_text = (png_charp)png_large_malloc(png_ptr, length + 1);
@@ -909,7 +913,7 @@ png_push_read_ztxt(png_structp png_ptr, png_infop info)
png_calculate_crc(png_ptr, (png_bytep)png_ptr->current_text_ptr,
text_size);
png_ptr->current_text_left -= text_size;
png_ptr->current_text_ptr += text_size;
png_ptr->current_text_ptr += (png_size_t)text_size;
}
if (!(png_ptr->current_text_left) && png_ptr->buffer_size >= 4)
{
@@ -923,8 +927,6 @@ png_push_read_ztxt(png_structp png_ptr, png_infop info)
key = png_ptr->current_text;
png_ptr->current_text = 0;
text = NULL;
for (text = key; *text; text++)
/* empty loop */ ;
@@ -954,7 +956,7 @@ png_push_read_ztxt(png_structp png_ptr, png_infop info)
key_size = text - key;
text_size = 0;
text = NULL;
ret = Z_STREAM_END;
ret = Z_STREAM_END;
while (png_ptr->zstream->avail_in)
{
@@ -971,7 +973,7 @@ png_push_read_ztxt(png_structp png_ptr, png_infop info)
{
if (!text)
{
text = (png_charp)png_malloc(png_ptr,
text = (png_charp)png_large_malloc(png_ptr,
png_ptr->zbuf_size - png_ptr->zstream->avail_out +
key_size + 1);
png_memcpy(text + (png_size_t)key_size, png_ptr->zbuf,
@@ -1073,7 +1075,7 @@ png_push_read_end(png_structp png_ptr, png_infop info)
png_push_fill_buffer(png_ptr, chunk_start, 8);
png_ptr->push_length = png_get_uint_32(chunk_start);
memcpy(png_ptr->push_chunk_name, chunk_start + 4, 4);
png_memcpy(png_ptr->push_chunk_name, (png_voidp)(chunk_start + 4), 4);
png_ptr->have_chunk_header = 1;
png_reset_crc(png_ptr);
png_calculate_crc(png_ptr, chunk_start + 4, 4);
@@ -1173,7 +1175,7 @@ png_push_read_end(png_structp png_ptr, png_infop info)
png_ptr->mode == PNG_AFTER_IEND)
png_error(png_ptr, "Out of Place tEXt");
png_push_handle_tEXt(png_ptr, info, png_ptr->push_length);
png_push_handle_tEXt(png_ptr, png_ptr->push_length);
}
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
@@ -1183,7 +1185,7 @@ png_push_read_end(png_structp png_ptr, png_infop info)
png_ptr->mode == PNG_AFTER_IEND)
png_error(png_ptr, "Out of Place zTXt");
png_push_handle_zTXt(png_ptr, info, png_ptr->push_length);
png_push_handle_zTXt(png_ptr, png_ptr->push_length);
}
#endif
else
@@ -1214,6 +1216,9 @@ void
png_progressive_combine_row (png_structp png_ptr,
png_bytep old_row, png_bytep new_row)
{
png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
if (new_row)
png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
}
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */