pngread.c 27.4 KB
Newer Older
G
Guy Schalnat 已提交
1

A
Andreas Dilger 已提交
2
/* pngread.c - read a PNG file
3
 *
4
 * 1.0.1d
5 6 7
 * For conditions of distribution and use, see copyright notice in png.h
 * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
 * Copyright (c) 1996, 1997 Andreas Dilger
8
 * Copyright (c) 1998, Glenn Randers-Pehrson
9
 * May 21, 1998
10 11 12 13
 *
 * This file contains routines that an application calls directly to
 * read a PNG file or stream.
 */
G
Guy Schalnat 已提交
14 15 16 17

#define PNG_INTERNAL
#include "png.h"

A
Andreas Dilger 已提交
18
/* Create a PNG structure for reading, and allocate any memory needed. */
G
Guy Schalnat 已提交
19
png_structp
20
png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
A
Andreas Dilger 已提交
21
   png_error_ptr error_fn, png_error_ptr warn_fn)
G
Guy Schalnat 已提交
22 23
{
   png_structp png_ptr;
A
Andreas Dilger 已提交
24 25 26
#ifdef USE_FAR_KEYWORD
   jmp_buf jmpbuf;
#endif
A
Andreas Dilger 已提交
27
   png_debug(1, "in png_create_read_struct\n");
G
Guy Schalnat 已提交
28 29 30 31
   if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL)
   {
      return (png_structp)NULL;
   }
A
Andreas Dilger 已提交
32 33 34
#ifdef USE_FAR_KEYWORD
   if (setjmp(jmpbuf))
#else
G
Guy Schalnat 已提交
35
   if (setjmp(png_ptr->jmpbuf))
A
Andreas Dilger 已提交
36
#endif
G
Guy Schalnat 已提交
37
   {
A
Andreas Dilger 已提交
38
      png_free(png_ptr, png_ptr->zbuf);
G
Guy Schalnat 已提交
39 40 41
      png_destroy_struct(png_ptr);
      return (png_structp)NULL;
   }
A
Andreas Dilger 已提交
42 43 44 45 46
#ifdef USE_FAR_KEYWORD
   png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
#endif
   png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);

A
Andreas Dilger 已提交
47 48 49 50 51 52 53
   /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
    * we must recompile any applications that use any older library version.
    * For versions after libpng 1.0, we will be compatible, so we need
    * only check the first digit.
    */
   if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
       (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
G
Guy Schalnat 已提交
54
   {
A
Andreas Dilger 已提交
55
      png_error(png_ptr,
A
Andreas Dilger 已提交
56
         "Incompatible libpng version in application and library");
G
Guy Schalnat 已提交
57 58 59 60
   }

   /* initialize zbuf - compression buffer */
   png_ptr->zbuf_size = PNG_ZBUF_SIZE;
61 62
   png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
     (png_uint_32)png_ptr->zbuf_size);
A
Andreas Dilger 已提交
63 64 65
   png_ptr->zstream.zalloc = png_zalloc;
   png_ptr->zstream.zfree = png_zfree;
   png_ptr->zstream.opaque = (voidpf)png_ptr;
G
Guy Schalnat 已提交
66

A
Andreas Dilger 已提交
67
   switch (inflateInit(&png_ptr->zstream))
G
Guy Schalnat 已提交
68 69 70 71 72 73 74 75
   {
     case Z_OK: /* Do nothing */ break;
     case Z_MEM_ERROR:
     case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
     case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
     default: png_error(png_ptr, "Unknown zlib error");
   }

A
Andreas Dilger 已提交
76 77
   png_ptr->zstream.next_out = png_ptr->zbuf;
   png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
G
Guy Schalnat 已提交
78 79 80 81 82 83

   png_set_read_fn(png_ptr, NULL, NULL);

   return (png_ptr);
}

A
Andreas Dilger 已提交
84
/* Initialize PNG structure for reading, and allocate any memory needed.
85
   This interface is deprecated in favour of the png_create_read_struct(),
A
Andreas Dilger 已提交
86
   and it will eventually disappear. */
G
Guy Schalnat 已提交
87
void
G
Guy Schalnat 已提交
88
png_read_init(png_structp png_ptr)
G
Guy Schalnat 已提交
89
{
G
Guy Schalnat 已提交
90
   jmp_buf tmp_jmp;  /* to save current jump buffer */
G
Guy Schalnat 已提交
91

A
Andreas Dilger 已提交
92
   png_debug(1, "in png_read_init\n");
G
Guy Schalnat 已提交
93
   /* save jump buffer and error functions */
G
Guy Schalnat 已提交
94
   png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
G
Guy Schalnat 已提交
95

G
Guy Schalnat 已提交
96
   /* reset all variables to 0 */
G
Guy Schalnat 已提交
97
   png_memset(png_ptr, 0, sizeof (png_struct));
G
Guy Schalnat 已提交
98

G
Guy Schalnat 已提交
99
   /* restore jump buffer */
G
Guy Schalnat 已提交
100
   png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
G
Guy Schalnat 已提交
101

G
Guy Schalnat 已提交
102
   /* initialize zbuf - compression buffer */
G
Guy Schalnat 已提交
103
   png_ptr->zbuf_size = PNG_ZBUF_SIZE;
104 105
   png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
     (png_uint_32)png_ptr->zbuf_size);
