OSDN Git Service

#26977 DTXViewerで使用しているjpeglib, libpng, zlib, libogg, libvorbisを最新のものにした。詳細はチケットを参照。
[dtxmania/dtxmania.git] / @libpngソリューション / lpng157 / pngtest.c
diff --git a/@libpngソリューション/lpng157/pngtest.c b/@libpngソリューション/lpng157/pngtest.c
deleted file mode 100644 (file)
index 2a9a2d6..0000000
+++ /dev/null
@@ -1,1820 +0,0 @@
-\r
-/* pngtest.c - a simple test program to test libpng\r
- *\r
- * Last changed in libpng 1.5.6 [November 3, 2011]\r
- * Copyright (c) 1998-2011 Glenn Randers-Pehrson\r
- * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\r
- * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\r
- *\r
- * This code is released under the libpng license.\r
- * For conditions of distribution and use, see the disclaimer\r
- * and license in png.h\r
- *\r
- * This program reads in a PNG image, writes it out again, and then\r
- * compares the two files.  If the files are identical, this shows that\r
- * the basic chunk handling, filtering, and (de)compression code is working\r
- * properly.  It does not currently test all of the transforms, although\r
- * it probably should.\r
- *\r
- * The program will report "FAIL" in certain legitimate cases:\r
- * 1) when the compression level or filter selection method is changed.\r
- * 2) when the maximum IDAT size (PNG_ZBUF_SIZE in pngconf.h) is not 8192.\r
- * 3) unknown unsafe-to-copy ancillary chunks or unknown critical chunks\r
- *    exist in the input file.\r
- * 4) others not listed here...\r
- * In these cases, it is best to check with another tool such as "pngcheck"\r
- * to see what the differences between the two files are.\r
- *\r
- * If a filename is given on the command-line, then this file is used\r
- * for the input, rather than the default "pngtest.png".  This allows\r
- * testing a wide variety of files easily.  You can also test a number\r
- * of files at once by typing "pngtest -m file1.png file2.png ..."\r
- */\r
-\r
-#define _POSIX_SOURCE 1\r
-\r
-#include "zlib.h"\r
-#include "png.h"\r
-/* Copied from pngpriv.h but only used in error messages below. */\r
-#ifndef PNG_ZBUF_SIZE\r
-#  define PNG_ZBUF_SIZE 8192\r
-#endif\r
-#  include <stdio.h>\r
-#  include <stdlib.h>\r
-#  include <string.h>\r
-#  define FCLOSE(file) fclose(file)\r
-\r
-#ifndef PNG_STDIO_SUPPORTED\r
-typedef FILE                * png_FILE_p;\r
-#endif\r
-\r
-/* Makes pngtest verbose so we can find problems. */\r
-#ifndef PNG_DEBUG\r
-#  define PNG_DEBUG 0\r
-#endif\r
-\r
-#if PNG_DEBUG > 1\r
-#  define pngtest_debug(m)        ((void)fprintf(stderr, m "\n"))\r
-#  define pngtest_debug1(m,p1)    ((void)fprintf(stderr, m "\n", p1))\r
-#  define pngtest_debug2(m,p1,p2) ((void)fprintf(stderr, m "\n", p1, p2))\r
-#else\r
-#  define pngtest_debug(m)        ((void)0)\r
-#  define pngtest_debug1(m,p1)    ((void)0)\r
-#  define pngtest_debug2(m,p1,p2) ((void)0)\r
-#endif\r
-\r
-#if !PNG_DEBUG\r
-#  define SINGLE_ROWBUF_ALLOC  /* Makes buffer overruns easier to nail */\r
-#endif\r
-\r
-/* The code uses memcmp and memcpy on large objects (typically row pointers) so\r
- * it is necessary to do soemthing special on certain architectures, note that\r
- * the actual support for this was effectively removed in 1.4, so only the\r
- * memory remains in this program:\r
- */\r
-#define CVT_PTR(ptr)         (ptr)\r
-#define CVT_PTR_NOCHECK(ptr) (ptr)\r
-#define png_memcmp  memcmp\r
-#define png_memcpy  memcpy\r
-#define png_memset  memset\r
-\r
-/* Turn on CPU timing\r
-#define PNGTEST_TIMING\r
-*/\r
-\r
-#ifndef PNG_FLOATING_POINT_SUPPORTED\r
-#undef PNGTEST_TIMING\r
-#endif\r
-\r
-#ifdef PNGTEST_TIMING\r
-static float t_start, t_stop, t_decode, t_encode, t_misc;\r
-#include <time.h>\r
-#endif\r
-\r
-#ifdef PNG_TIME_RFC1123_SUPPORTED\r
-#define PNG_tIME_STRING_LENGTH 29\r
-static int tIME_chunk_present = 0;\r
-static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present";\r
-#endif\r
-\r
-static int verbose = 0;\r
-static int strict = 0;\r
-\r
-int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname));\r
-\r
-#ifdef __TURBOC__\r
-#include <mem.h>\r
-#endif\r
-\r
-/* Defined so I can write to a file on gui/windowing platforms */\r
-/*  #define STDERR stderr  */\r
-#define STDERR stdout   /* For DOS */\r
-\r
-/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */\r
-#ifndef png_jmpbuf\r
-#  define png_jmpbuf(png_ptr) png_ptr->jmpbuf\r
-#endif\r
-\r
-/* Example of using row callbacks to make a simple progress meter */\r
-static int status_pass = 1;\r
-static int status_dots_requested = 0;\r
-static int status_dots = 1;\r
-\r
-void PNGCBAPI\r
-read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass);\r
-void PNGCBAPI\r
-read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)\r
-{\r
-   if (png_ptr == NULL || row_number > PNG_UINT_31_MAX)\r
-      return;\r
-\r
-   if (status_pass != pass)\r
-   {\r
-      fprintf(stdout, "\n Pass %d: ", pass);\r
-      status_pass = pass;\r
-      status_dots = 31;\r
-   }\r
-\r
-   status_dots--;\r
-\r
-   if (status_dots == 0)\r
-   {\r
-      fprintf(stdout, "\n         ");\r
-      status_dots=30;\r
-   }\r
-\r
-   fprintf(stdout, "r");\r
-}\r
-\r
-void PNGCBAPI\r
-write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass);\r
-void PNGCBAPI\r
-write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)\r
-{\r
-   if (png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7)\r
-      return;\r
-\r
-   fprintf(stdout, "w");\r
-}\r
-\r
-\r
-#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED\r
-/* Example of using user transform callback (we don't transform anything,\r
- * but merely examine the row filters.  We set this to 256 rather than\r
- * 5 in case illegal filter values are present.)\r
- */\r
-static png_uint_32 filters_used[256];\r
-void PNGCBAPI\r
-count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data);\r
-void PNGCBAPI\r
-count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data)\r
-{\r
-   if (png_ptr != NULL && row_info != NULL)\r
-      ++filters_used[*(data - 1)];\r
-}\r
-#endif\r
-\r
-#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED\r
-/* Example of using user transform callback (we don't transform anything,\r
- * but merely count the zero samples)\r
- */\r
-\r
-static png_uint_32 zero_samples;\r
-\r
-void PNGCBAPI\r
-count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data);\r
-void PNGCBAPI\r
-count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)\r
-{\r
-   png_bytep dp = data;\r
-   if (png_ptr == NULL)\r
-      return;\r
-\r
-   /* Contents of row_info:\r
-    *  png_uint_32 width      width of row\r
-    *  png_uint_32 rowbytes   number of bytes in row\r
-    *  png_byte color_type    color type of pixels\r
-    *  png_byte bit_depth     bit depth of samples\r
-    *  png_byte channels      number of channels (1-4)\r
-    *  png_byte pixel_depth   bits per pixel (depth*channels)\r
-    */\r
-\r
-    /* Counts the number of zero samples (or zero pixels if color_type is 3 */\r
-\r
-    if (row_info->color_type == 0 || row_info->color_type == 3)\r
-    {\r
-       int pos = 0;\r
-       png_uint_32 n, nstop;\r
-\r
-       for (n = 0, nstop=row_info->width; n<nstop; n++)\r
-       {\r
-          if (row_info->bit_depth == 1)\r
-          {\r
-             if (((*dp << pos++ ) & 0x80) == 0)\r
-                zero_samples++;\r
-\r
-             if (pos == 8)\r
-             {\r
-                pos = 0;\r
-                dp++;\r
-             }\r
-          }\r
-\r
-          if (row_info->bit_depth == 2)\r
-          {\r
-             if (((*dp << (pos+=2)) & 0xc0) == 0)\r
-                zero_samples++;\r
-\r
-             if (pos == 8)\r
-             {\r
-                pos = 0;\r
-                dp++;\r
-             }\r
-          }\r
-\r
-          if (row_info->bit_depth == 4)\r
-          {\r
-             if (((*dp << (pos+=4)) & 0xf0) == 0)\r
-                zero_samples++;\r
-\r
-             if (pos == 8)\r
-             {\r
-                pos = 0;\r
-                dp++;\r
-             }\r
-          }\r
-\r
-          if (row_info->bit_depth == 8)\r
-             if (*dp++ == 0)\r
-                zero_samples++;\r
-\r
-          if (row_info->bit_depth == 16)\r
-          {\r
-             if ((*dp | *(dp+1)) == 0)\r
-                zero_samples++;\r
-             dp+=2;\r
-          }\r
-       }\r
-    }\r
-    else /* Other color types */\r
-    {\r
-       png_uint_32 n, nstop;\r
-       int channel;\r
-       int color_channels = row_info->channels;\r
-       if (row_info->color_type > 3)color_channels--;\r
-\r
-       for (n = 0, nstop=row_info->width; n<nstop; n++)\r
-       {\r
-          for (channel = 0; channel < color_channels; channel++)\r
-          {\r
-             if (row_info->bit_depth == 8)\r
-                if (*dp++ == 0)\r
-                   zero_samples++;\r
-\r
-             if (row_info->bit_depth == 16)\r
-             {\r
-                if ((*dp | *(dp+1)) == 0)\r
-                   zero_samples++;\r
-\r
-                dp+=2;\r
-             }\r
-          }\r
-          if (row_info->color_type > 3)\r
-          {\r
-             dp++;\r
-             if (row_info->bit_depth == 16)\r
-                dp++;\r
-          }\r
-       }\r
-    }\r
-}\r
-#endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */\r
-\r
-static int wrote_question = 0;\r
-\r
-#ifndef PNG_STDIO_SUPPORTED\r
-/* START of code to validate stdio-free compilation */\r
-/* These copies of the default read/write functions come from pngrio.c and\r
- * pngwio.c.  They allow "don't include stdio" testing of the library.\r
- * This is the function that does the actual reading of data.  If you are\r
- * not reading from a standard C stream, you should create a replacement\r
- * read_data function and use it at run time with png_set_read_fn(), rather\r
- * than changing the library.\r
- */\r
-\r
-#ifdef PNG_IO_STATE_SUPPORTED\r
-void\r
-pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,\r
-   png_uint_32 io_op);\r
-void\r
-pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,\r
-   png_uint_32 io_op)\r
-{\r
-   png_uint_32 io_state = png_get_io_state(png_ptr);\r
-   int err = 0;\r
-\r
-   /* Check if the current operation (reading / writing) is as expected. */\r
-   if ((io_state & PNG_IO_MASK_OP) != io_op)\r
-      png_error(png_ptr, "Incorrect operation in I/O state");\r
-\r
-   /* Check if the buffer size specific to the current location\r
-    * (file signature / header / data / crc) is as expected.\r
-    */\r
-   switch (io_state & PNG_IO_MASK_LOC)\r
-   {\r
-   case PNG_IO_SIGNATURE:\r
-      if (data_length > 8)\r
-         err = 1;\r
-      break;\r
-   case PNG_IO_CHUNK_HDR:\r
-      if (data_length != 8)\r
-         err = 1;\r
-      break;\r
-   case PNG_IO_CHUNK_DATA:\r
-      break;  /* no restrictions here */\r
-   case PNG_IO_CHUNK_CRC:\r
-      if (data_length != 4)\r
-         err = 1;\r
-      break;\r
-   default:\r
-      err = 1;  /* uninitialized */\r
-   }\r
-   if (err)\r
-      png_error(png_ptr, "Bad I/O state or buffer size");\r
-}\r
-#endif\r
-\r
-#ifndef USE_FAR_KEYWORD\r
-static void PNGCBAPI\r
-pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)\r
-{\r
-   png_size_t check = 0;\r
-   png_voidp io_ptr;\r
-\r
-   /* fread() returns 0 on error, so it is OK to store this in a png_size_t\r
-    * instead of an int, which is what fread() actually returns.\r
-    */\r
-   io_ptr = png_get_io_ptr(png_ptr);\r
-   if (io_ptr != NULL)\r
-   {\r
-      check = fread(data, 1, length, (png_FILE_p)io_ptr);\r
-   }\r
-\r
-   if (check != length)\r
-   {\r
-      png_error(png_ptr, "Read Error");\r
-   }\r
-\r
-#ifdef PNG_IO_STATE_SUPPORTED\r
-   pngtest_check_io_state(png_ptr, length, PNG_IO_READING);\r
-#endif\r
-}\r
-#else\r
-/* This is the model-independent version. Since the standard I/O library\r
-   can't handle far buffers in the medium and small models, we have to copy\r
-   the data.\r
-*/\r
-\r
-#define NEAR_BUF_SIZE 1024\r
-#define MIN(a,b) (a <= b ? a : b)\r
-\r
-static void PNGCBAPI\r
-pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)\r
-{\r
-   png_size_t check;\r
-   png_byte *n_data;\r
-   png_FILE_p io_ptr;\r
-\r
-   /* Check if data really is near. If so, use usual code. */\r
-   n_data = (png_byte *)CVT_PTR_NOCHECK(data);\r
-   io_ptr = (png_FILE_p)CVT_PTR(png_get_io_ptr(png_ptr));\r
-   if ((png_bytep)n_data == data)\r
-   {\r
-      check = fread(n_data, 1, length, io_ptr);\r
-   }\r
-   else\r
-   {\r
-      png_byte buf[NEAR_BUF_SIZE];\r
-      png_size_t read, remaining, err;\r
-      check = 0;\r
-      remaining = length;\r
-\r
-      do\r
-      {\r
-         read = MIN(NEAR_BUF_SIZE, remaining);\r
-         err = fread(buf, 1, 1, io_ptr);\r
-         png_memcpy(data, buf, read); /* Copy far buffer to near buffer */\r
-         if (err != read)\r
-            break;\r
-         else\r
-            check += err;\r
-         data += read;\r
-         remaining -= read;\r
-      }\r
-      while (remaining != 0);\r
-   }\r
-\r
-   if (check != length)\r
-      png_error(png_ptr, "Read Error");\r
-\r
-#ifdef PNG_IO_STATE_SUPPORTED\r
-   pngtest_check_io_state(png_ptr, length, PNG_IO_READING);\r
-#endif\r
-}\r
-#endif /* USE_FAR_KEYWORD */\r
-\r
-#ifdef PNG_WRITE_FLUSH_SUPPORTED\r
-static void PNGCBAPI\r
-pngtest_flush(png_structp png_ptr)\r
-{\r
-   /* Do nothing; fflush() is said to be just a waste of energy. */\r
-   PNG_UNUSED(png_ptr)   /* Stifle compiler warning */\r
-}\r
-#endif\r
-\r
-/* This is the function that does the actual writing of data.  If you are\r
- * not writing to a standard C stream, you should create a replacement\r
- * write_data function and use it at run time with png_set_write_fn(), rather\r
- * than changing the library.\r
- */\r
-#ifndef USE_FAR_KEYWORD\r
-static void PNGCBAPI\r
-pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)\r
-{\r
-   png_size_t check;\r
-\r
-   check = fwrite(data, 1, length, (png_FILE_p)png_get_io_ptr(png_ptr));\r
-\r
-   if (check != length)\r
-   {\r
-      png_error(png_ptr, "Write Error");\r
-   }\r
-\r
-#ifdef PNG_IO_STATE_SUPPORTED\r
-   pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);\r
-#endif\r
-}\r
-#else\r
-/* This is the model-independent version. Since the standard I/O library\r
-   can't handle far buffers in the medium and small models, we have to copy\r
-   the data.\r
-*/\r
-\r
-#define NEAR_BUF_SIZE 1024\r
-#define MIN(a,b) (a <= b ? a : b)\r
-\r
-static void PNGCBAPI\r
-pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)\r
-{\r
-   png_size_t check;\r
-   png_byte *near_data;  /* Needs to be "png_byte *" instead of "png_bytep" */\r
-   png_FILE_p io_ptr;\r
-\r
-   /* Check if data really is near. If so, use usual code. */\r
-   near_data = (png_byte *)CVT_PTR_NOCHECK(data);\r
-   io_ptr = (png_FILE_p)CVT_PTR(png_get_io_ptr(png_ptr));\r
-\r
-   if ((png_bytep)near_data == data)\r
-   {\r
-      check = fwrite(near_data, 1, length, io_ptr);\r
-   }\r
-\r
-   else\r
-   {\r
-      png_byte buf[NEAR_BUF_SIZE];\r
-      png_size_t written, remaining, err;\r
-      check = 0;\r
-      remaining = length;\r
-\r
-      do\r
-      {\r
-         written = MIN(NEAR_BUF_SIZE, remaining);\r
-         png_memcpy(buf, data, written); /* Copy far buffer to near buffer */\r
-         err = fwrite(buf, 1, written, io_ptr);\r
-         if (err != written)\r
-            break;\r
-         else\r
-            check += err;\r
-         data += written;\r
-         remaining -= written;\r
-      }\r
-      while (remaining != 0);\r
-   }\r
-\r
-   if (check != length)\r
-   {\r
-      png_error(png_ptr, "Write Error");\r
-   }\r
-\r
-#ifdef PNG_IO_STATE_SUPPORTED\r
-   pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);\r
-#endif\r
-}\r
-#endif /* USE_FAR_KEYWORD */\r
-\r
-/* This function is called when there is a warning, but the library thinks\r
- * it can continue anyway.  Replacement functions don't have to do anything\r
- * here if you don't want to.  In the default configuration, png_ptr is\r
- * not used, but it is passed in case it may be useful.\r
- */\r
-static void PNGCBAPI\r
-pngtest_warning(png_structp png_ptr, png_const_charp message)\r
-{\r
-   PNG_CONST char *name = "UNKNOWN (ERROR!)";\r
-   char *test;\r
-   test = png_get_error_ptr(png_ptr);\r
-\r
-   if (test == NULL)\r
-     fprintf(STDERR, "%s: libpng warning: %s\n", name, message);\r
-\r
-   else\r
-     fprintf(STDERR, "%s: libpng warning: %s\n", test, message);\r
-}\r
-\r
-/* This is the default error handling function.  Note that replacements for\r
- * this function MUST NOT RETURN, or the program will likely crash.  This\r
- * function is used by default, or if the program supplies NULL for the\r
- * error function pointer in png_set_error_fn().\r
- */\r
-static void PNGCBAPI\r
-pngtest_error(png_structp png_ptr, png_const_charp message)\r
-{\r
-   pngtest_warning(png_ptr, message);\r
-   /* We can return because png_error calls the default handler, which is\r
-    * actually OK in this case.\r
-    */\r
-}\r
-#endif /* !PNG_STDIO_SUPPORTED */\r
-/* END of code to validate stdio-free compilation */\r
-\r
-/* START of code to validate memory allocation and deallocation */\r
-#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\r
-\r
-/* Allocate memory.  For reasonable files, size should never exceed\r
- * 64K.  However, zlib may allocate more then 64K if you don't tell\r
- * it not to.  See zconf.h and png.h for more information.  zlib does\r
- * need to allocate exactly 64K, so whatever you call here must\r
- * have the ability to do that.\r
- *\r
- * This piece of code can be compiled to validate max 64K allocations\r
- * by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K.\r
- */\r
-typedef struct memory_information\r
-{\r
-   png_alloc_size_t          size;\r
-   png_voidp                 pointer;\r
-   struct memory_information FAR *next;\r
-} memory_information;\r
-typedef memory_information FAR *memory_infop;\r
-\r
-static memory_infop pinformation = NULL;\r
-static int current_allocation = 0;\r
-static int maximum_allocation = 0;\r
-static int total_allocation = 0;\r
-static int num_allocations = 0;\r
-\r
-png_voidp PNGCBAPI png_debug_malloc PNGARG((png_structp png_ptr,\r
-    png_alloc_size_t size));\r
-void PNGCBAPI png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr));\r
-\r
-png_voidp\r
-PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)\r
-{\r
-\r
-   /* png_malloc has already tested for NULL; png_create_struct calls\r
-    * png_debug_malloc directly, with png_ptr == NULL which is OK\r
-    */\r
-\r
-   if (size == 0)\r
-      return (NULL);\r
-\r
-   /* This calls the library allocator twice, once to get the requested\r
-      buffer and once to get a new free list entry. */\r
-   {\r
-      /* Disable malloc_fn and free_fn */\r
-      memory_infop pinfo;\r
-      png_set_mem_fn(png_ptr, NULL, NULL, NULL);\r
-      pinfo = (memory_infop)png_malloc(png_ptr,\r
-         png_sizeof(*pinfo));\r
-      pinfo->size = size;\r
-      current_allocation += size;\r
-      total_allocation += size;\r
-      num_allocations ++;\r
-\r
-      if (current_allocation > maximum_allocation)\r
-         maximum_allocation = current_allocation;\r
-\r
-      pinfo->pointer = png_malloc(png_ptr, size);\r
-      /* Restore malloc_fn and free_fn */\r
-\r
-      png_set_mem_fn(png_ptr,\r
-          NULL, png_debug_malloc, png_debug_free);\r
-\r
-      if (size != 0 && pinfo->pointer == NULL)\r
-      {\r
-         current_allocation -= size;\r
-         total_allocation -= size;\r
-         png_error(png_ptr,\r
-           "out of memory in pngtest->png_debug_malloc");\r
-      }\r
-\r
-      pinfo->next = pinformation;\r
-      pinformation = pinfo;\r
-      /* Make sure the caller isn't assuming zeroed memory. */\r
-      png_memset(pinfo->pointer, 0xdd, pinfo->size);\r
-\r
-      if (verbose)\r
-         printf("png_malloc %lu bytes at %p\n", (unsigned long)size,\r
-            pinfo->pointer);\r
-\r
-      return (png_voidp)(pinfo->pointer);\r
-   }\r
-}\r
-\r
-/* Free a pointer.  It is removed from the list at the same time. */\r
-void PNGCBAPI\r
-png_debug_free(png_structp png_ptr, png_voidp ptr)\r
-{\r
-   if (png_ptr == NULL)\r
-      fprintf(STDERR, "NULL pointer to png_debug_free.\n");\r
-\r
-   if (ptr == 0)\r
-   {\r
-#if 0 /* This happens all the time. */\r
-      fprintf(STDERR, "WARNING: freeing NULL pointer\n");\r
-#endif\r
-      return;\r
-   }\r
-\r
-   /* Unlink the element from the list. */\r
-   {\r
-      memory_infop FAR *ppinfo = &pinformation;\r
-\r
-      for (;;)\r
-      {\r
-         memory_infop pinfo = *ppinfo;\r
-\r
-         if (pinfo->pointer == ptr)\r
-         {\r
-            *ppinfo = pinfo->next;\r
-            current_allocation -= pinfo->size;\r
-            if (current_allocation < 0)\r
-               fprintf(STDERR, "Duplicate free of memory\n");\r
-            /* We must free the list element too, but first kill\r
-               the memory that is to be freed. */\r
-            png_memset(ptr, 0x55, pinfo->size);\r
-            png_free_default(png_ptr, pinfo);\r
-            pinfo = NULL;\r
-            break;\r
-         }\r
-\r
-         if (pinfo->next == NULL)\r
-         {\r
-            fprintf(STDERR, "Pointer %x not found\n", (unsigned int)ptr);\r
-            break;\r
-         }\r
-\r
-         ppinfo = &pinfo->next;\r
-      }\r
-   }\r
-\r
-   /* Finally free the data. */\r
-   if (verbose)\r
-      printf("Freeing %p\n", ptr);\r
-\r
-   png_free_default(png_ptr, ptr);\r
-   ptr = NULL;\r
-}\r
-#endif /* PNG_USER_MEM_SUPPORTED && PNG_DEBUG */\r
-/* END of code to test memory allocation/deallocation */\r
-\r
-\r
-/* Demonstration of user chunk support of the sTER and vpAg chunks */\r
-#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED\r
-\r
-/* (sTER is a public chunk not yet known by libpng.  vpAg is a private\r
-chunk used in ImageMagick to store "virtual page" size).  */\r
-\r
-static png_uint_32 user_chunk_data[4];\r
-\r
-    /* 0: sTER mode + 1\r
-     * 1: vpAg width\r
-     * 2: vpAg height\r
-     * 3: vpAg units\r
-     */\r
-\r
-static int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr,\r
-   png_unknown_chunkp chunk)\r
-{\r
-   png_uint_32\r
-     *my_user_chunk_data;\r
-\r
-   /* Return one of the following:\r
-    *    return (-n);  chunk had an error\r
-    *    return (0);  did not recognize\r
-    *    return (n);  success\r
-    *\r
-    * The unknown chunk structure contains the chunk data:\r
-    * png_byte name[5];\r
-    * png_byte *data;\r
-    * png_size_t size;\r
-    *\r
-    * Note that libpng has already taken care of the CRC handling.\r
-    */\r
-\r
-   if (chunk->name[0] == 115 && chunk->name[1] ==  84 &&     /* s  T */\r
-       chunk->name[2] ==  69 && chunk->name[3] ==  82)       /* E  R */\r
-      {\r
-         /* Found sTER chunk */\r
-         if (chunk->size != 1)\r
-            return (-1); /* Error return */\r
-\r
-         if (chunk->data[0] != 0 && chunk->data[0] != 1)\r
-            return (-1);  /* Invalid mode */\r
-\r
-         my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr);\r
-         my_user_chunk_data[0]=chunk->data[0]+1;\r
-         return (1);\r
-      }\r
-\r
-   if (chunk->name[0] != 118 || chunk->name[1] != 112 ||    /* v  p */\r
-       chunk->name[2] !=  65 || chunk->name[3] != 103)      /* A  g */\r
-      return (0); /* Did not recognize */\r
-\r
-   /* Found ImageMagick vpAg chunk */\r
-\r
-   if (chunk->size != 9)\r
-      return (-1); /* Error return */\r
-\r
-   my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr);\r
-\r
-   my_user_chunk_data[1]=png_get_uint_31(png_ptr, chunk->data);\r
-   my_user_chunk_data[2]=png_get_uint_31(png_ptr, chunk->data + 4);\r
-   my_user_chunk_data[3]=(png_uint_32)chunk->data[8];\r
-\r
-   return (1);\r
-\r
-}\r
-#endif\r
-/* END of code to demonstrate user chunk support */\r
-\r
-/* Test one file */\r
-int\r
-test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)\r
-{\r
-   static png_FILE_p fpin;\r
-   static png_FILE_p fpout;  /* "static" prevents setjmp corruption */\r
-   png_structp read_ptr;\r
-   png_infop read_info_ptr, end_info_ptr;\r
-#ifdef PNG_WRITE_SUPPORTED\r
-   png_structp write_ptr;\r
-   png_infop write_info_ptr;\r
-   png_infop write_end_info_ptr;\r
-#else\r
-   png_structp write_ptr = NULL;\r
-   png_infop write_info_ptr = NULL;\r
-   png_infop write_end_info_ptr = NULL;\r
-#endif\r
-   png_bytep row_buf;\r
-   png_uint_32 y;\r
-   png_uint_32 width, height;\r
-   int num_pass, pass;\r
-   int bit_depth, color_type;\r
-#ifdef PNG_SETJMP_SUPPORTED\r
-#ifdef USE_FAR_KEYWORD\r
-   jmp_buf tmp_jmpbuf;\r
-#endif\r
-#endif\r
-\r
-   char inbuf[256], outbuf[256];\r
-\r
-   row_buf = NULL;\r
-\r
-   if ((fpin = fopen(inname, "rb")) == NULL)\r
-   {\r
-      fprintf(STDERR, "Could not find input file %s\n", inname);\r
-      return (1);\r
-   }\r
-\r
-   if ((fpout = fopen(outname, "wb")) == NULL)\r
-   {\r
-      fprintf(STDERR, "Could not open output file %s\n", outname);\r
-      FCLOSE(fpin);\r
-      return (1);\r
-   }\r
-\r
-   pngtest_debug("Allocating read and write structures");\r
-#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\r
-   read_ptr =\r
-      png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL,\r
-      NULL, NULL, NULL, png_debug_malloc, png_debug_free);\r
-#else\r
-   read_ptr =\r
-      png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);\r
-#endif\r
-#ifndef PNG_STDIO_SUPPORTED\r
-   png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error,\r
-       pngtest_warning);\r
-#endif\r
-\r
-#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED\r
-   user_chunk_data[0] = 0;\r
-   user_chunk_data[1] = 0;\r
-   user_chunk_data[2] = 0;\r
-   user_chunk_data[3] = 0;\r
-   png_set_read_user_chunk_fn(read_ptr, user_chunk_data,\r
-     read_user_chunk_callback);\r
-\r
-#endif\r
-#ifdef PNG_WRITE_SUPPORTED\r
-#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\r
-   write_ptr =\r
-      png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL,\r
-      NULL, NULL, NULL, png_debug_malloc, png_debug_free);\r
-#else\r
-   write_ptr =\r
-      png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);\r
-#endif\r
-#ifndef PNG_STDIO_SUPPORTED\r
-   png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error,\r
-       pngtest_warning);\r
-#endif\r
-#endif\r
-   pngtest_debug("Allocating read_info, write_info and end_info structures");\r
-   read_info_ptr = png_create_info_struct(read_ptr);\r
-   end_info_ptr = png_create_info_struct(read_ptr);\r
-#ifdef PNG_WRITE_SUPPORTED\r
-   write_info_ptr = png_create_info_struct(write_ptr);\r
-   write_end_info_ptr = png_create_info_struct(write_ptr);\r
-#endif\r
-\r
-#ifdef PNG_SETJMP_SUPPORTED\r
-   pngtest_debug("Setting jmpbuf for read struct");\r
-#ifdef USE_FAR_KEYWORD\r
-   if (setjmp(tmp_jmpbuf))\r
-#else\r
-   if (setjmp(png_jmpbuf(read_ptr)))\r
-#endif\r
-   {\r
-      fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);\r
-      png_free(read_ptr, row_buf);\r
-      row_buf = NULL;\r
-      png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);\r
-#ifdef PNG_WRITE_SUPPORTED\r
-      png_destroy_info_struct(write_ptr, &write_end_info_ptr);\r
-      png_destroy_write_struct(&write_ptr, &write_info_ptr);\r
-#endif\r
-      FCLOSE(fpin);\r
-      FCLOSE(fpout);\r
-      return (1);\r
-   }\r
-#ifdef USE_FAR_KEYWORD\r
-   png_memcpy(png_jmpbuf(read_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));\r
-#endif\r
-\r
-#ifdef PNG_WRITE_SUPPORTED\r
-   pngtest_debug("Setting jmpbuf for write struct");\r
-#ifdef USE_FAR_KEYWORD\r
-\r
-   if (setjmp(tmp_jmpbuf))\r
-#else\r
-   if (setjmp(png_jmpbuf(write_ptr)))\r
-#endif\r
-   {\r
-      fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname);\r
-      png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);\r
-      png_destroy_info_struct(write_ptr, &write_end_info_ptr);\r
-#ifdef PNG_WRITE_SUPPORTED\r
-      png_destroy_write_struct(&write_ptr, &write_info_ptr);\r
-#endif\r
-      FCLOSE(fpin);\r
-      FCLOSE(fpout);\r
-      return (1);\r
-   }\r
-\r
-#ifdef USE_FAR_KEYWORD\r
-   png_memcpy(png_jmpbuf(write_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));\r
-#endif\r
-#endif\r
-#endif\r
-\r
-   pngtest_debug("Initializing input and output streams");\r
-#ifdef PNG_STDIO_SUPPORTED\r
-   png_init_io(read_ptr, fpin);\r
-#  ifdef PNG_WRITE_SUPPORTED\r
-   png_init_io(write_ptr, fpout);\r
-#  endif\r
-#else\r
-   png_set_read_fn(read_ptr, (png_voidp)fpin, pngtest_read_data);\r
-#  ifdef PNG_WRITE_SUPPORTED\r
-   png_set_write_fn(write_ptr, (png_voidp)fpout,  pngtest_write_data,\r
-#    ifdef PNG_WRITE_FLUSH_SUPPORTED\r
-      pngtest_flush);\r
-#    else\r
-      NULL);\r
-#    endif\r
-#  endif\r
-#endif\r
-\r
-#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED\r
-   /* Normally one would use Z_DEFAULT_STRATEGY for text compression.\r
-    * This is here just to make pngtest replicate the results from libpng\r
-    * versions prior to 1.5.4, and to test this new API.\r
-    */\r
-   png_set_text_compression_strategy(write_ptr, Z_FILTERED);\r
-#endif\r
-\r
-   if (status_dots_requested == 1)\r
-   {\r
-#ifdef PNG_WRITE_SUPPORTED\r
-      png_set_write_status_fn(write_ptr, write_row_callback);\r
-#endif\r
-      png_set_read_status_fn(read_ptr, read_row_callback);\r
-   }\r
-\r
-   else\r
-   {\r
-#ifdef PNG_WRITE_SUPPORTED\r
-      png_set_write_status_fn(write_ptr, NULL);\r
-#endif\r
-      png_set_read_status_fn(read_ptr, NULL);\r
-   }\r
-\r
-#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED\r
-   {\r
-      int i;\r
-\r
-      for (i = 0; i<256; i++)\r
-         filters_used[i] = 0;\r
-\r
-      png_set_read_user_transform_fn(read_ptr, count_filters);\r
-   }\r
-#endif\r
-#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED\r
-   zero_samples = 0;\r
-   png_set_write_user_transform_fn(write_ptr, count_zero_samples);\r
-#endif\r
-\r
-#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED\r
-#  ifndef PNG_HANDLE_CHUNK_ALWAYS\r
-#    define PNG_HANDLE_CHUNK_ALWAYS       3\r
-#  endif\r
-   png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS,\r
-      NULL, 0);\r
-#endif\r
-#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED\r
-#  ifndef PNG_HANDLE_CHUNK_IF_SAFE\r
-#    define PNG_HANDLE_CHUNK_IF_SAFE      2\r
-#  endif\r
-   png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_IF_SAFE,\r
-      NULL, 0);\r
-#endif\r
-\r
-   pngtest_debug("Reading info struct");\r
-   png_read_info(read_ptr, read_info_ptr);\r
-\r
-   pngtest_debug("Transferring info struct");\r
-   {\r
-      int interlace_type, compression_type, filter_type;\r
-\r
-      if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth,\r
-          &color_type, &interlace_type, &compression_type, &filter_type))\r
-      {\r
-         png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,\r
-#ifdef PNG_WRITE_INTERLACING_SUPPORTED\r
-            color_type, interlace_type, compression_type, filter_type);\r
-#else\r
-            color_type, PNG_INTERLACE_NONE, compression_type, filter_type);\r
-#endif\r
-      }\r
-   }\r
-#ifdef PNG_FIXED_POINT_SUPPORTED\r
-#ifdef PNG_cHRM_SUPPORTED\r
-   {\r
-      png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x,\r
-         blue_y;\r
-\r
-      if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y,\r
-         &red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y))\r
-      {\r
-         png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x,\r
-            red_y, green_x, green_y, blue_x, blue_y);\r
-      }\r
-   }\r
-#endif\r
-#ifdef PNG_gAMA_SUPPORTED\r
-   {\r
-      png_fixed_point gamma;\r
-\r
-      if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma))\r
-         png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma);\r
-   }\r
-#endif\r
-#else /* Use floating point versions */\r
-#ifdef PNG_FLOATING_POINT_SUPPORTED\r
-#ifdef PNG_cHRM_SUPPORTED\r
-   {\r
-      double white_x, white_y, red_x, red_y, green_x, green_y, blue_x,\r
-         blue_y;\r
-\r
-      if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,\r
-         &red_y, &green_x, &green_y, &blue_x, &blue_y))\r
-      {\r
-         png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x,\r
-            red_y, green_x, green_y, blue_x, blue_y);\r
-      }\r
-   }\r
-#endif\r
-#ifdef PNG_gAMA_SUPPORTED\r
-   {\r
-      double gamma;\r
-\r
-      if (png_get_gAMA(read_ptr, read_info_ptr, &gamma))\r
-         png_set_gAMA(write_ptr, write_info_ptr, gamma);\r
-   }\r
-#endif\r
-#endif /* Floating point */\r
-#endif /* Fixed point */\r
-#ifdef PNG_iCCP_SUPPORTED\r
-   {\r
-      png_charp name;\r
-      png_bytep profile;\r
-      png_uint_32 proflen;\r
-      int compression_type;\r
-\r
-      if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type,\r
-                      &profile, &proflen))\r
-      {\r
-         png_set_iCCP(write_ptr, write_info_ptr, name, compression_type,\r
-                      profile, proflen);\r
-      }\r
-   }\r
-#endif\r
-#ifdef PNG_sRGB_SUPPORTED\r
-   {\r
-      int intent;\r
-\r
-      if (png_get_sRGB(read_ptr, read_info_ptr, &intent))\r
-         png_set_sRGB(write_ptr, write_info_ptr, intent);\r
-   }\r
-#endif\r
-   {\r
-      png_colorp palette;\r
-      int num_palette;\r
-\r
-      if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette))\r
-         png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette);\r
-   }\r
-#ifdef PNG_bKGD_SUPPORTED\r
-   {\r
-      png_color_16p background;\r
-\r
-      if (png_get_bKGD(read_ptr, read_info_ptr, &background))\r
-      {\r
-         png_set_bKGD(write_ptr, write_info_ptr, background);\r
-      }\r
-   }\r
-#endif\r
-#ifdef PNG_hIST_SUPPORTED\r
-   {\r
-      png_uint_16p hist;\r
-\r
-      if (png_get_hIST(read_ptr, read_info_ptr, &hist))\r
-         png_set_hIST(write_ptr, write_info_ptr, hist);\r
-   }\r
-#endif\r
-#ifdef PNG_oFFs_SUPPORTED\r
-   {\r
-      png_int_32 offset_x, offset_y;\r
-      int unit_type;\r
-\r
-      if (png_get_oFFs(read_ptr, read_info_ptr, &offset_x, &offset_y,\r
-          &unit_type))\r
-      {\r
-         png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type);\r
-      }\r
-   }\r
-#endif\r
-#ifdef PNG_pCAL_SUPPORTED\r
-   {\r
-      png_charp purpose, units;\r
-      png_charpp params;\r
-      png_int_32 X0, X1;\r
-      int type, nparams;\r
-\r
-      if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type,\r
-         &nparams, &units, &params))\r
-      {\r
-         png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type,\r
-            nparams, units, params);\r
-      }\r
-   }\r
-#endif\r
-#ifdef PNG_pHYs_SUPPORTED\r
-   {\r
-      png_uint_32 res_x, res_y;\r
-      int unit_type;\r
-\r
-      if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type))\r
-         png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type);\r
-   }\r
-#endif\r
-#ifdef PNG_sBIT_SUPPORTED\r
-   {\r
-      png_color_8p sig_bit;\r
-\r
-      if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit))\r
-         png_set_sBIT(write_ptr, write_info_ptr, sig_bit);\r
-   }\r
-#endif\r
-#ifdef PNG_sCAL_SUPPORTED\r
-#ifdef PNG_FLOATING_POINT_SUPPORTED\r
-   {\r
-      int unit;\r
-      double scal_width, scal_height;\r
-\r
-      if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width,\r
-         &scal_height))\r
-      {\r
-         png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height);\r
-      }\r
-   }\r
-#else\r
-#ifdef PNG_FIXED_POINT_SUPPORTED\r
-   {\r
-      int unit;\r
-      png_charp scal_width, scal_height;\r
-\r
-      if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width,\r
-          &scal_height))\r
-      {\r
-         png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width,\r
-             scal_height);\r
-      }\r
-   }\r
-#endif\r
-#endif\r
-#endif\r
-#ifdef PNG_TEXT_SUPPORTED\r
-   {\r
-      png_textp text_ptr;\r
-      int num_text;\r
-\r
-      if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0)\r
-      {\r
-         pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);\r
-\r
-         if (verbose)\r
-            printf("\nText compression=%d\n", text_ptr->compression);\r
-\r
-         png_set_text(write_ptr, write_info_ptr, text_ptr, num_text);\r
-      }\r
-   }\r
-#endif\r
-#ifdef PNG_tIME_SUPPORTED\r
-   {\r
-      png_timep mod_time;\r
-\r
-      if (png_get_tIME(read_ptr, read_info_ptr, &mod_time))\r
-      {\r
-         png_set_tIME(write_ptr, write_info_ptr, mod_time);\r
-#ifdef PNG_TIME_RFC1123_SUPPORTED\r
-         /* We have to use png_memcpy instead of "=" because the string\r
-          * pointed to by png_convert_to_rfc1123() gets free'ed before\r
-          * we use it.\r
-          */\r
-         png_memcpy(tIME_string,\r
-                    png_convert_to_rfc1123(read_ptr, mod_time),\r
-                    png_sizeof(tIME_string));\r
-\r
-         tIME_string[png_sizeof(tIME_string) - 1] = '\0';\r
-         tIME_chunk_present++;\r
-#endif /* PNG_TIME_RFC1123_SUPPORTED */\r
-      }\r
-   }\r
-#endif\r
-#ifdef PNG_tRNS_SUPPORTED\r
-   {\r
-      png_bytep trans_alpha;\r
-      int num_trans;\r
-      png_color_16p trans_color;\r
-\r
-      if (png_get_tRNS(read_ptr, read_info_ptr, &trans_alpha, &num_trans,\r
-         &trans_color))\r
-      {\r
-         int sample_max = (1 << bit_depth);\r
-         /* libpng doesn't reject a tRNS chunk with out-of-range samples */\r
-         if (!((color_type == PNG_COLOR_TYPE_GRAY &&\r
-             (int)trans_color->gray > sample_max) ||\r
-             (color_type == PNG_COLOR_TYPE_RGB &&\r
-             ((int)trans_color->red > sample_max ||\r
-             (int)trans_color->green > sample_max ||\r
-             (int)trans_color->blue > sample_max))))\r
-            png_set_tRNS(write_ptr, write_info_ptr, trans_alpha, num_trans,\r
-               trans_color);\r
-      }\r
-   }\r
-#endif\r
-#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED\r
-   {\r
-      png_unknown_chunkp unknowns;\r
-      int num_unknowns = png_get_unknown_chunks(read_ptr, read_info_ptr,\r
-         &unknowns);\r
-\r
-      if (num_unknowns)\r
-      {\r
-         int i;\r
-         png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns,\r
-           num_unknowns);\r
-         /* Copy the locations from the read_info_ptr.  The automatically\r
-          * generated locations in write_info_ptr are wrong because we\r
-          * haven't written anything yet.\r
-          */\r
-         for (i = 0; i < num_unknowns; i++)\r
-           png_set_unknown_chunk_location(write_ptr, write_info_ptr, i,\r
-             unknowns[i].location);\r
-      }\r
-   }\r
-#endif\r
-\r
-#ifdef PNG_WRITE_SUPPORTED\r
-   pngtest_debug("Writing info struct");\r
-\r
-/* If we wanted, we could write info in two steps:\r
- * png_write_info_before_PLTE(write_ptr, write_info_ptr);\r
- */\r
-   png_write_info(write_ptr, write_info_ptr);\r
-\r
-#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED\r
-   if (user_chunk_data[0] != 0)\r
-   {\r
-      png_byte png_sTER[5] = {115,  84,  69,  82, '\0'};\r
-\r
-      unsigned char\r
-        ster_chunk_data[1];\r
-\r
-      if (verbose)\r
-         fprintf(STDERR, "\n stereo mode = %lu\n",\r
-           (unsigned long)(user_chunk_data[0] - 1));\r
-\r
-      ster_chunk_data[0]=(unsigned char)(user_chunk_data[0] - 1);\r
-      png_write_chunk(write_ptr, png_sTER, ster_chunk_data, 1);\r
-   }\r
-\r
-   if (user_chunk_data[1] != 0 || user_chunk_data[2] != 0)\r
-   {\r
-      png_byte png_vpAg[5] = {118, 112,  65, 103, '\0'};\r
-\r
-      unsigned char\r
-        vpag_chunk_data[9];\r
-\r
-      if (verbose)\r
-         fprintf(STDERR, " vpAg = %lu x %lu, units = %lu\n",\r
-           (unsigned long)user_chunk_data[1],\r
-           (unsigned long)user_chunk_data[2],\r
-           (unsigned long)user_chunk_data[3]);\r
-\r
-      png_save_uint_32(vpag_chunk_data, user_chunk_data[1]);\r
-      png_save_uint_32(vpag_chunk_data + 4, user_chunk_data[2]);\r
-      vpag_chunk_data[8] = (unsigned char)(user_chunk_data[3] & 0xff);\r
-      png_write_chunk(write_ptr, png_vpAg, vpag_chunk_data, 9);\r
-   }\r
-\r
-#endif\r
-#endif\r
-\r
-#ifdef SINGLE_ROWBUF_ALLOC\r
-   pngtest_debug("Allocating row buffer...");\r
-   row_buf = (png_bytep)png_malloc(read_ptr,\r
-      png_get_rowbytes(read_ptr, read_info_ptr));\r
-\r
-   pngtest_debug1("\t0x%08lx", (unsigned long)row_buf);\r
-#endif /* SINGLE_ROWBUF_ALLOC */\r
-   pngtest_debug("Writing row data");\r
-\r
-#if defined(PNG_READ_INTERLACING_SUPPORTED) || \\r
-  defined(PNG_WRITE_INTERLACING_SUPPORTED)\r
-   num_pass = png_set_interlace_handling(read_ptr);\r
-#  ifdef PNG_WRITE_SUPPORTED\r
-   png_set_interlace_handling(write_ptr);\r
-#  endif\r
-#else\r
-   num_pass = 1;\r
-#endif\r
-\r
-#ifdef PNGTEST_TIMING\r
-   t_stop = (float)clock();\r
-   t_misc += (t_stop - t_start);\r
-   t_start = t_stop;\r
-#endif\r
-   for (pass = 0; pass < num_pass; pass++)\r
-   {\r
-      pngtest_debug1("Writing row data for pass %d", pass);\r
-      for (y = 0; y < height; y++)\r
-      {\r
-#ifndef SINGLE_ROWBUF_ALLOC\r
-         pngtest_debug2("Allocating row buffer (pass %d, y = %u)...", pass, y);\r
-         row_buf = (png_bytep)png_malloc(read_ptr,\r
-            png_get_rowbytes(read_ptr, read_info_ptr));\r
-\r
-         pngtest_debug2("\t0x%08lx (%u bytes)", (unsigned long)row_buf,\r
-            png_get_rowbytes(read_ptr, read_info_ptr));\r
-\r
-#endif /* !SINGLE_ROWBUF_ALLOC */\r
-         png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1);\r
-\r
-#ifdef PNG_WRITE_SUPPORTED\r
-#ifdef PNGTEST_TIMING\r
-         t_stop = (float)clock();\r
-         t_decode += (t_stop - t_start);\r
-         t_start = t_stop;\r
-#endif\r
-         png_write_rows(write_ptr, (png_bytepp)&row_buf, 1);\r
-#ifdef PNGTEST_TIMING\r
-         t_stop = (float)clock();\r
-         t_encode += (t_stop - t_start);\r
-         t_start = t_stop;\r
-#endif\r
-#endif /* PNG_WRITE_SUPPORTED */\r
-\r
-#ifndef SINGLE_ROWBUF_ALLOC\r
-         pngtest_debug2("Freeing row buffer (pass %d, y = %u)", pass, y);\r
-         png_free(read_ptr, row_buf);\r
-         row_buf = NULL;\r
-#endif /* !SINGLE_ROWBUF_ALLOC */\r
-      }\r
-   }\r
-\r
-#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED\r
-   png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1);\r
-#endif\r
-#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED\r
-   png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);\r
-#endif\r
-\r
-   pngtest_debug("Reading and writing end_info data");\r
-\r
-   png_read_end(read_ptr, end_info_ptr);\r
-#ifdef PNG_TEXT_SUPPORTED\r
-   {\r
-      png_textp text_ptr;\r
-      int num_text;\r
-\r
-      if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0)\r
-      {\r
-         pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);\r
-         png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text);\r
-      }\r
-   }\r
-#endif\r
-#ifdef PNG_tIME_SUPPORTED\r
-   {\r
-      png_timep mod_time;\r
-\r
-      if (png_get_tIME(read_ptr, end_info_ptr, &mod_time))\r
-      {\r
-         png_set_tIME(write_ptr, write_end_info_ptr, mod_time);\r
-#ifdef PNG_TIME_RFC1123_SUPPORTED\r
-         /* We have to use png_memcpy instead of "=" because the string\r
-            pointed to by png_convert_to_rfc1123() gets free'ed before\r
-            we use it */\r
-         png_memcpy(tIME_string,\r
-                    png_convert_to_rfc1123(read_ptr, mod_time),\r
-                    png_sizeof(tIME_string));\r
-\r
-         tIME_string[png_sizeof(tIME_string) - 1] = '\0';\r
-         tIME_chunk_present++;\r
-#endif /* PNG_TIME_RFC1123_SUPPORTED */\r
-      }\r
-   }\r
-#endif\r
-#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED\r
-   {\r
-      png_unknown_chunkp unknowns;\r
-      int num_unknowns = png_get_unknown_chunks(read_ptr, end_info_ptr,\r
-         &unknowns);\r
-\r
-      if (num_unknowns)\r
-      {\r
-         int i;\r
-         png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns,\r
-           num_unknowns);\r
-         /* Copy the locations from the read_info_ptr.  The automatically\r
-          * generated locations in write_end_info_ptr are wrong because we\r
-          * haven't written the end_info yet.\r
-          */\r
-         for (i = 0; i < num_unknowns; i++)\r
-           png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i,\r
-             unknowns[i].location);\r
-      }\r
-   }\r
-#endif\r
-#ifdef PNG_WRITE_SUPPORTED\r
-   png_write_end(write_ptr, write_end_info_ptr);\r
-#endif\r
-\r
-#ifdef PNG_EASY_ACCESS_SUPPORTED\r
-   if (verbose)\r
-   {\r
-      png_uint_32 iwidth, iheight;\r
-      iwidth = png_get_image_width(write_ptr, write_info_ptr);\r
-      iheight = png_get_image_height(write_ptr, write_info_ptr);\r
-      fprintf(STDERR, "\n Image width = %lu, height = %lu\n",\r
-         (unsigned long)iwidth, (unsigned long)iheight);\r
-   }\r
-#endif\r
-\r
-   pngtest_debug("Destroying data structs");\r
-#ifdef SINGLE_ROWBUF_ALLOC\r
-   pngtest_debug("destroying row_buf for read_ptr");\r
-   png_free(read_ptr, row_buf);\r
-   row_buf = NULL;\r
-#endif /* SINGLE_ROWBUF_ALLOC */\r
-   pngtest_debug("destroying read_ptr, read_info_ptr, end_info_ptr");\r
-   png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);\r
-#ifdef PNG_WRITE_SUPPORTED\r
-   pngtest_debug("destroying write_end_info_ptr");\r
-   png_destroy_info_struct(write_ptr, &write_end_info_ptr);\r
-   pngtest_debug("destroying write_ptr, write_info_ptr");\r
-   png_destroy_write_struct(&write_ptr, &write_info_ptr);\r
-#endif\r
-   pngtest_debug("Destruction complete.");\r
-\r
-   FCLOSE(fpin);\r
-   FCLOSE(fpout);\r
-\r
-   pngtest_debug("Opening files for comparison");\r
-   if ((fpin = fopen(inname, "rb")) == NULL)\r
-   {\r
-      fprintf(STDERR, "Could not find file %s\n", inname);\r
-      return (1);\r
-   }\r
-\r
-   if ((fpout = fopen(outname, "rb")) == NULL)\r
-   {\r
-      fprintf(STDERR, "Could not find file %s\n", outname);\r
-      FCLOSE(fpin);\r
-      return (1);\r
-   }\r
-\r
-   for (;;)\r
-   {\r
-      png_size_t num_in, num_out;\r
-\r
-         num_in = fread(inbuf, 1, 1, fpin);\r
-         num_out = fread(outbuf, 1, 1, fpout);\r
-\r
-      if (num_in != num_out)\r
-      {\r
-         fprintf(STDERR, "\nFiles %s and %s are of a different size\n",\r
-                 inname, outname);\r
-\r
-         if (wrote_question == 0)\r
-         {\r
-            fprintf(STDERR,\r
-         "   Was %s written with the same maximum IDAT chunk size (%d bytes),",\r
-              inname, PNG_ZBUF_SIZE);\r
-            fprintf(STDERR,\r
-              "\n   filtering heuristic (libpng default), compression");\r
-            fprintf(STDERR,\r
-              " level (zlib default),\n   and zlib version (%s)?\n\n",\r
-              ZLIB_VERSION);\r
-            wrote_question = 1;\r
-         }\r
-\r
-         FCLOSE(fpin);\r
-         FCLOSE(fpout);\r
-\r
-         if (strict != 0)\r
-           return (1);\r
-\r
-         else\r
-           return (0);\r
-      }\r
-\r
-      if (!num_in)\r
-         break;\r
-\r
-      if (png_memcmp(inbuf, outbuf, num_in))\r
-      {\r
-         fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname);\r
-\r
-         if (wrote_question == 0)\r
-         {\r
-            fprintf(STDERR,\r
-         "   Was %s written with the same maximum IDAT chunk size (%d bytes),",\r
-                 inname, PNG_ZBUF_SIZE);\r
-            fprintf(STDERR,\r
-              "\n   filtering heuristic (libpng default), compression");\r
-            fprintf(STDERR,\r
-              " level (zlib default),\n   and zlib version (%s)?\n\n",\r
-              ZLIB_VERSION);\r
-            wrote_question = 1;\r
-         }\r
-\r
-         FCLOSE(fpin);\r
-         FCLOSE(fpout);\r
-\r
-         if (strict != 0)\r
-           return (1);\r
-\r
-         else\r
-           return (0);\r
-      }\r
-   }\r
-\r
-   FCLOSE(fpin);\r
-   FCLOSE(fpout);\r
-\r
-   return (0);\r
-}\r
-\r
-/* Input and output filenames */\r
-#ifdef RISCOS\r
-static PNG_CONST char *inname = "pngtest/png";\r
-static PNG_CONST char *outname = "pngout/png";\r
-#else\r
-static PNG_CONST char *inname = "pngtest.png";\r
-static PNG_CONST char *outname = "pngout.png";\r
-#endif\r
-\r
-int\r
-main(int argc, char *argv[])\r
-{\r
-   int multiple = 0;\r
-   int ierror = 0;\r
-\r
-   fprintf(STDERR, "\n Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);\r
-   fprintf(STDERR, "   with zlib   version %s\n", ZLIB_VERSION);\r
-   fprintf(STDERR, "%s", png_get_copyright(NULL));\r
-   /* Show the version of libpng used in building the library */\r
-   fprintf(STDERR, " library (%lu):%s",\r
-      (unsigned long)png_access_version_number(),\r
-      png_get_header_version(NULL));\r
-\r
-   /* Show the version of libpng used in building the application */\r
-   fprintf(STDERR, " pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER,\r
-      PNG_HEADER_VERSION_STRING);\r
-\r
-   /* Do some consistency checking on the memory allocation settings, I'm\r
-    * not sure this matters, but it is nice to know, the first of these\r
-    * tests should be impossible because of the way the macros are set\r
-    * in pngconf.h\r
-    */\r
-#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)\r
-      fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n");\r
-#endif\r
-   /* I think the following can happen. */\r
-#if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K)\r
-      fprintf(STDERR, " NOTE: libpng compiled for max 64k, zlib not\n");\r
-#endif\r
-\r
-   if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING))\r
-   {\r
-      fprintf(STDERR,\r
-         "Warning: versions are different between png.h and png.c\n");\r
-      fprintf(STDERR, "  png.h version: %s\n", PNG_LIBPNG_VER_STRING);\r
-      fprintf(STDERR, "  png.c version: %s\n\n", png_libpng_ver);\r
-      ++ierror;\r
-   }\r
-\r
-   if (argc > 1)\r
-   {\r
-      if (strcmp(argv[1], "-m") == 0)\r
-      {\r
-         multiple = 1;\r
-         status_dots_requested = 0;\r
-      }\r
-\r
-      else if (strcmp(argv[1], "-mv") == 0 ||\r
-               strcmp(argv[1], "-vm") == 0 )\r
-      {\r
-         multiple = 1;\r
-         verbose = 1;\r
-         status_dots_requested = 1;\r
-      }\r
-\r
-      else if (strcmp(argv[1], "-v") == 0)\r
-      {\r
-         verbose = 1;\r
-         status_dots_requested = 1;\r
-         inname = argv[2];\r
-      }\r
-\r
-      else if (strcmp(argv[1], "--strict") == 0)\r
-      {\r
-         status_dots_requested = 0;\r
-         verbose = 1;\r
-         inname = argv[2];\r
-         strict++;\r
-      }\r
-\r
-      else\r
-      {\r
-         inname = argv[1];\r
-         status_dots_requested = 0;\r
-      }\r
-   }\r
-\r
-   if (!multiple && argc == 3 + verbose)\r
-     outname = argv[2 + verbose];\r
-\r
-   if ((!multiple && argc > 3 + verbose) || (multiple && argc < 2))\r
-   {\r
-     fprintf(STDERR,\r
-       "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",\r
-        argv[0], argv[0]);\r
-     fprintf(STDERR,\r
-       "  reads/writes one PNG file (without -m) or multiple files (-m)\n");\r
-     fprintf(STDERR,\r
-       "  with -m %s is used as a temporary file\n", outname);\r
-     exit(1);\r
-   }\r
-\r
-   if (multiple)\r
-   {\r
-      int i;\r
-#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\r
-      int allocation_now = current_allocation;\r
-#endif\r
-      for (i=2; i<argc; ++i)\r
-      {\r
-         int kerror;\r
-         fprintf(STDERR, "\n Testing %s:", argv[i]);\r
-         kerror = test_one_file(argv[i], outname);\r
-         if (kerror == 0)\r
-         {\r
-#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED\r
-            int k;\r
-#endif\r
-#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED\r
-            fprintf(STDERR, "\n PASS (%lu zero samples)\n",\r
-               (unsigned long)zero_samples);\r
-#else\r
-            fprintf(STDERR, " PASS\n");\r
-#endif\r
-#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED\r
-            for (k = 0; k<256; k++)\r
-               if (filters_used[k])\r
-                  fprintf(STDERR, " Filter %d was used %lu times\n",\r
-                     k, (unsigned long)filters_used[k]);\r
-#endif\r
-#ifdef PNG_TIME_RFC1123_SUPPORTED\r
-         if (tIME_chunk_present != 0)\r
-            fprintf(STDERR, " tIME = %s\n", tIME_string);\r
-\r
-         tIME_chunk_present = 0;\r
-#endif /* PNG_TIME_RFC1123_SUPPORTED */\r
-         }\r
-\r
-         else\r
-         {\r
-            fprintf(STDERR, " FAIL\n");\r
-            ierror += kerror;\r
-         }\r
-#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\r
-         if (allocation_now != current_allocation)\r
-            fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",\r
-               current_allocation - allocation_now);\r
-\r
-         if (current_allocation != 0)\r
-         {\r
-            memory_infop pinfo = pinformation;\r
-\r
-            fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",\r
-               current_allocation);\r
-\r
-            while (pinfo != NULL)\r
-            {\r
-               fprintf(STDERR, " %lu bytes at %x\n",\r
-                 (unsigned long)pinfo->size,\r
-                 (unsigned int)pinfo->pointer);\r
-               pinfo = pinfo->next;\r
-            }\r
-         }\r
-#endif\r
-      }\r
-#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\r
-         fprintf(STDERR, " Current memory allocation: %10d bytes\n",\r
-            current_allocation);\r
-         fprintf(STDERR, " Maximum memory allocation: %10d bytes\n",\r
-            maximum_allocation);\r
-         fprintf(STDERR, " Total   memory allocation: %10d bytes\n",\r
-            total_allocation);\r
-         fprintf(STDERR, "     Number of allocations: %10d\n",\r
-            num_allocations);\r
-#endif\r
-   }\r
-\r
-   else\r
-   {\r
-      int i;\r
-      for (i = 0; i<3; ++i)\r
-      {\r
-         int kerror;\r
-#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\r
-         int allocation_now = current_allocation;\r
-#endif\r
-         if (i == 1)\r
-            status_dots_requested = 1;\r
-\r
-         else if (verbose == 0)\r
-            status_dots_requested = 0;\r
-\r
-         if (i == 0 || verbose == 1 || ierror != 0)\r
-            fprintf(STDERR, "\n Testing %s:", inname);\r
-\r
-         kerror = test_one_file(inname, outname);\r
-\r
-         if (kerror == 0)\r
-         {\r
-            if (verbose == 1 || i == 2)\r
-            {\r
-#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED\r
-                int k;\r
-#endif\r
-#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED\r
-                fprintf(STDERR, "\n PASS (%lu zero samples)\n",\r
-                   (unsigned long)zero_samples);\r
-#else\r
-                fprintf(STDERR, " PASS\n");\r
-#endif\r
-#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED\r
-                for (k = 0; k<256; k++)\r
-                   if (filters_used[k])\r
-                      fprintf(STDERR, " Filter %d was used %lu times\n",\r
-                         k, (unsigned long)filters_used[k]);\r
-#endif\r
-#ifdef PNG_TIME_RFC1123_SUPPORTED\r
-             if (tIME_chunk_present != 0)\r
-                fprintf(STDERR, " tIME = %s\n", tIME_string);\r
-#endif /* PNG_TIME_RFC1123_SUPPORTED */\r
-            }\r
-         }\r
-\r
-         else\r
-         {\r
-            if (verbose == 0 && i != 2)\r
-               fprintf(STDERR, "\n Testing %s:", inname);\r
-\r
-            fprintf(STDERR, " FAIL\n");\r
-            ierror += kerror;\r
-         }\r
-#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\r
-         if (allocation_now != current_allocation)\r
-             fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",\r
-               current_allocation - allocation_now);\r
-\r
-         if (current_allocation != 0)\r
-         {\r
-             memory_infop pinfo = pinformation;\r
-\r
-             fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",\r
-                current_allocation);\r
-\r
-             while (pinfo != NULL)\r
-             {\r
-                fprintf(STDERR, " %lu bytes at %x\n",\r
-                   (unsigned long)pinfo->size, (unsigned int)pinfo->pointer);\r
-                pinfo = pinfo->next;\r
-             }\r
-          }\r
-#endif\r
-       }\r
-#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\r
-       fprintf(STDERR, " Current memory allocation: %10d bytes\n",\r
-          current_allocation);\r
-       fprintf(STDERR, " Maximum memory allocation: %10d bytes\n",\r
-          maximum_allocation);\r
-       fprintf(STDERR, " Total   memory allocation: %10d bytes\n",\r
-          total_allocation);\r
-       fprintf(STDERR, "     Number of allocations: %10d\n",\r
-            num_allocations);\r
-#endif\r
-   }\r
-\r
-#ifdef PNGTEST_TIMING\r
-   t_stop = (float)clock();\r
-   t_misc += (t_stop - t_start);\r
-   t_start = t_stop;\r
-   fprintf(STDERR, " CPU time used = %.3f seconds",\r
-      (t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC);\r
-   fprintf(STDERR, " (decoding %.3f,\n",\r
-      t_decode/(float)CLOCKS_PER_SEC);\r
-   fprintf(STDERR, "        encoding %.3f ,",\r
-      t_encode/(float)CLOCKS_PER_SEC);\r
-   fprintf(STDERR, " other %.3f seconds)\n\n",\r
-      t_misc/(float)CLOCKS_PER_SEC);\r
-#endif\r
-\r
-   if (ierror == 0)\r
-      fprintf(STDERR, " libpng passes test\n");\r
-\r
-   else\r
-      fprintf(STDERR, " libpng FAILS test\n");\r
-\r
-   return (int)(ierror != 0);\r
-}\r
-\r
-/* Generate a compiler error if there is an old png.h in the search path. */\r
-typedef png_libpng_version_1_5_7 Your_png_h_is_not_version_1_5_7;\r