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/pngwrite.c

    r561 r846  
    22/* pngwrite.c - general routines to write a PNG file
    33 *
    4  * Last changed in libpng 1.2.37 [June 4, 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.)
     
    1313
    1414/* Get internal access to png.h */
    15 #define PNG_INTERNAL
     15#define PNG_NO_PEDANTIC_WARNINGS
    1616#include "png.h"
    1717#ifdef PNG_WRITE_SUPPORTED
     18#include "pngpriv.h"
    1819
    1920/* Writes all the PNG information.  This is the suggested way to use the
     
    3031{
    3132   png_debug(1, "in png_write_info_before_PLTE");
     33
    3234   if (png_ptr == NULL || info_ptr == NULL)
    3335      return;
    3436   if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
    3537   {
    36    png_write_sig(png_ptr); /* Write PNG signature */
    37 #if defined(PNG_MNG_FEATURES_SUPPORTED)
     38   /* Write PNG signature */
     39   png_write_sig(png_ptr);
     40#ifdef PNG_MNG_FEATURES_SUPPORTED
    3841   if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
    3942   {
    4043      png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
    41       png_ptr->mng_features_permitted=0;
     44      png_ptr->mng_features_permitted = 0;
    4245   }
    4346#endif
     
    4649      info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
    4750      info_ptr->filter_type,
    48 #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
     51#ifdef PNG_WRITE_INTERLACING_SUPPORTED
    4952      info_ptr->interlace_type);
    5053#else
     
    5457    * flag set, and if it does, writes the chunk.
    5558    */
    56 #if defined(PNG_WRITE_gAMA_SUPPORTED)
     59#ifdef PNG_WRITE_gAMA_SUPPORTED
    5760   if (info_ptr->valid & PNG_INFO_gAMA)
    5861   {
     
    6669   }
    6770#endif
    68 #if defined(PNG_WRITE_sRGB_SUPPORTED)
     71#ifdef PNG_WRITE_sRGB_SUPPORTED
    6972   if (info_ptr->valid & PNG_INFO_sRGB)
    7073      png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
    7174#endif
    72 #if defined(PNG_WRITE_iCCP_SUPPORTED)
     75#ifdef PNG_WRITE_iCCP_SUPPORTED
    7376   if (info_ptr->valid & PNG_INFO_iCCP)
    7477      png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
    7578                     info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
    7679#endif
    77 #if defined(PNG_WRITE_sBIT_SUPPORTED)
     80#ifdef PNG_WRITE_sBIT_SUPPORTED
    7881   if (info_ptr->valid & PNG_INFO_sBIT)
    7982      png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
    8083#endif
    81 #if defined(PNG_WRITE_cHRM_SUPPORTED)
     84#ifdef PNG_WRITE_cHRM_SUPPORTED
    8285   if (info_ptr->valid & PNG_INFO_cHRM)
    8386   {
     
    99102   }
    100103#endif
    101 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
     104#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
    102105   if (info_ptr->unknown_chunks_num)
    103106   {
     
    110113           up++)
    111114      {
    112          int keep=png_handle_as_unknown(png_ptr, up->name);
     115         int keep = png_handle_as_unknown(png_ptr, up->name);
    113116         if (keep != PNG_HANDLE_CHUNK_NEVER &&
    114117            up->location && !(up->location & PNG_HAVE_PLTE) &&
     
    148151      png_error(png_ptr, "Valid palette required for paletted images");
    149152
    150 #if defined(PNG_WRITE_tRNS_SUPPORTED)
     153#ifdef PNG_WRITE_tRNS_SUPPORTED
    151154   if (info_ptr->valid & PNG_INFO_tRNS)
    152155   {
    153 #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
     156#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
    154157      /* Invert the alpha channel (in tRNS) */
    155158      if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
     
    157160      {
    158161         int j;
    159          for (j=0; j<(int)info_ptr->num_trans; j++)
    160             info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
    161       }
    162 #endif
    163       png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
     162         for (j = 0; j<(int)info_ptr->num_trans; j++)
     163            info_ptr->trans_alpha[j] = (png_byte)(255 - info_ptr->trans_alpha[j]);
     164      }
     165#endif
     166      png_write_tRNS(png_ptr, info_ptr->trans_alpha, &(info_ptr->trans_color),
    164167         info_ptr->num_trans, info_ptr->color_type);
    165168   }
    166169#endif
    167 #if defined(PNG_WRITE_bKGD_SUPPORTED)
     170#ifdef PNG_WRITE_bKGD_SUPPORTED
    168171   if (info_ptr->valid & PNG_INFO_bKGD)
    169172      png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
    170173#endif
    171 #if defined(PNG_WRITE_hIST_SUPPORTED)
     174#ifdef PNG_WRITE_hIST_SUPPORTED
    172175   if (info_ptr->valid & PNG_INFO_hIST)
    173176      png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
    174177#endif
    175 #if defined(PNG_WRITE_oFFs_SUPPORTED)
     178#ifdef PNG_WRITE_oFFs_SUPPORTED
    176179   if (info_ptr->valid & PNG_INFO_oFFs)
    177180      png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
    178181         info_ptr->offset_unit_type);
    179182#endif
    180 #if defined(PNG_WRITE_pCAL_SUPPORTED)
     183#ifdef PNG_WRITE_pCAL_SUPPORTED
    181184   if (info_ptr->valid & PNG_INFO_pCAL)
    182185      png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
     
    185188#endif
    186189
    187 #if defined(PNG_sCAL_SUPPORTED)
     190#ifdef PNG_sCAL_SUPPORTED
    188191   if (info_ptr->valid & PNG_INFO_sCAL)
    189 #if defined(PNG_WRITE_sCAL_SUPPORTED)
    190 #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
     192#ifdef PNG_WRITE_sCAL_SUPPORTED
     193#if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_STDIO_SUPPORTED)
    191194      png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
    192195          info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
     
    199202#else  /* !WRITE_sCAL */
    200203      png_warning(png_ptr,
    201           "png_write_sCAL not supported; sCAL chunk not written.");
     204          "png_write_sCAL not supported; sCAL chunk not written");
    202205#endif /* WRITE_sCAL */
    203206#endif /* sCAL */
    204207
    205 #if defined(PNG_WRITE_pHYs_SUPPORTED)
     208#ifdef PNG_WRITE_pHYs_SUPPORTED
    206209   if (info_ptr->valid & PNG_INFO_pHYs)
    207210      png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
     
    209212#endif /* pHYs */
    210213
    211 #if defined(PNG_WRITE_tIME_SUPPORTED)
     214#ifdef PNG_WRITE_tIME_SUPPORTED
    212215   if (info_ptr->valid & PNG_INFO_tIME)
    213216   {
     
    217220#endif /* tIME */
    218221
    219 #if defined(PNG_WRITE_sPLT_SUPPORTED)
     222#ifdef PNG_WRITE_sPLT_SUPPORTED
    220223   if (info_ptr->valid & PNG_INFO_sPLT)
    221224     for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
     
    223226#endif /* sPLT */
    224227
    225 #if defined(PNG_WRITE_TEXT_SUPPORTED)
     228#ifdef PNG_WRITE_TEXT_SUPPORTED
    226229   /* Check to see if we need to write text chunks */
    227230   for (i = 0; i < info_ptr->num_text; i++)
     
    232235      if (info_ptr->text[i].compression > 0)
    233236      {
    234 #if defined(PNG_WRITE_iTXt_SUPPORTED)
     237#ifdef PNG_WRITE_iTXt_SUPPORTED
    235238          /* Write international chunk */
    236239          png_write_iTXt(png_ptr,
     
    249252      else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
    250253      {
    251 #if defined(PNG_WRITE_zTXt_SUPPORTED)
     254#ifdef PNG_WRITE_zTXt_SUPPORTED
    252255         /* Write compressed chunk */
    253256         png_write_zTXt(png_ptr, info_ptr->text[i].key,
     
    262265      else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
    263266      {
    264 #if defined(PNG_WRITE_tEXt_SUPPORTED)
     267#ifdef PNG_WRITE_tEXt_SUPPORTED
    265268         /* Write uncompressed chunk */
    266269         png_write_tEXt(png_ptr, info_ptr->text[i].key,
     
    277280#endif /* tEXt */
    278281
    279 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
     282#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
    280283   if (info_ptr->unknown_chunks_num)
    281284   {
    282        png_unknown_chunk *up;
    283 
    284        png_debug(5, "writing extra chunks");
    285 
    286        for (up = info_ptr->unknown_chunks;
    287             up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
    288             up++)
    289        {
    290          int keep=png_handle_as_unknown(png_ptr, up->name);
     285      png_unknown_chunk *up;
     286
     287      png_debug(5, "writing extra chunks");
     288
     289      for (up = info_ptr->unknown_chunks;
     290           up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
     291           up++)
     292      {
     293         int keep = png_handle_as_unknown(png_ptr, up->name);
    291294         if (keep != PNG_HANDLE_CHUNK_NEVER &&
    292295            up->location && (up->location & PNG_HAVE_PLTE) &&
     
    297300            png_write_chunk(png_ptr, up->name, up->data, up->size);
    298301         }
    299        }
     302      }
    300303   }
    301304#endif
     
    311314{
    312315   png_debug(1, "in png_write_end");
     316
    313317   if (png_ptr == NULL)
    314318      return;
     
    319323   if (info_ptr != NULL)
    320324   {
    321 #if defined(PNG_WRITE_TEXT_SUPPORTED)
    322       int i; /* Local index variable */
    323 #endif
    324 #if defined(PNG_WRITE_tIME_SUPPORTED)
     325#ifdef PNG_WRITE_TEXT_SUPPORTED
     326      int i; /* local index variable */
     327#endif
     328#ifdef PNG_WRITE_tIME_SUPPORTED
    325329      /* Check to see if user has supplied a time chunk */
    326330      if ((info_ptr->valid & PNG_INFO_tIME) &&
     
    328332         png_write_tIME(png_ptr, &(info_ptr->mod_time));
    329333#endif
    330 #if defined(PNG_WRITE_TEXT_SUPPORTED)
     334#ifdef PNG_WRITE_TEXT_SUPPORTED
    331335      /* Loop through comment chunks */
    332336      for (i = 0; i < info_ptr->num_text; i++)
     
    337341         if (info_ptr->text[i].compression > 0)
    338342         {
    339 #if defined(PNG_WRITE_iTXt_SUPPORTED)
    340              /* Write international chunk */
    341              png_write_iTXt(png_ptr,
    342                          info_ptr->text[i].compression,
    343                          info_ptr->text[i].key,
    344                          info_ptr->text[i].lang,
    345                          info_ptr->text[i].lang_key,
    346                          info_ptr->text[i].text);
    347 #else
    348              png_warning(png_ptr, "Unable to write international text");
    349 #endif
    350              /* Mark this chunk as written */
    351              info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
     343#ifdef PNG_WRITE_iTXt_SUPPORTED
     344            /* Write international chunk */
     345            png_write_iTXt(png_ptr,
     346                        info_ptr->text[i].compression,
     347                        info_ptr->text[i].key,
     348                        info_ptr->text[i].lang,
     349                        info_ptr->text[i].lang_key,
     350                        info_ptr->text[i].text);
     351#else
     352            png_warning(png_ptr, "Unable to write international text");
     353#endif
     354            /* Mark this chunk as written */
     355            info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
    352356         }
    353357         else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
    354358         {
    355 #if defined(PNG_WRITE_zTXt_SUPPORTED)
     359#ifdef PNG_WRITE_zTXt_SUPPORTED
    356360            /* Write compressed chunk */
    357361            png_write_zTXt(png_ptr, info_ptr->text[i].key,
     
    366370         else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
    367371         {
    368 #if defined(PNG_WRITE_tEXt_SUPPORTED)
     372#ifdef PNG_WRITE_tEXt_SUPPORTED
    369373            /* Write uncompressed chunk */
    370374            png_write_tEXt(png_ptr, info_ptr->text[i].key,
     
    379383      }
    380384#endif
    381 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
     385#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
    382386   if (info_ptr->unknown_chunks_num)
    383387   {
    384        png_unknown_chunk *up;
    385 
    386        png_debug(5, "writing extra chunks");
    387 
    388        for (up = info_ptr->unknown_chunks;
    389             up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
    390             up++)
    391        {
    392          int keep=png_handle_as_unknown(png_ptr, up->name);
     388      png_unknown_chunk *up;
     389
     390      png_debug(5, "writing extra chunks");
     391
     392      for (up = info_ptr->unknown_chunks;
     393           up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
     394           up++)
     395      {
     396         int keep = png_handle_as_unknown(png_ptr, up->name);
    393397         if (keep != PNG_HANDLE_CHUNK_NEVER &&
    394398            up->location && (up->location & PNG_AFTER_IDAT) &&
     
    398402            png_write_chunk(png_ptr, up->name, up->data, up->size);
    399403         }
    400        }
     404      }
    401405   }
    402406#endif
     
    412416    * experiences a problem, please try building libpng with
    413417    * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to
    414     * png-mng-implement at lists.sf.net .  This kludge will be removed
    415     * from libpng-1.4.0.
     418    * png-mng-implement at lists.sf.net .
    416419    */
    417 #if defined(PNG_WRITE_FLUSH_SUPPORTED) && \
    418     defined(PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED)
     420#ifdef PNG_WRITE_FLUSH_SUPPORTED
     421#  ifdef PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED
    419422   png_flush(png_ptr);
    420 #endif
    421 }
    422 
    423 #if defined(PNG_WRITE_tIME_SUPPORTED)
    424 #if !defined(_WIN32_WCE)
    425 /* "time.h" functions are not supported on WindowsCE */
     423#  endif
     424#endif
     425}
     426
     427#ifdef PNG_CONVERT_tIME_SUPPORTED
     428/* "tm" structure is not supported on WindowsCE */
    426429void PNGAPI
    427430png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
    428431{
    429432   png_debug(1, "in png_convert_from_struct_tm");
     433
    430434   ptime->year = (png_uint_16)(1900 + ttime->tm_year);
    431435   ptime->month = (png_byte)(ttime->tm_mon + 1);
     
    442446
    443447   png_debug(1, "in png_convert_from_time_t");
     448
    444449   tbuf = gmtime(&ttime);
    445450   png_convert_from_struct_tm(ptime, tbuf);
    446451}
    447 #endif
    448452#endif
    449453
     
    455459#ifdef PNG_USER_MEM_SUPPORTED
    456460   return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
    457       warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
     461      warn_fn, NULL, NULL, NULL));
    458462}
    459463
     
    465469{
    466470#endif /* PNG_USER_MEM_SUPPORTED */
     471   volatile int png_cleanup_needed = 0;
    467472#ifdef PNG_SETJMP_SUPPORTED
    468     volatile
    469 #endif
    470     png_structp png_ptr;
     473   volatile
     474#endif
     475   png_structp png_ptr;
    471476#ifdef PNG_SETJMP_SUPPORTED
    472477#ifdef USE_FAR_KEYWORD
     
    475480#endif
    476481   int i;
     482
    477483   png_debug(1, "in png_create_write_struct");
     484
    478485#ifdef PNG_USER_MEM_SUPPORTED
    479486   png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
     
    487494   /* Added at libpng-1.2.6 */
    488495#ifdef PNG_SET_USER_LIMITS_SUPPORTED
    489    png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
    490    png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
     496   png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
     497   png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
    491498#endif
    492499
    493500#ifdef PNG_SETJMP_SUPPORTED
     501/* Applications that neglect to set up their own setjmp() and then
     502   encounter a png_error() will longjmp here.  Since the jmpbuf is
     503   then meaningless we abort instead of returning. */
    494504#ifdef USE_FAR_KEYWORD
    495505   if (setjmp(jmpbuf))
    496506#else
    497    if (setjmp(png_ptr->jmpbuf))
    498 #endif
    499    {
    500       png_free(png_ptr, png_ptr->zbuf);
    501        png_ptr->zbuf=NULL;
    502       png_destroy_struct(png_ptr);
    503       return (NULL);
    504    }
     507   if (setjmp(png_jmpbuf(png_ptr))) /* sets longjmp to match setjmp */
     508#endif
    505509#ifdef USE_FAR_KEYWORD
    506    png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
    507 #endif
     510   png_memcpy(png_jmpbuf(png_ptr), jmpbuf, png_sizeof(jmp_buf));
     511#endif
     512      PNG_ABORT();
    508513#endif
    509514
     
    515520   if (user_png_ver)
    516521   {
    517      i=0;
    518      do
    519      {
    520        if (user_png_ver[i] != png_libpng_ver[i])
    521           png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
    522      } while (png_libpng_ver[i++]);
     522      i = 0;
     523      do
     524      {
     525         if (user_png_ver[i] != png_libpng_ver[i])
     526            png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
     527      } while (png_libpng_ver[i++]);
    523528   }
    524529
     
    534539         (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
    535540     {
    536 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
     541#ifdef PNG_STDIO_SUPPORTED
    537542        char msg[80];
    538543        if (user_png_ver)
    539544        {
    540           png_snprintf(msg, 80,
    541              "Application was compiled with png.h from libpng-%.20s",
    542              user_png_ver);
    543           png_warning(png_ptr, msg);
     545           png_snprintf(msg, 80,
     546              "Application was compiled with png.h from libpng-%.20s",
     547              user_png_ver);
     548           png_warning(png_ptr, msg);
    544549        }
    545550        png_snprintf(msg, 80,
     
    549554#endif
    550555#ifdef PNG_ERROR_NUMBERS_SUPPORTED
    551         png_ptr->flags=0;
    552 #endif
    553         png_error(png_ptr,
     556        png_ptr->flags = 0;
     557#endif
     558        png_warning(png_ptr,
    554559           "Incompatible libpng version in application and library");
     560        png_cleanup_needed = 1;
    555561     }
    556562   }
     
    558564   /* Initialize zbuf - compression buffer */
    559565   png_ptr->zbuf_size = PNG_ZBUF_SIZE;
    560    png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
    561       (png_uint_32)png_ptr->zbuf_size);
    562 
    563    png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
    564       png_flush_ptr_NULL);
    565 
    566 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
     566   if (!png_cleanup_needed)
     567   {
     568      png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr,
     569         png_ptr->zbuf_size);
     570      if (png_ptr->zbuf == NULL)
     571         png_cleanup_needed = 1;
     572   }
     573   if (png_cleanup_needed)
     574   {
     575       /* Clean up PNG structure and deallocate any memory. */
     576       png_free(png_ptr, png_ptr->zbuf);
     577       png_ptr->zbuf = NULL;
     578#ifdef PNG_USER_MEM_SUPPORTED
     579       png_destroy_struct_2((png_voidp)png_ptr,
     580          (png_free_ptr)free_fn, (png_voidp)mem_ptr);
     581#else
     582       png_destroy_struct((png_voidp)png_ptr);
     583#endif
     584       return (NULL);
     585   }
     586
     587   png_set_write_fn(png_ptr, NULL, NULL, NULL);
     588
     589#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    567590   png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
    568       1, png_doublep_NULL, png_doublep_NULL);
    569 #endif
    570 
    571 #ifdef PNG_SETJMP_SUPPORTED
    572 /* Applications that neglect to set up their own setjmp() and then encounter
    573    a png_error() will longjmp here.  Since the jmpbuf is then meaningless we
    574    abort instead of returning. */
    575 #ifdef USE_FAR_KEYWORD
    576    if (setjmp(jmpbuf))
    577       PNG_ABORT();
    578    png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
    579 #else
    580    if (setjmp(png_ptr->jmpbuf))
    581       PNG_ABORT();
    582 #endif
    583 #endif
     591      1, NULL, NULL);
     592#endif
     593
    584594   return (png_ptr);
    585595}
    586596
    587 /* Initialize png_ptr structure, and allocate any memory needed */
    588 #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
    589 /* Deprecated. */
    590 #undef png_write_init
    591 void PNGAPI
    592 png_write_init(png_structp png_ptr)
    593 {
    594    /* We only come here via pre-1.0.7-compiled applications */
    595    png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
    596 }
    597 
    598 void PNGAPI
    599 png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
    600    png_size_t png_struct_size, png_size_t png_info_size)
    601 {
    602    /* We only come here via pre-1.0.12-compiled applications */
    603    if (png_ptr == NULL) return;
    604 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
    605    if (png_sizeof(png_struct) > png_struct_size ||
    606       png_sizeof(png_info) > png_info_size)
    607    {
    608       char msg[80];
    609       png_ptr->warning_fn=NULL;
    610       if (user_png_ver)
    611       {
    612         png_snprintf(msg, 80,
    613            "Application was compiled with png.h from libpng-%.20s",
    614            user_png_ver);
    615         png_warning(png_ptr, msg);
    616       }
    617       png_snprintf(msg, 80,
    618          "Application  is  running with png.c from libpng-%.20s",
    619          png_libpng_ver);
    620       png_warning(png_ptr, msg);
    621    }
    622 #endif
    623    if (png_sizeof(png_struct) > png_struct_size)
    624      {
    625        png_ptr->error_fn=NULL;
    626 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
    627        png_ptr->flags=0;
    628 #endif
    629        png_error(png_ptr,
    630        "The png struct allocated by the application for writing is too small.");
    631      }
    632    if (png_sizeof(png_info) > png_info_size)
    633      {
    634        png_ptr->error_fn=NULL;
    635 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
    636        png_ptr->flags=0;
    637 #endif
    638        png_error(png_ptr,
    639        "The info struct allocated by the application for writing is too small.");
    640      }
    641    png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
    642 }
    643 #endif /* PNG_1_0_X || PNG_1_2_X */
    644 
    645 
    646 void PNGAPI
    647 png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
    648    png_size_t png_struct_size)
    649 {
    650    png_structp png_ptr=*ptr_ptr;
    651 #ifdef PNG_SETJMP_SUPPORTED
    652    jmp_buf tmp_jmp; /* To save current jump buffer */
    653 #endif
    654 
    655    int i = 0;
    656 
    657    if (png_ptr == NULL)
    658       return;
    659 
    660    do
    661    {
    662      if (user_png_ver[i] != png_libpng_ver[i])
    663      {
    664 #ifdef PNG_LEGACY_SUPPORTED
    665        png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
    666 #else
    667        png_ptr->warning_fn=NULL;
    668        png_warning(png_ptr,
    669  "Application uses deprecated png_write_init() and should be recompiled.");
    670        break;
    671 #endif
    672      }
    673    } while (png_libpng_ver[i++]);
    674 
    675    png_debug(1, "in png_write_init_3");
    676 
    677 #ifdef PNG_SETJMP_SUPPORTED
    678    /* Save jump buffer and error functions */
    679    png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
    680 #endif
    681 
    682    if (png_sizeof(png_struct) > png_struct_size)
    683      {
    684        png_destroy_struct(png_ptr);
    685        png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
    686        *ptr_ptr = png_ptr;
    687      }
    688 
    689    /* Reset all variables to 0 */
    690    png_memset(png_ptr, 0, png_sizeof(png_struct));
    691 
    692    /* Added at libpng-1.2.6 */
    693 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
    694    png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
    695    png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
    696 #endif
    697 
    698 #ifdef PNG_SETJMP_SUPPORTED
    699    /* Restore jump buffer */
    700    png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
    701 #endif
    702 
    703    png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
    704       png_flush_ptr_NULL);
    705 
    706    /* Initialize zbuf - compression buffer */
    707    png_ptr->zbuf_size = PNG_ZBUF_SIZE;
    708    png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
    709       (png_uint_32)png_ptr->zbuf_size);
    710 
    711 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
    712    png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
    713       1, png_doublep_NULL, png_doublep_NULL);
    714 #endif
    715 }
    716597
    717598/* Write a few rows of image data.  If the image is interlaced,
     
    724605   png_uint_32 num_rows)
    725606{
    726    png_uint_32 i; /* Row counter */
    727    png_bytepp rp; /* Row pointer */
     607   png_uint_32 i; /* row counter */
     608   png_bytepp rp; /* row pointer */
    728609
    729610   png_debug(1, "in png_write_rows");
     
    745626png_write_image(png_structp png_ptr, png_bytepp image)
    746627{
    747    png_uint_32 i; /* Row index */
    748    int pass, num_pass; /* Pass variables */
    749    png_bytepp rp; /* Points to current row */
     628   png_uint_32 i; /* row index */
     629   int pass, num_pass; /* pass variables */
     630   png_bytepp rp; /* points to current row */
    750631
    751632   if (png_ptr == NULL)
     
    753634
    754635   png_debug(1, "in png_write_image");
    755 #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
     636
     637#ifdef PNG_WRITE_INTERLACING_SUPPORTED
    756638   /* Initialize interlace handling.  If image is not interlaced,
    757639    * this will set pass to 1
     
    778660   if (png_ptr == NULL)
    779661      return;
     662
    780663   png_debug2(1, "in png_write_row (row %ld, pass %d)",
    781664      png_ptr->row_number, png_ptr->pass);
     
    787670      if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
    788671         png_error(png_ptr,
    789             "png_write_info was never called before png_write_row.");
     672            "png_write_info was never called before png_write_row");
    790673
    791674      /* Check for transforms that have been set but were defined out */
    792675#if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
    793676      if (png_ptr->transformations & PNG_INVERT_MONO)
    794          png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
     677         png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined");
    795678#endif
    796679#if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
    797680      if (png_ptr->transformations & PNG_FILLER)
    798          png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
     681         png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined");
    799682#endif
    800683#if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
    801684      if (png_ptr->transformations & PNG_PACKSWAP)
    802          png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
     685         png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined");
    803686#endif
    804687#if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
    805688      if (png_ptr->transformations & PNG_PACK)
    806          png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
     689         png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined");
    807690#endif
    808691#if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
    809692      if (png_ptr->transformations & PNG_SHIFT)
    810          png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
     693         png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined");
    811694#endif
    812695#if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
    813696      if (png_ptr->transformations & PNG_BGR)
    814          png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
     697         png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined");
    815698#endif
    816699#if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
    817700      if (png_ptr->transformations & PNG_SWAP_BYTES)
    818          png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
     701         png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined");
    819702#endif
    820703
     
    822705   }
    823706
    824 #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
     707#ifdef PNG_WRITE_INTERLACING_SUPPORTED
    825708   /* If interlaced and not interested in row, return */
    826709   if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
     
    900783
    901784   /* Copy user's row into buffer, leaving room for filter byte. */
    902    png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
    903       png_ptr->row_info.rowbytes);
    904 
    905 #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
     785   png_memcpy(png_ptr->row_buf + 1, row, png_ptr->row_info.rowbytes);
     786
     787#ifdef PNG_WRITE_INTERLACING_SUPPORTED
    906788   /* Handle interlacing */
    907789   if (png_ptr->interlaced && png_ptr->pass < 6 &&
     
    923805      png_do_write_transformations(png_ptr);
    924806
    925 #if defined(PNG_MNG_FEATURES_SUPPORTED)
     807#ifdef PNG_MNG_FEATURES_SUPPORTED
    926808   /* Write filter_method 64 (intrapixel differencing) only if
    927809    * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
     
    948830}
    949831
    950 #if defined(PNG_WRITE_FLUSH_SUPPORTED)
     832#ifdef PNG_WRITE_FLUSH_SUPPORTED
    951833/* Set the automatic flush interval or 0 to turn flushing off */
    952834void PNGAPI
     
    954836{
    955837   png_debug(1, "in png_set_flush");
     838
    956839   if (png_ptr == NULL)
    957840      return;
     
    966849
    967850   png_debug(1, "in png_write_flush");
     851
    968852   if (png_ptr == NULL)
    969853      return;
     
    1026910
    1027911   png_debug(1, "in png_destroy_write_struct");
     912
    1028913   if (png_ptr_ptr != NULL)
    1029914   {
     
    1052937        png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
    1053938
    1054 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
     939#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
    1055940        if (png_ptr->num_chunk_list)
    1056941        {
    1057942           png_free(png_ptr, png_ptr->chunk_list);
    1058            png_ptr->chunk_list=NULL;
    1059943           png_ptr->num_chunk_list = 0;
    1060944        }
     
    1100984
    1101985   png_debug(1, "in png_write_destroy");
     986
    1102987   /* Free any memory zlib uses */
    1103988   deflateEnd(&png_ptr->zstream);
     
    1106991   png_free(png_ptr, png_ptr->zbuf);
    1107992   png_free(png_ptr, png_ptr->row_buf);
    1108 #ifndef PNG_NO_WRITE_FILTER
     993#ifdef PNG_WRITE_FILTER_SUPPORTED
    1109994   png_free(png_ptr, png_ptr->prev_row);
    1110995   png_free(png_ptr, png_ptr->sub_row);
     
    1114999#endif
    11151000
    1116 #if defined(PNG_TIME_RFC1123_SUPPORTED)
     1001#ifdef PNG_TIME_RFC1123_SUPPORTED
    11171002   png_free(png_ptr, png_ptr->time_buffer);
    11181003#endif
    11191004
    1120 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
     1005#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    11211006   png_free(png_ptr, png_ptr->prev_filters);
    11221007   png_free(png_ptr, png_ptr->filter_weights);
     
    11571042{
    11581043   png_debug(1, "in png_set_filter");
    1159    if (png_ptr == NULL)
    1160       return;
    1161 #if defined(PNG_MNG_FEATURES_SUPPORTED)
     1044
     1045   if (png_ptr == NULL)
     1046      return;
     1047#ifdef PNG_MNG_FEATURES_SUPPORTED
    11621048   if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
    11631049      (method == PNG_INTRAPIXEL_DIFFERENCING))
     
    11681054      switch (filters & (PNG_ALL_FILTERS | 0x07))
    11691055      {
    1170 #ifndef PNG_NO_WRITE_FILTER
     1056#ifdef PNG_WRITE_FILTER_SUPPORTED
    11711057         case 5:
    11721058         case 6:
    11731059         case 7: png_warning(png_ptr, "Unknown row filter for method 0");
    1174 #endif /* PNG_NO_WRITE_FILTER */
     1060#endif /* PNG_WRITE_FILTER_SUPPORTED */
    11751061         case PNG_FILTER_VALUE_NONE:
    1176               png_ptr->do_filter=PNG_FILTER_NONE; break;
    1177 #ifndef PNG_NO_WRITE_FILTER
     1062              png_ptr->do_filter = PNG_FILTER_NONE; break;
     1063#ifdef PNG_WRITE_FILTER_SUPPORTED
    11781064         case PNG_FILTER_VALUE_SUB:
    1179               png_ptr->do_filter=PNG_FILTER_SUB; break;
     1065              png_ptr->do_filter = PNG_FILTER_SUB; break;
    11801066         case PNG_FILTER_VALUE_UP:
    1181               png_ptr->do_filter=PNG_FILTER_UP; break;
     1067              png_ptr->do_filter = PNG_FILTER_UP; break;
    11821068         case PNG_FILTER_VALUE_AVG:
    1183               png_ptr->do_filter=PNG_FILTER_AVG; break;
     1069              png_ptr->do_filter = PNG_FILTER_AVG; break;
    11841070         case PNG_FILTER_VALUE_PAETH:
    1185               png_ptr->do_filter=PNG_FILTER_PAETH; break;
     1071              png_ptr->do_filter = PNG_FILTER_PAETH; break;
    11861072         default: png_ptr->do_filter = (png_byte)filters; break;
    11871073#else
    11881074         default: png_warning(png_ptr, "Unknown row filter for method 0");
    1189 #endif /* PNG_NO_WRITE_FILTER */
     1075#endif /* PNG_WRITE_FILTER_SUPPORTED */
    11901076      }
    11911077
     
    12011087      if (png_ptr->row_buf != NULL)
    12021088      {
    1203 #ifndef PNG_NO_WRITE_FILTER
     1089#ifdef PNG_WRITE_FILTER_SUPPORTED
    12041090         if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
    12051091         {
     
    12561142
    12571143         if (png_ptr->do_filter == PNG_NO_FILTERS)
    1258 #endif /* PNG_NO_WRITE_FILTER */
     1144#endif /* PNG_WRITE_FILTER_SUPPORTED */
    12591145            png_ptr->do_filter = PNG_FILTER_NONE;
    12601146      }
     
    12711157 * better compression.
    12721158 */
    1273 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)      /* GRR 970116 */
     1159#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED      /* GRR 970116 */
    12741160void PNGAPI
    12751161png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
     
    12801166
    12811167   png_debug(1, "in png_set_filter_heuristics");
     1168
    12821169   if (png_ptr == NULL)
    12831170      return;
     
    13941281{
    13951282   png_debug(1, "in png_set_compression_level");
     1283
    13961284   if (png_ptr == NULL)
    13971285      return;
     
    14041292{
    14051293   png_debug(1, "in png_set_compression_mem_level");
     1294
    14061295   if (png_ptr == NULL)
    14071296      return;
     
    14141303{
    14151304   png_debug(1, "in png_set_compression_strategy");
     1305
    14161306   if (png_ptr == NULL)
    14171307      return;
     
    14341324     {
    14351325       png_warning(png_ptr, "Compression window is being reset to 512");
    1436        window_bits=9;
     1326       window_bits = 9;
    14371327     }
    14381328#endif
     
    14451335{
    14461336   png_debug(1, "in png_set_compression_method");
     1337
    14471338   if (png_ptr == NULL)
    14481339      return;
     
    14611352}
    14621353
    1463 #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
     1354#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
    14641355void PNGAPI
    14651356png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
     
    14671358{
    14681359   png_debug(1, "in png_set_write_user_transform_fn");
     1360
    14691361   if (png_ptr == NULL)
    14701362      return;
     
    14751367
    14761368
    1477 #if defined(PNG_INFO_IMAGE_SUPPORTED)
     1369#ifdef PNG_INFO_IMAGE_SUPPORTED
    14781370void PNGAPI
    14791371png_write_png(png_structp png_ptr, png_infop info_ptr,
     
    14821374   if (png_ptr == NULL || info_ptr == NULL)
    14831375      return;
    1484 #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
    1485    /* Invert the alpha channel from opacity to transparency */
    1486    if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
    1487       png_set_invert_alpha(png_ptr);
    1488 #endif
    14891376
    14901377   /* Write the file header information. */
     
    14931380   /* ------ these transformations don't touch the info structure ------- */
    14941381
    1495 #if defined(PNG_WRITE_INVERT_SUPPORTED)
     1382#ifdef PNG_WRITE_INVERT_SUPPORTED
    14961383   /* Invert monochrome pixels */
    14971384   if (transforms & PNG_TRANSFORM_INVERT_MONO)
     
    14991386#endif
    15001387
    1501 #if defined(PNG_WRITE_SHIFT_SUPPORTED)
     1388#ifdef PNG_WRITE_SHIFT_SUPPORTED
    15021389   /* Shift the pixels up to a legal bit depth and fill in
    15031390    * as appropriate to correctly scale the image.
     
    15081395#endif
    15091396
    1510 #if defined(PNG_WRITE_PACK_SUPPORTED)
     1397#ifdef PNG_WRITE_PACK_SUPPORTED
    15111398   /* Pack pixels into bytes */
    15121399   if (transforms & PNG_TRANSFORM_PACKING)
     
    15141401#endif
    15151402
    1516 #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
     1403#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
    15171404   /* Swap location of alpha bytes from ARGB to RGBA */
    15181405   if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
     
    15201407#endif
    15211408
    1522 #if defined(PNG_WRITE_FILLER_SUPPORTED)
     1409#ifdef PNG_WRITE_FILLER_SUPPORTED
    15231410   /* Pack XRGB/RGBX/ARGB/RGBA into * RGB (4 channels -> 3 channels) */
    15241411   if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER)
     
    15281415#endif
    15291416
    1530 #if defined(PNG_WRITE_BGR_SUPPORTED)
     1417#ifdef PNG_WRITE_BGR_SUPPORTED
    15311418   /* Flip BGR pixels to RGB */
    15321419   if (transforms & PNG_TRANSFORM_BGR)
     
    15341421#endif
    15351422
    1536 #if defined(PNG_WRITE_SWAP_SUPPORTED)
     1423#ifdef PNG_WRITE_SWAP_SUPPORTED
    15371424   /* Swap bytes of 16-bit files to most significant byte first */
    15381425   if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
     
    15401427#endif
    15411428
    1542 #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
     1429#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
    15431430   /* Swap bits of 1, 2, 4 bit packed pixel formats */
    15441431   if (transforms & PNG_TRANSFORM_PACKSWAP)
     
    15461433#endif
    15471434
     1435#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
     1436   /* Invert the alpha channel from opacity to transparency */
     1437   if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
     1438      png_set_invert_alpha(png_ptr);
     1439#endif
     1440
    15481441   /* ----------------------- end of transformations ------------------- */
    15491442
Note: See TracChangeset for help on using the changeset viewer.