A
Andreas Dilger 已提交
106 107 108
   png_ptr->zstream.zalloc = png_zalloc;
   png_ptr->zstream.zfree = png_zfree;
   png_ptr->zstream.opaque = (voidpf)png_ptr;
G
Guy Schalnat 已提交
109

A
Andreas Dilger 已提交
110
   switch (inflateInit(&png_ptr->zstream))
G
Guy Schalnat 已提交
111 112 113 114 115 116 117 118
   {
     case Z_OK: /* Do nothing */ break;
     case Z_MEM_ERROR:
     case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
     case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
     default: png_error(png_ptr, "Unknown zlib error");
   }

A
Andreas Dilger 已提交
119 120
   png_ptr->zstream.next_out = png_ptr->zbuf;
   png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
G
Guy Schalnat 已提交
121 122

   png_set_read_fn(png_ptr, NULL, NULL);
G
Guy Schalnat 已提交
123 124
}

A
Andreas Dilger 已提交
125
/* Read the information before the actual image data.  This has been
126
 * changed in v0.90 to allow reading a file that already has the magic
A
Andreas Dilger 已提交
127
 * bytes read from the stream.  You can tell libpng how many bytes have
128
 * been read from the beginning of the stream (up to the maximum of 8)
A
Andreas Dilger 已提交
129 130 131 132
 * via png_set_sig_bytes(), and we will only check the remaining bytes
 * here.  The application can then have access to the signature bytes we
 * read if it is determined that this isn't a valid PNG file.
 */
G
Guy Schalnat 已提交
133
void
A
Andreas Dilger 已提交
134
png_read_info(png_structp png_ptr, png_infop info_ptr)
G
Guy Schalnat 已提交
135
{
A
Andreas Dilger 已提交
136 137
   png_debug(1, "in png_read_info\n");
   /* save jump buffer and error functions */
A
Andreas Dilger 已提交
138 139
   /* If we haven't checked all of the PNG signature bytes, do so now. */
   if (png_ptr->sig_bytes < 8)
G
Guy Schalnat 已提交
140
   {
A
Andreas Dilger 已提交
141 142
      png_size_t num_checked = png_ptr->sig_bytes,
                 num_to_check = 8 - num_checked;
A
Andreas Dilger 已提交
143

A
Andreas Dilger 已提交
144
      png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
A
Andreas Dilger 已提交
145 146 147 148 149 150 151 152 153 154
      png_ptr->sig_bytes = 8;

      if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
      {
         if (num_checked < 4 &&
             png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
            png_error(png_ptr, "Not a PNG file");
         else
            png_error(png_ptr, "PNG file corrupted by ASCII conversion");
      }
G
Guy Schalnat 已提交
155
   }
G
Guy Schalnat 已提交
156

157
   for(;;)
G
Guy Schalnat 已提交
158
   {
A
Andreas Dilger 已提交
159 160
      png_byte chunk_length[4];
      png_uint_32 length;
G
Guy Schalnat 已提交
161

A
Andreas Dilger 已提交
162 163
      png_read_data(png_ptr, chunk_length, 4);
      length = png_get_uint_32(chunk_length);
G
Guy Schalnat 已提交
164

A
Andreas Dilger 已提交
165 166 167
      png_reset_crc(png_ptr);
      png_crc_read(png_ptr, png_ptr->chunk_name, 4);

A
Andreas Dilger 已提交
168 169 170 171 172
      png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);

      /* This should be a binary subdivision search or a hash for
       * matching the chunk name rather than a linear search.
       */
A
Andreas Dilger 已提交
173 174 175 176 177 178
      if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
         png_handle_IHDR(png_ptr, info_ptr, length);
      else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
         png_handle_PLTE(png_ptr, info_ptr, length);
      else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
         png_handle_IEND(png_ptr, info_ptr, length);
A
Andreas Dilger 已提交
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
      else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
      {
         if (!(png_ptr->mode & PNG_HAVE_IHDR))
            png_error(png_ptr, "Missing IHDR before IDAT");
         else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
                  !(png_ptr->mode & PNG_HAVE_PLTE))
            png_error(png_ptr, "Missing PLTE before IDAT");

         png_ptr->idat_size = length;
         png_ptr->mode |= PNG_HAVE_IDAT;
         break;
      }
#if defined(PNG_READ_bKGD_SUPPORTED)
      else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
         png_handle_bKGD(png_ptr, info_ptr, length);
G
Guy Schalnat 已提交
194 195
#endif
#if defined(PNG_READ_cHRM_SUPPORTED)
A
Andreas Dilger 已提交
196 197
      else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
         png_handle_cHRM(png_ptr, info_ptr, length);
G
Guy Schalnat 已提交
198
#endif
A
Andreas Dilger 已提交
199 200 201
#if defined(PNG_READ_gAMA_SUPPORTED)
      else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
         png_handle_gAMA(png_ptr, info_ptr, length);
G
Guy Schalnat 已提交
202 203
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
A
Andreas Dilger 已提交
204 205
      else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
         png_handle_hIST(png_ptr, info_ptr, length);
G
Guy Schalnat 已提交
206
#endif
A
Andreas Dilger 已提交
207 208 209 210 211 212 213 214
#if defined(PNG_READ_oFFs_SUPPORTED)
      else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
         png_handle_oFFs(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
      else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
         png_handle_pCAL(png_ptr, info_ptr, length);
#endif
G
Guy Schalnat 已提交
215
#if defined(PNG_READ_pHYs_SUPPORTED)
A
Andreas Dilger 已提交
216 217
      else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
         png_handle_pHYs(png_ptr, info_ptr, length);
G
Guy Schalnat 已提交
218
#endif
A
Andreas Dilger 已提交
219 220 221 222
#if defined(PNG_READ_sBIT_SUPPORTED)
      else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
         png_handle_sBIT(png_ptr, info_ptr, length);
#endif
223 224 225 226
#if defined(PNG_READ_sRGB_SUPPORTED)
      else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
         png_handle_sRGB(png_ptr, info_ptr, length);
#endif
A
Andreas Dilger 已提交
227 228 229
#if defined(PNG_READ_tEXt_SUPPORTED)
      else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
         png_handle_tEXt(png_ptr, info_ptr, length);
G
Guy Schalnat 已提交
230 231
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
A
Andreas Dilger 已提交
232 233
      else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
         png_handle_tIME(png_ptr, info_ptr, length);
G
Guy Schalnat 已提交
234
#endif
A
Andreas Dilger 已提交
235 236 237
#if defined(PNG_READ_tRNS_SUPPORTED)
      else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
         png_handle_tRNS(png_ptr, info_ptr, length);
G
Guy Schalnat 已提交
238 239
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
A
Andreas Dilger 已提交
240 241
      else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
         png_handle_zTXt(png_ptr, info_ptr, length);
G
Guy Schalnat 已提交
242
#endif
A
Andreas Dilger 已提交
243 244
      else
         png_handle_unknown(png_ptr, info_ptr, length);
G
Guy Schalnat 已提交
245 246 247
   }
}

