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

    r2 r561  
    22/* pngrtran.c - transforms the data in a row for PNG readers
    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.38 [July 16, 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 * This file contains functions optionally called by an application
     
    1619#define PNG_INTERNAL
    1720#include "png.h"
    18 
    1921#if defined(PNG_READ_SUPPORTED)
    2022
     
    2325png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
    2426{
    25    png_debug(1, "in png_set_crc_action\n");
     27   png_debug(1, "in png_set_crc_action");
    2628   /* Tell libpng how we react to CRC errors in critical chunks */
    27    if(png_ptr == NULL) return;
     29   if (png_ptr == NULL)
     30      return;
    2831   switch (crit_action)
    2932   {
    30       case PNG_CRC_NO_CHANGE:                        /* leave setting as is */
     33      case PNG_CRC_NO_CHANGE:                        /* Leave setting as is */
    3134         break;
    32       case PNG_CRC_WARN_USE:                               /* warn/use data */
     35
     36      case PNG_CRC_WARN_USE:                               /* Warn/use data */
    3337         png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
    3438         png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
    3539         break;
    36       case PNG_CRC_QUIET_USE:                             /* quiet/use data */
     40
     41      case PNG_CRC_QUIET_USE:                             /* Quiet/use data */
    3742         png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
    3843         png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
    3944                           PNG_FLAG_CRC_CRITICAL_IGNORE;
    4045         break;
    41       case PNG_CRC_WARN_DISCARD:    /* not a valid action for critical data */
    42          png_warning(png_ptr, "Can't discard critical data on CRC error.");
    43       case PNG_CRC_ERROR_QUIT:                                /* error/quit */
     46
     47      case PNG_CRC_WARN_DISCARD:    /* Not a valid action for critical data */
     48         png_warning(png_ptr,
     49            "Can't discard critical data on CRC error.");
     50      case PNG_CRC_ERROR_QUIT:                                /* Error/quit */
     51
    4452      case PNG_CRC_DEFAULT:
    4553      default:
     
    5058   switch (ancil_action)
    5159   {
    52       case PNG_CRC_NO_CHANGE:                       /* leave setting as is */
     60      case PNG_CRC_NO_CHANGE:                       /* Leave setting as is */
    5361         break;
    54       case PNG_CRC_WARN_USE:                              /* warn/use data */
     62
     63      case PNG_CRC_WARN_USE:                              /* Warn/use data */
    5564         png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
    5665         png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
    5766         break;
    58       case PNG_CRC_QUIET_USE:                            /* quiet/use data */
     67
     68      case PNG_CRC_QUIET_USE:                            /* Quiet/use data */
    5969         png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
    6070         png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
    6171                           PNG_FLAG_CRC_ANCILLARY_NOWARN;
    6272         break;
    63       case PNG_CRC_ERROR_QUIT:                               /* error/quit */
     73
     74      case PNG_CRC_ERROR_QUIT:                               /* Error/quit */
    6475         png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
    6576         png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
    6677         break;
    67       case PNG_CRC_WARN_DISCARD:                      /* warn/discard data */
     78
     79      case PNG_CRC_WARN_DISCARD:                      /* Warn/discard data */
     80
    6881      case PNG_CRC_DEFAULT:
    6982      default:
     
    7588#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
    7689    defined(PNG_FLOATING_POINT_SUPPORTED)
    77 /* handle alpha and tRNS via a background color */
     90/* Handle alpha and tRNS via a background color */
    7891void PNGAPI
    7992png_set_background(png_structp png_ptr,
     
    8194   int need_expand, double background_gamma)
    8295{
    83    png_debug(1, "in png_set_background\n");
    84    if(png_ptr == NULL) return;
     96   png_debug(1, "in png_set_background");
     97   if (png_ptr == NULL)
     98      return;
    8599   if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
    86100   {
     
    99113
    100114#if defined(PNG_READ_16_TO_8_SUPPORTED)
    101 /* strip 16 bit depth files to 8 bit depth */
     115/* Strip 16 bit depth files to 8 bit depth */
    102116void PNGAPI
    103117png_set_strip_16(png_structp png_ptr)
    104118{
    105    png_debug(1, "in png_set_strip_16\n");
    106    if(png_ptr == NULL) return;
     119   png_debug(1, "in png_set_strip_16");
     120   if (png_ptr == NULL)
     121      return;
    107122   png_ptr->transformations |= PNG_16_TO_8;
    108123}
     
    113128png_set_strip_alpha(png_structp png_ptr)
    114129{
    115    png_debug(1, "in png_set_strip_alpha\n");
    116    if(png_ptr == NULL) return;
     130   png_debug(1, "in png_set_strip_alpha");
     131   if (png_ptr == NULL)
     132      return;
    117133   png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
    118134}
     
    143159   int full_dither)
    144160{
    145    png_debug(1, "in png_set_dither\n");
    146    if(png_ptr == NULL) return;
     161   png_debug(1, "in png_set_dither");
     162   if (png_ptr == NULL)
     163      return;
    147164   png_ptr->transformations |= PNG_DITHER;
    148165
     
    152169
    153170      png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
    154          (png_uint_32)(num_palette * png_sizeof (png_byte)));
     171         (png_uint_32)(num_palette * png_sizeof(png_byte)));
    155172      for (i = 0; i < num_palette; i++)
    156173         png_ptr->dither_index[i] = (png_byte)i;
     
    162179      {
    163180         /* This is easy enough, just throw out the least used colors.
    164             Perhaps not the best solution, but good enough. */
     181          * Perhaps not the best solution, but good enough.
     182          */
    165183
    166184         int i;
    167185
    168          /* initialize an array to sort colors */
     186         /* Initialize an array to sort colors */
    169187         png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
    170             (png_uint_32)(num_palette * png_sizeof (png_byte)));
    171 
    172          /* initialize the dither_sort array */
     188            (png_uint_32)(num_palette * png_sizeof(png_byte)));
     189
     190         /* Initialize the dither_sort array */
    173191         for (i = 0; i < num_palette; i++)
    174192            png_ptr->dither_sort[i] = (png_byte)i;
    175193
    176194         /* Find the least used palette entries by starting a
    177             bubble sort, and running it until we have sorted
    178             out enough colors.  Note that we don't care about
    179             sorting all the colors, just finding which are
    180             least used. */
     195          * bubble sort, and running it until we have sorted
     196          * out enough colors.  Note that we don't care about
     197          * sorting all the colors, just finding which are
     198          * least used.
     199          */
    181200
    182201         for (i = num_palette - 1; i >= maximum_colors; i--)
    183202         {
    184             int done; /* to stop early if the list is pre-sorted */
     203            int done; /* To stop early if the list is pre-sorted */
    185204            int j;
    186205
     
    203222         }
    204223
    205          /* swap the palette around, and set up a table, if necessary */
     224         /* Swap the palette around, and set up a table, if necessary */
    206225         if (full_dither)
    207226         {
    208227            int j = num_palette;
    209228
    210             /* put all the useful colors within the max, but don't
    211                move the others */
     229            /* Put all the useful colors within the max, but don't
     230             * move the others.
     231             */
    212232            for (i = 0; i < maximum_colors; i++)
    213233            {
     
    225245            int j = num_palette;
    226246
    227             /* move all the used colors inside the max limit, and
    228                develop a translation table */
     247            /* Move all the used colors inside the max limit, and
     248             * develop a translation table.
     249             */
    229250            for (i = 0; i < maximum_colors; i++)
    230251            {
    231                /* only move the colors we need to */
     252               /* Only move the colors we need to */
    232253               if ((int)png_ptr->dither_sort[i] >= maximum_colors)
    233254               {
     
    241262                  palette[j] = palette[i];
    242263                  palette[i] = tmp_color;
    243                   /* indicate where the color went */
     264                  /* Indicate where the color went */
    244265                  png_ptr->dither_index[j] = (png_byte)i;
    245266                  png_ptr->dither_index[i] = (png_byte)j;
     
    247268            }
    248269
    249             /* find closest color for those colors we are not using */
     270            /* Find closest color for those colors we are not using */
    250271            for (i = 0; i < num_palette; i++)
    251272            {
     
    254275                  int min_d, k, min_k, d_index;
    255276
    256                   /* find the closest color to one we threw out */
     277                  /* Find the closest color to one we threw out */
    257278                  d_index = png_ptr->dither_index[i];
    258279                  min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
     
    269290                     }
    270291                  }
    271                   /* point to closest color */
     292                  /* Point to closest color */
    272293                  png_ptr->dither_index[i] = (png_byte)min_k;
    273294               }
     
    275296         }
    276297         png_free(png_ptr, png_ptr->dither_sort);
    277          png_ptr->dither_sort=NULL;
     298         png_ptr->dither_sort = NULL;
    278299      }
    279300      else
    280301      {
    281302         /* This is much harder to do simply (and quickly).  Perhaps
    282             we need to go through a median cut routine, but those
    283             don't always behave themselves with only a few colors
    284             as input.  So we will just find the closest two colors,
    285             and throw out one of them (chosen somewhat randomly).
    286             [We don't understand this at all, so if someone wants to
    287              work on improving it, be our guest - AED, GRP]
    288             */
     303          * we need to go through a median cut routine, but those
     304          * don't always behave themselves with only a few colors
     305          * as input.  So we will just find the closest two colors,
     306          * and throw out one of them (chosen somewhat randomly).
     307          * [We don't understand this at all, so if someone wants to
     308          *  work on improving it, be our guest - AED, GRP]
     309          */
    289310         int i;
    290311         int max_d;
     
    293314         png_dsortpp hash;
    294315
    295          t=NULL;
    296 
    297          /* initialize palette index arrays */
     316         t = NULL;
     317
     318         /* Initialize palette index arrays */
    298319         png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
    299             (png_uint_32)(num_palette * png_sizeof (png_byte)));
     320            (png_uint_32)(num_palette * png_sizeof(png_byte)));
    300321         png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
    301             (png_uint_32)(num_palette * png_sizeof (png_byte)));
    302 
    303          /* initialize the sort array */
     322            (png_uint_32)(num_palette * png_sizeof(png_byte)));
     323
     324         /* Initialize the sort array */
    304325         for (i = 0; i < num_palette; i++)
    305326         {
     
    309330
    310331         hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
    311             png_sizeof (png_dsortp)));
    312          for (i = 0; i < 769; i++)
    313             hash[i] = NULL;
    314 /*         png_memset(hash, 0, 769 * png_sizeof (png_dsortp)); */
     332            png_sizeof(png_dsortp)));
     333         png_memset(hash, 0, 769 * png_sizeof(png_dsortp));
    315334
    316335         num_new_palette = num_palette;
    317336
    318          /* initial wild guess at how far apart the farthest pixel
    319             pair we will be eliminating will be.  Larger
    320             numbers mean more areas will be allocated, Smaller
    321             numbers run the risk of not saving enough data, and
    322             having to do this all over again.
    323 
    324             I have not done extensive checking on this number.
    325             */
     337         /* Initial wild guess at how far apart the farthest pixel
     338          * pair we will be eliminating will be.  Larger
     339          * numbers mean more areas will be allocated, Smaller
     340          * numbers run the risk of not saving enough data, and
     341          * having to do this all over again.
     342          *
     343          * I have not done extensive checking on this number.
     344          */
    326345         max_d = 96;
    327346
     
    437456         png_free(png_ptr, png_ptr->palette_to_index);
    438457         png_free(png_ptr, png_ptr->index_to_palette);
    439          png_ptr->palette_to_index=NULL;
    440          png_ptr->index_to_palette=NULL;
     458         png_ptr->palette_to_index = NULL;
     459         png_ptr->index_to_palette = NULL;
    441460      }
    442461      num_palette = maximum_colors;
     
    458477      int num_blue = (1 << PNG_DITHER_BLUE_BITS);
    459478      png_size_t num_entries = ((png_size_t)1 << total_bits);
    460 
    461479      png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
    462          (png_uint_32)(num_entries * png_sizeof (png_byte)));
    463 
     480         (png_uint_32)(num_entries * png_sizeof(png_byte)));
    464481      png_memset(png_ptr->palette_lookup, 0, num_entries *
    465          png_sizeof (png_byte));
     482         png_sizeof(png_byte));
    466483
    467484      distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
     
    527544png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
    528545{
    529    png_debug(1, "in png_set_gamma\n");
    530    if(png_ptr == NULL) return;
     546   png_debug(1, "in png_set_gamma");
     547   if (png_ptr == NULL)
     548      return;
    531549   if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
    532550       (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
     
    546564png_set_expand(png_structp png_ptr)
    547565{
    548    png_debug(1, "in png_set_expand\n");
    549    if(png_ptr == NULL) return;
     566   png_debug(1, "in png_set_expand");
     567   if (png_ptr == NULL)
     568      return;
    550569   png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
    551570   png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
     
    573592png_set_palette_to_rgb(png_structp png_ptr)
    574593{
    575    png_debug(1, "in png_set_palette_to_rgb\n");
    576    if(png_ptr == NULL) return;
     594   png_debug(1, "in png_set_palette_to_rgb");
     595   if (png_ptr == NULL)
     596      return;
    577597   png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
    578598   png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
     
    584604png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
    585605{
    586    png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
    587    if(png_ptr == NULL) return;
     606   png_debug(1, "in png_set_expand_gray_1_2_4_to_8");
     607   if (png_ptr == NULL)
     608      return;
    588609   png_ptr->transformations |= PNG_EXPAND;
    589610   png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
     
    597618png_set_gray_1_2_4_to_8(png_structp png_ptr)
    598619{
    599    png_debug(1, "in png_set_gray_1_2_4_to_8\n");
    600    if(png_ptr == NULL) return;
     620   png_debug(1, "in png_set_gray_1_2_4_to_8");
     621   if (png_ptr == NULL)
     622      return;
    601623   png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
    602624}
     
    608630png_set_tRNS_to_alpha(png_structp png_ptr)
    609631{
    610    png_debug(1, "in png_set_tRNS_to_alpha\n");
     632   png_debug(1, "in png_set_tRNS_to_alpha");
    611633   png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
    612634   png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
     
    618640png_set_gray_to_rgb(png_structp png_ptr)
    619641{
    620    png_debug(1, "in png_set_gray_to_rgb\n");
     642   png_debug(1, "in png_set_gray_to_rgb");
    621643   png_ptr->transformations |= PNG_GRAY_TO_RGB;
    622644   png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
     
    634656   double green)
    635657{
    636       int red_fixed = (int)((float)red*100000.0 + 0.5);
    637       int green_fixed = (int)((float)green*100000.0 + 0.5);
    638       if(png_ptr == NULL) return;
    639       png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
     658   int red_fixed = (int)((float)red*100000.0 + 0.5);
     659   int green_fixed = (int)((float)green*100000.0 + 0.5);
     660   if (png_ptr == NULL)
     661      return;
     662   png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
    640663}
    641664#endif
     
    645668   png_fixed_point red, png_fixed_point green)
    646669{
    647    png_debug(1, "in png_set_rgb_to_gray\n");
    648    if(png_ptr == NULL) return;
     670   png_debug(1, "in png_set_rgb_to_gray");
     671   if (png_ptr == NULL)
     672      return;
    649673   switch(error_action)
    650674   {
    651675      case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
    652676              break;
     677
    653678      case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
    654679              break;
     680
    655681      case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
    656682   }
     
    660686#else
    661687   {
    662       png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
     688      png_warning(png_ptr,
     689        "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
    663690      png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
    664691   }
     
    666693   {
    667694      png_uint_16 red_int, green_int;
    668       if(red < 0 || green < 0)
     695      if (red < 0 || green < 0)
    669696      {
    670697         red_int   =  6968; /* .212671 * 32768 + .5 */
    671698         green_int = 23434; /* .715160 * 32768 + .5 */
    672699      }
    673       else if(red + green < 100000L)
    674       {
    675         red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
    676         green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
     700      else if (red + green < 100000L)
     701      {
     702         red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
     703         green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
    677704      }
    678705      else
     
    684711      png_ptr->rgb_to_gray_red_coeff   = red_int;
    685712      png_ptr->rgb_to_gray_green_coeff = green_int;
    686       png_ptr->rgb_to_gray_blue_coeff  = (png_uint_16)(32768-red_int-green_int);
     713      png_ptr->rgb_to_gray_blue_coeff  =
     714         (png_uint_16)(32768 - red_int - green_int);
    687715   }
    688716}
     
    690718
    691719#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
    692     defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
    693     defined(PNG_LEGACY_SUPPORTED)
     720    defined(PNG_LEGACY_SUPPORTED) || \
     721    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
    694722void PNGAPI
    695723png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
    696724   read_user_transform_fn)
    697725{
    698    png_debug(1, "in png_set_read_user_transform_fn\n");
    699    if(png_ptr == NULL) return;
     726   png_debug(1, "in png_set_read_user_transform_fn");
     727   if (png_ptr == NULL)
     728      return;
    700729#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
    701730   png_ptr->transformations |= PNG_USER_TRANSFORM;
     
    703732#endif
    704733#ifdef PNG_LEGACY_SUPPORTED
    705    if(read_user_transform_fn)
     734   if (read_user_transform_fn)
    706735      png_warning(png_ptr,
    707736        "This version of libpng does not support user transforms");
     
    716745png_init_read_transformations(png_structp png_ptr)
    717746{
    718    png_debug(1, "in png_init_read_transformations\n");
     747   png_debug(1, "in png_init_read_transformations");
    719748#if defined(PNG_USELESS_TESTS_SUPPORTED)
    720    if(png_ptr != NULL)
     749   if (png_ptr != NULL)
    721750#endif
    722751  {
     
    730759#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
    731760   /* Detect gray background and attempt to enable optimization
    732     * for gray --> RGB case */
    733    /* Note:  if PNG_BACKGROUND_EXPAND is set and color_type is either RGB or
     761    * for gray --> RGB case
     762    *
     763    * Note:  if PNG_BACKGROUND_EXPAND is set and color_type is either RGB or
    734764    * RGB_ALPHA (in which case need_expand is superfluous anyway), the
    735765    * background color might actually be gray yet not be flagged as such.
     
    758788      if (!(color_type & PNG_COLOR_MASK_COLOR))  /* i.e., GRAY or GRAY_ALPHA */
    759789      {
    760          /* expand background and tRNS chunks */
     790         /* Expand background and tRNS chunks */
    761791         switch (png_ptr->bit_depth)
    762792         {
     
    772802               }
    773803               break;
     804
    774805            case 2:
    775806               png_ptr->background.gray *= (png_uint_16)0x55;
     
    783814               }
    784815               break;
     816
    785817            case 4:
    786818               png_ptr->background.gray *= (png_uint_16)0x11;
     
    794826               }
    795827               break;
     828
    796829            case 8:
     830
    797831            case 16:
    798832               png_ptr->background.red = png_ptr->background.green
     
    817851#endif
    818852           {
    819            /* invert the alpha channel (in tRNS) unless the pixels are
    820               going to be expanded, in which case leave it for later */
    821               int i,istop;
     853           /* Invert the alpha channel (in tRNS) unless the pixels are
     854            * going to be expanded, in which case leave it for later
     855            */
     856              int i, istop;
    822857              istop=(int)png_ptr->num_trans;
    823858              for (i=0; i<istop; i++)
     
    840875         < PNG_GAMMA_THRESHOLD))
    841876   {
    842     int i,k;
     877    int i, k;
    843878    k=0;
    844879    for (i=0; i<png_ptr->num_trans; i++)
    845880    {
    846881      if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
    847         k=1; /* partial transparency is present */
     882        k=1; /* Partial transparency is present */
    848883    }
    849884    if (k == 0)
     
    860895         if (color_type == PNG_COLOR_TYPE_PALETTE)
    861896         {
    862            /* could skip if no transparency and
    863            */
     897           /* Could skip if no transparency */
    864898            png_color back, back_1;
    865899            png_colorp palette = png_ptr->palette;
     
    886920                     gs = 1.0;
    887921                     break;
     922
    888923                  case PNG_BACKGROUND_GAMMA_FILE:
    889924                     g = 1.0 / (png_ptr->gamma);
    890925                     gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
    891926                     break;
     927
    892928                  case PNG_BACKGROUND_GAMMA_UNIQUE:
    893929                     g = 1.0 / (png_ptr->background_gamma);
     
    9781014                  gs = 1.0;
    9791015                  break;
     1016
    9801017               case PNG_BACKGROUND_GAMMA_FILE:
    9811018                  g = 1.0 / (png_ptr->gamma);
    9821019                  gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
    9831020                  break;
     1021
    9841022               case PNG_BACKGROUND_GAMMA_UNIQUE:
    9851023                  g = 1.0 / (png_ptr->background_gamma);
     
    10231061      }
    10241062      else
    1025       /* transformation does not include PNG_BACKGROUND */
     1063      /* Transformation does not include PNG_BACKGROUND */
    10261064#endif /* PNG_READ_BACKGROUND_SUPPORTED */
    10271065      if (color_type == PNG_COLOR_TYPE_PALETTE)
     
    11111149#if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
    11121150 && !defined(PNG_READ_BACKGROUND_SUPPORTED)
    1113    if(png_ptr)
     1151   if (png_ptr)
    11141152      return;
    11151153#endif
     
    11231161png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
    11241162{
    1125    png_debug(1, "in png_read_transform_info\n");
     1163   png_debug(1, "in png_read_transform_info");
    11261164#if defined(PNG_READ_EXPAND_SUPPORTED)
    11271165   if (png_ptr->transformations & PNG_EXPAND)
     
    11431181            if (png_ptr->transformations & PNG_EXPAND_tRNS)
    11441182              info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
    1145 #if 0 /* Removed from libpng-1.2.27 */
    1146             else
    1147               info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
    1148 #endif
    11491183         }
    11501184         if (info_ptr->bit_depth < 8)
     
    11951229   {
    11961230      if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
    1197          (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
    1198          png_ptr->palette_lookup && info_ptr->bit_depth == 8)
     1231          (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
     1232          png_ptr->palette_lookup && info_ptr->bit_depth == 8)
    11991233      {
    12001234         info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
     
    12301264   {
    12311265      info_ptr->channels++;
    1232       /* if adding a true alpha channel not just filler */
     1266      /* If adding a true alpha channel not just filler */
    12331267#if !defined(PNG_1_0_X)
    12341268      if (png_ptr->transformations & PNG_ADD_ALPHA)
     
    12401274#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
    12411275defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
    1242    if(png_ptr->transformations & PNG_USER_TRANSFORM)
     1276   if (png_ptr->transformations & PNG_USER_TRANSFORM)
    12431277     {
    1244        if(info_ptr->bit_depth < png_ptr->user_transform_depth)
     1278       if (info_ptr->bit_depth < png_ptr->user_transform_depth)
    12451279         info_ptr->bit_depth = png_ptr->user_transform_depth;
    1246        if(info_ptr->channels < png_ptr->user_transform_channels)
     1280       if (info_ptr->channels < png_ptr->user_transform_channels)
    12471281         info_ptr->channels = png_ptr->user_transform_channels;
    12481282     }
     
    12521286      info_ptr->bit_depth);
    12531287
    1254    info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
     1288   info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, info_ptr->width);
    12551289
    12561290#if !defined(PNG_READ_EXPAND_SUPPORTED)
    1257    if(png_ptr)
     1291   if (png_ptr)
    12581292      return;
    12591293#endif
     
    12671301png_do_read_transformations(png_structp png_ptr)
    12681302{
    1269    png_debug(1, "in png_do_read_transformations\n");
     1303   png_debug(1, "in png_do_read_transformations");
    12701304   if (png_ptr->row_buf == NULL)
    12711305   {
     
    12741308
    12751309      png_snprintf2(msg, 50,
    1276          "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
     1310         "NULL row buffer for row %ld, pass %d", (long)png_ptr->row_number,
    12771311         png_ptr->pass);
    12781312      png_error(png_ptr, msg);
     
    12851319      /* Application has failed to call either png_read_start_image()
    12861320       * or png_read_update_info() after setting transforms that expand
    1287        * pixels.  This check added to libpng-1.2.19 */
     1321       * pixels.  This check added to libpng-1.2.19
     1322       */
    12881323#if (PNG_WARN_UNINITIALIZED_ROW==1)
    12891324      png_error(png_ptr, "Uninitialized row");
     
    13251360      int rgb_error =
    13261361         png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
    1327       if(rgb_error)
     1362      if (rgb_error)
    13281363      {
    13291364         png_ptr->rgb_to_gray_status=1;
    1330          if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
     1365         if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
    13311366             PNG_RGB_TO_GRAY_WARN)
    13321367            png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
    1333          if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
     1368         if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
    13341369             PNG_RGB_TO_GRAY_ERR)
    13351370            png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
     
    13381373#endif
    13391374
    1340 /*
    1341 From Andreas Dilger e-mail to png-implement, 26 March 1998:
    1342 
    1343   In most cases, the "simple transparency" should be done prior to doing
    1344   gray-to-RGB, or you will have to test 3x as many bytes to check if a
    1345   pixel is transparent.  You would also need to make sure that the
    1346   transparency information is upgraded to RGB.
    1347 
    1348   To summarize, the current flow is:
    1349   - Gray + simple transparency -> compare 1 or 2 gray bytes and composite
    1350                                   with background "in place" if transparent,
    1351                                   convert to RGB if necessary
    1352   - Gray + alpha -> composite with gray background and remove alpha bytes,
    1353                                   convert to RGB if necessary
    1354 
    1355   To support RGB backgrounds for gray images we need:
    1356   - Gray + simple transparency -> convert to RGB + simple transparency, compare
    1357                                   3 or 6 bytes and composite with background
    1358                                   "in place" if transparent (3x compare/pixel
    1359                                   compared to doing composite with gray bkgrnd)
    1360   - Gray + alpha -> convert to RGB + alpha, composite with background and
    1361                                   remove alpha bytes (3x float operations/pixel
    1362                                   compared with composite on gray background)
    1363 
    1364   Greg's change will do this.  The reason it wasn't done before is for
    1365   performance, as this increases the per-pixel operations.  If we would check
    1366   in advance if the background was gray or RGB, and position the gray-to-RGB
    1367   transform appropriately, then it would save a lot of work/time.
     1375/* From Andreas Dilger e-mail to png-implement, 26 March 1998:
     1376 *
     1377 *   In most cases, the "simple transparency" should be done prior to doing
     1378 *   gray-to-RGB, or you will have to test 3x as many bytes to check if a
     1379 *   pixel is transparent.  You would also need to make sure that the
     1380 *   transparency information is upgraded to RGB.
     1381 *
     1382 *   To summarize, the current flow is:
     1383 *   - Gray + simple transparency -> compare 1 or 2 gray bytes and composite
     1384 *                                   with background "in place" if transparent,
     1385 *                                   convert to RGB if necessary
     1386 *   - Gray + alpha -> composite with gray background and remove alpha bytes,
     1387 *                                   convert to RGB if necessary
     1388 *
     1389 *   To support RGB backgrounds for gray images we need:
     1390 *   - Gray + simple transparency -> convert to RGB + simple transparency,
     1391 *                                   compare 3 or 6 bytes and composite with
     1392 *                                   background "in place" if transparent
     1393 *                                   (3x compare/pixel compared to doing
     1394 *                                   composite with gray bkgrnd)
     1395 *   - Gray + alpha -> convert to RGB + alpha, composite with background and
     1396 *                                   remove alpha bytes (3x float
     1397 *                                   operations/pixel compared with composite
     1398 *                                   on gray background)
     1399 *
     1400 *  Greg's change will do this.  The reason it wasn't done before is for
     1401 *  performance, as this increases the per-pixel operations.  If we would check
     1402 *  in advance if the background was gray or RGB, and position the gray-to-RGB
     1403 *  transform appropriately, then it would save a lot of work/time.
    13681404 */
    13691405
    13701406#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
    1371    /* if gray -> RGB, do so now only if background is non-gray; else do later
    1372     * for performance reasons */
     1407   /* If gray -> RGB, do so now only if background is non-gray; else do later
     1408    * for performance reasons
     1409    */
    13731410   if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
    13741411       !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
     
    13951432   if ((png_ptr->transformations & PNG_GAMMA) &&
    13961433#if defined(PNG_READ_BACKGROUND_SUPPORTED)
    1397       !((png_ptr->transformations & PNG_BACKGROUND) &&
    1398       ((png_ptr->num_trans != 0) ||
    1399       (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
    1400 #endif
    1401       (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
     1434       !((png_ptr->transformations & PNG_BACKGROUND) &&
     1435       ((png_ptr->num_trans != 0) ||
     1436       (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
     1437#endif
     1438       (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
    14021439      png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
    1403          png_ptr->gamma_table, png_ptr->gamma_16_table,
    1404          png_ptr->gamma_shift);
     1440          png_ptr->gamma_table, png_ptr->gamma_16_table,
     1441          png_ptr->gamma_shift);
    14051442#endif
    14061443
     
    14151452      png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
    14161453         png_ptr->palette_lookup, png_ptr->dither_index);
    1417       if(png_ptr->row_info.rowbytes == (png_uint_32)0)
     1454      if (png_ptr->row_info.rowbytes == (png_uint_32)0)
    14181455         png_error(png_ptr, "png_do_dither returned rowbytes=0");
    14191456   }
     
    14471484
    14481485#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
    1449    /* if gray -> RGB, do so now only if we did not do so above */
     1486   /* If gray -> RGB, do so now only if we did not do so above */
    14501487   if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
    14511488       (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
     
    14771514   if (png_ptr->transformations & PNG_USER_TRANSFORM)
    14781515    {
    1479       if(png_ptr->read_user_transform_fn != NULL)
    1480         (*(png_ptr->read_user_transform_fn)) /* user read transform function */
    1481           (png_ptr,                    /* png_ptr */
    1482            &(png_ptr->row_info),       /* row_info:    */
    1483              /*  png_uint_32 width;          width of row */
    1484              /*  png_uint_32 rowbytes;       number of bytes in row */
    1485              /*  png_byte color_type;        color type of pixels */
    1486              /*  png_byte bit_depth;         bit depth of samples */
    1487              /*  png_byte channels;          number of channels (1-4) */
    1488              /*  png_byte pixel_depth;       bits per pixel (depth*channels) */
    1489            png_ptr->row_buf + 1);      /* start of pixel data for row */
     1516      if (png_ptr->read_user_transform_fn != NULL)
     1517         (*(png_ptr->read_user_transform_fn)) /* User read transform function */
     1518            (png_ptr,                    /* png_ptr */
     1519               &(png_ptr->row_info),     /* row_info: */
     1520               /*  png_uint_32 width;       width of row */
     1521               /*  png_uint_32 rowbytes;    number of bytes in row */
     1522               /*  png_byte color_type;     color type of pixels */
     1523               /*  png_byte bit_depth;      bit depth of samples */
     1524               /*  png_byte channels;       number of channels (1-4) */
     1525               /*  png_byte pixel_depth;    bits per pixel (depth*channels) */
     1526               png_ptr->row_buf + 1);    /* start of pixel data for row */
    14901527#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
    1491       if(png_ptr->user_transform_depth)
     1528      if (png_ptr->user_transform_depth)
    14921529         png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
    1493       if(png_ptr->user_transform_channels)
     1530      if (png_ptr->user_transform_channels)
    14941531         png_ptr->row_info.channels = png_ptr->user_transform_channels;
    14951532#endif
     
    15131550png_do_unpack(png_row_infop row_info, png_bytep row)
    15141551{
    1515    png_debug(1, "in png_do_unpack\n");
     1552   png_debug(1, "in png_do_unpack");
    15161553#if defined(PNG_USELESS_TESTS_SUPPORTED)
    15171554   if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
     
    15451582            break;
    15461583         }
     1584
    15471585         case 2:
    15481586         {
     
    15661604            break;
    15671605         }
     1606
    15681607         case 4:
    15691608         {
     
    16031642png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
    16041643{
    1605    png_debug(1, "in png_do_unshift\n");
     1644   png_debug(1, "in png_do_unshift");
    16061645   if (
    16071646#if defined(PNG_USELESS_TESTS_SUPPORTED)
     
    16571696            break;
    16581697         }
     1698
    16591699         case 4:
    16601700         {
     
    16721712            break;
    16731713         }
     1714
    16741715         case 8:
    16751716         {
     
    16841725            break;
    16851726         }
     1727
    16861728         case 16:
    16871729         {
     
    17051747
    17061748#if defined(PNG_READ_16_TO_8_SUPPORTED)
    1707 /* chop rows of bit depth 16 down to 8 */
     1749/* Chop rows of bit depth 16 down to 8 */
    17081750void /* PRIVATE */
    17091751png_do_chop(png_row_infop row_info, png_bytep row)
    17101752{
    1711    png_debug(1, "in png_do_chop\n");
     1753   png_debug(1, "in png_do_chop");
    17121754#if defined(PNG_USELESS_TESTS_SUPPORTED)
    17131755   if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
     
    17291771       * What the ideal calculation should be:
    17301772       *   *dp = (((((png_uint_32)(*sp) << 8) |
    1731        *          (png_uint_32)(*(sp + 1))) * 255 + 127) / (png_uint_32)65535L;
     1773       *          (png_uint_32)(*(sp + 1))) * 255 + 127)
     1774       *          / (png_uint_32)65535L;
    17321775       *
    17331776       * GRR: no, I think this is what it really should be:
    17341777       *   *dp = (((((png_uint_32)(*sp) << 8) |
    1735        *           (png_uint_32)(*(sp + 1))) + 128L) / (png_uint_32)257L;
     1778       *           (png_uint_32)(*(sp + 1))) + 128L)
     1779       *           / (png_uint_32)257L;
    17361780       *
    17371781       * GRR: here's the exact calculation with shifts:
    1738        *   temp = (((png_uint_32)(*sp) << 8) | (png_uint_32)(*(sp + 1))) + 128L;
     1782       *   temp = (((png_uint_32)(*sp) << 8) |
     1783       *           (png_uint_32)(*(sp + 1))) + 128L;
    17391784       *   *dp = (temp - (temp >> 8)) >> 8;
    17401785       *
     
    17631808png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
    17641809{
    1765    png_debug(1, "in png_do_read_swap_alpha\n");
     1810   png_debug(1, "in png_do_read_swap_alpha");
    17661811#if defined(PNG_USELESS_TESTS_SUPPORTED)
    17671812   if (row != NULL && row_info != NULL)
     
    18551900png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
    18561901{
    1857    png_debug(1, "in png_do_read_invert_alpha\n");
     1902   png_debug(1, "in png_do_read_invert_alpha");
    18581903#if defined(PNG_USELESS_TESTS_SUPPORTED)
    18591904   if (row != NULL && row_info != NULL)
     
    19612006   png_byte lo_filler = (png_byte)(filler & 0xff);
    19622007
    1963    png_debug(1, "in png_do_read_filler\n");
     2008   png_debug(1, "in png_do_read_filler");
    19642009   if (
    19652010#if defined(PNG_USELESS_TESTS_SUPPORTED)
     
    19682013       row_info->color_type == PNG_COLOR_TYPE_GRAY)
    19692014   {
    1970       if(row_info->bit_depth == 8)
     2015      if (row_info->bit_depth == 8)
    19712016      {
    19722017         /* This changes the data from G to GX */
     
    20002045         }
    20012046      }
    2002       else if(row_info->bit_depth == 16)
     2047      else if (row_info->bit_depth == 16)
    20032048      {
    20042049         /* This changes the data from GG to GGXX */
     
    20402085   else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
    20412086   {
    2042       if(row_info->bit_depth == 8)
     2087      if (row_info->bit_depth == 8)
    20432088      {
    20442089         /* This changes the data from RGB to RGBX */
     
    20762121         }
    20772122      }
    2078       else if(row_info->bit_depth == 16)
     2123      else if (row_info->bit_depth == 16)
    20792124      {
    20802125         /* This changes the data from RRGGBB to RRGGBBXX */
     
    21262171
    21272172#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
    2128 /* expand grayscale files to RGB, with or without alpha */
     2173/* Expand grayscale files to RGB, with or without alpha */
    21292174void /* PRIVATE */
    21302175png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
     
    21332178   png_uint_32 row_width = row_info->width;
    21342179
    2135    png_debug(1, "in png_do_gray_to_rgb\n");
     2180   png_debug(1, "in png_do_gray_to_rgb");
    21362181   if (row_info->bit_depth >= 8 &&
    21372182#if defined(PNG_USELESS_TESTS_SUPPORTED)
     
    22032248      row_info->pixel_depth = (png_byte)(row_info->channels *
    22042249         row_info->bit_depth);
    2205       row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
     2250      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
    22062251   }
    22072252}
     
    22092254
    22102255#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
    2211 /* reduce RGB files to grayscale, with or without alpha
     2256/* Reduce RGB files to grayscale, with or without alpha
    22122257 * using the equation given in Poynton's ColorFAQ at
    2213  * <http://www.inforamp.net/~poynton/>
    2214  * Copyright (c) 1998-01-04 Charles Poynton poynton at inforamp.net
     2258 * <http://www.inforamp.net/~poynton/>  (THIS LINK IS DEAD June 2008)
     2259 * New link:
     2260 * <http://www.poynton.com/notes/colour_and_gamma/>
     2261 * Charles Poynton poynton at poynton.com
    22152262 *
    22162263 *     Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
     
    22372284   int rgb_error = 0;
    22382285
    2239    png_debug(1, "in png_do_rgb_to_gray\n");
     2286   png_debug(1, "in png_do_rgb_to_gray");
    22402287   if (
    22412288#if defined(PNG_USELESS_TESTS_SUPPORTED)
     
    22632310                  png_byte green = png_ptr->gamma_to_1[*(sp++)];
    22642311                  png_byte blue  = png_ptr->gamma_to_1[*(sp++)];
    2265                   if(red != green || red != blue)
     2312                  if (red != green || red != blue)
    22662313                  {
    22672314                     rgb_error |= 1;
    22682315                     *(dp++) = png_ptr->gamma_from_1[
    2269                        (rc*red+gc*green+bc*blue)>>15];
     2316                       (rc*red + gc*green + bc*blue)>>15];
    22702317                  }
    22712318                  else
    2272                      *(dp++) = *(sp-1);
     2319                     *(dp++) = *(sp - 1);
    22732320               }
    22742321            }
     
    22832330                  png_byte green = *(sp++);
    22842331                  png_byte blue  = *(sp++);
    2285                   if(red != green || red != blue)
     2332                  if (red != green || red != blue)
    22862333                  {
    22872334                     rgb_error |= 1;
    2288                      *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
     2335                     *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
    22892336                  }
    22902337                  else
    2291                      *(dp++) = *(sp-1);
     2338                     *(dp++) = *(sp - 1);
    22922339               }
    22932340            }
     
    23102357                  blue  = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
    23112358
    2312                   if(red == green && red == blue)
     2359                  if (red == green && red == blue)
    23132360                     w = red;
    23142361                  else
     
    23442391                  blue  = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
    23452392
    2346                   if(red != green || red != blue)
     2393                  if (red != green || red != blue)
    23472394                     rgb_error |= 1;
    23482395                  gray16  = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
     
    23672414                  png_byte green = png_ptr->gamma_to_1[*(sp++)];
    23682415                  png_byte blue  = png_ptr->gamma_to_1[*(sp++)];
    2369                   if(red != green || red != blue)
     2416                  if (red != green || red != blue)
    23702417                     rgb_error |= 1;
    23712418                  *(dp++) =  png_ptr->gamma_from_1
     
    23842431                  png_byte green = *(sp++);
    23852432                  png_byte blue  = *(sp++);
    2386                   if(red != green || red != blue)
     2433                  if (red != green || red != blue)
    23872434                     rgb_error |= 1;
    23882435                  *(dp++) =  (png_byte)((rc*red + gc*green + bc*blue)>>15);
     
    24072454                  blue  = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
    24082455
    2409                   if(red == green && red == blue)
     2456                  if (red == green && red == blue)
    24102457                     w = red;
    24112458                  else
     
    24412488                  green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
    24422489                  blue  = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
    2443                   if(red != green || red != blue)
     2490                  if (red != green || red != blue)
    24442491                     rgb_error |= 1;
    24452492                  gray16  = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
     
    24562503      row_info->pixel_depth = (png_byte)(row_info->channels *
    24572504         row_info->bit_depth);
    2458       row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
     2505      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
    24592506   }
    24602507   return rgb_error;
     
    24752522   int v;
    24762523
    2477    png_debug(1, "in png_do_build_grayscale_palette\n");
     2524   png_debug(1, "in png_do_build_grayscale_palette");
    24782525   if (palette == NULL)
    24792526      return;
     
    24852532         color_inc = 0xff;
    24862533         break;
     2534
    24872535      case 2:
    24882536         num_palette = 4;
    24892537         color_inc = 0x55;
    24902538         break;
     2539
    24912540      case 4:
    24922541         num_palette = 16;
    24932542         color_inc = 0x11;
    24942543         break;
     2544
    24952545      case 8:
    24962546         num_palette = 256;
    24972547         color_inc = 1;
    24982548         break;
     2549
    24992550      default:
    25002551         num_palette = 0;
     
    25172568   int num_palette)
    25182569{
    2519    png_debug(1, "in png_correct_palette\n");
     2570   png_debug(1, "in png_correct_palette");
    25202571#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
    25212572    defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
     
    26742725         }
    26752726      }
    2676       else /* assume grayscale palette (what else could it be?) */
     2727      else /* Assume grayscale palette (what else could it be?) */
    26772728      {
    26782729         int i;
     
    27142765   int shift;
    27152766
    2716    png_debug(1, "in png_do_background\n");
     2767   png_debug(1, "in png_do_background");
    27172768   if (background != NULL &&
    27182769#if defined(PNG_USELESS_TESTS_SUPPORTED)
     
    27502801                  break;
    27512802               }
     2803
    27522804               case 2:
    27532805               {
     
    28062858                  break;
    28072859               }
     2860
    28082861               case 4:
    28092862               {
     
    28622915                  break;
    28632916               }
     2917
    28642918               case 8:
    28652919               {
     
    28942948                  break;
    28952949               }
     2950
    28962951               case 16:
    28972952               {
     
    29072962                        if (v == trans_values->gray)
    29082963                        {
    2909                            /* background is already in screen gamma */
     2964                           /* Background is already in screen gamma */
    29102965                           *sp = (png_byte)((background->gray >> 8) & 0xff);
    29112966                           *(sp + 1) = (png_byte)(background->gray & 0xff);
     
    29402995            break;
    29412996         }
     2997
    29422998         case PNG_COLOR_TYPE_RGB:
    29432999         {
     
    29973053                        b == trans_values->blue)
    29983054                     {
    2999                         /* background is already in screen gamma */
     3055                        /* Background is already in screen gamma */
    30003056                        *sp = (png_byte)((background->red >> 8) & 0xff);
    30013057                        *(sp + 1) = (png_byte)(background->red & 0xff);
     
    30443100            break;
    30453101         }
     3102
    30463103         case PNG_COLOR_TYPE_GRAY_ALPHA:
    30473104         {
     
    30643121                     else if (a == 0)
    30653122                     {
    3066                         /* background is already in screen gamma */
     3123                        /* Background is already in screen gamma */
    30673124                        *dp = (png_byte)background->gray;
    30683125                     }
     
    31313188#endif
    31323189                     {
    3133                         /* background is already in screen gamma */
     3190                        /* Background is already in screen gamma */
    31343191                        *dp = (png_byte)((background->gray >> 8) & 0xff);
    31353192                        *(dp + 1) = (png_byte)(background->gray & 0xff);
     
    31863243            break;
    31873244         }
     3245
    31883246         case PNG_COLOR_TYPE_RGB_ALPHA:
    31893247         {
     
    32083266                     else if (a == 0)
    32093267                     {
    3210                         /* background is already in screen gamma */
     3268                        /* Background is already in screen gamma */
    32113269                        *dp = (png_byte)background->red;
    32123270                        *(dp + 1) = (png_byte)background->green;
     
    32893347                     else if (a == 0)
    32903348                     {
    3291                         /* background is already in screen gamma */
     3349                        /* Background is already in screen gamma */
    32923350                        *dp = (png_byte)((background->red >> 8) & 0xff);
    32933351                        *(dp + 1) = (png_byte)(background->red & 0xff);
     
    33743432         row_info->pixel_depth = (png_byte)(row_info->channels *
    33753433            row_info->bit_depth);
    3376          row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
     3434         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
    33773435      }
    33783436   }
     
    33963454   png_uint_32 row_width=row_info->width;
    33973455
    3398    png_debug(1, "in png_do_gamma\n");
     3456   png_debug(1, "in png_do_gamma");
    33993457   if (
    34003458#if defined(PNG_USELESS_TESTS_SUPPORTED)
     
    34443502            break;
    34453503         }
     3504
    34463505         case PNG_COLOR_TYPE_RGB_ALPHA:
    34473506         {
     
    34813540            break;
    34823541         }
     3542
    34833543         case PNG_COLOR_TYPE_GRAY_ALPHA:
    34843544         {
     
    35053565            break;
    35063566         }
     3567
    35073568         case PNG_COLOR_TYPE_GRAY:
    35083569         {
     
    35253586               }
    35263587            }
     3588
    35273589            if (row_info->bit_depth == 4)
    35283590            {
     
    35383600               }
    35393601            }
     3602
    35403603            else if (row_info->bit_depth == 8)
    35413604            {
     
    35473610               }
    35483611            }
     3612
    35493613            else if (row_info->bit_depth == 16)
    35503614            {
     
    35783642   png_uint_32 row_width=row_info->width;
    35793643
    3580    png_debug(1, "in png_do_expand_palette\n");
     3644   png_debug(1, "in png_do_expand_palette");
    35813645   if (
    35823646#if defined(PNG_USELESS_TESTS_SUPPORTED)
     
    36123676               break;
    36133677            }
     3678
    36143679            case 2:
    36153680            {
     
    36333698               break;
    36343699            }
     3700
    36353701            case 4:
    36363702            {
     
    36973763                  sp--;
    36983764               }
     3765
    36993766               row_info->bit_depth = 8;
    37003767               row_info->pixel_depth = 24;
     
    37213788   png_uint_32 row_width=row_info->width;
    37223789
    3723    png_debug(1, "in png_do_expand\n");
     3790   png_debug(1, "in png_do_expand");
    37243791#if defined(PNG_USELESS_TESTS_SUPPORTED)
    37253792   if (row != NULL && row_info != NULL)
     
    37583825                  break;
    37593826               }
     3827
    37603828               case 2:
    37613829               {
     
    37813849                  break;
    37823850               }
     3851
    37833852               case 4:
    37843853               {
     
    38043873               }
    38053874            }
     3875
    38063876            row_info->bit_depth = 8;
    38073877            row_info->pixel_depth = 8;
     
    38253895               }
    38263896            }
     3897
    38273898            else if (row_info->bit_depth == 16)
    38283899            {
     
    38333904               for (i = 0; i < row_width; i++)
    38343905               {
    3835                   if (*(sp-1) == gray_high && *(sp) == gray_low)
     3906                  if (*(sp - 1) == gray_high && *(sp) == gray_low)
    38363907                  {
    38373908                     *dp-- = 0;
     
    38473918               }
    38483919            }
     3920
    38493921            row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
    38503922            row_info->channels = 2;
     
    39123984         row_info->channels = 4;
    39133985         row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
    3914          row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
     3986         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
    39153987      }
    39163988   }
     
    39273999   png_uint_32 row_width=row_info->width;
    39284000
    3929    png_debug(1, "in png_do_dither\n");
     4001   png_debug(1, "in png_do_dither");
    39304002#if defined(PNG_USELESS_TESTS_SUPPORTED)
    39314003   if (row != NULL && row_info != NULL)
     
    39444016            b = *sp++;
    39454017
    3946             /* this looks real messy, but the compiler will reduce
    3947                it down to a reasonable formula.  For example, with
    3948                5 bits per color, we get:
    3949                p = (((r >> 3) & 0x1f) << 10) |
    3950                   (((g >> 3) & 0x1f) << 5) |
    3951                   ((b >> 3) & 0x1f);
    3952                */
     4018            /* This looks real messy, but the compiler will reduce
     4019             * it down to a reasonable formula.  For example, with
     4020             * 5 bits per color, we get:
     4021             * p = (((r >> 3) & 0x1f) << 10) |
     4022             *    (((g >> 3) & 0x1f) << 5) |
     4023             *    ((b >> 3) & 0x1f);
     4024             */
    39534025            p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
    39544026               ((1 << PNG_DITHER_RED_BITS) - 1)) <<
     
    39654037         row_info->channels = 1;
    39664038         row_info->pixel_depth = row_info->bit_depth;
    3967          row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
     4039         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
    39684040      }
    39694041      else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
     
    39944066         row_info->channels = 1;
    39954067         row_info->pixel_depth = row_info->bit_depth;
    3996          row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
     4068         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
    39974069      }
    39984070      else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
     
    40224094png_build_gamma_table(png_structp png_ptr)
    40234095{
    4024   png_debug(1, "in png_build_gamma_table\n");
     4096  png_debug(1, "in png_build_gamma_table");
    40254097
    40264098  if (png_ptr->bit_depth <= 8)
     
    40314103     if (png_ptr->screen_gamma > .000001)
    40324104        g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
     4105
    40334106     else
    40344107        g = 1.0;
     
    40634136           (png_uint_32)256);
    40644137
    4065         if(png_ptr->screen_gamma > 0.000001)
     4138        if (png_ptr->screen_gamma > 0.000001)
    40664139           g = 1.0 / png_ptr->screen_gamma;
     4140
    40674141        else
    4068            g = png_ptr->gamma;   /* probably doing rgb_to_gray */
     4142           g = png_ptr->gamma;   /* Probably doing rgb_to_gray */
    40694143
    40704144        for (i = 0; i < 256; i++)
     
    40874161     {
    40884162        sig_bit = (int)png_ptr->sig_bit.red;
     4163
    40894164        if ((int)png_ptr->sig_bit.green > sig_bit)
    40904165           sig_bit = png_ptr->sig_bit.green;
     4166
    40914167        if ((int)png_ptr->sig_bit.blue > sig_bit)
    40924168           sig_bit = png_ptr->sig_bit.blue;
     
    40994175     if (sig_bit > 0)
    41004176        shift = 16 - sig_bit;
     4177
    41014178     else
    41024179        shift = 0;
     
    41104187     if (shift > 8)
    41114188        shift = 8;
     4189
    41124190     if (shift < 0)
    41134191        shift = 0;
     
    41234201
    41244202     png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
    4125         (png_uint_32)(num * png_sizeof (png_uint_16p)));
     4203        (png_uint_32)(num * png_sizeof(png_uint_16p)));
     4204     png_memset(png_ptr->gamma_16_table, 0, num * png_sizeof(png_uint_16p));
    41264205
    41274206     if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
     
    41334212        {
    41344213           png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
    4135               (png_uint_32)(256 * png_sizeof (png_uint_16)));
     4214              (png_uint_32)(256 * png_sizeof(png_uint_16)));
    41364215        }
    41374216
     
    41634242        {
    41644243           png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
    4165               (png_uint_32)(256 * png_sizeof (png_uint_16)));
     4244              (png_uint_32)(256 * png_sizeof(png_uint_16)));
    41664245
    41674246           ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
     4247
    41684248           for (j = 0; j < 256; j++)
    41694249           {
     
    41834263
    41844264        png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
    4185            (png_uint_32)(num * png_sizeof (png_uint_16p )));
     4265           (png_uint_32)(num * png_sizeof(png_uint_16p )));
     4266        png_memset(png_ptr->gamma_16_to_1, 0, num * png_sizeof(png_uint_16p));
    41864267
    41874268        for (i = 0; i < num; i++)
    41884269        {
    41894270           png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
    4190               (png_uint_32)(256 * png_sizeof (png_uint_16)));
     4271              (png_uint_32)(256 * png_sizeof(png_uint_16)));
    41914272
    41924273           ig = (((png_uint_32)i *
     
    42004281        }
    42014282
    4202         if(png_ptr->screen_gamma > 0.000001)
     4283        if (png_ptr->screen_gamma > 0.000001)
    42034284           g = 1.0 / png_ptr->screen_gamma;
     4285
    42044286        else
    4205            g = png_ptr->gamma;   /* probably doing rgb_to_gray */
     4287           g = png_ptr->gamma;   /* Probably doing rgb_to_gray */
    42064288
    42074289        png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
    4208            (png_uint_32)(num * png_sizeof (png_uint_16p)));
     4290           (png_uint_32)(num * png_sizeof(png_uint_16p)));
     4291        png_memset(png_ptr->gamma_16_from_1, 0,
     4292           num * png_sizeof(png_uint_16p));
    42094293
    42104294        for (i = 0; i < num; i++)
    42114295        {
    42124296           png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
    4213               (png_uint_32)(256 * png_sizeof (png_uint_16)));
     4297              (png_uint_32)(256 * png_sizeof(png_uint_16)));
    42144298
    42154299           ig = (((png_uint_32)i *
    42164300              (png_uint_32)png_gamma_shift[shift]) >> 4);
     4301
    42174302           for (j = 0; j < 256; j++)
    42184303           {
     
    42314316
    42324317#if defined(PNG_MNG_FEATURES_SUPPORTED)
    4233 /* undoes intrapixel differencing  */
     4318/* Undoes intrapixel differencing  */
    42344319void /* PRIVATE */
    42354320png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
    42364321{
    4237    png_debug(1, "in png_do_read_intrapixel\n");
     4322   png_debug(1, "in png_do_read_intrapixel");
    42384323   if (
    42394324#if defined(PNG_USELESS_TESTS_SUPPORTED)
     
    42514336         if (row_info->color_type == PNG_COLOR_TYPE_RGB)
    42524337            bytes_per_pixel = 3;
     4338
    42534339         else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
    42544340            bytes_per_pixel = 4;
     4341
    42554342         else
    42564343            return;
     
    42694356         if (row_info->color_type == PNG_COLOR_TYPE_RGB)
    42704357            bytes_per_pixel = 6;
     4358
    42714359         else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
    42724360            bytes_per_pixel = 8;
     4361
    42734362         else
    42744363            return;
     
    42764365         for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
    42774366         {
    4278             png_uint_32 s0   = (*(rp  ) << 8) | *(rp+1);
    4279             png_uint_32 s1   = (*(rp+2) << 8) | *(rp+3);
    4280             png_uint_32 s2   = (*(rp+4) << 8) | *(rp+5);
    4281             png_uint_32 red  = (png_uint_32)((s0+s1+65536L) & 0xffffL);
    4282             png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
     4367            png_uint_32 s0   = (*(rp    ) << 8) | *(rp + 1);
     4368            png_uint_32 s1   = (*(rp + 2) << 8) | *(rp + 3);
     4369            png_uint_32 s2   = (*(rp + 4) << 8) | *(rp + 5);
     4370            png_uint_32 red  = (png_uint_32)((s0 + s1 + 65536L) & 0xffffL);
     4371            png_uint_32 blue = (png_uint_32)((s2 + s1 + 65536L) & 0xffffL);
    42834372            *(rp  ) = (png_byte)((red >> 8) & 0xff);
    42844373            *(rp+1) = (png_byte)(red & 0xff);
Note: See TracChangeset for help on using the changeset viewer.