~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to frmts/png/libpng/pngread.c

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/* pngread.c - read a PNG file
3
3
 *
4
 
 * Last changed in libpng 1.2.35 [February 14, 2009]
5
 
 * For conditions of distribution and use, see copyright notice in png.h
6
 
 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
 
4
 * Last changed in libpng 1.2.44 [June 26, 2010]
 
5
 * Copyright (c) 1998-2010 Glenn Randers-Pehrson
7
6
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8
7
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
9
8
 *
 
9
 * This code is released under the libpng license.
 
10
 * For conditions of distribution and use, see the disclaimer
 
11
 * and license in png.h
 
12
 *
10
13
 * This file contains routines that an application calls directly to
11
14
 * read a PNG file or stream.
12
15
 */
13
16
 
14
17
#define PNG_INTERNAL
 
18
#define PNG_NO_PEDANTIC_WARNINGS
15
19
#include "png.h"
16
 
#if defined(PNG_READ_SUPPORTED)
 
20
#ifdef PNG_READ_SUPPORTED
 
21
 
17
22
 
18
23
/* Create a PNG structure for reading, and allocate any memory needed. */
19
24
png_structp PNGAPI
26
31
      warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
27
32
}
28
33
 
29
 
/* Alternate create PNG structure for reading, and allocate any memory needed. */
 
34
/* Alternate create PNG structure for reading, and allocate any memory
 
35
 * needed.
 
36
 */
30
37
png_structp PNGAPI
31
38
png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
32
39
   png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
48
55
   int i;
49
56
 
50
57
   png_debug(1, "in png_create_read_struct");
 
58
 
51
59
#ifdef PNG_USER_MEM_SUPPORTED
52
60
   png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