A
Andreas Dilger 已提交
248
/* optional call to update the users info_ptr structure */
G
Guy Schalnat 已提交
249
void
A
Andreas Dilger 已提交
250
png_read_update_info(png_structp png_ptr, png_infop info_ptr)
G
Guy Schalnat 已提交
251
{
A
Andreas Dilger 已提交
252 253
   png_debug(1, "in png_read_update_info\n");
   /* save jump buffer and error functions */
G
Guy Schalnat 已提交
254
   if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
G
Guy Schalnat 已提交
255
      png_read_start_row(png_ptr);
A
Andreas Dilger 已提交
256
   png_read_transform_info(png_ptr, info_ptr);
G
Guy Schalnat 已提交
257 258
}

259 260 261 262 263
/* Initialize palette, background, etc, after transformations
 * are set, but before any reading takes place.  This allows
 * the user to obtail a gamma corrected palette, for example.
 * If the user doesn't call this, we will do it ourselves.
 */
G
Guy Schalnat 已提交
264
void
G
Guy Schalnat 已提交
265
png_start_read_image(png_structp png_ptr)
G
Guy Schalnat 已提交
266
{
A
Andreas Dilger 已提交
267 268
   png_debug(1, "in png_start_read_image\n");
   /* save jump buffer and error functions */
G
Guy Schalnat 已提交
269
   if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
G
Guy Schalnat 已提交
270
      png_read_start_row(png_ptr);
G
Guy Schalnat 已提交
271 272 273
}

