aboutsummaryrefslogtreecommitdiffstats
path: root/pngtest.c
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-09 11:52:12 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-09 11:52:12 -0700
commit4215dd1533c56e1a89ae6f1d6ea68677fac27fda (patch)
tree99318267166103602095f7af976be5b7f0e25d04 /pngtest.c
parent893912bfc2683463dc3e2c445336752d012563d3 (diff)
downloadexternal_libpng-4215dd1533c56e1a89ae6f1d6ea68677fac27fda.zip
external_libpng-4215dd1533c56e1a89ae6f1d6ea68677fac27fda.tar.gz
external_libpng-4215dd1533c56e1a89ae6f1d6ea68677fac27fda.tar.bz2
auto import from //branches/cupcake/...@137197
Diffstat (limited to 'pngtest.c')
-rw-r--r--pngtest.c409
1 files changed, 267 insertions, 142 deletions
diff --git a/pngtest.c b/pngtest.c
index 60980c2..f5e098f 100644
--- a/pngtest.c
+++ b/pngtest.c
@@ -1,7 +1,7 @@
/* pngtest.c - a simple test program to test libpng
*
- * Last changed in libpng 1.2.27 - [April 29, 2008]
+ * Last changed in libpng 1.2.32 [September 18, 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)
@@ -37,7 +37,7 @@
# include <windows.h>
# include <stdlib.h>
# define READFILE(file, data, length, check) \
- if (ReadFile(file, data, length, &check,NULL)) check = 0
+ if (ReadFile(file, data, length, &check, NULL)) check = 0
# define WRITEFILE(file, data, length, check)) \
if (WriteFile(file, data, length, &check, NULL)) check = 0
# define FCLOSE(file) CloseHandle(file)
@@ -45,9 +45,9 @@
# include <stdio.h>
# include <stdlib.h>
# define READFILE(file, data, length, check) \
- check=(png_size_t)fread(data,(png_size_t)1,length,file)
+ check=(png_size_t)fread(data, (png_size_t)1, length, file)
# define WRITEFILE(file, data, length, check) \
- check=(png_size_t)fwrite(data,(png_size_t)1, length, file)
+ check=(png_size_t)fwrite(data, (png_size_t)1, length, file)
# define FCLOSE(file) fclose(file)
#endif
@@ -82,9 +82,9 @@ static float t_start, t_stop, t_decode, t_encode, t_misc;
#endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
-#define PNG_tIME_STRING_LENGTH 30
-static int tIME_chunk_present=0;
-static char tIME_string[PNG_tIME_STRING_LENGTH] = "no tIME chunk present in file";
+#define PNG_tIME_STRING_LENGTH 29
+static int tIME_chunk_present = 0;
+static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present";
#endif
static int verbose = 0;
@@ -99,11 +99,6 @@ int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname));
/* #define STDERR stderr */
#define STDERR stdout /* for DOS */
-/* 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;
-
/* In case a system header (e.g., on AIX) defined jmpbuf */
#ifdef jmpbuf
# undef jmpbuf
@@ -114,6 +109,11 @@ static int status_dots=1;
# define png_jmpbuf(png_ptr) png_ptr->jmpbuf
#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;
+
void
#ifdef PNG_1_0_X
PNGAPI
@@ -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);
+ 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
@@ -511,7 +511,7 @@ png_debug_malloc(png_structp png_ptr, png_uint_32 size)
memory_infop pinfo;
png_set_mem_fn(png_ptr, NULL, NULL, NULL);
pinfo = (memory_infop)png_malloc(png_ptr,
- (png_uint_32)png_sizeof (*pinfo));
+ (png_uint_32)png_sizeof(*pinfo));
pinfo->size = size;
current_allocation += size;
total_allocation += size;
@@ -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)
- printf("png_malloc %lu bytes at %x\n",(unsigned long)size,
- pinfo->pointer);
+ if (verbose)
+ printf("png_malloc %lu bytes at %x\n", (unsigned long)size,
+ pinfo->pointer);
return (png_voidp)(pinfo->pointer);
}
}
@@ -570,7 +571,7 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
the memory that is to be freed. */
png_memset(ptr, 0x55, pinfo->size);
png_free_default(png_ptr, pinfo);
- pinfo=NULL;
+ pinfo = NULL;
break;
}
if (pinfo->next == NULL)
@@ -583,14 +584,81 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
}
/* Finally free the data. */
- if(verbose)
- printf("Freeing %x\n",ptr);
+ if (verbose)
+ printf("Freeing %x\n", ptr);
png_free_default(png_ptr, ptr);
- ptr=NULL;
+ ptr = NULL;
}
#endif /* PNG_USER_MEM_SUPPORTED && PNG_DEBUG */
/* END of code to test memory allocation/deallocation */
+
+/* Demonstration of user chunk support of the sTER and vpAg chunks */
+#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
+
+/* (sTER is a public chunk not yet understood by libpng. vpAg is a private
+chunk used in ImageMagick to store "virtual page" size). */
+
+static png_uint_32 user_chunk_data[4];
+
+ /* 0: sTER mode + 1
+ * 1: vpAg width
+ * 2: vpAg height
+ * 3: vpAg units
+ */
+
+static int read_user_chunk_callback(png_struct *png_ptr,
+ png_unknown_chunkp chunk)
+{
+ png_uint_32
+ *user_chunk_data;
+
+ /* Return one of the following: */
+ /* return (-n); chunk had an error */
+ /* return (0); did not recognize */
+ /* return (n); success */
+
+ /* The unknown chunk structure contains the chunk data:
+ * png_byte name[5];
+ * png_byte *data;
+ * png_size_t size;
+ *
+ * Note that libpng has already taken care of the CRC handling.
+ */
+
+ if (chunk->name[0] == 115 && chunk->name[1] == 84 && /* s T */
+ chunk->name[2] == 69 && chunk->name[3] == 82) /* E R */
+ {
+ /* Found sTER chunk */
+ if (chunk->size != 1)
+ return (-1); /* Error return */
+ if (chunk->data[0] != 0 && chunk->data[0] != 1)
+ return (-1); /* Invalid mode */
+ user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr);
+ user_chunk_data[0]=chunk->data[0]+1;
+ return (1);
+ }
+ if (chunk->name[0] != 118 || chunk->name[1] != 112 || /* v p */
+ chunk->name[2] != 65 || chunk->name[3] != 103) /* A g */
+ return (0); /* Did not recognize */
+
+ /* Found ImageMagick vpAg chunk */
+
+ if (chunk->size != 9)
+ return (-1); /* Error return */
+
+ user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr);
+
+ user_chunk_data[1]=png_get_uint_31(png_ptr, chunk->data);
+ user_chunk_data[2]=png_get_uint_31(png_ptr, chunk->data + 4);
+ user_chunk_data[3]=(png_uint_32)chunk->data[8];
+
+ return (1);
+
+}
+#endif
+/* END of code to demonstrate user chunk support */
+
/* Test one file */
int
test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
@@ -649,30 +717,48 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
return (1);
}
- png_debug(0, "Allocating read and write structures\n");
+ png_debug(0, "Allocating read and write structures");
#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;
+ 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
- png_debug(0, "Allocating read_info, write_info and end_info structures\n");
+#endif
+ png_debug(0, "Allocating read_info, write_info and end_info structures");
read_info_ptr = png_create_info_struct(read_ptr);
end_info_ptr = png_create_info_struct(read_ptr);
#ifdef PNG_WRITE_SUPPORTED
@@ -681,7 +767,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
#ifdef PNG_SETJMP_SUPPORTED
- png_debug(0, "Setting jmpbuf for read struct\n");
+ png_debug(0, "Setting jmpbuf for read struct");
#ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf))
#else
@@ -690,6 +776,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
png_free(read_ptr, row_buf);
+ row_buf = NULL;
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);
@@ -700,11 +787,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
return (1);
}
#ifdef USE_FAR_KEYWORD
- png_memcpy(png_jmpbuf(read_ptr),jmpbuf,png_sizeof(jmp_buf));
+ png_memcpy(png_jmpbuf(read_ptr), jmpbuf, png_sizeof(jmp_buf));
#endif
#ifdef PNG_WRITE_SUPPORTED
- png_debug(0, "Setting jmpbuf for write struct\n");
+ png_debug(0, "Setting jmpbuf for write struct");
#ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf))
#else
@@ -722,12 +809,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
return (1);
}
#ifdef USE_FAR_KEYWORD
- png_memcpy(png_jmpbuf(write_ptr),jmpbuf,png_sizeof(jmp_buf));
+ png_memcpy(png_jmpbuf(write_ptr), jmpbuf, png_sizeof(jmp_buf));
#endif
#endif
#endif
- png_debug(0, "Initializing input and output streams\n");
+ png_debug(0, "Initializing input and output streams");
#if !defined(PNG_NO_STDIO)
png_init_io(read_ptr, fpin);
# ifdef PNG_WRITE_SUPPORTED
@@ -744,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);
@@ -762,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
@@ -787,10 +874,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_bytep_NULL, 0);
#endif
- png_debug(0, "Reading info struct\n");
+ png_debug(0, "Reading info struct");
png_read_info(read_ptr, read_info_ptr);
- png_debug(0, "Transferring info struct\n");
+ png_debug(0, "Transferring info struct");
{
int interlace_type, compression_type, filter_type;
@@ -913,7 +1000,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_int_32 offset_x, offset_y;
int unit_type;
- if (png_get_oFFs(read_ptr, read_info_ptr,&offset_x,&offset_y,&unit_type))
+ if (png_get_oFFs(read_ptr, read_info_ptr, &offset_x, &offset_y,
+ &unit_type))
{
png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type);
}
@@ -989,7 +1077,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0)
{
- png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks\n", num_text);
+ png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks", num_text);
png_set_text(write_ptr, write_info_ptr, text_ptr, num_text);
}
}
@@ -1006,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 */
}
@@ -1057,21 +1145,55 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
#ifdef PNG_WRITE_SUPPORTED
- png_debug(0, "\nWriting info struct\n");
+ png_debug(0, "Writing info struct");
/* If we wanted, we could write info in two steps:
png_write_info_before_PLTE(write_ptr, write_info_ptr);
*/
png_write_info(write_ptr, write_info_ptr);
+
+#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
+ if (user_chunk_data[0] != 0)
+ {
+ png_byte png_sTER[5] = {115, 84, 69, 82, '\0'};
+
+ unsigned char
+ ster_chunk_data[1];
+
+ 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);
+ png_write_chunk(write_ptr, png_sTER, ster_chunk_data, 1);
+ }
+ if (user_chunk_data[1] != 0 || user_chunk_data[2] != 0)
+ {
+ png_byte png_vpAg[5] = {118, 112, 65, 103, '\0'};
+
+ unsigned char
+ vpag_chunk_data[9];
+
+ if (verbose)
+ fprintf(STDERR, "vpAg = %lu x %lu, units=%lu\n",
+ (unsigned long)user_chunk_data[1],
+ (unsigned long)user_chunk_data[2],
+ (unsigned long)user_chunk_data[3]);
+ png_save_uint_32(vpag_chunk_data, user_chunk_data[1]);
+ png_save_uint_32(vpag_chunk_data + 4, user_chunk_data[2]);
+ vpag_chunk_data[8] = (unsigned char)(user_chunk_data[3] & 0xff);
+ png_write_chunk(write_ptr, png_vpAg, vpag_chunk_data, 9);
+ }
+
+#endif
#endif
#ifdef SINGLE_ROWBUF_ALLOC
- png_debug(0, "\nAllocating row buffer...");
+ png_debug(0, "Allocating row buffer...");
row_buf = (png_bytep)png_malloc(read_ptr,
png_get_rowbytes(read_ptr, read_info_ptr));
- png_debug1(0, "0x%08lx\n\n", (unsigned long)row_buf);
+ png_debug1(0, "0x%08lx", (unsigned long)row_buf);
#endif /* SINGLE_ROWBUF_ALLOC */
- png_debug(0, "Writing row data\n");
+ png_debug(0, "Writing row data");
#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
defined(PNG_WRITE_INTERLACING_SUPPORTED)
@@ -1080,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
@@ -1090,14 +1212,14 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
for (pass = 0; pass < num_pass; pass++)
{
- png_debug1(0, "Writing row data for pass %d\n",pass);
+ png_debug1(0, "Writing row data for pass %d", pass);
for (y = 0; y < height; y++)
{
#ifndef SINGLE_ROWBUF_ALLOC
- png_debug2(0, "\nAllocating row buffer (pass %d, y = %ld)...", pass,y);
+ png_debug2(0, "Allocating row buffer (pass %d, y = %ld)...", pass, y);
row_buf = (png_bytep)png_malloc(read_ptr,
png_get_rowbytes(read_ptr, read_info_ptr));
- png_debug2(0, "0x%08lx (%ld bytes)\n", (unsigned long)row_buf,
+ png_debug2(0, "0x%08lx (%ld bytes)", (unsigned long)row_buf,
png_get_rowbytes(read_ptr, read_info_ptr));
#endif /* !SINGLE_ROWBUF_ALLOC */
png_read_rows(read_ptr, (png_bytepp)&row_buf, png_bytepp_NULL, 1);
@@ -1117,8 +1239,9 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif /* PNG_WRITE_SUPPORTED */
#ifndef SINGLE_ROWBUF_ALLOC
- png_debug2(0, "Freeing row buffer (pass %d, y = %ld)\n\n", pass, y);
+ png_debug2(0, "Freeing row buffer (pass %d, y = %ld)", pass, y);
png_free(read_ptr, row_buf);
+ row_buf = NULL;
#endif /* !SINGLE_ROWBUF_ALLOC */
}
}
@@ -1130,7 +1253,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);
#endif
- png_debug(0, "Reading and writing end_info data\n");
+ png_debug(0, "Reading and writing end_info data");
png_read_end(read_ptr, end_info_ptr);
#if defined(PNG_TEXT_SUPPORTED)
@@ -1140,7 +1263,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0)
{
- png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks\n", num_text);
+ png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks", num_text);
png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text);
}
}
@@ -1159,7 +1282,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 */
}
@@ -1190,7 +1313,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);
@@ -1200,26 +1323,26 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
}
#endif
- png_debug(0, "Destroying data structs\n");
+ png_debug(0, "Destroying data structs");
#ifdef SINGLE_ROWBUF_ALLOC
- png_debug(1, "destroying row_buf for read_ptr\n");
+ png_debug(1, "destroying row_buf for read_ptr");
png_free(read_ptr, row_buf);
- row_buf=NULL;
+ row_buf = NULL;
#endif /* SINGLE_ROWBUF_ALLOC */
- png_debug(1, "destroying read_ptr, read_info_ptr, end_info_ptr\n");
+ png_debug(1, "destroying read_ptr, read_info_ptr, end_info_ptr");
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
#ifdef PNG_WRITE_SUPPORTED
- png_debug(1, "destroying write_end_info_ptr\n");
+ png_debug(1, "destroying write_end_info_ptr");
png_destroy_info_struct(write_ptr, &write_end_info_ptr);
- png_debug(1, "destroying write_ptr, write_info_ptr\n");
+ png_debug(1, "destroying write_ptr, write_info_ptr");
png_destroy_write_struct(&write_ptr, &write_info_ptr);
#endif
- png_debug(0, "Destruction complete.\n");
+ png_debug(0, "Destruction complete.");
FCLOSE(fpin);
FCLOSE(fpout);
- png_debug(0, "Opening files for comparison\n");
+ png_debug(0, "Opening files for comparison");
#if defined(_WIN32_WCE)
MultiByteToWideChar(CP_ACP, 0, inname, -1, path, MAX_PATH);
if ((fpin = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE)
@@ -1243,28 +1366,28 @@ 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),",
- inname,PNG_ZBUF_SIZE);
+ inname, PNG_ZBUF_SIZE);
fprintf(STDERR,
"\n filtering heuristic (libpng default), compression");
fprintf(STDERR,
" level (zlib default),\n and zlib version (%s)?\n\n",
ZLIB_VERSION);
- wrote_question=1;
+ wrote_question = 1;
}
FCLOSE(fpin);
FCLOSE(fpout);
@@ -1277,17 +1400,17 @@ 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),",
- inname,PNG_ZBUF_SIZE);
+ inname, PNG_ZBUF_SIZE);
fprintf(STDERR,
"\n filtering heuristic (libpng default), compression");
fprintf(STDERR,
" level (zlib default),\n and zlib version (%s)?\n\n",
ZLIB_VERSION);
- wrote_question=1;
+ wrote_question = 1;
}
FCLOSE(fpin);
FCLOSE(fpout);
@@ -1318,15 +1441,15 @@ main(int argc, char *argv[])
fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION);
- fprintf(STDERR,"%s",png_get_copyright(NULL));
+ fprintf(STDERR, "%s", png_get_copyright(NULL));
/* Show the version of libpng used in building the library */
- fprintf(STDERR," library (%lu):%s",
+ fprintf(STDERR, " library (%lu):%s",
(unsigned long)png_access_version_number(),
png_get_header_version(NULL));
/* Show the version of libpng used in building the application */
- fprintf(STDERR," pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER,
+ fprintf(STDERR, " pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER,
PNG_HEADER_VERSION_STRING);
- fprintf(STDERR," png_sizeof(png_struct)=%ld, png_sizeof(png_info)=%ld\n",
+ fprintf(STDERR, " sizeof(png_struct)=%ld, sizeof(png_info)=%ld\n",
(long)png_sizeof(png_struct), (long)png_sizeof(png_info));
/* Do some consistency checking on the memory allocation settings, I'm
@@ -1377,10 +1500,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",
@@ -1404,7 +1527,7 @@ main(int argc, char *argv[])
int k;
#endif
int kerror;
- fprintf(STDERR, "Testing %s:",argv[i]);
+ fprintf(STDERR, "Testing %s:", argv[i]);
kerror = test_one_file(argv[i], outname);
if (kerror == 0)
{
@@ -1415,14 +1538,14 @@ 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)
- fprintf(STDERR, " tIME = %s\n",tIME_string);
+ if (tIME_chunk_present != 0)
+ fprintf(STDERR, " tIME = %s\n", tIME_string);
tIME_chunk_present = 0;
#endif /* PNG_TIME_RFC1123_SUPPORTED */
}
@@ -1434,7 +1557,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;
@@ -1443,7 +1566,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;
}
@@ -1464,20 +1588,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);
+ 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;
@@ -1489,28 +1613,29 @@ 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)
- fprintf(STDERR, " tIME = %s\n",tIME_string);
+ if (tIME_chunk_present != 0)
+ fprintf(STDERR, " tIME = %s\n", tIME_string);
#endif /* PNG_TIME_RFC1123_SUPPORTED */
}
}
else
{
- if(verbose == 0 && i != 2)
- fprintf(STDERR, "Testing %s:",inname);
+ if (verbose == 0 && i != 2)
+ fprintf(STDERR, "Testing %s:", inname);
fprintf(STDERR, " FAIL\n");
ierror += kerror;
}
#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;
@@ -1519,7 +1644,7 @@ main(int argc, char *argv[])
current_allocation);
while (pinfo != NULL)
{
- fprintf(STDERR," %lu bytes at %x\n",
+ fprintf(STDERR, " %lu bytes at %x\n",
(unsigned long)pinfo->size, (unsigned int)pinfo->pointer);
pinfo = pinfo->next;
}
@@ -1542,13 +1667,13 @@ main(int argc, char *argv[])
t_stop = (float)clock();
t_misc += (t_stop - t_start);
t_start = t_stop;
- fprintf(STDERR," CPU time used = %.3f seconds",
+ fprintf(STDERR, " CPU time used = %.3f seconds",
(t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC);
- fprintf(STDERR," (decoding %.3f,\n",
+ fprintf(STDERR, " (decoding %.3f,\n",
t_decode/(float)CLOCKS_PER_SEC);
- fprintf(STDERR," encoding %.3f ,",
+ fprintf(STDERR, " encoding %.3f ,",
t_encode/(float)CLOCKS_PER_SEC);
- fprintf(STDERR," other %.3f seconds)\n\n",
+ fprintf(STDERR, " other %.3f seconds)\n\n",
t_misc/(float)CLOCKS_PER_SEC);
#endif
@@ -1560,4 +1685,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_29 your_png_h_is_not_version_1_2_29;
+typedef version_1_2_35 your_png_h_is_not_version_1_2_35;