~ubuntu-branches/ubuntu/hardy/ghostscript/hardy

« back to all changes in this revision

Viewing changes to libpng/pngpread.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2007-11-22 12:17:43 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071122121743-cd70s3ypq0r243mp
Tags: 8.61.dfsg.1-0ubtuntu1
* New upstream release
  o Final 8.61 release
* debian/patches/09_ijs_krgb_support.dpatch: Adapted to upstream changes.
* debian/rules: Updated CUPS-related variables for "make install" calls.
* debian/rules: Remove /usr/include/ghostscript from the ghostscript
  package, they go into lings-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/* pngpread.c - read a png file in push mode
3
3
 *
4
 
 * Last changed in libpng 1.2.17 May 15, 2007
 
4
 * Last changed in libpng 1.2.22 [October 13, 2007]
5
5
 * For conditions of distribution and use, see copyright notice in png.h
6
6
 * Copyright (c) 1998-2007 Glenn Randers-Pehrson
7
7
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
137
137
png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
138
138
{
139
139
#ifdef PNG_USE_LOCAL_ARRAYS
140
 
      PNG_IHDR;
141
 
      PNG_IDAT;
142
 
      PNG_IEND;
143
 
      PNG_PLTE;
 
140
      PNG_CONST PNG_IHDR;
 
141
      PNG_CONST PNG_IDAT;
 
142
      PNG_CONST PNG_IEND;
 
143
      PNG_CONST PNG_PLTE;
144
144
#if defined(PNG_READ_bKGD_SUPPORTED)
145
 
      PNG_bKGD;
 
145
      PNG_CONST PNG_bKGD;
146
146
#endif
147
147
#if defined(PNG_READ_cHRM_SUPPORTED)
148
 
      PNG_cHRM;
 
148
      PNG_CONST PNG_cHRM;
149
149
#endif
150
150
#if defined(PNG_READ_gAMA_SUPPORTED)
151
 
      PNG_gAMA;
 
151
      PNG_CONST PNG_gAMA;
152
152
#endif
153
153
#if defined(PNG_READ_hIST_SUPPORTED)
154
 
      PNG_hIST;
 
154
      PNG_CONST PNG_hIST;
155
155
#endif
156
156
#if defined(PNG_READ_iCCP_SUPPORTED)
157
 
      PNG_iCCP;
 
157
      PNG_CONST PNG_iCCP;
158
158
#endif
159
159
#if defined(PNG_READ_iTXt_SUPPORTED)
160
 
      PNG_iTXt;
 
160
      PNG_CONST PNG_iTXt;
161
161
#endif
162
162
#if defined(PNG_READ_oFFs_SUPPORTED)
163
 
      PNG_oFFs;
 
163
      PNG_CONST PNG_oFFs;
164
164
#endif
165
165
#if defined(PNG_READ_pCAL_SUPPORTED)
166
 
      PNG_pCAL;
 
166
      PNG_CONST PNG_pCAL;
167
167
#endif
168
168
#if defined(PNG_READ_pHYs_SUPPORTED)
169
 
      PNG_pHYs;
 
169
      PNG_CONST PNG_pHYs;
170
170
#endif
171
171
#if defined(PNG_READ_sBIT_SUPPORTED)
172
 
      PNG_sBIT;
 
172
      PNG_CONST PNG_sBIT;
173
173
#endif
174
174
#if defined(PNG_READ_sCAL_SUPPORTED)
175
 
      PNG_sCAL;
 
175
      PNG_CONST PNG_sCAL;
176
176
#endif
177
177
#if defined(PNG_READ_sRGB_SUPPORTED)
178
 
      PNG_sRGB;
 
178
      PNG_CONST PNG_sRGB;
179
179
#endif
180
180
#if defined(PNG_READ_sPLT_SUPPORTED)
181
 
      PNG_sPLT;
 
181
      PNG_CONST PNG_sPLT;
182
182
#endif
183
183
#if defined(PNG_READ_tEXt_SUPPORTED)
184
 
      PNG_tEXt;
 
184
      PNG_CONST PNG_tEXt;
185
185
#endif
186
186
#if defined(PNG_READ_tIME_SUPPORTED)
187
 
      PNG_tIME;
 
187
      PNG_CONST PNG_tIME;
188
188
#endif
189
189
#if defined(PNG_READ_tRNS_SUPPORTED)
190
 
      PNG_tRNS;
 
190
      PNG_CONST PNG_tRNS;
191
191
#endif
192
192
#if defined(PNG_READ_zTXt_SUPPORTED)
193
 
      PNG_zTXt;
 
193
      PNG_CONST PNG_zTXt;
194
194
#endif
195
195
#endif /* PNG_USE_LOCAL_ARRAYS */
196
196
   /* First we make sure we have enough data for the 4 byte chunk name
216
216
      png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
217
217
   }
218
218
 
219
 
   if (!png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4))
 
219
   if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
220
220
     if(png_ptr->mode & PNG_AFTER_IDAT)
221
221
        png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
222
222
 
273
273
      }
274
274
      png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
275
275
   }
276
 
   else if (!png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4))
 
276
   else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
277
277
   {
278
278
      /* If we reach an IDAT chunk, this means we have read all of the
279
279
       * header chunks, and we can start reading the image (or if this
660
660
png_push_read_IDAT(png_structp png_ptr)
661
661
{
662
662
#ifdef PNG_USE_LOCAL_ARRAYS
663
 
   PNG_IDAT;
 
663
   PNG_CONST PNG_IDAT;
664
664
#endif
665
665
   if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
666
666
   {
678
678
      png_crc_read(png_ptr, png_ptr->chunk_name, 4);
679
679
      png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
680
680
 
681
 
      if (png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4))
 
681
      if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
682
682
      {
683
683
         png_ptr->process_mode = PNG_READ_CHUNK_MODE;
684
684
         if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
990
990
   /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
991
991
 
992
992
   /* start of interlace block */