void
G
Guy Schalnat 已提交
274
png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
G
Guy Schalnat 已提交
275 276
{
   int ret;
A
Andreas Dilger 已提交
277 278 279
   png_debug2(1, "in png_read_row (row %d, pass %d)\n",
      png_ptr->row_number, png_ptr->pass);
   /* save jump buffer and error functions */
G
Guy Schalnat 已提交
280
   if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
G
Guy Schalnat 已提交
281
      png_read_start_row(png_ptr);
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
   if (png_ptr->row_number == 0 && png_ptr->pass == 0)
   {
   /* check for transforms that have been set but were defined out */
#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
   if (png_ptr->transformations & PNG_INVERT_MONO)
      png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
   if (png_ptr->transformations & PNG_FILLER)
      png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
   if (png_ptr->transformations & PNG_PACKSWAP)
      png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
   if (png_ptr->transformations & PNG_PACK)
      png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
   if (png_ptr->transformations & PNG_SHIFT)
      png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
   if (png_ptr->transformations & PNG_BGR)
      png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
   if (png_ptr->transformations & PNG_SWAP_BYTES)
      png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
#endif
   }
G
Guy Schalnat 已提交
314

G
Guy Schalnat 已提交
315
#if defined(PNG_READ_INTERLACING_SUPPORTED)
G
Guy Schalnat 已提交
316 317 318 319 320 321 322 323
   /* if interlaced and we do not need a new row, combine row and return */
   if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
   {
      switch (png_ptr->pass)
      {
         case 0:
            if (png_ptr->row_number & 7)
            {
A
Andreas Dilger 已提交
324
               if (dsp_row != NULL)
G
Guy Schalnat 已提交
325 326
                  png_combine_row(png_ptr, dsp_row,
                     png_pass_dsp_mask[png_ptr->pass]);
G
Guy Schalnat 已提交
327
               png_read_finish_row(png_ptr);
G
Guy Schalnat 已提交
328 329 330 331 332 333
               return;
            }
            break;
         case 1:
            if ((png_ptr->row_number & 7) || png_ptr->width < 5)
            {
A
Andreas Dilger 已提交
334
               if (dsp_row != NULL)
G
Guy Schalnat 已提交
335 336 337 338 339 340 341 342 343
                  png_combine_row(png_ptr, dsp_row,
                     png_pass_dsp_mask[png_ptr->pass]);
               png_read_finish_row(png_ptr);
               return;
            }
            break;
         case 2:
            if ((png_ptr->row_number & 7) != 4)
            {
A
Andreas Dilger 已提交
344
               if (dsp_row != NULL && (png_ptr->row_number & 4))
G
Guy Schalnat 已提交
345
                  png_combine_row(png_ptr, dsp_row,
G
Guy Schalnat 已提交
346 347 348 349 350 351 352 353
                     png_pass_dsp_mask[png_ptr->pass]);
               png_read_finish_row(png_ptr);
               return;
            }
            break;
         case 3:
            if ((png_ptr->row_number & 3) || png_ptr->width < 3)
            {
A
Andreas Dilger 已提交
354
               if (dsp_row != NULL)
G
Guy Schalnat 已提交
355 356 357 358 359 360 361 362
                  png_combine_row(png_ptr, dsp_row,
                     png_pass_dsp_mask[png_ptr->pass]);
               png_read_finish_row(png_ptr);
               return;
            }
            break;
         case 4:
            if ((png_ptr->row_number & 3) != 2)
G
Guy Schalnat 已提交
363
            {
A
Andreas Dilger 已提交
364
               if (dsp_row != NULL && (png_ptr->row_number & 2))
G
Guy Schalnat 已提交
365 366 367 368 369 370 371 372 373
                  png_combine_row(png_ptr, dsp_row,
                     png_pass_dsp_mask[png_ptr->pass]);
               png_read_finish_row(png_ptr);
               return;
            }
            break;
         case 5:
            if ((png_ptr->row_number & 1) || png_ptr->width < 2)
            {
A
Andreas Dilger 已提交
374
               if (dsp_row != NULL)
G
Guy Schalnat 已提交
375 376 377 378 379 380
                  png_combine_row(png_ptr, dsp_row,
                     png_pass_dsp_mask[png_ptr->pass]);
               png_read_finish_row(png_ptr);
               return;
            }
            break;
G
Guy Schalnat 已提交
381
         case 6:
G
Guy Schalnat 已提交
382 383 384 385 386 387 388 389
            if (!(png_ptr->row_number & 1))
            {
               png_read_finish_row(png_ptr);
               return;
            }
            break;
      }
   }
G
Guy Schalnat 已提交
390
#endif
G
Guy Schalnat 已提交
391

G
Guy Schalnat 已提交
392 393
   if (!(png_ptr->mode & PNG_HAVE_IDAT))
      png_error(png_ptr, "Invalid attempt to read row data");
G
Guy Schalnat 已提交
394

A
Andreas Dilger 已提交
395 396
   png_ptr->zstream.next_out = png_ptr->row_buf;
   png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
G
Guy Schalnat 已提交
397 398
   do
   {
A
Andreas Dilger 已提交
399
      if (!(png_ptr->zstream.avail_in))
G
Guy Schalnat 已提交
400 401 402
      {
         while (!png_ptr->idat_size)
         {
A
Andreas Dilger 已提交
403
            png_byte chunk_length[4];
G
Guy Schalnat 已提交
404

A
Andreas Dilger 已提交
405
            png_crc_finish(png_ptr, 0);
G
Guy Schalnat 已提交
406

A
Andreas Dilger 已提交
407 408
            png_read_data(png_ptr, chunk_length, 4);
            png_ptr->idat_size = png_get_uint_32(chunk_length);
G
Guy Schalnat 已提交
409

A
Andreas Dilger 已提交
410 411 412 413
            png_reset_crc(png_ptr);
            png_crc_read(png_ptr, png_ptr->chunk_name, 4);
            if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
               png_error(png_ptr, "Not enough image data");
G
Guy Schalnat 已提交
414
         }
A
Andreas Dilger 已提交
415 416
         png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
         png_ptr->zstream.next_in = png_ptr->zbuf;
G
Guy Schalnat 已提交
417
         if (png_ptr->zbuf_size > png_ptr->idat_size)
A
Andreas Dilger 已提交
418
            png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
A
Andreas Dilger 已提交
419 420
         png_crc_read(png_ptr, png_ptr->zbuf,
            (png_size_t)png_ptr->zstream.avail_in);
A
Andreas Dilger 已提交
421
         png_ptr->idat_size -= png_ptr->zstream.avail_in;
G
Guy Schalnat 已提交
422
      }
A
Andreas Dilger 已提交
423
      ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
G
Guy Schalnat 已提交
424 425
      if (ret == Z_STREAM_END)
      {
A
Andreas Dilger 已提交
426
         if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
G
Guy Schalnat 已提交
427
            png_ptr->idat_size)
G
Guy Schalnat 已提交
428
            png_error(png_ptr, "Extra compressed data");
A
Andreas Dilger 已提交
429
         png_ptr->mode |= PNG_AFTER_IDAT;
G
Guy Schalnat 已提交
430
         png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
G
Guy Schalnat 已提交
431
         break;
G
Guy Schalnat 已提交
432 433
      }
      if (ret != Z_OK)
A
Andreas Dilger 已提交
434
         png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
G
Guy Schalnat 已提交
435
                   "Decompression error");
