~ubuntu-branches/ubuntu/maverick/libpng/maverick-security

« back to all changes in this revision

Viewing changes to pngread.c

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2009-12-04 11:23:50 UTC
  • mfrom: (1.1.10 upstream) (15.2.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091204112350-ln22xyakgn9bh39k
Tags: 1.2.41-1
* New upstream release
* Debian source format is 3.0 (quilt)
* Update debian/watch
* Add 02-export-png_set_strip_error_numbers.patch
  Define PNG_ERROR_NUMBERS_SUPPORTED
  Upstream doesn't define PNG_ERROR_NUMBERS_SUPPORTED since 1.2.41. As
  a consecuence, the symbol png_set_strip_error_numbe@@PNG12_0 wasn't
  exported.

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.37 [June 4, 2009]
 
4
 * Last changed in libpng 1.2.41 [December 3, 2009]
5
5
 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
6
6
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7
7
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
15
15
 */
16
16
 
17
17
#define PNG_INTERNAL
 
18
#define PNG_NO_PEDANTIC_WARNINGS
18
19
#include "png.h"
19
 
#if defined(PNG_READ_SUPPORTED)
 
20
#ifdef PNG_READ_SUPPORTED
 
21
 
20
22
 
21
23
/* Create a PNG structure for reading, and allocate any memory needed. */
22
24
png_structp PNGAPI
51
53
   int i;
52
54
 
53
55
   png_debug(1, "in png_create_read_struct");
 
56
 
54
57
#ifdef PNG_USER_MEM_SUPPORTED
55
58
   png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
56
59
      (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
62
65
 
63
66
   /* Added at libpng-1.2.6 */
64
67
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
65
 
   png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
66
 
   png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
 
68
   png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
 
69
   png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
67
70
#endif
68
71
 
69
72
#ifdef PNG_SETJMP_SUPPORTED
86
89
#ifdef USE_FAR_KEYWORD
87
90
   png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
88
91
#endif
89
 
#endif
 
92
#endif /* PNG_SETJMP_SUPPORTED */
90
93
 
91
94
#ifdef PNG_USER_MEM_SUPPORTED
92
95
   png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
96
99
 
97
100
   if (user_png_ver)
98
101
   {
99
 
     i = 0;
100
 
     do
101
 
     {
102
 
       if (user_png_ver[i] != png_libpng_ver[i])
103
 
          png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
104
 
     } while (png_libpng_ver[i++]);
105
 
   }
106
 
   else
107
 
        png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
108
 
 
109
 
 
110
 
   if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
111
 
   {
112
 
     /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
113
 
      * we must recompile any applications that use any older library version.
114
 
      * For versions after libpng 1.0, we will be compatible, so we need
115
 
      * only check the first digit.
116
 
      */
117
 
     if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
118
 
         (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
119
 
         (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
120
 
     {
121
 
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
122
 
        char msg[80];
123
 
        if (user_png_ver)
124
 
        {
125
 
          png_snprintf(msg, 80,
126
 
             "Application was compiled with png.h from libpng-%.20s",
127
 
             user_png_ver);
128
 
          png_warning(png_ptr, msg);
129
 
        }
130
 
        png_snprintf(msg, 80,
 
102
      i = 0;
 
103
      do
 
104
      {
 
105
         if (user_png_ver[i] != png_libpng_ver[i])
 
106
            png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
 
107
      } while (png_libpng_ver[i++]);
 
108
    }
 
109
    else
 
110
         png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
 
111
 
 
112
 
 
113
    if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
 
114
    {
 
115
       /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
 
116
       * we must recompile any applications that use any older library version.
 
117
       * For versions after libpng 1.0, we will be compatible, so we need
 
118
       * only check the first digit.
 
119
       */
 
120
      if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
 
121
          (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
 
122
          (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
 
123
      {
 
124
#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
 
125
         char msg[80];
 
126
         if (user_png_ver)
 
127
         {
 
128
           png_snprintf(msg, 80,
 
129
              "Application was compiled with png.h from libpng-%.20s",
 
130
              user_png_ver);
 
131
           png_warning(png_ptr, msg);
 
132
         }
 
133
         png_snprintf(msg, 80,
131
134
             "Application  is  running with png.c from libpng-%.20s",
132
 
           png_libpng_ver);
133
 
        png_warning(png_ptr, msg);
 
135
             png_libpng_ver);
 
136
         png_warning(png_ptr, msg);
134
137
#endif
135
138
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
136
 
        png_ptr->flags = 0;
 
139
         png_ptr->flags = 0;
137
140
#endif
138
 
        png_error(png_ptr,
139
 
           "Incompatible libpng version in application and library");
140
 
     }
 
141
         png_error(png_ptr,
 
142
            "Incompatible libpng version in application and library");
 
143
      }
141
144
   }
142
145
 
143
146
   /* Initialize zbuf - compression buffer */
148
151
   png_ptr->zstream.zfree = png_zfree;
149
152
   png_ptr->zstream.opaque = (voidpf)png_ptr;
150
153
 
151
 
   switch (inflateInit(&png_ptr->zstream))
152
 
   {
153
 
     case Z_OK: /* Do nothing */ break;
154
 
     case Z_MEM_ERROR:
155
 
     case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
156
 
     case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
157
 
     default: png_error(png_ptr, "Unknown zlib error");
158
 
   }
 
154
      switch (inflateInit(&png_ptr->zstream))
 
155
      {
 
156
         case Z_OK: /* Do nothing */ break;
 
157
         case Z_MEM_ERROR:
 
158
         case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error");
 
159
            break;
 
160
         case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error");
 
161
            break;
 
162
         default: png_error(png_ptr, "Unknown zlib error");
 
163
      }
 
164
 
159
165
 
160
166
   png_ptr->zstream.next_out = png_ptr->zbuf;
161
167
   png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
163
169
   png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
164
170
 
165
171
#ifdef PNG_SETJMP_SUPPORTED
166
 
/* Applications that neglect to set up their own setjmp() and then encounter
167
 
   a png_error() will longjmp here.  Since the jmpbuf is then meaningless we
168
 
   abort instead of returning. */
 
172
/* Applications that neglect to set up their own setjmp() and then
 
173
   encounter a png_error() will longjmp here.  Since the jmpbuf is
 
174
   then meaningless we abort instead of returning. */
169
175
#ifdef USE_FAR_KEYWORD
170
176
   if (setjmp(jmpbuf))
171
 
      PNG_ABORT();
 
177
       PNG_ABORT();
172
178
   png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
173
179
#else
174
180
   if (setjmp(png_ptr->jmpbuf))
175
 
      PNG_ABORT();
176
 
#endif
177
 
#endif
 
181
       PNG_ABORT();
 
182
#endif
 
183
#endif /* PNG_SETJMP_SUPPORTED */
 
184
 
178
185
   return (png_ptr);
179
186
}
180
187
 
181
188
#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
182
189
/* Initialize PNG structure for reading, and allocate any memory needed.
183
 
   This interface is deprecated in favour of the png_create_read_struct(),
184
 
   and it will disappear as of libpng-1.3.0. */
 
190
 * This interface is deprecated in favour of the png_create_read_struct(),
 
191
 * and it will disappear as of libpng-1.3.0.
 
192
 */
185
193
#undef png_read_init
186
194
void PNGAPI
187
195
png_read_init(png_structp png_ptr)
197
205
   /* We only come here via pre-1.0.12-compiled applications */
198
206
   if (png_ptr == NULL)
199
207
      return;
200
 
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
 
208
#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
201
209
   if (png_sizeof(png_struct) > png_struct_size ||
202
210
      png_sizeof(png_info) > png_info_size)
203
211
   {
217
225
   }
218
226
#endif
219
227
   if (png_sizeof(png_struct) > png_struct_size)
220
 
     {
221
 
       png_ptr->error_fn = NULL;
 
228
   {
 
229
      png_ptr->error_fn = NULL;
222
230
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
223
 
       png_ptr->flags = 0;
 
231
      png_ptr->flags = 0;
224
232
#endif
225
 
       png_error(png_ptr,
226
 
       "The png struct allocated by the application for reading is too small.");
227
 
     }
 
233
      png_error(png_ptr,
 
234
      "The png struct allocated by the application for reading is too small.");
 
235
   }
228
236
   if (png_sizeof(png_info) > png_info_size)
229
 
     {
230
 
       png_ptr->error_fn = NULL;
 
237
   {
 
238
      png_ptr->error_fn = NULL;
231
239
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
232
 
       png_ptr->flags = 0;
 
240
      png_ptr->flags = 0;
233
241
#endif
234
 
       png_error(png_ptr,
235
 
         "The info struct allocated by application for reading is too small.");
236
 
     }
 
242
      png_error(png_ptr,
 
243
        "The info struct allocated by application for reading is too small.");
 
244
   }
237
245
   png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
238
246
}
239
247
#endif /* PNG_1_0_X || PNG_1_2_X */
255
263
 
256
264
   do
257
265
   {
258
 
     if (user_png_ver[i] != png_libpng_ver[i])
259
 
     {
 
266
      if (user_png_ver[i] != png_libpng_ver[i])
 
267
      {
260
268
#ifdef PNG_LEGACY_SUPPORTED
261
 
       png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
 
269
        png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
262
270
#else
263
 
       png_ptr->warning_fn = NULL;
264
 
       png_warning(png_ptr,
265
 
        "Application uses deprecated png_read_init() and should be recompiled.");
266
 
       break;
 
271
        png_ptr->warning_fn = NULL;
 
272
        png_warning(png_ptr,
 
273
         "Application uses deprecated png_read_init() and should be recompiled.");
 
274
        break;
267
275
#endif
268
 
     }
 
276
      }
269
277
   } while (png_libpng_ver[i++]);
270
278
 
271
279
   png_debug(1, "in png_read_init_3");
292
300
 
293
301
   /* Added at libpng-1.2.6 */
294
302
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
295
 
   png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
296
 
   png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
 
303
   png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
 
304
   png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
297
305
#endif
298
306
 
299
307
   /* Initialize zbuf - compression buffer */
300
308
   png_ptr->zbuf_size = PNG_ZBUF_SIZE;
 
309
   png_ptr->zstream.zalloc = png_zalloc;
301
310
   png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
302
311
     (png_uint_32)png_ptr->zbuf_size);
303
312
   png_ptr->zstream.zalloc = png_zalloc;
306
315
 
307
316
   switch (inflateInit(&png_ptr->zstream))
308
317
   {
309
 
     case Z_OK: /* Do nothing */ break;
310
 
     case Z_MEM_ERROR:
311
 
     case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
312
 
     case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
313
 
     default: png_error(png_ptr, "Unknown zlib error");
 
318
      case Z_OK: /* Do nothing */ break;
 
319
      case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
 
320
      case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
 
321
      default: png_error(png_ptr, "Unknown zlib error");
314
322
   }
315
323
 
316
324
   png_ptr->zstream.next_out = png_ptr->zbuf;
319
327
   png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
320
328
}
321
329
 
322
 
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
 
330
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
323
331
/* Read the information before the actual image data.  This has been
324
332
 * changed in v0.90 to allow reading a file that already has the magic
325
333
 * bytes read from the stream.  You can tell libpng how many bytes have
331
339
void PNGAPI
332
340
png_read_info(png_structp png_ptr, png_infop info_ptr)
333
341
{
 
342
   png_debug(1, "in png_read_info");
 
343
 
334
344
   if (png_ptr == NULL || info_ptr == NULL)
335
345
      return;
336
 
   png_debug(1, "in png_read_info");
 
346
 
337
347
   /* If we haven't checked all of the PNG signature bytes, do so now. */
338
348
   if (png_ptr->sig_bytes < 8)
339
349
   {
362
372
      PNG_CONST PNG_IDAT;
363
373
      PNG_CONST PNG_IEND;
364
374
      PNG_CONST PNG_PLTE;
365
 
#if defined(PNG_READ_bKGD_SUPPORTED)
 
375
#ifdef PNG_READ_bKGD_SUPPORTED
366
376
      PNG_CONST PNG_bKGD;
367
377
#endif
368
 
#if defined(PNG_READ_cHRM_SUPPORTED)
 
378
#ifdef PNG_READ_cHRM_SUPPORTED
369
379
      PNG_CONST PNG_cHRM;
370
380
#endif
371
 
#if defined(PNG_READ_gAMA_SUPPORTED)
 
381
#ifdef PNG_READ_gAMA_SUPPORTED
372
382
      PNG_CONST PNG_gAMA;
373
383
#endif
374
 
#if defined(PNG_READ_hIST_SUPPORTED)
 
384
#ifdef PNG_READ_hIST_SUPPORTED
375
385
      PNG_CONST PNG_hIST;
376
386
#endif
377
 
#if defined(PNG_READ_iCCP_SUPPORTED)
 
387
#ifdef PNG_READ_iCCP_SUPPORTED
378
388
      PNG_CONST PNG_iCCP;
379
389
#endif
380
 
#if defined(PNG_READ_iTXt_SUPPORTED)
 
390
#ifdef PNG_READ_iTXt_SUPPORTED
381
391
      PNG_CONST PNG_iTXt;
382
392
#endif
383
 
#if defined(PNG_READ_oFFs_SUPPORTED)
 
393
#ifdef PNG_READ_oFFs_SUPPORTED
384
394
      PNG_CONST PNG_oFFs;
385
395
#endif
386
 
#if defined(PNG_READ_pCAL_SUPPORTED)
 
396
#ifdef PNG_READ_pCAL_SUPPORTED
387
397
      PNG_CONST PNG_pCAL;
388
398
#endif
389
 
#if defined(PNG_READ_pHYs_SUPPORTED)
 
399
#ifdef PNG_READ_pHYs_SUPPORTED
390
400
      PNG_CONST PNG_pHYs;
391
401
#endif
392
 
#if defined(PNG_READ_sBIT_SUPPORTED)
 
402
#ifdef PNG_READ_sBIT_SUPPORTED
393
403
      PNG_CONST PNG_sBIT;
394
404
#endif
395
 
#if defined(PNG_READ_sCAL_SUPPORTED)
 
405
#ifdef PNG_READ_sCAL_SUPPORTED
396
406
      PNG_CONST PNG_sCAL;
397
407
#endif
398
 
#if defined(PNG_READ_sPLT_SUPPORTED)
 
408
#ifdef PNG_READ_sPLT_SUPPORTED
399
409
      PNG_CONST PNG_sPLT;
400
410
#endif
401
 
#if defined(PNG_READ_sRGB_SUPPORTED)
 
411
#ifdef PNG_READ_sRGB_SUPPORTED
402
412
      PNG_CONST PNG_sRGB;
403
413
#endif
404
 
#if defined(PNG_READ_tEXt_SUPPORTED)
 
414
#ifdef PNG_READ_tEXt_SUPPORTED
405
415
      PNG_CONST PNG_tEXt;
406
416
#endif
407
 
#if defined(PNG_READ_tIME_SUPPORTED)
 
417
#ifdef PNG_READ_tIME_SUPPORTED
408
418
      PNG_CONST PNG_tIME;
409
419
#endif
410
 
#if defined(PNG_READ_tRNS_SUPPORTED)
 
420
#ifdef PNG_READ_tRNS_SUPPORTED
411
421
      PNG_CONST PNG_tRNS;
412
422
#endif
413
 
#if defined(PNG_READ_zTXt_SUPPORTED)
 
423
#ifdef PNG_READ_zTXt_SUPPORTED
414
424
      PNG_CONST PNG_zTXt;
415
425
#endif
416
426
#endif /* PNG_USE_LOCAL_ARRAYS */
461
471
         png_ptr->mode |= PNG_HAVE_IDAT;
462
472
         break;
463
473
      }
464
 
#if defined(PNG_READ_bKGD_SUPPORTED)
 
474
#ifdef PNG_READ_bKGD_SUPPORTED
465
475
      else if (!png_memcmp(chunk_name, png_bKGD, 4))
466
476
         png_handle_bKGD(png_ptr, info_ptr, length);
467
477
#endif
468
 
#if defined(PNG_READ_cHRM_SUPPORTED)
 
478
#ifdef PNG_READ_cHRM_SUPPORTED
469
479
      else if (!png_memcmp(chunk_name, png_cHRM, 4))
470
480
         png_handle_cHRM(png_ptr, info_ptr, length);
471
481
#endif
472
 
#if defined(PNG_READ_gAMA_SUPPORTED)
 
482
#ifdef PNG_READ_gAMA_SUPPORTED
473
483
      else if (!png_memcmp(chunk_name, png_gAMA, 4))
474
484
         png_handle_gAMA(png_ptr, info_ptr, length);
475
485
#endif
476
 
#if defined(PNG_READ_hIST_SUPPORTED)
 
486
#ifdef PNG_READ_hIST_SUPPORTED
477
487
      else if (!png_memcmp(chunk_name, png_hIST, 4))
478
488
         png_handle_hIST(png_ptr, info_ptr, length);
479
489
#endif
480
 
#if defined(PNG_READ_oFFs_SUPPORTED)
 
490
#ifdef PNG_READ_oFFs_SUPPORTED
481
491
      else if (!png_memcmp(chunk_name, png_oFFs, 4))
482
492
         png_handle_oFFs(png_ptr, info_ptr, length);
483
493
#endif
484
 
#if defined(PNG_READ_pCAL_SUPPORTED)
 
494
#ifdef PNG_READ_pCAL_SUPPORTED
485
495
      else if (!png_memcmp(chunk_name, png_pCAL, 4))
486
496
         png_handle_pCAL(png_ptr, info_ptr, length);
487
497
#endif
488
 
#if defined(PNG_READ_sCAL_SUPPORTED)
 
498
#ifdef PNG_READ_sCAL_SUPPORTED
489
499
      else if (!png_memcmp(chunk_name, png_sCAL, 4))
490
500
         png_handle_sCAL(png_ptr, info_ptr, length);
491
501
#endif
492
 
#if defined(PNG_READ_pHYs_SUPPORTED)
 
502
#ifdef PNG_READ_pHYs_SUPPORTED
493
503
      else if (!png_memcmp(chunk_name, png_pHYs, 4))
494
504
         png_handle_pHYs(png_ptr, info_ptr, length);
495
505
#endif
496
 
#if defined(PNG_READ_sBIT_SUPPORTED)
 
506
#ifdef PNG_READ_sBIT_SUPPORTED
497
507
      else if (!png_memcmp(chunk_name, png_sBIT, 4))
498
508
         png_handle_sBIT(png_ptr, info_ptr, length);
499
509
#endif
500
 
#if defined(PNG_READ_sRGB_SUPPORTED)
 
510
#ifdef PNG_READ_sRGB_SUPPORTED
501
511
      else if (!png_memcmp(chunk_name, png_sRGB, 4))
502
512
         png_handle_sRGB(png_ptr, info_ptr, length);
503
513
#endif
504
 
#if defined(PNG_READ_iCCP_SUPPORTED)
 
514
#ifdef PNG_READ_iCCP_SUPPORTED
505
515
      else if (!png_memcmp(chunk_name, png_iCCP, 4))
506
516
         png_handle_iCCP(png_ptr, info_ptr, length);
507
517
#endif
508
 
#if defined(PNG_READ_sPLT_SUPPORTED)
 
518
#ifdef PNG_READ_sPLT_SUPPORTED
509
519
      else if (!png_memcmp(chunk_name, png_sPLT, 4))
510
520
         png_handle_sPLT(png_ptr, info_ptr, length);
511
521
#endif
512
 
#if defined(PNG_READ_tEXt_SUPPORTED)
 
522
#ifdef PNG_READ_tEXt_SUPPORTED
513
523
      else if (!png_memcmp(chunk_name, png_tEXt, 4))
514
524
         png_handle_tEXt(png_ptr, info_ptr, length);
515
525
#endif
516
 
#if defined(PNG_READ_tIME_SUPPORTED)
 
526
#ifdef PNG_READ_tIME_SUPPORTED
517
527
      else if (!png_memcmp(chunk_name, png_tIME, 4))
518
528
         png_handle_tIME(png_ptr, info_ptr, length);
519
529
#endif
520
 
#if defined(PNG_READ_tRNS_SUPPORTED)
 
530
#ifdef PNG_READ_tRNS_SUPPORTED
521
531
      else if (!png_memcmp(chunk_name, png_tRNS, 4))
522
532
         png_handle_tRNS(png_ptr, info_ptr, length);
523
533
#endif
524
 
#if defined(PNG_READ_zTXt_SUPPORTED)
 
534
#ifdef PNG_READ_zTXt_SUPPORTED
525
535
      else if (!png_memcmp(chunk_name, png_zTXt, 4))
526
536
         png_handle_zTXt(png_ptr, info_ptr, length);
527
537
#endif
528
 
#if defined(PNG_READ_iTXt_SUPPORTED)
 
538
#ifdef PNG_READ_iTXt_SUPPORTED
529
539
      else if (!png_memcmp(chunk_name, png_iTXt, 4))
530
540
         png_handle_iTXt(png_ptr, info_ptr, length);
531
541
#endif
533
543
         png_handle_unknown(png_ptr, info_ptr, length);
534
544
   }
535
545
}
536
 
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
 
