Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

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

    r2 r561  
    22/* pngwutil.c - utilities to write a PNG file
    33 *
    4  * Last changed in libpng 1.2.27 [April 29, 2008]
    5  * For conditions of distribution and use, see copyright notice in png.h
    6  * Copyright (c) 1998-2008 Glenn Randers-Pehrson
     4 * Last changed in libpng 1.2.40 [September 10, 2009]
     5 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
    76 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    87 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     8 *
     9 * This code is released under the libpng license.
     10 * For conditions of distribution and use, see the disclaimer
     11 * and license in png.h
    912 */
    1013
     
    4851   buf[0] = (png_byte)((i >> 8) & 0xff);
    4952   buf[1] = (png_byte)(i & 0xff);
     53}
     54
     55/* Simple function to write the signature.  If we have already written
     56 * the magic bytes of the signature, or more likely, the PNG stream is
     57 * being embedded into another stream and doesn't need its own signature,
     58 * we should call png_set_sig_bytes() to tell libpng how many of the
     59 * bytes have already been written.
     60 */
     61void /* PRIVATE */
     62png_write_sig(png_structp png_ptr)
     63{
     64   png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
     65
     66   /* Write the rest of the 8 byte signature */
     67   png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
     68      (png_size_t)(8 - png_ptr->sig_bytes));
     69   if (png_ptr->sig_bytes < 3)
     70      png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
    5071}
    5172
     
    6384   png_bytep data, png_size_t length)
    6485{
    65    if(png_ptr == NULL) return;
     86   if (png_ptr == NULL)
     87      return;
    6688   png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
    67    png_write_chunk_data(png_ptr, data, length);
     89   png_write_chunk_data(png_ptr, data, (png_size_t)length);
    6890   png_write_chunk_end(png_ptr);
    6991}
     
    7799   png_uint_32 length)
    78100{
    79    png_byte buf[4];
    80    png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
    81    if(png_ptr == NULL) return;
    82 
    83    /* write the length */
     101   png_byte buf[8];
     102
     103   png_debug2(0, "Writing %s chunk, length = %lu", chunk_name,
     104      (unsigned long)length);
     105
     106   if (png_ptr == NULL)
     107      return;
     108
     109   /* Write the length and the chunk name */
    84110   png_save_uint_32(buf, length);
    85    png_write_data(png_ptr, buf, (png_size_t)4);
    86 
    87    /* write the chunk name */
    88    png_write_data(png_ptr, chunk_name, (png_size_t)4);
    89    /* reset the crc and run it over the chunk name */
     111   png_memcpy(buf + 4, chunk_name, 4);
     112   png_write_data(png_ptr, buf, (png_size_t)8);
     113   /* Put the chunk name into png_ptr->chunk_name */
     114   png_memcpy(png_ptr->chunk_name, chunk_name, 4);
     115   /* Reset the crc and run it over the chunk name */
    90116   png_reset_crc(png_ptr);
    91117   png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
     
    100126png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
    101127{
    102    /* write the data, and run the CRC over it */
    103    if(png_ptr == NULL) return;
     128   /* Write the data, and run the CRC over it */
     129   if (png_ptr == NULL)
     130      return;
    104131   if (data != NULL && length > 0)
    105132   {
     133      png_write_data(png_ptr, data, length);
     134      /* Update the CRC after writing the data,
     135       * in case that the user I/O routine alters it.
     136       */
    106137      png_calculate_crc(png_ptr, data, length);
    107       png_write_data(png_ptr, data, length);
    108138   }
    109139}
     
    115145   png_byte buf[4];
    116146
    117    if(png_ptr == NULL) return;
    118 
    119    /* write the crc */
     147   if (png_ptr == NULL) return;
     148
     149   /* Write the crc in a single operation */
    120150   png_save_uint_32(buf, png_ptr->crc);
    121151
     
    123153}
    124154
    125 /* Simple function to write the signature.  If we have already written
    126  * the magic bytes of the signature, or more likely, the PNG stream is
    127  * being embedded into another stream and doesn't need its own signature,
    128  * we should call png_set_sig_bytes() to tell libpng how many of the
    129  * bytes have already been written.
    130  */
    131 void /* PRIVATE */
    132 png_write_sig(png_structp png_ptr)
    133 {
    134    png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
    135    /* write the rest of the 8 byte signature */
    136    png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
    137       (png_size_t)8 - png_ptr->sig_bytes);
    138    if(png_ptr->sig_bytes < 3)
    139       png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
    140 }
    141 
    142155#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
    143 /*
    144  * This pair of functions encapsulates the operation of (a) compressing a
     156/* This pair of functions encapsulates the operation of (a) compressing a
    145157 * text string, and (b) issuing it later as a series of chunk data writes.
    146158 * The compression_state structure is shared context for these functions
     
    150162typedef struct
    151163{
    152     char *input;   /* the uncompressed input data */
    153     int input_len;   /* its length */
    154     int num_output_ptr; /* number of output pointers used */
    155     int max_output_ptr; /* size of output_ptr */
    156     png_charpp output_ptr; /* array of pointers to output */
     164   char *input;   /* The uncompressed input data */
     165   int input_len;   /* Its length */
     166   int num_output_ptr; /* Number of output pointers used */
     167   int max_output_ptr; /* Size of output_ptr */
     168   png_charpp output_ptr; /* Array of pointers to output */
    157169} compression_state;
    158170
    159 /* compress given text into storage in the png_ptr structure */
     171/* Compress given text into storage in the png_ptr structure */
    160172static int /* PRIVATE */
    161173png_text_compress(png_structp png_ptr,
     
    171183   comp->input_len = 0;
    172184
    173    /* we may just want to pass the text right through */
     185   /* We may just want to pass the text right through */
    174186   if (compression == PNG_TEXT_COMPRESSION_NONE)
    175187   {
     
    205217    */
    206218
    207    /* set up the compression buffers */
     219   /* Set up the compression buffers */
    208220   png_ptr->zstream.avail_in = (uInt)text_len;
    209221   png_ptr->zstream.next_in = (Bytef *)text;
     
    211223   png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
    212224
    213    /* this is the same compression loop as in png_write_row() */
     225   /* This is the same compression loop as in png_write_row() */
    214226   do
    215227   {
    216       /* compress the data */
     228      /* Compress the data */
    217229      ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
    218230      if (ret != Z_OK)
    219231      {
    220          /* error */
     232         /* Error */
    221233         if (png_ptr->zstream.msg != NULL)
    222234            png_error(png_ptr, png_ptr->zstream.msg);
     
    224236            png_error(png_ptr, "zlib error");
    225237      }
    226       /* check to see if we need more room */
     238      /* Check to see if we need more room */
    227239      if (!(png_ptr->zstream.avail_out))
    228240      {
    229          /* make sure the output array has room */
     241         /* Make sure the output array has room */
    230242         if (comp->num_output_ptr >= comp->max_output_ptr)
    231243         {
     
    240252               old_ptr = comp->output_ptr;
    241253               comp->output_ptr = (png_charpp)png_malloc(png_ptr,
    242                   (png_uint_32)(comp->max_output_ptr *
    243                   png_sizeof (png_charpp)));
     254                  (png_uint_32)
     255                  (comp->max_output_ptr * png_sizeof(png_charpp)));
    244256               png_memcpy(comp->output_ptr, old_ptr, old_max
    245                   * png_sizeof (png_charp));
     257                  * png_sizeof(png_charp));
    246258               png_free(png_ptr, old_ptr);
    247259            }
    248260            else
    249261               comp->output_ptr = (png_charpp)png_malloc(png_ptr,
    250                   (png_uint_32)(comp->max_output_ptr *
    251                   png_sizeof (png_charp)));
     262                  (png_uint_32)
     263                  (comp->max_output_ptr * png_sizeof(png_charp)));
    252264         }
    253265
    254          /* save the data */
    255          comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
     266         /* Save the data */
     267         comp->output_ptr[comp->num_output_ptr] =
     268            (png_charp)png_malloc(png_ptr,
    256269            (png_uint_32)png_ptr->zbuf_size);
    257270         png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
     
    263276         png_ptr->zstream.next_out = png_ptr->zbuf;
    264277      }
    265    /* continue until we don't have any more to compress */
     278   /* Continue until we don't have any more to compress */
    266279   } while (png_ptr->zstream.avail_in);
    267280
    268    /* finish the compression */
     281   /* Finish the compression */
    269282   do
    270283   {
    271       /* tell zlib we are finished */
     284      /* Tell zlib we are finished */
    272285      ret = deflate(&png_ptr->zstream, Z_FINISH);
    273286
    274287      if (ret == Z_OK)
    275288      {
    276          /* check to see if we need more room */
     289         /* Check to see if we need more room */
    277290         if (!(png_ptr->zstream.avail_out))
    278291         {
    279             /* check to make sure our output array has room */
     292            /* Check to make sure our output array has room */
    280293            if (comp->num_output_ptr >= comp->max_output_ptr)
    281294            {
     
    292305                  comp->output_ptr = (png_charpp)png_malloc(png_ptr,
    293306                     (png_uint_32)(comp->max_output_ptr *
    294                      png_sizeof (png_charpp)));
     307                     png_sizeof(png_charp)));
    295308                  png_memcpy(comp->output_ptr, old_ptr,
    296                      old_max * png_sizeof (png_charp));
     309                     old_max * png_sizeof(png_charp));
    297310                  png_free(png_ptr, old_ptr);
    298311               }
     
    300313                  comp->output_ptr = (png_charpp)png_malloc(png_ptr,
    301314                     (png_uint_32)(comp->max_output_ptr *
    302                      png_sizeof (png_charp)));
     315                     png_sizeof(png_charp)));
    303316            }
    304317
    305             /* save off the data */
     318            /* Save the data */
    306319            comp->output_ptr[comp->num_output_ptr] =
    307                (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
     320               (png_charp)png_malloc(png_ptr,
     321               (png_uint_32)png_ptr->zbuf_size);
    308322            png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
    309323               png_ptr->zbuf_size);
     
    317331      else if (ret != Z_STREAM_END)
    318332      {
    319          /* we got an error */
     333         /* We got an error */
    320334         if (png_ptr->zstream.msg != NULL)
    321335            png_error(png_ptr, png_ptr->zstream.msg);
     
    325339   } while (ret != Z_STREAM_END);
    326340
    327    /* text length is number of buffers plus last buffer */
     341   /* Text length is number of buffers plus last buffer */
    328342   text_len = png_ptr->zbuf_size * comp->num_output_ptr;
    329343   if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
     
    333347}
    334348
    335 /* ship the compressed text out via chunk writes */
     349/* Ship the compressed text out via chunk writes */
    336350static void /* PRIVATE */
    337351png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
     
    339353   int i;
    340354
    341    /* handle the no-compression case */
     355   /* Handle the no-compression case */
    342356   if (comp->input)
    343357   {
    344        png_write_chunk_data(png_ptr, (png_bytep)comp->input,
     358      png_write_chunk_data(png_ptr, (png_bytep)comp->input,
    345359                            (png_size_t)comp->input_len);
    346        return;
    347    }
    348 
    349    /* write saved output buffers, if any */
     360      return;
     361   }
     362
     363   /* Write saved output buffers, if any */
    350364   for (i = 0; i < comp->num_output_ptr; i++)
    351365   {
    352       png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
    353          png_ptr->zbuf_size);
     366      png_write_chunk_data(png_ptr, (png_bytep)comp->output_ptr[i],
     367         (png_size_t)png_ptr->zbuf_size);
    354368      png_free(png_ptr, comp->output_ptr[i]);
    355       comp->output_ptr[i]=NULL;
     369       comp->output_ptr[i]=NULL;
    356370   }
    357371   if (comp->max_output_ptr != 0)
    358372      png_free(png_ptr, comp->output_ptr);
    359       comp->output_ptr=NULL;
    360    /* write anything left in zbuf */
     373       comp->output_ptr=NULL;
     374   /* Write anything left in zbuf */
    361375   if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
    362376      png_write_chunk_data(png_ptr, png_ptr->zbuf,
    363          png_ptr->zbuf_size - png_ptr->zstream.avail_out);
    364 
    365    /* reset zlib for another zTXt/iTXt or image data */
     377         (png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out));
     378
     379   /* Reset zlib for another zTXt/iTXt or image data */
    366380   deflateReset(&png_ptr->zstream);
    367381   png_ptr->zstream.data_type = Z_BINARY;
     
    383397   int ret;
    384398
    385    png_byte buf[13]; /* buffer to store the IHDR info */
    386 
    387    png_debug(1, "in png_write_IHDR\n");
     399   png_byte buf[13]; /* Buffer to store the IHDR info */
     400
     401   png_debug(1, "in png_write_IHDR");
     402
    388403   /* Check that we have valid input data from the application info */
    389404   switch (color_type)
     
    397412            case 8:
    398413            case 16: png_ptr->channels = 1; break;
    399             default: png_error(png_ptr,"Invalid bit depth for grayscale image");
     414            default: png_error(png_ptr, "Invalid bit depth for grayscale image");
    400415         }
    401416         break;
     
    469484#endif
    470485
    471    /* save off the relevent information */
     486   /* Save the relevent information */
    472487   png_ptr->bit_depth = (png_byte)bit_depth;
    473488   png_ptr->color_type = (png_byte)color_type;
     
    482497   png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
    483498   png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
    484    /* set the usr info, so any transformations can modify it */
     499   /* Set the usr info, so any transformations can modify it */
    485500   png_ptr->usr_width = png_ptr->width;
    486501   png_ptr->usr_bit_depth = png_ptr->bit_depth;
    487502   png_ptr->usr_channels = png_ptr->channels;
    488503
    489    /* pack the header information into the buffer */
     504   /* Pack the header information into the buffer */
    490505   png_save_uint_32(buf, width);
    491506   png_save_uint_32(buf + 4, height);
     
    496511   buf[12] = (png_byte)interlace_type;
    497512
    498    /* write the chunk */
    499    png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
    500 
    501    /* initialize zlib with PNG info */
     513   /* Write the chunk */
     514   png_write_chunk(png_ptr, (png_bytep)png_IHDR, buf, (png_size_t)13);
     515
     516   /* Initialize zlib with PNG info */
    502517   png_ptr->zstream.zalloc = png_zalloc;
    503518   png_ptr->zstream.zfree = png_zfree;
     
    542557   png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
    543558   /* libpng is not interested in zstream.data_type */
    544    /* set it to a predefined value, to avoid its evaluation inside zlib */
     559   /* Set it to a predefined value, to avoid its evaluation inside zlib */
    545560   png_ptr->zstream.data_type = Z_BINARY;
    546561
     
    548563}
    549564
    550 /* write the palette.  We are careful not to trust png_color to be in the
     565/* Write the palette.  We are careful not to trust png_color to be in the
    551566 * correct order for PNG, so people can redefine it to any convenient
    552567 * structure.
     
    562577   png_byte buf[3];
    563578
    564    png_debug(1, "in png_write_PLTE\n");
     579   png_debug(1, "in png_write_PLTE");
     580
    565581   if ((
    566582#if defined(PNG_MNG_FEATURES_SUPPORTED)
     
    588604
    589605   png_ptr->num_palette = (png_uint_16)num_pal;
    590    png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
    591 
    592    png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
     606   png_debug1(3, "num_palette = %d", png_ptr->num_palette);
     607
     608   png_write_chunk_start(png_ptr, (png_bytep)png_PLTE,
     609     (png_uint_32)(num_pal * 3));
    593610#ifndef PNG_NO_POINTER_INDEXING
    594611   for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
     
    614631}
    615632
    616 /* write an IDAT chunk */
     633/* Write an IDAT chunk */
    617634void /* PRIVATE */
    618635png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
     
    621638   PNG_IDAT;
    622639#endif
    623    png_debug(1, "in png_write_IDAT\n");
     640
     641   png_debug(1, "in png_write_IDAT");
    624642
    625643   /* Optimize the CMF field in the zlib stream. */
     
    631649      if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
    632650      {
    633          /* Avoid memory underflows and multiplication overflows. */
    634          /* The conditions below are practically always satisfied;
    635             however, they still must be checked. */
     651         /* Avoid memory underflows and multiplication overflows.
     652          *
     653          * The conditions below are practically always satisfied;
     654          * however, they still must be checked.
     655          */
    636656         if (length >= 2 &&
    637657             png_ptr->height < 16384 && png_ptr->width < 16384)
     
    662682   }
    663683
    664    png_write_chunk(png_ptr, png_IDAT, data, length);
     684   png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length);
    665685   png_ptr->mode |= PNG_HAVE_IDAT;
    666686}
    667687
    668 /* write an IEND chunk */
     688/* Write an IEND chunk */
    669689void /* PRIVATE */
    670690png_write_IEND(png_structp png_ptr)
     
    673693   PNG_IEND;
    674694#endif
    675    png_debug(1, "in png_write_IEND\n");
    676    png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
     695
     696   png_debug(1, "in png_write_IEND");
     697
     698   png_write_chunk(png_ptr, (png_bytep)png_IEND, png_bytep_NULL,
    677699     (png_size_t)0);
    678700   png_ptr->mode |= PNG_HAVE_IEND;
     
    680702
    681703#if defined(PNG_WRITE_gAMA_SUPPORTED)
    682 /* write a gAMA chunk */
     704/* Write a gAMA chunk */
    683705#ifdef PNG_FLOATING_POINT_SUPPORTED
    684706void /* PRIVATE */
     
    691713   png_byte buf[4];
    692714
    693    png_debug(1, "in png_write_gAMA\n");
     715   png_debug(1, "in png_write_gAMA");
     716
    694717   /* file_gamma is saved in 1/100,000ths */
    695718   igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
    696719   png_save_uint_32(buf, igamma);
    697    png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
     720   png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4);
    698721}
    699722#endif
     
    707730   png_byte buf[4];
    708731
    709    png_debug(1, "in png_write_gAMA\n");
     732   png_debug(1, "in png_write_gAMA");
     733
    710734   /* file_gamma is saved in 1/100,000ths */
    711735   png_save_uint_32(buf, (png_uint_32)file_gamma);
    712    png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
     736   png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4);
    713737}
    714738#endif
     
    716740
    717741#if defined(PNG_WRITE_sRGB_SUPPORTED)
    718 /* write a sRGB chunk */
     742/* Write a sRGB chunk */
    719743void /* PRIVATE */
    720744png_write_sRGB(png_structp png_ptr, int srgb_intent)
     
    725749   png_byte buf[1];
    726750
    727    png_debug(1, "in png_write_sRGB\n");
    728    if(srgb_intent >= PNG_sRGB_INTENT_LAST)
     751   png_debug(1, "in png_write_sRGB");
     752
     753   if (srgb_intent >= PNG_sRGB_INTENT_LAST)
    729754         png_warning(png_ptr,
    730755            "Invalid sRGB rendering intent specified");
    731756   buf[0]=(png_byte)srgb_intent;
    732    png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
     757   png_write_chunk(png_ptr, (png_bytep)png_sRGB, buf, (png_size_t)1);
    733758}
    734759#endif
    735760
    736761#if defined(PNG_WRITE_iCCP_SUPPORTED)
    737 /* write an iCCP chunk */
     762/* Write an iCCP chunk */
    738763void /* PRIVATE */
    739764png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
     
    748773   int embedded_profile_len = 0;
    749774
    750    png_debug(1, "in png_write_iCCP\n");
     775   png_debug(1, "in png_write_iCCP");
    751776
    752777   comp.num_output_ptr = 0;
     
    756781   comp.input_len = 0;
    757782
    758    if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
     783   if ((name_len = png_check_keyword(png_ptr, name,
    759784      &new_name)) == 0)
    760    {
    761       png_warning(png_ptr, "Empty keyword in iCCP chunk");
    762785      return;
    763    }
    764786
    765787   if (compression_type != PNG_COMPRESSION_TYPE_BASE)
     
    771793   if (profile_len > 3)
    772794      embedded_profile_len =
    773           ((*( (png_bytep)profile  ))<<24) |
    774           ((*( (png_bytep)profile+1))<<16) |
    775           ((*( (png_bytep)profile+2))<< 8) |
    776           ((*( (png_bytep)profile+3))    );
     795          ((*( (png_bytep)profile    ))<<24) |
     796          ((*( (png_bytep)profile + 1))<<16) |
     797          ((*( (png_bytep)profile + 2))<< 8) |
     798          ((*( (png_bytep)profile + 3))    );
     799
     800   if (embedded_profile_len < 0)
     801   {
     802      png_warning(png_ptr,
     803        "Embedded profile length in iCCP chunk is negative");
     804      png_free(png_ptr, new_name);
     805      return;
     806   }
    777807
    778808   if (profile_len < embedded_profile_len)
    779      {
    780         png_warning(png_ptr,
    781           "Embedded profile length too large in iCCP chunk");
    782         return;
    783      }
     809   {
     810      png_warning(png_ptr,
     811        "Embedded profile length too large in iCCP chunk");
     812      png_free(png_ptr, new_name);
     813      return;
     814   }
    784815
    785816   if (profile_len > embedded_profile_len)
    786      {
    787         png_warning(png_ptr,
    788           "Truncating profile to actual length in iCCP chunk");
    789         profile_len = embedded_profile_len;
    790      }
     817   {
     818      png_warning(png_ptr,
     819        "Truncating profile to actual length in iCCP chunk");
     820      profile_len = embedded_profile_len;
     821   }
    791822
    792823   if (profile_len)
    793        profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
    794           PNG_COMPRESSION_TYPE_BASE, &comp);
    795 
    796    /* make sure we include the NULL after the name and the compression type */
    797    png_write_chunk_start(png_ptr, png_iCCP,
    798           (png_uint_32)name_len+profile_len+2);
    799    new_name[name_len+1]=0x00;
    800    png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
     824      profile_len = png_text_compress(png_ptr, profile,
     825        (png_size_t)profile_len, PNG_COMPRESSION_TYPE_BASE, &comp);
     826
     827   /* Make sure we include the NULL after the name and the compression type */
     828   png_write_chunk_start(png_ptr, (png_bytep)png_iCCP,
     829          (png_uint_32)(name_len + profile_len + 2));
     830   new_name[name_len + 1] = 0x00;
     831   png_write_chunk_data(png_ptr, (png_bytep)new_name,
     832     (png_size_t)(name_len + 2));
    801833
    802834   if (profile_len)
     
    809841
    810842#if defined(PNG_WRITE_sPLT_SUPPORTED)
    811 /* write a sPLT chunk */
     843/* Write a sPLT chunk */
    812844void /* PRIVATE */
    813845png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
     
    826858#endif
    827859
    828    png_debug(1, "in png_write_sPLT\n");
    829    if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
    830       spalette->name, &new_name))==0)
    831    {
    832       png_warning(png_ptr, "Empty keyword in sPLT chunk");
     860   png_debug(1, "in png_write_sPLT");
     861
     862   if ((name_len = png_check_keyword(png_ptr,spalette->name, &new_name))==0)
    833863      return;
    834    }
    835 
    836    /* make sure we include the NULL after the name */
    837    png_write_chunk_start(png_ptr, png_sPLT,
    838           (png_uint_32)(name_len + 2 + palette_size));
    839    png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
    840    png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
    841 
    842    /* loop through each palette entry, writing appropriately */
     864
     865   /* Make sure we include the NULL after the name */
     866   png_write_chunk_start(png_ptr, (png_bytep)png_sPLT,
     867     (png_uint_32)(name_len + 2 + palette_size));
     868   png_write_chunk_data(png_ptr, (png_bytep)new_name,
     869     (png_size_t)(name_len + 1));
     870   png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, (png_size_t)1);
     871
     872   /* Loop through each palette entry, writing appropriately */
    843873#ifndef PNG_NO_POINTER_INDEXING
    844    for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
    845    {
    846        if (spalette->depth == 8)
    847        {
    848            entrybuf[0] = (png_byte)ep->red;
    849            entrybuf[1] = (png_byte)ep->green;
    850            entrybuf[2] = (png_byte)ep->blue;
    851            entrybuf[3] = (png_byte)ep->alpha;
    852            png_save_uint_16(entrybuf + 4, ep->frequency);
    853        }
    854        else
    855        {
    856            png_save_uint_16(entrybuf + 0, ep->red);
    857            png_save_uint_16(entrybuf + 2, ep->green);
    858            png_save_uint_16(entrybuf + 4, ep->blue);
    859            png_save_uint_16(entrybuf + 6, ep->alpha);
    860            png_save_uint_16(entrybuf + 8, ep->frequency);
    861        }
    862        png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
     874   for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++)
     875   {
     876      if (spalette->depth == 8)
     877      {
     878          entrybuf[0] = (png_byte)ep->red;
     879          entrybuf[1] = (png_byte)ep->green;
     880          entrybuf[2] = (png_byte)ep->blue;
     881          entrybuf[3] = (png_byte)ep->alpha;
     882          png_save_uint_16(entrybuf + 4, ep->frequency);
     883      }
     884      else
     885      {
     886          png_save_uint_16(entrybuf + 0, ep->red);
     887          png_save_uint_16(entrybuf + 2, ep->green);
     888          png_save_uint_16(entrybuf + 4, ep->blue);
     889          png_save_uint_16(entrybuf + 6, ep->alpha);
     890          png_save_uint_16(entrybuf + 8, ep->frequency);
     891      }
     892      png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
    863893   }
    864894#else
     
    866896   for (i=0; i>spalette->nentries; i++)
    867897   {
    868        if (spalette->depth == 8)
    869        {
    870            entrybuf[0] = (png_byte)ep[i].red;
    871            entrybuf[1] = (png_byte)ep[i].green;
    872            entrybuf[2] = (png_byte)ep[i].blue;
    873            entrybuf[3] = (png_byte)ep[i].alpha;
    874            png_save_uint_16(entrybuf + 4, ep[i].frequency);
    875        }
    876        else
    877        {
    878            png_save_uint_16(entrybuf + 0, ep[i].red);
    879            png_save_uint_16(entrybuf + 2, ep[i].green);
    880            png_save_uint_16(entrybuf + 4, ep[i].blue);
    881            png_save_uint_16(entrybuf + 6, ep[i].alpha);
    882            png_save_uint_16(entrybuf + 8, ep[i].frequency);
    883        }
    884        png_write_chunk_data(png_ptr, entrybuf, entry_size);
     898      if (spalette->depth == 8)
     899      {
     900          entrybuf[0] = (png_byte)ep[i].red;
     901          entrybuf[1] = (png_byte)ep[i].green;
     902          entrybuf[2] = (png_byte)ep[i].blue;
     903          entrybuf[3] = (png_byte)ep[i].alpha;
     904          png_save_uint_16(entrybuf + 4, ep[i].frequency);
     905      }
     906      else
     907      {
     908          png_save_uint_16(entrybuf + 0, ep[i].red);
     909          png_save_uint_16(entrybuf + 2, ep[i].green);
     910          png_save_uint_16(entrybuf + 4, ep[i].blue);
     911          png_save_uint_16(entrybuf + 6, ep[i].alpha);
     912          png_save_uint_16(entrybuf + 8, ep[i].frequency);
     913      }
     914      png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
    885915   }
    886916#endif
     
    892922
    893923#if defined(PNG_WRITE_sBIT_SUPPORTED)
    894 /* write the sBIT chunk */
     924/* Write the sBIT chunk */
    895925void /* PRIVATE */
    896926png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
     
    902932   png_size_t size;
    903933
    904    png_debug(1, "in png_write_sBIT\n");
    905    /* make sure we don't depend upon the order of PNG_COLOR_8 */
     934   png_debug(1, "in png_write_sBIT");
     935
     936   /* Make sure we don't depend upon the order of PNG_COLOR_8 */
    906937   if (color_type & PNG_COLOR_MASK_COLOR)
    907938   {
     
    943974   }
    944975
    945    png_write_chunk(png_ptr, png_sBIT, buf, size);
     976   png_write_chunk(png_ptr, (png_bytep)png_sBIT, buf, size);
    946977}
    947978#endif
    948979
    949980#if defined(PNG_WRITE_cHRM_SUPPORTED)
    950 /* write the cHRM chunk */
     981/* Write the cHRM chunk */
    951982#ifdef PNG_FLOATING_POINT_SUPPORTED
    952983void /* PRIVATE */
     
    959990#endif
    960991   png_byte buf[32];
    961    png_uint_32 itemp;
    962 
    963    png_debug(1, "in png_write_cHRM\n");
    964    /* each value is saved in 1/100,000ths */
    965    if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
    966        white_x + white_y > 1.0)
    967    {
    968       png_warning(png_ptr, "Invalid cHRM white point specified");
    969 #if !defined(PNG_NO_CONSOLE_IO)
    970       fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
    971 #endif
    972       return;
    973    }
    974    itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
    975    png_save_uint_32(buf, itemp);
    976    itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
    977    png_save_uint_32(buf + 4, itemp);
    978 
    979    if (red_x < 0 ||  red_y < 0 || red_x + red_y > 1.0)
    980    {
    981       png_warning(png_ptr, "Invalid cHRM red point specified");
    982       return;
    983    }
    984    itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
    985    png_save_uint_32(buf + 8, itemp);
    986    itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
    987    png_save_uint_32(buf + 12, itemp);
    988 
    989    if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
    990    {
    991       png_warning(png_ptr, "Invalid cHRM green point specified");
    992       return;
    993    }
    994    itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
    995    png_save_uint_32(buf + 16, itemp);
    996    itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
    997    png_save_uint_32(buf + 20, itemp);
    998 
    999    if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
    1000    {
    1001       png_warning(png_ptr, "Invalid cHRM blue point specified");
    1002       return;
    1003    }
    1004    itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
    1005    png_save_uint_32(buf + 24, itemp);
    1006    itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
    1007    png_save_uint_32(buf + 28, itemp);
    1008 
    1009    png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
     992
     993   png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y,
     994      int_green_x, int_green_y, int_blue_x, int_blue_y;
     995
     996   png_debug(1, "in png_write_cHRM");
     997
     998   int_white_x = (png_uint_32)(white_x * 100000.0 + 0.5);
     999   int_white_y = (png_uint_32)(white_y * 100000.0 + 0.5);
     1000   int_red_x   = (png_uint_32)(red_x   * 100000.0 + 0.5);
     1001   int_red_y   = (png_uint_32)(red_y   * 100000.0 + 0.5);
     1002   int_green_x = (png_uint_32)(green_x * 100000.0 + 0.5);
     1003   int_green_y = (png_uint_32)(green_y * 100000.0 + 0.5);
     1004   int_blue_x  = (png_uint_32)(blue_x  * 100000.0 + 0.5);
     1005   int_blue_y  = (png_uint_32)(blue_y  * 100000.0 + 0.5);
     1006
     1007#if !defined(PNG_NO_CHECK_cHRM)
     1008   if (png_check_cHRM_fixed(png_ptr, int_white_x, int_white_y,
     1009      int_red_x, int_red_y, int_green_x, int_green_y, int_blue_x, int_blue_y))
     1010#endif
     1011   {
     1012      /* Each value is saved in 1/100,000ths */
     1013
     1014      png_save_uint_32(buf, int_white_x);
     1015      png_save_uint_32(buf + 4, int_white_y);
     1016
     1017      png_save_uint_32(buf + 8, int_red_x);
     1018      png_save_uint_32(buf + 12, int_red_y);
     1019
     1020      png_save_uint_32(buf + 16, int_green_x);
     1021      png_save_uint_32(buf + 20, int_green_y);
     1022
     1023      png_save_uint_32(buf + 24, int_blue_x);
     1024      png_save_uint_32(buf + 28, int_blue_y);
     1025
     1026      png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32);
     1027   }
    10101028}
    10111029#endif
     
    10221040   png_byte buf[32];
    10231041
    1024    png_debug(1, "in png_write_cHRM\n");
    1025    /* each value is saved in 1/100,000ths */
    1026    if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
    1027    {
    1028       png_warning(png_ptr, "Invalid fixed cHRM white point specified");
    1029 #if !defined(PNG_NO_CONSOLE_IO)
    1030       fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
    1031 #endif
    1032       return;
    1033    }
    1034    png_save_uint_32(buf, (png_uint_32)white_x);
    1035    png_save_uint_32(buf + 4, (png_uint_32)white_y);
    1036 
    1037    if (red_x + red_y > 100000L)
    1038    {
    1039       png_warning(png_ptr, "Invalid cHRM fixed red point specified");
    1040       return;
    1041    }
    1042    png_save_uint_32(buf + 8, (png_uint_32)red_x);
    1043    png_save_uint_32(buf + 12, (png_uint_32)red_y);
    1044 
    1045    if (green_x + green_y > 100000L)
    1046    {
    1047       png_warning(png_ptr, "Invalid fixed cHRM green point specified");
    1048       return;
    1049    }
    1050    png_save_uint_32(buf + 16, (png_uint_32)green_x);
    1051    png_save_uint_32(buf + 20, (png_uint_32)green_y);
    1052 
    1053    if (blue_x + blue_y > 100000L)
    1054    {
    1055       png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
    1056       return;
    1057    }
    1058    png_save_uint_32(buf + 24, (png_uint_32)blue_x);
    1059    png_save_uint_32(buf + 28, (png_uint_32)blue_y);
    1060 
    1061    png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
     1042   png_debug(1, "in png_write_cHRM");
     1043
     1044   /* Each value is saved in 1/100,000ths */
     1045#if !defined(PNG_NO_CHECK_cHRM)
     1046   if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y,
     1047      green_x, green_y, blue_x, blue_y))
     1048#endif
     1049   {
     1050      png_save_uint_32(buf, (png_uint_32)white_x);
     1051      png_save_uint_32(buf + 4, (png_uint_32)white_y);
     1052
     1053      png_save_uint_32(buf + 8, (png_uint_32)red_x);
     1054      png_save_uint_32(buf + 12, (png_uint_32)red_y);
     1055
     1056      png_save_uint_32(buf + 16, (png_uint_32)green_x);
     1057      png_save_uint_32(buf + 20, (png_uint_32)green_y);
     1058
     1059      png_save_uint_32(buf + 24, (png_uint_32)blue_x);
     1060      png_save_uint_32(buf + 28, (png_uint_32)blue_y);
     1061
     1062      png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32);
     1063   }
    10621064}
    10631065#endif
     
    10651067
    10661068#if defined(PNG_WRITE_tRNS_SUPPORTED)
    1067 /* write the tRNS chunk */
     1069/* Write the tRNS chunk */
    10681070void /* PRIVATE */
    10691071png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
     
    10751077   png_byte buf[6];
    10761078
    1077    png_debug(1, "in png_write_tRNS\n");
     1079   png_debug(1, "in png_write_tRNS");
     1080
    10781081   if (color_type == PNG_COLOR_TYPE_PALETTE)
    10791082   {
    10801083      if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
    10811084      {
    1082          png_warning(png_ptr,"Invalid number of transparent colors specified");
     1085         png_warning(png_ptr, "Invalid number of transparent colors specified");
    10831086         return;
    10841087      }
    1085       /* write the chunk out as it is */
    1086       png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
     1088      /* Write the chunk out as it is */
     1089      png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans,
     1090        (png_size_t)num_trans);
    10871091   }
    10881092   else if (color_type == PNG_COLOR_TYPE_GRAY)
    10891093   {
    1090       /* one 16 bit value */
    1091       if(tran->gray >= (1 << png_ptr->bit_depth))
     1094      /* One 16 bit value */
     1095      if (tran->gray >= (1 << png_ptr->bit_depth))
    10921096      {
    10931097         png_warning(png_ptr,
     
    10961100      }
    10971101      png_save_uint_16(buf, tran->gray);
    1098       png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
     1102      png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)2);
    10991103   }
    11001104   else if (color_type == PNG_COLOR_TYPE_RGB)
    11011105   {
    1102       /* three 16 bit values */
     1106      /* Three 16 bit values */
    11031107      png_save_uint_16(buf, tran->red);
    11041108      png_save_uint_16(buf + 2, tran->green);
    11051109      png_save_uint_16(buf + 4, tran->blue);
    1106       if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
    1107          {
    1108             png_warning(png_ptr,
    1109               "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
    1110             return;
    1111          }
    1112       png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
     1110      if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
     1111      {
     1112         png_warning(png_ptr,
     1113           "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
     1114         return;
     1115      }
     1116      png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)6);
    11131117   }
    11141118   else
     
    11201124
    11211125#if defined(PNG_WRITE_bKGD_SUPPORTED)
    1122 /* write the background chunk */
     1126/* Write the background chunk */
    11231127void /* PRIVATE */
    11241128png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
     
    11291133   png_byte buf[6];
    11301134
    1131    png_debug(1, "in png_write_bKGD\n");
     1135   png_debug(1, "in png_write_bKGD");
     1136
    11321137   if (color_type == PNG_COLOR_TYPE_PALETTE)
    11331138   {
     
    11371142          (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
    11381143#endif
    1139          back->index > png_ptr->num_palette)
     1144         back->index >= png_ptr->num_palette)
    11401145      {
    11411146         png_warning(png_ptr, "Invalid background palette index");
     
    11431148      }
    11441149      buf[0] = back->index;
    1145       png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
     1150      png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)1);
    11461151   }
    11471152   else if (color_type & PNG_COLOR_MASK_COLOR)
     
    11501155      png_save_uint_16(buf + 2, back->green);
    11511156      png_save_uint_16(buf + 4, back->blue);
    1152       if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
    1153          {
    1154             png_warning(png_ptr,
    1155               "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
    1156             return;
    1157          }
    1158       png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
     1157      if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
     1158      {
     1159         png_warning(png_ptr,
     1160           "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
     1161         return;
     1162      }
     1163      png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)6);
    11591164   }
    11601165   else
    11611166   {
    1162       if(back->gray >= (1 << png_ptr->bit_depth))
     1167      if (back->gray >= (1 << png_ptr->bit_depth))
    11631168      {
    11641169         png_warning(png_ptr,
     
    11671172      }
    11681173      png_save_uint_16(buf, back->gray);
    1169       png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
     1174      png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)2);
    11701175   }
    11711176}
     
    11731178
    11741179#if defined(PNG_WRITE_hIST_SUPPORTED)
    1175 /* write the histogram */
     1180/* Write the histogram */
    11761181void /* PRIVATE */
    11771182png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
     
    11831188   png_byte buf[3];
    11841189
    1185    png_debug(1, "in png_write_hIST\n");
     1190   png_debug(1, "in png_write_hIST");
     1191
    11861192   if (num_hist > (int)png_ptr->num_palette)
    11871193   {
    1188       png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
     1194      png_debug2(3, "num_hist = %d, num_palette = %d", num_hist,
    11891195         png_ptr->num_palette);
    11901196      png_warning(png_ptr, "Invalid number of histogram entries specified");
     
    11921198   }
    11931199
    1194    png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
     1200   png_write_chunk_start(png_ptr, (png_bytep)png_hIST,
     1201     (png_uint_32)(num_hist * 2));
    11951202   for (i = 0; i < num_hist; i++)
    11961203   {
     
    12221229   int kwarn=0;
    12231230
    1224    png_debug(1, "in png_check_keyword\n");
     1231   png_debug(1, "in png_check_keyword");
     1232
    12251233   *new_key = NULL;
    12261234
     
    12311239   }
    12321240
    1233    png_debug1(2, "Keyword to be checked is '%s'\n", key);
     1241   png_debug1(2, "Keyword to be checked is '%s'", key);
    12341242
    12351243   *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
     
    12721280      while (*kp == ' ')
    12731281      {
    1274         *(kp--) = '\0';
    1275         key_len--;
     1282         *(kp--) = '\0';
     1283         key_len--;
    12761284      }
    12771285   }
     
    12851293      while (*kp == ' ')
    12861294      {
    1287         kp++;
    1288         key_len--;
    1289       }
    1290    }
    1291 
    1292    png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
     1295         kp++;
     1296         key_len--;
     1297      }
     1298   }
     1299
     1300   png_debug1(2, "Checking for multiple internal spaces in '%s'", kp);
    12931301
    12941302   /* Remove multiple internal spaces. */
     
    13121320   }
    13131321   *dp = '\0';
    1314    if(kwarn)
     1322   if (kwarn)
    13151323      png_warning(png_ptr, "extra interior spaces removed from keyword");
    13161324
     
    13181326   {
    13191327      png_free(png_ptr, *new_key);
    1320       *new_key=NULL;
     1328       *new_key=NULL;
    13211329      png_warning(png_ptr, "Zero length keyword");
    13221330   }
     
    13251333   {
    13261334      png_warning(png_ptr, "keyword length must be 1 - 79 characters");
    1327       new_key[79] = '\0';
     1335      (*new_key)[79] = '\0';
    13281336      key_len = 79;
    13291337   }
     
    13341342
    13351343#if defined(PNG_WRITE_tEXt_SUPPORTED)
    1336 /* write a tEXt chunk */
     1344/* Write a tEXt chunk */
    13371345void /* PRIVATE */
    13381346png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
     
    13451353   png_charp new_key;
    13461354
    1347    png_debug(1, "in png_write_tEXt\n");
    1348    if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
    1349    {
    1350       png_warning(png_ptr, "Empty keyword in tEXt chunk");
     1355   png_debug(1, "in png_write_tEXt");
     1356
     1357   if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0)
    13511358      return;
    1352    }
    13531359
    13541360   if (text == NULL || *text == '\0')
     
    13571363      text_len = png_strlen(text);
    13581364
    1359    /* make sure we include the 0 after the key */
    1360    png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
     1365   /* Make sure we include the 0 after the key */
     1366   png_write_chunk_start(png_ptr, (png_bytep)png_tEXt,
     1367      (png_uint_32)(key_len + text_len + 1));
    13611368   /*
    13621369    * We leave it to the application to meet PNG-1.0 requirements on the
     
    13651372    * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.
    13661373    */
    1367    png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
     1374   png_write_chunk_data(png_ptr, (png_bytep)new_key,
     1375     (png_size_t)(key_len + 1));
    13681376   if (text_len)
    1369       png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
     1377      png_write_chunk_data(png_ptr, (png_bytep)text, (png_size_t)text_len);
    13701378
    13711379   png_write_chunk_end(png_ptr);
     
    13751383
    13761384#if defined(PNG_WRITE_zTXt_SUPPORTED)
    1377 /* write a compressed text chunk */
     1385/* Write a compressed text chunk */
    13781386void /* PRIVATE */
    13791387png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
     
    13881396   compression_state comp;
    13891397
    1390    png_debug(1, "in png_write_zTXt\n");
     1398   png_debug(1, "in png_write_zTXt");
    13911399
    13921400   comp.num_output_ptr = 0;
     
    13961404   comp.input_len = 0;
    13971405
    1398    if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
    1399    {
    1400       png_warning(png_ptr, "Empty keyword in zTXt chunk");
     1406   if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0)
     1407   {
     1408      png_free(png_ptr, new_key);
    14011409      return;
    14021410   }
     
    14111419   text_len = png_strlen(text);
    14121420
    1413    /* compute the compressed data; do it now for the length */
     1421   /* Compute the compressed data; do it now for the length */
    14141422   text_len = png_text_compress(png_ptr, text, text_len, compression,
    14151423       &comp);
    14161424
    1417    /* write start of chunk */
    1418    png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
    1419       (key_len+text_len+2));
    1420    /* write key */
    1421    png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
     1425   /* Write start of chunk */
     1426   png_write_chunk_start(png_ptr, (png_bytep)png_zTXt,
     1427     (png_uint_32)(key_len+text_len + 2));
     1428   /* Write key */
     1429   png_write_chunk_data(png_ptr, (png_bytep)new_key,
     1430     (png_size_t)(key_len + 1));
    14221431   png_free(png_ptr, new_key);
    14231432
    14241433   buf[0] = (png_byte)compression;
    1425    /* write compression */
     1434   /* Write compression */
    14261435   png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
    1427    /* write the compressed data */
     1436   /* Write the compressed data */
    14281437   png_write_compressed_data_out(png_ptr, &comp);
    14291438
    1430    /* close the chunk */
     1439   /* Close the chunk */
    14311440   png_write_chunk_end(png_ptr);
    14321441}
     
    14341443
    14351444#if defined(PNG_WRITE_iTXt_SUPPORTED)
    1436 /* write an iTXt chunk */
     1445/* Write an iTXt chunk */
    14371446void /* PRIVATE */
    14381447png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
     
    14431452#endif
    14441453   png_size_t lang_len, key_len, lang_key_len, text_len;
    1445    png_charp new_lang, new_key;
     1454   png_charp new_lang;
     1455   png_charp new_key = NULL;
    14461456   png_byte cbuf[2];
    14471457   compression_state comp;
    14481458
    1449    png_debug(1, "in png_write_iTXt\n");
     1459   png_debug(1, "in png_write_iTXt");
    14501460
    14511461   comp.num_output_ptr = 0;
     
    14541464   comp.input = NULL;
    14551465
    1456    if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
    1457    {
    1458       png_warning(png_ptr, "Empty keyword in iTXt chunk");
     1466   if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0)
    14591467      return;
    1460    }
    1461    if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
     1468
     1469   if ((lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
    14621470   {
    14631471      png_warning(png_ptr, "Empty language field in iTXt chunk");
     
    14671475
    14681476   if (lang_key == NULL)
    1469      lang_key_len = 0;
     1477      lang_key_len = 0;
    14701478   else
    1471      lang_key_len = png_strlen(lang_key);
     1479      lang_key_len = png_strlen(lang_key);
    14721480
    14731481   if (text == NULL)
    14741482      text_len = 0;
    14751483   else
    1476      text_len = png_strlen(text);
    1477 
    1478    /* compute the compressed data; do it now for the length */
     1484      text_len = png_strlen(text);
     1485
     1486   /* Compute the compressed data; do it now for the length */
    14791487   text_len = png_text_compress(png_ptr, text, text_len, compression-2,
    14801488      &comp);
    14811489
    14821490
    1483    /* make sure we include the compression flag, the compression byte,
     1491   /* Make sure we include the compression flag, the compression byte,
    14841492    * and the NULs after the key, lang, and lang_key parts */
    14851493
    1486    png_write_chunk_start(png_ptr, png_iTXt,
     1494   png_write_chunk_start(png_ptr, (png_bytep)png_iTXt,
    14871495          (png_uint_32)(
    14881496        5 /* comp byte, comp flag, terminators for key, lang and lang_key */
     
    14921500        + text_len));
    14931501
    1494    /*
    1495     * We leave it to the application to meet PNG-1.0 requirements on the
     1502   /* We leave it to the application to meet PNG-1.0 requirements on the
    14961503    * contents of the text.  PNG-1.0 through PNG-1.2 discourage the use of
    14971504    * any non-Latin-1 characters except for NEWLINE.  ISO PNG will forbid them.
    14981505    * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.
    14991506    */
    1500    png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
    1501 
    1502    /* set the compression flag */
     1507   png_write_chunk_data(png_ptr, (png_bytep)new_key,
     1508     (png_size_t)(key_len + 1));
     1509
     1510   /* Set the compression flag */
    15031511   if (compression == PNG_ITXT_COMPRESSION_NONE || \
    15041512       compression == PNG_TEXT_COMPRESSION_NONE)
     
    15061514   else /* compression == PNG_ITXT_COMPRESSION_zTXt */
    15071515       cbuf[0] = 1;
    1508    /* set the compression method */
     1516   /* Set the compression method */
    15091517   cbuf[1] = 0;
    1510    png_write_chunk_data(png_ptr, cbuf, 2);
     1518   png_write_chunk_data(png_ptr, cbuf, (png_size_t)2);
    15111519
    15121520   cbuf[0] = 0;
    1513    png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
    1514    png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
     1521   png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf),
     1522     (png_size_t)(lang_len + 1));
     1523   png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf),
     1524     (png_size_t)(lang_key_len + 1));
    15151525   png_write_compressed_data_out(png_ptr, &comp);
    15161526
     
    15221532
    15231533#if defined(PNG_WRITE_oFFs_SUPPORTED)
    1524 /* write the oFFs chunk */
     1534/* Write the oFFs chunk */
    15251535void /* PRIVATE */
    15261536png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
     
    15321542   png_byte buf[9];
    15331543
    1534    png_debug(1, "in png_write_oFFs\n");
     1544   png_debug(1, "in png_write_oFFs");
     1545
    15351546   if (unit_type >= PNG_OFFSET_LAST)
    15361547      png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
     
    15401551   buf[8] = (png_byte)unit_type;
    15411552
    1542    png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
     1553   png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, (png_size_t)9);
    15431554}
    15441555#endif
    15451556#if defined(PNG_WRITE_pCAL_SUPPORTED)
    1546 /* write the pCAL chunk (described in the PNG extensions document) */
     1557/* Write the pCAL chunk (described in the PNG extensions document) */
    15471558void /* PRIVATE */
    15481559png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
     
    15581569   int i;
    15591570
    1560    png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
     1571   png_debug1(1, "in png_write_pCAL (%d parameters)", nparams);
     1572
    15611573   if (type >= PNG_EQUATION_LAST)
    15621574      png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
    15631575
    15641576   purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
    1565    png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
     1577   png_debug1(3, "pCAL purpose length = %d", (int)purpose_len);
    15661578   units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
    1567    png_debug1(3, "pCAL units length = %d\n", (int)units_len);
     1579   png_debug1(3, "pCAL units length = %d", (int)units_len);
    15681580   total_len = purpose_len + units_len + 10;
    15691581
    1570    params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
    1571       *png_sizeof(png_uint_32)));
     1582   params_len = (png_uint_32p)png_malloc(png_ptr,
     1583      (png_uint_32)(nparams * png_sizeof(png_uint_32)));
    15721584
    15731585   /* Find the length of each parameter, making sure we don't count the
     
    15761588   {
    15771589      params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
    1578       png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
     1590      png_debug2(3, "pCAL parameter %d length = %lu", i,
     1591        (unsigned long) params_len[i]);
    15791592      total_len += (png_size_t)params_len[i];
    15801593   }
    15811594
    1582    png_debug1(3, "pCAL total length = %d\n", (int)total_len);
    1583    png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
    1584    png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
     1595   png_debug1(3, "pCAL total length = %d", (int)total_len);
     1596   png_write_chunk_start(png_ptr, (png_bytep)png_pCAL, (png_uint_32)total_len);
     1597   png_write_chunk_data(png_ptr, (png_bytep)new_purpose,
     1598     (png_size_t)purpose_len);
    15851599   png_save_int_32(buf, X0);
    15861600   png_save_int_32(buf + 4, X1);
     
    16041618
    16051619#if defined(PNG_WRITE_sCAL_SUPPORTED)
    1606 /* write the sCAL chunk */
     1620/* Write the sCAL chunk */
    16071621#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
    16081622void /* PRIVATE */
     
    16151629   png_size_t total_len;
    16161630
    1617    png_debug(1, "in png_write_sCAL\n");
     1631   png_debug(1, "in png_write_sCAL");
    16181632
    16191633   buf[0] = (char)unit;
     
    16401654#endif
    16411655
    1642    png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
    1643    png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
     1656   png_debug1(3, "sCAL total length = %u", (unsigned int)total_len);
     1657   png_write_chunk(png_ptr, (png_bytep)png_sCAL, (png_bytep)buf, total_len);
    16441658}
    16451659#else
     
    16551669   png_size_t wlen, hlen, total_len;
    16561670
    1657    png_debug(1, "in png_write_sCAL_s\n");
     1671   png_debug(1, "in png_write_sCAL_s");
    16581672
    16591673   wlen = png_strlen(width);
     
    16671681
    16681682   buf[0] = (png_byte)unit;
    1669    png_memcpy(buf + 1, width, wlen + 1);      /* append the '\0' here */
    1670    png_memcpy(buf + wlen + 2, height, hlen);  /* do NOT append the '\0' here */
    1671 
    1672    png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
    1673    png_write_chunk(png_ptr, png_sCAL, buf, total_len);
     1683   png_memcpy(buf + 1, width, wlen + 1);      /* Append the '\0' here */
     1684   png_memcpy(buf + wlen + 2, height, hlen);  /* Do NOT append the '\0' here */
     1685
     1686   png_debug1(3, "sCAL total length = %u", (unsigned int)total_len);
     1687   png_write_chunk(png_ptr, (png_bytep)png_sCAL, buf, total_len);
    16741688}
    16751689#endif
     
    16781692
    16791693#if defined(PNG_WRITE_pHYs_SUPPORTED)
    1680 /* write the pHYs chunk */
     1694/* Write the pHYs chunk */
    16811695void /* PRIVATE */
    16821696png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
     
    16891703   png_byte buf[9];
    16901704
    1691    png_debug(1, "in png_write_pHYs\n");
     1705   png_debug(1, "in png_write_pHYs");
     1706
    16921707   if (unit_type >= PNG_RESOLUTION_LAST)
    16931708      png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
     
    16971712   buf[8] = (png_byte)unit_type;
    16981713
    1699    png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
     1714   png_write_chunk(png_ptr, (png_bytep)png_pHYs, buf, (png_size_t)9);
    17001715}
    17011716#endif
     
    17131728   png_byte buf[7];
    17141729
    1715    png_debug(1, "in png_write_tIME\n");
     1730   png_debug(1, "in png_write_tIME");
     1731
    17161732   if (mod_time->month  > 12 || mod_time->month  < 1 ||
    17171733       mod_time->day    > 31 || mod_time->day    < 1 ||
     
    17291745   buf[6] = mod_time->second;
    17301746
    1731    png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
    1732 }
    1733 #endif
    1734 
    1735 /* initializes the row writing capability of libpng */
     1747   png_write_chunk(png_ptr, (png_bytep)png_tIME, buf, (png_size_t)7);
     1748}
     1749#endif
     1750
     1751/* Initializes the row writing capability of libpng */
    17361752void /* PRIVATE */
    17371753png_write_start_row(png_structp png_ptr)
     
    17391755#ifdef PNG_WRITE_INTERLACING_SUPPORTED
    17401756#ifdef PNG_USE_LOCAL_ARRAYS
    1741    /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
    1742 
    1743    /* start of interlace block */
     1757   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
     1758
     1759   /* Start of interlace block */
    17441760   int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
    17451761
    1746    /* offset to next interlace block */
     1762   /* Offset to next interlace block */
    17471763   int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
    17481764
    1749    /* start of interlace block in the y direction */
     1765   /* Start of interlace block in the y direction */
    17501766   int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
    17511767
    1752    /* offset to next interlace block in the y direction */
     1768   /* Offset to next interlace block in the y direction */
    17531769   int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
    17541770#endif
     
    17571773   png_size_t buf_size;
    17581774
    1759    png_debug(1, "in png_write_start_row\n");
     1775   png_debug(1, "in png_write_start_row");
     1776
    17601777   buf_size = (png_size_t)(PNG_ROWBYTES(
    1761       png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
    1762 
    1763    /* set up row buffer */
    1764    png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
     1778      png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1);
     1779
     1780   /* Set up row buffer */
     1781   png_ptr->row_buf = (png_bytep)png_malloc(png_ptr,
     1782     (png_uint_32)buf_size);
    17651783   png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
    17661784
    1767 #ifndef PNG_NO_WRITE_FILTERING
    1768    /* set up filtering buffer, if using this filter */
     1785#ifndef PNG_NO_WRITE_FILTER
     1786   /* Set up filtering buffer, if using this filter */
    17691787   if (png_ptr->do_filter & PNG_FILTER_SUB)
    17701788   {
    17711789      png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
    1772          (png_ptr->rowbytes + 1));
     1790         (png_uint_32)(png_ptr->rowbytes + 1));
    17731791      png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
    17741792   }
     
    17771795   if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
    17781796   {
    1779      /* set up previous row buffer */
    1780       png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
    1781       png_memset(png_ptr->prev_row, 0, buf_size);
     1797     /* Set up previous row buffer */
     1798     png_ptr->prev_row = (png_bytep)png_malloc(png_ptr,
     1799        (png_uint_32)buf_size);
     1800     png_memset(png_ptr->prev_row, 0, buf_size);
    17821801
    17831802      if (png_ptr->do_filter & PNG_FILTER_UP)
    17841803      {
    17851804         png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
    1786             (png_ptr->rowbytes + 1));
     1805           (png_uint_32)(png_ptr->rowbytes + 1));
    17871806         png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
    17881807      }
     
    17911810      {
    17921811         png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
    1793             (png_ptr->rowbytes + 1));
     1812           (png_uint_32)(png_ptr->rowbytes + 1));
    17941813         png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
    17951814      }
     
    17981817      {
    17991818         png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
    1800             (png_ptr->rowbytes + 1));
     1819           (png_uint_32)(png_ptr->rowbytes + 1));
    18011820         png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
    18021821      }
    1803 #endif /* PNG_NO_WRITE_FILTERING */
    1804    }
     1822   }
     1823#endif /* PNG_NO_WRITE_FILTER */
    18051824
    18061825#ifdef PNG_WRITE_INTERLACING_SUPPORTED
    1807    /* if interlaced, we need to set up width and height of pass */
     1826   /* If interlaced, we need to set up width and height of pass */
    18081827   if (png_ptr->interlaced)
    18091828   {
     
    18371856#ifdef PNG_WRITE_INTERLACING_SUPPORTED
    18381857#ifdef PNG_USE_LOCAL_ARRAYS
    1839    /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
    1840 
    1841    /* start of interlace block */
     1858   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
     1859
     1860   /* Start of interlace block */
    18421861   int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
    18431862
    1844    /* offset to next interlace block */
     1863   /* Offset to next interlace block */
    18451864   int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
    18461865
    1847    /* start of interlace block in the y direction */
     1866   /* Start of interlace block in the y direction */
    18481867   int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
    18491868
    1850    /* offset to next interlace block in the y direction */
     1869   /* Offset to next interlace block in the y direction */
    18511870   int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
    18521871#endif
     
    18551874   int ret;
    18561875
    1857    png_debug(1, "in png_write_finish_row\n");
    1858    /* next row */
     1876   png_debug(1, "in png_write_finish_row");
     1877
     1878   /* Next row */
    18591879   png_ptr->row_number++;
    18601880
    1861    /* see if we are done */
     1881   /* See if we are done */
    18621882   if (png_ptr->row_number < png_ptr->num_rows)
    18631883      return;
    18641884
    18651885#ifdef PNG_WRITE_INTERLACING_SUPPORTED
    1866    /* if interlaced, go to next pass */
     1886   /* If interlaced, go to next pass */
    18671887   if (png_ptr->interlaced)
    18681888   {
     
    18741894      else
    18751895      {
    1876          /* loop until we find a non-zero width or height pass */
     1896         /* Loop until we find a non-zero width or height pass */
    18771897         do
    18781898         {
     
    18941914      }
    18951915
    1896       /* reset the row above the image for the next pass */
     1916      /* Reset the row above the image for the next pass */
    18971917      if (png_ptr->pass < 7)
    18981918      {
     
    19001920            png_memset(png_ptr->prev_row, 0,
    19011921               (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
    1902                png_ptr->usr_bit_depth,png_ptr->width))+1);
     1922               png_ptr->usr_bit_depth, png_ptr->width)) + 1);
    19031923         return;
    19041924      }
     
    19061926#endif
    19071927
    1908    /* if we get here, we've just written the last row, so we need
     1928   /* If we get here, we've just written the last row, so we need
    19091929      to flush the compressor */
    19101930   do
    19111931   {
    1912       /* tell the compressor we are done */
     1932      /* Tell the compressor we are done */
    19131933      ret = deflate(&png_ptr->zstream, Z_FINISH);
    1914       /* check for an error */
     1934      /* Check for an error */
    19151935      if (ret == Z_OK)
    19161936      {
    1917          /* check to see if we need more room */
     1937         /* Check to see if we need more room */
    19181938         if (!(png_ptr->zstream.avail_out))
    19191939         {
     
    19321952   } while (ret != Z_STREAM_END);
    19331953
    1934    /* write any extra space */
     1954   /* Write any extra space */
    19351955   if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
    19361956   {
     
    19551975{
    19561976#ifdef PNG_USE_LOCAL_ARRAYS
    1957    /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
    1958 
    1959    /* start of interlace block */
     1977   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
     1978
     1979   /* Start of interlace block */
    19601980   int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
    19611981
    1962    /* offset to next interlace block */
     1982   /* Offset to next interlace block */
    19631983   int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
    19641984#endif
    19651985
    1966    png_debug(1, "in png_do_write_interlace\n");
    1967    /* we don't have to do anything on the last pass (6) */
     1986   png_debug(1, "in png_do_write_interlace");
     1987
     1988   /* We don't have to do anything on the last pass (6) */
    19681989#if defined(PNG_USELESS_TESTS_SUPPORTED)
    19691990   if (row != NULL && row_info != NULL && pass < 6)
     
    19721993#endif
    19731994   {
    1974       /* each pixel depth is handled separately */
     1995      /* Each pixel depth is handled separately */
    19751996      switch (row_info->pixel_depth)
    19761997      {
     
    20832104            png_size_t pixel_bytes;
    20842105
    2085             /* start at the beginning */
     2106            /* Start at the beginning */
    20862107            dp = row;
    2087             /* find out how many bytes each pixel takes up */
     2108            /* Find out how many bytes each pixel takes up */
    20882109            pixel_bytes = (row_info->pixel_depth >> 3);
    2089             /* loop through the row, only looking at the pixels that
     2110            /* Loop through the row, only looking at the pixels that
    20902111               matter */
    20912112            for (i = png_pass_start[pass]; i < row_width;
    20922113               i += png_pass_inc[pass])
    20932114            {
    2094                /* find out where the original pixel is */
     2115               /* Find out where the original pixel is */
    20952116               sp = row + (png_size_t)i * pixel_bytes;
    2096                /* move the pixel */
     2117               /* Move the pixel */
    20972118               if (dp != sp)
    20982119                  png_memcpy(dp, sp, pixel_bytes);
    2099                /* next pixel */
     2120               /* Next pixel */
    21002121               dp += pixel_bytes;
    21012122            }
     
    21032124         }
    21042125      }
    2105       /* set new row width */
     2126      /* Set new row width */
    21062127      row_info->width = (row_info->width +
    21072128         png_pass_inc[pass] - 1 -
     
    21312152   png_byte filter_to_do = png_ptr->do_filter;
    21322153   png_uint_32 row_bytes = row_info->rowbytes;
    2133 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
     2154#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
    21342155   int num_p_filters = (int)png_ptr->num_prev_filters;
    2135 #endif
    2136 
    2137    png_debug(1, "in png_write_find_filter\n");
    2138    /* find out how many bytes offset each pixel is */
     2156#endif
     2157
     2158   png_debug(1, "in png_write_find_filter");
     2159
     2160   /* Find out how many bytes offset each pixel is */
    21392161   bpp = (row_info->pixel_depth + 7) >> 3;
    21402162
     
    22232245   }
    22242246
    2225    /* sub filter */
     2247   /* Sub filter */
    22262248   if (filter_to_do == PNG_FILTER_SUB)
    2227    /* it's the only filter so no testing is needed */
     2249   /* It's the only filter so no testing is needed */
    22282250   {
    22292251      png_bytep rp, lp, dp;
     
    23402362   }
    23412363
    2342    /* up filter */
     2364   /* Up filter */
    23432365   if (filter_to_do == PNG_FILTER_UP)
    23442366   {
     
    24432465   }
    24442466
    2445    /* avg filter */
     2467   /* Avg filter */
    24462468   if (filter_to_do == PNG_FILTER_AVG)
    24472469   {
     
    27442766png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
    27452767{
    2746    png_debug(1, "in png_write_filtered_row\n");
    2747    png_debug1(2, "filter = %d\n", filtered_row[0]);
    2748    /* set up the zlib input buffer */
     2768   png_debug(1, "in png_write_filtered_row");
     2769
     2770   png_debug1(2, "filter = %d", filtered_row[0]);
     2771   /* Set up the zlib input buffer */
    27492772
    27502773   png_ptr->zstream.next_in = filtered_row;
    27512774   png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
    2752    /* repeat until we have compressed all the data */
     2775   /* Repeat until we have compressed all the data */
    27532776   do
    27542777   {
    2755       int ret; /* return of zlib */
    2756 
    2757       /* compress the data */
     2778      int ret; /* Return of zlib */
     2779
     2780      /* Compress the data */
    27582781      ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
    2759       /* check for compression errors */
     2782      /* Check for compression errors */
    27602783      if (ret != Z_OK)
    27612784      {
     
    27662789      }
    27672790
    2768       /* see if it is time to write another IDAT */
     2791      /* See if it is time to write another IDAT */
    27692792      if (!(png_ptr->zstream.avail_out))
    27702793      {
    2771          /* write the IDAT and reset the zlib output buffer */
     2794         /* Write the IDAT and reset the zlib output buffer */
    27722795         png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
    27732796         png_ptr->zstream.next_out = png_ptr->zbuf;
    27742797         png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
    27752798      }
    2776    /* repeat until all data has been compressed */
     2799   /* Repeat until all data has been compressed */
    27772800   } while (png_ptr->zstream.avail_in);
    27782801
    2779    /* swap the current and previous rows */
     2802   /* Swap the current and previous rows */
    27802803   if (png_ptr->prev_row != NULL)
    27812804   {
     
    27872810   }
    27882811
    2789    /* finish row - updates counters and flushes zlib if last row */
     2812   /* Finish row - updates counters and flushes zlib if last row */
    27902813   png_write_finish_row(png_ptr);
    27912814
Note: See TracChangeset for help on using the changeset viewer.