A
Andreas Dilger 已提交
436 437

   } while (png_ptr->zstream.avail_out);
G
Guy Schalnat 已提交
438 439 440 441 442 443

   png_ptr->row_info.color_type = png_ptr->color_type;
   png_ptr->row_info.width = png_ptr->iwidth;
   png_ptr->row_info.channels = png_ptr->channels;
   png_ptr->row_info.bit_depth = png_ptr->bit_depth;
   png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
444 445 446 447
   {
      png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
         (png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
   }
G
Guy Schalnat 已提交
448

G
Guy Schalnat 已提交
449 450 451
   png_read_filter_row(png_ptr, &(png_ptr->row_info),
      png_ptr->row_buf + 1, png_ptr->prev_row + 1,
      (int)(png_ptr->row_buf[0]));
G
Guy Schalnat 已提交
452

453
   png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
454
      png_ptr->rowbytes + 1);
G
Guy Schalnat 已提交
455 456 457 458

   if (png_ptr->transformations)
      png_do_read_transformations(png_ptr);

G
Guy Schalnat 已提交
459
#if defined(PNG_READ_INTERLACING_SUPPORTED)
G
Guy Schalnat 已提交
460 461 462 463 464 465
   /* blow up interlaced rows to full size */
   if (png_ptr->interlaced &&
      (png_ptr->transformations & PNG_INTERLACE))
   {
      if (png_ptr->pass < 6)
         png_do_read_interlace(&(png_ptr->row_info),
A
Andreas Dilger 已提交
466
            png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
G
Guy Schalnat 已提交
467

A
Andreas Dilger 已提交
468
      if (dsp_row != NULL)
G
Guy Schalnat 已提交
469 470
         png_combine_row(png_ptr, dsp_row,
            png_pass_dsp_mask[png_ptr->pass]);
A
Andreas Dilger 已提交
471
      if (row != NULL)
G
Guy Schalnat 已提交
472 473 474 475
         png_combine_row(png_ptr, row,
            png_pass_mask[png_ptr->pass]);
   }
   else
G
Guy Schalnat 已提交
476
#endif
G
Guy Schalnat 已提交
477
   {
A
Andreas Dilger 已提交
478
      if (row != NULL)
G
Guy Schalnat 已提交
479
         png_combine_row(png_ptr, row, 0xff);
A
Andreas Dilger 已提交
480
      if (dsp_row != NULL)
G
Guy Schalnat 已提交
481 482 483
         png_combine_row(png_ptr, dsp_row, 0xff);
   }
   png_read_finish_row(png_ptr);
484 485 486

   if (png_ptr->read_row_fn != NULL)
      (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
G
Guy Schalnat 已提交
487 488
}

A
Andreas Dilger 已提交
489
/* Read one or more rows of image data.  If the image is interlaced,
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
 * and png_set_interlace_handling() has been called, the rows need to
 * contain the contents of the rows from the previous pass.  If the
 * image has alpha or transparency, and png_handle_alpha() has been
 * called, the rows contents must be initialized to the contents of the
 * screen.
 * 
 * "row" holds the actual image, and pixels are placed in it
 * as they arrive.  If the image is displayed after each pass, it will
 * appear to "sparkle" in.  "display_row" can be used to display a
 * "chunky" progressive image, with finer detail added as it becomes
 * available.  If you do not want this "chunky" display, you may pass
 * NULL for display_row.  If you do not want the sparkle display, and
 * you have not called png_handle_alpha(), you may pass NULL for rows.
 * If you have called png_handle_alpha(), and the image has either an
 * alpha channel or a transparency chunk, you must provide a buffer for
 * rows.  In this case, you do not have to provide a display_row buffer
 * also, but you may.  If the image is not interlaced, or if you have
 * not called png_set_interlace_handling(), the display_row buffer will
 * be ignored, so pass NULL to it.
 */
G
Guy Schalnat 已提交
510

G
Guy Schalnat 已提交
511
void
G
Guy Schalnat 已提交
512
png_read_rows(png_structp png_ptr, png_bytepp row,
G
Guy Schalnat 已提交
513
   png_bytepp display_row, png_uint_32 num_rows)
G
Guy Schalnat 已提交
514
{
G
Guy Schalnat 已提交
515 516 517
   png_uint_32 i;
   png_bytepp rp;
   png_bytepp dp;
G
Guy Schalnat 已提交
518

A
Andreas Dilger 已提交
519 520
   png_debug(1, "in png_read_rows\n");
   /* save jump buffer and error functions */
G
Guy Schalnat 已提交
521 522
   rp = row;
   dp = display_row;
523
   if (rp != NULL && dp != NULL)
524 525 526 527 528 529 530
      for (i = 0; i < num_rows; i++)
      {
         png_bytep rptr = *rp++;
         png_bytep dptr = *dp++;
   
         png_read_row(png_ptr, rptr, dptr);
      }
531
   else if(rp != NULL)
532 533
      for (i = 0; i < num_rows; i++)
      {
534 535 536 537 538 539 540 541 542 543
         png_bytep rptr = *rp;
         png_read_row(png_ptr, rptr, NULL);
         rp++;
      }
   else if(dp != NULL)
      for (i = 0; i < num_rows; i++)
      {
         png_bytep dptr = *dp;
         png_read_row(png_ptr, NULL, dptr);
         dp++;
544
      }
G
Guy Schalnat 已提交
545 546
}

A
Andreas Dilger 已提交
547
/* Read the entire image.  If the image has an alpha channel or a tRNS
548 549 550 551 552 553 554 555 556
 * chunk, and you have called png_handle_alpha(), you will need to
 * initialize the image to the current image that PNG will be overlaying.
 * We set the num_rows again here, in case it was incorrectly set in
 * png_read_start_row() by a call to png_read_update_info() or
 * png_start_read_image() if png_set_interlace_handling() wasn't called
 * prior to either of these functions like it should have been.  You can
 * only call this function once.  If you desire to have an image for
 * each pass of a interlaced image, use png_read_rows() instead.
 */
G
Guy Schalnat 已提交
557
void
G
Guy Schalnat 已提交
558
png_read_image(png_structp png_ptr, png_bytepp image)
G
Guy Schalnat 已提交
559
{
560
   png_uint_32 i,image_height;
G
Guy Schalnat 已提交
561
   int pass, j;
G
Guy Schalnat 已提交
562
   png_bytepp rp;
G
Guy Schalnat 已提交
563

A
Andreas Dilger 已提交
564 565
   png_debug(1, "in png_read_image\n");
   /* save jump buffer and error functions */
G
Guy Schalnat 已提交
566
   pass = png_set_interlace_handling(png_ptr);
G
Guy Schalnat 已提交
567

568 569
   image_height=png_ptr->height;
   png_ptr->num_rows = image_height; /* Make sure this is set correctly */
G
Guy Schalnat 已提交
570

G
Guy Schalnat 已提交
571 572 573
   for (j = 0; j < pass; j++)
   {
      rp = image;
574
      for (i = 0; i < image_height; i++)
G
Guy Schalnat 已提交
575 576 577 578 579 580 581
      {
         png_read_row(png_ptr, *rp, NULL);
         rp++;
      }
   }
}

A
Andreas Dilger 已提交
582
/* Read the end of the PNG file.  Will not read past the end of the
583 584 585
 * file, will verify the end is accurate, and will read any comments
 * or time information at the end of the file, if info is not NULL.
 */
G
Guy Schalnat 已提交
586
void
A
Andreas Dilger 已提交
587
png_read_end(png_structp png_ptr, png_infop info_ptr)
G
Guy Schalnat 已提交
588
{
A
Andreas Dilger 已提交
589
   png_byte chunk_length[4];
G
Guy Schalnat 已提交
590 591
   png_uint_32 length;

A
Andreas Dilger 已提交
592 593 594
   png_debug(1, "in png_read_end\n");
   /* save jump buffer and error functions */
   png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
G
Guy Schalnat 已提交
595 596 597

   do
   {
A
Andreas Dilger 已提交
598 599
      png_read_data(png_ptr, chunk_length, 4);
      length = png_get_uint_32(chunk_length);
G
Guy Schalnat 已提交
600

A
Andreas Dilger 已提交
601 602 603
      png_reset_crc(png_ptr);
      png_crc_read(png_ptr, png_ptr->chunk_name, 4);

A
Andreas Dilger 已提交
604 605
      png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);

A
Andreas Dilger 已提交
606 607
      if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
         png_handle_IHDR(png_ptr, info_ptr, length);
A
Andreas Dilger 已提交
608 609 610 611 612 613 614 615 616 617
      else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
      {
         /* Zero length IDATs are legal after the last IDAT has been
          * read, but not after other chunks have been read.
          */
         if (length > 0 || png_ptr->mode & PNG_AFTER_IDAT)
            png_error(png_ptr, "Too many IDAT's found");
         else
            png_crc_finish(png_ptr, 0);
      }
A
Andreas Dilger 已提交
618 619
      else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
         png_handle_PLTE(png_ptr, info_ptr, length);
A
Andreas Dilger 已提交
620 621 622
      else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
         png_handle_IEND(png_ptr, info_ptr, length);
#if defined(PNG_READ_bKGD_SUPPORTED)
A
Andreas Dilger 已提交
623 624
      else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
         png_handle_bKGD(png_ptr, info_ptr, length);
A
Andreas Dilger 已提交
625 626 627 628 629 630 631 632 633 634
#endif
#if defined(PNG_READ_cHRM_SUPPORTED)
      else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
         png_handle_cHRM(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_gAMA_SUPPORTED)
      else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
         png_handle_gAMA(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
A
Andreas Dilger 已提交
635 636
      else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
         png_handle_hIST(png_ptr, info_ptr, length);
A
Andreas Dilger 已提交
637 638
#endif
#if defined(PNG_READ_oFFs_SUPPORTED)
A
Andreas Dilger 已提交
639 640
      else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
         png_handle_oFFs(png_ptr, info_ptr, length);
A
Andreas Dilger 已提交
641 642 643 644 645 646 647 648 649 650 651 652
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
      else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
         png_handle_pCAL(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_pHYs_SUPPORTED)
      else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
         png_handle_pHYs(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_sBIT_SUPPORTED)
      else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
         png_handle_sBIT(png_ptr, info_ptr, length);
G
Guy Schalnat 已提交
653
#endif
654 655 656 657
#if defined(PNG_READ_sRGB_SUPPORTED)
      else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
         png_handle_sRGB(png_ptr, info_ptr, length);
#endif
G
Guy Schalnat 已提交
658
#if defined(PNG_READ_tEXt_SUPPORTED)
A
Andreas Dilger 已提交
659 660
      else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
         png_handle_tEXt(png_ptr, info_ptr, length);
G
Guy Schalnat 已提交
661
#endif
A
Andreas Dilger 已提交
662 663 664 665 666 667 668 669
#if defined(PNG_READ_tIME_SUPPORTED)
      else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
         png_handle_tIME(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_tRNS_SUPPORTED)
      else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
         png_handle_tRNS(png_ptr, info_ptr, length);
#endif
G
Guy Schalnat 已提交
670
#if defined(PNG_READ_zTXt_SUPPORTED)
A
Andreas Dilger 已提交
671 672
      else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
         png_handle_zTXt(png_ptr, info_ptr, length);
G
Guy Schalnat 已提交
673
#endif
G
Guy Schalnat 已提交
674
      else
A
Andreas Dilger 已提交
675 676
         png_handle_unknown(png_ptr, info_ptr, length);
   } while (!(png_ptr->mode & PNG_HAVE_IEND));
G
Guy Schalnat 已提交
677 678 679 680
}

/* free all memory used by the read */
void
G
Guy Schalnat 已提交
681
png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
A
Andreas Dilger 已提交
682
   png_infopp end_info_ptr_ptr)
