0N/A/*
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
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 *
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 *
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.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* pngtest.c - a simple test program to test libpng
0N/A *
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:
0N/A *
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.)
0N/A *
4418N/A * This code is released under the libpng license.
4418N/A * For conditions of distribution and use, see the disclaimer
4418N/A * and license in png.h
4418N/A *
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 *
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 *
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 ..."
0N/A */
0N/A
4418N/A#define _POSIX_SOURCE 1
0N/A
4418N/A#include "zlib.h"
4418N/A#include "png.h"
4418N/A/* Copied from pngpriv.h but only used in error messages below. */
4418N/A#ifndef PNG_ZBUF_SIZE
4418N/A# define PNG_ZBUF_SIZE 8192
4418N/A#endif
0N/A# include <stdio.h>
0N/A# include <stdlib.h>
4418N/A# include <string.h>
0N/A# define FCLOSE(file) fclose(file)
4418N/A
4418N/A#ifndef PNG_STDIO_SUPPORTED
4418N/Atypedef FILE * png_FILE_p;
0N/A#endif
0N/A
4418N/A/* Makes pngtest verbose so we can find problems. */
0N/A#ifndef PNG_DEBUG
0N/A# define PNG_DEBUG 0
0N/A#endif
0N/A
4418N/A#if PNG_DEBUG > 1
4418N/A# define pngtest_debug(m) ((void)fprintf(stderr, m "\n"))
4418N/A# define pngtest_debug1(m,p1) ((void)fprintf(stderr, m "\n", p1))
4418N/A# define pngtest_debug2(m,p1,p2) ((void)fprintf(stderr, m "\n", p1, p2))
4418N/A#else
4418N/A# define pngtest_debug(m) ((void)0)
4418N/A# define pngtest_debug1(m,p1) ((void)0)
4418N/A# define pngtest_debug2(m,p1,p2) ((void)0)
4418N/A#endif
4418N/A
0N/A#if !PNG_DEBUG
4418N/A# define SINGLE_ROWBUF_ALLOC /* Makes buffer overruns easier to nail */
0N/A#endif
0N/A
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:
4418N/A */
4418N/A#define CVT_PTR(ptr) (ptr)
4418N/A#define CVT_PTR_NOCHECK(ptr) (ptr)
4418N/A#define png_memcmp memcmp
4418N/A#define png_memcpy memcpy
4418N/A#define png_memset memset
4418N/A
0N/A/* Turn on CPU timing
0N/A#define PNGTEST_TIMING
0N/A*/
0N/A
4418N/A#ifndef PNG_FLOATING_POINT_SUPPORTED
0N/A#undef PNGTEST_TIMING
0N/A#endif
0N/A
0N/A#ifdef PNGTEST_TIMING
0N/Astatic float t_start, t_stop, t_decode, t_encode, t_misc;
0N/A#include <time.h>
0N/A#endif
0N/A
4418N/A#ifdef PNG_TIME_RFC1123_SUPPORTED
4418N/A#define PNG_tIME_STRING_LENGTH 29
4418N/Astatic int tIME_chunk_present = 0;
4418N/Astatic char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present";
0N/A#endif
0N/A
0N/Astatic int verbose = 0;
0N/A
0N/Aint test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname));
0N/A
0N/A#ifdef __TURBOC__
0N/A#include <mem.h>
0N/A#endif
0N/A
4418N/A/* Defined so I can write to a file on gui/windowing platforms */
0N/A/* #define STDERR stderr */
4418N/A#define STDERR stdout /* For DOS */
0N/A
0N/A/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
0N/A#ifndef png_jmpbuf
0N/A# define png_jmpbuf(png_ptr) png_ptr->jmpbuf
0N/A#endif
0N/A
4418N/A/* Example of using row callbacks to make a simple progress meter */
4418N/Astatic int status_pass = 1;
4418N/Astatic int status_dots_requested = 0;
4418N/Astatic int status_dots = 1;
4418N/A
4418N/Avoid PNGCBAPI
0N/Aread_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass);
4418N/Avoid PNGCBAPI
0N/Aread_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
0N/A{
4418N/A if (png_ptr == NULL || row_number > PNG_UINT_31_MAX)
4418N/A return;
4418N/A
4418N/A if (status_pass != pass)
4418N/A {
4418N/A fprintf(stdout, "\n Pass %d: ", pass);
4418N/A status_pass = pass;
4418N/A status_dots = 31;
4418N/A }
4418N/A
4418N/A status_dots--;
4418N/A
4418N/A if (status_dots == 0)
4418N/A {
4418N/A fprintf(stdout, "\n ");
4418N/A status_dots=30;
4418N/A }
4418N/A
4418N/A fprintf(stdout, "r");
0N/A}
0N/A
4418N/Avoid PNGCBAPI
0N/Awrite_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass);
4418N/Avoid PNGCBAPI
0N/Awrite_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
0N/A{
4418N/A if (png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7)
4418N/A return;
4418N/A
4418N/A fprintf(stdout, "w");
0N/A}
0N/A
0N/A
4418N/A#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
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 */
0N/Astatic png_uint_32 filters_used[256];
4418N/Avoid PNGCBAPI
0N/Acount_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data);
4418N/Avoid PNGCBAPI
0N/Acount_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data)
0N/A{
4418N/A if (png_ptr != NULL && row_info != NULL)
4418N/A ++filters_used[*(data - 1)];
0N/A}
0N/A#endif
0N/A
4418N/A#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
4418N/A/* Example of using user transform callback (we don't transform anything,
4418N/A * but merely count the zero samples)
4418N/A */
0N/A
0N/Astatic png_uint_32 zero_samples;
0N/A
4418N/Avoid PNGCBAPI
0N/Acount_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data);
4418N/Avoid PNGCBAPI
0N/Acount_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
0N/A{
0N/A png_bytep dp = data;
4418N/A if (png_ptr == NULL)
4418N/A return;
0N/A
4418N/A /* Contents of row_info:
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)
0N/A */
0N/A
4418N/A /* Counts the number of zero samples (or zero pixels if color_type is 3 */
0N/A
4418N/A if (row_info->color_type == 0 || row_info->color_type == 3)
0N/A {
4418N/A int pos = 0;
0N/A png_uint_32 n, nstop;
4418N/A
4418N/A for (n = 0, nstop=row_info->width; n<nstop; n++)
0N/A {
4418N/A if (row_info->bit_depth == 1)
0N/A {
4418N/A if (((*dp << pos++ ) & 0x80) == 0)
4418N/A zero_samples++;
4418N/A
4418N/A if (pos == 8)
0N/A {
0N/A pos = 0;
0N/A dp++;
0N/A }
0N/A }
4418N/A
4418N/A if (row_info->bit_depth == 2)
0N/A {
4418N/A if (((*dp << (pos+=2)) & 0xc0) == 0)
4418N/A zero_samples++;
4418N/A
4418N/A if (pos == 8)
0N/A {
0N/A pos = 0;
0N/A dp++;
0N/A }
0N/A }
4418N/A
4418N/A if (row_info->bit_depth == 4)
0N/A {
4418N/A if (((*dp << (pos+=4)) & 0xf0) == 0)
4418N/A zero_samples++;
4418N/A
4418N/A if (pos == 8)
0N/A {
0N/A pos = 0;
0N/A dp++;
0N/A }
0N/A }
4418N/A
4418N/A if (row_info->bit_depth == 8)
4418N/A if (*dp++ == 0)
4418N/A zero_samples++;
4418N/A
4418N/A if (row_info->bit_depth == 16)
0N/A {
4418N/A if ((*dp | *(dp+1)) == 0)
4418N/A zero_samples++;
0N/A dp+=2;
0N/A }
0N/A }
0N/A }
4418N/A else /* Other color types */
0N/A {
0N/A png_uint_32 n, nstop;
0N/A int channel;
0N/A int color_channels = row_info->channels;
4418N/A if (row_info->color_type > 3)color_channels--;
0N/A
4418N/A for (n = 0, nstop=row_info->width; n<nstop; n++)
0N/A {
0N/A for (channel = 0; channel < color_channels; channel++)
0N/A {
4418N/A if (row_info->bit_depth == 8)
4418N/A if (*dp++ == 0)
4418N/A zero_samples++;
4418N/A
4418N/A if (row_info->bit_depth == 16)
0N/A {
4418N/A if ((*dp | *(dp+1)) == 0)
4418N/A zero_samples++;
4418N/A
0N/A dp+=2;
0N/A }
0N/A }
4418N/A if (row_info->color_type > 3)
0N/A {
0N/A dp++;
4418N/A if (row_info->bit_depth == 16)
4418N/A dp++;
0N/A }
0N/A }
0N/A }
0N/A}
0N/A#endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */
0N/A
0N/Astatic int wrote_question = 0;
0N/A
4418N/A#ifndef PNG_STDIO_SUPPORTED
0N/A/* START of code to validate stdio-free compilation */
4418N/A/* These copies of the default read/write functions come from pngrio.c and
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 */
4418N/A
4418N/A#ifdef PNG_IO_STATE_SUPPORTED
4418N/Avoid
4418N/Apngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
4418N/A png_uint_32 io_op);
4418N/Avoid
4418N/Apngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
4418N/A png_uint_32 io_op)
4418N/A{
4418N/A png_uint_32 io_state = png_get_io_state(png_ptr);
4418N/A int err = 0;
4418N/A
4418N/A /* Check if the current operation (reading / writing) is as expected. */
4418N/A if ((io_state & PNG_IO_MASK_OP) != io_op)
4418N/A png_error(png_ptr, "Incorrect operation in I/O state");
4418N/A
4418N/A /* Check if the buffer size specific to the current location
4418N/A * (file signature / header / data / crc) is as expected.
4418N/A */
4418N/A switch (io_state & PNG_IO_MASK_LOC)
4418N/A {
4418N/A case PNG_IO_SIGNATURE:
4418N/A if (data_length > 8)
4418N/A err = 1;
4418N/A break;
4418N/A case PNG_IO_CHUNK_HDR:
4418N/A if (data_length != 8)
4418N/A err = 1;
4418N/A break;
4418N/A case PNG_IO_CHUNK_DATA:
4418N/A break; /* no restrictions here */
4418N/A case PNG_IO_CHUNK_CRC:
4418N/A if (data_length != 4)
4418N/A err = 1;
4418N/A break;
4418N/A default:
4418N/A err = 1; /* uninitialized */
4418N/A }
4418N/A if (err)
4418N/A png_error(png_ptr, "Bad I/O state or buffer size");
4418N/A}
4418N/A#endif
0N/A
0N/A#ifndef USE_FAR_KEYWORD
4418N/Astatic void PNGCBAPI
0N/Apngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
0N/A{
4418N/A png_size_t check = 0;
4418N/A png_voidp io_ptr;
0N/A
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.
0N/A */
4418N/A io_ptr = png_get_io_ptr(png_ptr);
4418N/A if (io_ptr != NULL)
4418N/A {
4418N/A check = fread(data, 1, length, (png_FILE_p)io_ptr);
4418N/A }
0N/A
0N/A if (check != length)
0N/A {
4418N/A png_error(png_ptr, "Read Error");
0N/A }
4418N/A
4418N/A#ifdef PNG_IO_STATE_SUPPORTED
4418N/A pngtest_check_io_state(png_ptr, length, PNG_IO_READING);
4418N/A#endif
0N/A}
0N/A#else
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 the data.
0N/A*/
0N/A
0N/A#define NEAR_BUF_SIZE 1024
0N/A#define MIN(a,b) (a <= b ? a : b)
0N/A
4418N/Astatic void PNGCBAPI
0N/Apngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
0N/A{
4418N/A png_size_t check;
0N/A png_byte *n_data;
0N/A png_FILE_p io_ptr;
0N/A
0N/A /* Check if data really is near. If so, use usual code. */
0N/A n_data = (png_byte *)CVT_PTR_NOCHECK(data);
4418N/A io_ptr = (png_FILE_p)CVT_PTR(png_get_io_ptr(png_ptr));
0N/A if ((png_bytep)n_data == data)
0N/A {
4418N/A check = fread(n_data, 1, length, io_ptr);
0N/A }
0N/A else
0N/A {
0N/A png_byte buf[NEAR_BUF_SIZE];
0N/A png_size_t read, remaining, err;
0N/A check = 0;
0N/A remaining = length;
4418N/A
0N/A do
0N/A {
0N/A read = MIN(NEAR_BUF_SIZE, remaining);
4418N/A err = fread(buf, 1, 1, io_ptr);
4418N/A png_memcpy(data, buf, read); /* Copy far buffer to near buffer */
4418N/A if (err != read)
0N/A break;
0N/A else
0N/A check += err;
0N/A data += read;
0N/A remaining -= read;
0N/A }
0N/A while (remaining != 0);
0N/A }
4418N/A
0N/A if (check != length)
4418N/A png_error(png_ptr, "Read Error");
4418N/A
4418N/A#ifdef PNG_IO_STATE_SUPPORTED
4418N/A pngtest_check_io_state(png_ptr, length, PNG_IO_READING);
4418N/A#endif
0N/A}
0N/A#endif /* USE_FAR_KEYWORD */
0N/A
4418N/A#ifdef PNG_WRITE_FLUSH_SUPPORTED
4418N/Astatic void PNGCBAPI
0N/Apngtest_flush(png_structp png_ptr)
0N/A{
4418N/A /* Do nothing; fflush() is said to be just a waste of energy. */
4418N/A PNG_UNUSED(png_ptr) /* Stifle compiler warning */
0N/A}
0N/A#endif
0N/A
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 */
0N/A#ifndef USE_FAR_KEYWORD
4418N/Astatic void PNGCBAPI
0N/Apngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
0N/A{
4418N/A png_size_t check;
0N/A
4418N/A check = fwrite(data, 1, length, (png_FILE_p)png_get_io_ptr(png_ptr));
4418N/A
0N/A if (check != length)
0N/A {
0N/A png_error(png_ptr, "Write Error");
0N/A }
4418N/A
4418N/A#ifdef PNG_IO_STATE_SUPPORTED
4418N/A pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);
4418N/A#endif
0N/A}
0N/A#else
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 the data.
0N/A*/
0N/A
0N/A#define NEAR_BUF_SIZE 1024
0N/A#define MIN(a,b) (a <= b ? a : b)
0N/A
4418N/Astatic void PNGCBAPI
0N/Apngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
0N/A{
4418N/A png_size_t check;
0N/A png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
0N/A png_FILE_p io_ptr;
0N/A
0N/A /* Check if data really is near. If so, use usual code. */
0N/A near_data = (png_byte *)CVT_PTR_NOCHECK(data);
4418N/A io_ptr = (png_FILE_p)CVT_PTR(png_get_io_ptr(png_ptr));
4418N/A
0N/A if ((png_bytep)near_data == data)
0N/A {
4418N/A check = fwrite(near_data, 1, length, io_ptr);
0N/A }
4418N/A
0N/A else
0N/A {
0N/A png_byte buf[NEAR_BUF_SIZE];
0N/A png_size_t written, remaining, err;
0N/A check = 0;
0N/A remaining = length;
4418N/A
0N/A do
0N/A {
0N/A written = MIN(NEAR_BUF_SIZE, remaining);
4418N/A png_memcpy(buf, data, written); /* Copy far buffer to near buffer */
4418N/A err = fwrite(buf, 1, written, io_ptr);
0N/A if (err != written)
0N/A break;
0N/A else
0N/A check += err;
0N/A data += written;
0N/A remaining -= written;
0N/A }
0N/A while (remaining != 0);
0N/A }
4418N/A
0N/A if (check != length)
0N/A {
0N/A png_error(png_ptr, "Write Error");
0N/A }
4418N/A
4418N/A#ifdef PNG_IO_STATE_SUPPORTED
4418N/A pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);
4418N/A#endif
0N/A}
0N/A#endif /* USE_FAR_KEYWORD */
0N/A
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 */
4418N/Astatic void PNGCBAPI
0N/Apngtest_warning(png_structp png_ptr, png_const_charp message)
0N/A{
0N/A PNG_CONST char *name = "UNKNOWN (ERROR!)";
4418N/A char *test;
4418N/A test = png_get_error_ptr(png_ptr);
4418N/A
4418N/A if (test == NULL)
4418N/A fprintf(STDERR, "%s: libpng warning: %s\n", name, message);
4418N/A
4418N/A else
4418N/A fprintf(STDERR, "%s: libpng warning: %s\n", test, message);
0N/A}
0N/A
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 */
4418N/Astatic void PNGCBAPI
0N/Apngtest_error(png_structp png_ptr, png_const_charp message)
0N/A{
0N/A pngtest_warning(png_ptr, message);
0N/A /* We can return because png_error calls the default handler, which is
4418N/A * actually OK in this case.
4418N/A */
0N/A}
4418N/A#endif /* !PNG_STDIO_SUPPORTED */
0N/A/* END of code to validate stdio-free compilation */
0N/A
0N/A/* START of code to validate memory allocation and deallocation */
0N/A#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
0N/A
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 * it not to. See zconf.h and png.h for more information. zlib does
4418N/A * need to allocate exactly 64K, so whatever you call here must
4418N/A * have the ability to do that.
4418N/A *
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.
4418N/A */
0N/Atypedef struct memory_information
0N/A{
4418N/A png_alloc_size_t size;
0N/A png_voidp pointer;
0N/A struct memory_information FAR *next;
0N/A} memory_information;
0N/Atypedef memory_information FAR *memory_infop;
0N/A
0N/Astatic memory_infop pinformation = NULL;
0N/Astatic int current_allocation = 0;
0N/Astatic int maximum_allocation = 0;
0N/Astatic int total_allocation = 0;
0N/Astatic int num_allocations = 0;
0N/A
4418N/Apng_voidp PNGCBAPI png_debug_malloc PNGARG((png_structp png_ptr,
4418N/A png_alloc_size_t size));
4418N/Avoid PNGCBAPI png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr));
0N/A
0N/Apng_voidp
4418N/APNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
0N/A{
0N/A
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
4418N/A */
0N/A
0N/A if (size == 0)
0N/A return (NULL);
0N/A
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 {
0N/A /* Disable malloc_fn and free_fn */
0N/A memory_infop pinfo;
0N/A png_set_mem_fn(png_ptr, NULL, NULL, NULL);
0N/A pinfo = (memory_infop)png_malloc(png_ptr,
4418N/A png_sizeof(*pinfo));
0N/A pinfo->size = size;
0N/A current_allocation += size;
0N/A total_allocation += size;
0N/A num_allocations ++;
4418N/A
0N/A if (current_allocation > maximum_allocation)
0N/A maximum_allocation = current_allocation;
4418N/A
4418N/A pinfo->pointer = png_malloc(png_ptr, size);
0N/A /* Restore malloc_fn and free_fn */
4418N/A
4418N/A png_set_mem_fn(png_ptr,
4418N/A NULL, png_debug_malloc, png_debug_free);
4418N/A
0N/A if (size != 0 && pinfo->pointer == NULL)
0N/A {
0N/A current_allocation -= size;
0N/A total_allocation -= size;
0N/A png_error(png_ptr,
4418N/A "out of memory in pngtest->png_debug_malloc");
0N/A }
4418N/A
0N/A pinfo->next = pinformation;
0N/A pinformation = pinfo;
0N/A /* Make sure the caller isn't assuming zeroed memory. */
0N/A png_memset(pinfo->pointer, 0xdd, pinfo->size);
4418N/A
4418N/A if (verbose)
4418N/A printf("png_malloc %lu bytes at %p\n", (unsigned long)size,
4418N/A pinfo->pointer);
4418N/A
0N/A return (png_voidp)(pinfo->pointer);
0N/A }
0N/A}
0N/A
0N/A/* Free a pointer. It is removed from the list at the same time. */
4418N/Avoid PNGCBAPI
0N/Apng_debug_free(png_structp png_ptr, png_voidp ptr)
0N/A{
0N/A if (png_ptr == NULL)
0N/A fprintf(STDERR, "NULL pointer to png_debug_free.\n");
4418N/A
0N/A if (ptr == 0)
0N/A {
0N/A#if 0 /* This happens all the time. */
0N/A fprintf(STDERR, "WARNING: freeing NULL pointer\n");
0N/A#endif
0N/A return;
0N/A }
0N/A
0N/A /* Unlink the element from the list. */
0N/A {
0N/A memory_infop FAR *ppinfo = &pinformation;
4418N/A
0N/A for (;;)
0N/A {
0N/A memory_infop pinfo = *ppinfo;
4418N/A
0N/A if (pinfo->pointer == ptr)
0N/A {
0N/A *ppinfo = pinfo->next;
0N/A current_allocation -= pinfo->size;
0N/A if (current_allocation < 0)
0N/A fprintf(STDERR, "Duplicate free of memory\n");
0N/A /* We must free the list element too, but first kill
0N/A the memory that is to be freed. */
0N/A png_memset(ptr, 0x55, pinfo->size);
0N/A png_free_default(png_ptr, pinfo);
4418N/A pinfo = NULL;
0N/A break;
0N/A }
4418N/A
0N/A if (pinfo->next == NULL)
0N/A {
0N/A fprintf(STDERR, "Pointer %x not found\n", (unsigned int)ptr);
0N/A break;
0N/A }
4418N/A
0N/A ppinfo = &pinfo->next;
0N/A }
0N/A }
0N/A
0N/A /* Finally free the data. */
4418N/A if (verbose)
4418N/A printf("Freeing %p\n", ptr);
4418N/A
0N/A png_free_default(png_ptr, ptr);
4418N/A ptr = NULL;
0N/A}
0N/A#endif /* PNG_USER_MEM_SUPPORTED && PNG_DEBUG */
0N/A/* END of code to test memory allocation/deallocation */
0N/A
4418N/A
4418N/A/* Demonstration of user chunk support of the sTER and vpAg chunks */
4418N/A#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
4418N/A
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
4418N/Astatic png_uint_32 user_chunk_data[4];
4418N/A
4418N/A /* 0: sTER mode + 1
4418N/A * 1: vpAg width
4418N/A * 2: vpAg height
4418N/A * 3: vpAg units
4418N/A */
4418N/A
4418N/Astatic int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr,
4418N/A png_unknown_chunkp chunk)
4418N/A{
4418N/A png_uint_32
4418N/A *my_user_chunk_data;
4418N/A
4418N/A /* Return one of the following:
4418N/A * return (-n); chunk had an error
4418N/A * return (0); did not recognize
4418N/A * return (n); success
4418N/A *
4418N/A * The unknown chunk structure contains the chunk data:
4418N/A * png_byte name[5];
4418N/A * png_byte *data;
4418N/A * png_size_t size;
4418N/A *
4418N/A * Note that libpng has already taken care of the CRC handling.
4418N/A */
4418N/A
4418N/A if (chunk->name[0] == 115 && chunk->name[1] == 84 && /* s T */
4418N/A chunk->name[2] == 69 && chunk->name[3] == 82) /* E R */
4418N/A {
4418N/A /* Found sTER chunk */
4418N/A if (chunk->size != 1)
4418N/A return (-1); /* Error return */
4418N/A
4418N/A if (chunk->data[0] != 0 && chunk->data[0] != 1)
4418N/A return (-1); /* Invalid mode */
4418N/A
4418N/A my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr);
4418N/A my_user_chunk_data[0]=chunk->data[0]+1;
4418N/A return (1);
4418N/A }
4418N/A
4418N/A if (chunk->name[0] != 118 || chunk->name[1] != 112 || /* v p */
4418N/A chunk->name[2] != 65 || chunk->name[3] != 103) /* A g */
4418N/A return (0); /* Did not recognize */
4418N/A
4418N/A /* Found ImageMagick vpAg chunk */
4418N/A
4418N/A if (chunk->size != 9)
4418N/A return (-1); /* Error return */
4418N/A
4418N/A my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr);
4418N/A
4418N/A my_user_chunk_data[1]=png_get_uint_31(png_ptr, chunk->data);
4418N/A my_user_chunk_data[2]=png_get_uint_31(png_ptr, chunk->data + 4);
4418N/A my_user_chunk_data[3]=(png_uint_32)chunk->data[8];
4418N/A
4418N/A return (1);
4418N/A
4418N/A}
4418N/A#endif
4418N/A/* END of code to demonstrate user chunk support */
4418N/A
0N/A/* Test one file */
0N/Aint
0N/Atest_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
0N/A{
0N/A static png_FILE_p fpin;
0N/A static png_FILE_p fpout; /* "static" prevents setjmp corruption */
0N/A png_structp read_ptr;
0N/A png_infop read_info_ptr, end_info_ptr;
0N/A#ifdef PNG_WRITE_SUPPORTED
0N/A png_structp write_ptr;
0N/A png_infop write_info_ptr;
0N/A png_infop write_end_info_ptr;
0N/A#else
0N/A png_structp write_ptr = NULL;
0N/A png_infop write_info_ptr = NULL;
0N/A png_infop write_end_info_ptr = NULL;
0N/A#endif
0N/A png_bytep row_buf;
0N/A png_uint_32 y;
0N/A png_uint_32 width, height;
0N/A int num_pass, pass;
0N/A int bit_depth, color_type;
0N/A#ifdef PNG_SETJMP_SUPPORTED
0N/A#ifdef USE_FAR_KEYWORD
4418N/A jmp_buf tmp_jmpbuf;
0N/A#endif
0N/A#endif
0N/A
0N/A char inbuf[256], outbuf[256];
0N/A
0N/A row_buf = NULL;
0N/A
0N/A if ((fpin = fopen(inname, "rb")) == NULL)
0N/A {
0N/A fprintf(STDERR, "Could not find input file %s\n", inname);
0N/A return (1);
0N/A }
0N/A
0N/A if ((fpout = fopen(outname, "wb")) == NULL)
0N/A {
0N/A fprintf(STDERR, "Could not open output file %s\n", outname);
0N/A FCLOSE(fpin);
0N/A return (1);
0N/A }
0N/A
4418N/A pngtest_debug("Allocating read and write structures");
0N/A#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
4418N/A read_ptr =
4418N/A png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL,
4418N/A NULL, NULL, NULL, png_debug_malloc, png_debug_free);
0N/A#else
4418N/A read_ptr =
4418N/A png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
0N/A#endif
4418N/A#ifndef PNG_STDIO_SUPPORTED
0N/A png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error,
0N/A pngtest_warning);
0N/A#endif
4418N/A
4418N/A#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
4418N/A user_chunk_data[0] = 0;
4418N/A user_chunk_data[1] = 0;
4418N/A user_chunk_data[2] = 0;
4418N/A user_chunk_data[3] = 0;
4418N/A png_set_read_user_chunk_fn(read_ptr, user_chunk_data,
4418N/A read_user_chunk_callback);
4418N/A
4418N/A#endif
0N/A#ifdef PNG_WRITE_SUPPORTED
0N/A#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
4418N/A write_ptr =
4418N/A png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL,
4418N/A NULL, NULL, NULL, png_debug_malloc, png_debug_free);
0N/A#else
4418N/A write_ptr =
4418N/A png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
0N/A#endif
4418N/A#ifndef PNG_STDIO_SUPPORTED
0N/A png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error,
0N/A pngtest_warning);
0N/A#endif
0N/A#endif
4418N/A pngtest_debug("Allocating read_info, write_info and end_info structures");
0N/A read_info_ptr = png_create_info_struct(read_ptr);
0N/A end_info_ptr = png_create_info_struct(read_ptr);
0N/A#ifdef PNG_WRITE_SUPPORTED
0N/A write_info_ptr = png_create_info_struct(write_ptr);
0N/A write_end_info_ptr = png_create_info_struct(write_ptr);
0N/A#endif
0N/A
0N/A#ifdef PNG_SETJMP_SUPPORTED
4418N/A pngtest_debug("Setting jmpbuf for read struct");
0N/A#ifdef USE_FAR_KEYWORD
4418N/A if (setjmp(tmp_jmpbuf))
0N/A#else
0N/A if (setjmp(png_jmpbuf(read_ptr)))
0N/A#endif
0N/A {
0N/A fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
4418N/A png_free(read_ptr, row_buf);
4418N/A row_buf = NULL;
0N/A png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
0N/A#ifdef PNG_WRITE_SUPPORTED
0N/A png_destroy_info_struct(write_ptr, &write_end_info_ptr);
0N/A png_destroy_write_struct(&write_ptr, &write_info_ptr);
0N/A#endif
0N/A FCLOSE(fpin);
0N/A FCLOSE(fpout);
0N/A return (1);
0N/A }
0N/A#ifdef USE_FAR_KEYWORD
4418N/A png_memcpy(png_jmpbuf(read_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));
0N/A#endif
0N/A
0N/A#ifdef PNG_WRITE_SUPPORTED
4418N/A pngtest_debug("Setting jmpbuf for write struct");
0N/A#ifdef USE_FAR_KEYWORD
4418N/A
4418N/A if (setjmp(tmp_jmpbuf))
0N/A#else
0N/A if (setjmp(png_jmpbuf(write_ptr)))
0N/A#endif
0N/A {
0N/A fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname);
0N/A png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
0N/A png_destroy_info_struct(write_ptr, &write_end_info_ptr);
0N/A#ifdef PNG_WRITE_SUPPORTED
0N/A png_destroy_write_struct(&write_ptr, &write_info_ptr);
0N/A#endif
0N/A FCLOSE(fpin);
0N/A FCLOSE(fpout);
0N/A return (1);
0N/A }
4418N/A
0N/A#ifdef USE_FAR_KEYWORD
4418N/A png_memcpy(png_jmpbuf(write_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));
0N/A#endif
0N/A#endif
0N/A#endif
0N/A
4418N/A pngtest_debug("Initializing input and output streams");
4418N/A#ifdef PNG_STDIO_SUPPORTED
0N/A png_init_io(read_ptr, fpin);
0N/A# ifdef PNG_WRITE_SUPPORTED
0N/A png_init_io(write_ptr, fpout);
0N/A# endif
0N/A#else
0N/A png_set_read_fn(read_ptr, (png_voidp)fpin, pngtest_read_data);
0N/A# ifdef PNG_WRITE_SUPPORTED
0N/A png_set_write_fn(write_ptr, (png_voidp)fpout, pngtest_write_data,
4418N/A# ifdef PNG_WRITE_FLUSH_SUPPORTED
0N/A pngtest_flush);
0N/A# else
0N/A NULL);
0N/A# endif
0N/A# endif
0N/A#endif
4418N/A
4418N/A#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
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.
4418N/A */
4418N/A png_set_text_compression_strategy(write_ptr, Z_FILTERED);
4418N/A#endif
4418N/A
4418N/A if (status_dots_requested == 1)
0N/A {
0N/A#ifdef PNG_WRITE_SUPPORTED
0N/A png_set_write_status_fn(write_ptr, write_row_callback);
0N/A#endif
0N/A png_set_read_status_fn(read_ptr, read_row_callback);
0N/A }
4418N/A
0N/A else
0N/A {
0N/A#ifdef PNG_WRITE_SUPPORTED
4418N/A png_set_write_status_fn(write_ptr, NULL);
0N/A#endif
4418N/A png_set_read_status_fn(read_ptr, NULL);
0N/A }
0N/A
4418N/A#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
0N/A {
4418N/A int i;
4418N/A
4418N/A for (i = 0; i<256; i++)
4418N/A filters_used[i] = 0;
4418N/A
4418N/A png_set_read_user_transform_fn(read_ptr, count_filters);
0N/A }
0N/A#endif
4418N/A#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
4418N/A zero_samples = 0;
0N/A png_set_write_user_transform_fn(write_ptr, count_zero_samples);
0N/A#endif
0N/A
4418N/A#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
0N/A# ifndef PNG_HANDLE_CHUNK_ALWAYS
0N/A# define PNG_HANDLE_CHUNK_ALWAYS 3
0N/A# endif
0N/A png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS,
4418N/A NULL, 0);
0N/A#endif
4418N/A#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
0N/A# ifndef PNG_HANDLE_CHUNK_IF_SAFE
0N/A# define PNG_HANDLE_CHUNK_IF_SAFE 2
0N/A# endif
0N/A png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_IF_SAFE,
4418N/A NULL, 0);
0N/A#endif
0N/A
4418N/A pngtest_debug("Reading info struct");
0N/A png_read_info(read_ptr, read_info_ptr);
0N/A
4418N/A pngtest_debug("Transferring info struct");
0N/A {
0N/A int interlace_type, compression_type, filter_type;
0N/A
0N/A if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth,
0N/A &color_type, &interlace_type, &compression_type, &filter_type))
0N/A {
0N/A png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
4418N/A#ifdef PNG_WRITE_INTERLACING_SUPPORTED
0N/A color_type, interlace_type, compression_type, filter_type);
0N/A#else
0N/A color_type, PNG_INTERLACE_NONE, compression_type, filter_type);
0N/A#endif
0N/A }
0N/A }
4418N/A#ifdef PNG_FIXED_POINT_SUPPORTED
4418N/A#ifdef PNG_cHRM_SUPPORTED
0N/A {
0N/A png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
0N/A blue_y;
4418N/A
4418N/A if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y,
4418N/A &red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y))
0N/A {
0N/A png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x,
0N/A red_y, green_x, green_y, blue_x, blue_y);
0N/A }
0N/A }
0N/A#endif
4418N/A#ifdef PNG_gAMA_SUPPORTED
0N/A {
0N/A png_fixed_point gamma;
0N/A
0N/A if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma))
0N/A png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma);
0N/A }
0N/A#endif
0N/A#else /* Use floating point versions */
4418N/A#ifdef PNG_FLOATING_POINT_SUPPORTED
4418N/A#ifdef PNG_cHRM_SUPPORTED
0N/A {
0N/A double white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
0N/A blue_y;
4418N/A
0N/A if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
0N/A &red_y, &green_x, &green_y, &blue_x, &blue_y))
0N/A {
0N/A png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x,
0N/A red_y, green_x, green_y, blue_x, blue_y);
0N/A }
0N/A }
0N/A#endif
4418N/A#ifdef PNG_gAMA_SUPPORTED
0N/A {
0N/A double gamma;
0N/A
0N/A if (png_get_gAMA(read_ptr, read_info_ptr, &gamma))
0N/A png_set_gAMA(write_ptr, write_info_ptr, gamma);
0N/A }
0N/A#endif
4418N/A#endif /* Floating point */
4418N/A#endif /* Fixed point */
4418N/A#ifdef PNG_iCCP_SUPPORTED
0N/A {
0N/A png_charp name;
4418N/A png_bytep profile;
0N/A png_uint_32 proflen;
0N/A int compression_type;
0N/A
0N/A if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type,
0N/A &profile, &proflen))
0N/A {
0N/A png_set_iCCP(write_ptr, write_info_ptr, name, compression_type,
0N/A profile, proflen);
0N/A }
0N/A }
0N/A#endif
4418N/A#ifdef PNG_sRGB_SUPPORTED
0N/A {
0N/A int intent;
0N/A
0N/A if (png_get_sRGB(read_ptr, read_info_ptr, &intent))
0N/A png_set_sRGB(write_ptr, write_info_ptr, intent);
0N/A }
0N/A#endif
0N/A {
0N/A png_colorp palette;
0N/A int num_palette;
0N/A
0N/A if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette))
0N/A png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette);
0N/A }
4418N/A#ifdef PNG_bKGD_SUPPORTED
0N/A {
0N/A png_color_16p background;
0N/A
0N/A if (png_get_bKGD(read_ptr, read_info_ptr, &background))
0N/A {
0N/A png_set_bKGD(write_ptr, write_info_ptr, background);
0N/A }
0N/A }
0N/A#endif
4418N/A#ifdef PNG_hIST_SUPPORTED
0N/A {
0N/A png_uint_16p hist;
0N/A
0N/A if (png_get_hIST(read_ptr, read_info_ptr, &hist))
0N/A png_set_hIST(write_ptr, write_info_ptr, hist);
0N/A }
0N/A#endif
4418N/A#ifdef PNG_oFFs_SUPPORTED
0N/A {
0N/A png_int_32 offset_x, offset_y;
0N/A int unit_type;
0N/A
4418N/A if (png_get_oFFs(read_ptr, read_info_ptr, &offset_x, &offset_y,
4418N/A &unit_type))
0N/A {
0N/A png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type);
0N/A }
0N/A }
0N/A#endif
4418N/A#ifdef PNG_pCAL_SUPPORTED
0N/A {
0N/A png_charp purpose, units;
0N/A png_charpp params;
0N/A png_int_32 X0, X1;
0N/A int type, nparams;
0N/A
0N/A if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type,
0N/A &nparams, &units, &params))
0N/A {
0N/A png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type,
0N/A nparams, units, params);
0N/A }
0N/A }
0N/A#endif
4418N/A#ifdef PNG_pHYs_SUPPORTED
0N/A {
0N/A png_uint_32 res_x, res_y;
0N/A int unit_type;
0N/A
0N/A if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type))
0N/A png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type);
0N/A }
0N/A#endif
4418N/A#ifdef PNG_sBIT_SUPPORTED
0N/A {
0N/A png_color_8p sig_bit;
0N/A
0N/A if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit))
0N/A png_set_sBIT(write_ptr, write_info_ptr, sig_bit);
0N/A }
0N/A#endif
4418N/A#ifdef PNG_sCAL_SUPPORTED
0N/A#ifdef PNG_FLOATING_POINT_SUPPORTED
0N/A {
0N/A int unit;
0N/A double scal_width, scal_height;
0N/A
0N/A if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width,
0N/A &scal_height))
0N/A {
0N/A png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height);
0N/A }
0N/A }
0N/A#else
0N/A#ifdef PNG_FIXED_POINT_SUPPORTED
0N/A {
0N/A int unit;
0N/A png_charp scal_width, scal_height;
0N/A
0N/A if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width,
0N/A &scal_height))
0N/A {
4418N/A png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width,
4418N/A scal_height);
0N/A }
0N/A }
0N/A#endif
0N/A#endif
0N/A#endif
4418N/A#ifdef PNG_TEXT_SUPPORTED
0N/A {
0N/A png_textp text_ptr;
0N/A int num_text;
0N/A
0N/A if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0)
0N/A {
4418N/A pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);
0N/A png_set_text(write_ptr, write_info_ptr, text_ptr, num_text);
0N/A }
0N/A }
0N/A#endif
4418N/A#ifdef PNG_tIME_SUPPORTED
0N/A {
0N/A png_timep mod_time;
0N/A
0N/A if (png_get_tIME(read_ptr, read_info_ptr, &mod_time))
0N/A {
0N/A png_set_tIME(write_ptr, write_info_ptr, mod_time);
4418N/A#ifdef PNG_TIME_RFC1123_SUPPORTED
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
4418N/A * we use it.
4418N/A */
4418N/A png_memcpy(tIME_string,
4418N/A png_convert_to_rfc1123(read_ptr, mod_time),
4418N/A png_sizeof(tIME_string));
4418N/A
4418N/A tIME_string[png_sizeof(tIME_string) - 1] = '\0';
0N/A tIME_chunk_present++;
0N/A#endif /* PNG_TIME_RFC1123_SUPPORTED */
0N/A }
0N/A }
0N/A#endif
4418N/A#ifdef PNG_tRNS_SUPPORTED
0N/A {
4418N/A png_bytep trans_alpha;
0N/A int num_trans;
4418N/A png_color_16p trans_color;
0N/A
4418N/A if (png_get_tRNS(read_ptr, read_info_ptr, &trans_alpha, &num_trans,
4418N/A &trans_color))
0N/A {
4418N/A int sample_max = (1 << bit_depth);
4418N/A /* libpng doesn't reject a tRNS chunk with out-of-range samples */
4418N/A if (!((color_type == PNG_COLOR_TYPE_GRAY &&
4418N/A (int)trans_color->gray > sample_max) ||
4418N/A (color_type == PNG_COLOR_TYPE_RGB &&
4418N/A ((int)trans_color->red > sample_max ||
4418N/A (int)trans_color->green > sample_max ||
4418N/A (int)trans_color->blue > sample_max))))
4418N/A png_set_tRNS(write_ptr, write_info_ptr, trans_alpha, num_trans,
4418N/A trans_color);
0N/A }
0N/A }
0N/A#endif
4418N/A#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
0N/A {
0N/A png_unknown_chunkp unknowns;
4418N/A int num_unknowns = png_get_unknown_chunks(read_ptr, read_info_ptr,
0N/A &unknowns);
4418N/A
0N/A if (num_unknowns)
0N/A {
4418N/A int i;
0N/A png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns,
0N/A num_unknowns);
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.
4418N/A */
4418N/A for (i = 0; i < num_unknowns; i++)
0N/A png_set_unknown_chunk_location(write_ptr, write_info_ptr, i,
0N/A unknowns[i].location);
0N/A }
0N/A }
0N/A#endif
0N/A
0N/A#ifdef PNG_WRITE_SUPPORTED
4418N/A pngtest_debug("Writing info struct");
0N/A
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 */
0N/A png_write_info(write_ptr, write_info_ptr);
4418N/A
4418N/A#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
4418N/A if (user_chunk_data[0] != 0)
4418N/A {
4418N/A png_byte png_sTER[5] = {115, 84, 69, 82, '\0'};
4418N/A
4418N/A unsigned char
4418N/A ster_chunk_data[1];
4418N/A
4418N/A if (verbose)
4418N/A fprintf(STDERR, "\n stereo mode = %lu\n",
4418N/A (unsigned long)(user_chunk_data[0] - 1));
4418N/A
4418N/A ster_chunk_data[0]=(unsigned char)(user_chunk_data[0] - 1);
4418N/A png_write_chunk(write_ptr, png_sTER, ster_chunk_data, 1);
4418N/A }
4418N/A
4418N/A if (user_chunk_data[1] != 0 || user_chunk_data[2] != 0)
4418N/A {
4418N/A png_byte png_vpAg[5] = {118, 112, 65, 103, '\0'};
4418N/A
4418N/A unsigned char
4418N/A vpag_chunk_data[9];
4418N/A
4418N/A if (verbose)
4418N/A fprintf(STDERR, " vpAg = %lu x %lu, units = %lu\n",
4418N/A (unsigned long)user_chunk_data[1],
4418N/A (unsigned long)user_chunk_data[2],
4418N/A (unsigned long)user_chunk_data[3]);
4418N/A
4418N/A png_save_uint_32(vpag_chunk_data, user_chunk_data[1]);
4418N/A png_save_uint_32(vpag_chunk_data + 4, user_chunk_data[2]);
4418N/A vpag_chunk_data[8] = (unsigned char)(user_chunk_data[3] & 0xff);
4418N/A png_write_chunk(write_ptr, png_vpAg, vpag_chunk_data, 9);
4418N/A }
4418N/A
4418N/A#endif
0N/A#endif
0N/A
0N/A#ifdef SINGLE_ROWBUF_ALLOC
4418N/A pngtest_debug("Allocating row buffer...");
0N/A row_buf = (png_bytep)png_malloc(read_ptr,
0N/A png_get_rowbytes(read_ptr, read_info_ptr));
4418N/A
4418N/A pngtest_debug1("\t0x%08lx", (unsigned long)row_buf);
0N/A#endif /* SINGLE_ROWBUF_ALLOC */
4418N/A pngtest_debug("Writing row data");
0N/A
0N/A#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
0N/A defined(PNG_WRITE_INTERLACING_SUPPORTED)
0N/A num_pass = png_set_interlace_handling(read_ptr);
0N/A# ifdef PNG_WRITE_SUPPORTED
0N/A png_set_interlace_handling(write_ptr);
0N/A# endif
0N/A#else
4418N/A num_pass = 1;
0N/A#endif
0N/A
0N/A#ifdef PNGTEST_TIMING
0N/A t_stop = (float)clock();
0N/A t_misc += (t_stop - t_start);
0N/A t_start = t_stop;
0N/A#endif
0N/A for (pass = 0; pass < num_pass; pass++)
0N/A {
4418N/A pngtest_debug1("Writing row data for pass %d", pass);
0N/A for (y = 0; y < height; y++)
0N/A {
0N/A#ifndef SINGLE_ROWBUF_ALLOC
4418N/A pngtest_debug2("Allocating row buffer (pass %d, y = %u)...", pass, y);
0N/A row_buf = (png_bytep)png_malloc(read_ptr,
0N/A png_get_rowbytes(read_ptr, read_info_ptr));
4418N/A
4418N/A pngtest_debug2("\t0x%08lx (%u bytes)", (unsigned long)row_buf,
0N/A png_get_rowbytes(read_ptr, read_info_ptr));
4418N/A
0N/A#endif /* !SINGLE_ROWBUF_ALLOC */
4418N/A png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1);
0N/A
0N/A#ifdef PNG_WRITE_SUPPORTED
0N/A#ifdef PNGTEST_TIMING
0N/A t_stop = (float)clock();
0N/A t_decode += (t_stop - t_start);
0N/A t_start = t_stop;
0N/A#endif
0N/A png_write_rows(write_ptr, (png_bytepp)&row_buf, 1);
0N/A#ifdef PNGTEST_TIMING
0N/A t_stop = (float)clock();
0N/A t_encode += (t_stop - t_start);
0N/A t_start = t_stop;
0N/A#endif
0N/A#endif /* PNG_WRITE_SUPPORTED */
0N/A
0N/A#ifndef SINGLE_ROWBUF_ALLOC
4418N/A pngtest_debug2("Freeing row buffer (pass %d, y = %u)", pass, y);
0N/A png_free(read_ptr, row_buf);
4418N/A row_buf = NULL;
0N/A#endif /* !SINGLE_ROWBUF_ALLOC */
0N/A }
0N/A }
0N/A
4418N/A#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
0N/A png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1);
0N/A#endif
4418N/A#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
0N/A png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);
0N/A#endif
0N/A
4418N/A pngtest_debug("Reading and writing end_info data");
0N/A
0N/A png_read_end(read_ptr, end_info_ptr);
4418N/A#ifdef PNG_TEXT_SUPPORTED
0N/A {
0N/A png_textp text_ptr;
0N/A int num_text;
0N/A
0N/A if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0)
0N/A {
4418N/A pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);
0N/A png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text);
0N/A }
0N/A }
0N/A#endif
4418N/A#ifdef PNG_tIME_SUPPORTED
0N/A {
0N/A png_timep mod_time;
0N/A
0N/A if (png_get_tIME(read_ptr, end_info_ptr, &mod_time))
0N/A {
0N/A png_set_tIME(write_ptr, write_end_info_ptr, mod_time);
4418N/A#ifdef PNG_TIME_RFC1123_SUPPORTED
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 we use it */
4418N/A png_memcpy(tIME_string,
4418N/A png_convert_to_rfc1123(read_ptr, mod_time),
4418N/A png_sizeof(tIME_string));
4418N/A
4418N/A tIME_string[png_sizeof(tIME_string) - 1] = '\0';
0N/A tIME_chunk_present++;
0N/A#endif /* PNG_TIME_RFC1123_SUPPORTED */
0N/A }
0N/A }
0N/A#endif
4418N/A#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
0N/A {
0N/A png_unknown_chunkp unknowns;
4418N/A int num_unknowns = png_get_unknown_chunks(read_ptr, end_info_ptr,
0N/A &unknowns);
4418N/A
0N/A if (num_unknowns)
0N/A {
4418N/A int i;
0N/A png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns,
0N/A num_unknowns);
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.
4418N/A */
4418N/A for (i = 0; i < num_unknowns; i++)
0N/A png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i,
0N/A unknowns[i].location);
0N/A }
0N/A }
0N/A#endif
0N/A#ifdef PNG_WRITE_SUPPORTED
0N/A png_write_end(write_ptr, write_end_info_ptr);
0N/A#endif
0N/A
0N/A#ifdef PNG_EASY_ACCESS_SUPPORTED
4418N/A if (verbose)
0N/A {
0N/A png_uint_32 iwidth, iheight;
0N/A iwidth = png_get_image_width(write_ptr, write_info_ptr);
0N/A iheight = png_get_image_height(write_ptr, write_info_ptr);
4418N/A fprintf(STDERR, "\n Image width = %lu, height = %lu\n",
0N/A (unsigned long)iwidth, (unsigned long)iheight);
0N/A }
0N/A#endif
0N/A
4418N/A pngtest_debug("Destroying data structs");
0N/A#ifdef SINGLE_ROWBUF_ALLOC
4418N/A pngtest_debug("destroying row_buf for read_ptr");
0N/A png_free(read_ptr, row_buf);
4418N/A row_buf = NULL;
0N/A#endif /* SINGLE_ROWBUF_ALLOC */
4418N/A pngtest_debug("destroying read_ptr, read_info_ptr, end_info_ptr");
0N/A png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
0N/A#ifdef PNG_WRITE_SUPPORTED
4418N/A pngtest_debug("destroying write_end_info_ptr");
0N/A png_destroy_info_struct(write_ptr, &write_end_info_ptr);
4418N/A pngtest_debug("destroying write_ptr, write_info_ptr");
0N/A png_destroy_write_struct(&write_ptr, &write_info_ptr);
0N/A#endif
4418N/A pngtest_debug("Destruction complete.");
0N/A
0N/A FCLOSE(fpin);
0N/A FCLOSE(fpout);
0N/A
4418N/A pngtest_debug("Opening files for comparison");
0N/A if ((fpin = fopen(inname, "rb")) == NULL)
0N/A {
0N/A fprintf(STDERR, "Could not find file %s\n", inname);
0N/A return (1);
0N/A }
0N/A
0N/A if ((fpout = fopen(outname, "rb")) == NULL)
0N/A {
0N/A fprintf(STDERR, "Could not find file %s\n", outname);
0N/A FCLOSE(fpin);
0N/A return (1);
0N/A }
0N/A
4418N/A for (;;)
0N/A {
0N/A png_size_t num_in, num_out;
0N/A
4418N/A num_in = fread(inbuf, 1, 1, fpin);
4418N/A num_out = fread(outbuf, 1, 1, fpout);
0N/A
0N/A if (num_in != num_out)
0N/A {
0N/A fprintf(STDERR, "\nFiles %s and %s are of a different size\n",
0N/A inname, outname);
4418N/A
4418N/A if (wrote_question == 0)
0N/A {
0N/A fprintf(STDERR,
0N/A " Was %s written with the same maximum IDAT chunk size (%d bytes),",
4418N/A inname, PNG_ZBUF_SIZE);
0N/A fprintf(STDERR,
0N/A "\n filtering heuristic (libpng default), compression");
0N/A fprintf(STDERR,
0N/A " level (zlib default),\n and zlib version (%s)?\n\n",
0N/A ZLIB_VERSION);
4418N/A wrote_question = 1;
0N/A }
4418N/A
0N/A FCLOSE(fpin);
0N/A FCLOSE(fpout);
0N/A return (0);
0N/A }
0N/A
0N/A if (!num_in)
0N/A break;
0N/A
0N/A if (png_memcmp(inbuf, outbuf, num_in))
0N/A {
0N/A fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname);
4418N/A
4418N/A if (wrote_question == 0)
0N/A {
0N/A fprintf(STDERR,
0N/A " Was %s written with the same maximum IDAT chunk size (%d bytes),",
4418N/A inname, PNG_ZBUF_SIZE);
0N/A fprintf(STDERR,
0N/A "\n filtering heuristic (libpng default), compression");
0N/A fprintf(STDERR,
0N/A " level (zlib default),\n and zlib version (%s)?\n\n",
0N/A ZLIB_VERSION);
4418N/A wrote_question = 1;
0N/A }
4418N/A
0N/A FCLOSE(fpin);
0N/A FCLOSE(fpout);
0N/A return (0);
0N/A }
0N/A }
0N/A
0N/A FCLOSE(fpin);
0N/A FCLOSE(fpout);
0N/A
0N/A return (0);
0N/A}
0N/A
4418N/A/* Input and output filenames */
0N/A#ifdef RISCOS
0N/Astatic PNG_CONST char *inname = "pngtest/png";
0N/Astatic PNG_CONST char *outname = "pngout/png";
0N/A#else
0N/Astatic PNG_CONST char *inname = "pngtest.png";
0N/Astatic PNG_CONST char *outname = "pngout.png";
0N/A#endif
0N/A
0N/Aint
0N/Amain(int argc, char *argv[])
0N/A{
0N/A int multiple = 0;
0N/A int ierror = 0;
0N/A
4418N/A fprintf(STDERR, "\n Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
0N/A fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION);
4418N/A fprintf(STDERR, "%s", png_get_copyright(NULL));
0N/A /* Show the version of libpng used in building the library */
4418N/A fprintf(STDERR, " library (%lu):%s",
0N/A (unsigned long)png_access_version_number(),
0N/A png_get_header_version(NULL));
4418N/A
0N/A /* Show the version of libpng used in building the application */
4418N/A fprintf(STDERR, " pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER,
0N/A PNG_HEADER_VERSION_STRING);
0N/A
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
4418N/A * in pngconf.h
4418N/A */
0N/A#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
0N/A fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n");
0N/A#endif
0N/A /* I think the following can happen. */
0N/A#if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K)
0N/A fprintf(STDERR, " NOTE: libpng compiled for max 64k, zlib not\n");
0N/A#endif
0N/A
0N/A if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING))
0N/A {
0N/A fprintf(STDERR,
0N/A "Warning: versions are different between png.h and png.c\n");
0N/A fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING);
0N/A fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver);
0N/A ++ierror;
0N/A }
0N/A
0N/A if (argc > 1)
0N/A {
0N/A if (strcmp(argv[1], "-m") == 0)
0N/A {
0N/A multiple = 1;
0N/A status_dots_requested = 0;
0N/A }
4418N/A
0N/A else if (strcmp(argv[1], "-mv") == 0 ||
0N/A strcmp(argv[1], "-vm") == 0 )
0N/A {
0N/A multiple = 1;
0N/A verbose = 1;
0N/A status_dots_requested = 1;
0N/A }
4418N/A
0N/A else if (strcmp(argv[1], "-v") == 0)
0N/A {
0N/A verbose = 1;
0N/A status_dots_requested = 1;
0N/A inname = argv[2];
0N/A }
4418N/A
0N/A else
0N/A {
0N/A inname = argv[1];
0N/A status_dots_requested = 0;
0N/A }
0N/A }
0N/A
4418N/A if (!multiple && argc == 3 + verbose)
4418N/A outname = argv[2 + verbose];
0N/A
4418N/A if ((!multiple && argc > 3 + verbose) || (multiple && argc < 2))
0N/A {
0N/A fprintf(STDERR,
0N/A "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
0N/A argv[0], argv[0]);
0N/A fprintf(STDERR,
0N/A " reads/writes one PNG file (without -m) or multiple files (-m)\n");
0N/A fprintf(STDERR,
0N/A " with -m %s is used as a temporary file\n", outname);
0N/A exit(1);
0N/A }
0N/A
0N/A if (multiple)
0N/A {
0N/A int i;
0N/A#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
0N/A int allocation_now = current_allocation;
0N/A#endif
0N/A for (i=2; i<argc; ++i)
0N/A {
0N/A int kerror;
4418N/A fprintf(STDERR, "\n Testing %s:", argv[i]);
0N/A kerror = test_one_file(argv[i], outname);
0N/A if (kerror == 0)
0N/A {
4418N/A#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
4418N/A int k;
4418N/A#endif
4418N/A#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
0N/A fprintf(STDERR, "\n PASS (%lu zero samples)\n",
0N/A (unsigned long)zero_samples);
0N/A#else
0N/A fprintf(STDERR, " PASS\n");
0N/A#endif
4418N/A#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
4418N/A for (k = 0; k<256; k++)
4418N/A if (filters_used[k])
0N/A fprintf(STDERR, " Filter %d was used %lu times\n",
4418N/A k, (unsigned long)filters_used[k]);
0N/A#endif
4418N/A#ifdef PNG_TIME_RFC1123_SUPPORTED
4418N/A if (tIME_chunk_present != 0)
4418N/A fprintf(STDERR, " tIME = %s\n", tIME_string);
4418N/A
0N/A tIME_chunk_present = 0;
0N/A#endif /* PNG_TIME_RFC1123_SUPPORTED */
0N/A }
4418N/A
0N/A else
0N/A {
0N/A fprintf(STDERR, " FAIL\n");
0N/A ierror += kerror;
0N/A }
0N/A#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
0N/A if (allocation_now != current_allocation)
0N/A fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
4418N/A current_allocation - allocation_now);
4418N/A
0N/A if (current_allocation != 0)
0N/A {
0N/A memory_infop pinfo = pinformation;
0N/A
0N/A fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
0N/A current_allocation);
4418N/A
0N/A while (pinfo != NULL)
0N/A {
4418N/A fprintf(STDERR, " %lu bytes at %x\n",
4418N/A (unsigned long)pinfo->size,
4418N/A (unsigned int)pinfo->pointer);
0N/A pinfo = pinfo->next;
0N/A }
0N/A }
0N/A#endif
0N/A }
0N/A#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
0N/A fprintf(STDERR, " Current memory allocation: %10d bytes\n",
0N/A current_allocation);
0N/A fprintf(STDERR, " Maximum memory allocation: %10d bytes\n",
0N/A maximum_allocation);
0N/A fprintf(STDERR, " Total memory allocation: %10d bytes\n",
0N/A total_allocation);
0N/A fprintf(STDERR, " Number of allocations: %10d\n",
0N/A num_allocations);
0N/A#endif
0N/A }
4418N/A
0N/A else
0N/A {
0N/A int i;
4418N/A for (i = 0; i<3; ++i)
0N/A {
0N/A int kerror;
0N/A#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
0N/A int allocation_now = current_allocation;
0N/A#endif
4418N/A if (i == 1)
4418N/A status_dots_requested = 1;
4418N/A
4418N/A else if (verbose == 0)
4418N/A status_dots_requested = 0;
4418N/A
0N/A if (i == 0 || verbose == 1 || ierror != 0)
4418N/A fprintf(STDERR, "\n Testing %s:", inname);
4418N/A
0N/A kerror = test_one_file(inname, outname);
4418N/A
4418N/A if (kerror == 0)
0N/A {
4418N/A if (verbose == 1 || i == 2)
0N/A {
4418N/A#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
0N/A int k;
0N/A#endif
4418N/A#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
0N/A fprintf(STDERR, "\n PASS (%lu zero samples)\n",
0N/A (unsigned long)zero_samples);
0N/A#else
0N/A fprintf(STDERR, " PASS\n");
0N/A#endif
4418N/A#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
4418N/A for (k = 0; k<256; k++)
4418N/A if (filters_used[k])
0N/A fprintf(STDERR, " Filter %d was used %lu times\n",
4418N/A k, (unsigned long)filters_used[k]);
0N/A#endif
4418N/A#ifdef PNG_TIME_RFC1123_SUPPORTED
4418N/A if (tIME_chunk_present != 0)
4418N/A fprintf(STDERR, " tIME = %s\n", tIME_string);
0N/A#endif /* PNG_TIME_RFC1123_SUPPORTED */
0N/A }
0N/A }
4418N/A
0N/A else
0N/A {
4418N/A if (verbose == 0 && i != 2)
4418N/A fprintf(STDERR, "\n Testing %s:", inname);
4418N/A
0N/A fprintf(STDERR, " FAIL\n");
0N/A ierror += kerror;
0N/A }
0N/A#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
0N/A if (allocation_now != current_allocation)
0N/A fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
4418N/A current_allocation - allocation_now);
4418N/A
0N/A if (current_allocation != 0)
0N/A {
0N/A memory_infop pinfo = pinformation;
0N/A
0N/A fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
0N/A current_allocation);
4418N/A
0N/A while (pinfo != NULL)
0N/A {
4418N/A fprintf(STDERR, " %lu bytes at %x\n",
0N/A (unsigned long)pinfo->size, (unsigned int)pinfo->pointer);
0N/A pinfo = pinfo->next;
0N/A }
0N/A }
0N/A#endif
0N/A }
0N/A#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
0N/A fprintf(STDERR, " Current memory allocation: %10d bytes\n",
0N/A current_allocation);
0N/A fprintf(STDERR, " Maximum memory allocation: %10d bytes\n",
0N/A maximum_allocation);
0N/A fprintf(STDERR, " Total memory allocation: %10d bytes\n",
0N/A total_allocation);
0N/A fprintf(STDERR, " Number of allocations: %10d\n",
0N/A num_allocations);
0N/A#endif
0N/A }
0N/A
0N/A#ifdef PNGTEST_TIMING
0N/A t_stop = (float)clock();
0N/A t_misc += (t_stop - t_start);
0N/A t_start = t_stop;
4418N/A fprintf(STDERR, " CPU time used = %.3f seconds",
0N/A (t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC);
4418N/A fprintf(STDERR, " (decoding %.3f,\n",
0N/A t_decode/(float)CLOCKS_PER_SEC);
4418N/A fprintf(STDERR, " encoding %.3f ,",
0N/A t_encode/(float)CLOCKS_PER_SEC);
4418N/A fprintf(STDERR, " other %.3f seconds)\n\n",
0N/A t_misc/(float)CLOCKS_PER_SEC);
0N/A#endif
0N/A
0N/A if (ierror == 0)
4418N/A fprintf(STDERR, " libpng passes test\n");
4418N/A
0N/A else
4418N/A fprintf(STDERR, " libpng FAILS test\n");
4418N/A
0N/A return (int)(ierror != 0);
0N/A}
0N/A
0N/A/* Generate a compiler error if there is an old png.h in the search path. */
4418N/Atypedef png_libpng_version_1_5_4 Your_png_h_is_not_version_1_5_4;