53
61
      (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
57
65
   if (png_ptr == NULL)
58
66
      return (NULL);
59
67
 
60
 
   /* added at libpng-1.2.6 */
61
 
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
62
 
   png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
63
 
   png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
 
68
   /* Added at libpng-1.2.6 */
 
69
#ifdef PNG_USER_LIMITS_SUPPORTED
 
70
   png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
 
71
   png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
 
72
#  ifdef PNG_USER_CHUNK_CACHE_MAX
 
73
   /* Added at libpng-1.2.43 and 1.4.0 */
 
74
   png_ptr->user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX;
 
75
#  endif
 
76
#  ifdef PNG_SET_USER_CHUNK_MALLOC_MAX
 
77
   /* Added at libpng-1.2.43 and 1.4.1 */
 
78
   png_ptr->user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX;
 
79
#  endif
64
80
#endif
65
81
 
66
82
#ifdef PNG_SETJMP_SUPPORTED
83
99
#ifdef USE_FAR_KEYWORD
84
100
   png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
85
101
#endif
86
 
#endif
 
102
#endif /* PNG_SETJMP_SUPPORTED */
87
103
 
88
104
#ifdef PNG_USER_MEM_SUPPORTED
89
105
   png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
93
109
 
94
110
   if (user_png_ver)
95
111
   {
96
 
     i = 0;
97
 
     do
98
 
     {
99
 
       if (user_png_ver[i] != png_libpng_ver[i])
100
 
          png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
101
 
     } while (png_libpng_ver[i++]);
102
 
   }
103
 
   else
104
 
        png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
105
 
   
106
 
 
107
 
   if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
108
 
   {
109
 
     /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
110
 
      * we must recompile any applications that use any older library version.
111
 
      * For versions after libpng 1.0, we will be compatible, so we need
112
 
      * only check the first digit.
113
 
      */
114
 
     if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
115
 
         (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
116
 
         (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
117
 
     {
118
 
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
119
 
        char msg[80];
120
 
        if (user_png_ver)
121
 
        {
122
 
          png_snprintf(msg, 80,
123
 
             "Application was compiled with png.h from libpng-%.20s",
124
 
             user_png_ver);
125
 
          png_warning(png_ptr, msg);
126
 
        }
127
 
        png_snprintf(msg, 80,
 
112
      i = 0;
 
113
      do
 
114
      {
 
115
         if (user_png_ver[i] != png_libpng_ver[i])
 
116
            png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
 
117
      } while (png_libpng_ver[i++]);
 
118
    }
 
119
    else
 
120
         png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
 
121
 
 
122
 
 
123
    if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
 
124
    {
 
125
       /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
 
126
       * we must recompile any applications that use any older library version.
 
127
       * For versions after libpng 1.0, we will be compatible, so we need
 
128
       * only check the first digit.
 
129
       */
 
130
      if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
 
131
          (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
 
132
          (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
 
133
      {
 
134
#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
 
135
         char msg[80];
 
136
         if (user_png_ver)
 
137
         {
 
138
           png_snprintf(msg, 80,
 
139
              "Application was compiled with png.h from libpng-%.20s",
 
140
              user_png_ver);
 
141
           png_warning(png_ptr, msg);
 
142
         }
 
143
         png_snprintf(msg, 80,
128
144
             "Application  is  running with png.c from libpng-%.20s",
129
 
           png_libpng_ver);
130
 
        png_warning(png_ptr, msg);
 
145
             png_libpng_ver);
 
146
         png_warning(png_ptr, msg);
131
147
#endif
132
148
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
133
 
        png_ptr->flags = 0;
 
149
         png_ptr->flags = 0;
134
150
#endif
135
 
        png_error(png_ptr,
136
 
           "Incompatible libpng version in application and library");
137
 
     }
 
151
         png_error(png_ptr,
 
152
            "Incompatible libpng version in application and library");
 
153
      }
138
154
   }
139
155
 
140
 
   /* initialize zbuf - compression buffer */
 
156
   /* Initialize zbuf - compression buffer */
141
157
   png_ptr->zbuf_size = PNG_ZBUF_SIZE;
142
158
   png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
143
159
     (png_uint_32)png_ptr->zbuf_size);
145
161
   png_ptr->zstream.zfree = png_zfree;
146
162
   png_ptr->zstream.opaque = (voidpf)png_ptr;
147
163
 
148
 
   switch (inflateInit(&png_ptr->zstream))
149
 
   {
150
 
     case Z_OK: /* Do nothing */ break;
151
 
     case Z_MEM_ERROR:
152
 
     case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
153
 
     case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
154
 
     default: png_error(png_ptr, "Unknown zlib error");
155
 
   }
 
164
      switch (inflateInit(&png_ptr->zstream))
 
165
      {
 
166
         case Z_OK: /* Do nothing */ break;
 
167
         case Z_MEM_ERROR:
 
168
         case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error");
 
169
            break;
 
170
         case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error");
 
171
            break;
 
172
         default: png_error(png_ptr, "Unknown zlib error");
 
173
      }
 
174
 
156
175
 
157
176
   png_ptr->zstream.next_out = png_ptr->zbuf;
158
177
   png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
160
179
   png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
161
180
 
162
181
#ifdef PNG_SETJMP_SUPPORTED
163
 
/* Applications that neglect to set up their own setjmp() and then encounter
164
 
   a png_error() will longjmp here.  Since the jmpbuf is then meaningless we
165
 
   abort instead of returning. */
 
182
/* Applications that neglect to set up their own setjmp() and then
 
183
   encounter a png_error() will longjmp here.  Since the jmpbuf is
 
184
   then meaningless we abort instead of returning. */
166
185
#ifdef USE_FAR_KEYWORD
167
186
   if (setjmp(jmpbuf))
168
 
      PNG_ABORT();
 
187
       PNG_ABORT();
169
188
   png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
170
189
#else
171
190
   if (setjmp(png_ptr->jmpbuf))
172
 
      PNG_ABORT();
173
 
#endif
174
 
#endif
 
191
       PNG_ABORT();
 
192
#endif
 
193
#endif /* PNG_SETJMP_SUPPORTED */
 
194
 
175
195
   return (png_ptr);
176
196
}
177
197
 
178
198
#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
179
199
/* Initialize PNG structure for reading, and allocate any memory needed.
180
 
   This interface is deprecated in favour of the png_create_read_struct(),
181
 
   and it will disappear as of libpng-1.3.0. */
 
200
 * This interface is deprecated in favour of the png_create_read_struct(),
 
201
 * and it will disappear as of libpng-1.3.0.
 
202
 */
182
203
#undef png_read_init
183
204
void PNGAPI
184
205
png_read_init(png_structp png_ptr)
192
213
   png_size_t png_struct_size, png_size_t png_info_size)
193
214
{
194
215
   /* We only come here via pre-1.0.12-compiled applications */
195
 
   if (png_ptr == NULL) return;
196
 
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
 
216
   if (png_ptr == NULL)
 
217
      return;
 
218
#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
197
219
   if (png_sizeof(png_struct) > png_struct_size ||
198
220
      png_sizeof(png_info) > png_info_size)
199
221
   {
213
235
   }
214
236
#endif
215
237
   if (png_sizeof(png_struct) > png_struct_size)
216
 
     {
217
 
       png_ptr->error_fn = NULL;
 
238
   {
 
239
      png_ptr->error_fn = NULL;
218
240
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
219
 
       png_ptr->flags = 0;
 
241
      png_ptr->flags = 0;
220
242
#endif
221
 
       png_error(png_ptr,
222
 
       "The png struct allocated by the application for reading is too small.");
223
 
     }
 
243
      png_error(png_ptr,
 
244
      "The png struct allocated by the application for reading is"
 
245
      " too small.");
 
246
   }
224
247
   if (png_sizeof(png_info) > png_info_size)
225
 
     {
226
 
       png_ptr->error_fn = NULL;
 
248
   {
 
249
      png_ptr->error_fn = NULL;
227
250
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
228
 
       png_ptr->flags = 0;
 
251
      png_ptr->flags = 0;
229
252
#endif
230
 
       png_error(png_ptr,
231
 
         "The info struct allocated by application for reading is too small.");
232
 
     }
 
253
      png_error(png_ptr,
 
254
        "The info struct allocated by application for reading is"
 
255
        " too small.");
 
256
   }
233
257
   png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
234
258
}
235
259
#endif /* PNG_1_0_X || PNG_1_2_X */
246
270
 
247
271
   png_structp png_ptr=*ptr_ptr;
248
272
 
249
 
   if (png_ptr == NULL) return;
 
273
   if (png_ptr == NULL)
 
274
      return;
250
275
 
251
276
   do
252
277
   {
253
 
     if (user_png_ver[i] != png_libpng_ver[i])
254
 
     {
 
278
      if (user_png_ver[i] != png_libpng_ver[i])
 
279
      {
255
280
#ifdef PNG_LEGACY_SUPPORTED
256
 
       png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
 
281
        png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
257
282
#else
258
 
       png_ptr->warning_fn = NULL;
259
 
       png_warning(png_ptr,
260
 
        "Application uses deprecated png_read_init() and should be recompiled.");
261
 
       break;
 
283
        png_ptr->warning_fn = NULL;
 
284
        png_warning(png_ptr,
 
285
         "Application uses deprecated png_read_init() and should be"
 
286
         " recompiled.");
 
287
        break;
262
288
#endif
263
 
     }
 
289
      }
264
290
   } while (png_libpng_ver[i++]);
265
291
 
266
292
   png_debug(1, "in png_read_init_3");
267
293
 
268
294
#ifdef PNG_SETJMP_SUPPORTED
269
 
   /* save jump buffer and error functions */
 
295
   /* Save jump buffer and error functions */
270
296
   png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
271
297
#endif
272
298
 
277
303
      png_ptr = *ptr_ptr;
278
304
   }
279
305
 
280
 
   /* reset all variables to 0 */
 
306
   /* Reset all variables to 0 */
281
307
   png_memset(png_ptr, 0, png_sizeof(png_struct));
282
308
 
283
309
#ifdef PNG_SETJMP_SUPPORTED
284
 
   /* restore jump buffer */
 
310
   /* Restore jump buffer */
285
311
   png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
286
312
#endif
287
313
 
288
 
   /* added at libpng-1.2.6 */
 
314
   /* Added at libpng-1.2.6 */
289
315
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
290
 
   png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
291
 
   png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
 
316
   png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
 
317
   png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
292
318
#endif
293
319
 
294
 
   /* initialize zbuf - compression buffer */
 
320
   /* Initialize zbuf - compression buffer */
295
321
   png_ptr->zbuf_size = PNG_ZBUF_SIZE;
 
322
   png_ptr->zstream.zalloc = png_zalloc;
296
323
   png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
297
324
     (png_uint_32)png_ptr->zbuf_size);
298
325
   png_ptr->zstream.zalloc = png_zalloc;
301
328
 
302
329
   switch (inflateInit(&png_ptr->zstream))
303
330
   {
304
 
     case Z_OK: /* Do nothing */ break;
305
 
     case Z_MEM_ERROR:
306
 
     case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
307
 
     case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
308
 
     default: png_error(png_ptr, "Unknown zlib error");
 
331
      case Z_OK: /* Do nothing */ break;
 
332
      case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
 
333
      case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error");
 
334
          break;
 
335
      default: png_error(png_ptr, "Unknown zlib error");
309
336
   }
310
337
 
311
338
   png_ptr->zstream.next_out = png_ptr->zbuf;
314
341
   png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
315
342
}
316
343
 
317
 
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
 