G
Guy Schalnat 已提交
683 684
{
   png_structp png_ptr = NULL;
A
Andreas Dilger 已提交
685
   png_infop info_ptr = NULL, end_info_ptr = NULL;
G
Guy Schalnat 已提交
686

A
Andreas Dilger 已提交
687 688 689
   png_debug(1, "in png_destroy_read_struct\n");
   /* save jump buffer and error functions */
   if (png_ptr_ptr != NULL)
G
Guy Schalnat 已提交
690 691
      png_ptr = *png_ptr_ptr;

A
Andreas Dilger 已提交
692
   if (info_ptr_ptr != NULL)
G
Guy Schalnat 已提交
693 694
      info_ptr = *info_ptr_ptr;

A
Andreas Dilger 已提交
695
   if (end_info_ptr_ptr != NULL)
A
Andreas Dilger 已提交
696
      end_info_ptr = *end_info_ptr_ptr;
G
Guy Schalnat 已提交
697

A
Andreas Dilger 已提交
698
   png_read_destroy(png_ptr, info_ptr, end_info_ptr);
G
Guy Schalnat 已提交
699

A
Andreas Dilger 已提交
700
   if (info_ptr != NULL)
G
Guy Schalnat 已提交
701
   {
702 703 704
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
      png_free(png_ptr, info_ptr->text);
#endif
A
Andreas Dilger 已提交
705
      png_destroy_struct((png_voidp)info_ptr);
G
Guy Schalnat 已提交
706 707 708
      *info_ptr_ptr = (png_infop)NULL;
   }

A
Andreas Dilger 已提交
709
   if (end_info_ptr != NULL)
G
Guy Schalnat 已提交
710
   {
711
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
712
      png_free(png_ptr, end_info_ptr->text);
713
#endif
A
Andreas Dilger 已提交
714 715
      png_destroy_struct((png_voidp)end_info_ptr);
      *end_info_ptr_ptr = (png_infop)NULL;
G
Guy Schalnat 已提交
716 717
   }

A
Andreas Dilger 已提交
718
   if (png_ptr != NULL)
G
Guy Schalnat 已提交
719
   {
A
Andreas Dilger 已提交
720
      png_destroy_struct((png_voidp)png_ptr);
G
Guy Schalnat 已提交
721 722 723 724
      *png_ptr_ptr = (png_structp)NULL;
   }
}

