Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/3rdparty/libpng/png.c

    r561 r846  
    22/* png.c - location for general purpose libpng functions
    33 *
    4  * Last changed in libpng 1.2.39 [August 13, 2009]
    5  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.4.0 [January 3, 2010]
     5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson
    66 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    77 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     
    1212 */
    1313
    14 #define PNG_INTERNAL
    1514#define PNG_NO_EXTERN
     15#define PNG_NO_PEDANTIC_WARNINGS
    1616#include "png.h"
     17#include "pngpriv.h"
    1718
    1819/* Generate a compiler error if there is an old png.h in the search path. */
    19 typedef version_1_2_40 Your_png_h_is_not_version_1_2_40;
     20typedef version_1_4_0 Your_png_h_is_not_version_1_4_0;
    2021
    2122/* Version information for C files.  This had better match the version
    22  * string defined in png.h.  */
    23 
    24 #ifdef PNG_USE_GLOBAL_ARRAYS
    25 /* png_libpng_ver was changed to a function in version 1.0.5c */
    26 PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
    27 
    28 #ifdef PNG_READ_SUPPORTED
    29 
    30 /* png_sig was changed to a function in version 1.0.5c */
    31 /* Place to hold the signature string for a PNG file. */
    32 PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
    33 #endif /* PNG_READ_SUPPORTED */
    34 
    35 /* Invoke global declarations for constant strings for known chunk types */
    36 PNG_IHDR;
    37 PNG_IDAT;
    38 PNG_IEND;
    39 PNG_PLTE;
    40 PNG_bKGD;
    41 PNG_cHRM;
    42 PNG_gAMA;
    43 PNG_hIST;
    44 PNG_iCCP;
    45 PNG_iTXt;
    46 PNG_oFFs;
    47 PNG_pCAL;
    48 PNG_sCAL;
    49 PNG_pHYs;
    50 PNG_sBIT;
    51 PNG_sPLT;
    52 PNG_sRGB;
    53 PNG_tEXt;
    54 PNG_tIME;
    55 PNG_tRNS;
    56 PNG_zTXt;
    57 
    58 #ifdef PNG_READ_SUPPORTED
    59 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
    60 
    61 /* Start of interlace block */
    62 PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
    63 
    64 /* Offset to next interlace block */
    65 PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
    66 
    67 /* Start of interlace block in the y direction */
    68 PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
    69 
    70 /* Offset to next interlace block in the y direction */
    71 PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
    72 
    73 /* Height of interlace block.  This is not currently used - if you need
    74  * it, uncomment it here and in png.h
    75 PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
    76 */
    77 
    78 /* Mask to determine which pixels are valid in a pass */
    79 PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
    80 
    81 /* Mask to determine which pixels to overwrite while displaying */
    82 PNG_CONST int FARDATA png_pass_dsp_mask[]
    83    = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
    84 
    85 #endif /* PNG_READ_SUPPORTED */
    86 #endif /* PNG_USE_GLOBAL_ARRAYS */
     23 * string defined in png.h.
     24 */
    8725
    8826/* Tells libpng that we have already handled the first "num_bytes" bytes
     
    9634png_set_sig_bytes(png_structp png_ptr, int num_bytes)
    9735{
     36   png_debug(1, "in png_set_sig_bytes");
     37
    9838   if (png_ptr == NULL)
    9939      return;
    100    png_debug(1, "in png_set_sig_bytes");
     40
    10141   if (num_bytes > 8)
    102       png_error(png_ptr, "Too many bytes for PNG signature.");
     42      png_error(png_ptr, "Too many bytes for PNG signature");
    10343
    10444   png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
     
    13171}
    13272
    133 #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
    134 /* (Obsolete) function to check signature bytes.  It does not allow one
    135  * to check a partial signature.  This function might be removed in the
    136  * future - use png_sig_cmp().  Returns true (nonzero) if the file is PNG.
    137  */
    138 int PNGAPI
    139 png_check_sig(png_bytep sig, int num)
    140 {
    141   return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
    142 }
    143 #endif
    14473#endif /* PNG_READ_SUPPORTED */
    14574
    14675#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
    14776/* Function to allocate memory for zlib and clear it to 0. */
    148 #ifdef PNG_1_0_X
    149 voidpf PNGAPI
    150 #else
    15177voidpf /* PRIVATE */
    152 #endif
    15378png_zalloc(voidpf png_ptr, uInt items, uInt size)
    15479{
     
    15681   png_structp p=(png_structp)png_ptr;
    15782   png_uint_32 save_flags=p->flags;
    158    png_uint_32 num_bytes;
     83   png_alloc_size_t num_bytes;
    15984
    16085   if (png_ptr == NULL)
     
    16590     return (NULL);
    16691   }
    167    num_bytes = (png_uint_32)items * size;
     92   num_bytes = (png_alloc_size_t)items * size;
    16893
    16994   p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
     
    17196   p->flags=save_flags;
    17297
    173 #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
    174    if (ptr == NULL)
    175        return ((voidpf)ptr);
    176 
    177    if (num_bytes > (png_uint_32)0x8000L)
    178    {
    179       png_memset(ptr, 0, (png_size_t)0x8000L);
    180       png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
    181          (png_size_t)(num_bytes - (png_uint_32)0x8000L));
    182    }
    183    else
    184    {
    185       png_memset(ptr, 0, (png_size_t)num_bytes);
    186    }
    187 #endif
    18898   return ((voidpf)ptr);
    18999}
    190100
    191101/* Function to free memory for zlib */
    192 #ifdef PNG_1_0_X
    193 void PNGAPI
    194 #else
    195102void /* PRIVATE */
    196 #endif
    197103png_zfree(voidpf png_ptr, voidpf ptr)
    198104{
     
    247153
    248154   png_debug(1, "in png_create_info_struct");
     155
    249156   if (png_ptr == NULL)
    250157      return (NULL);
     158
    251159#ifdef PNG_USER_MEM_SUPPORTED
    252160   info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
     
    270178{
    271179   png_infop info_ptr = NULL;
     180
     181   png_debug(1, "in png_destroy_info_struct");
     182
    272183   if (png_ptr == NULL)
    273184      return;
    274185
    275    png_debug(1, "in png_destroy_info_struct");
    276186   if (info_ptr_ptr != NULL)
    277187      info_ptr = *info_ptr_ptr;
     
    295205 * instead.
    296206 */
    297 #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
    298 #undef png_info_init
    299 void PNGAPI
    300 png_info_init(png_infop info_ptr)
    301 {
    302    /* We only come here via pre-1.0.12-compiled applications */
    303    png_info_init_3(&info_ptr, 0);
    304 }
    305 #endif
    306207
    307208void PNGAPI
     
    310211   png_infop info_ptr = *ptr_ptr;
    311212
     213   png_debug(1, "in png_info_init_3");
     214
    312215   if (info_ptr == NULL)
    313216      return;
    314 
    315    png_debug(1, "in png_info_init_3");
    316217
    317218   if (png_sizeof(png_info) > png_info_struct_size)
     
    326227}
    327228
    328 #ifdef PNG_FREE_ME_SUPPORTED
    329229void PNGAPI
    330230png_data_freer(png_structp png_ptr, png_infop info_ptr,
     
    332232{
    333233   png_debug(1, "in png_data_freer");
     234
    334235   if (png_ptr == NULL || info_ptr == NULL)
    335236      return;
     237
    336238   if (freer == PNG_DESTROY_WILL_FREE_DATA)
    337239      info_ptr->free_me |= mask;
     
    340242   else
    341243      png_warning(png_ptr,
    342          "Unknown freer parameter in png_data_freer.");
    343 }
    344 #endif
     244         "Unknown freer parameter in png_data_freer");
     245}
    345246
    346247void PNGAPI
     
    349250{
    350251   png_debug(1, "in png_free_data");
     252
    351253   if (png_ptr == NULL || info_ptr == NULL)
    352254      return;
    353255
    354 #if defined(PNG_TEXT_SUPPORTED)
     256#ifdef PNG_TEXT_SUPPORTED
    355257   /* Free text item num or (if num == -1) all text items */
    356 #ifdef PNG_FREE_ME_SUPPORTED
    357258   if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
    358 #else
    359    if (mask & PNG_FREE_TEXT)
    360 #endif
    361259   {
    362260      if (num != -1)
     
    380278#endif
    381279
    382 #if defined(PNG_tRNS_SUPPORTED)
     280#ifdef PNG_tRNS_SUPPORTED
    383281   /* Free any tRNS entry */
    384 #ifdef PNG_FREE_ME_SUPPORTED
    385282   if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
    386 #else
    387    if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
    388 #endif
    389    {
    390       png_free(png_ptr, info_ptr->trans);
    391       info_ptr->trans = NULL;
     283   {
     284      png_free(png_ptr, info_ptr->trans_alpha);
     285      info_ptr->trans_alpha = NULL;
    392286      info_ptr->valid &= ~PNG_INFO_tRNS;
    393 #ifndef PNG_FREE_ME_SUPPORTED
    394       png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
    395 #endif
    396    }
    397 #endif
    398 
    399 #if defined(PNG_sCAL_SUPPORTED)
     287   }
     288#endif
     289
     290#ifdef PNG_sCAL_SUPPORTED
    400291   /* Free any sCAL entry */
    401 #ifdef PNG_FREE_ME_SUPPORTED
    402292   if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
    403 #else
    404    if (mask & PNG_FREE_SCAL)
    405 #endif
    406293   {
    407294#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
     
    415302#endif
    416303
    417 #if defined(PNG_pCAL_SUPPORTED)
     304#ifdef PNG_pCAL_SUPPORTED
    418305   /* Free any pCAL entry */
    419 #ifdef PNG_FREE_ME_SUPPORTED
    420306   if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
    421 #else
    422    if (mask & PNG_FREE_PCAL)
    423 #endif
    424307   {
    425308      png_free(png_ptr, info_ptr->pcal_purpose);
     
    433316            {
    434317               png_free(png_ptr, info_ptr->pcal_params[i]);
    435                info_ptr->pcal_params[i]=NULL;
     318               info_ptr->pcal_params[i] = NULL;
    436319            }
    437320            png_free(png_ptr, info_ptr->pcal_params);
     
    442325#endif
    443326
    444 #if defined(PNG_iCCP_SUPPORTED)
     327#ifdef PNG_iCCP_SUPPORTED
    445328   /* Free any iCCP entry */
    446 #ifdef PNG_FREE_ME_SUPPORTED
    447329   if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
    448 #else
    449    if (mask & PNG_FREE_ICCP)
    450 #endif
    451330   {
    452331      png_free(png_ptr, info_ptr->iccp_name);
     
    458337#endif
    459338
    460 #if defined(PNG_sPLT_SUPPORTED)
     339#ifdef PNG_sPLT_SUPPORTED
    461340   /* Free a given sPLT entry, or (if num == -1) all sPLT entries */
    462 #ifdef PNG_FREE_ME_SUPPORTED
    463341   if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
    464 #else
    465    if (mask & PNG_FREE_SPLT)
    466 #endif
    467342   {
    468343      if (num != -1)
     
    493368#endif
    494369
    495 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
     370#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
    496371   if (png_ptr->unknown_chunk.data)
    497372   {
     
    500375   }
    501376
    502 #ifdef PNG_FREE_ME_SUPPORTED
    503377   if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
    504 #else
    505    if (mask & PNG_FREE_UNKN)
    506 #endif
    507378   {
    508379      if (num != -1)
     
    531402#endif
    532403
    533 #if defined(PNG_hIST_SUPPORTED)
     404#ifdef PNG_hIST_SUPPORTED
    534405   /* Free any hIST entry */
    535 #ifdef PNG_FREE_ME_SUPPORTED
    536406   if ((mask & PNG_FREE_HIST)  & info_ptr->free_me)
    537 #else
    538    if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
    539 #endif
    540407   {
    541408      png_free(png_ptr, info_ptr->hist);
    542409      info_ptr->hist = NULL;
    543410      info_ptr->valid &= ~PNG_INFO_hIST;
    544 #ifndef PNG_FREE_ME_SUPPORTED
    545       png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
    546 #endif
    547411   }
    548412#endif
    549413
    550414   /* Free any PLTE entry that was internally allocated */
    551 #ifdef PNG_FREE_ME_SUPPORTED
    552415   if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
    553 #else
    554    if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
    555 #endif
    556416   {
    557417      png_zfree(png_ptr, info_ptr->palette);
    558418      info_ptr->palette = NULL;
    559419      info_ptr->valid &= ~PNG_INFO_PLTE;
    560 #ifndef PNG_FREE_ME_SUPPORTED
    561       png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
    562 #endif
    563420      info_ptr->num_palette = 0;
    564421   }
    565422
    566 #if defined(PNG_INFO_IMAGE_SUPPORTED)
     423#ifdef PNG_INFO_IMAGE_SUPPORTED
    567424   /* Free any image bits attached to the info structure */
    568 #ifdef PNG_FREE_ME_SUPPORTED
    569425   if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
    570 #else
    571    if (mask & PNG_FREE_ROWS)
    572 #endif
    573426   {
    574427      if (info_ptr->row_pointers)
     
    578431         {
    579432            png_free(png_ptr, info_ptr->row_pointers[row]);
    580             info_ptr->row_pointers[row]=NULL;
     433            info_ptr->row_pointers[row] = NULL;
    581434         }
    582435         png_free(png_ptr, info_ptr->row_pointers);
    583          info_ptr->row_pointers=NULL;
     436         info_ptr->row_pointers = NULL;
    584437      }
    585438      info_ptr->valid &= ~PNG_INFO_IDAT;
     
    587440#endif
    588441
    589 #ifdef PNG_FREE_ME_SUPPORTED
    590442   if (num == -1)
    591443      info_ptr->free_me &= ~mask;
    592444   else
    593445      info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
    594 #endif
    595446}
    596447
     
    606457   png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
    607458
    608 #if defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
     459#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
    609460   if (png_ptr->num_chunk_list)
    610461   {
    611462      png_free(png_ptr, png_ptr->chunk_list);
    612       png_ptr->chunk_list=NULL;
     463      png_ptr->chunk_list = NULL;
    613464      png_ptr->num_chunk_list = 0;
    614465   }
     
    632483
    633484#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
    634 #if !defined(PNG_NO_STDIO)
     485#ifdef PNG_STDIO_SUPPORTED
    635486/* Initialize the default input/output functions for the PNG file.  If you
    636487 * use your own read or write routines, you can call either png_set_read_fn()
     
    643494{
    644495   png_debug(1, "in png_init_io");
     496
    645497   if (png_ptr == NULL)
    646498      return;
     499
    647500   png_ptr->io_ptr = (png_voidp)fp;
    648501}
    649502#endif
    650503
    651 #if defined(PNG_TIME_RFC1123_SUPPORTED)
     504#ifdef PNG_TIME_RFC1123_SUPPORTED
    652505/* Convert the supplied time into an RFC 1123 string suitable for use in
    653506 * a "Creation Time" or other text-based time string.
     
    668521   }
    669522
    670 #if defined(_WIN32_WCE)
    671    {
    672       wchar_t time_buf[29];
    673       wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
    674           ptime->day % 32, short_months[(ptime->month - 1) % 12],
    675         ptime->year, ptime->hour % 24, ptime->minute % 60,
    676           ptime->second % 61);
    677       WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
    678           NULL, NULL);
    679    }
    680 #else
    681523#ifdef USE_FAR_KEYWORD
    682524   {
     
    695537       ptime->second % 61);
    696538#endif
    697 #endif /* _WIN32_WCE */
    698539   return ((png_charp)png_ptr->time_buffer);
    699540}
     
    706547{
    707548   png_ptr = png_ptr;  /* Silence compiler warning about unused png_ptr */
    708    return ((png_charp) "\n libpng version 1.2.40 - September 10, 2009\n\
    709    Copyright (c) 1998-2009 Glenn Randers-Pehrson\n\
    710    Copyright (c) 1996-1997 Andreas Dilger\n\
    711    Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
     549#ifdef PNG_STRING_COPYRIGHT
     550      return PNG_STRING_COPYRIGHT
     551#else
     552#ifdef __STDC__
     553   return ((png_charp) PNG_STRING_NEWLINE \
     554     "libpng version 1.4.0 - January 3, 2010" PNG_STRING_NEWLINE \
     555     "Copyright (c) 1998-2010 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
     556     "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
     557     "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
     558     PNG_STRING_NEWLINE);
     559#else
     560      return ((png_charp) "libpng version 1.4.0 - January 3, 2010\
     561      Copyright (c) 1998-2010 Glenn Randers-Pehrson\
     562      Copyright (c) 1996-1997 Andreas Dilger\
     563      Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.");
     564#endif
     565#endif
    712566}
    713567
     
    741595   /* Returns longer string containing both version and date */
    742596   png_ptr = png_ptr;  /* Silence compiler warning about unused png_ptr */
     597#ifdef __STDC__
    743598   return ((png_charp) PNG_HEADER_VERSION_STRING
    744599#ifndef PNG_READ_SUPPORTED
    745600   "     (NO READ SUPPORT)"
    746601#endif
    747    "\n");
     602   PNG_STRING_NEWLINE);
     603#else
     604   return ((png_charp) PNG_HEADER_VERSION_STRING);
     605#endif
    748606}
    749607
     
    785643
    786644
    787 #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
    788 #if !defined(PNG_1_0_X)
    789 /* This function was added to libpng 1.2.0 */
    790 int PNGAPI
    791 png_mmx_support(void)
    792 {
    793    /* Obsolete, to be removed from libpng-1.4.0 */
    794     return -1;
    795 }
    796 #endif /* PNG_1_0_X */
    797 #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
    798645
    799646#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
     
    811658
    812659/* Added at libpng version 1.2.34 and 1.4.0 (moved from pngset.c) */
    813 #if defined(PNG_cHRM_SUPPORTED)
    814 #if !defined(PNG_NO_CHECK_cHRM)
     660#ifdef PNG_cHRM_SUPPORTED
     661#ifdef PNG_CHECK_cHRM_SUPPORTED
    815662
    816663/*
     
    864711
    865712   png_debug(1, "in function png_check_cHRM_fixed");
     713
    866714   if (png_ptr == NULL)
    867715      return 0;
     
    922770   return ret;
    923771}
    924 #endif /* NO_PNG_CHECK_cHRM */
     772#endif /* PNG_CHECK_cHRM_SUPPORTED */
    925773#endif /* PNG_cHRM_SUPPORTED */
     774
     775void /* PRIVATE */
     776png_check_IHDR(png_structp png_ptr,
     777   png_uint_32 width, png_uint_32 height, int bit_depth,
     778   int color_type, int interlace_type, int compression_type,
     779   int filter_type)
     780{
     781   int error = 0;
     782
     783   /* Check for width and height valid values */
     784   if (width == 0)
     785   {
     786      png_warning(png_ptr, "Image width is zero in IHDR");
     787      error = 1;
     788   }
     789
     790   if (height == 0)
     791   {
     792      png_warning(png_ptr, "Image height is zero in IHDR");
     793      error = 1;
     794   }
     795
     796#ifdef PNG_SET_USER_LIMITS_SUPPORTED
     797   if (width > png_ptr->user_width_max || width > PNG_USER_WIDTH_MAX)
     798#else
     799   if (width > PNG_USER_WIDTH_MAX)
     800#endif
     801   {
     802      png_warning(png_ptr, "Image width exceeds user limit in IHDR");
     803      error = 1;
     804   }
     805
     806#ifdef PNG_SET_USER_LIMITS_SUPPORTED
     807   if (height > png_ptr->user_height_max || height > PNG_USER_HEIGHT_MAX)
     808#else
     809   if (height > PNG_USER_HEIGHT_MAX)
     810#endif
     811   {
     812      png_warning(png_ptr, "Image height exceeds user limit in IHDR");
     813      error = 1;
     814   }
     815
     816   if (width > PNG_UINT_31_MAX)
     817   {
     818      png_warning(png_ptr, "Invalid image width in IHDR");
     819      error = 1;
     820   }
     821
     822   if ( height > PNG_UINT_31_MAX)
     823   {
     824      png_warning(png_ptr, "Invalid image height in IHDR");
     825      error = 1;
     826   }
     827
     828   if ( width > (PNG_UINT_32_MAX
     829                 >> 3)      /* 8-byte RGBA pixels */
     830                 - 64       /* bigrowbuf hack */
     831                 - 1        /* filter byte */
     832                 - 7*8      /* rounding of width to multiple of 8 pixels */
     833                 - 8)       /* extra max_pixel_depth pad */
     834      png_warning(png_ptr, "Width is too large for libpng to process pixels");
     835
     836   /* Check other values */
     837   if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
     838       bit_depth != 8 && bit_depth != 16)
     839   {
     840      png_warning(png_ptr, "Invalid bit depth in IHDR");
     841      error = 1;
     842   }
     843
     844   if (color_type < 0 || color_type == 1 ||
     845       color_type == 5 || color_type > 6)
     846   {
     847      png_warning(png_ptr, "Invalid color type in IHDR");
     848      error = 1;
     849   }
     850
     851   if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
     852       ((color_type == PNG_COLOR_TYPE_RGB ||
     853         color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
     854         color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
     855   {
     856      png_warning(png_ptr, "Invalid color type/bit depth combination in IHDR");
     857      error = 1;
     858   }
     859
     860   if (interlace_type >= PNG_INTERLACE_LAST)
     861   {
     862      png_warning(png_ptr, "Unknown interlace method in IHDR");
     863      error = 1;
     864   }
     865
     866   if (compression_type != PNG_COMPRESSION_TYPE_BASE)
     867   {
     868      png_warning(png_ptr, "Unknown compression method in IHDR");
     869      error = 1;
     870   }
     871
     872#ifdef PNG_MNG_FEATURES_SUPPORTED
     873   /* Accept filter_method 64 (intrapixel differencing) only if
     874    * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
     875    * 2. Libpng did not read a PNG signature (this filter_method is only
     876    *    used in PNG datastreams that are embedded in MNG datastreams) and
     877    * 3. The application called png_permit_mng_features with a mask that
     878    *    included PNG_FLAG_MNG_FILTER_64 and
     879    * 4. The filter_method is 64 and
     880    * 5. The color_type is RGB or RGBA
     881    */
     882   if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) &&
     883       png_ptr->mng_features_permitted)
     884      png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
     885
     886   if (filter_type != PNG_FILTER_TYPE_BASE)
     887   {
     888      if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
     889         (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
     890         ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) &&
     891         (color_type == PNG_COLOR_TYPE_RGB ||
     892         color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
     893      {
     894         png_warning(png_ptr, "Unknown filter method in IHDR");
     895         error = 1;
     896      }
     897
     898      if (png_ptr->mode & PNG_HAVE_PNG_SIGNATURE)
     899      {
     900         png_warning(png_ptr, "Invalid filter method in IHDR");
     901         error = 1;
     902      }
     903   }
     904
     905#else
     906   if (filter_type != PNG_FILTER_TYPE_BASE)
     907   {
     908      png_warning(png_ptr, "Unknown filter method in IHDR");
     909      error = 1;
     910   }
     911#endif
     912
     913   if (error == 1)
     914      png_error(png_ptr, "Invalid IHDR data");
     915}
    926916#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
Note: See TracChangeset for help on using the changeset viewer.