344
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
318
345
/* Read the information before the actual image data.  This has been
319
346
 * changed in v0.90 to allow reading a file that already has the magic
320
347
 * bytes read from the stream.  You can tell libpng how many bytes have
326
353
void PNGAPI
327
354
png_read_info(png_structp png_ptr, png_infop info_ptr)
328
355
{
329
 
   if (png_ptr == NULL || info_ptr == NULL) return;
330
356
   png_debug(1, "in png_read_info");
 
357
 
 
358
   if (png_ptr == NULL || info_ptr == NULL)
 
359
      return;
 
360
 
331
361
   /* If we haven't checked all of the PNG signature bytes, do so now. */
332
362
   if (png_ptr->sig_bytes < 8)
333
363
   {
356
386
      PNG_CONST PNG_IDAT;
357
387
      PNG_CONST PNG_IEND;
358
388
      PNG_CONST PNG_PLTE;
359
 
#if defined(PNG_READ_bKGD_SUPPORTED)
 
389
#ifdef PNG_READ_bKGD_SUPPORTED
360
390
      PNG_CONST PNG_bKGD;
361
391
#endif
362
 
#if defined(PNG_READ_cHRM_SUPPORTED)
 
392
#ifdef PNG_READ_cHRM_SUPPORTED
363
393
      PNG_CONST PNG_cHRM;
364
394
#endif
365
 
#if defined(PNG_READ_gAMA_SUPPORTED)
 
395
#ifdef PNG_READ_gAMA_SUPPORTED
366
396
      PNG_CONST PNG_gAMA;
367
397
#endif
368
 
#if defined(PNG_READ_hIST_SUPPORTED)
 
398
#ifdef PNG_READ_hIST_SUPPORTED
369
399
      PNG_CONST PNG_hIST;
370
400
#endif
371
 
#if defined(PNG_READ_iCCP_SUPPORTED)
 
401
#ifdef PNG_READ_iCCP_SUPPORTED
372
402
      PNG_CONST PNG_iCCP;
373
403
#endif
374
 
#if defined(PNG_READ_iTXt_SUPPORTED)
 
404
#ifdef PNG_READ_iTXt_SUPPORTED
375
405
      PNG_CONST PNG_iTXt;
376
406
#endif
377
 
#if defined(PNG_READ_oFFs_SUPPORTED)
 
407
#ifdef PNG_READ_oFFs_SUPPORTED
378
408
      PNG_CONST PNG_oFFs;
379
409
#endif
380
 
#if defined(PNG_READ_pCAL_SUPPORTED)
 
410
#ifdef PNG_READ_pCAL_SUPPORTED
381
411
      PNG_CONST PNG_pCAL;
382
412
#endif
383
 
#if defined(PNG_READ_pHYs_SUPPORTED)
 
413
#ifdef PNG_READ_pHYs_SUPPORTED
384
414
      PNG_CONST PNG_pHYs;
385
415
#endif
386
 
#if defined(PNG_READ_sBIT_SUPPORTED)
 
416
#ifdef PNG_READ_sBIT_SUPPORTED
387
417
      PNG_CONST PNG_sBIT;
388
418
#endif
389
 
#if defined(PNG_READ_sCAL_SUPPORTED)
 
419
#ifdef PNG_READ_sCAL_SUPPORTED
390
420
      PNG_CONST PNG_sCAL;
391
421
#endif
392
 
#if defined(PNG_READ_sPLT_SUPPORTED)
 
422
#ifdef PNG_READ_sPLT_SUPPORTED
393
423
      PNG_CONST PNG_sPLT;
394
424
#endif
395
 
#if defined(PNG_READ_sRGB_SUPPORTED)
 
425
#ifdef PNG_READ_sRGB_SUPPORTED
396
426
      PNG_CONST PNG_sRGB;
397
427
#endif
398
 
#if defined(PNG_READ_tEXt_SUPPORTED)
 
428
#ifdef PNG_READ_tEXt_SUPPORTED
399
429
      PNG_CONST PNG_tEXt;
400
430
#endif
401
 
#if defined(PNG_READ_tIME_SUPPORTED)
 
431
#ifdef PNG_READ_tIME_SUPPORTED
402
432
      PNG_CONST PNG_tIME;
403
433
#endif
404
 
#if defined(PNG_READ_tRNS_SUPPORTED)
 
434
#ifdef PNG_READ_tRNS_SUPPORTED
405
435
      PNG_CONST PNG_tRNS;
406
436
#endif
407
 
#if defined(PNG_READ_zTXt_SUPPORTED)
 
437
#ifdef PNG_READ_zTXt_SUPPORTED
408
438
      PNG_CONST PNG_zTXt;
409
439
#endif
410
440
#endif /* PNG_USE_LOCAL_ARRAYS */
455
485
         png_ptr->mode |= PNG_HAVE_IDAT;
456
486
         break;
457
487
      }
458
 
#if defined(PNG_READ_bKGD_SUPPORTED)
 
488
#ifdef PNG_READ_bKGD_SUPPORTED
459
489
      else if (!png_memcmp(chunk_name, png_bKGD, 4))
460
490
         png_handle_bKGD(png_ptr, info_ptr, length);
461
491
#endif
462
 
#if defined(PNG_READ_cHRM_SUPPORTED)
 
492
#ifdef PNG_READ_cHRM_SUPPORTED
463
493
      else if (!png_memcmp(chunk_name, png_cHRM, 4))
464
494
         png_handle_cHRM(png_ptr, info_ptr, length);
465
495
#endif
466
 
#if defined(PNG_READ_gAMA_SUPPORTED)
 
496
#ifdef PNG_READ_gAMA_SUPPORTED
467
497
      else if (!png_memcmp(chunk_name, png_gAMA, 4))
468
498
         png_handle_gAMA(png_ptr, info_ptr, length);
469
499
#endif
470
 
#if defined(PNG_READ_hIST_SUPPORTED)
 
500
#ifdef PNG_READ_hIST_SUPPORTED
471
501
      else if (!png_memcmp(chunk_name, png_hIST, 4))
472
502
         png_handle_hIST(png_ptr, info_ptr, length);
473
503
#endif
474
 
#if defined(PNG_READ_oFFs_SUPPORTED)
 
504
#ifdef PNG_READ_oFFs_SUPPORTED
475
505
      else if (!png_memcmp(chunk_name, png_oFFs, 4))
476
506
         png_handle_oFFs(png_ptr, info_ptr, length);
477
507
#endif
478
 
#if defined(PNG_READ_pCAL_SUPPORTED)
 
508
#ifdef PNG_READ_pCAL_SUPPORTED
479
509
      else if (!png_memcmp(chunk_name, png_pCAL, 4))
480
510
         png_handle_pCAL(png_ptr, info_ptr, length);
481
511
#endif
482
 
#if defined(PNG_READ_sCAL_SUPPORTED)
 
512
#ifdef PNG_READ_sCAL_SUPPORTED
483
513
      else if (!png_memcmp(chunk_name, png_sCAL, 4))