A
Andreas Dilger 已提交
725
/* free all memory used by the read (old method) */
G
Guy Schalnat 已提交
726
void
A
Andreas Dilger 已提交
727
png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
G
Guy Schalnat 已提交
728 729
{
   jmp_buf tmp_jmp;
G
Guy Schalnat 已提交
730 731 732
   png_error_ptr error_fn;
   png_error_ptr warning_fn;
   png_voidp error_ptr;
G
Guy Schalnat 已提交
733

A
Andreas Dilger 已提交
734 735 736
   png_debug(1, "in png_read_destroy\n");
   /* save jump buffer and error functions */
   if (info_ptr != NULL)
A
Andreas Dilger 已提交
737
      png_info_destroy(png_ptr, info_ptr);
G
Guy Schalnat 已提交
738

A
Andreas Dilger 已提交
739
   if (end_info_ptr != NULL)
A
Andreas Dilger 已提交
740
      png_info_destroy(png_ptr, end_info_ptr);
G
Guy Schalnat 已提交
741

A
Andreas Dilger 已提交
742 743 744
   png_free(png_ptr, png_ptr->zbuf);
   png_free(png_ptr, png_ptr->row_buf);
   png_free(png_ptr, png_ptr->prev_row);
G
Guy Schalnat 已提交
745
#if defined(PNG_READ_DITHER_SUPPORTED)
A
Andreas Dilger 已提交
746 747
   png_free(png_ptr, png_ptr->palette_lookup);
   png_free(png_ptr, png_ptr->dither_index);
G
Guy Schalnat 已提交
748 749
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED)
A
Andreas Dilger 已提交
750
   png_free(png_ptr, png_ptr->gamma_table);
