Show
Ignore:
Timestamp:
02/15/10 11:37:15 (2 years ago)
Author:
Carsten
Message:

Upgraded vendor/libpng from 1.2.40 to 1.2.42.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vendor/libpng/pngwrite.c

    r11 r43  
    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.2.42 [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.) 
     
    1414/* Get internal access to png.h */ 
    1515#define PNG_INTERNAL 
     16#define PNG_NO_PEDANTIC_WARNINGS 
    1617#include "png.h" 
    1718#ifdef PNG_WRITE_SUPPORTED 
     
    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++) 
     162         for (j = 0; j<(int)info_ptr->num_trans; j++) 
    160163            info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]); 
    161164      } 
     
    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); 
     
    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 
     
    466470#endif /* PNG_USER_MEM_SUPPORTED */ 
    467471#ifdef PNG_SETJMP_SUPPORTED 
    468     volatile 
    469 #endif 
    470     png_structp png_ptr; 
     472   volatile 
     473#endif 
     474   png_structp png_ptr; 
    471475#ifdef PNG_SETJMP_SUPPORTED 
    472476#ifdef USE_FAR_KEYWORD 
     
    475479#endif 
    476480   int i; 
     481 
    477482   png_debug(1, "in png_create_write_struct"); 
     483 
    478484#ifdef PNG_USER_MEM_SUPPORTED 
    479485   png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, 
     
    487493   /* Added at libpng-1.2.6 */ 
    488494#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; 
     495   png_ptr->user_width_max = PNG_USER_WIDTH_MAX; 
     496   png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; 
    491497#endif 
    492498 
     
    499505   { 
    500506      png_free(png_ptr, png_ptr->zbuf); 
    501        png_ptr->zbuf=NULL; 
    502       png_destroy_struct(png_ptr); 
     507      png_ptr->zbuf = NULL; 
     508#ifdef PNG_USER_MEM_SUPPORTED 
     509      png_destroy_struct_2((png_voidp)png_ptr, 
     510         (png_free_ptr)free_fn, (png_voidp)mem_ptr); 
     511#else 
     512      png_destroy_struct((png_voidp)png_ptr); 
     513#endif 
    503514      return (NULL); 
    504515   } 
     
    515526   if (user_png_ver) 
    516527   { 
    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++]); 
     528      i = 0; 
     529      do 
     530      { 
     531         if (user_png_ver[i] != png_libpng_ver[i]) 
     532            png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; 
     533      } while (png_libpng_ver[i++]); 
    523534   } 
    524535 
     
    534545         (user_png_ver[0] == '0' && user_png_ver[2] < '9')) 
    535546     { 
    536 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) 
     547#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) 
    537548        char msg[80]; 
    538549        if (user_png_ver) 
    539550        { 
    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); 
     551           png_snprintf(msg, 80, 
     552              "Application was compiled with png.h from libpng-%.20s", 
     553              user_png_ver); 
     554           png_warning(png_ptr, msg); 
    544555        } 
    545556        png_snprintf(msg, 80, 
     
    549560#endif 
    550561#ifdef PNG_ERROR_NUMBERS_SUPPORTED 
    551         png_ptr->flags=0; 
     562        png_ptr->flags = 0; 
    552563#endif 
    553564        png_error(png_ptr, 
     
    559570   png_ptr->zbuf_size = PNG_ZBUF_SIZE; 
    560571   png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, 
    561       (png_uint_32)png_ptr->zbuf_size); 
     572     (png_uint_32)png_ptr->zbuf_size); 
    562573 
    563574   png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, 
    564575      png_flush_ptr_NULL); 
    565576 
    566 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 
     577#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 
    567578   png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, 
    568579      1, png_doublep_NULL, png_doublep_NULL); 
     
    570581 
    571582#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. */ 
     583   /* Applications that neglect to set up their own setjmp() and then 
     584    * encounter a png_error() will longjmp here.  Since the jmpbuf is 
     585    * then meaningless we abort instead of returning. 
     586    */ 
    575587#ifdef USE_FAR_KEYWORD 
    576588   if (setjmp(jmpbuf)) 
     
    602614   /* We only come here via pre-1.0.12-compiled applications */ 
    603615   if (png_ptr == NULL) return; 
    604 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) 
     616#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) 
    605617   if (png_sizeof(png_struct) > png_struct_size || 
    606618      png_sizeof(png_info) > png_info_size) 
    607619   { 
    608620      char msg[80]; 
    609       png_ptr->warning_fn=NULL; 
     621      png_ptr->warning_fn = NULL; 
    610622      if (user_png_ver) 
    611623      { 
    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); 
     624         png_snprintf(msg, 80, 
     625            "Application was compiled with png.h from libpng-%.20s", 
     626            user_png_ver); 
     627         png_warning(png_ptr, msg); 
    616628      } 
    617629      png_snprintf(msg, 80, 
     
    622634#endif 
    623635   if (png_sizeof(png_struct) > png_struct_size) 
    624      { 
    625        png_ptr->error_fn=NULL; 
     636   { 
     637      png_ptr->error_fn = NULL; 
    626638#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      } 
     639      png_ptr->flags = 0; 
     640#endif 
     641      png_error(png_ptr, 
     642      "The png struct allocated by the application for writing is too small."); 
     643   } 
    632644   if (png_sizeof(png_info) > png_info_size) 
    633      { 
    634        png_ptr->error_fn=NULL; 
     645   { 
     646      png_ptr->error_fn = NULL; 
    635647#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      } 
     648      png_ptr->flags = 0; 
     649#endif 
     650      png_error(png_ptr, 
     651      "The info struct allocated by the application for writing is too small."); 
     652   } 
    641653   png_write_init_3(&png_ptr, user_png_ver, png_struct_size); 
    642654} 
     
    648660   png_size_t png_struct_size) 
    649661{ 
    650    png_structp png_ptr=*ptr_ptr; 
     662   png_structp png_ptr = *ptr_ptr; 
    651663#ifdef PNG_SETJMP_SUPPORTED 
    652    jmp_buf tmp_jmp; /* To save current jump buffer */ 
     664   jmp_buf tmp_jmp; /* to save current jump buffer */ 
    653665#endif 
    654666 
     
    660672   do 
    661673   { 
    662      if (user_png_ver[i] != png_libpng_ver[i]) 
    663      { 
     674      if (user_png_ver[i] != png_libpng_ver[i]) 
     675      { 
    664676#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, 
     677         png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; 
     678#else 
     679         png_ptr->warning_fn = NULL; 
     680         png_warning(png_ptr, 
    669681 "Application uses deprecated png_write_init() and should be recompiled."); 
    670        break; 
    671 #endif 
    672      } 
     682#endif 
     683      } 
    673684   } while (png_libpng_ver[i++]); 
    674685 
     
    681692 
    682693   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      } 
     694   { 
     695      png_destroy_struct(png_ptr); 
     696      png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); 
     697      *ptr_ptr = png_ptr; 
     698   } 
    688699 
    689700   /* Reset all variables to 0 */ 
     
    692703   /* Added at libpng-1.2.6 */ 
    693704#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; 
     705   png_ptr->user_width_max = PNG_USER_WIDTH_MAX; 
     706   png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; 
    696707#endif 
    697708 
     
    707718   png_ptr->zbuf_size = PNG_ZBUF_SIZE; 
    708719   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) 
     720     (png_uint_32)png_ptr->zbuf_size); 
     721#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 
    712722   png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, 
    713723      1, png_doublep_NULL, png_doublep_NULL); 
     
    724734   png_uint_32 num_rows) 
    725735{ 
    726    png_uint_32 i; /* Row counter */ 
    727    png_bytepp rp; /* Row pointer */ 
     736   png_uint_32 i; /* row counter */ 
     737   png_bytepp rp; /* row pointer */ 
    728738 
    729739   png_debug(1, "in png_write_rows"); 
     
    745755png_write_image(png_structp png_ptr, png_bytepp image) 
    746756{ 
    747    png_uint_32 i; /* Row index */ 
    748    int pass, num_pass; /* Pass variables */ 
    749    png_bytepp rp; /* Points to current row */ 
     757   png_uint_32 i; /* row index */ 
     758   int pass, num_pass; /* pass variables */ 
     759   png_bytepp rp; /* points to current row */ 
    750760 
    751761   if (png_ptr == NULL) 
     
    753763 
    754764   png_debug(1, "in png_write_image"); 
    755 #if defined(PNG_WRITE_INTERLACING_SUPPORTED) 
     765 
     766#ifdef PNG_WRITE_INTERLACING_SUPPORTED 
    756767   /* Initialize interlace handling.  If image is not interlaced, 
    757768    * this will set pass to 1 
     
    778789   if (png_ptr == NULL) 
    779790      return; 
     791 
    780792   png_debug2(1, "in png_write_row (row %ld, pass %d)", 
    781793      png_ptr->row_number, png_ptr->pass); 
     
    822834   } 
    823835 
    824 #if defined(PNG_WRITE_INTERLACING_SUPPORTED) 
     836#ifdef PNG_WRITE_INTERLACING_SUPPORTED 
    825837   /* If interlaced and not interested in row, return */ 
    826838   if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) 
     
    903915      png_ptr->row_info.rowbytes); 
    904916 
    905 #if defined(PNG_WRITE_INTERLACING_SUPPORTED) 
     917#ifdef PNG_WRITE_INTERLACING_SUPPORTED 
    906918   /* Handle interlacing */ 
    907919   if (png_ptr->interlaced && png_ptr->pass < 6 && 
     
    923935      png_do_write_transformations(png_ptr); 
    924936 
    925 #if defined(PNG_MNG_FEATURES_SUPPORTED) 
     937#ifdef PNG_MNG_FEATURES_SUPPORTED 
    926938   /* Write filter_method 64 (intrapixel differencing) only if 
    927939    * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and 
     
    948960} 
    949961 
    950 #if defined(PNG_WRITE_FLUSH_SUPPORTED) 
     962#ifdef PNG_WRITE_FLUSH_SUPPORTED 
    951963/* Set the automatic flush interval or 0 to turn flushing off */ 
    952964void PNGAPI 
     
    954966{ 
    955967   png_debug(1, "in png_set_flush"); 
     968 
    956969   if (png_ptr == NULL) 
    957970      return; 
     
    966979 
    967980   png_debug(1, "in png_write_flush"); 
     981 
    968982   if (png_ptr == NULL) 
    969983      return; 
     
    10261040 
    10271041   png_debug(1, "in png_destroy_write_struct"); 
     1042 
    10281043   if (png_ptr_ptr != NULL) 
    10291044   { 
     
    10521067        png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); 
    10531068 
    1054 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) 
     1069#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED 
    10551070        if (png_ptr->num_chunk_list) 
    10561071        { 
    10571072           png_free(png_ptr, png_ptr->chunk_list); 
    1058            png_ptr->chunk_list=NULL; 
     1073           png_ptr->chunk_list = NULL; 
    10591074           png_ptr->num_chunk_list = 0; 
    10601075        } 
     
    11001115 
    11011116   png_debug(1, "in png_write_destroy"); 
     1117 
    11021118   /* Free any memory zlib uses */ 
    11031119   deflateEnd(&png_ptr->zstream); 
     
    11061122   png_free(png_ptr, png_ptr->zbuf); 
    11071123   png_free(png_ptr, png_ptr->row_buf); 
    1108 #ifndef PNG_NO_WRITE_FILTER 
     1124#ifdef PNG_WRITE_FILTER_SUPPORTED 
    11091125   png_free(png_ptr, png_ptr->prev_row); 
    11101126   png_free(png_ptr, png_ptr->sub_row); 
     
    11141130#endif 
    11151131 
    1116 #if defined(PNG_TIME_RFC1123_SUPPORTED) 
     1132#ifdef PNG_TIME_RFC1123_SUPPORTED 
    11171133   png_free(png_ptr, png_ptr->time_buffer); 
    11181134#endif 
    11191135 
    1120 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 
     1136#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 
    11211137   png_free(png_ptr, png_ptr->prev_filters); 
    11221138   png_free(png_ptr, png_ptr->filter_weights); 
     
    11571173{ 
    11581174   png_debug(1, "in png_set_filter"); 
    1159    if (png_ptr == NULL) 
    1160       return; 
    1161 #if defined(PNG_MNG_FEATURES_SUPPORTED) 
     1175 
     1176   if (png_ptr == NULL) 
     1177      return; 
     1178#ifdef PNG_MNG_FEATURES_SUPPORTED 
    11621179   if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && 
    11631180      (method == PNG_INTRAPIXEL_DIFFERENCING)) 
     
    11681185      switch (filters & (PNG_ALL_FILTERS | 0x07)) 
    11691186      { 
    1170 #ifndef PNG_NO_WRITE_FILTER 
     1187#ifdef PNG_WRITE_FILTER_SUPPORTED 
    11711188         case 5: 
    11721189         case 6: 
    11731190         case 7: png_warning(png_ptr, "Unknown row filter for method 0"); 
    1174 #endif /* PNG_NO_WRITE_FILTER */ 
     1191#endif /* PNG_WRITE_FILTER_SUPPORTED */ 
    11751192         case PNG_FILTER_VALUE_NONE: 
    1176               png_ptr->do_filter=PNG_FILTER_NONE; break; 
    1177 #ifndef PNG_NO_WRITE_FILTER 
     1193              png_ptr->do_filter = PNG_FILTER_NONE; break; 
     1194#ifdef PNG_WRITE_FILTER_SUPPORTED 
    11781195         case PNG_FILTER_VALUE_SUB: 
    1179               png_ptr->do_filter=PNG_FILTER_SUB; break; 
     1196              png_ptr->do_filter = PNG_FILTER_SUB; break; 
    11801197         case PNG_FILTER_VALUE_UP: 
    1181               png_ptr->do_filter=PNG_FILTER_UP; break; 
     1198              png_ptr->do_filter = PNG_FILTER_UP; break; 
    11821199         case PNG_FILTER_VALUE_AVG: 
    1183               png_ptr->do_filter=PNG_FILTER_AVG; break; 
     1200              png_ptr->do_filter = PNG_FILTER_AVG; break; 
    11841201         case PNG_FILTER_VALUE_PAETH: 
    1185               png_ptr->do_filter=PNG_FILTER_PAETH; break; 
     1202              png_ptr->do_filter = PNG_FILTER_PAETH; break; 
    11861203         default: png_ptr->do_filter = (png_byte)filters; break; 
    11871204#else 
    11881205         default: png_warning(png_ptr, "Unknown row filter for method 0"); 
    1189 #endif /* PNG_NO_WRITE_FILTER */ 
     1206#endif /* PNG_WRITE_FILTER_SUPPORTED */ 
    11901207      } 
    11911208 
     
    12011218      if (png_ptr->row_buf != NULL) 
    12021219      { 
    1203 #ifndef PNG_NO_WRITE_FILTER 
     1220#ifdef PNG_WRITE_FILTER_SUPPORTED 
    12041221         if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL) 
    12051222         { 
     
    12561273 
    12571274         if (png_ptr->do_filter == PNG_NO_FILTERS) 
    1258 #endif /* PNG_NO_WRITE_FILTER */ 
     1275#endif /* PNG_WRITE_FILTER_SUPPORTED */ 
    12591276            png_ptr->do_filter = PNG_FILTER_NONE; 
    12601277      } 
     
    12711288 * better compression. 
    12721289 */ 
    1273 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)      /* GRR 970116 */ 
     1290#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED      /* GRR 970116 */ 
    12741291void PNGAPI 
    12751292png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, 
     
    12801297 
    12811298   png_debug(1, "in png_set_filter_heuristics"); 
     1299 
    12821300   if (png_ptr == NULL) 
    12831301      return; 
     
    13941412{ 
    13951413   png_debug(1, "in png_set_compression_level"); 
     1414 
    13961415   if (png_ptr == NULL) 
    13971416      return; 
     
    14041423{ 
    14051424   png_debug(1, "in png_set_compression_mem_level"); 
     1425 
    14061426   if (png_ptr == NULL) 
    14071427      return; 
     
    14141434{ 
    14151435   png_debug(1, "in png_set_compression_strategy"); 
     1436 
    14161437   if (png_ptr == NULL) 
    14171438      return; 
     
    14341455     { 
    14351456       png_warning(png_ptr, "Compression window is being reset to 512"); 
    1436        window_bits=9; 
     1457       window_bits = 9; 
    14371458     } 
    14381459#endif 
     
    14451466{ 
    14461467   png_debug(1, "in png_set_compression_method"); 
     1468 
    14471469   if (png_ptr == NULL) 
    14481470      return; 
     
    14611483} 
    14621484 
    1463 #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) 
     1485#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED 
    14641486void PNGAPI 
    14651487png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr 
     
    14671489{ 
    14681490   png_debug(1, "in png_set_write_user_transform_fn"); 
     1491 
    14691492   if (png_ptr == NULL) 
    14701493      return; 
     
    14751498 
    14761499 
    1477 #if defined(PNG_INFO_IMAGE_SUPPORTED) 
     1500#ifdef PNG_INFO_IMAGE_SUPPORTED 
    14781501void PNGAPI 
    14791502png_write_png(png_structp png_ptr, png_infop info_ptr, 
     
    14821505   if (png_ptr == NULL || info_ptr == NULL) 
    14831506      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 
    14891507 
    14901508   /* Write the file header information. */ 
     
    14931511   /* ------ these transformations don't touch the info structure ------- */ 
    14941512 
    1495 #if defined(PNG_WRITE_INVERT_SUPPORTED) 
     1513#ifdef PNG_WRITE_INVERT_SUPPORTED 
    14961514   /* Invert monochrome pixels */ 
    14971515   if (transforms & PNG_TRANSFORM_INVERT_MONO) 
     
    14991517#endif 
    15001518 
    1501 #if defined(PNG_WRITE_SHIFT_SUPPORTED) 
     1519#ifdef PNG_WRITE_SHIFT_SUPPORTED 
    15021520   /* Shift the pixels up to a legal bit depth and fill in 
    15031521    * as appropriate to correctly scale the image. 
     
    15081526#endif 
    15091527 
    1510 #if defined(PNG_WRITE_PACK_SUPPORTED) 
     1528#ifdef PNG_WRITE_PACK_SUPPORTED 
    15111529   /* Pack pixels into bytes */ 
    15121530   if (transforms & PNG_TRANSFORM_PACKING) 
     
    15141532#endif 
    15151533 
    1516 #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) 
     1534#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED 
    15171535   /* Swap location of alpha bytes from ARGB to RGBA */ 
    15181536   if (transforms & PNG_TRANSFORM_SWAP_ALPHA) 
     
    15201538#endif 
    15211539 
    1522 #if defined(PNG_WRITE_FILLER_SUPPORTED) 
     1540#ifdef PNG_WRITE_FILLER_SUPPORTED 
    15231541   /* Pack XRGB/RGBX/ARGB/RGBA into * RGB (4 channels -> 3 channels) */ 
    15241542   if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER) 
     
    15281546#endif 
    15291547 
    1530 #if defined(PNG_WRITE_BGR_SUPPORTED) 
     1548#ifdef PNG_WRITE_BGR_SUPPORTED 
    15311549   /* Flip BGR pixels to RGB */ 
    15321550   if (transforms & PNG_TRANSFORM_BGR) 
     
    15341552#endif 
    15351553 
    1536 #if defined(PNG_WRITE_SWAP_SUPPORTED) 
     1554#ifdef PNG_WRITE_SWAP_SUPPORTED 
    15371555   /* Swap bytes of 16-bit files to most significant byte first */ 
    15381556   if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) 
     
    15401558#endif 
    15411559 
    1542 #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) 
     1560#ifdef PNG_WRITE_PACKSWAP_SUPPORTED 
    15431561   /* Swap bits of 1, 2, 4 bit packed pixel formats */ 
    15441562   if (transforms & PNG_TRANSFORM_PACKSWAP) 
     
    15461564#endif 
    15471565 
     1566#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED 
     1567   /* Invert the alpha channel from opacity to transparency */ 
     1568   if (transforms & PNG_TRANSFORM_INVERT_ALPHA) 
     1569      png_set_invert_alpha(png_ptr); 
     1570#endif 
     1571 
    15481572   /* ----------------------- end of transformations ------------------- */ 
    15491573