484
514
         png_handle_sCAL(png_ptr, info_ptr, length);
485
515
#endif
486
 
#if defined(PNG_READ_pHYs_SUPPORTED)
 
516
#ifdef PNG_READ_pHYs_SUPPORTED
487
517
      else if (!png_memcmp(chunk_name, png_pHYs, 4))
488
518
         png_handle_pHYs(png_ptr, info_ptr, length);
489
519
#endif
490
 
#if defined(PNG_READ_sBIT_SUPPORTED)
 
520
#ifdef PNG_READ_sBIT_SUPPORTED
491
521
      else if (!png_memcmp(chunk_name, png_sBIT, 4))
492
522
         png_handle_sBIT(png_ptr, info_ptr, length);
493
523
#endif
494
 
#if defined(PNG_READ_sRGB_SUPPORTED)
 
524
#ifdef PNG_READ_sRGB_SUPPORTED
495
525
      else if (!png_memcmp(chunk_name, png_sRGB, 4))
496
526
         png_handle_sRGB(png_ptr, info_ptr, length);
497
527
#endif
498
 
#if defined(PNG_READ_iCCP_SUPPORTED)
 
528
#ifdef PNG_READ_iCCP_SUPPORTED
499
529
      else if (!png_memcmp(chunk_name, png_iCCP, 4))
500
530
         png_handle_iCCP(png_ptr, info_ptr, length);
501
531
#endif
502
 
#if defined(PNG_READ_sPLT_SUPPORTED)
 
532
#ifdef PNG_READ_sPLT_SUPPORTED
503
533
      else if (!png_memcmp(chunk_name, png_sPLT, 4))
504
534
         png_handle_sPLT(png_ptr, info_ptr, length);
505
535
#endif
506
 
#if defined(PNG_READ_tEXt_SUPPORTED)
 
536
#ifdef PNG_READ_tEXt_SUPPORTED
507
537
      else if (!png_memcmp(chunk_name, png_tEXt, 4))
508
538
         png_handle_tEXt(png_ptr, info_ptr, length);
509
539
#endif
510
 
#if defined(PNG_READ_tIME_SUPPORTED)
 
540
#ifdef PNG_READ_tIME_SUPPORTED
511
541
      else if (!png_memcmp(chunk_name, png_tIME, 4))
512
542
         png_handle_tIME(png_ptr, info_ptr, length);
513
543
#endif
514
 
#if defined(PNG_READ_tRNS_SUPPORTED)
 
544
#ifdef PNG_READ_tRNS_SUPPORTED
515
545
      else if (!png_memcmp(chunk_name, png_tRNS, 4))
516
546
         png_handle_tRNS(png_ptr, info_ptr, length);
517
547
#endif
518
 
#if defined(PNG_READ_zTXt_SUPPORTED)
 
548
#ifdef PNG_READ_zTXt_SUPPORTED
519
549
      else if (!png_memcmp(chunk_name, png_zTXt, 4))
520
550
         png_handle_zTXt(png_ptr, info_ptr, length);
521
551
#endif
522
 
#if defined(PNG_READ_iTXt_SUPPORTED)
 
552
#ifdef PNG_READ_iTXt_SUPPORTED
523
553
      else if (!png_memcmp(chunk_name, png_iTXt, 4))
524
554
         png_handle_iTXt(png_ptr, info_ptr, length);
525
555
#endif
527
557
         png_handle_unknown(png_ptr, info_ptr, length);
528
558
   }
529
559
}
530
 
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
 
560
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
531
561
 
532
 
/* optional call to update the users info_ptr structure */
 
562
/* Optional call to update the users info_ptr structure */
533
563
void PNGAPI
534
564
png_read_update_info(png_structp png_ptr, png_infop info_ptr)
535
565
{
536
566
   png_debug(1, "in png_read_update_info");
537
 
   if (png_ptr == NULL) return;
 
567
 
 
568
   if (png_ptr == NULL)
 
569
      return;
538
570
   if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
539
571
      png_read_start_row(png_ptr);
540
572
   else
541
573
      png_warning(png_ptr,
542
574
      "Ignoring extra png_read_update_info() call; row buffer not reallocated");
 
575
 
543
576
   png_read_transform_info(png_ptr, info_ptr);
544
577
}
545
578
 
546
 
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
 
579
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
547
580
/* Initialize palette, background, etc, after transformations
548
581
 * are set, but before any reading takes place.  This allows
549
582
 * the user to obtain a gamma-corrected palette, for example.
553
586
png_start_read_image(png_structp png_ptr)
554
587
{
555
588
   png_debug(1, "in png_start_read_image");
556
 
   if (png_ptr == NULL) return;
 
589
 
 
590
   if (png_ptr == NULL)
 
591
      return;
557
592
   if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
558
593
      png_read_start_row(png_ptr);
559
594
}
560
 
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
 
595
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
561
596
 
562
 
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
 
597
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
563
598
void PNGAPI
564
599
png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
565
600
{
566
 
#ifdef PNG_USE_LOCAL_ARRAYS
567
601
   PNG_CONST PNG_IDAT;
568
602
   PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
569
603
      0xff};
570
604
   PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
571
 
#endif
572
605
   int ret;
573
 
   if (png_ptr == NULL) return;
 
606
 
 
607
   if (png_ptr == NULL)
 
608
      return;
 
609
 
574
610
   png_debug2(1, "in png_read_row (row %lu, pass %d)",
575
611
      png_ptr->row_number, png_ptr->pass);
 
612
 
576
613
   if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
577
614
      png_read_start_row(png_ptr);
578
615
   if (png_ptr->row_number == 0 && png_ptr->pass == 0)
579
616
   {
580
 
   /* check for transforms that have been set but were defined out */
 
617
   /* Check for transforms that have been set but were defined out */
581
618
#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
582
619
   if (png_ptr->transformations & PNG_INVERT_MONO)
583
620
      png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
586
623
   if (png_ptr->transformations & PNG_FILLER)
587
624
      png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
588
625
#endif
589
 
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
 
626
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \
 
627
    !defined(PNG_READ_PACKSWAP_SUPPORTED)
590
628
   if (png_ptr->transformations & PNG_PACKSWAP)
591
629
      png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
592
630
#endif
608
646
#endif
609
647
   }
610
648
 
611
 
#if defined(PNG_READ_INTERLACING_SUPPORTED)
612
 
   /* if interlaced and we do not need a new row, combine row and return */
 
649
#ifdef PNG_READ_INTERLACING_SUPPORTED
 
650
   /* If interlaced and we do not need a new row, combine row and return */
613
651
   if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