546
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
537
547
 
538
548
/* Optional call to update the users info_ptr structure */
539
549
void PNGAPI
540
550
png_read_update_info(png_structp png_ptr, png_infop info_ptr)
541
551
{
542
552
   png_debug(1, "in png_read_update_info");
 
553
 
543
554
   if (png_ptr == NULL)
544
555
      return;
545
556
   if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
550
561
   png_read_transform_info(png_ptr, info_ptr);
551
562
}
552
563
 
553
 
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
 
564
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
554
565
/* Initialize palette, background, etc, after transformations
555
566
 * are set, but before any reading takes place.  This allows
556
567
 * the user to obtain a gamma-corrected palette, for example.
560
571
png_start_read_image(png_structp png_ptr)
561
572
{
562
573
   png_debug(1, "in png_start_read_image");
 
574
 
563
575
   if (png_ptr == NULL)
564
576
      return;
565
577
   if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
566
578
      png_read_start_row(png_ptr);
567
579
}
568
 
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
 
580
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
569
581
 
570
 
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
 
582
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
571
583
void PNGAPI
572
584
png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
573
585
{
574
 
#ifdef PNG_USE_LOCAL_ARRAYS
575
586
   PNG_CONST PNG_IDAT;
576
587
   PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
577
588
      0xff};
578
589
   PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
579
 
#endif
580
590
   int ret;
 
591
 
581
592
   if (png_ptr == NULL)
582
593
      return;
 
594
 
583
595
   png_debug2(1, "in png_read_row (row %lu, pass %d)",
584
596
      png_ptr->row_number, png_ptr->pass);
 
597
 
585
598
   if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
586
599
      png_read_start_row(png_ptr);
587
600
   if (png_ptr->row_number == 0 && png_ptr->pass == 0)
617
630
#endif
618
631
   }
619
632
 
620
 
#if defined(PNG_READ_INTERLACING_SUPPORTED)
 
633
#ifdef PNG_READ_INTERLACING_SUPPORTED
621
634
   /* If interlaced and we do not need a new row, combine row and return */
