~ubuntu-branches/ubuntu/precise/xulrunner-1.9/precise

« back to all changes in this revision

Viewing changes to mozilla/modules/libimg/png/pngread.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2009-03-05 17:19:38 UTC
  • mfrom: (1.1.17 upstream)
  • Revision ID: james.westby@ubuntu.com-20090305171938-em56xsox7j2mfqdq
Tags: 1.9.0.7+nobinonly-0ubuntu1
* security/stability v1.9.0.7 (FIREFOX_3_0_7_RELEASE)
  - USN-728-1
* bump required soft-depends on nspr to >= 4.7.3
  - update debian/rules

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.24 December 14, 2007
 
4
 * Last changed in libpng 1.2.35 [February 14, 2009]
5
5
 * For conditions of distribution and use, see copyright notice in png.h
6
 
 * Copyright (c) 1998-2007 Glenn Randers-Pehrson
 
6
 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
7
7
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8
8
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
9
9
 *
13
13
 
14
14
#define PNG_INTERNAL
15
15
#include "png.h"
16
 
 
17
16
#if defined(PNG_READ_SUPPORTED)
18
17
 
19
18
/* Create a PNG structure for reading, and allocate any memory needed. */
35
34
{
36
35
#endif /* PNG_USER_MEM_SUPPORTED */
37
36
 
 
37
#ifdef PNG_SETJMP_SUPPORTED
 
38
   volatile
 
39
#endif
38
40
   png_structp png_ptr;
39
41
 
40
42
#ifdef PNG_SETJMP_SUPPORTED
45
47
 
46
48
   int i;
47
49
 
48
 
   png_debug(1, "in png_create_read_struct\n");
 
50
   png_debug(1, "in png_create_read_struct");
49
51
#ifdef PNG_USER_MEM_SUPPORTED
50
52
   png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
51
53
      (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
69
71
#endif
70
72
   {
71
73
      png_free(png_ptr, png_ptr->zbuf);
72
 
      png_ptr->zbuf=NULL;
 
74
      png_ptr->zbuf = NULL;
73
75
#ifdef PNG_USER_MEM_SUPPORTED
74
76
      png_destroy_struct_2((png_voidp)png_ptr,
75
77
         (png_free_ptr)free_fn, (png_voidp)mem_ptr);
79
81
      return (NULL);
80
82
   }
81
83
#ifdef USE_FAR_KEYWORD
82
 
   png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
 
84
   png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
83
85
#endif
84
86
#endif
85
87
 
89
91
 
90
92
   png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
91
93
 
92
 
   i=0;
93
 
   do
 
94
   if (user_png_ver)
94
95
   {
95
 
     if(user_png_ver[i] != png_libpng_ver[i])
 
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
96
104
        png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
97
 
   } while (png_libpng_ver[i++]);
 
105
   
98
106
 
99
107
   if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
100
108
   {
122
130
        png_warning(png_ptr, msg);
123
131
#endif
124
132
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
125
 
        png_ptr->flags=0;
 
133
        png_ptr->flags = 0;
126
134
#endif
127
135
        png_error(png_ptr,
128
136
           "Incompatible libpng version in application and library");
158
166
#ifdef USE_FAR_KEYWORD
159
167
   if (setjmp(jmpbuf))
160
168
      PNG_ABORT();
161
 
   png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
 
169
   png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
162
170
#else
163
171
   if (setjmp(png_ptr->jmpbuf))
164
172
      PNG_ABORT();
184
192
   png_size_t png_struct_size, png_size_t png_info_size)
185
193
{
186
194
   /* We only come here via pre-1.0.12-compiled applications */
187
 
   if(png_ptr == NULL) return;
 
195
   if (png_ptr == NULL) return;
188
196
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
189
 
   if(png_sizeof(png_struct) > png_struct_size ||
 
197
   if (png_sizeof(png_struct) > png_struct_size ||
190
198
      png_sizeof(png_info) > png_info_size)
191
199
   {
192
200
      char msg[80];
193
 
      png_ptr->warning_fn=NULL;
 
201
      png_ptr->warning_fn = NULL;
194
202
      if (user_png_ver)
195
203
      {
196
204
        png_snprintf(msg, 80,
204
212
      png_warning(png_ptr, msg);
205
213
   }
206
214
#endif
207
 
   if(png_sizeof(png_struct) > png_struct_size)
 
215
   if (png_sizeof(png_struct) > png_struct_size)
208
216
     {
209
 
       png_ptr->error_fn=NULL;
 
217
       png_ptr->error_fn = NULL;
210
218
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
211
 
       png_ptr->flags=0;
 
219
       png_ptr->flags = 0;
212
220
#endif
213
221
       png_error(png_ptr,
214
222
       "The png struct allocated by the application for reading is too small.");
215
223
     }
216
 
   if(png_sizeof(png_info) > png_info_size)
 
224
   if (png_sizeof(png_info) > png_info_size)
217
225
     {
218
 
       png_ptr->error_fn=NULL;
 
226
       png_ptr->error_fn = NULL;
219
227
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
220
 
       png_ptr->flags=0;
 
228
       png_ptr->flags = 0;
221
229
#endif
222
230
       png_error(png_ptr,
223
231
         "The info struct allocated by application for reading is too small.");
234
242
   jmp_buf tmp_jmp;  /* to save current jump buffer */
235
243
#endif
236
244
 
237
 
   int i=0;
 
245
   int i = 0;
238
246
 
239
247
   png_structp png_ptr=*ptr_ptr;
240
248
 
241
 
   if(png_ptr == NULL) return;
 
249
   if (png_ptr == NULL) return;
242
250
 
243
251
   do
244
252
   {
245
 
     if(user_png_ver[i] != png_libpng_ver[i])
 
253
     if (user_png_ver[i] != png_libpng_ver[i])
246
254
     {
247
255
#ifdef PNG_LEGACY_SUPPORTED
248
256
       png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
249
257
#else
250
 
       png_ptr->warning_fn=NULL;
 
258
       png_ptr->warning_fn = NULL;
251
259
       png_warning(png_ptr,
252
260
        "Application uses deprecated png_read_init() and should be recompiled.");
253
261
       break;
255
263
     }
256
264
   } while (png_libpng_ver[i++]);
257
265
 
258
 
   png_debug(1, "in png_read_init_3\n");
 
266
   png_debug(1, "in png_read_init_3");
259
267
 
260
268
#ifdef PNG_SETJMP_SUPPORTED
261
269
   /* save jump buffer and error functions */
262
 
   png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
 
270
   png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
263
271
#endif
264
272
 
265
 
   if(png_sizeof(png_struct) > png_struct_size)
266
 
     {
267
 
       png_destroy_struct(png_ptr);
268
 
       *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
269
 
       png_ptr = *ptr_ptr;
270
 
     }
 
273
   if (png_sizeof(png_struct) > png_struct_size)
 
274
   {
 
275
      png_destroy_struct(png_ptr);
 
276
      *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
 
277
      png_ptr = *ptr_ptr;
 
278
   }
271
279
 
272
280
   /* reset all variables to 0 */
273
 
   png_memset(png_ptr, 0, png_sizeof (png_struct));
 
281
   png_memset(png_ptr, 0, png_sizeof(png_struct));
274
282
 
275
283
#ifdef PNG_SETJMP_SUPPORTED
276
284
   /* restore jump buffer */
277
 
   png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
 
285
   png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
278
286
#endif
279
287
 
280
288
   /* added at libpng-1.2.6 */
318
326
void PNGAPI
319
327
png_read_info(png_structp png_ptr, png_infop info_ptr)
320
328
{
321
 
   if(png_ptr == NULL) return;
322
 
   png_debug(1, "in png_read_info\n");
 
329
   if (png_ptr == NULL || info_ptr == NULL) return;
 
330
   png_debug(1, "in png_read_info");
323
331
   /* If we haven't checked all of the PNG signature bytes, do so now. */
324
332
   if (png_ptr->sig_bytes < 8)
325
333
   {
341
349
         png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
342
350
   }
343
351
 
344
 
   for(;;)
 
352
   for (;;)
345
353
   {
346
354
#ifdef PNG_USE_LOCAL_ARRAYS
347
355
      PNG_CONST PNG_IHDR;
405
413
      PNG_CONST PNG_fdAT;
406
414
#endif
407
415
#endif /* PNG_USE_LOCAL_ARRAYS */
408
 
      png_byte chunk_length[4];
409
 
      png_uint_32 length;
410
 
 
411
 
      png_read_data(png_ptr, chunk_length, 4);
412
 
      length = png_get_uint_31(png_ptr,chunk_length);
413
 
 
414
 
      png_reset_crc(png_ptr);
415
 
      png_crc_read(png_ptr, png_ptr->chunk_name, 4);
416
 
 
417
 
      png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
418
 
         length);
 
416
      png_uint_32 length = png_read_chunk_header(png_ptr);
 
417
      PNG_CONST png_bytep chunk_name = png_ptr->chunk_name;
419
418
 
420
419
      /* This should be a binary subdivision search or a hash for
421
420
       * matching the chunk name rather than a linear search.
422
421
       */
423
 
      if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
424
 
        if(png_ptr->mode & PNG_AFTER_IDAT)
 
422
      if (!png_memcmp(chunk_name, png_IDAT, 4))
 
423
        if (png_ptr->mode & PNG_AFTER_IDAT)
425
424
          png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
426
425
 
427
 
      if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
 
426
      if (!png_memcmp(chunk_name, png_IHDR, 4))
428
427
         png_handle_IHDR(png_ptr, info_ptr, length);
429
 
      else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
 
428
      else if (!png_memcmp(chunk_name, png_IEND, 4))
430
429
         png_handle_IEND(png_ptr, info_ptr, length);
431
430
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
432
 
      else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
 
431
      else if (png_handle_as_unknown(png_ptr, chunk_name))
433
432
      {
434
 
         if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
 
433
         if (!png_memcmp(chunk_name, png_IDAT, 4))
435
434
            png_ptr->mode |= PNG_HAVE_IDAT;
436
435
         png_handle_unknown(png_ptr, info_ptr, length);
437
 
         if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
 
436
         if (!png_memcmp(chunk_name, png_PLTE, 4))
438
437
            png_ptr->mode |= PNG_HAVE_PLTE;
439
 
         else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
 
438
         else if (!png_memcmp(chunk_name, png_IDAT, 4))
440
439
         {
441
440
            if (!(png_ptr->mode & PNG_HAVE_IHDR))
442
441
               png_error(png_ptr, "Missing IHDR before IDAT");
447
446
         }
448
447
      }
449
448
#endif
450
 
      else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
 
449
      else if (!png_memcmp(chunk_name, png_PLTE, 4))
451
450
         png_handle_PLTE(png_ptr, info_ptr, length);
452
 
      else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
 
451
      else if (!png_memcmp(chunk_name, png_IDAT, 4))
453
452
      {
454
453
         if (!(png_ptr->mode & PNG_HAVE_IHDR))
455
454
            png_error(png_ptr, "Missing IHDR before IDAT");
456
455
         else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
457
456
                  !(png_ptr->mode & PNG_HAVE_PLTE))
458
457
            png_error(png_ptr, "Missing PLTE before IDAT");
459
 
 
460
458
#if defined(PNG_READ_APNG_SUPPORTED)
461
459
         png_have_info(png_ptr, info_ptr);
462
460
#endif
465
463
         break;
466
464
      }
467
465
#if defined(PNG_READ_bKGD_SUPPORTED)
468
 
      else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
 
466
      else if (!png_memcmp(chunk_name, png_bKGD, 4))
469
467
         png_handle_bKGD(png_ptr, info_ptr, length);
470
468
#endif
471
469
#if defined(PNG_READ_cHRM_SUPPORTED)
472
 
      else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
 
470
      else if (!png_memcmp(chunk_name, png_cHRM, 4))
473
471
         png_handle_cHRM(png_ptr, info_ptr, length);
474
472
#endif
475
473
#if defined(PNG_READ_gAMA_SUPPORTED)
476
 
      else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
 
474
      else if (!png_memcmp(chunk_name, png_gAMA, 4))
477
475
         png_handle_gAMA(png_ptr, info_ptr, length);
478
476
#endif
479
477
#if defined(PNG_READ_hIST_SUPPORTED)
480
 
      else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
 
478
      else if (!png_memcmp(chunk_name, png_hIST, 4))
481
479
         png_handle_hIST(png_ptr, info_ptr, length);
482
480
#endif
483
481
#if defined(PNG_READ_oFFs_SUPPORTED)
484
 
      else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
 
482
      else if (!png_memcmp(chunk_name, png_oFFs, 4))
485
483
         png_handle_oFFs(png_ptr, info_ptr, length);
486
484
#endif
487
485
#if defined(PNG_READ_pCAL_SUPPORTED)
488
 
      else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
 
486
      else if (!png_memcmp(chunk_name, png_pCAL, 4))
489
487
         png_handle_pCAL(png_ptr, info_ptr, length);
490
488
#endif
491
489
#if defined(PNG_READ_sCAL_SUPPORTED)
492
 
      else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
 
490
      else if (!png_memcmp(chunk_name, png_sCAL, 4))
493
491
         png_handle_sCAL(png_ptr, info_ptr, length);
494
492
#endif
495
493
#if defined(PNG_READ_pHYs_SUPPORTED)
496
 
      else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
 
494
      else if (!png_memcmp(chunk_name, png_pHYs, 4))
497
495
         png_handle_pHYs(png_ptr, info_ptr, length);
498
496
#endif
499
497
#if defined(PNG_READ_sBIT_SUPPORTED)
500
 
      else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
 
498
      else if (!png_memcmp(chunk_name, png_sBIT, 4))
501
499
         png_handle_sBIT(png_ptr, info_ptr, length);
502
500
#endif
503
501
#if defined(PNG_READ_sRGB_SUPPORTED)
504
 
      else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
 
502
      else if (!png_memcmp(chunk_name, png_sRGB, 4))
505
503
         png_handle_sRGB(png_ptr, info_ptr, length);
506
504
#endif
507
505
#if defined(PNG_READ_iCCP_SUPPORTED)
508
 
      else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
 
506
      else if (!png_memcmp(chunk_name, png_iCCP, 4))
509
507
         png_handle_iCCP(png_ptr, info_ptr, length);
510
508
#endif
511
509
#if defined(PNG_READ_sPLT_SUPPORTED)
512
 
      else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
 
510
      else if (!png_memcmp(chunk_name, png_sPLT, 4))
513
511
         png_handle_sPLT(png_ptr, info_ptr, length);
514
512
#endif
515
513
#if defined(PNG_READ_tEXt_SUPPORTED)
516
 
      else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
 
514
      else if (!png_memcmp(chunk_name, png_tEXt, 4))
517
515
         png_handle_tEXt(png_ptr, info_ptr, length);
518
516
#endif
519
517
#if defined(PNG_READ_tIME_SUPPORTED)
520
 
      else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
 
518
      else if (!png_memcmp(chunk_name, png_tIME, 4))
521
519
         png_handle_tIME(png_ptr, info_ptr, length);
522
520
#endif
523
521
#if defined(PNG_READ_tRNS_SUPPORTED)
524
 
      else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
 
522
      else if (!png_memcmp(chunk_name, png_tRNS, 4))
525
523
         png_handle_tRNS(png_ptr, info_ptr, length);
526
524
#endif
527
525
#if defined(PNG_READ_zTXt_SUPPORTED)
528
 
      else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
 
526
      else if (!png_memcmp(chunk_name, png_zTXt, 4))
529
527
         png_handle_zTXt(png_ptr, info_ptr, length);
530
528
#endif
531
529
#if defined(PNG_READ_iTXt_SUPPORTED)
532
 
      else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
 
530
      else if (!png_memcmp(chunk_name, png_iTXt, 4))
533
531
         png_handle_iTXt(png_ptr, info_ptr, length);
534
532
#endif
535
533
#if defined(PNG_READ_APNG_SUPPORTED)
536
 
      else if (!png_memcmp(png_ptr->chunk_name, png_acTL, 4))
 
534
      else if (!png_memcmp(chunk_name, png_acTL, 4))
537
535
         png_handle_acTL(png_ptr, info_ptr, length);
538
 
      else if (!png_memcmp(png_ptr->chunk_name, png_fcTL, 4))
 
536
      else if (!png_memcmp(chunk_name, png_fcTL, 4))
539
537
         png_handle_fcTL(png_ptr, info_ptr, length);
540
 
      else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4))
 
538
      else if (!png_memcmp(chunk_name, png_fdAT, 4))
541
539
         png_handle_fdAT(png_ptr, info_ptr, length);
542
540
#endif
543
541
      else
552
550
{
553
551
    png_byte have_chunk_after_DAT; /* after IDAT or after fdAT */
554
552
    
555
 
    png_debug(0, "Reading frame head\n");
 
553
    png_debug(0, "Reading frame head");
556
554
    
557
555
    if (!(png_ptr->mode & PNG_HAVE_acTL))
558
556
        png_error(png_ptr, "attempt to png_read_frame_head() but "
627
625
void PNGAPI
628
626
png_read_update_info(png_structp png_ptr, png_infop info_ptr)
629
627
{
630
 
   png_debug(1, "in png_read_update_info\n");
631
 
   if(png_ptr == NULL) return;
 
628
   png_debug(1, "in png_read_update_info");
 
629
   if (png_ptr == NULL) return;
632
630
   if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
 
631
 
633
632
      png_read_start_row(png_ptr);
634
633
   else
635
634
      png_warning(png_ptr,
646
645
void PNGAPI
647
646
png_start_read_image(png_structp png_ptr)
648
647
{
649
 
   png_debug(1, "in png_start_read_image\n");
650
 
   if(png_ptr == NULL) return;
 
648
   png_debug(1, "in png_start_read_image");
 
649
   if (png_ptr == NULL) return;
651
650
   if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
652
651
      png_read_start_row(png_ptr);
653
652
}
664
663
   PNG_CONST PNG_IEND;
665
664
#endif
666
665
   PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
667
 
     0xff};
 
666
      0xff};
668
667
   PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
669
668
#endif
670
669
   int ret;
671
 
   if(png_ptr == NULL) return;
672
 
   png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
 
670
   if (png_ptr == NULL) return;
 
671
   png_debug2(1, "in png_read_row (row %lu, pass %d)",
673
672
      png_ptr->row_number, png_ptr->pass);
674
673
   if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
675
674
      png_read_start_row(png_ptr);
796
795
         
797
796
         while (!png_ptr->idat_size || bytes_to_skip != 0)
798
797
         {
799
 
            png_byte chunk_length[4];
800
 
 
801
798
            png_crc_finish(png_ptr, bytes_to_skip);
802
799
            bytes_to_skip = 0;
803
800
            
804
 
            png_read_data(png_ptr, chunk_length, 4);
805
 
            png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
806
 
            
807
 
            png_reset_crc(png_ptr);
808
 
            png_crc_read(png_ptr, png_ptr->chunk_name, 4);
 
801
            png_ptr->idat_size = png_read_chunk_header(png_ptr);
809
802
            
810
803
#if defined(PNG_READ_APNG_SUPPORTED)
811
804
            if (png_ptr->num_frames_read == 0)
857
850
      if (ret != Z_OK)
858
851
         png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
859
852
                   "Decompression error");
860
 
 
 
853
            
861
854
   } while (png_ptr->zstream.avail_out);
862
855
 
863
856
   png_ptr->row_info.color_type = png_ptr->color_type;
868
861
   png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
869
862
       png_ptr->row_info.width);
870
863
 
871
 
   if(png_ptr->row_buf[0])
 
864
   if (png_ptr->row_buf[0])
872
865
   png_read_filter_row(png_ptr, &(png_ptr->row_info),
873
866
      png_ptr->row_buf + 1, png_ptr->prev_row + 1,
874
867
      (int)(png_ptr->row_buf[0]));
877
870
      png_ptr->rowbytes + 1);
878
871
 
879
872
#if defined(PNG_MNG_FEATURES_SUPPORTED)
880
 
   if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
 
873
   if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
881
874
      (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
882
875
   {
883
876
      /* Intrapixel differencing */
956
949
   png_bytepp rp;
957
950
   png_bytepp dp;
958
951
 
959
 
   png_debug(1, "in png_read_rows\n");
960
 
   if(png_ptr == NULL) return;
 
952
   png_debug(1, "in png_read_rows");
 
953
   if (png_ptr == NULL) return;
961
954
   rp = row;
962
955
   dp = display_row;
963
956
   if (rp != NULL && dp != NULL)
968
961
 
969
962
         png_read_row(png_ptr, rptr, dptr);
970
963
      }
971
 
   else if(rp != NULL)
 
964
   else if (rp != NULL)
972
965
      for (i = 0; i < num_rows; i++)
973
966
      {
974
967
         png_bytep rptr = *rp;
975
968
         png_read_row(png_ptr, rptr, png_bytep_NULL);
976
969
         rp++;
977
970
      }
978
 
   else if(dp != NULL)
 
971
   else if (dp != NULL)
979
972
      for (i = 0; i < num_rows; i++)
980
973
      {
981
974
         png_bytep dptr = *dp;
1001
994
void PNGAPI
1002
995
png_read_image(png_structp png_ptr, png_bytepp image)
1003
996
{
1004
 
   png_uint_32 i,image_height;
 
997
   png_uint_32 i, image_height;
1005
998
   int pass, j;
1006
999
   png_bytepp rp;
1007
1000
 
1008
 
   png_debug(1, "in png_read_image\n");
1009
 
   if(png_ptr == NULL) return;
 
1001
   png_debug(1, "in png_read_image");
 
1002
   if (png_ptr == NULL) return;
1010
1003
 
1011
1004
#ifdef PNG_READ_INTERLACING_SUPPORTED
1012
1005
   pass = png_set_interlace_handling(png_ptr);
1041
1034
void PNGAPI
1042
1035
png_read_end(png_structp png_ptr, png_infop info_ptr)
1043
1036
{
1044
 
   png_byte chunk_length[4];
1045
 
   png_uint_32 length;
1046
 
 
1047
 
   png_debug(1, "in png_read_end\n");
1048
 
   if(png_ptr == NULL) return;
 
1037
   png_debug(1, "in png_read_end");
 
1038
   if (png_ptr == NULL) return;
1049
1039
   png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
1050
1040
 
1051
1041
   do
1112
1102
      PNG_CONST PNG_fdAT;
1113
1103
#endif
1114
1104
#endif /* PNG_USE_LOCAL_ARRAYS */
1115
 
 
1116
 
      png_read_data(png_ptr, chunk_length, 4);
1117
 
      length = png_get_uint_31(png_ptr,chunk_length);
1118
 
 
1119
 
      png_reset_crc(png_ptr);
1120
 
      png_crc_read(png_ptr, png_ptr->chunk_name, 4);
1121
 
 
1122
 
      png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
1123
 
 
1124
 
      if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
 
1105
      png_uint_32 length = png_read_chunk_header(png_ptr);
 
1106
      PNG_CONST png_bytep chunk_name = png_ptr->chunk_name;
 
1107
 
 
1108
      if (!png_memcmp(chunk_name, png_IHDR, 4))
1125
1109
         png_handle_IHDR(png_ptr, info_ptr, length);
1126
 
      else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
 
1110
      else if (!png_memcmp(chunk_name, png_IEND, 4))
1127
1111
         png_handle_IEND(png_ptr, info_ptr, length);
1128
1112
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
1129
 
      else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
 
1113
      else if (png_handle_as_unknown(png_ptr, chunk_name))
1130
1114
      {
1131
 
         if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
 
1115
         if (!png_memcmp(chunk_name, png_IDAT, 4))
1132
1116
         {
1133
1117
            if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
1134
1118
               png_error(png_ptr, "Too many IDAT's found");
1135
1119
         }
1136
1120
         png_handle_unknown(png_ptr, info_ptr, length);
1137
 
         if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
 
1121
         if (!png_memcmp(chunk_name, png_PLTE, 4))
1138
1122
            png_ptr->mode |= PNG_HAVE_PLTE;
1139
1123
      }
1140
1124
#endif
1141
 
      else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
 
1125
      else if (!png_memcmp(chunk_name, png_IDAT, 4))
1142
1126
      {
1143
1127
         /* Zero length IDATs are legal after the last IDAT has been
1144
1128
          * read, but not after other chunks have been read.
1147
1131
            png_error(png_ptr, "Too many IDAT's found");
1148
1132
         png_crc_finish(png_ptr, length);
1149
1133
      }
1150
 
      else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
 
1134
      else if (!png_memcmp(chunk_name, png_PLTE, 4))
1151
1135
         png_handle_PLTE(png_ptr, info_ptr, length);
1152
1136
#if defined(PNG_READ_bKGD_SUPPORTED)
1153
 
      else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
 
1137
      else if (!png_memcmp(chunk_name, png_bKGD, 4))
1154
1138
         png_handle_bKGD(png_ptr, info_ptr, length);
1155
1139
#endif
1156
1140
#if defined(PNG_READ_cHRM_SUPPORTED)
1157
 
      else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
 
1141
      else if (!png_memcmp(chunk_name, png_cHRM, 4))
1158
1142
         png_handle_cHRM(png_ptr, info_ptr, length);
1159
1143
#endif
1160
1144
#if defined(PNG_READ_gAMA_SUPPORTED)
1161
 
      else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
 
1145
      else if (!png_memcmp(chunk_name, png_gAMA, 4))
1162
1146
         png_handle_gAMA(png_ptr, info_ptr, length);
1163
1147
#endif
1164
1148
#if defined(PNG_READ_hIST_SUPPORTED)
1165
 
      else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
 
1149
      else if (!png_memcmp(chunk_name, png_hIST, 4))
1166
1150
         png_handle_hIST(png_ptr, info_ptr, length);
1167
1151
#endif
1168
1152
#if defined(PNG_READ_oFFs_SUPPORTED)
1169
 
      else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
 
1153
      else if (!png_memcmp(chunk_name, png_oFFs, 4))
1170
1154
         png_handle_oFFs(png_ptr, info_ptr, length);
1171
1155
#endif
1172
1156
#if defined(PNG_READ_pCAL_SUPPORTED)
1173
 
      else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
 
1157
      else if (!png_memcmp(chunk_name, png_pCAL, 4))
1174
1158
         png_handle_pCAL(png_ptr, info_ptr, length);
1175
1159
#endif
1176
1160
#if defined(PNG_READ_sCAL_SUPPORTED)
1177
 
      else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
 
1161
      else if (!png_memcmp(chunk_name, png_sCAL, 4))
1178
1162
         png_handle_sCAL(png_ptr, info_ptr, length);
1179
1163
#endif
1180
1164
#if defined(PNG_READ_pHYs_SUPPORTED)
1181
 
      else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
 
1165
      else if (!png_memcmp(chunk_name, png_pHYs, 4))
1182
1166
         png_handle_pHYs(png_ptr, info_ptr, length);
1183
1167
#endif
1184
1168
#if defined(PNG_READ_sBIT_SUPPORTED)
1185
 
      else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
 
1169
      else if (!png_memcmp(chunk_name, png_sBIT, 4))
1186
1170
         png_handle_sBIT(png_ptr, info_ptr, length);
1187
1171
#endif
1188
1172
#if defined(PNG_READ_sRGB_SUPPORTED)
1189
 
      else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
 
1173
      else if (!png_memcmp(chunk_name, png_sRGB, 4))
1190
1174
         png_handle_sRGB(png_ptr, info_ptr, length);
1191
1175
#endif
1192
1176
#if defined(PNG_READ_iCCP_SUPPORTED)
1193
 
      else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
 
1177
      else if (!png_memcmp(chunk_name, png_iCCP, 4))
1194
1178
         png_handle_iCCP(png_ptr, info_ptr, length);
1195
1179
#endif
1196
1180
#if defined(PNG_READ_sPLT_SUPPORTED)
1197
 
      else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
 
1181
      else if (!png_memcmp(chunk_name, png_sPLT, 4))
1198
1182
         png_handle_sPLT(png_ptr, info_ptr, length);
1199
1183
#endif
1200
1184
#if defined(PNG_READ_tEXt_SUPPORTED)
1201
 
      else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
 
1185
      else if (!png_memcmp(chunk_name, png_tEXt, 4))
1202
1186
         png_handle_tEXt(png_ptr, info_ptr, length);
1203
1187
#endif
1204
1188
#if defined(PNG_READ_tIME_SUPPORTED)
1205
 
      else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
 
1189
      else if (!png_memcmp(chunk_name, png_tIME, 4))
1206
1190
         png_handle_tIME(png_ptr, info_ptr, length);
1207
1191
#endif
1208
1192
#if defined(PNG_READ_tRNS_SUPPORTED)
1209
 
      else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
 
1193
      else if (!png_memcmp(chunk_name, png_tRNS, 4))
1210
1194
         png_handle_tRNS(png_ptr, info_ptr, length);
1211
1195
#endif
1212
1196
#if defined(PNG_READ_zTXt_SUPPORTED)
1213
 
      else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
 
1197
      else if (!png_memcmp(chunk_name, png_zTXt, 4))
1214
1198
         png_handle_zTXt(png_ptr, info_ptr, length);
1215
1199
#endif
1216
1200
#if defined(PNG_READ_iTXt_SUPPORTED)
1217
 
      else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
 
1201
      else if (!png_memcmp(chunk_name, png_iTXt, 4))
1218
1202
         png_handle_iTXt(png_ptr, info_ptr, length);
1219
1203
#endif
1220
1204
#if defined(PNG_READ_APNG_SUPPORTED)
1243
1227
   png_voidp mem_ptr = NULL;
1244
1228
#endif
1245
1229
 
1246
 
   png_debug(1, "in png_destroy_read_struct\n");
 
1230
   png_debug(1, "in png_destroy_read_struct");
1247
1231
   if (png_ptr_ptr != NULL)
1248
 
   {
1249
1232
      png_ptr = *png_ptr_ptr;
 
1233
   if (png_ptr == NULL)
 
1234
      return;
 
1235
 
1250
1236
#ifdef PNG_USER_MEM_SUPPORTED
1251
 
      free_fn = png_ptr->free_fn;
1252
 
      mem_ptr = png_ptr->mem_ptr;
 
1237
   free_fn = png_ptr->free_fn;
 
1238
   mem_ptr = png_ptr->mem_ptr;
1253
1239
#endif
1254
 
   }
1255
1240
 
1256
1241
   if (info_ptr_ptr != NULL)
1257
1242
      info_ptr = *info_ptr_ptr;
1316
1301
   png_free_ptr free_fn;
1317
1302
#endif
1318
1303
 
1319
 
   png_debug(1, "in png_read_destroy\n");
 
1304
   png_debug(1, "in png_read_destroy");
1320
1305
   if (info_ptr != NULL)
1321
1306
      png_info_destroy(png_ptr, info_ptr);
1322
1307
 
1326
1311
   png_free(png_ptr, png_ptr->zbuf);
1327
1312
   png_free(png_ptr, png_ptr->big_row_buf);
1328
1313
   png_free(png_ptr, png_ptr->prev_row);
 
1314
   png_free(png_ptr, png_ptr->chunkdata);
1329
1315
#if defined(PNG_READ_DITHER_SUPPORTED)
1330
1316
   png_free(png_ptr, png_ptr->palette_lookup);
1331
1317
   png_free(png_ptr, png_ptr->dither_index);
1422
1408
    * being used again.
1423
1409
    */
1424
1410
#ifdef PNG_SETJMP_SUPPORTED
1425
 
   png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
 
1411
   png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
1426
1412
#endif
1427
1413
 
1428
1414
   error_fn = png_ptr->error_fn;
1432
1418
   free_fn = png_ptr->free_fn;
1433
1419
#endif
1434
1420
 
1435
 
   png_memset(png_ptr, 0, png_sizeof (png_struct));
 
1421
   png_memset(png_ptr, 0, png_sizeof(png_struct));
1436
1422
 
1437
1423
   png_ptr->error_fn = error_fn;
1438
1424
   png_ptr->warning_fn = warning_fn;
1442
1428
#endif
1443
1429
 
1444
1430
#ifdef PNG_SETJMP_SUPPORTED
1445
 
   png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
 
1431
   png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
1446
1432
#endif
1447
1433
 
1448
1434
}
1450
1436
void PNGAPI
1451
1437
png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
1452
1438
{
1453
 
   if(png_ptr == NULL) return;
 
1439
   if (png_ptr == NULL) return;
1454
1440
   png_ptr->read_row_fn = read_row_fn;
1455
1441
}
1456
1442
 
1464
1450
{
1465
1451
   int row;
1466
1452
 
1467
 
   if(png_ptr == NULL) return;
 
1453
   if (png_ptr == NULL) return;
1468
1454
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
1469
1455
   /* invert the alpha channel from opacity to transparency
1470
1456
    */
1477
1463
    */
1478
1464
   png_read_info(png_ptr, info_ptr);
1479
1465
   if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
1480
 
      png_error(png_ptr,"Image is too high to process with png_read_png()");
 
1466
      png_error(png_ptr, "Image is too high to process with png_read_png()");
1481
1467
 
1482
1468
   /* -------------- image transformations start here ------------------- */
1483
1469
 
1584
1570
#ifdef PNG_FREE_ME_SUPPORTED
1585
1571
   png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
1586
1572
#endif
1587
 
   if(info_ptr->row_pointers == NULL)
 
1573
   if (info_ptr->row_pointers == NULL)
1588
1574
   {
1589
1575
      info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
1590
1576
         info_ptr->height * png_sizeof(png_bytep));
1591
1577
#ifdef PNG_FREE_ME_SUPPORTED
1592
1578
      info_ptr->free_me |= PNG_FREE_ROWS;
1593
1579
#endif
 
1580
      png_memset(info_ptr->row_pointers, 0, info_ptr->height
 
1581
         * png_sizeof(png_bytep));
1594
1582
      for (row = 0; row < (int)info_ptr->height; row++)
1595
 
      {
1596
1583
         info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
1597
1584
            png_get_rowbytes(png_ptr, info_ptr));
1598
 
      }
1599
1585
   }
1600
1586
 
1601
1587
   png_read_image(png_ptr, info_ptr->row_pointers);