614
652
   {
615
653
      switch (png_ptr->pass)
689
727
      png_error(png_ptr, "Invalid attempt to read row data");
690
728
 
691
729
   png_ptr->zstream.next_out = png_ptr->row_buf;
692
 
   png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
 
730
   png_ptr->zstream.avail_out =
 
731
       (uInt)(PNG_ROWBYTES(png_ptr->pixel_depth,
 
732
       png_ptr->iwidth) + 1);
693
733
   do
694
734
   {
695
735
      if (!(png_ptr->zstream.avail_in))
742
782
   png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
743
783
      png_ptr->rowbytes + 1);
744
784
 
745
 
#if defined(PNG_MNG_FEATURES_SUPPORTED)
 
785
#ifdef PNG_MNG_FEATURES_SUPPORTED
746
786
   if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
747
787
      (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
748
788
   {
755
795
   if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
756
796
      png_do_read_transformations(png_ptr);
757
797
 
758
 
#if defined(PNG_READ_INTERLACING_SUPPORTED)
759
 
   /* blow up interlaced rows to full size */
 
798
#ifdef PNG_READ_INTERLACING_SUPPORTED
 
799
   /* Blow up interlaced rows to full size */
760
800
   if (png_ptr->interlaced &&
761
801
      (png_ptr->transformations & PNG_INTERLACE))
762
802
   {
763
803
      if (png_ptr->pass < 6)
764
 
/*       old interface (pre-1.0.9):
765
 
         png_do_read_interlace(&(png_ptr->row_info),
766
 
            png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
767
 
 */
 
804
         /* Old interface (pre-1.0.9):
 
805
          * png_do_read_interlace(&(png_ptr->row_info),
 
806
          *    png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
 
807
          */
768
808
         png_do_read_interlace(png_ptr);
769
809
 
770
810
      if (dsp_row != NULL)
787
827
   if (png_ptr->read_row_fn != NULL)
788
828
      (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
789
829
}
790
 
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
 
830
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
791
831
 
792
 
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
 
832
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
793
833
/* Read one or more rows of image data.  If the image is interlaced,
794
834
 * and png_set_interlace_handling() has been called, the rows need to
795
835
 * contain the contents of the rows from the previous pass.  If the
823
863
   png_bytepp dp;
824
864
 
825
865
   png_debug(1, "in png_read_rows");
826
 
   if (png_ptr == NULL) return;
 
866
 
 
867
   if (png_ptr == NULL)
 
868
      return;
827
869
   rp = row;
828
870
   dp = display_row;
829
871
   if (rp != NULL && dp != NULL)
849
891
         dp++;
850
892
      }
851
893
}
852
 
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
 
894
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
853
895
 
854
 
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
 
896
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
855
897
/* Read the entire image.  If the image has an alpha channel or a tRNS
856
898
 * chunk, and you have called png_handle_alpha()[*], you will need to
857
899
 * initialize the image to the current image that PNG will be overlaying.
872
914
   png_bytepp rp;
873
915
 
874
916
   png_debug(1, "in png_read_image");
875
 
   if (png_ptr == NULL) return;
 
917
 
 
918
   if (png_ptr == NULL)
 
919
      return;
876
920
 
877
921
#ifdef PNG_READ_INTERLACING_SUPPORTED
878
922
   pass = png_set_interlace_handling(png_ptr);
897
941
      }
898
942
   }
899
943
}
900
 
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
 
944
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
901
945
 
902
 
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
 
946
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
903
947
/* Read the end of the PNG file.  Will not read past the end of the
904
948
 * file, will verify the end is accurate, and will read any comments
905
949
 * or time information at the end of the file, if info is not NULL.
908
952
png_read_end(png_structp png_ptr, png_infop info_ptr)
909
953
{
910
954
   png_debug(1, "in png_read_end");
911
 
   if (png_ptr == NULL) return;
 
955
 
 
956
   if (png_ptr == NULL)
 
957
      return;
912
958
   png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
913
959
 
914
960
   do
918
964
      PNG_CONST PNG_IDAT;
919
965
      PNG_CONST PNG_IEND;
920
966
      PNG_CONST PNG_PLTE;
921
 
#if defined(PNG_READ_bKGD_SUPPORTED)
 
967
#ifdef PNG_READ_bKGD_SUPPORTED
922
968
      PNG_CONST PNG_bKGD;
923
969
#endif
924
 
#if defined(PNG_READ_cHRM_SUPPORTED)
 
970
#ifdef PNG_READ_cHRM_SUPPORTED
925
971
      PNG_CONST PNG_cHRM;
926
972
#endif
927
 
#if defined(PNG_READ_gAMA_SUPPORTED)
 
973
#ifdef PNG_READ_gAMA_SUPPORTED
928
974
      PNG_CONST PNG_gAMA;
929
975
#endif
930
 
#if defined(PNG_READ_hIST_SUPPORTED)
 
976
#ifdef PNG_READ_hIST_SUPPORTED
931
977
      PNG_CONST PNG_hIST;
932
978
#endif
933
 
#if defined(PNG_READ_iCCP_SUPPORTED)
 
979
#ifdef PNG_READ_iCCP_SUPPORTED
934
980
      PNG_CONST PNG_iCCP;
935
981
#endif
936
 
#if defined(PNG_READ_iTXt_SUPPORTED)
 
982
#ifdef PNG_READ_iTXt_SUPPORTED
937
983
      PNG_CONST PNG_iTXt;
938
984
#endif
939
 
#if defined(PNG_READ_oFFs_SUPPORTED)
 
985
#ifdef PNG_READ_oFFs_SUPPORTED
940
986
      PNG_CONST PNG_oFFs;
941
987
#endif
942
 
#if defined(PNG_READ_pCAL_SUPPORTED)
 
988
#ifdef PNG_READ_pCAL_SUPPORTED
943
989
      PNG_CONST PNG_pCAL;
944
990
#endif
945
 
#if defined(PNG_READ_pHYs_SUPPORTED)
 
991
#ifdef PNG_READ_pHYs_SUPPORTED
946
992
      PNG_CONST PNG_pHYs;
947
993
#endif
948
 
#if defined(PNG_READ_sBIT_SUPPORTED)
 
994
#ifdef PNG_READ_sBIT_SUPPORTED
949
995
      PNG_CONST PNG_sBIT;
950
996
#endif
951
 
#if defined(PNG_READ_sCAL_SUPPORTED)
 
997
#ifdef PNG_READ_sCAL_SUPPORTED
952
998
      PNG_CONST PNG_sCAL;
953
999
#endif
954
 
#if defined(PNG_READ_sPLT_SUPPORTED)
 
1000
#ifdef PNG_READ_sPLT_SUPPORTED
955
1001
      PNG_CONST PNG_sPLT;
956
1002
#endif
957
 
#if defined(PNG_READ_sRGB_SUPPORTED)
 
1003
#ifdef PNG_READ_sRGB_SUPPORTED
958
1004
      PNG_CONST PNG_sRGB;
959
1005
#endif
960
 
#if defined(PNG_READ_tEXt_SUPPORTED)
 
1006
#ifdef PNG_READ_tEXt_SUPPORTED
961
1007
      PNG_CONST PNG_tEXt;
962
1008
#endif
963
 
#if defined(PNG_READ_tIME_SUPPORTED)
 
1009
#ifdef PNG_READ_tIME_SUPPORTED
964
1010
      PNG_CONST PNG_tIME;
965
1011
#endif
966
 
#if defined(PNG_READ_tRNS_SUPPORTED)
 
1012
#ifdef PNG_READ_tRNS_SUPPORTED
967
1013
      PNG_CONST PNG_tRNS;
968
1014
#endif
969
 
#if defined(PNG_READ_zTXt_SUPPORTED)
 
1015
#ifdef PNG_READ_zTXt_SUPPORTED
970
1016
      PNG_CONST PNG_zTXt;
971
1017
#endif
972
1018
#endif /* PNG_USE_LOCAL_ARRAYS */
1001
1047
      }
1002
1048
      else if (!png_memcmp(chunk_name, png_PLTE, 4))
1003
1049
         png_handle_PLTE(png_ptr, info_ptr, length);
1004
 
#if defined(PNG_READ_bKGD_SUPPORTED)
 
1050
#ifdef PNG_READ_bKGD_SUPPORTED
1005
1051
      else if (!png_memcmp(chunk_name, png_bKGD, 4))
1006
1052
         png_handle_bKGD(png_ptr, info_ptr, length);
1007
1053
#endif
1008
 
#if defined(PNG_READ_cHRM_SUPPORTED)
 
1054
#ifdef PNG_READ_cHRM_SUPPORTED
1009
1055
      else if (!png_memcmp(chunk_name, png_cHRM, 4))
1010
1056
         png_handle_cHRM(png_ptr, info_ptr, length);
1011
1057
#endif
1012
 
#if defined(PNG_READ_gAMA_SUPPORTED)
 
1058
#ifdef PNG_READ_gAMA_SUPPORTED
1013
1059
      else if (!png_memcmp(chunk_name, png_gAMA, 4))
1014
1060
         png_handle_gAMA(png_ptr, info_ptr, length);
1015
1061
#endif
1016
 
#if defined(PNG_READ_hIST_SUPPORTED)
 
1062
#ifdef PNG_READ_hIST_SUPPORTED
1017
1063
      else if (!png_memcmp(chunk_name, png_hIST, 4))
1018
1064
         png_handle_hIST(png_ptr, info_ptr, length);
1019
1065
#endif
1020
 
#if defined(PNG_READ_oFFs_SUPPORTED)
 
1066
#ifdef PNG_READ_oFFs_SUPPORTED
1021
1067
      else if (!png_memcmp(chunk_name, png_oFFs, 4))
1022
1068
         png_handle_oFFs(png_ptr, info_ptr, length);
1023
1069
#endif
1024
 
#if defined(PNG_READ_pCAL_SUPPORTED)
 
1070
#ifdef PNG_READ_pCAL_SUPPORTED
1025
1071
      else if (!png_memcmp(chunk_name, png_pCAL, 4))
1026
1072
         png_handle_pCAL(png_ptr, info_ptr, length);
1027
1073
#endif
1028
 
#if defined(PNG_READ_sCAL_SUPPORTED)
 
1074
#ifdef PNG_READ_sCAL_SUPPORTED
1029
1075
      else if (!png_memcmp(chunk_name, png_sCAL, 4))
1030
1076
         png_handle_sCAL(png_ptr, info_ptr, length);
1031
1077
#endif
1032
 
#if defined(PNG_READ_pHYs_SUPPORTED)
 
1078
#ifdef PNG_READ_pHYs_SUPPORTED
1033
1079
      else if (!png_memcmp(chunk_name, png_pHYs, 4))
1034
1080
         png_handle_pHYs(png_ptr, info_ptr, length);
1035
1081
#endif
1036
 
#if defined(PNG_READ_sBIT_SUPPORTED)
 
1082
#ifdef PNG_READ_sBIT_SUPPORTED
1037
1083
      else if (!png_memcmp(chunk_name, png_sBIT, 4))
1038
1084
         png_handle_sBIT(png_ptr, info_ptr, length);
1039
1085
#endif
1040
 
#if defined(PNG_READ_sRGB_SUPPORTED)
 
1086
#ifdef PNG_READ_sRGB_SUPPORTED
1041
1087
      else if (!png_memcmp(chunk_name, png_sRGB, 4))
1042
1088
         png_handle_sRGB(png_ptr, info_ptr, length);
1043
1089
#endif
1044
 
#if defined(PNG_READ_iCCP_SUPPORTED)
 
1090
#ifdef PNG_READ_iCCP_SUPPORTED
1045
1091
      else if (!png_memcmp(chunk_name, png_iCCP, 4))
1046
1092
         png_handle_iCCP(png_ptr, info_ptr, length);
1047
1093
#endif
1048
 
#if defined(PNG_READ_sPLT_SUPPORTED)
 
1094
#ifdef PNG_READ_sPLT_SUPPORTED
1049
1095
      else if (!png_memcmp(chunk_name, png_sPLT, 4))
1050
1096
         png_handle_sPLT(png_ptr, info_ptr, length);
1051
1097
#endif
1052
 
#if defined(PNG_READ_tEXt_SUPPORTED)
 
1098
#ifdef PNG_READ_tEXt_SUPPORTED
1053
1099
      else if (!png_memcmp(chunk_name, png_tEXt, 4))
1054
1100
         png_handle_tEXt(png_ptr, info_ptr, length);
1055
1101
#endif
1056
 
#if defined(PNG_READ_tIME_SUPPORTED)
 
1102
#ifdef PNG_READ_tIME_SUPPORTED
1057
1103
      else if (!png_memcmp(chunk_name, png_tIME, 4))
1058
1104
         png_handle_tIME(png_ptr, info_ptr, length);
1059
1105
#endif
1060
 
#if defined(PNG_READ_tRNS_SUPPORTED)
 
1106
#ifdef PNG_READ_tRNS_SUPPORTED
1061
1107
      else if (!png_memcmp(chunk_name, png_tRNS, 4))
1062
1108
         png_handle_tRNS(png_ptr, info_ptr, length);
1063
1109
#endif
1064
 
#if defined(PNG_READ_zTXt_SUPPORTED)
 
1110
#ifdef PNG_READ_zTXt_SUPPORTED
1065
1111
      else if (!png_memcmp(chunk_name, png_zTXt, 4))
1066
1112
         png_handle_zTXt(png_ptr, info_ptr, length);
1067
1113
#endif
1068
 
#if defined(PNG_READ_iTXt_SUPPORTED)
 
1114
#ifdef PNG_READ_iTXt_SUPPORTED
1069
1115
      else if (!png_memcmp(chunk_name, png_iTXt, 4))
1070
1116
         png_handle_iTXt(png_ptr, info_ptr, length);
1071
1117
#endif
1073
1119
         png_handle_unknown(png_ptr, info_ptr, length);
1074
1120
   } while (!(png_ptr->mode & PNG_HAVE_IEND));
1075
1121
}
1076
 
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
 
1122
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
1077
1123
 
1078
 
/* free all memory used by the read */
 
1124
/* Free all memory used by the read */
1079
1125
void PNGAPI
1080
1126
png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
1081
1127
   png_infopp end_info_ptr_ptr)