622
635
   if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
623
636
   {
751
764
   png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
752
765
      png_ptr->rowbytes + 1);
753
766
 
754
 
#if defined(PNG_MNG_FEATURES_SUPPORTED)
 
767
#ifdef PNG_MNG_FEATURES_SUPPORTED
755
768
   if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
756
769
      (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
757
770
   {
764
777
   if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
765
778
      png_do_read_transformations(png_ptr);
766
779
 
767
 
#if defined(PNG_READ_INTERLACING_SUPPORTED)
 
780
#ifdef PNG_READ_INTERLACING_SUPPORTED
768
781
   /* Blow up interlaced rows to full size */
769
782
   if (png_ptr->interlaced &&
770
783
      (png_ptr->transformations & PNG_INTERLACE))
796
809
   if (png_ptr->read_row_fn != NULL)
797
810
      (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
798
811
}
799
 
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
 
812
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
800
813
 
801
 
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
 
814
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
802
815
/* Read one or more rows of image data.  If the image is interlaced,
803
816
 * and png_set_interlace_handling() has been called, the rows need to
804
817
 * contain the contents of the rows from the previous pass.  If the
832
845
   png_bytepp dp;
833
846
 
834
847
   png_debug(1, "in png_read_rows");
 
848
 
835
849
   if (png_ptr == NULL)
836
850
      return;
837
851
   rp = row;
859
873
         dp++;
860
874
      }
861
875
}
862
 
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
 
876
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
863
877
 
864
 
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
 
878
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
865
879
/* Read the entire image.  If the image has an alpha channel or a tRNS
866
880
 * chunk, and you have called png_handle_alpha()[*], you will need to
867
881
 * initialize the image to the current image that PNG will be overlaying.
882
896
   png_bytepp rp;
883
897
 
884
898
   png_debug(1, "in png_read_image");
 
899
 
885
900
   if (png_ptr == NULL)
886
901
      return;
887
902
 
908
923
      }
909
924
   }
910
925
}
911
 
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
 
926
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
912
927
 
913
 
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
 
928
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
914
929
/* Read the end of the PNG file.  Will not read past the end of the
915
930
 * file, will verify the end is accurate, and will read any comments
916
931
 * or time information at the end of the file, if info is not NULL.
919
934
png_read_end(png_structp png_ptr, png_infop info_ptr)
920
935
{
921
936
   png_debug(1, "in png_read_end");
 
937
 
922
938
   if (png_ptr == NULL)
923
939
      return;
924
940
   png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
930
946
      PNG_CONST PNG_IDAT;
931
947
      PNG_CONST PNG_IEND;
932
948
      PNG_CONST PNG_PLTE;
933
 
#if defined(PNG_READ_bKGD_SUPPORTED)
 
949
#ifdef PNG_READ_bKGD_SUPPORTED
934
950
      PNG_CONST PNG_bKGD;
935
951
#endif
936
 
#if defined(PNG_READ_cHRM_SUPPORTED)
 
952
#ifdef PNG_READ_cHRM_SUPPORTED
937
953
      PNG_CONST PNG_cHRM;
938
954
#endif
939
 
#if defined(PNG_READ_gAMA_SUPPORTED)
 
955
#ifdef PNG_READ_gAMA_SUPPORTED
940
956
      PNG_CONST PNG_gAMA;
941
957
#endif
942
 
#if defined(PNG_READ_hIST_SUPPORTED)
 
958
#ifdef PNG_READ_hIST_SUPPORTED
943
959
      PNG_CONST PNG_hIST;
944
960
#endif
945
 
#if defined(PNG_READ_iCCP_SUPPORTED)
 
961
#ifdef PNG_READ_iCCP_SUPPORTED
946
962
      PNG_CONST PNG_iCCP;
947
963
#endif
948
 
#if defined(PNG_READ_iTXt_SUPPORTED)
 
964
#ifdef PNG_READ_iTXt_SUPPORTED
949
965
      PNG_CONST PNG_iTXt;
950
966
#endif
951
 
#if defined(PNG_READ_oFFs_SUPPORTED)
 
967
#ifdef PNG_READ_oFFs_SUPPORTED
952
968
      PNG_CONST PNG_oFFs;
953
969
#endif
954
 
#if defined(PNG_READ_pCAL_SUPPORTED)
 
970
#ifdef PNG_READ_pCAL_SUPPORTED
955
971
      PNG_CONST PNG_pCAL;
956
972
#endif
957
 
#if defined(PNG_READ_pHYs_SUPPORTED)
 
973
#ifdef PNG_READ_pHYs_SUPPORTED
958
974
      PNG_CONST PNG_pHYs;
959
975
#endif
960
 
#if defined(PNG_READ_sBIT_SUPPORTED)
 
976
#ifdef PNG_READ_sBIT_SUPPORTED
961
977
      PNG_CONST PNG_sBIT;
962
978
#endif
963
 
#if defined(PNG_READ_sCAL_SUPPORTED)
 
979
#ifdef PNG_READ_sCAL_SUPPORTED
964
980
      PNG_CONST PNG_sCAL;
965
981
#endif
966
 
#if defined(PNG_READ_sPLT_SUPPORTED)
 
982
#ifdef PNG_READ_sPLT_SUPPORTED
967
983
      PNG_CONST PNG_sPLT;
968
984
#endif
969
 
#if defined(PNG_READ_sRGB_SUPPORTED)
 
985
#ifdef PNG_READ_sRGB_SUPPORTED
970
986
      PNG_CONST PNG_sRGB;
971
987
#endif
972
 
#if defined(PNG_READ_tEXt_SUPPORTED)
 
988
#ifdef PNG_READ_tEXt_SUPPORTED
973
989
      PNG_CONST PNG_tEXt;
974
990
#endif
975
 
#if defined(PNG_READ_tIME_SUPPORTED)
 
991
#ifdef PNG_READ_tIME_SUPPORTED
976
992
      PNG_CONST PNG_tIME;
977
993
#endif
978
 
#if defined(PNG_READ_tRNS_SUPPORTED)
 
994
#ifdef PNG_READ_tRNS_SUPPORTED
979
995
      PNG_CONST PNG_tRNS;
980
996
#endif
981
 
#if defined(PNG_READ_zTXt_SUPPORTED)
 
997
#ifdef PNG_READ_zTXt_SUPPORTED
982
998
      PNG_CONST PNG_zTXt;
983
999
#endif
984
1000
#endif /* PNG_USE_LOCAL_ARRAYS */
1013
1029
      }
1014
1030
      else if (!png_memcmp(chunk_name, png_PLTE, 4))
1015
1031
         png_handle_PLTE(png_ptr, info_ptr, length);
1016
 
#if defined(PNG_READ_bKGD_SUPPORTED)
 
1032
#ifdef PNG_READ_bKGD_SUPPORTED
1017
1033
      else if (!png_memcmp(chunk_name, png_bKGD, 4))
1018
1034
         png_handle_bKGD(png_ptr, info_ptr, length);
1019
1035
#endif
1020
 
#if defined(PNG_READ_cHRM_SUPPORTED)
 
1036
#ifdef PNG_READ_cHRM_SUPPORTED
1021
1037
      else if (!png_memcmp(chunk_name, png_cHRM, 4))
1022
1038
         png_handle_cHRM(png_ptr, info_ptr, length);
1023
1039
#endif
1024
 
#if defined(PNG_READ_gAMA_SUPPORTED)
 
1040
#ifdef PNG_READ_gAMA_SUPPORTED
1025
1041
      else if (!png_memcmp(chunk_name, png_gAMA, 4))
1026
1042
         png_handle_gAMA(png_ptr, info_ptr, length);
1027
1043
#endif
1028
 
#if defined(PNG_READ_hIST_SUPPORTED)
 
1044
#ifdef PNG_READ_hIST_SUPPORTED
1029
1045
      else if (!png_memcmp(chunk_name, png_hIST, 4))
1030
1046
         png_handle_hIST(png_ptr, info_ptr, length);
1031
1047
#endif
1032
 
#if defined(PNG_READ_oFFs_SUPPORTED)
 
1048
#ifdef PNG_READ_oFFs_SUPPORTED
1033
1049
      else if (!png_memcmp(chunk_name, png_oFFs, 4))
1034
1050
         png_handle_oFFs(png_ptr, info_ptr, length);
1035
1051
#endif
1036
 
#if defined(PNG_READ_pCAL_SUPPORTED)
 
1052
#ifdef PNG_READ_pCAL_SUPPORTED
1037
1053
      else if (!png_memcmp(chunk_name, png_pCAL, 4))
1038
1054
         png_handle_pCAL(png_ptr, info_ptr, length);
1039
1055
#endif
1040
 
#if defined(PNG_READ_sCAL_SUPPORTED)
 
1056
#ifdef PNG_READ_sCAL_SUPPORTED
1041
1057
      else if (!png_memcmp(chunk_name, png_sCAL, 4))
1042
1058
         png_handle_sCAL(png_ptr, info_ptr, length);
1043
1059
#endif
1044
 
#if defined(PNG_READ_pHYs_SUPPORTED)
 
1060
#ifdef PNG_READ_pHYs_SUPPORTED
1045
1061
      else if (!png_memcmp(chunk_name, png_pHYs, 4))
1046
1062
         png_handle_pHYs(png_ptr, info_ptr, length);
1047
1063
#endif
1048
 
#if defined(PNG_READ_sBIT_SUPPORTED)
 
1064
#ifdef PNG_READ_sBIT_SUPPORTED
1049
1065
      else if (!png_memcmp(chunk_name, png_sBIT, 4))
1050
1066
         png_handle_sBIT(png_ptr, info_ptr, length);
1051
1067
#endif
1052
 
#if defined(PNG_READ_sRGB_SUPPORTED)
 
1068
#ifdef PNG_READ_sRGB_SUPPORTED
1053
1069
      else if (!png_memcmp(chunk_name, png_sRGB, 4))
1054
1070
         png_handle_sRGB(png_ptr, info_ptr, length);
1055
1071
#endif
1056
 
#if defined(PNG_READ_iCCP_SUPPORTED)
 
1072
#ifdef PNG_READ_iCCP_SUPPORTED
1057
1073
      else if (!png_memcmp(chunk_name, png_iCCP, 4))
1058
1074
         png_handle_iCCP(png_ptr, info_ptr, length);
1059
1075
#endif
1060
 
#if defined(PNG_READ_sPLT_SUPPORTED)
 
1076
#ifdef PNG_READ_sPLT_SUPPORTED
1061
1077
      else if (!png_memcmp(chunk_name, png_sPLT, 4))
1062
1078
         png_handle_sPLT(png_ptr, info_ptr, length);
1063
1079
#endif
1064
 
#if defined(PNG_READ_tEXt_SUPPORTED)
 
1080
#ifdef PNG_READ_tEXt_SUPPORTED
1065
1081
      else if (!png_memcmp(chunk_name, png_tEXt, 4))
1066
1082
         png_handle_tEXt(png_ptr, info_ptr, length);
1067
1083
#endif
1068
 
#if defined(PNG_READ_tIME_SUPPORTED)
 
1084
#ifdef PNG_READ_tIME_SUPPORTED
1069
1085
      else if (!png_memcmp(chunk_name, png_tIME, 4))
1070
1086
         png_handle_tIME(png_ptr, info_ptr, length);
1071
1087
#endif
1072
 
#if defined(PNG_READ_tRNS_SUPPORTED)
 
1088
#ifdef PNG_READ_tRNS_SUPPORTED
1073
1089
      else if (!png_memcmp(chunk_name, png_tRNS, 4))
1074
1090
         png_handle_tRNS(png_ptr, info_ptr, length);
1075
1091
#endif
1076
 
#if defined(PNG_READ_zTXt_SUPPORTED)
 
1092
#ifdef PNG_READ_zTXt_SUPPORTED
1077
1093
      else if (!png_memcmp(chunk_name, png_zTXt, 4))
1078
1094
         png_handle_zTXt(png_ptr, info_ptr, length);
1079
1095
#endif
1080
 
#if defined(PNG_READ_iTXt_SUPPORTED)
 
1096
#ifdef PNG_READ_iTXt_SUPPORTED
1081
1097
      else if (!png_memcmp(chunk_name, png_iTXt, 4))
1082
1098
         png_handle_iTXt(png_ptr, info_ptr, length);
1083
1099
#endif
1085
1101
         png_handle_unknown(png_ptr, info_ptr, length);
1086
1102
   } while (!(png_ptr->mode & PNG_HAVE_IEND));
