Imported from libpng-1.2.30beta04.tar

This commit is contained in:
Glenn Randers-Pehrson
2008-07-10 09:10:58 -05:00
parent b96b342561
commit 4310a4d813
63 changed files with 737 additions and 708 deletions

196
pngtest.c
View File

@@ -1,7 +1,7 @@
/* pngtest.c - a simple test program to test libpng
*
* Last changed in libpng 1.2.30 [July 6, 2008]
* Last changed in libpng 1.2.30 [July 10, 2008]
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -83,7 +83,7 @@ static float t_start, t_stop, t_decode, t_encode, t_misc;
#if defined(PNG_TIME_RFC1123_SUPPORTED)
#define PNG_tIME_STRING_LENGTH 30
static int tIME_chunk_present=0;
static int tIME_chunk_present = 0;
static char tIME_string[PNG_tIME_STRING_LENGTH] = "no tIME chunk present in file";
#endif
@@ -110,9 +110,9 @@ int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname));
#endif
/* example of using row callbacks to make a simple progress meter */
static int status_pass=1;
static int status_dots_requested=0;
static int status_dots=1;
static int status_pass = 1;
static int status_dots_requested = 0;
static int status_dots = 1;
void
#ifdef PNG_1_0_X
@@ -125,15 +125,15 @@ PNGAPI
#endif
read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
{
if(png_ptr == NULL || row_number > PNG_UINT_31_MAX) return;
if(status_pass != pass)
if (png_ptr == NULL || row_number > PNG_UINT_31_MAX) return;
if (status_pass != pass)
{
fprintf(stdout, "\n Pass %d: ", pass);
status_pass = pass;
status_dots = 31;
}
status_dots--;
if(status_dots == 0)
if (status_dots == 0)
{
fprintf(stdout, "\n ");
status_dots=30;
@@ -152,7 +152,7 @@ PNGAPI
#endif
write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
{
if(png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7) return;
if (png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7) return;
fprintf(stdout, "w");
}
@@ -173,8 +173,8 @@ PNGAPI
#endif
count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data)
{
if(png_ptr != NULL && row_info != NULL)
++filters_used[*(data-1)];
if (png_ptr != NULL && row_info != NULL)
++filters_used[*(data - 1)];
}
#endif
@@ -196,7 +196,7 @@ PNGAPI
count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
{
png_bytep dp = data;
if(png_ptr == NULL)return;
if (png_ptr == NULL)return;
/* contents of row_info:
* png_uint_32 width width of row
@@ -210,44 +210,44 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
/* counts the number of zero samples (or zero pixels if color_type is 3 */
if(row_info->color_type == 0 || row_info->color_type == 3)
if (row_info->color_type == 0 || row_info->color_type == 3)
{
int pos=0;
int pos = 0;
png_uint_32 n, nstop;
for (n=0, nstop=row_info->width; n<nstop; n++)
for (n = 0, nstop=row_info->width; n<nstop; n++)
{
if(row_info->bit_depth == 1)
if (row_info->bit_depth == 1)
{
if(((*dp << pos++ ) & 0x80) == 0) zero_samples++;
if(pos == 8)
if (((*dp << pos++ ) & 0x80) == 0) zero_samples++;
if (pos == 8)
{
pos = 0;
dp++;
}
}
if(row_info->bit_depth == 2)
if (row_info->bit_depth == 2)
{
if(((*dp << (pos+=2)) & 0xc0) == 0) zero_samples++;
if(pos == 8)
if (((*dp << (pos+=2)) & 0xc0) == 0) zero_samples++;
if (pos == 8)
{
pos = 0;
dp++;
}
}
if(row_info->bit_depth == 4)
if (row_info->bit_depth == 4)
{
if(((*dp << (pos+=4)) & 0xf0) == 0) zero_samples++;
if(pos == 8)
if (((*dp << (pos+=4)) & 0xf0) == 0) zero_samples++;
if (pos == 8)
{
pos = 0;
dp++;
}
}
if(row_info->bit_depth == 8)
if(*dp++ == 0) zero_samples++;
if(row_info->bit_depth == 16)
if (row_info->bit_depth == 8)
if (*dp++ == 0) zero_samples++;
if (row_info->bit_depth == 16)
{
if((*dp | *(dp+1)) == 0) zero_samples++;
if ((*dp | *(dp+1)) == 0) zero_samples++;
dp+=2;
}
}
@@ -257,24 +257,24 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
png_uint_32 n, nstop;
int channel;
int color_channels = row_info->channels;
if(row_info->color_type > 3)color_channels--;
if (row_info->color_type > 3)color_channels--;
for (n=0, nstop=row_info->width; n<nstop; n++)
for (n = 0, nstop=row_info->width; n<nstop; n++)
{
for (channel = 0; channel < color_channels; channel++)
{
if(row_info->bit_depth == 8)
if(*dp++ == 0) zero_samples++;
if(row_info->bit_depth == 16)
if (row_info->bit_depth == 8)
if (*dp++ == 0) zero_samples++;
if (row_info->bit_depth == 16)
{
if((*dp | *(dp+1)) == 0) zero_samples++;
if ((*dp | *(dp+1)) == 0) zero_samples++;
dp+=2;
}
}
if(row_info->color_type > 3)
if (row_info->color_type > 3)
{
dp++;
if(row_info->bit_depth == 16)dp++;
if (row_info->bit_depth == 16)dp++;
}
}
}
@@ -342,7 +342,7 @@ pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
read = MIN(NEAR_BUF_SIZE, remaining);
READFILE(io_ptr, buf, 1, err);
png_memcpy(data, buf, read); /* copy far buffer to near buffer */
if(err != read)
if (err != read)
break;
else
check += err;
@@ -436,8 +436,6 @@ pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
}
}
#endif /* USE_FAR_KEYWORD */
#endif /* PNG_NO_STDIO */
/* END of code to validate stdio-free compilation */
/* This function is called when there is a warning, but the library thinks
* it can continue anyway. Replacement functions don't have to do anything
@@ -465,6 +463,8 @@ pngtest_error(png_structp png_ptr, png_const_charp message)
/* We can return because png_error calls the default handler, which is
* actually OK in this case. */
}
#endif /* PNG_NO_STDIO */
/* END of code to validate stdio-free compilation */
/* START of code to validate memory allocation and deallocation */
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
@@ -520,8 +520,9 @@ png_debug_malloc(png_structp png_ptr, png_uint_32 size)
maximum_allocation = current_allocation;
pinfo->pointer = (png_voidp)png_malloc(png_ptr, size);
/* Restore malloc_fn and free_fn */
png_set_mem_fn(png_ptr, png_voidp_NULL, (png_malloc_ptr)png_debug_malloc,
(png_free_ptr)png_debug_free);
png_set_mem_fn(png_ptr,
png_voidp_NULL, (png_malloc_ptr)png_debug_malloc,
(png_free_ptr)png_debug_free);
if (size != 0 && pinfo->pointer == NULL)
{
current_allocation -= size;
@@ -533,9 +534,9 @@ png_debug_malloc(png_structp png_ptr, png_uint_32 size)
pinformation = pinfo;
/* Make sure the caller isn't assuming zeroed memory. */
png_memset(pinfo->pointer, 0xdd, pinfo->size);
if(verbose)
if (verbose)
printf("png_malloc %lu bytes at %x\n", (unsigned long)size,
pinfo->pointer);
pinfo->pointer);
return (png_voidp)(pinfo->pointer);
}
}
@@ -583,7 +584,7 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
}
/* Finally free the data. */
if(verbose)
if (verbose)
printf("Freeing %x\n", ptr);
png_free_default(png_ptr, ptr);
ptr=NULL;
@@ -718,36 +719,44 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_debug(0, "Allocating read and write structures\n");
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
read_ptr = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, png_voidp_NULL,
read_ptr =
png_create_read_struct_2(PNG_LIBPNG_VER_STRING, png_voidp_NULL,
png_error_ptr_NULL, png_error_ptr_NULL, png_voidp_NULL,
(png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free);
#else
read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL,
read_ptr =
png_create_read_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL,
png_error_ptr_NULL, png_error_ptr_NULL);
#endif
#if defined(PNG_NO_STDIO)
png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error,
pngtest_warning);
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
user_chunk_data[0]=0;
user_chunk_data[1]=0;
user_chunk_data[2]=0;
user_chunk_data[3]=0;
user_chunk_data[0] = 0;
user_chunk_data[1] = 0;
user_chunk_data[2] = 0;
user_chunk_data[3] = 0;
png_set_read_user_chunk_fn(read_ptr, user_chunk_data,
read_user_chunk_callback);
#endif
#ifdef PNG_WRITE_SUPPORTED
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
write_ptr = png_create_write_struct_2(PNG_LIBPNG_VER_STRING, png_voidp_NULL,
write_ptr =
png_create_write_struct_2(PNG_LIBPNG_VER_STRING, png_voidp_NULL,
png_error_ptr_NULL, png_error_ptr_NULL, png_voidp_NULL,
(png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free);
#else
write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL,
write_ptr =
png_create_write_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL,
png_error_ptr_NULL, png_error_ptr_NULL);
#endif
#if defined(PNG_NO_STDIO)
png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error,
pngtest_warning);
#endif
#endif
png_debug(0, "Allocating read_info, write_info and end_info structures\n");
read_info_ptr = png_create_info_struct(read_ptr);
@@ -766,7 +775,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
{
fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
png_free(read_ptr, row_buf);
if (row_buf)
png_free(read_ptr, row_buf);
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
#ifdef PNG_WRITE_SUPPORTED
png_destroy_info_struct(write_ptr, &write_end_info_ptr);
@@ -821,7 +831,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
# endif
# endif
#endif
if(status_dots_requested == 1)
if (status_dots_requested == 1)
{
#ifdef PNG_WRITE_SUPPORTED
png_set_write_status_fn(write_ptr, write_row_callback);
@@ -839,13 +849,13 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
{
int i;
for(i=0; i<256; i++)
filters_used[i]=0;
for (i = 0; i<256; i++)
filters_used[i] = 0;
png_set_read_user_transform_fn(read_ptr, count_filters);
}
#endif
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
zero_samples=0;
zero_samples = 0;
png_set_write_user_transform_fn(write_ptr, count_zero_samples);
#endif
@@ -1084,9 +1094,9 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
pointed to by png_convert_to_rfc1123() gets free'ed before
we use it */
png_memcpy(tIME_string,
png_convert_to_rfc1123(read_ptr, mod_time),
png_convert_to_rfc1123(read_ptr, mod_time),
png_sizeof(tIME_string));
tIME_string[png_sizeof(tIME_string)-1] = '\0';
tIME_string[png_sizeof(tIME_string) - 1] = '\0';
tIME_chunk_present++;
#endif /* PNG_TIME_RFC1123_SUPPORTED */
}
@@ -1150,10 +1160,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
unsigned char
ster_chunk_data[1];
if(verbose)
if (verbose)
fprintf(STDERR, "stereo mode = %lu\n",
(unsigned long)(user_chunk_data[0]-1));
ster_chunk_data[0]=(unsigned char)(user_chunk_data[0]-1);
(unsigned long)(user_chunk_data[0] - 1));
ster_chunk_data[0]=(unsigned char)(user_chunk_data[0] - 1);
png_write_chunk(write_ptr, png_sTER, ster_chunk_data, 1);
}
if (user_chunk_data[1] != 0 || user_chunk_data[2] != 0)
@@ -1163,7 +1173,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
unsigned char
vpag_chunk_data[9];
if(verbose)
if (verbose)
fprintf(STDERR, "vpAg = %lu x %lu, units=%lu\n",
(unsigned long)user_chunk_data[1],
(unsigned long)user_chunk_data[2],
@@ -1192,7 +1202,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_set_interlace_handling(write_ptr);
# endif
#else
num_pass=1;
num_pass = 1;
#endif
#ifdef PNGTEST_TIMING
@@ -1271,7 +1281,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_memcpy(tIME_string,
png_convert_to_rfc1123(read_ptr, mod_time),
png_sizeof(tIME_string));
tIME_string[png_sizeof(tIME_string)-1] = '\0';
tIME_string[png_sizeof(tIME_string) - 1] = '\0';
tIME_chunk_present++;
#endif /* PNG_TIME_RFC1123_SUPPORTED */
}
@@ -1302,7 +1312,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
#ifdef PNG_EASY_ACCESS_SUPPORTED
if(verbose)
if (verbose)
{
png_uint_32 iwidth, iheight;
iwidth = png_get_image_width(write_ptr, write_info_ptr);
@@ -1355,18 +1365,18 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
return (1);
}
for(;;)
for (;;)
{
png_size_t num_in, num_out;
READFILE(fpin, inbuf, 1, num_in);
READFILE(fpout, outbuf, 1, num_out);
READFILE(fpin, inbuf, 1, num_in);
READFILE(fpout, outbuf, 1, num_out);
if (num_in != num_out)
{
fprintf(STDERR, "\nFiles %s and %s are of a different size\n",
inname, outname);
if(wrote_question == 0)
if (wrote_question == 0)
{
fprintf(STDERR,
" Was %s written with the same maximum IDAT chunk size (%d bytes),",
@@ -1376,7 +1386,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
fprintf(STDERR,
" level (zlib default),\n and zlib version (%s)?\n\n",
ZLIB_VERSION);
wrote_question=1;
wrote_question = 1;
}
FCLOSE(fpin);
FCLOSE(fpout);
@@ -1389,7 +1399,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
if (png_memcmp(inbuf, outbuf, num_in))
{
fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname);
if(wrote_question == 0)
if (wrote_question == 0)
{
fprintf(STDERR,
" Was %s written with the same maximum IDAT chunk size (%d bytes),",
@@ -1399,7 +1409,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
fprintf(STDERR,
" level (zlib default),\n and zlib version (%s)?\n\n",
ZLIB_VERSION);
wrote_question=1;
wrote_question = 1;
}
FCLOSE(fpin);
FCLOSE(fpout);
@@ -1489,10 +1499,10 @@ main(int argc, char *argv[])
}
}
if (!multiple && argc == 3+verbose)
outname = argv[2+verbose];
if (!multiple && argc == 3 + verbose)
outname = argv[2 + verbose];
if ((!multiple && argc > 3+verbose) || (multiple && argc < 2))
if ((!multiple && argc > 3 + verbose) || (multiple && argc < 2))
{
fprintf(STDERR,
"usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
@@ -1527,13 +1537,13 @@ main(int argc, char *argv[])
fprintf(STDERR, " PASS\n");
#endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
for (k=0; k<256; k++)
if(filters_used[k])
for (k = 0; k<256; k++)
if (filters_used[k])
fprintf(STDERR, " Filter %d was used %lu times\n",
k, (unsigned long)filters_used[k]);
#endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
if(tIME_chunk_present != 0)
if (tIME_chunk_present != 0)
fprintf(STDERR, " tIME = %s\n", tIME_string);
tIME_chunk_present = 0;
#endif /* PNG_TIME_RFC1123_SUPPORTED */
@@ -1546,7 +1556,7 @@ main(int argc, char *argv[])
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
if (allocation_now != current_allocation)
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
current_allocation-allocation_now);
current_allocation - allocation_now);
if (current_allocation != 0)
{
memory_infop pinfo = pinformation;
@@ -1555,7 +1565,8 @@ main(int argc, char *argv[])
current_allocation);
while (pinfo != NULL)
{
fprintf(STDERR, " %lu bytes at %x\n", (unsigned long)pinfo->size,
fprintf(STDERR, " %lu bytes at %x\n",
(unsigned long)pinfo->size,
(unsigned int) pinfo->pointer);
pinfo = pinfo->next;
}
@@ -1576,20 +1587,20 @@ main(int argc, char *argv[])
else
{
int i;
for (i=0; i<3; ++i)
for (i = 0; i<3; ++i)
{
int kerror;
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
int allocation_now = current_allocation;
#endif
if (i == 1) status_dots_requested = 1;
else if(verbose == 0)status_dots_requested = 0;
else if (verbose == 0)status_dots_requested = 0;
if (i == 0 || verbose == 1 || ierror != 0)
fprintf(STDERR, "Testing %s:", inname);
kerror = test_one_file(inname, outname);
if(kerror == 0)
if (kerror == 0)
{
if(verbose == 1 || i == 2)
if (verbose == 1 || i == 2)
{
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
int k;
@@ -1601,20 +1612,21 @@ main(int argc, char *argv[])
fprintf(STDERR, " PASS\n");
#endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
for (k=0; k<256; k++)
if(filters_used[k])
for (k = 0; k<256; k++)
if (filters_used[k])
fprintf(STDERR, " Filter %d was used %lu times\n",
k, (unsigned long)filters_used[k]);
k,
(unsigned long)filters_used[k]);
#endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
if(tIME_chunk_present != 0)
if (tIME_chunk_present != 0)
fprintf(STDERR, " tIME = %s\n", tIME_string);
#endif /* PNG_TIME_RFC1123_SUPPORTED */
}
}
else
{
if(verbose == 0 && i != 2)
if (verbose == 0 && i != 2)
fprintf(STDERR, "Testing %s:", inname);
fprintf(STDERR, " FAIL\n");
ierror += kerror;
@@ -1622,7 +1634,7 @@ main(int argc, char *argv[])
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
if (allocation_now != current_allocation)
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
current_allocation-allocation_now);
current_allocation - allocation_now);
if (current_allocation != 0)
{
memory_infop pinfo = pinformation;
@@ -1672,4 +1684,4 @@ main(int argc, char *argv[])
}
/* Generate a compiler error if there is an old png.h in the search path. */
typedef version_1_2_30beta03 your_png_h_is_not_version_1_2_30beta03;
typedef version_1_2_30beta04 your_png_h_is_not_version_1_2_30beta04;