1088
1134
#endif
1089
1135
 
1090
1136
   png_debug(1, "in png_destroy_read_struct");
 
1137
 
1091
1138
   if (png_ptr_ptr != NULL)
1092
1139
      png_ptr = *png_ptr_ptr;
1093
1140
   if (png_ptr == NULL)
1108
1155
 
1109
1156
   if (info_ptr != NULL)
1110
1157
   {
1111
 
#if defined(PNG_TEXT_SUPPORTED)
 
1158
#ifdef PNG_TEXT_SUPPORTED
1112
1159
      png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
1113
1160
#endif
1114
1161
 
1123
1170
 
1124
1171
   if (end_info_ptr != NULL)
1125
1172
   {
1126
 
#if defined(PNG_READ_TEXT_SUPPORTED)
 
1173
#ifdef PNG_READ_TEXT_SUPPORTED
1127
1174
      png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
1128
1175
#endif
1129
1176
#ifdef PNG_USER_MEM_SUPPORTED
1147
1194
   }
1148
1195
}
1149
1196
 
1150
 
/* free all memory used by the read (old method) */
 
1197
/* Free all memory used by the read (old method) */
1151
1198
void /* PRIVATE */
1152
 
png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
 
1199
png_read_destroy(png_structp png_ptr, png_infop info_ptr,
 
1200
    png_infop end_info_ptr)
