0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A * This file is available under and governed by the GNU General Public 0N/A * License version 2 only, as published by the Free Software Foundation. 0N/A * However, the following notice accompanied the original version of this 0N/A * file and, per its terms, should not be removed: 4418N/A * Last changed in libpng 1.5.4 [July 7, 2011] 4418N/A * Copyright (c) 1998-2011 Glenn Randers-Pehrson 0N/A * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 0N/A * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 4418N/A * This code is released under the libpng license. 4418N/A * For conditions of distribution and use, see the disclaimer 0N/A * This program reads in a PNG image, writes it out again, and then 0N/A * compares the two files. If the files are identical, this shows that 0N/A * the basic chunk handling, filtering, and (de)compression code is working 0N/A * properly. It does not currently test all of the transforms, although 0N/A * it probably should. 0N/A * The program will report "FAIL" in certain legitimate cases: 0N/A * 1) when the compression level or filter selection method is changed. 0N/A * 2) when the maximum IDAT size (PNG_ZBUF_SIZE in pngconf.h) is not 8192. 0N/A * 3) unknown unsafe-to-copy ancillary chunks or unknown critical chunks 0N/A * exist in the input file. 0N/A * 4) others not listed here... 0N/A * In these cases, it is best to check with another tool such as "pngcheck" 0N/A * to see what the differences between the two files are. 0N/A * If a filename is given on the command-line, then this file is used 0N/A * for the input, rather than the default "pngtest.png". This allows 0N/A * testing a wide variety of files easily. You can also test a number 0N/A * of files at once by typing "pngtest -m file1.png file2.png ..." 4418N/A/* Makes pngtest verbose so we can find problems. */ 4418N/A/* The code uses memcmp and memcpy on large objects (typically row pointers) so 4418N/A * it is necessary to do soemthing special on certain architectures, note that 4418N/A * the actual support for this was effectively removed in 1.4, so only the 4418N/A * memory remains in this program: 0N/A/* Turn on CPU timing 0N/A#define PNGTEST_TIMING 0N/A/* #define STDERR stderr */ 0N/A/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */ 4418N/A/* Example of using row callbacks to make a simple progress meter */ 0N/A/* Example of using user transform callback (we don't transform anything, 4418N/A * but merely examine the row filters. We set this to 256 rather than 4418N/A * 5 in case illegal filter values are present.) 4418N/A/* Example of using user transform callback (we don't transform anything, 4418N/A * but merely count the zero samples) 0N/A * png_uint_32 width width of row 0N/A * png_uint_32 rowbytes number of bytes in row 0N/A * png_byte color_type color type of pixels 0N/A * png_byte bit_depth bit depth of samples 0N/A * png_byte channels number of channels (1-4) 0N/A * png_byte pixel_depth bits per pixel (depth*channels) 4418N/A /* Counts the number of zero samples (or zero pixels if color_type is 3 */ 4418N/A else /* Other color types */ 0N/A#
endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */ 0N/A/* START of code to validate stdio-free compilation */ 4418N/A * pngwio.c. They allow "don't include stdio" testing of the library. 4418N/A * This is the function that does the actual reading of data. If you are 4418N/A * not reading from a standard C stream, you should create a replacement 4418N/A * read_data function and use it at run time with png_set_read_fn(), rather 4418N/A * than changing the library. 4418N/A /* Check if the current operation (reading / writing) is as expected. */ 4418N/A /* Check if the buffer size specific to the current location 4418N/A * (file signature / header / data / crc) is as expected. 4418N/A break;
/* no restrictions here */ 0N/A /* fread() returns 0 on error, so it is OK to store this in a png_size_t 0N/A * instead of an int, which is what fread() actually returns. 4418N/A/* This is the model-independent version. Since the standard I/O library 0N/A can't handle far buffers in the medium and small models, we have to copy 0N/A#
define MIN(a,b) (a <= b ? a : b)
0N/A /* Check if data really is near. If so, use usual code. */ 0N/A#
endif /* USE_FAR_KEYWORD */ 4418N/A /* Do nothing; fflush() is said to be just a waste of energy. */ 0N/A/* This is the function that does the actual writing of data. If you are 4418N/A * not writing to a standard C stream, you should create a replacement 4418N/A * write_data function and use it at run time with png_set_write_fn(), rather 4418N/A * than changing the library. 4418N/A/* This is the model-independent version. Since the standard I/O library 0N/A can't handle far buffers in the medium and small models, we have to copy 0N/A#
define MIN(a,b) (a <= b ? a : b)
0N/A /* Check if data really is near. If so, use usual code. */ 0N/A#
endif /* USE_FAR_KEYWORD */ 0N/A/* This function is called when there is a warning, but the library thinks 0N/A * it can continue anyway. Replacement functions don't have to do anything 0N/A * here if you don't want to. In the default configuration, png_ptr is 0N/A * not used, but it is passed in case it may be useful. 0N/A/* This is the default error handling function. Note that replacements for 0N/A * this function MUST NOT RETURN, or the program will likely crash. This 0N/A * function is used by default, or if the program supplies NULL for the 0N/A * error function pointer in png_set_error_fn(). 0N/A /* We can return because png_error calls the default handler, which is 4418N/A * actually OK in this case. 4418N/A#
endif /* !PNG_STDIO_SUPPORTED */ 0N/A/* END of code to validate stdio-free compilation */ 0N/A/* START of code to validate memory allocation and deallocation */ 0N/A/* Allocate memory. For reasonable files, size should never exceed 4418N/A * 64K. However, zlib may allocate more then 64K if you don't tell 4418N/A * need to allocate exactly 64K, so whatever you call here must 4418N/A * have the ability to do that. 4418N/A * This piece of code can be compiled to validate max 64K allocations 4418N/A * by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K. 0N/A /* png_malloc has already tested for NULL; png_create_struct calls 4418N/A * png_debug_malloc directly, with png_ptr == NULL which is OK 0N/A /* This calls the library allocator twice, once to get the requested 0N/A buffer and once to get a new free list entry. */ 0N/A /* Disable malloc_fn and free_fn */ 0N/A /* Restore malloc_fn and free_fn */ 4418N/A "out of memory in pngtest->png_debug_malloc");
0N/A /* Make sure the caller isn't assuming zeroed memory. */ 0N/A/* Free a pointer. It is removed from the list at the same time. */ 0N/A#
if 0
/* This happens all the time. */ 0N/A /* Unlink the element from the list. */ 0N/A /* We must free the list element too, but first kill 0N/A the memory that is to be freed. */ 0N/A /* Finally free the data. */ 0N/A#
endif /* PNG_USER_MEM_SUPPORTED && PNG_DEBUG */ 4418N/A/* Demonstration of user chunk support of the sTER and vpAg chunks */ 4418N/A/* (sTER is a public chunk not yet known by libpng. vpAg is a private 4418N/Achunk used in ImageMagick to store "virtual page" size). */ 4418N/A /* Return one of the following: 4418N/A * return (-n); chunk had an error 4418N/A * return (0); did not recognize 4418N/A * The unknown chunk structure contains the chunk data: 4418N/A * Note that libpng has already taken care of the CRC handling. 4418N/A return (-
1);
/* Error return */ 4418N/A return (-
1);
/* Invalid mode */ 4418N/A return (0);
/* Did not recognize */ 4418N/A /* Found ImageMagick vpAg chunk */ 4418N/A return (-
1);
/* Error return */ 4418N/A/* END of code to demonstrate user chunk support */ 4418N/A /* Normally one would use Z_DEFAULT_STRATEGY for text compression. 4418N/A * This is here just to make pngtest replicate the results from libpng 4418N/A * versions prior to 1.5.4, and to test this new API. 0N/A#
else /* Use floating point versions */ 4418N/A /* We have to use png_memcpy instead of "=" because the string 4418N/A * pointed to by png_convert_to_rfc1123() gets free'ed before 0N/A#
endif /* PNG_TIME_RFC1123_SUPPORTED */ 4418N/A /* libpng doesn't reject a tRNS chunk with out-of-range samples */ 4418N/A /* Copy the locations from the read_info_ptr. The automatically 4418N/A * generated locations in write_info_ptr are wrong because we 4418N/A * haven't written anything yet. 0N/A/* If we wanted, we could write info in two steps: 4418N/A * png_write_info_before_PLTE(write_ptr, write_info_ptr); 0N/A#
endif /* SINGLE_ROWBUF_ALLOC */ 0N/A#
endif /* !SINGLE_ROWBUF_ALLOC */ 0N/A#
endif /* PNG_WRITE_SUPPORTED */ 0N/A#
endif /* !SINGLE_ROWBUF_ALLOC */ 4418N/A /* We have to use png_memcpy instead of "=" because the string 0N/A pointed to by png_convert_to_rfc1123() gets free'ed before 0N/A#
endif /* PNG_TIME_RFC1123_SUPPORTED */ 4418N/A /* Copy the locations from the read_info_ptr. The automatically 4418N/A * generated locations in write_end_info_ptr are wrong because we 4418N/A * haven't written the end_info yet. 0N/A#
endif /* SINGLE_ROWBUF_ALLOC */ 0N/A " Was %s written with the same maximum IDAT chunk size (%d bytes),",
0N/A "\n filtering heuristic (libpng default), compression");
0N/A " level (zlib default),\n and zlib version (%s)?\n\n",
0N/A " Was %s written with the same maximum IDAT chunk size (%d bytes),",
0N/A "\n filtering heuristic (libpng default), compression");
0N/A " level (zlib default),\n and zlib version (%s)?\n\n",
4418N/A/* Input and output filenames */ 0N/A /* Show the version of libpng used in building the library */ 0N/A /* Show the version of libpng used in building the application */ 0N/A /* Do some consistency checking on the memory allocation settings, I'm 4418N/A * not sure this matters, but it is nice to know, the first of these 4418N/A * tests should be impossible because of the way the macros are set 0N/A /* I think the following can happen. */ 0N/A "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
0N/A " with -m %s is used as a temporary file\n",
outname);
0N/A#
endif /* PNG_TIME_RFC1123_SUPPORTED */ 0N/A#
endif /* PNG_TIME_RFC1123_SUPPORTED */ 0N/A/* Generate a compiler error if there is an old png.h in the search path. */