993
 
   const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
 
993
   PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
994
994
 
995
995
   /* offset to next interlace block */
996
 
   const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
 
996
   PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
997
997
 
998
998
   /* start of interlace block in the y direction */
999
 
   const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
 
999
   PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
1000
1000
 
1001
1001
   /* offset to next interlace block in the y direction */
1002
 
   const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
1003
 
 
1004
 
   /* Width of interlace block.  This is not currently used - if you need
1005
 
    * it, uncomment it here and in png.h
1006
 
   const int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
1007
 
   */
 
1002
   PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
1008
1003
 
1009
1004
   /* Height of interlace block.  This is not currently used - if you need
1010
1005
    * it, uncomment it here and in png.h
1011
 
   const int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
 
1006
   PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
1012
1007
   */
1013
1008
#endif
1014
1009
 
1062
1057
   if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
1063
1058
      {
1064
1059
         png_error(png_ptr, "Out of place tEXt");
1065
 
         /* to quiet some compiler warnings */
1066
 
         if(info_ptr == NULL) return;
 
1060
         info_ptr = info_ptr; /* to quiet some compiler warnings */
1067
1061
      }
1068
1062
 
1069
1063
#ifdef PNG_MAX_MALLOC_64K
1126
1120
      for (text = key; *text; text++)
1127
1121
         /* empty loop */ ;
1128
1122
 
1129
 
      if (text != key + png_ptr->current_text_size)
 
1123
      if (text < key + png_ptr->current_text_size)
1130
1124
         text++;
1131
1125
 