1153
1201
{
1154
1202
#ifdef PNG_SETJMP_SUPPORTED
1155
1203
   jmp_buf tmp_jmp;
1162
1210
#endif
1163
1211
 
1164
1212
   png_debug(1, "in png_read_destroy");
 
1213
 
1165
1214
   if (info_ptr != NULL)
1166
1215
      png_info_destroy(png_ptr, info_ptr);
1167
1216
 
1172
1221
   png_free(png_ptr, png_ptr->big_row_buf);
1173
1222
   png_free(png_ptr, png_ptr->prev_row);
1174
1223
   png_free(png_ptr, png_ptr->chunkdata);
1175
 
#if defined(PNG_READ_DITHER_SUPPORTED)
 
1224
#ifdef PNG_READ_DITHER_SUPPORTED
1176
1225
   png_free(png_ptr, png_ptr->palette_lookup);
1177
1226
   png_free(png_ptr, png_ptr->dither_index);
1178
1227
#endif
1179
 
#if defined(PNG_READ_GAMMA_SUPPORTED)
 
1228
#ifdef PNG_READ_GAMMA_SUPPORTED
1180
1229
   png_free(png_ptr, png_ptr->gamma_table);
1181
1230
#endif
1182
 
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
 
1231
#ifdef PNG_READ_BACKGROUND_SUPPORTED
1183
1232
   png_free(png_ptr, png_ptr->gamma_from_1);
1184
1233
   png_free(png_ptr, png_ptr->gamma_to_1);
1185
1234
#endif
1204
1253
   png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
1205
1254
#endif
1206
1255
#endif
1207
 
#if defined(PNG_READ_hIST_SUPPORTED)
 
1256
#ifdef PNG_READ_hIST_SUPPORTED
1208
1257
#ifdef PNG_FREE_ME_SUPPORTED
1209
1258
   if (png_ptr->free_me & PNG_FREE_HIST)
1210
1259
      png_free(png_ptr, png_ptr->hist);
1215
1264
   png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
1216
1265
#endif
1217
1266
#endif
1218
 
#if defined(PNG_READ_GAMMA_SUPPORTED)
 
1267
#ifdef PNG_READ_GAMMA_SUPPORTED
1219
1268
   if (png_ptr->gamma_16_table != NULL)
1220
1269
   {
1221
1270
      int i;
1226
1275
      }
1227
1276
   png_free(png_ptr, png_ptr->gamma_16_table);
1228
1277
   }
1229
 
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
 
1278
#ifdef PNG_READ_BACKGROUND_SUPPORTED
1230
1279
   if (png_ptr->gamma_16_from_1 != NULL)
1231
1280
   {
1232
1281
      int i;
1249
1298
   }
1250
1299
#endif
1251
1300
#endif
1252
 
#if defined(PNG_TIME_RFC1123_SUPPORTED)
 
1301
#ifdef PNG_TIME_RFC1123_SUPPORTED
1253
1302
   png_free(png_ptr, png_ptr->time_buffer);
1254
1303
#endif
1255
1304
 
1296
1345
void PNGAPI
1297
1346
png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
1298
1347
{
1299
 
   if (png_ptr == NULL) return;
 
1348
   if (png_ptr == NULL)
 
1349
      return;
1300
1350
   png_ptr->read_row_fn = read_row_fn;
1301
1351
}
1302
1352
 
1303
1353
 
1304
 
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
1305
 
#if defined(PNG_INFO_IMAGE_SUPPORTED)
 
1354
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
 