1087
1103
}
1088
 
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
 
1104
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
1089
1105
 
1090
1106
/* Free all memory used by the read */
1091
1107
void PNGAPI
1100
1116
#endif
1101
1117
 
1102
1118
   png_debug(1, "in png_destroy_read_struct");
 
1119
 
1103
1120
   if (png_ptr_ptr != NULL)
1104
1121
      png_ptr = *png_ptr_ptr;
1105
1122
   if (png_ptr == NULL)
1120
1137
 
1121
1138
   if (info_ptr != NULL)
1122
1139
   {
1123
 
#if defined(PNG_TEXT_SUPPORTED)
 
1140
#ifdef PNG_TEXT_SUPPORTED
1124
1141
      png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
1125
1142
#endif
1126
1143
 
1135
1152
 
1136
1153
   if (end_info_ptr != NULL)
1137
1154
   {
1138
 
#if defined(PNG_READ_TEXT_SUPPORTED)
 
1155
#ifdef PNG_READ_TEXT_SUPPORTED
1139
1156
      png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
1140
1157
#endif
1141
1158
#ifdef PNG_USER_MEM_SUPPORTED
1174
1191
#endif
1175
1192
 
1176
1193
   png_debug(1, "in png_read_destroy");
 
1194
 
1177
1195
   if (info_ptr != NULL)
1178
1196
      png_info_destroy(png_ptr, info_ptr);
1179
1197
 
1184
1202
   png_free(png_ptr, png_ptr->big_row_buf);
1185
1203
   png_free(png_ptr, png_ptr->prev_row);
1186
1204
   png_free(png_ptr, png_ptr->chunkdata);
1187
 
#if defined(PNG_READ_DITHER_SUPPORTED)
 
1205
#ifdef PNG_READ_DITHER_SUPPORTED
1188
1206
   png_free(png_ptr, png_ptr->palette_lookup);
1189
1207
   png_free(png_ptr, png_ptr->dither_index);
1190
1208
#endif
1191
 
#if defined(PNG_READ_GAMMA_SUPPORTED)
 
1209
#ifdef PNG_READ_GAMMA_SUPPORTED
1192
1210
   png_free(png_ptr, png_ptr->gamma_table);
1193
1211
#endif
1194
 
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
 
1212
#ifdef PNG_READ_BACKGROUND_SUPPORTED
1195
1213
   png_free(png_ptr, png_ptr->gamma_from_1);
1196
1214
   png_free(png_ptr, png_ptr->gamma_to_1);
1197
1215
#endif
1216
1234
   png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
1217
1235
#endif
1218
1236
#endif
1219
 
#if defined(PNG_READ_hIST_SUPPORTED)
 
1237
#ifdef PNG_READ_hIST_SUPPORTED
1220
1238
#ifdef PNG_FREE_ME_SUPPORTED
1221
1239
   if (png_ptr->free_me & PNG_FREE_HIST)
1222
1240
      png_free(png_ptr, png_ptr->hist);
1227
1245
   png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
1228
1246
#endif
1229
1247
#endif
1230
 
#if defined(PNG_READ_GAMMA_SUPPORTED)
 
1248
#ifdef PNG_READ_GAMMA_SUPPORTED
1231
1249
   if (png_ptr->gamma_16_table != NULL)
1232
1250
   {
1233
1251
      int i;
1238
1256
      }
1239
1257
   png_free(png_ptr, png_ptr->gamma_16_table);
1240
1258
   }
1241
 
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
 
1259
#ifdef PNG_READ_BACKGROUND_SUPPORTED
1242
1260
   if (png_ptr->gamma_16_from_1 != NULL)
1243
1261
   {
1244
1262
      int i;
1261
1279
   }
1262
1280
#endif
1263
1281
#endif
1264
 
#if defined(PNG_TIME_RFC1123_SUPPORTED)
 
1282
#ifdef PNG_TIME_RFC1123_SUPPORTED
1265
1283
   png_free(png_ptr, png_ptr->time_buffer);
1266
1284
#endif
1267
1285
 
1314
1332
}
1315
1333
 