G
Guy Schalnat 已提交
751 752
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
A
Andreas Dilger 已提交
753 754
   png_free(png_ptr, png_ptr->gamma_from_1);
   png_free(png_ptr, png_ptr->gamma_to_1);
G
Guy Schalnat 已提交
755
#endif
A
Andreas Dilger 已提交
756
   if (png_ptr->flags & PNG_FLAG_FREE_PALETTE)
757
      png_zfree(png_ptr, png_ptr->palette);
A
Andreas Dilger 已提交
758 759
   if (png_ptr->flags & PNG_FLAG_FREE_TRANS)
      png_free(png_ptr, png_ptr->trans);
G
Guy Schalnat 已提交
760
#if defined(PNG_READ_hIST_SUPPORTED)
A
Andreas Dilger 已提交
761 762
   if (png_ptr->flags & PNG_FLAG_FREE_HIST)
      png_free(png_ptr, png_ptr->hist);
G
Guy Schalnat 已提交
763 764
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED)
A
Andreas Dilger 已提交
765
   if (png_ptr->gamma_16_table != NULL)
G
Guy Schalnat 已提交
766
   {
767 768
      int i;
      int istop = (1 << (8 - png_ptr->gamma_shift));
769
      for (i = 0; i < istop; i++)
G
Guy Schalnat 已提交
770
      {
A
Andreas Dilger 已提交
771
         png_free(png_ptr, png_ptr->gamma_16_table[i]);
G
Guy Schalnat 已提交
772
      }
G
Guy Schalnat 已提交
773
   }
G
Guy Schalnat 已提交
774 775
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
A
Andreas Dilger 已提交
776
   png_free(png_ptr, png_ptr->gamma_16_table);
A
Andreas Dilger 已提交
777
   if (png_ptr->gamma_16_from_1 != NULL)
G
Guy Schalnat 已提交
778
   {
779 780
      int i;
      int istop = (1 << (8 - png_ptr->gamma_shift));
781
      for (i = 0; i < istop; i++)
G
Guy Schalnat 已提交
782
      {
A
Andreas Dilger 已提交
783
         png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
G
Guy Schalnat 已提交
784 785
      }
   }
A
Andreas Dilger 已提交
786
   png_free(png_ptr, png_ptr->gamma_16_from_1);
A
Andreas Dilger 已提交
787
   if (png_ptr->gamma_16_to_1 != NULL)
G
Guy Schalnat 已提交
788
   {
789 790
      int i;
      int istop = (1 << (8 - png_ptr->gamma_shift));
791
      for (i = 0; i < istop; i++)
G
Guy Schalnat 已提交
792
      {
A
Andreas Dilger 已提交
793
         png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
G
Guy Schalnat 已提交
794
      }
G
Guy Schalnat 已提交
795
   }
A
Andreas Dilger 已提交
796
   png_free(png_ptr, png_ptr->gamma_16_to_1);
G
Guy Schalnat 已提交
797
#endif
G
Guy Schalnat 已提交
798

A
Andreas Dilger 已提交
799
   inflateEnd(&png_ptr->zstream);
G
Guy Schalnat 已提交
800
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
A
Andreas Dilger 已提交
801
   png_free(png_ptr, png_ptr->save_buffer);
G
Guy Schalnat 已提交
802
#endif
G
Guy Schalnat 已提交
803 804 805 806

   /* Save the important info out of the png_struct, in case it is
    * being used again.
    */
G
Guy Schalnat 已提交
807
   png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
G
Guy Schalnat 已提交
808 809 810 811 812

   error_fn = png_ptr->error_fn;
   warning_fn = png_ptr->warning_fn;
   error_ptr = png_ptr->error_ptr;

G
Guy Schalnat 已提交
813
   png_memset(png_ptr, 0, sizeof (png_struct));
G
Guy Schalnat 已提交
814 815 816 817 818

   png_ptr->error_fn = error_fn;
   png_ptr->warning_fn = warning_fn;
   png_ptr->error_ptr = error_ptr;

G
Guy Schalnat 已提交
819
   png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
G
Guy Schalnat 已提交
820
}
821 822 823 824 825 826

void
png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
{
   png_ptr->read_row_fn = read_row_fn;
}