1355
#ifdef PNG_INFO_IMAGE_SUPPORTED
1306
1356
void PNGAPI
1307
1357
png_read_png(png_structp png_ptr, png_infop info_ptr,
1308
1358
                           int transforms,
1310
1360
{
1311
1361
   int row;
1312
1362
 
1313
 
   if (png_ptr == NULL) return;
1314
 
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
1315
 
   /* invert the alpha channel from opacity to transparency
 
1363
   if (png_ptr == NULL)
 
1364
      return;
 
1365
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
 
1366
   /* Invert the alpha channel from opacity to transparency
1316
1367
    */
1317
1368
   if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
1318
1369
       png_set_invert_alpha(png_ptr);
1327
1378
 
1328
1379
   /* -------------- image transformations start here ------------------- */
1329
1380
 
1330
 
#if defined(PNG_READ_16_TO_8_SUPPORTED)
1331
 
   /* tell libpng to strip 16 bit/color files down to 8 bits per color
 
1381
#ifdef PNG_READ_16_TO_8_SUPPORTED
 
1382
   /* Tell libpng to strip 16 bit/color files down to 8 bits per color.
1332
1383
    */
1333
1384
   if (transforms & PNG_TRANSFORM_STRIP_16)
1334
 
       png_set_strip_16(png_ptr);
 
1385
      png_set_strip_16(png_ptr);
1335
1386
#endif
1336
1387
 
1337
 
#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
 
1388
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
1338
1389
   /* Strip alpha bytes from the input data without combining with
1339
1390
    * the background (not recommended).
1340
1391
    */
1341
1392
   if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
1342
 
       png_set_strip_alpha(png_ptr);
 
1393
      png_set_strip_alpha(png_ptr);
1343
1394
#endif
1344
1395
 
1345
1396
#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
1347
1398
    * byte into separate bytes (useful for paletted and grayscale images).
1348
1399
    */
1349
1400
   if (transforms & PNG_TRANSFORM_PACKING)
1350
 
       png_set_packing(png_ptr);
 
1401
      png_set_packing(png_ptr);
1351
1402
#endif
1352
1403
 
1353
 
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
 
1404
#ifdef PNG_READ_PACKSWAP_SUPPORTED
1354
1405
   /* Change the order of packed pixels to least significant bit first
1355
1406
    * (not useful if you are using png_set_packing).
1356
1407
    */
1357
1408
   if (transforms & PNG_TRANSFORM_PACKSWAP)
1358
 
       png_set_packswap(png_ptr);
 
1409
      png_set_packswap(png_ptr);
1359
1410
#endif
1360
1411
 
1361
 
#if defined(PNG_READ_EXPAND_SUPPORTED)
 
1412
#ifdef PNG_READ_EXPAND_SUPPORTED
1362
1413
   /* Expand paletted colors into true RGB triplets
1363
1414
    * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
1364
1415
    * Expand paletted or RGB images with transparency to full alpha
1365
1416
    * channels so the data will be available as RGBA quartets.
1366
1417
    */
1367
1418
   if (transforms & PNG_TRANSFORM_EXPAND)
1368
 
       if ((png_ptr->bit_depth < 8) ||
1369
 
           (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
1370
 
           (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
 
1419
      if ((png_ptr->bit_depth < 8) ||
 
1420
          (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
 
1421
          (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
1371
1422
         png_set_expand(png_ptr);
1372
1423
#endif
1373
1424
 
1374
1425
   /* We don't handle background color or gamma transformation or dithering.
1375
1426
    */
1376
1427
 
1377
 
#if defined(PNG_READ_INVERT_SUPPORTED)
1378
 
   /* invert monochrome files to have 0 as white and 1 as black
 
1428
#ifdef PNG_READ_INVERT_SUPPORTED
 
1429
   /* Invert monochrome files to have 0 as white and 1 as black
1379
1430
    */
1380
1431
   if (transforms & PNG_TRANSFORM_INVERT_MONO)
1381
 
       png_set_invert_mono(png_ptr);
 
1432
      png_set_invert_mono(png_ptr);
1382
1433
#endif
1383
1434
 
1384
 
#if defined(PNG_READ_SHIFT_SUPPORTED)
 
1435
#ifdef PNG_READ_SHIFT_SUPPORTED
1385
1436
   /* If you want to shift the pixel values from the range [0,255] or
1386
1437
    * [0,65535] to the original [0,7] or [0,31], or whatever range the
1387
1438
    * colors were originally in:
1396
1447
   }
1397
1448
#endif
1398
1449
 
1399
 
#if defined(PNG_READ_BGR_SUPPORTED)
1400
 
   /* flip the RGB pixels to BGR (or RGBA to BGRA)
 
1450
#ifdef PNG_READ_BGR_SUPPORTED
 
1451
   /* Flip the RGB pixels to BGR (or RGBA to BGRA)
1401
1452
    */
1402
1453
   if (transforms & PNG_TRANSFORM_BGR)
1403
 
       png_set_bgr(png_ptr);
 
1454
      png_set_bgr(png_ptr);
1404
1455
#endif
1405
1456
 
1406
 
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
1407
 
   /* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR)
 
1457
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
 
1458
   /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR)
1408
1459
    */
1409
1460
   if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
1410
1461
       png_set_swap_alpha(png_ptr);
1411
1462
#endif
1412
1463
 
1413
 
#if defined(PNG_READ_SWAP_SUPPORTED)
1414
 
   /* swap bytes of 16 bit files to least significant byte first
 
1464
#ifdef PNG_READ_SWAP_SUPPORTED
 
1465
   /* Swap bytes of 16 bit files to least significant byte first
1415
1466
    */
1416
1467
   if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
1417
 
       png_set_swap(png_ptr);
 
1468
      png_set_swap(png_ptr);
 
1469
#endif
 
1470
 
 
1471
/* Added at libpng-1.2.41 */
 
1472
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
 
1473
   /* Invert the alpha channel from opacity to transparency
 
1474
    */
 
1475
   if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
 
1476
       png_set_invert_alpha(png_ptr);
 
1477
#endif
 
1478
 
 
1479
/* Added at libpng-1.2.41 */
 
1480
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
 
1481
   /* Expand grayscale image to RGB
 
1482
    */
 
1483
   if (transforms & PNG_TRANSFORM_GRAY_TO_RGB)
 
1484
       png_set_gray_to_rgb(png_ptr);
1418
1485
#endif
1419
1486
 
1420
1487
   /* We don't handle adding filler bytes */
1434
1501
   {
1435
1502
      info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
1436
1503
         info_ptr->height * png_sizeof(png_bytep));
1437
 
#ifdef PNG_FREE_ME_SUPPORTED
1438
 
      info_ptr->free_me |= PNG_FREE_ROWS;
1439
 
#endif
1440
1504
      png_memset(info_ptr->row_pointers, 0, info_ptr->height
1441
1505
         * png_sizeof(png_bytep));
 
1506
 
 
1507
#ifdef PNG_FREE_ME_SUPPORTED
 
1508
      info_ptr->free_me |= PNG_FREE_ROWS;
 
1509
#endif
 
1510
 
1442
1511
      for (row = 0; row < (int)info_ptr->height; row++)
1443
1512
         info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
1444
1513
            png_get_rowbytes(png_ptr, info_ptr));
1447
1516
   png_read_image(png_ptr, info_ptr->row_pointers);
1448
1517
   info_ptr->valid |= PNG_INFO_IDAT;
1449
1518
 
1450
 
   /* read rest of file, and get additional chunks in info_ptr - REQUIRED */
 
1519
   /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */
1451
1520
   png_read_end(png_ptr, info_ptr);
1452
1521
 
1453
 
   transforms = transforms; /* quiet compiler warnings */
 
1522
   transforms = transforms; /* Quiet compiler warnings */
1454
1523
   params = params;
1455
1524
 
1456
1525
}
1457
1526
#endif /* PNG_INFO_IMAGE_SUPPORTED */
1458
 
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
 
1527
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
1459
1528
#endif /* PNG_READ_SUPPORTED */