1316
1334
 
1317
 
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
1318
 
#if defined(PNG_INFO_IMAGE_SUPPORTED)
 
1335
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
 
1336
#ifdef PNG_INFO_IMAGE_SUPPORTED
1319
1337
void PNGAPI
1320
1338
png_read_png(png_structp png_ptr, png_infop info_ptr,
1321
1339
                           int transforms,
1325
1343
 
1326
1344
   if (png_ptr == NULL)
1327
1345
      return;
1328
 
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
 
1346
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
1329
1347
   /* Invert the alpha channel from opacity to transparency
1330
1348
    */
1331
1349
   if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
1341
1359
 
1342
1360
   /* -------------- image transformations start here ------------------- */
1343
1361
 
1344
 
#if defined(PNG_READ_16_TO_8_SUPPORTED)
 
1362
#ifdef PNG_READ_16_TO_8_SUPPORTED
1345
1363
   /* Tell libpng to strip 16 bit/color files down to 8 bits per color.
1346
1364
    */
1347
1365
   if (transforms & PNG_TRANSFORM_STRIP_16)
1348
1366
      png_set_strip_16(png_ptr);
1349
1367
#endif
1350
1368
 
1351
 
#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
 
1369
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
1352
1370
   /* Strip alpha bytes from the input data without combining with
1353
1371
    * the background (not recommended).
1354
1372
    */
1364
1382
      png_set_packing(png_ptr);
1365
1383
#endif
1366
1384
 
1367
 
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
 
1385
#ifdef PNG_READ_PACKSWAP_SUPPORTED
1368
1386
   /* Change the order of packed pixels to least significant bit first
1369
1387
    * (not useful if you are using png_set_packing).
1370
1388
    */
1372
1390
      png_set_packswap(png_ptr);
1373
1391
#endif
1374
1392
 
1375
 
#if defined(PNG_READ_EXPAND_SUPPORTED)
 
1393
#ifdef PNG_READ_EXPAND_SUPPORTED
1376
1394
   /* Expand paletted colors into true RGB triplets
1377
1395
    * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
1378
1396
    * Expand paletted or RGB images with transparency to full alpha
1388
1406
   /* We don't handle background color or gamma transformation or dithering.
1389
1407
    */
1390
1408
 
1391
 
#if defined(PNG_READ_INVERT_SUPPORTED)
 
1409
#ifdef PNG_READ_INVERT_SUPPORTED
1392
1410
   /* Invert monochrome files to have 0 as white and 1 as black
1393
1411
    */
1394
1412
   if (transforms & PNG_TRANSFORM_INVERT_MONO)
1395
1413
      png_set_invert_mono(png_ptr);
1396
1414
#endif
1397
1415
 
1398
 
#if defined(PNG_READ_SHIFT_SUPPORTED)
 
1416
#ifdef PNG_READ_SHIFT_SUPPORTED
1399
1417
   /* If you want to shift the pixel values from the range [0,255] or
1400
1418
    * [0,65535] to the original [0,7] or [0,31], or whatever range the
1401
1419
    * colors were originally in:
1410
1428
   }
1411
1429
#endif
1412
1430
 
1413
 
#if defined(PNG_READ_BGR_SUPPORTED)
 
1431
#ifdef PNG_READ_BGR_SUPPORTED
1414
1432
   /* Flip the RGB pixels to BGR (or RGBA to BGRA)
1415
1433
    */
1416
1434
   if (transforms & PNG_TRANSFORM_BGR)
1417
1435
      png_set_bgr(png_ptr);
1418
1436
#endif
1419
1437
 
1420
 
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
 
1438
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
1421
1439
   /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR)
