jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngtest.c
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 10576 jdk/src/share/native/sun/awt/libpng/pngtest.c@db3409425573
child 29913 95258013e132
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/* pngtest.c - a simple test program to test libpng
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * This file is available under and governed by the GNU General Public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * License version 2 only, as published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * However, the following notice accompanied the original version of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * file and, per its terms, should not be removed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    32
 * Last changed in libpng 1.5.4 [July 7, 2011]
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    33
 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    37
 * This code is released under the libpng license.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    38
 * For conditions of distribution and use, see the disclaimer
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    39
 * and license in png.h
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    40
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This program reads in a PNG image, writes it out again, and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * compares the two files.  If the files are identical, this shows that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * the basic chunk handling, filtering, and (de)compression code is working
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * properly.  It does not currently test all of the transforms, although
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * it probably should.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * The program will report "FAIL" in certain legitimate cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * 1) when the compression level or filter selection method is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * 2) when the maximum IDAT size (PNG_ZBUF_SIZE in pngconf.h) is not 8192.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * 3) unknown unsafe-to-copy ancillary chunks or unknown critical chunks
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *    exist in the input file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * 4) others not listed here...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * In these cases, it is best to check with another tool such as "pngcheck"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * to see what the differences between the two files are.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * If a filename is given on the command-line, then this file is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * for the input, rather than the default "pngtest.png".  This allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * testing a wide variety of files easily.  You can also test a number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * of files at once by typing "pngtest -m file1.png file2.png ..."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    62
#define _POSIX_SOURCE 1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    64
#include "zlib.h"
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    65
#include "png.h"
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    66
/* Copied from pngpriv.h but only used in error messages below. */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    67
#ifndef PNG_ZBUF_SIZE
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    68
#  define PNG_ZBUF_SIZE 8192
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    69
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#  include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#  include <stdlib.h>
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    72
#  include <string.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
#  define FCLOSE(file) fclose(file)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    74
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    75
#ifndef PNG_STDIO_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    76
typedef FILE                * png_FILE_p;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    79
/* Makes pngtest verbose so we can find problems. */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
#ifndef PNG_DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
#  define PNG_DEBUG 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    84
#if PNG_DEBUG > 1
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    85
#  define pngtest_debug(m)        ((void)fprintf(stderr, m "\n"))
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    86
#  define pngtest_debug1(m,p1)    ((void)fprintf(stderr, m "\n", p1))
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    87
#  define pngtest_debug2(m,p1,p2) ((void)fprintf(stderr, m "\n", p1, p2))
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    88
#else
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    89
#  define pngtest_debug(m)        ((void)0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    90
#  define pngtest_debug1(m,p1)    ((void)0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    91
#  define pngtest_debug2(m,p1,p2) ((void)0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    92
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    93
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
#if !PNG_DEBUG
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    95
#  define SINGLE_ROWBUF_ALLOC  /* Makes buffer overruns easier to nail */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    98
/* The code uses memcmp and memcpy on large objects (typically row pointers) so
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    99
 * it is necessary to do soemthing special on certain architectures, note that
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   100
 * the actual support for this was effectively removed in 1.4, so only the
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   101
 * memory remains in this program:
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   102
 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   103
#define CVT_PTR(ptr)         (ptr)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   104
#define CVT_PTR_NOCHECK(ptr) (ptr)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   105
#define png_memcmp  memcmp
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   106
#define png_memcpy  memcpy
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   107
#define png_memset  memset
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   108
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
/* Turn on CPU timing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
#define PNGTEST_TIMING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   113
#ifndef PNG_FLOATING_POINT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
#undef PNGTEST_TIMING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
#ifdef PNGTEST_TIMING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
static float t_start, t_stop, t_decode, t_encode, t_misc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
#include <time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   122
#ifdef PNG_TIME_RFC1123_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   123
#define PNG_tIME_STRING_LENGTH 29
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   124
static int tIME_chunk_present = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   125
static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
static int verbose = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
#ifdef __TURBOC__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
#include <mem.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   136
/* Defined so I can write to a file on gui/windowing platforms */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
/*  #define STDERR stderr  */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   138
#define STDERR stdout   /* For DOS */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
#ifndef png_jmpbuf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
#  define png_jmpbuf(png_ptr) png_ptr->jmpbuf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   145
/* Example of using row callbacks to make a simple progress meter */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   146
static int status_pass = 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   147
static int status_dots_requested = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   148
static int status_dots = 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   149
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   150
void PNGCBAPI
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   152
void PNGCBAPI
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   155
   if (png_ptr == NULL || row_number > PNG_UINT_31_MAX)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   156
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   157
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   158
   if (status_pass != pass)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   159
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   160
      fprintf(stdout, "\n Pass %d: ", pass);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   161
      status_pass = pass;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   162
      status_dots = 31;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   163
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   164
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   165
   status_dots--;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   166
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   167
   if (status_dots == 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   168
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   169
      fprintf(stdout, "\n         ");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   170
      status_dots=30;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   171
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   172
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   173
   fprintf(stdout, "r");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   176
void PNGCBAPI
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   178
void PNGCBAPI
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   181
   if (png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   182
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   183
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   184
   fprintf(stdout, "w");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   188
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
/* Example of using user transform callback (we don't transform anything,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   190
 * but merely examine the row filters.  We set this to 256 rather than
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   191
 * 5 in case illegal filter values are present.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   192
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
static png_uint_32 filters_used[256];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   194
void PNGCBAPI
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   196
void PNGCBAPI
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   199
   if (png_ptr != NULL && row_info != NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   200
      ++filters_used[*(data - 1)];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   204
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   205
/* Example of using user transform callback (we don't transform anything,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   206
 * but merely count the zero samples)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   207
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
static png_uint_32 zero_samples;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   211
void PNGCBAPI
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   213
void PNGCBAPI
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
   png_bytep dp = data;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   217
   if (png_ptr == NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   218
      return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   220
   /* Contents of row_info:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    *  png_uint_32 width      width of row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    *  png_uint_32 rowbytes   number of bytes in row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    *  png_byte color_type    color type of pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    *  png_byte bit_depth     bit depth of samples
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    *  png_byte channels      number of channels (1-4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    *  png_byte pixel_depth   bits per pixel (depth*channels)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   229
    /* Counts the number of zero samples (or zero pixels if color_type is 3 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   231
    if (row_info->color_type == 0 || row_info->color_type == 3)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   233
       int pos = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
       png_uint_32 n, nstop;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   235
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   236
       for (n = 0, nstop=row_info->width; n<nstop; n++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
       {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   238
          if (row_info->bit_depth == 1)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
          {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   240
             if (((*dp << pos++ ) & 0x80) == 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   241
                zero_samples++;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   242
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   243
             if (pos == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
             {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                dp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
          }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   249
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   250
          if (row_info->bit_depth == 2)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
          {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   252
             if (((*dp << (pos+=2)) & 0xc0) == 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   253
                zero_samples++;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   254
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   255
             if (pos == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
             {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                dp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
          }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   261
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   262
          if (row_info->bit_depth == 4)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
          {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   264
             if (((*dp << (pos+=4)) & 0xf0) == 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   265
                zero_samples++;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   266
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   267
             if (pos == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
             {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                dp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
          }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   273
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   274
          if (row_info->bit_depth == 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   275
             if (*dp++ == 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   276
                zero_samples++;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   277
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   278
          if (row_info->bit_depth == 16)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
          {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   280
             if ((*dp | *(dp+1)) == 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   281
                zero_samples++;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
             dp+=2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   286
    else /* Other color types */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
       png_uint_32 n, nstop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
       int channel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
       int color_channels = row_info->channels;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   291
       if (row_info->color_type > 3)color_channels--;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   293
       for (n = 0, nstop=row_info->width; n<nstop; n++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
          for (channel = 0; channel < color_channels; channel++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
          {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   297
             if (row_info->bit_depth == 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   298
                if (*dp++ == 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   299
                   zero_samples++;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   300
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   301
             if (row_info->bit_depth == 16)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
             {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   303
                if ((*dp | *(dp+1)) == 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   304
                   zero_samples++;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   305
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                dp+=2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
          }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   309
          if (row_info->color_type > 3)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
          {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
             dp++;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   312
             if (row_info->bit_depth == 16)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   313
                dp++;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
#endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
static int wrote_question = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   322
#ifndef PNG_STDIO_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
/* START of code to validate stdio-free compilation */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   324
/* These copies of the default read/write functions come from pngrio.c and
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   325
 * pngwio.c.  They allow "don't include stdio" testing of the library.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   326
 * This is the function that does the actual reading of data.  If you are
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   327
 * not reading from a standard C stream, you should create a replacement
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   328
 * read_data function and use it at run time with png_set_read_fn(), rather
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   329
 * than changing the library.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   330
 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   331
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   332
#ifdef PNG_IO_STATE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   333
void
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   334
pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   335
   png_uint_32 io_op);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   336
void
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   337
pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   338
   png_uint_32 io_op)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   339
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   340
   png_uint_32 io_state = png_get_io_state(png_ptr);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   341
   int err = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   342
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   343
   /* Check if the current operation (reading / writing) is as expected. */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   344
   if ((io_state & PNG_IO_MASK_OP) != io_op)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   345
      png_error(png_ptr, "Incorrect operation in I/O state");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   346
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   347
   /* Check if the buffer size specific to the current location
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   348
    * (file signature / header / data / crc) is as expected.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   349
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   350
   switch (io_state & PNG_IO_MASK_LOC)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   351
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   352
   case PNG_IO_SIGNATURE:
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   353
      if (data_length > 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   354
         err = 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   355
      break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   356
   case PNG_IO_CHUNK_HDR:
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   357
      if (data_length != 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   358
         err = 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   359
      break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   360
   case PNG_IO_CHUNK_DATA:
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   361
      break;  /* no restrictions here */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   362
   case PNG_IO_CHUNK_CRC:
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   363
      if (data_length != 4)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   364
         err = 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   365
      break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   366
   default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   367
      err = 1;  /* uninitialized */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   368
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   369
   if (err)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   370
      png_error(png_ptr, "Bad I/O state or buffer size");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   371
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   372
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
#ifndef USE_FAR_KEYWORD
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   375
static void PNGCBAPI
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   378
   png_size_t check = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   379
   png_voidp io_ptr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
   /* fread() returns 0 on error, so it is OK to store this in a png_size_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    * instead of an int, which is what fread() actually returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   384
   io_ptr = png_get_io_ptr(png_ptr);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   385
   if (io_ptr != NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   386
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   387
      check = fread(data, 1, length, (png_FILE_p)io_ptr);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   388
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
   if (check != length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   392
      png_error(png_ptr, "Read Error");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   394
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   395
#ifdef PNG_IO_STATE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   396
   pngtest_check_io_state(png_ptr, length, PNG_IO_READING);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   397
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
#else
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   400
/* This is the model-independent version. Since the standard I/O library
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
   can't handle far buffers in the medium and small models, we have to copy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
   the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
#define NEAR_BUF_SIZE 1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
#define MIN(a,b) (a <= b ? a : b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   408
static void PNGCBAPI
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   411
   png_size_t check;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
   png_byte *n_data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
   png_FILE_p io_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
   /* Check if data really is near. If so, use usual code. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
   n_data = (png_byte *)CVT_PTR_NOCHECK(data);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   417
   io_ptr = (png_FILE_p)CVT_PTR(png_get_io_ptr(png_ptr));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
   if ((png_bytep)n_data == data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   420
      check = fread(n_data, 1, length, io_ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
      png_byte buf[NEAR_BUF_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
      png_size_t read, remaining, err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
      check = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
      remaining = length;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   428
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
      do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
         read = MIN(NEAR_BUF_SIZE, remaining);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   432
         err = fread(buf, 1, 1, io_ptr);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   433
         png_memcpy(data, buf, read); /* Copy far buffer to near buffer */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   434
         if (err != read)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            check += err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
         data += read;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
         remaining -= read;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
      while (remaining != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   443
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
   if (check != length)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   445
      png_error(png_ptr, "Read Error");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   446
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   447
#ifdef PNG_IO_STATE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   448
   pngtest_check_io_state(png_ptr, length, PNG_IO_READING);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   449
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
#endif /* USE_FAR_KEYWORD */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   453
#ifdef PNG_WRITE_FLUSH_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   454
static void PNGCBAPI
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
pngtest_flush(png_structp png_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   457
   /* Do nothing; fflush() is said to be just a waste of energy. */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   458
   PNG_UNUSED(png_ptr)   /* Stifle compiler warning */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
/* This is the function that does the actual writing of data.  If you are
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   463
 * not writing to a standard C stream, you should create a replacement
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   464
 * write_data function and use it at run time with png_set_write_fn(), rather
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   465
 * than changing the library.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   466
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
#ifndef USE_FAR_KEYWORD
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   468
static void PNGCBAPI
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   471
   png_size_t check;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   473
   check = fwrite(data, 1, length, (png_FILE_p)png_get_io_ptr(png_ptr));
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   474
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
   if (check != length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
      png_error(png_ptr, "Write Error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   479
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   480
#ifdef PNG_IO_STATE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   481
   pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   482
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
#else
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   485
/* This is the model-independent version. Since the standard I/O library
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
   can't handle far buffers in the medium and small models, we have to copy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
   the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
#define NEAR_BUF_SIZE 1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
#define MIN(a,b) (a <= b ? a : b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   493
static void PNGCBAPI
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   496
   png_size_t check;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
   png_byte *near_data;  /* Needs to be "png_byte *" instead of "png_bytep" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
   png_FILE_p io_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
   /* Check if data really is near. If so, use usual code. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
   near_data = (png_byte *)CVT_PTR_NOCHECK(data);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   502
   io_ptr = (png_FILE_p)CVT_PTR(png_get_io_ptr(png_ptr));
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   503
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
   if ((png_bytep)near_data == data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   506
      check = fwrite(near_data, 1, length, io_ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   508
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
      png_byte buf[NEAR_BUF_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
      png_size_t written, remaining, err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
      check = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
      remaining = length;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   515
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
      do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
         written = MIN(NEAR_BUF_SIZE, remaining);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   519
         png_memcpy(buf, data, written); /* Copy far buffer to near buffer */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   520
         err = fwrite(buf, 1, written, io_ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
         if (err != written)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            check += err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
         data += written;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
         remaining -= written;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
      while (remaining != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   530
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
   if (check != length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
      png_error(png_ptr, "Write Error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   535
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   536
#ifdef PNG_IO_STATE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   537
   pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   538
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
#endif /* USE_FAR_KEYWORD */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
/* This function is called when there is a warning, but the library thinks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
 * it can continue anyway.  Replacement functions don't have to do anything
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
 * here if you don't want to.  In the default configuration, png_ptr is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
 * not used, but it is passed in case it may be useful.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
 */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   547
static void PNGCBAPI
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
pngtest_warning(png_structp png_ptr, png_const_charp message)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
   PNG_CONST char *name = "UNKNOWN (ERROR!)";
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   551
   char *test;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   552
   test = png_get_error_ptr(png_ptr);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   553
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   554
   if (test == NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   555
     fprintf(STDERR, "%s: libpng warning: %s\n", name, message);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   556
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   557
   else
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   558
     fprintf(STDERR, "%s: libpng warning: %s\n", test, message);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
/* This is the default error handling function.  Note that replacements for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
 * this function MUST NOT RETURN, or the program will likely crash.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
 * function is used by default, or if the program supplies NULL for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
 * error function pointer in png_set_error_fn().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
 */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   566
static void PNGCBAPI
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
pngtest_error(png_structp png_ptr, png_const_charp message)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
   pngtest_warning(png_ptr, message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
   /* We can return because png_error calls the default handler, which is
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   571
    * actually OK in this case.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   572
    */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
}
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   574
#endif /* !PNG_STDIO_SUPPORTED */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
/* END of code to validate stdio-free compilation */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
/* START of code to validate memory allocation and deallocation */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
/* Allocate memory.  For reasonable files, size should never exceed
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   581
 * 64K.  However, zlib may allocate more then 64K if you don't tell
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   582
 * it not to.  See zconf.h and png.h for more information.  zlib does
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   583
 * need to allocate exactly 64K, so whatever you call here must
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   584
 * have the ability to do that.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   585
 *
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   586
 * This piece of code can be compiled to validate max 64K allocations
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   587
 * by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   588
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
typedef struct memory_information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   591
   png_alloc_size_t          size;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
   png_voidp                 pointer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
   struct memory_information FAR *next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
} memory_information;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
typedef memory_information FAR *memory_infop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
static memory_infop pinformation = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
static int current_allocation = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
static int maximum_allocation = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
static int total_allocation = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
static int num_allocations = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   603
png_voidp PNGCBAPI png_debug_malloc PNGARG((png_structp png_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   604
    png_alloc_size_t size));
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   605
void PNGCBAPI png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
png_voidp
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   608
PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
   /* png_malloc has already tested for NULL; png_create_struct calls
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   612
    * png_debug_malloc directly, with png_ptr == NULL which is OK
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   613
    */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
   if (size == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
      return (NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
   /* This calls the library allocator twice, once to get the requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
      buffer and once to get a new free list entry. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
      /* Disable malloc_fn and free_fn */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
      memory_infop pinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
      png_set_mem_fn(png_ptr, NULL, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
      pinfo = (memory_infop)png_malloc(png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   625
         png_sizeof(*pinfo));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
      pinfo->size = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
      current_allocation += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
      total_allocation += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
      num_allocations ++;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   630
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
      if (current_allocation > maximum_allocation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
         maximum_allocation = current_allocation;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   633
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   634
      pinfo->pointer = png_malloc(png_ptr, size);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
      /* Restore malloc_fn and free_fn */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   636
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   637
      png_set_mem_fn(png_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   638
          NULL, png_debug_malloc, png_debug_free);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   639
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
      if (size != 0 && pinfo->pointer == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
         current_allocation -= size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
         total_allocation -= size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
         png_error(png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   645
           "out of memory in pngtest->png_debug_malloc");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   647
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
      pinfo->next = pinformation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
      pinformation = pinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
      /* Make sure the caller isn't assuming zeroed memory. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
      png_memset(pinfo->pointer, 0xdd, pinfo->size);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   652
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   653
      if (verbose)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   654
         printf("png_malloc %lu bytes at %p\n", (unsigned long)size,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   655
            pinfo->pointer);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   656
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
      return (png_voidp)(pinfo->pointer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
/* Free a pointer.  It is removed from the list at the same time. */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   662
void PNGCBAPI
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
png_debug_free(png_structp png_ptr, png_voidp ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
      fprintf(STDERR, "NULL pointer to png_debug_free.\n");
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   667
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
   if (ptr == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
#if 0 /* This happens all the time. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
      fprintf(STDERR, "WARNING: freeing NULL pointer\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
   /* Unlink the element from the list. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
      memory_infop FAR *ppinfo = &pinformation;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   679
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
      for (;;)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
         memory_infop pinfo = *ppinfo;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   683
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
         if (pinfo->pointer == ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            *ppinfo = pinfo->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            current_allocation -= pinfo->size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            if (current_allocation < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
               fprintf(STDERR, "Duplicate free of memory\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            /* We must free the list element too, but first kill
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
               the memory that is to be freed. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            png_memset(ptr, 0x55, pinfo->size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            png_free_default(png_ptr, pinfo);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   694
            pinfo = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   697
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
         if (pinfo->next == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            fprintf(STDERR, "Pointer %x not found\n", (unsigned int)ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   703
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
         ppinfo = &pinfo->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
   /* Finally free the data. */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   709
   if (verbose)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   710
      printf("Freeing %p\n", ptr);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   711
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
   png_free_default(png_ptr, ptr);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   713
   ptr = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
#endif /* PNG_USER_MEM_SUPPORTED && PNG_DEBUG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
/* END of code to test memory allocation/deallocation */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   718
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   719
/* Demonstration of user chunk support of the sTER and vpAg chunks */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   720
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   721
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   722
/* (sTER is a public chunk not yet known by libpng.  vpAg is a private
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   723
chunk used in ImageMagick to store "virtual page" size).  */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   724
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   725
static png_uint_32 user_chunk_data[4];
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   726
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   727
    /* 0: sTER mode + 1
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   728
     * 1: vpAg width
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   729
     * 2: vpAg height
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   730
     * 3: vpAg units
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   731
     */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   732
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   733
static int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   734
   png_unknown_chunkp chunk)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   735
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   736
   png_uint_32
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   737
     *my_user_chunk_data;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   738
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   739
   /* Return one of the following:
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   740
    *    return (-n);  chunk had an error
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   741
    *    return (0);  did not recognize
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   742
    *    return (n);  success
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   743
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   744
    * The unknown chunk structure contains the chunk data:
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   745
    * png_byte name[5];
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   746
    * png_byte *data;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   747
    * png_size_t size;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   748
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   749
    * Note that libpng has already taken care of the CRC handling.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   750
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   751
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   752
   if (chunk->name[0] == 115 && chunk->name[1] ==  84 &&     /* s  T */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   753
       chunk->name[2] ==  69 && chunk->name[3] ==  82)       /* E  R */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   754
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   755
         /* Found sTER chunk */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   756
         if (chunk->size != 1)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   757
            return (-1); /* Error return */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   758
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   759
         if (chunk->data[0] != 0 && chunk->data[0] != 1)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   760
            return (-1);  /* Invalid mode */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   761
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   762
         my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   763
         my_user_chunk_data[0]=chunk->data[0]+1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   764
         return (1);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   765
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   766
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   767
   if (chunk->name[0] != 118 || chunk->name[1] != 112 ||    /* v  p */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   768
       chunk->name[2] !=  65 || chunk->name[3] != 103)      /* A  g */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   769
      return (0); /* Did not recognize */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   770
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   771
   /* Found ImageMagick vpAg chunk */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   772
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   773
   if (chunk->size != 9)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   774
      return (-1); /* Error return */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   775
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   776
   my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   777
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   778
   my_user_chunk_data[1]=png_get_uint_31(png_ptr, chunk->data);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   779
   my_user_chunk_data[2]=png_get_uint_31(png_ptr, chunk->data + 4);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   780
   my_user_chunk_data[3]=(png_uint_32)chunk->data[8];
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   781
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   782
   return (1);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   783
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   784
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   785
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   786
/* END of code to demonstrate user chunk support */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   787
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
/* Test one file */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
   static png_FILE_p fpin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
   static png_FILE_p fpout;  /* "static" prevents setjmp corruption */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
   png_structp read_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
   png_infop read_info_ptr, end_info_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
#ifdef PNG_WRITE_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
   png_structp write_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
   png_infop write_info_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
   png_infop write_end_info_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
   png_structp write_ptr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
   png_infop write_info_ptr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
   png_infop write_end_info_ptr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
   png_bytep row_buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
   png_uint_32 y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
   png_uint_32 width, height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
   int num_pass, pass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
   int bit_depth, color_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
#ifdef PNG_SETJMP_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
#ifdef USE_FAR_KEYWORD
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   812
   jmp_buf tmp_jmpbuf;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
   char inbuf[256], outbuf[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
   row_buf = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
   if ((fpin = fopen(inname, "rb")) == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
      fprintf(STDERR, "Could not find input file %s\n", inname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
      return (1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
   if ((fpout = fopen(outname, "wb")) == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
      fprintf(STDERR, "Could not open output file %s\n", outname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
      FCLOSE(fpin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
      return (1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   833
   pngtest_debug("Allocating read and write structures");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   835
   read_ptr =
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   836
      png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   837
      NULL, NULL, NULL, png_debug_malloc, png_debug_free);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
#else
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   839
   read_ptr =
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   840
      png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   842
#ifndef PNG_STDIO_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
   png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
       pngtest_warning);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   846
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   847
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   848
   user_chunk_data[0] = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   849
   user_chunk_data[1] = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   850
   user_chunk_data[2] = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   851
   user_chunk_data[3] = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   852
   png_set_read_user_chunk_fn(read_ptr, user_chunk_data,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   853
     read_user_chunk_callback);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   854
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   855
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
#ifdef PNG_WRITE_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   858
   write_ptr =
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   859
      png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   860
      NULL, NULL, NULL, png_debug_malloc, png_debug_free);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
#else
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   862
   write_ptr =
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   863
      png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   865
#ifndef PNG_STDIO_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
   png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
       pngtest_warning);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   870
   pngtest_debug("Allocating read_info, write_info and end_info structures");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
   read_info_ptr = png_create_info_struct(read_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
   end_info_ptr = png_create_info_struct(read_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
#ifdef PNG_WRITE_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
   write_info_ptr = png_create_info_struct(write_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
   write_end_info_ptr = png_create_info_struct(write_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
#ifdef PNG_SETJMP_SUPPORTED
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   879
   pngtest_debug("Setting jmpbuf for read struct");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
#ifdef USE_FAR_KEYWORD
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   881
   if (setjmp(tmp_jmpbuf))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
   if (setjmp(png_jmpbuf(read_ptr)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
      fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   887
      png_free(read_ptr, row_buf);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   888
      row_buf = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
      png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
#ifdef PNG_WRITE_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
      png_destroy_info_struct(write_ptr, &write_end_info_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
      png_destroy_write_struct(&write_ptr, &write_info_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
      FCLOSE(fpin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
      FCLOSE(fpout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
      return (1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
#ifdef USE_FAR_KEYWORD
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   899
   png_memcpy(png_jmpbuf(read_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
#ifdef PNG_WRITE_SUPPORTED
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   903
   pngtest_debug("Setting jmpbuf for write struct");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
#ifdef USE_FAR_KEYWORD
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   905
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   906
   if (setjmp(tmp_jmpbuf))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
   if (setjmp(png_jmpbuf(write_ptr)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
      fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
      png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
      png_destroy_info_struct(write_ptr, &write_end_info_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
#ifdef PNG_WRITE_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
      png_destroy_write_struct(&write_ptr, &write_info_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
      FCLOSE(fpin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
      FCLOSE(fpout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
      return (1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   921
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
#ifdef USE_FAR_KEYWORD
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   923
   png_memcpy(png_jmpbuf(write_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   928
   pngtest_debug("Initializing input and output streams");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   929
#ifdef PNG_STDIO_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
   png_init_io(read_ptr, fpin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
#  ifdef PNG_WRITE_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
   png_init_io(write_ptr, fpout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
#  endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
   png_set_read_fn(read_ptr, (png_voidp)fpin, pngtest_read_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
#  ifdef PNG_WRITE_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
   png_set_write_fn(write_ptr, (png_voidp)fpout,  pngtest_write_data,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   938
#    ifdef PNG_WRITE_FLUSH_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
      pngtest_flush);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
#    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
      NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
#    endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
#  endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   945
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   946
#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   947
   /* Normally one would use Z_DEFAULT_STRATEGY for text compression.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   948
    * This is here just to make pngtest replicate the results from libpng
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   949
    * versions prior to 1.5.4, and to test this new API.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   950
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   951
   png_set_text_compression_strategy(write_ptr, Z_FILTERED);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   952
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   953
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   954
   if (status_dots_requested == 1)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
#ifdef PNG_WRITE_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
      png_set_write_status_fn(write_ptr, write_row_callback);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
      png_set_read_status_fn(read_ptr, read_row_callback);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   961
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
#ifdef PNG_WRITE_SUPPORTED
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   965
      png_set_write_status_fn(write_ptr, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   967
      png_set_read_status_fn(read_ptr, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   970
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   972
      int i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   973
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   974
      for (i = 0; i<256; i++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   975
         filters_used[i] = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   976
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   977
      png_set_read_user_transform_fn(read_ptr, count_filters);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   980
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   981
   zero_samples = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
   png_set_write_user_transform_fn(write_ptr, count_zero_samples);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   985
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
#  ifndef PNG_HANDLE_CHUNK_ALWAYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
#    define PNG_HANDLE_CHUNK_ALWAYS       3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
#  endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
   png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   990
      NULL, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   992
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
#  ifndef PNG_HANDLE_CHUNK_IF_SAFE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
#    define PNG_HANDLE_CHUNK_IF_SAFE      2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
#  endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
   png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_IF_SAFE,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   997
      NULL, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1000
   pngtest_debug("Reading info struct");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
   png_read_info(read_ptr, read_info_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1003
   pngtest_debug("Transferring info struct");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
      int interlace_type, compression_type, filter_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
      if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
          &color_type, &interlace_type, &compression_type, &filter_type))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
         png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1011
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            color_type, interlace_type, compression_type, filter_type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            color_type, PNG_INTERLACE_NONE, compression_type, filter_type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1018
#ifdef PNG_FIXED_POINT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1019
#ifdef PNG_cHRM_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
      png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
         blue_y;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1023
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1024
      if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1025
         &red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
         png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            red_y, green_x, green_y, blue_x, blue_y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1032
#ifdef PNG_gAMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
      png_fixed_point gamma;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
      if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
         png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
#else /* Use floating point versions */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1041
#ifdef PNG_FLOATING_POINT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1042
#ifdef PNG_cHRM_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
      double white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
         blue_y;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1046
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
      if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
         &red_y, &green_x, &green_y, &blue_x, &blue_y))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
         png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            red_y, green_x, green_y, blue_x, blue_y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1055
#ifdef PNG_gAMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
      double gamma;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
      if (png_get_gAMA(read_ptr, read_info_ptr, &gamma))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
         png_set_gAMA(write_ptr, write_info_ptr, gamma);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1063
#endif /* Floating point */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1064
#endif /* Fixed point */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1065
#ifdef PNG_iCCP_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
      png_charp name;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1068
      png_bytep profile;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
      png_uint_32 proflen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
      int compression_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
      if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                      &profile, &proflen))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
         png_set_iCCP(write_ptr, write_info_ptr, name, compression_type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                      profile, proflen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1080
#ifdef PNG_sRGB_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
      int intent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
      if (png_get_sRGB(read_ptr, read_info_ptr, &intent))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
         png_set_sRGB(write_ptr, write_info_ptr, intent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
      png_colorp palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
      int num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
      if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
         png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1095
#ifdef PNG_bKGD_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
      png_color_16p background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
      if (png_get_bKGD(read_ptr, read_info_ptr, &background))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
         png_set_bKGD(write_ptr, write_info_ptr, background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1105
#ifdef PNG_hIST_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
      png_uint_16p hist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
      if (png_get_hIST(read_ptr, read_info_ptr, &hist))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
         png_set_hIST(write_ptr, write_info_ptr, hist);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1113
#ifdef PNG_oFFs_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
      png_int_32 offset_x, offset_y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
      int unit_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1118
      if (png_get_oFFs(read_ptr, read_info_ptr, &offset_x, &offset_y,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1119
          &unit_type))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
         png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1125
#ifdef PNG_pCAL_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
      png_charp purpose, units;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
      png_charpp params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
      png_int_32 X0, X1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
      int type, nparams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
      if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
         &nparams, &units, &params))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
         png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            nparams, units, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1140
#ifdef PNG_pHYs_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
      png_uint_32 res_x, res_y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
      int unit_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
      if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
         png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1149
#ifdef PNG_sBIT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
      png_color_8p sig_bit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
      if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
         png_set_sBIT(write_ptr, write_info_ptr, sig_bit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1157
#ifdef PNG_sCAL_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
#ifdef PNG_FLOATING_POINT_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
      int unit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
      double scal_width, scal_height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
      if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
         &scal_height))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
         png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
#ifdef PNG_FIXED_POINT_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
      int unit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
      png_charp scal_width, scal_height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
      if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
          &scal_height))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1178
         png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1179
             scal_height);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1185
#ifdef PNG_TEXT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
      png_textp text_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
      int num_text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
      if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1192
         pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
         png_set_text(write_ptr, write_info_ptr, text_ptr, num_text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1197
#ifdef PNG_tIME_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
      png_timep mod_time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
      if (png_get_tIME(read_ptr, read_info_ptr, &mod_time))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
         png_set_tIME(write_ptr, write_info_ptr, mod_time);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1204
#ifdef PNG_TIME_RFC1123_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1205
         /* We have to use png_memcpy instead of "=" because the string
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1206
          * pointed to by png_convert_to_rfc1123() gets free'ed before
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1207
          * we use it.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1208
          */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1209
         png_memcpy(tIME_string,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1210
                    png_convert_to_rfc1123(read_ptr, mod_time),
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1211
                    png_sizeof(tIME_string));
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1212
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1213
         tIME_string[png_sizeof(tIME_string) - 1] = '\0';
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
         tIME_chunk_present++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
#endif /* PNG_TIME_RFC1123_SUPPORTED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1219
#ifdef PNG_tRNS_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1221
      png_bytep trans_alpha;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
      int num_trans;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1223
      png_color_16p trans_color;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1225
      if (png_get_tRNS(read_ptr, read_info_ptr, &trans_alpha, &num_trans,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1226
         &trans_color))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1228
         int sample_max = (1 << bit_depth);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1229
         /* libpng doesn't reject a tRNS chunk with out-of-range samples */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1230
         if (!((color_type == PNG_COLOR_TYPE_GRAY &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1231
             (int)trans_color->gray > sample_max) ||
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1232
             (color_type == PNG_COLOR_TYPE_RGB &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1233
             ((int)trans_color->red > sample_max ||
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1234
             (int)trans_color->green > sample_max ||
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1235
             (int)trans_color->blue > sample_max))))
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1236
            png_set_tRNS(write_ptr, write_info_ptr, trans_alpha, num_trans,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1237
               trans_color);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1241
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
      png_unknown_chunkp unknowns;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1244
      int num_unknowns = png_get_unknown_chunks(read_ptr, read_info_ptr,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
         &unknowns);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1246
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
      if (num_unknowns)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1249
         int i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
         png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
           num_unknowns);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1252
         /* Copy the locations from the read_info_ptr.  The automatically
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1253
          * generated locations in write_info_ptr are wrong because we
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1254
          * haven't written anything yet.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1255
          */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1256
         for (i = 0; i < num_unknowns; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
           png_set_unknown_chunk_location(write_ptr, write_info_ptr, i,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
             unknowns[i].location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
#ifdef PNG_WRITE_SUPPORTED
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1264
   pngtest_debug("Writing info struct");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
/* If we wanted, we could write info in two steps:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1267
 * png_write_info_before_PLTE(write_ptr, write_info_ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
   png_write_info(write_ptr, write_info_ptr);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1270
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1271
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1272
   if (user_chunk_data[0] != 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1273
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1274
      png_byte png_sTER[5] = {115,  84,  69,  82, '\0'};
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1275
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1276
      unsigned char
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1277
        ster_chunk_data[1];
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1278
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1279
      if (verbose)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1280
         fprintf(STDERR, "\n stereo mode = %lu\n",
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1281
           (unsigned long)(user_chunk_data[0] - 1));
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1282
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1283
      ster_chunk_data[0]=(unsigned char)(user_chunk_data[0] - 1);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1284
      png_write_chunk(write_ptr, png_sTER, ster_chunk_data, 1);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1285
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1286
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1287
   if (user_chunk_data[1] != 0 || user_chunk_data[2] != 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1288
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1289
      png_byte png_vpAg[5] = {118, 112,  65, 103, '\0'};
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1290
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1291
      unsigned char
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1292
        vpag_chunk_data[9];
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1293
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1294
      if (verbose)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1295
         fprintf(STDERR, " vpAg = %lu x %lu, units = %lu\n",
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1296
           (unsigned long)user_chunk_data[1],
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1297
           (unsigned long)user_chunk_data[2],
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1298
           (unsigned long)user_chunk_data[3]);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1299
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1300
      png_save_uint_32(vpag_chunk_data, user_chunk_data[1]);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1301
      png_save_uint_32(vpag_chunk_data + 4, user_chunk_data[2]);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1302
      vpag_chunk_data[8] = (unsigned char)(user_chunk_data[3] & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1303
      png_write_chunk(write_ptr, png_vpAg, vpag_chunk_data, 9);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1304
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1305
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1306
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
#ifdef SINGLE_ROWBUF_ALLOC
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1310
   pngtest_debug("Allocating row buffer...");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
   row_buf = (png_bytep)png_malloc(read_ptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
      png_get_rowbytes(read_ptr, read_info_ptr));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1313
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1314
   pngtest_debug1("\t0x%08lx", (unsigned long)row_buf);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
#endif /* SINGLE_ROWBUF_ALLOC */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1316
   pngtest_debug("Writing row data");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
  defined(PNG_WRITE_INTERLACING_SUPPORTED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
   num_pass = png_set_interlace_handling(read_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
#  ifdef PNG_WRITE_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
   png_set_interlace_handling(write_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
#  endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
#else
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1325
   num_pass = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
#ifdef PNGTEST_TIMING
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
   t_stop = (float)clock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
   t_misc += (t_stop - t_start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
   t_start = t_stop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
   for (pass = 0; pass < num_pass; pass++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1335
      pngtest_debug1("Writing row data for pass %d", pass);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
      for (y = 0; y < height; y++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
#ifndef SINGLE_ROWBUF_ALLOC
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1339
         pngtest_debug2("Allocating row buffer (pass %d, y = %u)...", pass, y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
         row_buf = (png_bytep)png_malloc(read_ptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            png_get_rowbytes(read_ptr, read_info_ptr));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1342
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1343
         pngtest_debug2("\t0x%08lx (%u bytes)", (unsigned long)row_buf,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
            png_get_rowbytes(read_ptr, read_info_ptr));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1345
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
#endif /* !SINGLE_ROWBUF_ALLOC */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1347
         png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
#ifdef PNG_WRITE_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
#ifdef PNGTEST_TIMING
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
         t_stop = (float)clock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
         t_decode += (t_stop - t_start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
         t_start = t_stop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
         png_write_rows(write_ptr, (png_bytepp)&row_buf, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
#ifdef PNGTEST_TIMING
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
         t_stop = (float)clock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
         t_encode += (t_stop - t_start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
         t_start = t_stop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
#endif /* PNG_WRITE_SUPPORTED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
#ifndef SINGLE_ROWBUF_ALLOC
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1364
         pngtest_debug2("Freeing row buffer (pass %d, y = %u)", pass, y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
         png_free(read_ptr, row_buf);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1366
         row_buf = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
#endif /* !SINGLE_ROWBUF_ALLOC */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1371
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
   png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1374
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
   png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1378
   pngtest_debug("Reading and writing end_info data");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
   png_read_end(read_ptr, end_info_ptr);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1381
#ifdef PNG_TEXT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
      png_textp text_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
      int num_text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
      if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1388
         pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
         png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1393
#ifdef PNG_tIME_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
      png_timep mod_time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
      if (png_get_tIME(read_ptr, end_info_ptr, &mod_time))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
         png_set_tIME(write_ptr, write_end_info_ptr, mod_time);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1400
#ifdef PNG_TIME_RFC1123_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1401
         /* We have to use png_memcpy instead of "=" because the string
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
            pointed to by png_convert_to_rfc1123() gets free'ed before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
            we use it */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1404
         png_memcpy(tIME_string,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1405
                    png_convert_to_rfc1123(read_ptr, mod_time),
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1406
                    png_sizeof(tIME_string));
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1407
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1408
         tIME_string[png_sizeof(tIME_string) - 1] = '\0';
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
         tIME_chunk_present++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
#endif /* PNG_TIME_RFC1123_SUPPORTED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1414
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
      png_unknown_chunkp unknowns;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1417
      int num_unknowns = png_get_unknown_chunks(read_ptr, end_info_ptr,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
         &unknowns);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1419
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
      if (num_unknowns)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1422
         int i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
         png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
           num_unknowns);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1425
         /* Copy the locations from the read_info_ptr.  The automatically
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1426
          * generated locations in write_end_info_ptr are wrong because we
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1427
          * haven't written the end_info yet.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1428
          */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1429
         for (i = 0; i < num_unknowns; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
           png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
             unknowns[i].location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
#ifdef PNG_WRITE_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
   png_write_end(write_ptr, write_end_info_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
#ifdef PNG_EASY_ACCESS_SUPPORTED
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1440
   if (verbose)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
      png_uint_32 iwidth, iheight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
      iwidth = png_get_image_width(write_ptr, write_info_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
      iheight = png_get_image_height(write_ptr, write_info_ptr);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1445
      fprintf(STDERR, "\n Image width = %lu, height = %lu\n",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
         (unsigned long)iwidth, (unsigned long)iheight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1450
   pngtest_debug("Destroying data structs");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
#ifdef SINGLE_ROWBUF_ALLOC
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1452
   pngtest_debug("destroying row_buf for read_ptr");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
   png_free(read_ptr, row_buf);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1454
   row_buf = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
#endif /* SINGLE_ROWBUF_ALLOC */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1456
   pngtest_debug("destroying read_ptr, read_info_ptr, end_info_ptr");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
   png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
#ifdef PNG_WRITE_SUPPORTED
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1459
   pngtest_debug("destroying write_end_info_ptr");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
   png_destroy_info_struct(write_ptr, &write_end_info_ptr);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1461
   pngtest_debug("destroying write_ptr, write_info_ptr");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
   png_destroy_write_struct(&write_ptr, &write_info_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1464
   pngtest_debug("Destruction complete.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
   FCLOSE(fpin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
   FCLOSE(fpout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1469
   pngtest_debug("Opening files for comparison");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
   if ((fpin = fopen(inname, "rb")) == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
      fprintf(STDERR, "Could not find file %s\n", inname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
      return (1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
   if ((fpout = fopen(outname, "rb")) == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
      fprintf(STDERR, "Could not find file %s\n", outname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
      FCLOSE(fpin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
      return (1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1483
   for (;;)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
      png_size_t num_in, num_out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1487
         num_in = fread(inbuf, 1, 1, fpin);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1488
         num_out = fread(outbuf, 1, 1, fpout);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
      if (num_in != num_out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
         fprintf(STDERR, "\nFiles %s and %s are of a different size\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                 inname, outname);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1494
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1495
         if (wrote_question == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
            fprintf(STDERR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
         "   Was %s written with the same maximum IDAT chunk size (%d bytes),",
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1499
              inname, PNG_ZBUF_SIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
            fprintf(STDERR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
              "\n   filtering heuristic (libpng default), compression");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
            fprintf(STDERR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
              " level (zlib default),\n   and zlib version (%s)?\n\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
              ZLIB_VERSION);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1505
            wrote_question = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1507
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
         FCLOSE(fpin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
         FCLOSE(fpout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
         return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
      if (!num_in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
         break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
      if (png_memcmp(inbuf, outbuf, num_in))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
         fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1519
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1520
         if (wrote_question == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
            fprintf(STDERR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
         "   Was %s written with the same maximum IDAT chunk size (%d bytes),",
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1524
                 inname, PNG_ZBUF_SIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
            fprintf(STDERR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
              "\n   filtering heuristic (libpng default), compression");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
            fprintf(STDERR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
              " level (zlib default),\n   and zlib version (%s)?\n\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
              ZLIB_VERSION);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1530
            wrote_question = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1532
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
         FCLOSE(fpin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
         FCLOSE(fpout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
         return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
   FCLOSE(fpin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
   FCLOSE(fpout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
   return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1545
/* Input and output filenames */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
#ifdef RISCOS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
static PNG_CONST char *inname = "pngtest/png";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
static PNG_CONST char *outname = "pngout/png";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
static PNG_CONST char *inname = "pngtest.png";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
static PNG_CONST char *outname = "pngout.png";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
main(int argc, char *argv[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
   int multiple = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
   int ierror = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1560
   fprintf(STDERR, "\n Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
   fprintf(STDERR, "   with zlib   version %s\n", ZLIB_VERSION);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1562
   fprintf(STDERR, "%s", png_get_copyright(NULL));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
   /* Show the version of libpng used in building the library */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1564
   fprintf(STDERR, " library (%lu):%s",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
      (unsigned long)png_access_version_number(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
      png_get_header_version(NULL));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1567
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
   /* Show the version of libpng used in building the application */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1569
   fprintf(STDERR, " pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
      PNG_HEADER_VERSION_STRING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
   /* Do some consistency checking on the memory allocation settings, I'm
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1573
    * not sure this matters, but it is nice to know, the first of these
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1574
    * tests should be impossible because of the way the macros are set
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1575
    * in pngconf.h
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1576
    */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
      fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
   /* I think the following can happen. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
#if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
      fprintf(STDERR, " NOTE: libpng compiled for max 64k, zlib not\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
   if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
      fprintf(STDERR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
         "Warning: versions are different between png.h and png.c\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
      fprintf(STDERR, "  png.h version: %s\n", PNG_LIBPNG_VER_STRING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
      fprintf(STDERR, "  png.c version: %s\n\n", png_libpng_ver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
      ++ierror;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
   if (argc > 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
      if (strcmp(argv[1], "-m") == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
         multiple = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
         status_dots_requested = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1601
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
      else if (strcmp(argv[1], "-mv") == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
               strcmp(argv[1], "-vm") == 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
         multiple = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
         verbose = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
         status_dots_requested = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1609
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
      else if (strcmp(argv[1], "-v") == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
         verbose = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
         status_dots_requested = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
         inname = argv[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1616
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
         inname = argv[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
         status_dots_requested = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1624
   if (!multiple && argc == 3 + verbose)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1625
     outname = argv[2 + verbose];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1627
   if ((!multiple && argc > 3 + verbose) || (multiple && argc < 2))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
     fprintf(STDERR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
       "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
        argv[0], argv[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
     fprintf(STDERR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
       "  reads/writes one PNG file (without -m) or multiple files (-m)\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
     fprintf(STDERR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
       "  with -m %s is used as a temporary file\n", outname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
     exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
   if (multiple)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
      int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
      int allocation_now = current_allocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
      for (i=2; i<argc; ++i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
         int kerror;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1648
         fprintf(STDERR, "\n Testing %s:", argv[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
         kerror = test_one_file(argv[i], outname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
         if (kerror == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1652
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1653
            int k;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1654
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1655
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
            fprintf(STDERR, "\n PASS (%lu zero samples)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
               (unsigned long)zero_samples);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
            fprintf(STDERR, " PASS\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1661
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1662
            for (k = 0; k<256; k++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1663
               if (filters_used[k])
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
                  fprintf(STDERR, " Filter %d was used %lu times\n",
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1665
                     k, (unsigned long)filters_used[k]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1667
#ifdef PNG_TIME_RFC1123_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1668
         if (tIME_chunk_present != 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1669
            fprintf(STDERR, " tIME = %s\n", tIME_string);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1670
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
         tIME_chunk_present = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
#endif /* PNG_TIME_RFC1123_SUPPORTED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1674
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
            fprintf(STDERR, " FAIL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
            ierror += kerror;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
         if (allocation_now != current_allocation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
            fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1683
               current_allocation - allocation_now);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1684
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
         if (current_allocation != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
            memory_infop pinfo = pinformation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
            fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
               current_allocation);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1691
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
            while (pinfo != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1694
               fprintf(STDERR, " %lu bytes at %x\n",
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1695
                 (unsigned long)pinfo->size,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1696
                 (unsigned int)pinfo->pointer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
               pinfo = pinfo->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
         fprintf(STDERR, " Current memory allocation: %10d bytes\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
            current_allocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
         fprintf(STDERR, " Maximum memory allocation: %10d bytes\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
            maximum_allocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
         fprintf(STDERR, " Total   memory allocation: %10d bytes\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
            total_allocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
         fprintf(STDERR, "     Number of allocations: %10d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
            num_allocations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1713
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
      int i;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1717
      for (i = 0; i<3; ++i)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
         int kerror;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
         int allocation_now = current_allocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1723
         if (i == 1)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1724
            status_dots_requested = 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1725
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1726
         else if (verbose == 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1727
            status_dots_requested = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1728
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
         if (i == 0 || verbose == 1 || ierror != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1730
            fprintf(STDERR, "\n Testing %s:", inname);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1731
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
         kerror = test_one_file(inname, outname);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1733
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1734
         if (kerror == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1736
            if (verbose == 1 || i == 2)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1738
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
                int k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1741
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
                fprintf(STDERR, "\n PASS (%lu zero samples)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
                   (unsigned long)zero_samples);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
                fprintf(STDERR, " PASS\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1747
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1748
                for (k = 0; k<256; k++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1749
                   if (filters_used[k])
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
                      fprintf(STDERR, " Filter %d was used %lu times\n",
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1751
                         k, (unsigned long)filters_used[k]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1753
#ifdef PNG_TIME_RFC1123_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1754
             if (tIME_chunk_present != 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1755
                fprintf(STDERR, " tIME = %s\n", tIME_string);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
#endif /* PNG_TIME_RFC1123_SUPPORTED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1759
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1762
            if (verbose == 0 && i != 2)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1763
               fprintf(STDERR, "\n Testing %s:", inname);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1764
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
            fprintf(STDERR, " FAIL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
            ierror += kerror;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
         if (allocation_now != current_allocation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
             fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1771
               current_allocation - allocation_now);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1772
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
         if (current_allocation != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
             memory_infop pinfo = pinformation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
             fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
                current_allocation);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1779
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
             while (pinfo != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
             {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1782
                fprintf(STDERR, " %lu bytes at %x\n",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
                   (unsigned long)pinfo->size, (unsigned int)pinfo->pointer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
                pinfo = pinfo->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
       fprintf(STDERR, " Current memory allocation: %10d bytes\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
          current_allocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
       fprintf(STDERR, " Maximum memory allocation: %10d bytes\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
          maximum_allocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
       fprintf(STDERR, " Total   memory allocation: %10d bytes\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
          total_allocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
       fprintf(STDERR, "     Number of allocations: %10d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
            num_allocations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
#ifdef PNGTEST_TIMING
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
   t_stop = (float)clock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
   t_misc += (t_stop - t_start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
   t_start = t_stop;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1805
   fprintf(STDERR, " CPU time used = %.3f seconds",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
      (t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1807
   fprintf(STDERR, " (decoding %.3f,\n",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
      t_decode/(float)CLOCKS_PER_SEC);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1809
   fprintf(STDERR, "        encoding %.3f ,",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
      t_encode/(float)CLOCKS_PER_SEC);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1811
   fprintf(STDERR, " other %.3f seconds)\n\n",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
      t_misc/(float)CLOCKS_PER_SEC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
   if (ierror == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1816
      fprintf(STDERR, " libpng passes test\n");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1817
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
   else
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1819
      fprintf(STDERR, " libpng FAILS test\n");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1820
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
   return (int)(ierror != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
/* Generate a compiler error if there is an old png.h in the search path. */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1825
typedef png_libpng_version_1_5_4 Your_png_h_is_not_version_1_5_4;