1132
1126
      text_ptr = (png_textp)png_malloc(png_ptr,
1159
1153
   if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
1160
1154
      {
1161
1155
         png_error(png_ptr, "Out of place zTXt");
1162
 
         /* to quiet some compiler warnings */
1163
 
         if(info_ptr == NULL) return;
 
1156
         info_ptr = info_ptr; /* to quiet some compiler warnings */
1164
1157
      }
1165
1158
 
1166
1159
#ifdef PNG_MAX_MALLOC_64K
1222
1215
         /* empty loop */ ;
1223
1216
 
1224
1217
      /* zTXt can't have zero text */
1225
 
      if (text == key + png_ptr->current_text_size)
 
1218
      if (text >= key + png_ptr->current_text_size)
1226
1219
      {
1227
1220
         png_ptr->current_text = NULL;
1228
1221
         png_free(png_ptr, key);
1352
1345
   if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
1353
1346
      {
1354
1347
         png_error(png_ptr, "Out of place iTXt");
1355
 
         /* to quiet some compiler warnings */
1356
 
         if(info_ptr == NULL) return;
 
1348
         info_ptr = info_ptr; /* to quiet some compiler warnings */
1357
1349
      }
1358
1350
 
1359
1351
#ifdef PNG_MAX_MALLOC_64K
1420
1412
      for (lang = key; *lang; lang++)
1421
1413
         /* empty loop */ ;
1422
1414
 
1423
 
      if (lang != key + png_ptr->current_text_size)
 
1415
      if (lang < key + png_ptr->current_text_size - 3)
1424
1416
         lang++;
1425
1417
 
1426
1418
      comp_flag = *lang++;
1430
1422
         /* empty loop */ ;
1431
1423
      lang_key++;        /* skip NUL separator */
1432
1424
 
1433
 
      for (text = lang_key; *text; text++)
1434
 
         /* empty loop */ ;
 
1425
      text=lang_key;
 
1426
      if (lang_key < key + png_ptr->current_text_size - 1)
 
1427
      {
 
1428
        for (; *text; text++)
 
1429
           /* empty loop */ ;
 
1430
      }
1435
1431
 
1436
 
      if (text != key + png_ptr->current_text_size)
 
1432
      if (text < key + png_ptr->current_text_size)
1437
1433
         text++;
1438
1434
 
1439
1435
      text_ptr = (png_textp)png_malloc(png_ptr,
1471
1467
   if (!(png_ptr->chunk_name[0] & 0x20))
1472
1468
   {
1473
1469
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
1474
 
      if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
1475
 
           PNG_HANDLE_CHUNK_ALWAYS
 
1470
     if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
 
1471
          PNG_HANDLE_CHUNK_ALWAYS
1476
1472
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
1477
 
           && png_ptr->read_user_chunk_fn == NULL
1478
 
#endif
1479
 
         )
1480
 
#endif
1481
 
         png_chunk_error(png_ptr, "unknown critical chunk");
 
1473
          && png_ptr->read_user_chunk_fn == NULL
 
1474
#endif
 
1475
        )
 
1476
#endif
 
1477
        png_chunk_error(png_ptr, "unknown critical chunk");
1482
1478
 
1483
 
      /* to quiet compiler warnings about unused info_ptr */
1484
 
      if (info_ptr == NULL)
1485
 
         return;
 
1479
     info_ptr = info_ptr; /* to quiet some compiler warnings */
1486
1480
   }
1487
1481
 
1488
1482
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
1489
1483
   if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
1490
1484
   {
1491
1485
#ifdef PNG_MAX_MALLOC_64K
1492
 
       if (length > (png_uint_32)65535L)
1493
 
       {
1494
 
           png_warning(png_ptr, "unknown chunk too large to fit in memory");
1495
 
           skip = length - (png_uint_32)65535L;
1496
 
           length = (png_uint_32)65535L;
1497
 
       }
 
1486
      if (length > (png_uint_32)65535L)
 
1487
      {
 
1488
          png_warning(png_ptr, "unknown chunk too large to fit in memory");
 
1489
          skip = length - (png_uint_32)65535L;
 
1490
          length = (png_uint_32)65535L;
 
1491
      }
1498
1492
#endif
1499
 
       png_strcpy((png_charp)png_ptr->unknown_chunk.name,
1500
 
         (png_charp)png_ptr->chunk_name);
1501
 
       png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
1502
 
       png_ptr->unknown_chunk.size = (png_size_t)length;
1503
 
       png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
 
1493
      png_strncpy((png_charp)png_ptr->unknown_chunk.name,
 
1494
         (png_charp)png_ptr->chunk_name, 4);
 
1495
      png_ptr->unknown_chunk.name[4] = '\0';
 
1496
      png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
 
1497
      png_ptr->unknown_chunk.size = (png_size_t)length;
 
1498
      png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
1504
1499
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
1505
 
       if(png_ptr->read_user_chunk_fn != NULL)
1506
 
       {
1507
 
          /* callback to user unknown chunk handler */
1508
 
          int ret;
1509
 
          ret = (*(png_ptr->read_user_chunk_fn))
1510
 
            (png_ptr, &png_ptr->unknown_chunk);
1511
 
          if (ret < 0)
1512
 
             png_chunk_error(png_ptr, "error in user chunk");
1513
 
          if (ret == 0)
1514
 
          {
1515
 
             if (!(png_ptr->chunk_name[0] & 0x20))
1516
 
                if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
1517
 
                     PNG_HANDLE_CHUNK_ALWAYS)
1518
 
                   png_chunk_error(png_ptr, "unknown critical chunk");
1519
 
                png_set_unknown_chunks(png_ptr, info_ptr,
1520
 
                   &png_ptr->unknown_chunk, 1);
1521
 
          }
1522
 
       }
 
1500
      if(png_ptr->read_user_chunk_fn != NULL)
 
1501
      {
 
1502
         /* callback to user unknown chunk handler */
 
1503
         int ret;
 
1504
         ret = (*(png_ptr->read_user_chunk_fn))
 
1505
           (png_ptr, &png_ptr->unknown_chunk);
 
1506
         if (ret < 0)
 
1507
            png_chunk_error(png_ptr, "error in user chunk");
 
1508
         if (ret == 0)
 
1509
         {
 
1510
            if (!(png_ptr->chunk_name[0] & 0x20))
 
1511
               if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
 
1512
                    PNG_HANDLE_CHUNK_ALWAYS)
 
1513
                  png_chunk_error(png_ptr, "unknown critical chunk");
 
1514
            png_set_unknown_chunks(png_ptr, info_ptr,
 
1515
               &png_ptr->unknown_chunk, 1);
 
1516
         }
 
1517
      }
1523
1518
#else
1524
 
       png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
 
1519
      png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
1525
1520
#endif
1526
 
       png_free(png_ptr, png_ptr->unknown_chunk.data);
1527
 
       png_ptr->unknown_chunk.data = NULL;
 
1521
      png_free(png_ptr, png_ptr->unknown_chunk.data);
 
1522
      png_ptr->unknown_chunk.data = NULL;
1528
1523
   }
1529
1524
   else
1530
1525
#endif
1559
1554
   png_bytep old_row, png_bytep new_row)
1560
1555
{
1561
1556
#ifdef PNG_USE_LOCAL_ARRAYS
1562
 
   const int FARDATA png_pass_dsp_mask[7] =
 
1557
   PNG_CONST int FARDATA png_pass_dsp_mask[7] =
1563
1558
      {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
1564
1559
#endif
1565
1560
   if(png_ptr == NULL) return;