1422
1440
    */
1423
1441
   if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
1424
1442
       png_set_swap_alpha(png_ptr);
1425
1443
#endif
1426
1444
 
1427
 
#if defined(PNG_READ_SWAP_SUPPORTED)
 
1445
#ifdef PNG_READ_SWAP_SUPPORTED
1428
1446
   /* Swap bytes of 16 bit files to least significant byte first
1429
1447
    */
1430
1448
   if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
1431
1449
      png_set_swap(png_ptr);
1432
1450
#endif
1433
1451
 
 
1452
/* Added at libpng-1.2.41 */
 
1453
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
 
1454
   /* Invert the alpha channel from opacity to transparency
 
1455
    */
 
1456
   if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
 
1457
       png_set_invert_alpha(png_ptr);
 
1458
#endif
 
1459
 
 
1460
/* Added at libpng-1.2.41 */
 
1461
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
 
1462
   /* Expand grayscale image to RGB
 
1463
    */
 
1464
   if (transforms & PNG_TRANSFORM_GRAY_TO_RGB)
 
1465
       png_set_gray_to_rgb(png_ptr);
 
1466
#endif
 
1467
 
1434
1468
   /* We don't handle adding filler bytes */
1435
1469
 
1436
1470
   /* Optional call to gamma correct and add the background to the palette
1450
1484
         info_ptr->height * png_sizeof(png_bytep));
1451
1485
      png_memset(info_ptr->row_pointers, 0, info_ptr->height
1452
1486
         * png_sizeof(png_bytep));
 
1487
 
1453
1488
#ifdef PNG_FREE_ME_SUPPORTED
1454
1489
      info_ptr->free_me |= PNG_FREE_ROWS;
1455
1490
#endif
 
1491
 
1456
1492
      for (row = 0; row < (int)info_ptr->height; row++)
1457
1493
         info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
1458
1494
            png_get_rowbytes(png_ptr, info_ptr));
1469
1505
 
1470
1506
}
1471
1507
#endif /* PNG_INFO_IMAGE_SUPPORTED */
1472
 
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
 
1508
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
1473
1509
#endif /* PNG_READ_SUPPORTED */