jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngrtran.c
author azvegint
Wed, 10 Aug 2016 02:50:58 +0300
changeset 40436 94ae0ede53a5
parent 35692 ee66ced7896c
child 43321 2b8d397c03a4
permissions -rw-r--r--
8155690: Update libPNG library to the latest up-to-date Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/* pngrtran.c - transforms the data in a row for PNG readers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * This file is available under and governed by the GNU General Public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * License version 2 only, as published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * However, the following notice accompanied the original version of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * file and, per its terms, should not be removed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
40436
94ae0ede53a5 8155690: Update libPNG library to the latest up-to-date
azvegint
parents: 35692
diff changeset
    32
 * Last changed in libpng 1.6.22 [May 26, 2016]
94ae0ede53a5 8155690: Update libPNG library to the latest up-to-date
azvegint
parents: 35692
diff changeset
    33
 * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    37
 * This code is released under the libpng license.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    38
 * For conditions of distribution and use, see the disclaimer
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    39
 * and license in png.h
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    40
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This file contains functions optionally called by an application
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * in order to tell libpng how to handle data when reading a PNG.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Transformations that are used in both reading and writing are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * in pngtrans.c.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    47
#include "pngpriv.h"
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    48
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    49
#ifdef PNG_READ_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
/* Set the action on getting a CRC error for an ancillary or critical chunk. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
    53
png_set_crc_action(png_structrp png_ptr, int crit_action, int ancil_action)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    55
   png_debug(1, "in png_set_crc_action");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    56
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    57
   if (png_ptr == NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    58
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    59
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
   /* Tell libpng how we react to CRC errors in critical chunks */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
   switch (crit_action)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    63
      case PNG_CRC_NO_CHANGE:                        /* Leave setting as is */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
         break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    65
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    66
      case PNG_CRC_WARN_USE:                               /* Warn/use data */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
         png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
         png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
         break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    70
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    71
      case PNG_CRC_QUIET_USE:                             /* Quiet/use data */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
         png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
         png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                           PNG_FLAG_CRC_CRITICAL_IGNORE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
         break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    76
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    77
      case PNG_CRC_WARN_DISCARD:    /* Not a valid action for critical data */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    78
         png_warning(png_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    79
            "Can't discard critical data on CRC error");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    80
      case PNG_CRC_ERROR_QUIT:                                /* Error/quit */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    81
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
      case PNG_CRC_DEFAULT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
      default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
         png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
         break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    88
   /* Tell libpng how we react to CRC errors in ancillary chunks */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
   switch (ancil_action)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    91
      case PNG_CRC_NO_CHANGE:                       /* Leave setting as is */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
         break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    93
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    94
      case PNG_CRC_WARN_USE:                              /* Warn/use data */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
         png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
         png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
         break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    98
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    99
      case PNG_CRC_QUIET_USE:                            /* Quiet/use data */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
         png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
         png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                           PNG_FLAG_CRC_ANCILLARY_NOWARN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
         break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   104
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   105
      case PNG_CRC_ERROR_QUIT:                               /* Error/quit */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
         png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
         break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   109
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   110
      case PNG_CRC_WARN_DISCARD:                      /* Warn/discard data */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   111
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
      case PNG_CRC_DEFAULT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
      default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
         png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
         break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   119
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   120
/* Is it OK to set a transformation now?  Only if png_start_read_image or
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   121
 * png_read_update_info have not been called.  It is not necessary for the IHDR
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   122
 * to have been read in all cases; the need_IHDR parameter allows for this
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   123
 * check too.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   124
 */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   125
static int
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   126
png_rtran_ok(png_structrp png_ptr, int need_IHDR)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   127
{
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   128
   if (png_ptr != NULL)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   129
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   130
      if ((png_ptr->flags & PNG_FLAG_ROW_INIT) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   131
         png_app_error(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   132
            "invalid after png_start_read_image or png_read_update_info");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   133
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   134
      else if (need_IHDR && (png_ptr->mode & PNG_HAVE_IHDR) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   135
         png_app_error(png_ptr, "invalid before the PNG header has been read");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   136
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   137
      else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   138
      {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   139
         /* Turn on failure to initialize correctly for all transforms. */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   140
         png_ptr->flags |= PNG_FLAG_DETECT_UNINITIALIZED;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   141
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   142
         return 1; /* Ok */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   143
      }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   144
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   145
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   146
   return 0; /* no png_error possible! */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   147
}
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   148
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   149
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   150
#ifdef PNG_READ_BACKGROUND_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   151
/* Handle alpha and tRNS via a background color */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   152
void PNGFAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   153
png_set_background_fixed(png_structrp png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   154
    png_const_color_16p background_color, int background_gamma_code,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   155
    int need_expand, png_fixed_point background_gamma)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   157
   png_debug(1, "in png_set_background_fixed");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   158
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   159
   if (png_rtran_ok(png_ptr, 0) == 0 || background_color == NULL)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   160
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   161
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
   if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
      png_warning(png_ptr, "Application must supply a known background gamma");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   168
   png_ptr->transformations |= PNG_COMPOSE | PNG_STRIP_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   169
   png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   170
   png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   171
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   172
   png_ptr->background = *background_color;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   173
   png_ptr->background_gamma = background_gamma;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
   png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   175
   if (need_expand != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   176
      png_ptr->transformations |= PNG_BACKGROUND_EXPAND;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   177
   else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   178
      png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   179
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   180
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   181
#  ifdef PNG_FLOATING_POINT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   182
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   183
png_set_background(png_structrp png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   184
    png_const_color_16p background_color, int background_gamma_code,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   185
    int need_expand, double background_gamma)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   186
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   187
   png_set_background_fixed(png_ptr, background_color, background_gamma_code,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   188
      need_expand, png_fixed(png_ptr, background_gamma, "png_set_background"));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   189
}
40436
94ae0ede53a5 8155690: Update libPNG library to the latest up-to-date
azvegint
parents: 35692
diff changeset
   190
#  endif /* FLOATING_POINT */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   191
#endif /* READ_BACKGROUND */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   192
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   193
/* Scale 16-bit depth files to 8-bit depth.  If both of these are set then the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   194
 * one that pngrtran does first (scale) happens.  This is necessary to allow the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   195
 * TRANSFORM and API behavior to be somewhat consistent, and it's simpler.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   196
 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   197
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   198
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   199
png_set_scale_16(png_structrp png_ptr)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   200
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   201
   png_debug(1, "in png_set_scale_16");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   202
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   203
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   204
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   205
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   206
   png_ptr->transformations |= PNG_SCALE_16_TO_8;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   210
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   211
/* Chop 16-bit depth files to 8-bit depth */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   213
png_set_strip_16(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   215
   png_debug(1, "in png_set_strip_16");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   216
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   217
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   218
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   219
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
   png_ptr->transformations |= PNG_16_TO_8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   224
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   226
png_set_strip_alpha(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   228
   png_debug(1, "in png_set_strip_alpha");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   229
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   230
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   231
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   232
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   233
   png_ptr->transformations |= PNG_STRIP_ALPHA;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   237
#if defined(PNG_READ_ALPHA_MODE_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   238
static png_fixed_point
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   239
translate_gamma_flags(png_structrp png_ptr, png_fixed_point output_gamma,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   240
   int is_screen)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   241
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   242
   /* Check for flag values.  The main reason for having the old Mac value as a
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   243
    * flag is that it is pretty near impossible to work out what the correct
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   244
    * value is from Apple documentation - a working Mac system is needed to
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   245
    * discover the value!
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   246
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   247
   if (output_gamma == PNG_DEFAULT_sRGB ||
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   248
      output_gamma == PNG_FP_1 / PNG_DEFAULT_sRGB)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   249
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   250
      /* If there is no sRGB support this just sets the gamma to the standard
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   251
       * sRGB value.  (This is a side effect of using this function!)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   252
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   253
#     ifdef PNG_READ_sRGB_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   254
         png_ptr->flags |= PNG_FLAG_ASSUME_sRGB;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   255
#     else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   256
         PNG_UNUSED(png_ptr)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   257
#     endif
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   258
      if (is_screen != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   259
         output_gamma = PNG_GAMMA_sRGB;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   260
      else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   261
         output_gamma = PNG_GAMMA_sRGB_INVERSE;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   262
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   263
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   264
   else if (output_gamma == PNG_GAMMA_MAC_18 ||
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   265
      output_gamma == PNG_FP_1 / PNG_GAMMA_MAC_18)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   266
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   267
      if (is_screen != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   268
         output_gamma = PNG_GAMMA_MAC_OLD;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   269
      else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   270
         output_gamma = PNG_GAMMA_MAC_INVERSE;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   271
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   272
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   273
   return output_gamma;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   274
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   275
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   276
#  ifdef PNG_FLOATING_POINT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   277
static png_fixed_point
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   278
convert_gamma_value(png_structrp png_ptr, double output_gamma)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   279
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   280
   /* The following silently ignores cases where fixed point (times 100,000)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   281
    * gamma values are passed to the floating point API.  This is safe and it
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   282
    * means the fixed point constants work just fine with the floating point
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   283
    * API.  The alternative would just lead to undetected errors and spurious
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   284
    * bug reports.  Negative values fail inside the _fixed API unless they
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   285
    * correspond to the flag values.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   286
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   287
   if (output_gamma > 0 && output_gamma < 128)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   288
      output_gamma *= PNG_FP_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   289
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   290
   /* This preserves -1 and -2 exactly: */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   291
   output_gamma = floor(output_gamma + .5);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   292
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   293
   if (output_gamma > PNG_FP_MAX || output_gamma < PNG_FP_MIN)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   294
      png_fixed_error(png_ptr, "gamma value");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   295
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   296
   return (png_fixed_point)output_gamma;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   297
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   298
#  endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   299
#endif /* READ_ALPHA_MODE || READ_GAMMA */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   300
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   301
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   302
void PNGFAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   303
png_set_alpha_mode_fixed(png_structrp png_ptr, int mode,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   304
   png_fixed_point output_gamma)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   305
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   306
   int compose = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   307
   png_fixed_point file_gamma;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   308
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   309
   png_debug(1, "in png_set_alpha_mode");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   310
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   311
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   312
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   313
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   314
   output_gamma = translate_gamma_flags(png_ptr, output_gamma, 1/*screen*/);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   315
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   316
   /* Validate the value to ensure it is in a reasonable range. The value
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   317
    * is expected to be 1 or greater, but this range test allows for some
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   318
    * viewing correction values.  The intent is to weed out users of this API
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   319
    * who use the inverse of the gamma value accidentally!  Since some of these
40436
94ae0ede53a5 8155690: Update libPNG library to the latest up-to-date
azvegint
parents: 35692
diff changeset
   320
    * values are reasonable this may have to be changed:
94ae0ede53a5 8155690: Update libPNG library to the latest up-to-date
azvegint
parents: 35692
diff changeset
   321
    *
94ae0ede53a5 8155690: Update libPNG library to the latest up-to-date
azvegint
parents: 35692
diff changeset
   322
    * 1.6.x: changed from 0.07..3 to 0.01..100 (to accomodate the optimal 16-bit
94ae0ede53a5 8155690: Update libPNG library to the latest up-to-date
azvegint
parents: 35692
diff changeset
   323
    * gamma of 36, and its reciprocal.)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   324
    */
40436
94ae0ede53a5 8155690: Update libPNG library to the latest up-to-date
azvegint
parents: 35692
diff changeset
   325
   if (output_gamma < 1000 || output_gamma > 10000000)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   326
      png_error(png_ptr, "output gamma out of expected range");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   327
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   328
   /* The default file gamma is the inverse of the output gamma; the output
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   329
    * gamma may be changed below so get the file value first:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   330
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   331
   file_gamma = png_reciprocal(output_gamma);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   332
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   333
   /* There are really 8 possibilities here, composed of any combination
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   334
    * of:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   335
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   336
    *    premultiply the color channels
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   337
    *    do not encode non-opaque pixels
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   338
    *    encode the alpha as well as the color channels
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   339
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   340
    * The differences disappear if the input/output ('screen') gamma is 1.0,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   341
    * because then the encoding is a no-op and there is only the choice of
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   342
    * premultiplying the color channels or not.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   343
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   344
    * png_set_alpha_mode and png_set_background interact because both use
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   345
    * png_compose to do the work.  Calling both is only useful when
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   346
    * png_set_alpha_mode is used to set the default mode - PNG_ALPHA_PNG - along
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   347
    * with a default gamma value.  Otherwise PNG_COMPOSE must not be set.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   348
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   349
   switch (mode)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   350
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   351
      case PNG_ALPHA_PNG:        /* default: png standard */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   352
         /* No compose, but it may be set by png_set_background! */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   353
         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   354
         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   355
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   356
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   357
      case PNG_ALPHA_ASSOCIATED: /* color channels premultiplied */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   358
         compose = 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   359
         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   360
         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   361
         /* The output is linear: */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   362
         output_gamma = PNG_FP_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   363
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   364
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   365
      case PNG_ALPHA_OPTIMIZED:  /* associated, non-opaque pixels linear */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   366
         compose = 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   367
         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   368
         png_ptr->flags |= PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   369
         /* output_gamma records the encoding of opaque pixels! */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   370
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   371
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   372
      case PNG_ALPHA_BROKEN:     /* associated, non-linear, alpha encoded */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   373
         compose = 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   374
         png_ptr->transformations |= PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   375
         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   376
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   377
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   378
      default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   379
         png_error(png_ptr, "invalid alpha mode");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   380
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   381
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   382
   /* Only set the default gamma if the file gamma has not been set (this has
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   383
    * the side effect that the gamma in a second call to png_set_alpha_mode will
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   384
    * be ignored.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   385
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   386
   if (png_ptr->colorspace.gamma == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   387
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   388
      png_ptr->colorspace.gamma = file_gamma;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   389
      png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   390
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   391
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   392
   /* But always set the output gamma: */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   393
   png_ptr->screen_gamma = output_gamma;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   394
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   395
   /* Finally, if pre-multiplying, set the background fields to achieve the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   396
    * desired result.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   397
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   398
   if (compose != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   399
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   400
      /* And obtain alpha pre-multiplication by composing on black: */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   401
      memset(&png_ptr->background, 0, (sizeof png_ptr->background));
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   402
      png_ptr->background_gamma = png_ptr->colorspace.gamma; /* just in case */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   403
      png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_FILE;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   404
      png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   405
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   406
      if ((png_ptr->transformations & PNG_COMPOSE) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   407
         png_error(png_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   408
            "conflicting calls to set alpha mode and background");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   409
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   410
      png_ptr->transformations |= PNG_COMPOSE;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   411
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   412
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   413
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   414
#  ifdef PNG_FLOATING_POINT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   415
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   416
png_set_alpha_mode(png_structrp png_ptr, int mode, double output_gamma)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   417
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   418
   png_set_alpha_mode_fixed(png_ptr, mode, convert_gamma_value(png_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   419
      output_gamma));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   420
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   421
#  endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   422
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   423
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   424
#ifdef PNG_READ_QUANTIZE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   425
/* Dither file to 8-bit.  Supply a palette, the current number
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
 * of elements in the palette, the maximum number of elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
 * allowed, and a histogram if possible.  If the current number
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
   428
 * of colors is greater than the maximum number, the palette will be
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   429
 * modified to fit in the maximum number.  "full_quantize" indicates
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   430
 * whether we need a quantizing cube set up for RGB images, or if we
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
 * simply are reducing the number of colors in a paletted image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
typedef struct png_dsort_struct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
{
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   436
   struct png_dsort_struct * next;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
   png_byte left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
   png_byte right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
} png_dsort;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   440
typedef png_dsort *   png_dsortp;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   441
typedef png_dsort * * png_dsortpp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   444
png_set_quantize(png_structrp png_ptr, png_colorp palette,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   445
    int num_palette, int maximum_colors, png_const_uint_16p histogram,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   446
    int full_quantize)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   448
   png_debug(1, "in png_set_quantize");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   449
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   450
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   451
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   452
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   453
   png_ptr->transformations |= PNG_QUANTIZE;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   454
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   455
   if (full_quantize == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
      int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   459
      png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr,
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   460
          (png_uint_32)(num_palette * (sizeof (png_byte))));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
      for (i = 0; i < num_palette; i++)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   462
         png_ptr->quantize_index[i] = (png_byte)i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
   if (num_palette > maximum_colors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
      if (histogram != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
         /* This is easy enough, just throw out the least used colors.
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   470
          * Perhaps not the best solution, but good enough.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   471
          */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
         int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   475
         /* Initialize an array to sort colors */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   476
         png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr,
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   477
             (png_uint_32)(num_palette * (sizeof (png_byte))));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   478
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   479
         /* Initialize the quantize_sort array */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
         for (i = 0; i < num_palette; i++)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   481
            png_ptr->quantize_sort[i] = (png_byte)i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
         /* Find the least used palette entries by starting a
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   484
          * bubble sort, and running it until we have sorted
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   485
          * out enough colors.  Note that we don't care about
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   486
          * sorting all the colors, just finding which are
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   487
          * least used.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   488
          */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
         for (i = num_palette - 1; i >= maximum_colors; i--)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   492
            int done; /* To stop early if the list is pre-sorted */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            done = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            for (j = 0; j < i; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   498
               if (histogram[png_ptr->quantize_sort[j]]
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   499
                   < histogram[png_ptr->quantize_sort[j + 1]])
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                  png_byte t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   503
                  t = png_ptr->quantize_sort[j];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   504
                  png_ptr->quantize_sort[j] = png_ptr->quantize_sort[j + 1];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   505
                  png_ptr->quantize_sort[j + 1] = t;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                  done = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   509
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   510
            if (done != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
               break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   514
         /* Swap the palette around, and set up a table, if necessary */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   515
         if (full_quantize != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            int j = num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   519
            /* Put all the useful colors within the max, but don't
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   520
             * move the others.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   521
             */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            for (i = 0; i < maximum_colors; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   524
               if ((int)png_ptr->quantize_sort[i] >= maximum_colors)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                  do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                     j--;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   528
                  while ((int)png_ptr->quantize_sort[j] >= maximum_colors);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   529
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                  palette[i] = palette[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            int j = num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   538
            /* Move all the used colors inside the max limit, and
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   539
             * develop a translation table.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   540
             */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            for (i = 0; i < maximum_colors; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   543
               /* Only move the colors we need to */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   544
               if ((int)png_ptr->quantize_sort[i] >= maximum_colors)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                  png_color tmp_color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                  do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                     j--;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   550
                  while ((int)png_ptr->quantize_sort[j] >= maximum_colors);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                  tmp_color = palette[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                  palette[j] = palette[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                  palette[i] = tmp_color;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   555
                  /* Indicate where the color went */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   556
                  png_ptr->quantize_index[j] = (png_byte)i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   557
                  png_ptr->quantize_index[i] = (png_byte)j;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   561
            /* Find closest color for those colors we are not using */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            for (i = 0; i < num_palette; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   564
               if ((int)png_ptr->quantize_index[i] >= maximum_colors)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                  int min_d, k, min_k, d_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   568
                  /* Find the closest color to one we threw out */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   569
                  d_index = png_ptr->quantize_index[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                  min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                  for (k = 1, min_k = 0; k < maximum_colors; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                     int d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                     d = PNG_COLOR_DIST(palette[d_index], palette[k]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                     if (d < min_d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                        min_d = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                        min_k = k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   583
                  /* Point to closest color */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   584
                  png_ptr->quantize_index[i] = (png_byte)min_k;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   588
         png_free(png_ptr, png_ptr->quantize_sort);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   589
         png_ptr->quantize_sort = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
         /* This is much harder to do simply (and quickly).  Perhaps
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   594
          * we need to go through a median cut routine, but those
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   595
          * don't always behave themselves with only a few colors
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   596
          * as input.  So we will just find the closest two colors,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   597
          * and throw out one of them (chosen somewhat randomly).
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   598
          * [We don't understand this at all, so if someone wants to
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   599
          *  work on improving it, be our guest - AED, GRP]
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   600
          */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
         int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
         int max_d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
         int num_new_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
         png_dsortp t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
         png_dsortpp hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   607
         t = NULL;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   608
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   609
         /* Initialize palette index arrays */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
         png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   611
             (png_uint_32)(num_palette * (sizeof (png_byte))));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
         png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   613
             (png_uint_32)(num_palette * (sizeof (png_byte))));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   614
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   615
         /* Initialize the sort array */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
         for (i = 0; i < num_palette; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            png_ptr->index_to_palette[i] = (png_byte)i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            png_ptr->palette_to_index[i] = (png_byte)i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   622
         hash = (png_dsortpp)png_calloc(png_ptr, (png_uint_32)(769 *
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   623
             (sizeof (png_dsortp))));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
         num_new_palette = num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   627
         /* Initial wild guess at how far apart the farthest pixel
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   628
          * pair we will be eliminating will be.  Larger
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   629
          * numbers mean more areas will be allocated, Smaller
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   630
          * numbers run the risk of not saving enough data, and
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   631
          * having to do this all over again.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   632
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   633
          * I have not done extensive checking on this number.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   634
          */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
         max_d = 96;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
         while (num_new_palette > maximum_colors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            for (i = 0; i < num_new_palette - 1; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
               int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
               for (j = i + 1; j < num_new_palette; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                  int d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                  d = PNG_COLOR_DIST(palette[i], palette[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                  if (d <= max_d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                     t = (png_dsortp)png_malloc_warn(png_ptr,
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   653
                         (png_uint_32)(sizeof (png_dsort)));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   654
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                     if (t == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                         break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   657
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                     t->next = hash[d];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                     t->left = (png_byte)i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                     t->right = (png_byte)j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                     hash[d] = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
               if (t == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            if (t != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            for (i = 0; i <= max_d; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
               if (hash[i] != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                  png_dsortp p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                  for (p = hash[i]; p; p = p->next)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                     if ((int)png_ptr->index_to_palette[p->left]
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   678
                         < num_new_palette &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   679
                         (int)png_ptr->index_to_palette[p->right]
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   680
                         < num_new_palette)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                        int j, next_j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                        if (num_new_palette & 0x01)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                           j = p->left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                           next_j = p->right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                           j = p->right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                           next_j = p->left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                        num_new_palette--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                        palette[png_ptr->index_to_palette[j]]
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   697
                            = palette[num_new_palette];
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   698
                        if (full_quantize == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                           int k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                           for (k = 0; k < num_palette; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                           {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   704
                              if (png_ptr->quantize_index[k] ==
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   705
                                  png_ptr->index_to_palette[j])
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   706
                                 png_ptr->quantize_index[k] =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   707
                                     png_ptr->index_to_palette[next_j];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   708
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   709
                              if ((int)png_ptr->quantize_index[k] ==
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   710
                                  num_new_palette)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   711
                                 png_ptr->quantize_index[k] =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   712
                                     png_ptr->index_to_palette[j];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                        png_ptr->index_to_palette[png_ptr->palette_to_index
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   717
                            [num_new_palette]] = png_ptr->index_to_palette[j];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   718
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                        png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   720
                            = png_ptr->palette_to_index[num_new_palette];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   721
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   722
                        png_ptr->index_to_palette[j] =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   723
                            (png_byte)num_new_palette;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   724
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   725
                        png_ptr->palette_to_index[num_new_palette] =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   726
                            (png_byte)j;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                     if (num_new_palette <= maximum_colors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                  if (num_new_palette <= maximum_colors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                     break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            for (i = 0; i < 769; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
               if (hash[i] != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                  png_dsortp p = hash[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                  while (p)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                     t = p->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                     png_free(png_ptr, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                     p = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
               hash[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            max_d += 96;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
         png_free(png_ptr, hash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
         png_free(png_ptr, png_ptr->palette_to_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
         png_free(png_ptr, png_ptr->index_to_palette);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   755
         png_ptr->palette_to_index = NULL;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   756
         png_ptr->index_to_palette = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
      num_palette = maximum_colors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
   if (png_ptr->palette == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
      png_ptr->palette = palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
   png_ptr->num_palette = (png_uint_16)num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   766
   if (full_quantize != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
      int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
      png_bytep distance;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   770
      int total_bits = PNG_QUANTIZE_RED_BITS + PNG_QUANTIZE_GREEN_BITS +
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   771
          PNG_QUANTIZE_BLUE_BITS;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   772
      int num_red = (1 << PNG_QUANTIZE_RED_BITS);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   773
      int num_green = (1 << PNG_QUANTIZE_GREEN_BITS);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   774
      int num_blue = (1 << PNG_QUANTIZE_BLUE_BITS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
      png_size_t num_entries = ((png_size_t)1 << total_bits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   777
      png_ptr->palette_lookup = (png_bytep)png_calloc(png_ptr,
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   778
          (png_uint_32)(num_entries * (sizeof (png_byte))));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
      distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   781
          (sizeof (png_byte))));
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   782
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   783
      memset(distance, 0xff, num_entries * (sizeof (png_byte)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
      for (i = 0; i < num_palette; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
         int ir, ig, ib;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   788
         int r = (palette[i].red >> (8 - PNG_QUANTIZE_RED_BITS));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   789
         int g = (palette[i].green >> (8 - PNG_QUANTIZE_GREEN_BITS));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   790
         int b = (palette[i].blue >> (8 - PNG_QUANTIZE_BLUE_BITS));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
         for (ir = 0; ir < num_red; ir++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            /* int dr = abs(ir - r); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            int dr = ((ir > r) ? ir - r : r - ir);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   796
            int index_r = (ir << (PNG_QUANTIZE_BLUE_BITS +
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   797
                PNG_QUANTIZE_GREEN_BITS));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            for (ig = 0; ig < num_green; ig++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
               /* int dg = abs(ig - g); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
               int dg = ((ig > g) ? ig - g : g - ig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
               int dt = dr + dg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
               int dm = ((dr > dg) ? dr : dg);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   805
               int index_g = index_r | (ig << PNG_QUANTIZE_BLUE_BITS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
               for (ib = 0; ib < num_blue; ib++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                  int d_index = index_g | ib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                  /* int db = abs(ib - b); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                  int db = ((ib > b) ? ib - b : b - ib);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                  int dmax = ((dm > db) ? dm : db);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                  int d = dmax + dt + db;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                  if (d < (int)distance[d_index])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                     distance[d_index] = (png_byte)d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                     png_ptr->palette_lookup[d_index] = (png_byte)i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
      png_free(png_ptr, distance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   828
#endif /* READ_QUANTIZE */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   829
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   830
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   831
void PNGFAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   832
png_set_gamma_fixed(png_structrp png_ptr, png_fixed_point scrn_gamma,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   833
   png_fixed_point file_gamma)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   834
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   835
   png_debug(1, "in png_set_gamma_fixed");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   836
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   837
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   838
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   839
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   840
   /* New in libpng-1.5.4 - reserve particular negative values as flags. */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   841
   scrn_gamma = translate_gamma_flags(png_ptr, scrn_gamma, 1/*screen*/);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   842
   file_gamma = translate_gamma_flags(png_ptr, file_gamma, 0/*file*/);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   843
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   844
   /* Checking the gamma values for being >0 was added in 1.5.4 along with the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   845
    * premultiplied alpha support; this actually hides an undocumented feature
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   846
    * of the previous implementation which allowed gamma processing to be
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   847
    * disabled in background handling.  There is no evidence (so far) that this
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   848
    * was being used; however, png_set_background itself accepted and must still
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   849
    * accept '0' for the gamma value it takes, because it isn't always used.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   850
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   851
    * Since this is an API change (albeit a very minor one that removes an
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   852
    * undocumented API feature) the following checks were only enabled in
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   853
    * libpng-1.6.0.
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   854
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   855
   if (file_gamma <= 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   856
      png_error(png_ptr, "invalid file gamma in png_set_gamma");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   857
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   858
   if (scrn_gamma <= 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   859
      png_error(png_ptr, "invalid screen gamma in png_set_gamma");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   861
   /* Set the gamma values unconditionally - this overrides the value in the PNG
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   862
    * file if a gAMA chunk was present.  png_set_alpha_mode provides a
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   863
    * different, easier, way to default the file gamma.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   864
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   865
   png_ptr->colorspace.gamma = file_gamma;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   866
   png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   867
   png_ptr->screen_gamma = scrn_gamma;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   868
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   869
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   870
#  ifdef PNG_FLOATING_POINT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   872
png_set_gamma(png_structrp png_ptr, double scrn_gamma, double file_gamma)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   874
   png_set_gamma_fixed(png_ptr, convert_gamma_value(png_ptr, scrn_gamma),
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   875
      convert_gamma_value(png_ptr, file_gamma));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   877
#  endif /* FLOATING_POINT */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   878
#endif /* READ_GAMMA */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   879
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   880
#ifdef PNG_READ_EXPAND_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
/* Expand paletted images to RGB, expand grayscale images of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
 * less than 8-bit depth to 8-bit depth, and expand tRNS chunks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
 * to alpha channels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   886
png_set_expand(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   888
   png_debug(1, "in png_set_expand");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   889
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   890
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   891
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   892
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
   png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
/* GRR 19990627:  the following three functions currently are identical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
 *  to png_set_expand().  However, it is entirely reasonable that someone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
 *  might wish to expand an indexed image to RGB but *not* expand a single,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
 *  fully transparent palette entry to a full alpha channel--perhaps instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
 *  convert tRNS to the grayscale/RGB format (16-bit RGB value), or replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
 *  the transparent color with a particular RGB value, or drop tRNS entirely.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
 *  IOW, a future version of the library may make the transformations flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
 *  a bit more fine-grained, with separate bits for each of these three
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
 *  functions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
 *  More to the point, these functions make it obvious what libpng will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
 *  doing, whereas "expand" can (and does) mean any number of things.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
 *
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   909
 *  GRP 20060307: In libpng-1.2.9, png_set_gray_1_2_4_to_8() was modified
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   910
 *  to expand only the sample depth but not to expand the tRNS to alpha
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   911
 *  and its name was changed to png_set_expand_gray_1_2_4_to_8().
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
/* Expand paletted images to RGB. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   916
png_set_palette_to_rgb(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   918
   png_debug(1, "in png_set_palette_to_rgb");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   919
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   920
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   921
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   922
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
   png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
/* Expand grayscale images of less than 8-bit depth to 8 bits. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   928
png_set_expand_gray_1_2_4_to_8(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   930
   png_debug(1, "in png_set_expand_gray_1_2_4_to_8");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   931
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   932
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   933
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   934
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
   png_ptr->transformations |= PNG_EXPAND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
}
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   937
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
/* Expand tRNS chunks to alpha channels. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   940
png_set_tRNS_to_alpha(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   942
   png_debug(1, "in png_set_tRNS_to_alpha");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   943
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   944
   if (png_rtran_ok(png_ptr, 0) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   945
      return;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   946
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
   png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   949
#endif /* READ_EXPAND */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   951
#ifdef PNG_READ_EXPAND_16_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   952
/* Expand to 16-bit channels, expand the tRNS chunk too (because otherwise
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   953
 * it may not work correctly.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   954
 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   955
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   956
png_set_expand_16(png_structrp png_ptr)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   957
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   958
   png_debug(1, "in png_set_expand_16");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   959
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   960
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   961
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   962
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   963
   png_ptr->transformations |= (PNG_EXPAND_16 | PNG_EXPAND | PNG_EXPAND_tRNS);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   964
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   965
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   966
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   967
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   969
png_set_gray_to_rgb(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   971
   png_debug(1, "in png_set_gray_to_rgb");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   972
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   973
   if (png_rtran_ok(png_ptr, 0) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   974
      return;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   975
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   976
   /* Because rgb must be 8 bits or more: */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   977
   png_set_expand_gray_1_2_4_to_8(png_ptr);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   978
   png_ptr->transformations |= PNG_GRAY_TO_RGB;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   982
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   983
void PNGFAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   984
png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   985
    png_fixed_point red, png_fixed_point green)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   986
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   987
   png_debug(1, "in png_set_rgb_to_gray");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   988
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   989
   /* Need the IHDR here because of the check on color_type below. */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   990
   /* TODO: fix this */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   991
   if (png_rtran_ok(png_ptr, 1) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   992
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   993
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   994
   switch (error_action)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   995
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   996
      case PNG_ERROR_ACTION_NONE:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   997
         png_ptr->transformations |= PNG_RGB_TO_GRAY;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   998
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   999
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1000
      case PNG_ERROR_ACTION_WARN:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1001
         png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1002
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1003
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1004
      case PNG_ERROR_ACTION_ERROR:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1005
         png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1006
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1007
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1008
      default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1009
         png_error(png_ptr, "invalid error action to rgb_to_gray");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1010
   }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1011
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1012
   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1013
#ifdef PNG_READ_EXPAND_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1014
      png_ptr->transformations |= PNG_EXPAND;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1015
#else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1016
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1017
      /* Make this an error in 1.6 because otherwise the application may assume
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1018
       * that it just worked and get a memory overwrite.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1019
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1020
      png_error(png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1021
        "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1022
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1023
      /* png_ptr->transformations &= ~PNG_RGB_TO_GRAY; */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1024
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1025
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1026
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1027
      if (red >= 0 && green >= 0 && red + green <= PNG_FP_1)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1028
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1029
         png_uint_16 red_int, green_int;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1030
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1031
         /* NOTE: this calculation does not round, but this behavior is retained
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1032
          * for consistency; the inaccuracy is very small.  The code here always
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1033
          * overwrites the coefficients, regardless of whether they have been
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1034
          * defaulted or set already.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1035
          */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1036
         red_int = (png_uint_16)(((png_uint_32)red*32768)/100000);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1037
         green_int = (png_uint_16)(((png_uint_32)green*32768)/100000);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1038
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1039
         png_ptr->rgb_to_gray_red_coeff   = red_int;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1040
         png_ptr->rgb_to_gray_green_coeff = green_int;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1041
         png_ptr->rgb_to_gray_coefficients_set = 1;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1042
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1043
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1044
      else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1045
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1046
         if (red >= 0 && green >= 0)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1047
            png_app_warning(png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1048
               "ignoring out of range rgb_to_gray coefficients");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1049
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1050
         /* Use the defaults, from the cHRM chunk if set, else the historical
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1051
          * values which are close to the sRGB/HDTV/ITU-Rec 709 values.  See
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1052
          * png_do_rgb_to_gray for more discussion of the values.  In this case
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1053
          * the coefficients are not marked as 'set' and are not overwritten if
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1054
          * something has already provided a default.
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1055
          */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1056
         if (png_ptr->rgb_to_gray_red_coeff == 0 &&
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1057
            png_ptr->rgb_to_gray_green_coeff == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1058
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1059
            png_ptr->rgb_to_gray_red_coeff   = 6968;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1060
            png_ptr->rgb_to_gray_green_coeff = 23434;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1061
            /* png_ptr->rgb_to_gray_blue_coeff  = 2366; */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1062
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1063
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1064
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1065
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1066
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1067
#ifdef PNG_FLOATING_POINT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
/* Convert a RGB image to a grayscale of the same width.  This allows us,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
 * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1073
png_set_rgb_to_gray(png_structrp png_ptr, int error_action, double red,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
   double green)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1076
   png_set_rgb_to_gray_fixed(png_ptr, error_action,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1077
      png_fixed(png_ptr, red, "rgb to gray red coefficient"),
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1078
      png_fixed(png_ptr, green, "rgb to gray green coefficient"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
}
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1080
#endif /* FLOATING POINT */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1081
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1082
#endif /* RGB_TO_GRAY */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1085
    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1087
png_set_read_user_transform_fn(png_structrp png_ptr, png_user_transform_ptr
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1088
    read_user_transform_fn)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1090
   png_debug(1, "in png_set_read_user_transform_fn");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1091
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1092
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
   png_ptr->transformations |= PNG_USER_TRANSFORM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
   png_ptr->read_user_transform_fn = read_user_transform_fn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1096
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1098
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1099
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1100
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1101
/* In the case of gamma transformations only do transformations on images where
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1102
 * the [file] gamma and screen_gamma are not close reciprocals, otherwise it
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1103
 * slows things down slightly, and also needlessly introduces small errors.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1104
 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1105
static int /* PRIVATE */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1106
png_gamma_threshold(png_fixed_point screen_gamma, png_fixed_point file_gamma)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1107
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1108
   /* PNG_GAMMA_THRESHOLD is the threshold for performing gamma
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1109
    * correction as a difference of the overall transform from 1.0
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1110
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1111
    * We want to compare the threshold with s*f - 1, if we get
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1112
    * overflow here it is because of wacky gamma values so we
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1113
    * turn on processing anyway.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1114
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1115
   png_fixed_point gtest;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1116
   return !png_muldiv(&gtest, screen_gamma, file_gamma, PNG_FP_1) ||
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1117
       png_gamma_significant(gtest);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
/* Initialize everything needed for the read.  This includes modifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
 * the palette.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
 */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1124
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1125
/* For the moment 'png_init_palette_transformations' and
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1126
 * 'png_init_rgb_transformations' only do some flag canceling optimizations.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1127
 * The intent is that these two routines should have palette or rgb operations
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1128
 * extracted from 'png_init_read_transformations'.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1129
 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1130
static void /* PRIVATE */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1131
png_init_palette_transformations(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1133
   /* Called to handle the (input) palette case.  In png_do_read_transformations
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1134
    * the first step is to expand the palette if requested, so this code must
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1135
    * take care to only make changes that are invariant with respect to the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1136
    * palette expansion, or only do them if there is no expansion.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1137
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1138
    * STRIP_ALPHA has already been handled in the caller (by setting num_trans
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1139
    * to 0.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1140
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1141
   int input_has_alpha = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1142
   int input_has_transparency = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1143
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1144
   if (png_ptr->num_trans > 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1145
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1146
      int i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1147
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1148
      /* Ignore if all the entries are opaque (unlikely!) */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1149
      for (i=0; i<png_ptr->num_trans; ++i)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1150
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1151
         if (png_ptr->trans_alpha[i] == 255)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1152
            continue;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1153
         else if (png_ptr->trans_alpha[i] == 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1154
            input_has_transparency = 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1155
         else
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1156
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1157
            input_has_transparency = 1;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1158
            input_has_alpha = 1;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1159
            break;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1160
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1161
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1162
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1163
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1164
   /* If no alpha we can optimize. */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1165
   if (input_has_alpha == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1166
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1167
      /* Any alpha means background and associative alpha processing is
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1168
       * required, however if the alpha is 0 or 1 throughout OPTIMIZE_ALPHA
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1169
       * and ENCODE_ALPHA are irrelevant.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1170
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1171
      png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1172
      png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1173
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1174
      if (input_has_transparency == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1175
         png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1176
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1179
   /* png_set_background handling - deals with the complexity of whether the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1180
    * background color is in the file format or the screen format in the case
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1181
    * where an 'expand' will happen.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1183
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1184
   /* The following code cannot be entered in the alpha pre-multiplication case
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1185
    * because PNG_BACKGROUND_EXPAND is cancelled below.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1186
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1187
   if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1188
       (png_ptr->transformations & PNG_EXPAND) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1191
         png_ptr->background.red   =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1192
             png_ptr->palette[png_ptr->background.index].red;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1193
         png_ptr->background.green =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1194
             png_ptr->palette[png_ptr->background.index].green;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1195
         png_ptr->background.blue  =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1196
             png_ptr->palette[png_ptr->background.index].blue;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1197
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1198
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1199
        if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1200
        {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1201
           if ((png_ptr->transformations & PNG_EXPAND_tRNS) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1202
           {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1203
              /* Invert the alpha channel (in tRNS) unless the pixels are
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1204
               * going to be expanded, in which case leave it for later
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1205
               */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1206
              int i, istop = png_ptr->num_trans;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1207
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1208
              for (i=0; i<istop; i++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1209
                 png_ptr->trans_alpha[i] = (png_byte)(255 -
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1210
                    png_ptr->trans_alpha[i]);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1211
           }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1212
        }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1213
#endif /* READ_INVERT_ALPHA */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1214
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1215
   } /* background expand and (therefore) no alpha association. */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1216
#endif /* READ_EXPAND && READ_BACKGROUND */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1217
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1218
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1219
static void /* PRIVATE */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1220
png_init_rgb_transformations(png_structrp png_ptr)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1221
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1222
   /* Added to libpng-1.5.4: check the color type to determine whether there
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1223
    * is any alpha or transparency in the image and simply cancel the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1224
    * background and alpha mode stuff if there isn't.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1225
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1226
   int input_has_alpha = (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1227
   int input_has_transparency = png_ptr->num_trans > 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1228
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1229
   /* If no alpha we can optimize. */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1230
   if (input_has_alpha == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1231
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1232
      /* Any alpha means background and associative alpha processing is
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1233
       * required, however if the alpha is 0 or 1 throughout OPTIMIZE_ALPHA
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1234
       * and ENCODE_ALPHA are irrelevant.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1235
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1236
#     ifdef PNG_READ_ALPHA_MODE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1237
         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1238
         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1239
#     endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1240
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1241
      if (input_has_transparency == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1242
         png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1243
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1244
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1245
#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1246
   /* png_set_background handling - deals with the complexity of whether the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1247
    * background color is in the file format or the screen format in the case
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1248
    * where an 'expand' will happen.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1249
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1250
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1251
   /* The following code cannot be entered in the alpha pre-multiplication case
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1252
    * because PNG_BACKGROUND_EXPAND is cancelled below.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1253
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1254
   if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1255
       (png_ptr->transformations & PNG_EXPAND) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1256
       (png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1257
       /* i.e., GRAY or GRAY_ALPHA */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1258
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1259
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1260
         /* Expand background and tRNS chunks */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1261
         int gray = png_ptr->background.gray;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1262
         int trans_gray = png_ptr->trans_color.gray;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1263
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
         switch (png_ptr->bit_depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            case 1:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1267
               gray *= 0xff;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1268
               trans_gray *= 0xff;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
               break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1270
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            case 2:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1272
               gray *= 0x55;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1273
               trans_gray *= 0x55;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
               break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1275
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            case 4:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1277
               gray *= 0x11;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1278
               trans_gray *= 0x11;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
               break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1280
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1281
            default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1282
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            case 8:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1284
               /* FALL THROUGH (Already 8 bits) */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1285
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            case 16:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1287
               /* Already a full 16 bits */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
               break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
         }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1290
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1291
         png_ptr->background.red = png_ptr->background.green =
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1292
            png_ptr->background.blue = (png_uint_16)gray;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1293
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1294
         if ((png_ptr->transformations & PNG_EXPAND_tRNS) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1295
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1296
            png_ptr->trans_color.red = png_ptr->trans_color.green =
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1297
               png_ptr->trans_color.blue = (png_uint_16)trans_gray;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1298
         }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1300
   } /* background expand and (therefore) no alpha association. */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1301
#endif /* READ_EXPAND && READ_BACKGROUND */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1302
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1303
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1304
void /* PRIVATE */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1305
png_init_read_transformations(png_structrp png_ptr)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1306
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1307
   png_debug(1, "in png_init_read_transformations");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1308
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1309
   /* This internal function is called from png_read_start_row in pngrutil.c
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1310
    * and it is called before the 'rowbytes' calculation is done, so the code
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1311
    * in here can change or update the transformations flags.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1312
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1313
    * First do updates that do not depend on the details of the PNG image data
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1314
    * being processed.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1315
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1316
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1317
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1318
   /* Prior to 1.5.4 these tests were performed from png_set_gamma, 1.5.4 adds
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1319
    * png_set_alpha_mode and this is another source for a default file gamma so
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1320
    * the test needs to be performed later - here.  In addition prior to 1.5.4
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1321
    * the tests were repeated for the PALETTE color type here - this is no
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1322
    * longer necessary (and doesn't seem to have been necessary before.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1323
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1324
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1325
      /* The following temporary indicates if overall gamma correction is
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1326
       * required.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1327
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1328
      int gamma_correction = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1329
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1330
      if (png_ptr->colorspace.gamma != 0) /* has been set */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1332
         if (png_ptr->screen_gamma != 0) /* screen set too */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1333
            gamma_correction = png_gamma_threshold(png_ptr->colorspace.gamma,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1334
               png_ptr->screen_gamma);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1335
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1336
         else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1337
            /* Assume the output matches the input; a long time default behavior
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1338
             * of libpng, although the standard has nothing to say about this.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1339
             */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1340
            png_ptr->screen_gamma = png_reciprocal(png_ptr->colorspace.gamma);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1341
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1342
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1343
      else if (png_ptr->screen_gamma != 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1344
         /* The converse - assume the file matches the screen, note that this
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1345
          * perhaps undesireable default can (from 1.5.4) be changed by calling
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1346
          * png_set_alpha_mode (even if the alpha handling mode isn't required
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1347
          * or isn't changed from the default.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1348
          */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1349
         png_ptr->colorspace.gamma = png_reciprocal(png_ptr->screen_gamma);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1350
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1351
      else /* neither are set */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1352
         /* Just in case the following prevents any processing - file and screen
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1353
          * are both assumed to be linear and there is no way to introduce a
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1354
          * third gamma value other than png_set_background with 'UNIQUE', and,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1355
          * prior to 1.5.4
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1356
          */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1357
         png_ptr->screen_gamma = png_ptr->colorspace.gamma = PNG_FP_1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1358
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1359
      /* We have a gamma value now. */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1360
      png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1361
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1362
      /* Now turn the gamma transformation on or off as appropriate.  Notice
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1363
       * that PNG_GAMMA just refers to the file->screen correction.  Alpha
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1364
       * composition may independently cause gamma correction because it needs
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1365
       * linear data (e.g. if the file has a gAMA chunk but the screen gamma
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1366
       * hasn't been specified.)  In any case this flag may get turned off in
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1367
       * the code immediately below if the transform can be handled outside the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1368
       * row loop.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1369
       */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1370
      if (gamma_correction != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1371
         png_ptr->transformations |= PNG_GAMMA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1372
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1373
      else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1374
         png_ptr->transformations &= ~PNG_GAMMA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1375
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1377
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1378
   /* Certain transformations have the effect of preventing other
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1379
    * transformations that happen afterward in png_do_read_transformations;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1380
    * resolve the interdependencies here.  From the code of
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1381
    * png_do_read_transformations the order is:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1382
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1383
    *  1) PNG_EXPAND (including PNG_EXPAND_tRNS)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1384
    *  2) PNG_STRIP_ALPHA (if no compose)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1385
    *  3) PNG_RGB_TO_GRAY
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1386
    *  4) PNG_GRAY_TO_RGB iff !PNG_BACKGROUND_IS_GRAY
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1387
    *  5) PNG_COMPOSE
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1388
    *  6) PNG_GAMMA
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1389
    *  7) PNG_STRIP_ALPHA (if compose)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1390
    *  8) PNG_ENCODE_ALPHA
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1391
    *  9) PNG_SCALE_16_TO_8
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1392
    * 10) PNG_16_TO_8
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1393
    * 11) PNG_QUANTIZE (converts to palette)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1394
    * 12) PNG_EXPAND_16
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1395
    * 13) PNG_GRAY_TO_RGB iff PNG_BACKGROUND_IS_GRAY
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1396
    * 14) PNG_INVERT_MONO
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1397
    * 15) PNG_INVERT_ALPHA
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1398
    * 16) PNG_SHIFT
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1399
    * 17) PNG_PACK
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1400
    * 18) PNG_BGR
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1401
    * 19) PNG_PACKSWAP
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1402
    * 20) PNG_FILLER (includes PNG_ADD_ALPHA)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1403
    * 21) PNG_SWAP_ALPHA
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1404
    * 22) PNG_SWAP_BYTES
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1405
    * 23) PNG_USER_TRANSFORM [must be last]
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1406
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1407
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1408
   if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1409
       (png_ptr->transformations & PNG_COMPOSE) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1410
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1411
      /* Stripping the alpha channel happens immediately after the 'expand'
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1412
       * transformations, before all other transformation, so it cancels out
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1413
       * the alpha handling.  It has the side effect negating the effect of
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1414
       * PNG_EXPAND_tRNS too:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1415
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1416
      png_ptr->transformations &= ~(PNG_BACKGROUND_EXPAND | PNG_ENCODE_ALPHA |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1417
         PNG_EXPAND_tRNS);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1418
      png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1419
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1420
      /* Kill the tRNS chunk itself too.  Prior to 1.5.4 this did not happen
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1421
       * so transparency information would remain just so long as it wasn't
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1422
       * expanded.  This produces unexpected API changes if the set of things
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1423
       * that do PNG_EXPAND_tRNS changes (perfectly possible given the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1424
       * documentation - which says ask for what you want, accept what you
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1425
       * get.)  This makes the behavior consistent from 1.5.4:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1426
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1427
      png_ptr->num_trans = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1428
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1429
#endif /* STRIP_ALPHA supported, no COMPOSE */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1430
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1431
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1432
   /* If the screen gamma is about 1.0 then the OPTIMIZE_ALPHA and ENCODE_ALPHA
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1433
    * settings will have no effect.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1434
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1435
   if (png_gamma_significant(png_ptr->screen_gamma) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1436
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1437
      png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1438
      png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1442
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1443
   /* Make sure the coefficients for the rgb to gray conversion are set
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1444
    * appropriately.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1445
    */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1446
   if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1447
      png_colorspace_set_rgb_coefficients(png_ptr);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1448
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1449
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1450
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1451
#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1452
   /* Detect gray background and attempt to enable optimization for
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1453
    * gray --> RGB case.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1454
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1455
    * Note:  if PNG_BACKGROUND_EXPAND is set and color_type is either RGB or
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1456
    * RGB_ALPHA (in which case need_expand is superfluous anyway), the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1457
    * background color might actually be gray yet not be flagged as such.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1458
    * This is not a problem for the current code, which uses
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1459
    * PNG_BACKGROUND_IS_GRAY only to decide when to do the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1460
    * png_do_gray_to_rgb() transformation.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1461
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1462
    * TODO: this code needs to be revised to avoid the complexity and
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1463
    * interdependencies.  The color type of the background should be recorded in
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1464
    * png_set_background, along with the bit depth, then the code has a record
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1465
    * of exactly what color space the background is currently in.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1466
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1467
   if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1468
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1469
      /* PNG_BACKGROUND_EXPAND: the background is in the file color space, so if
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1470
       * the file was grayscale the background value is gray.
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1471
       */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1472
      if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1473
         png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1474
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1475
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1476
   else if ((png_ptr->transformations & PNG_COMPOSE) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1477
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1478
      /* PNG_COMPOSE: png_set_background was called with need_expand false,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1479
       * so the color is in the color space of the output or png_set_alpha_mode
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1480
       * was called and the color is black.  Ignore RGB_TO_GRAY because that
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1481
       * happens before GRAY_TO_RGB.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1482
       */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1483
      if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1484
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1485
         if (png_ptr->background.red == png_ptr->background.green &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1486
             png_ptr->background.red == png_ptr->background.blue)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1487
         {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1488
            png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1489
            png_ptr->background.gray = png_ptr->background.red;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1490
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1491
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1492
   }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1493
#endif /* READ_EXPAND && READ_BACKGROUND */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1494
#endif /* READ_GRAY_TO_RGB */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1495
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1496
   /* For indexed PNG data (PNG_COLOR_TYPE_PALETTE) many of the transformations
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1497
    * can be performed directly on the palette, and some (such as rgb to gray)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1498
    * can be optimized inside the palette.  This is particularly true of the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1499
    * composite (background and alpha) stuff, which can be pretty much all done
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1500
    * in the palette even if the result is expanded to RGB or gray afterward.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1501
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1502
    * NOTE: this is Not Yet Implemented, the code behaves as in 1.5.1 and
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1503
    * earlier and the palette stuff is actually handled on the first row.  This
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1504
    * leads to the reported bug that the palette returned by png_get_PLTE is not
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1505
    * updated.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1506
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1507
   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1508
      png_init_palette_transformations(png_ptr);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1509
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1510
   else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1511
      png_init_rgb_transformations(png_ptr);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1512
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1513
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1514
   defined(PNG_READ_EXPAND_16_SUPPORTED)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1515
   if ((png_ptr->transformations & PNG_EXPAND_16) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1516
       (png_ptr->transformations & PNG_COMPOSE) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1517
       (png_ptr->transformations & PNG_BACKGROUND_EXPAND) == 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1518
       png_ptr->bit_depth != 16)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1520
      /* TODO: fix this.  Because the expand_16 operation is after the compose
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1521
       * handling the background color must be 8, not 16, bits deep, but the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1522
       * application will supply a 16-bit value so reduce it here.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1523
       *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1524
       * The PNG_BACKGROUND_EXPAND code above does not expand to 16 bits at
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1525
       * present, so that case is ok (until do_expand_16 is moved.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1526
       *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1527
       * NOTE: this discards the low 16 bits of the user supplied background
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1528
       * color, but until expand_16 works properly there is no choice!
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1529
       */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1530
#     define CHOP(x) (x)=((png_uint_16)PNG_DIV257(x))
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1531
      CHOP(png_ptr->background.red);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1532
      CHOP(png_ptr->background.green);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1533
      CHOP(png_ptr->background.blue);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1534
      CHOP(png_ptr->background.gray);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1535
#     undef CHOP
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
   }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1537
#endif /* READ_BACKGROUND && READ_EXPAND_16 */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1538
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1539
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1540
   (defined(PNG_READ_SCALE_16_TO_8_SUPPORTED) || \
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1541
   defined(PNG_READ_STRIP_16_TO_8_SUPPORTED))
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1542
   if ((png_ptr->transformations & (PNG_16_TO_8|PNG_SCALE_16_TO_8)) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1543
       (png_ptr->transformations & PNG_COMPOSE) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1544
       (png_ptr->transformations & PNG_BACKGROUND_EXPAND) == 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1545
       png_ptr->bit_depth == 16)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1546
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1547
      /* On the other hand, if a 16-bit file is to be reduced to 8-bits per
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1548
       * component this will also happen after PNG_COMPOSE and so the background
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1549
       * color must be pre-expanded here.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1550
       *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1551
       * TODO: fix this too.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1552
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1553
      png_ptr->background.red = (png_uint_16)(png_ptr->background.red * 257);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1554
      png_ptr->background.green =
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1555
         (png_uint_16)(png_ptr->background.green * 257);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1556
      png_ptr->background.blue = (png_uint_16)(png_ptr->background.blue * 257);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1557
      png_ptr->background.gray = (png_uint_16)(png_ptr->background.gray * 257);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1558
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1559
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1560
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1561
   /* NOTE: below 'PNG_READ_ALPHA_MODE_SUPPORTED' is presumed to also enable the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1562
    * background support (see the comments in scripts/pnglibconf.dfa), this
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1563
    * allows pre-multiplication of the alpha channel to be implemented as
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1564
    * compositing on black.  This is probably sub-optimal and has been done in
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1565
    * 1.5.4 betas simply to enable external critique and testing (i.e. to
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1566
    * implement the new API quickly, without lots of internal changes.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1567
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1568
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1569
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1570
#  ifdef PNG_READ_BACKGROUND_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1571
      /* Includes ALPHA_MODE */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1572
      png_ptr->background_1 = png_ptr->background;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1573
#  endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1574
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1575
   /* This needs to change - in the palette image case a whole set of tables are
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1576
    * built when it would be quicker to just calculate the correct value for
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1577
    * each palette entry directly.  Also, the test is too tricky - why check
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1578
    * PNG_RGB_TO_GRAY if PNG_GAMMA is not set?  The answer seems to be that
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1579
    * PNG_GAMMA is cancelled even if the gamma is known?  The test excludes the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1580
    * PNG_COMPOSE case, so apparently if there is no *overall* gamma correction
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1581
    * the gamma tables will not be built even if composition is required on a
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1582
    * gamma encoded value.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1583
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1584
    * In 1.5.4 this is addressed below by an additional check on the individual
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1585
    * file gamma - if it is not 1.0 both RGB_TO_GRAY and COMPOSE need the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1586
    * tables.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1587
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1588
   if ((png_ptr->transformations & PNG_GAMMA) != 0 ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1589
       ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1590
        (png_gamma_significant(png_ptr->colorspace.gamma) != 0 ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1591
         png_gamma_significant(png_ptr->screen_gamma) != 0)) ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1592
        ((png_ptr->transformations & PNG_COMPOSE) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1593
         (png_gamma_significant(png_ptr->colorspace.gamma) != 0 ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1594
          png_gamma_significant(png_ptr->screen_gamma) != 0
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1595
#  ifdef PNG_READ_BACKGROUND_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1596
         || (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_UNIQUE &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1597
           png_gamma_significant(png_ptr->background_gamma) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1598
#  endif
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1599
        )) || ((png_ptr->transformations & PNG_ENCODE_ALPHA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1600
       png_gamma_significant(png_ptr->screen_gamma) != 0))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1602
      png_build_gamma_table(png_ptr, png_ptr->bit_depth);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1603
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1604
#ifdef PNG_READ_BACKGROUND_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1605
      if ((png_ptr->transformations & PNG_COMPOSE) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1607
         /* Issue a warning about this combination: because RGB_TO_GRAY is
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1608
          * optimized to do the gamma transform if present yet do_background has
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1609
          * to do the same thing if both options are set a
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1610
          * double-gamma-correction happens.  This is true in all versions of
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1611
          * libpng to date.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1612
          */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1613
         if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1614
            png_warning(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1615
               "libpng does not support gamma+background+rgb_to_gray");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1616
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1617
         if ((png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1619
            /* We don't get to here unless there is a tRNS chunk with non-opaque
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1620
             * entries - see the checking code at the start of this function.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1621
             */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
            png_color back, back_1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
            png_colorp palette = png_ptr->palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
            int num_palette = png_ptr->num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
            if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1628
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
               back.red = png_ptr->gamma_table[png_ptr->background.red];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
               back.green = png_ptr->gamma_table[png_ptr->background.green];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
               back.blue = png_ptr->gamma_table[png_ptr->background.blue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
               back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
               back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
               back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1639
               png_fixed_point g, gs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
               switch (png_ptr->background_gamma_type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                  case PNG_BACKGROUND_GAMMA_SCREEN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                     g = (png_ptr->screen_gamma);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1645
                     gs = PNG_FP_1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
                     break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1647
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
                  case PNG_BACKGROUND_GAMMA_FILE:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1649
                     g = png_reciprocal(png_ptr->colorspace.gamma);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1650
                     gs = png_reciprocal2(png_ptr->colorspace.gamma,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1651
                        png_ptr->screen_gamma);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                     break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1653
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                  case PNG_BACKGROUND_GAMMA_UNIQUE:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1655
                     g = png_reciprocal(png_ptr->background_gamma);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1656
                     gs = png_reciprocal2(png_ptr->background_gamma,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1657
                        png_ptr->screen_gamma);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
                     break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
                  default:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1660
                     g = PNG_FP_1;    /* back_1 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1661
                     gs = PNG_FP_1;   /* back */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1662
                     break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1665
               if (png_gamma_significant(gs) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1666
               {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1667
                  back.red = png_gamma_8bit_correct(png_ptr->background.red,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1668
                      gs);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1669
                  back.green = png_gamma_8bit_correct(png_ptr->background.green,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1670
                      gs);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1671
                  back.blue = png_gamma_8bit_correct(png_ptr->background.blue,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1672
                      gs);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1673
               }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1674
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1675
               else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                  back.red   = (png_byte)png_ptr->background.red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                  back.green = (png_byte)png_ptr->background.green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                  back.blue  = (png_byte)png_ptr->background.blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1681
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1682
               if (png_gamma_significant(g) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1683
               {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1684
                  back_1.red = png_gamma_8bit_correct(png_ptr->background.red,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1685
                     g);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1686
                  back_1.green = png_gamma_8bit_correct(
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1687
                     png_ptr->background.green, g);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1688
                  back_1.blue = png_gamma_8bit_correct(png_ptr->background.blue,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1689
                     g);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1690
               }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1691
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
               {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1694
                  back_1.red   = (png_byte)png_ptr->background.red;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1695
                  back_1.green = (png_byte)png_ptr->background.green;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1696
                  back_1.blue  = (png_byte)png_ptr->background.blue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1699
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
            for (i = 0; i < num_palette; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1702
               if (i < (int)png_ptr->num_trans &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1703
                   png_ptr->trans_alpha[i] != 0xff)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
               {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1705
                  if (png_ptr->trans_alpha[i] == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
                     palette[i] = back;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1709
                  else /* if (png_ptr->trans_alpha[i] != 0xff) */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
                     png_byte v, w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
                     v = png_ptr->gamma_to_1[palette[i].red];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1714
                     png_composite(w, v, png_ptr->trans_alpha[i], back_1.red);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
                     palette[i].red = png_ptr->gamma_from_1[w];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
                     v = png_ptr->gamma_to_1[palette[i].green];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1718
                     png_composite(w, v, png_ptr->trans_alpha[i], back_1.green);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
                     palette[i].green = png_ptr->gamma_from_1[w];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
                     v = png_ptr->gamma_to_1[palette[i].blue];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1722
                     png_composite(w, v, png_ptr->trans_alpha[i], back_1.blue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
                     palette[i].blue = png_ptr->gamma_from_1[w];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
                  palette[i].red = png_ptr->gamma_table[palette[i].red];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
                  palette[i].green = png_ptr->gamma_table[palette[i].green];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
                  palette[i].blue = png_ptr->gamma_table[palette[i].blue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1733
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1734
            /* Prevent the transformations being done again.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1735
             *
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1736
             * NOTE: this is highly dubious; it removes the transformations in
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1737
             * place.  This seems inconsistent with the general treatment of the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1738
             * transformations elsewhere.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1739
             */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1740
            png_ptr->transformations &= ~(PNG_COMPOSE | PNG_GAMMA);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1741
         } /* color_type == PNG_COLOR_TYPE_PALETTE */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1742
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
         /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1744
         else /* color_type != PNG_COLOR_TYPE_PALETTE */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1746
            int gs_sig, g_sig;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1747
            png_fixed_point g = PNG_FP_1;  /* Correction to linear */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1748
            png_fixed_point gs = PNG_FP_1; /* Correction to screen */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
            switch (png_ptr->background_gamma_type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
               case PNG_BACKGROUND_GAMMA_SCREEN:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1753
                  g = png_ptr->screen_gamma;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1754
                  /* gs = PNG_FP_1; */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
                  break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1756
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
               case PNG_BACKGROUND_GAMMA_FILE:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1758
                  g = png_reciprocal(png_ptr->colorspace.gamma);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1759
                  gs = png_reciprocal2(png_ptr->colorspace.gamma,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1760
                     png_ptr->screen_gamma);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                  break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1762
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
               case PNG_BACKGROUND_GAMMA_UNIQUE:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1764
                  g = png_reciprocal(png_ptr->background_gamma);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1765
                  gs = png_reciprocal2(png_ptr->background_gamma,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1766
                      png_ptr->screen_gamma);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
                  break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1768
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1769
               default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1770
                  png_error(png_ptr, "invalid background gamma type");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1773
            g_sig = png_gamma_significant(g);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1774
            gs_sig = png_gamma_significant(gs);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1775
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1776
            if (g_sig != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1777
               png_ptr->background_1.gray = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1778
                   png_ptr->background.gray, g);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1779
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1780
            if (gs_sig != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1781
               png_ptr->background.gray = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1782
                   png_ptr->background.gray, gs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
            if ((png_ptr->background.red != png_ptr->background.green) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
                (png_ptr->background.red != png_ptr->background.blue) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                (png_ptr->background.red != png_ptr->background.gray))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
               /* RGB or RGBA with color background */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1789
               if (g_sig != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1790
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1791
                  png_ptr->background_1.red = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1792
                      png_ptr->background.red, g);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1793
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1794
                  png_ptr->background_1.green = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1795
                      png_ptr->background.green, g);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1796
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1797
                  png_ptr->background_1.blue = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1798
                      png_ptr->background.blue, g);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1799
               }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1800
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1801
               if (gs_sig != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1802
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1803
                  png_ptr->background.red = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1804
                      png_ptr->background.red, gs);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1805
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1806
                  png_ptr->background.green = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1807
                      png_ptr->background.green, gs);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1808
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1809
                  png_ptr->background.blue = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1810
                      png_ptr->background.blue, gs);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1811
               }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1813
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
               /* GRAY, GRAY ALPHA, RGB, or RGBA with gray background */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
               png_ptr->background_1.red = png_ptr->background_1.green
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1818
                   = png_ptr->background_1.blue = png_ptr->background_1.gray;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1819
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
               png_ptr->background.red = png_ptr->background.green
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1821
                   = png_ptr->background.blue = png_ptr->background.gray;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
            }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1823
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1824
            /* The background is now in screen gamma: */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1825
            png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_SCREEN;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1826
         } /* color_type != PNG_COLOR_TYPE_PALETTE */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1827
      }/* png_ptr->transformations & PNG_BACKGROUND */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1828
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
      else
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1830
      /* Transformation does not include PNG_BACKGROUND */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1831
#endif /* READ_BACKGROUND */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1832
      if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1833
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1834
         /* RGB_TO_GRAY needs to have non-gamma-corrected values! */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1835
         && ((png_ptr->transformations & PNG_EXPAND) == 0 ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1836
         (png_ptr->transformations & PNG_RGB_TO_GRAY) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1837
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1838
         )
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
         png_colorp palette = png_ptr->palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
         int num_palette = png_ptr->num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
         int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1844
         /* NOTE: there are other transformations that should probably be in
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1845
          * here too.
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1846
          */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
         for (i = 0; i < num_palette; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
            palette[i].red = png_ptr->gamma_table[palette[i].red];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
            palette[i].green = png_ptr->gamma_table[palette[i].green];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
            palette[i].blue = png_ptr->gamma_table[palette[i].blue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1853
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1854
         /* Done the gamma correction. */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1855
         png_ptr->transformations &= ~PNG_GAMMA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1856
      } /* color_type == PALETTE && !PNG_BACKGROUND transformation */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1858
#ifdef PNG_READ_BACKGROUND_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
#endif
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1861
#endif /* READ_GAMMA */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1862
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1863
#ifdef PNG_READ_BACKGROUND_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1864
   /* No GAMMA transformation (see the hanging else 4 lines above) */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1865
   if ((png_ptr->transformations & PNG_COMPOSE) != 0 &&
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1866
       (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
      int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
      int istop = (int)png_ptr->num_trans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
      png_color back;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
      png_colorp palette = png_ptr->palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
      back.red   = (png_byte)png_ptr->background.red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
      back.green = (png_byte)png_ptr->background.green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
      back.blue  = (png_byte)png_ptr->background.blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
      for (i = 0; i < istop; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1879
         if (png_ptr->trans_alpha[i] == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
            palette[i] = back;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1883
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1884
         else if (png_ptr->trans_alpha[i] != 0xff)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
            /* The png_composite() macro is defined in png.h */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
            png_composite(palette[i].red, palette[i].red,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1888
                png_ptr->trans_alpha[i], back.red);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1889
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
            png_composite(palette[i].green, palette[i].green,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1891
                png_ptr->trans_alpha[i], back.green);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1892
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
            png_composite(palette[i].blue, palette[i].blue,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1894
                png_ptr->trans_alpha[i], back.blue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1897
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1898
      png_ptr->transformations &= ~PNG_COMPOSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
   }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1900
#endif /* READ_BACKGROUND */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1902
#ifdef PNG_READ_SHIFT_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1903
   if ((png_ptr->transformations & PNG_SHIFT) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1904
       (png_ptr->transformations & PNG_EXPAND) == 0 &&
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1905
       (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1907
      int i;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1908
      int istop = png_ptr->num_palette;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1909
      int shift = 8 - png_ptr->sig_bit.red;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1910
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1911
      png_ptr->transformations &= ~PNG_SHIFT;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1912
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1913
      /* significant bits can be in the range 1 to 7 for a meaninful result, if
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1914
       * the number of significant bits is 0 then no shift is done (this is an
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1915
       * error condition which is silently ignored.)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1916
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1917
      if (shift > 0 && shift < 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1918
         for (i=0; i<istop; ++i)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1919
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1920
            int component = png_ptr->palette[i].red;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1921
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1922
            component >>= shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1923
            png_ptr->palette[i].red = (png_byte)component;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1924
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1925
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1926
      shift = 8 - png_ptr->sig_bit.green;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1927
      if (shift > 0 && shift < 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1928
         for (i=0; i<istop; ++i)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1929
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1930
            int component = png_ptr->palette[i].green;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1931
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1932
            component >>= shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1933
            png_ptr->palette[i].green = (png_byte)component;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1934
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1935
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1936
      shift = 8 - png_ptr->sig_bit.blue;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1937
      if (shift > 0 && shift < 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1938
         for (i=0; i<istop; ++i)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1939
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1940
            int component = png_ptr->palette[i].blue;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1941
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1942
            component >>= shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1943
            png_ptr->palette[i].blue = (png_byte)component;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1944
         }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
   }
40436
94ae0ede53a5 8155690: Update libPNG library to the latest up-to-date
azvegint
parents: 35692
diff changeset
  1946
#endif /* READ_SHIFT */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
/* Modify the info structure to reflect the transformations.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
 * info should be updated so a PNG file could be written with it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
 * assuming the transformations result in valid PNG data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
void /* PRIVATE */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1954
png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1956
   png_debug(1, "in png_read_transform_info");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1957
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1958
#ifdef PNG_READ_EXPAND_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1959
   if ((png_ptr->transformations & PNG_EXPAND) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1963
         /* This check must match what actually happens in
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1964
          * png_do_expand_palette; if it ever checks the tRNS chunk to see if
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1965
          * it is all opaque we must do the same (at present it does not.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1966
          */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1967
         if (png_ptr->num_trans > 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
            info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1969
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
            info_ptr->color_type = PNG_COLOR_TYPE_RGB;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1972
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
         info_ptr->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
         info_ptr->num_trans = 0;
23903
3e78d4a02113 8031352: Enhance PNG handling
serb
parents: 10576
diff changeset
  1975
3e78d4a02113 8031352: Enhance PNG handling
serb
parents: 10576
diff changeset
  1976
         if (png_ptr->palette == NULL)
3e78d4a02113 8031352: Enhance PNG handling
serb
parents: 10576
diff changeset
  1977
            png_error (png_ptr, "Palette is NULL in indexed image");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1981
         if (png_ptr->num_trans != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1983
            if ((png_ptr->transformations & PNG_EXPAND_tRNS) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1984
               info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
         if (info_ptr->bit_depth < 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
            info_ptr->bit_depth = 8;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1988
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
         info_ptr->num_trans = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1994
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1995
   defined(PNG_READ_ALPHA_MODE_SUPPORTED)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1996
   /* The following is almost certainly wrong unless the background value is in
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1997
    * the screen space!
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1998
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1999
   if ((png_ptr->transformations & PNG_COMPOSE) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
      info_ptr->background = png_ptr->background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2003
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2004
   /* The following used to be conditional on PNG_GAMMA (prior to 1.5.4),
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2005
    * however it seems that the code in png_init_read_transformations, which has
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2006
    * been called before this from png_read_update_info->png_read_start_row
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2007
    * sometimes does the gamma transform and cancels the flag.
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2008
    *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2009
    * TODO: this looks wrong; the info_ptr should end up with a gamma equal to
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2010
    * the screen_gamma value.  The following probably results in weirdness if
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2011
    * the info_ptr is used by the app after the rows have been read.
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2012
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2013
   info_ptr->colorspace.gamma = png_ptr->colorspace.gamma;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2014
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2015
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2016
   if (info_ptr->bit_depth == 16)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2018
#  ifdef PNG_READ_16BIT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2019
#     ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2020
         if ((png_ptr->transformations & PNG_SCALE_16_TO_8) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2021
            info_ptr->bit_depth = 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2022
#     endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2023
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2024
#     ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2025
         if ((png_ptr->transformations & PNG_16_TO_8) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2026
            info_ptr->bit_depth = 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2027
#     endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2028
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2029
#  else
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2030
      /* No 16-bit support: force chopping 16-bit input down to 8, in this case
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2031
       * the app program can chose if both APIs are available by setting the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2032
       * correct scaling to use.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2033
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2034
#     ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2035
         /* For compatibility with previous versions use the strip method by
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2036
          * default.  This code works because if PNG_SCALE_16_TO_8 is already
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2037
          * set the code below will do that in preference to the chop.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2038
          */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2039
         png_ptr->transformations |= PNG_16_TO_8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2040
         info_ptr->bit_depth = 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2041
#     else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2042
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2043
#        ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2044
            png_ptr->transformations |= PNG_SCALE_16_TO_8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2045
            info_ptr->bit_depth = 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2046
#        else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2047
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2048
            CONFIGURATION ERROR: you must enable at least one 16 to 8 method
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2049
#        endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2050
#    endif
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2051
#endif /* !READ_16BIT */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2053
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2054
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2055
   if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2056
      info_ptr->color_type = (png_byte)(info_ptr->color_type |
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2057
         PNG_COLOR_MASK_COLOR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2060
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2061
   if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2062
      info_ptr->color_type = (png_byte)(info_ptr->color_type &
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2063
         ~PNG_COLOR_MASK_COLOR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2066
#ifdef PNG_READ_QUANTIZE_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2067
   if ((png_ptr->transformations & PNG_QUANTIZE) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
      if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2070
          (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2071
          png_ptr->palette_lookup != 0 && info_ptr->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
         info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2078
#ifdef PNG_READ_EXPAND_16_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2079
   if ((png_ptr->transformations & PNG_EXPAND_16) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2080
       info_ptr->bit_depth == 8 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2081
       info_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2082
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2083
      info_ptr->bit_depth = 16;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2084
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2085
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2086
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2087
#ifdef PNG_READ_PACK_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2088
   if ((png_ptr->transformations & PNG_PACK) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2089
       (info_ptr->bit_depth < 8))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
      info_ptr->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
   if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
      info_ptr->channels = 1;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2095
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2096
   else if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
      info_ptr->channels = 3;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2098
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
      info_ptr->channels = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2102
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2103
   if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2104
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2105
      info_ptr->color_type = (png_byte)(info_ptr->color_type &
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2106
         ~PNG_COLOR_MASK_ALPHA);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2107
      info_ptr->num_trans = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2108
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2111
   if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
      info_ptr->channels++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2114
#ifdef PNG_READ_FILLER_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
   /* STRIP_ALPHA and FILLER allowed:  MASK_ALPHA bit stripped above */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2116
   if ((png_ptr->transformations & PNG_FILLER) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2117
       (info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2118
       info_ptr->color_type == PNG_COLOR_TYPE_GRAY))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
      info_ptr->channels++;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2121
      /* If adding a true alpha channel not just filler */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2122
      if ((png_ptr->transformations & PNG_ADD_ALPHA) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2123
         info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2129
   if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2130
   {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2131
      if (png_ptr->user_transform_depth != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
         info_ptr->bit_depth = png_ptr->user_transform_depth;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2133
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2134
      if (png_ptr->user_transform_channels != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
         info_ptr->channels = png_ptr->user_transform_channels;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2136
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
   info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2140
       info_ptr->bit_depth);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2141
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2142
   info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, info_ptr->width);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2143
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2144
   /* Adding in 1.5.4: cache the above value in png_struct so that we can later
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2145
    * check in png_rowbytes that the user buffer won't get overwritten.  Note
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2146
    * that the field is not always set - if png_read_update_info isn't called
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2147
    * the application has to either not do any transforms or get the calculation
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2148
    * right itself.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2149
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2150
   png_ptr->info_rowbytes = info_ptr->rowbytes;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2151
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2152
#ifndef PNG_READ_EXPAND_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2153
   if (png_ptr != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2158
#ifdef PNG_READ_PACK_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
/* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
 * without changing the actual values.  Thus, if you had a row with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
 * a bit depth of 1, you would end up with bytes that only contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
 * the numbers 0 or 1.  If you would rather they contain 0 and 255, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
 * png_do_shift() after this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2165
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
png_do_unpack(png_row_infop row_info, png_bytep row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2168
   png_debug(1, "in png_do_unpack");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2169
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
   if (row_info->bit_depth < 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
      png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
      png_uint_32 row_width=row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
      switch (row_info->bit_depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
         case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
            png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
            png_bytep dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
            png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
               *dp = (png_byte)((*sp >> shift) & 0x01);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2185
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
               if (shift == 7)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
                  shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
                  sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2191
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
                  shift++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
               dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2199
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
         case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
            png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
            png_bytep dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
            png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
               *dp = (png_byte)((*sp >> shift) & 0x03);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2209
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
               if (shift == 6)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
                  shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
                  sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2215
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
                  shift += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
               dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2223
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
         case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
            png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
            png_bytep dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
            png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
               *dp = (png_byte)((*sp >> shift) & 0x0f);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2232
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
               if (shift == 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
                  shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
                  sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2238
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
                  shift = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
               dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2246
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2247
         default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2248
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
      row_info->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
      row_info->pixel_depth = (png_byte)(8 * row_info->channels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
      row_info->rowbytes = row_width * row_info->channels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2257
#ifdef PNG_READ_SHIFT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
/* Reverse the effects of png_do_shift.  This routine merely shifts the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
 * pixels back to their significant bits values.  Thus, if you have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
 * a row of bit depth 8, but only 5 are significant, this will shift
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
 * the values back to 0 through 31.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2263
static void
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2264
png_do_unshift(png_row_infop row_info, png_bytep row,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2265
    png_const_color_8p sig_bits)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
{
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2267
   int color_type;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2268
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2269
   png_debug(1, "in png_do_unshift");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2270
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2271
   /* The palette case has already been handled in the _init routine. */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2272
   color_type = row_info->color_type;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2273
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2274
   if (color_type != PNG_COLOR_TYPE_PALETTE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
      int shift[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
      int channels = 0;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2278
      int bit_depth = row_info->bit_depth;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2279
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2280
      if ((color_type & PNG_COLOR_MASK_COLOR) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2282
         shift[channels++] = bit_depth - sig_bits->red;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2283
         shift[channels++] = bit_depth - sig_bits->green;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2284
         shift[channels++] = bit_depth - sig_bits->blue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2286
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2289
         shift[channels++] = bit_depth - sig_bits->gray;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2291
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2292
      if ((color_type & PNG_COLOR_MASK_ALPHA) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2294
         shift[channels++] = bit_depth - sig_bits->alpha;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2298
         int c, have_shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2299
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2300
         for (c = have_shift = 0; c < channels; ++c)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2301
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2302
            /* A shift of more than the bit depth is an error condition but it
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2303
             * gets ignored here.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2304
             */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2305
            if (shift[c] <= 0 || shift[c] >= bit_depth)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2306
               shift[c] = 0;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2307
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2308
            else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2309
               have_shift = 1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2310
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2311
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2312
         if (have_shift == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2313
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2316
      switch (bit_depth)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2318
         default:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2319
         /* Must be 1bpp gray: should not be here! */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2320
            /* NOTREACHED */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2321
            break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2322
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
         case 2:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2324
         /* Must be 2bpp gray */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2325
         /* assert(channels == 1 && shift[0] == 1) */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2327
            png_bytep bp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2328
            png_bytep bp_end = bp + row_info->rowbytes;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2329
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2330
            while (bp < bp_end)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2332
               int b = (*bp >> 1) & 0x55;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2333
               *bp++ = (png_byte)b;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2337
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
         case 4:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2339
         /* Must be 4bpp gray */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2340
         /* assert(channels == 1) */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
            png_bytep bp = row;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2343
            png_bytep bp_end = bp + row_info->rowbytes;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2344
            int gray_shift = shift[0];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2345
            int mask =  0xf >> gray_shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2346
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2347
            mask |= mask << 4;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2348
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2349
            while (bp < bp_end)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2351
               int b = (*bp >> gray_shift) & mask;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2352
               *bp++ = (png_byte)b;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2356
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
         case 8:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2358
         /* Single byte components, G, GA, RGB, RGBA */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
            png_bytep bp = row;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2361
            png_bytep bp_end = bp + row_info->rowbytes;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2362
            int channel = 0;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2363
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2364
            while (bp < bp_end)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2366
               int b = *bp >> shift[channel];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2367
               if (++channel >= channels)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2368
                  channel = 0;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2369
               *bp++ = (png_byte)b;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2373
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2374
#ifdef PNG_READ_16BIT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
         case 16:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2376
         /* Double byte components, G, GA, RGB, RGBA */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
            png_bytep bp = row;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2379
            png_bytep bp_end = bp + row_info->rowbytes;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2380
            int channel = 0;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2381
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2382
            while (bp < bp_end)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2384
               int value = (bp[0] << 8) + bp[1];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2385
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2386
               value >>= shift[channel];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2387
               if (++channel >= channels)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2388
                  channel = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
               *bp++ = (png_byte)(value >> 8);
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2390
               *bp++ = (png_byte)value;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2394
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2400
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2401
/* Scale rows of bit depth 16 down to 8 accurately */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2402
static void
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2403
png_do_scale_16_to_8(png_row_infop row_info, png_bytep row)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2405
   png_debug(1, "in png_do_scale_16_to_8");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2406
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
   if (row_info->bit_depth == 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2409
      png_bytep sp = row; /* source */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2410
      png_bytep dp = row; /* destination */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2411
      png_bytep ep = sp + row_info->rowbytes; /* end+1 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2412
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2413
      while (sp < ep)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
      {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2415
         /* The input is an array of 16-bit components, these must be scaled to
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2416
          * 8 bits each.  For a 16-bit value V the required value (from the PNG
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2417
          * specification) is:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2418
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2419
          *    (V * 255) / 65535
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2420
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2421
          * This reduces to round(V / 257), or floor((V + 128.5)/257)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2422
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2423
          * Represent V as the two byte value vhi.vlo.  Make a guess that the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2424
          * result is the top byte of V, vhi, then the correction to this value
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2425
          * is:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2426
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2427
          *    error = floor(((V-vhi.vhi) + 128.5) / 257)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2428
          *          = floor(((vlo-vhi) + 128.5) / 257)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2429
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2430
          * This can be approximated using integer arithmetic (and a signed
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2431
          * shift):
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2432
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2433
          *    error = (vlo-vhi+128) >> 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2434
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2435
          * The approximate differs from the exact answer only when (vlo-vhi) is
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2436
          * 128; it then gives a correction of +1 when the exact correction is
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2437
          * 0.  This gives 128 errors.  The exact answer (correct for all 16-bit
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2438
          * input values) is:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2439
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2440
          *    error = (vlo-vhi+128)*65535 >> 24;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2441
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2442
          * An alternative arithmetic calculation which also gives no errors is:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2443
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2444
          *    (V * 255 + 32895) >> 16
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2445
          */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2446
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2447
         png_int_32 tmp = *sp++; /* must be signed! */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2448
         tmp += (((int)*sp++ - tmp + 128) * 65535) >> 24;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2449
         *dp++ = (png_byte)tmp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2451
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
      row_info->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
      row_info->pixel_depth = (png_byte)(8 * row_info->channels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
      row_info->rowbytes = row_info->width * row_info->channels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2459
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2460
static void
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2461
/* Simply discard the low byte.  This was the default behavior prior
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2462
 * to libpng-1.5.4.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2463
 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2464
png_do_chop(png_row_infop row_info, png_bytep row)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2465
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2466
   png_debug(1, "in png_do_chop");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2467
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2468
   if (row_info->bit_depth == 16)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2469
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2470
      png_bytep sp = row; /* source */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2471
      png_bytep dp = row; /* destination */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2472
      png_bytep ep = sp + row_info->rowbytes; /* end+1 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2473
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2474
      while (sp < ep)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2475
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2476
         *dp++ = *sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2477
         sp += 2; /* skip low byte */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2478
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2479
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2480
      row_info->bit_depth = 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2481
      row_info->pixel_depth = (png_byte)(8 * row_info->channels);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2482
      row_info->rowbytes = row_info->width * row_info->channels;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2483
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2484
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2485
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2486
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2487
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2488
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2491
   png_debug(1, "in png_do_read_swap_alpha");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2492
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
      png_uint_32 row_width = row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
      if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
         /* This converts from RGBA to ARGB */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
         if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
            png_bytep sp = row + row_info->rowbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
            png_bytep dp = sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
            png_byte save;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
            png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
               save = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
               *(--dp) = save;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2514
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2515
#ifdef PNG_READ_16BIT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
         /* This converts from RRGGBBAA to AARRGGBB */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
            png_bytep sp = row + row_info->rowbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
            png_bytep dp = sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
            png_byte save[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
            png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
               save[0] = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
               save[1] = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
               *(--dp) = save[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
               *(--dp) = save[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2538
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2540
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
      else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
         /* This converts from GA to AG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
         if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
            png_bytep sp = row + row_info->rowbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
            png_bytep dp = sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
            png_byte save;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
            png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
               save = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
               *(--dp) = save;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2558
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2559
#ifdef PNG_READ_16BIT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
         /* This converts from GGAA to AAGG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
            png_bytep sp = row + row_info->rowbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
            png_bytep dp = sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
            png_byte save[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
            png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
               save[0] = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
               save[1] = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
               *(--dp) = save[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
               *(--dp) = save[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2578
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2584
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2585
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2588
   png_uint_32 row_width;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2589
   png_debug(1, "in png_do_read_invert_alpha");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2590
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2591
   row_width = row_info->width;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2592
   if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2594
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
         /* This inverts the alpha channel in RGBA */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2597
         png_bytep sp = row + row_info->rowbytes;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2598
         png_bytep dp = sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2599
         png_uint_32 i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2600
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2601
         for (i = 0; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2603
            *(--dp) = (png_byte)(255 - *(--sp));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2604
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2605
/*          This does nothing:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2606
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2607
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2608
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2609
            We can replace it with:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
*/
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2611
            sp-=3;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2612
            dp=sp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2615
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2616
#ifdef PNG_READ_16BIT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2617
      /* This inverts the alpha channel in RRGGBBAA */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2618
      else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2619
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2620
         png_bytep sp = row + row_info->rowbytes;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2621
         png_bytep dp = sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2622
         png_uint_32 i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2623
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2624
         for (i = 0; i < row_width; i++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2625
         {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2626
            *(--dp) = (png_byte)(255 - *(--sp));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2627
            *(--dp) = (png_byte)(255 - *(--sp));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2628
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2629
/*          This does nothing:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2630
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2631
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2632
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2633
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2634
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2635
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2636
            We can replace it with:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2637
*/
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2638
            sp-=6;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2639
            dp=sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2640
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2641
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2642
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2643
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2644
   else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2645
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2646
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
         /* This inverts the alpha channel in GA */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2649
         png_bytep sp = row + row_info->rowbytes;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2650
         png_bytep dp = sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2651
         png_uint_32 i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2652
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2653
         for (i = 0; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2655
            *(--dp) = (png_byte)(255 - *(--sp));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2656
            *(--dp) = *(--sp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2659
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2660
#ifdef PNG_READ_16BIT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2661
      else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2662
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2663
         /* This inverts the alpha channel in GGAA */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2664
         png_bytep sp  = row + row_info->rowbytes;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2665
         png_bytep dp = sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2666
         png_uint_32 i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2667
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2668
         for (i = 0; i < row_width; i++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2669
         {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2670
            *(--dp) = (png_byte)(255 - *(--sp));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2671
            *(--dp) = (png_byte)(255 - *(--sp));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2672
/*
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2673
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2674
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2675
*/
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2676
            sp-=2;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2677
            dp=sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2678
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2679
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2680
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2685
#ifdef PNG_READ_FILLER_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
/* Add filler channel if we have RGB color */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2687
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
png_do_read_filler(png_row_infop row_info, png_bytep row,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2689
    png_uint_32 filler, png_uint_32 flags)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
   png_uint_32 row_width = row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2694
#ifdef PNG_READ_16BIT_SUPPORTED
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2695
   png_byte hi_filler = (png_byte)(filler>>8);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2696
#endif
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2697
   png_byte lo_filler = (png_byte)filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2699
   png_debug(1, "in png_do_read_filler");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2700
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
   if (
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
       row_info->color_type == PNG_COLOR_TYPE_GRAY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2704
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2706
         if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2708
            /* This changes the data from G to GX */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
            png_bytep sp = row + (png_size_t)row_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
            png_bytep dp =  sp + (png_size_t)row_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
            for (i = 1; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
               *(--dp) = lo_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
            *(--dp) = lo_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
            row_info->channels = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
            row_info->pixel_depth = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
            row_info->rowbytes = row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2721
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2724
            /* This changes the data from G to XG */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
            png_bytep sp = row + (png_size_t)row_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
            png_bytep dp = sp  + (png_size_t)row_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
               *(--dp) = lo_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
            row_info->channels = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
            row_info->pixel_depth = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
            row_info->rowbytes = row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2737
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2738
#ifdef PNG_READ_16BIT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2739
      else if (row_info->bit_depth == 16)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2741
         if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2743
            /* This changes the data from GG to GGXX */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
            png_bytep sp = row + (png_size_t)row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
            png_bytep dp = sp  + (png_size_t)row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
            for (i = 1; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
            {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2748
               *(--dp) = lo_filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
               *(--dp) = hi_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
            }
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2753
            *(--dp) = lo_filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
            *(--dp) = hi_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
            row_info->channels = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
            row_info->pixel_depth = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
            row_info->rowbytes = row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2759
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2762
            /* This changes the data from GG to XXGG */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
            png_bytep sp = row + (png_size_t)row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
            png_bytep dp = sp  + (png_size_t)row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
               *(--dp) = *(--sp);
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2769
               *(--dp) = lo_filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
               *(--dp) = hi_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
            row_info->channels = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
            row_info->pixel_depth = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
            row_info->rowbytes = row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2777
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
   } /* COLOR_TYPE == GRAY */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
   else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2781
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2783
         if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2785
            /* This changes the data from RGB to RGBX */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
            png_bytep sp = row + (png_size_t)row_width * 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
            png_bytep dp = sp  + (png_size_t)row_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
            for (i = 1; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
               *(--dp) = lo_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
            *(--dp) = lo_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
            row_info->channels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
            row_info->pixel_depth = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
            row_info->rowbytes = row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2800
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2803
            /* This changes the data from RGB to XRGB */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
            png_bytep sp = row + (png_size_t)row_width * 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
            png_bytep dp = sp + (png_size_t)row_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
               *(--dp) = lo_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
            row_info->channels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
            row_info->pixel_depth = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
            row_info->rowbytes = row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2818
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2819
#ifdef PNG_READ_16BIT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2820
      else if (row_info->bit_depth == 16)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2822
         if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2824
            /* This changes the data from RRGGBB to RRGGBBXX */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
            png_bytep sp = row + (png_size_t)row_width * 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
            png_bytep dp = sp  + (png_size_t)row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
            for (i = 1; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
            {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2829
               *(--dp) = lo_filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
               *(--dp) = hi_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
            }
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2838
            *(--dp) = lo_filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
            *(--dp) = hi_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
            row_info->channels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
            row_info->pixel_depth = 64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
            row_info->rowbytes = row_width * 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2844
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2847
            /* This changes the data from RRGGBB to XXRRGGBB */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
            png_bytep sp = row + (png_size_t)row_width * 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
            png_bytep dp = sp  + (png_size_t)row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
               *(--dp) = *(--sp);
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2858
               *(--dp) = lo_filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
               *(--dp) = hi_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2861
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
            row_info->channels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
            row_info->pixel_depth = 64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
            row_info->rowbytes = row_width * 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2867
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
   } /* COLOR_TYPE == RGB */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2872
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2873
/* Expand grayscale files to RGB, with or without alpha */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2874
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
   png_uint_32 row_width = row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2880
   png_debug(1, "in png_do_gray_to_rgb");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2881
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
   if (row_info->bit_depth >= 8 &&
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2883
       (row_info->color_type & PNG_COLOR_MASK_COLOR) == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
      if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
         if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2889
            /* This changes G to RGB */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
            png_bytep sp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
            png_bytep dp = sp  + (png_size_t)row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2899
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2902
            /* This changes GG to RRGGBB */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
            png_bytep sp = row + (png_size_t)row_width * 2 - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
            png_bytep dp = sp  + (png_size_t)row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
               *(dp--) = *(sp - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
               *(dp--) = *(sp - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2916
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
      else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
         if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2921
            /* This changes GA to RGBA */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
            png_bytep sp = row + (png_size_t)row_width * 2 - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
            png_bytep dp = sp  + (png_size_t)row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2932
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2935
            /* This changes GGAA to RRGGBBAA */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
            png_bytep sp = row + (png_size_t)row_width * 4 - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
            png_bytep dp = sp  + (png_size_t)row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
               *(dp--) = *(sp - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
               *(dp--) = *(sp - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
      }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2951
      row_info->channels = (png_byte)(row_info->channels + 2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
      row_info->color_type |= PNG_COLOR_MASK_COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
      row_info->pixel_depth = (png_byte)(row_info->channels *
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2954
          row_info->bit_depth);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2955
      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2960
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2961
/* Reduce RGB files to grayscale, with or without alpha
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2962
 * using the equation given in Poynton's ColorFAQ of 1998-01-04 at
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2963
 * <http://www.inforamp.net/~poynton/>  (THIS LINK IS DEAD June 2008 but
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2964
 * versions dated 1998 through November 2002 have been archived at
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2965
 * http://web.archive.org/web/20000816232553/http://www.inforamp.net/
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2966
 * ~poynton/notes/colour_and_gamma/ColorFAQ.txt )
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2967
 * Charles Poynton poynton at poynton.com
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
 *     Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
 *  which can be expressed with integers as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
 *     Y = (6969 * R + 23434 * G + 2365 * B)/32768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
 *
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2975
 * Poynton's current link (as of January 2003 through July 2011):
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2976
 * <http://www.poynton.com/notes/colour_and_gamma/>
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2977
 * has changed the numbers slightly:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2978
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2979
 *     Y = 0.2126*R + 0.7152*G + 0.0722*B
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2980
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2981
 *  which can be expressed with integers as
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2982
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2983
 *     Y = (6966 * R + 23436 * G + 2366 * B)/32768
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2984
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2985
 *  Historically, however, libpng uses numbers derived from the ITU-R Rec 709
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2986
 *  end point chromaticities and the D65 white point.  Depending on the
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2987
 *  precision used for the D65 white point this produces a variety of different
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2988
 *  numbers, however if the four decimal place value used in ITU-R Rec 709 is
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2989
 *  used (0.3127,0.3290) the Y calculation would be:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2990
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2991
 *     Y = (6968 * R + 23435 * G + 2366 * B)/32768
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
 *
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2993
 *  While this is correct the rounding results in an overflow for white, because
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2994
 *  the sum of the rounded coefficients is 32769, not 32768.  Consequently
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2995
 *  libpng uses, instead, the closest non-overflowing approximation:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2996
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2997
 *     Y = (6968 * R + 23434 * G + 2366 * B)/32768
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2998
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2999
 *  Starting with libpng-1.5.5, if the image being converted has a cHRM chunk
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3000
 *  (including an sRGB chunk) then the chromaticities are used to calculate the
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3001
 *  coefficients.  See the chunk handling in pngrutil.c for more information.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3002
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3003
 *  In all cases the calculation is to be done in a linear colorspace.  If no
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3004
 *  gamma information is available to correct the encoding of the original RGB
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3005
 *  values this results in an implicit assumption that the original PNG RGB
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3006
 *  values were linear.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3007
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3008
 *  Other integer coefficents can be used via png_set_rgb_to_gray().  Because
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3009
 *  the API takes just red and green coefficients the blue coefficient is
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3010
 *  calculated to make the sum 32768.  This will result in different rounding
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3011
 *  to that used above.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3013
static int
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3014
png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
   int rgb_error = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3019
   png_debug(1, "in png_do_rgb_to_gray");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3020
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3021
   if ((row_info->color_type & PNG_COLOR_MASK_PALETTE) == 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3022
       (row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3024
      PNG_CONST png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3025
      PNG_CONST png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3026
      PNG_CONST png_uint_32 bc = 32768 - rc - gc;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3027
      PNG_CONST png_uint_32 row_width = row_info->width;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3028
      PNG_CONST int have_alpha =
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3029
         (row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3030
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3031
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3033
#ifdef PNG_READ_GAMMA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3034
         /* Notice that gamma to/from 1 are not necessarily inverses (if
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3035
          * there is an overall gamma correction).  Prior to 1.5.5 this code
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3036
          * checked the linearized values for equality; this doesn't match
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3037
          * the documentation, the original values must be checked.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3038
          */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3039
         if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3041
            png_bytep sp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3042
            png_bytep dp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3043
            png_uint_32 i;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3044
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3045
            for (i = 0; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3047
               png_byte red   = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3048
               png_byte green = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3049
               png_byte blue  = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3050
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3051
               if (red != green || red != blue)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3052
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3053
                  red = png_ptr->gamma_to_1[red];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3054
                  green = png_ptr->gamma_to_1[green];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3055
                  blue = png_ptr->gamma_to_1[blue];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3056
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3057
                  rgb_error |= 1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3058
                  *(dp++) = png_ptr->gamma_from_1[
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3059
                      (rc*red + gc*green + bc*blue + 16384)>>15];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3060
               }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3061
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3062
               else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
               {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3064
                  /* If there is no overall correction the table will not be
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3065
                   * set.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3066
                   */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3067
                  if (png_ptr->gamma_table != NULL)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3068
                     red = png_ptr->gamma_table[red];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3069
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3070
                  *(dp++) = red;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3071
               }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3072
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3073
               if (have_alpha != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3074
                  *(dp++) = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3075
            }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3076
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3077
         else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3078
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3079
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3080
            png_bytep sp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3081
            png_bytep dp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3082
            png_uint_32 i;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3083
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3084
            for (i = 0; i < row_width; i++)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3085
            {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3086
               png_byte red   = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3087
               png_byte green = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3088
               png_byte blue  = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3089
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3090
               if (red != green || red != blue)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3091
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3092
                  rgb_error |= 1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3093
                  /* NOTE: this is the historical approach which simply
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3094
                   * truncates the results.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3095
                   */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3096
                  *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3097
               }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3098
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3099
               else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3100
                  *(dp++) = red;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3101
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3102
               if (have_alpha != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3103
                  *(dp++) = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3104
            }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3105
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3106
      }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3107
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3108
      else /* RGB bit_depth == 16 */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3109
      {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3110
#ifdef PNG_READ_GAMMA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3111
         if (png_ptr->gamma_16_to_1 != NULL && png_ptr->gamma_16_from_1 != NULL)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3112
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3113
            png_bytep sp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3114
            png_bytep dp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3115
            png_uint_32 i;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3116
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3117
            for (i = 0; i < row_width; i++)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3118
            {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3119
               png_uint_16 red, green, blue, w;
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3120
               png_byte hi,lo;
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3121
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3122
               hi=*(sp)++; lo=*(sp)++; red   = (png_uint_16)((hi << 8) | (lo));
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3123
               hi=*(sp)++; lo=*(sp)++; green = (png_uint_16)((hi << 8) | (lo));
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3124
               hi=*(sp)++; lo=*(sp)++; blue  = (png_uint_16)((hi << 8) | (lo));
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3125
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3126
               if (red == green && red == blue)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3127
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3128
                  if (png_ptr->gamma_16_table != NULL)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3129
                     w = png_ptr->gamma_16_table[(red & 0xff)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3130
                         >> png_ptr->gamma_shift][red >> 8];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3131
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
                  else
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3133
                     w = red;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
               }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3135
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3136
               else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
               {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3138
                  png_uint_16 red_1   = png_ptr->gamma_16_to_1[(red & 0xff)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3139
                      >> png_ptr->gamma_shift][red>>8];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3140
                  png_uint_16 green_1 =
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3141
                      png_ptr->gamma_16_to_1[(green & 0xff) >>
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3142
                      png_ptr->gamma_shift][green>>8];
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3143
                  png_uint_16 blue_1  = png_ptr->gamma_16_to_1[(blue & 0xff)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3144
                      >> png_ptr->gamma_shift][blue>>8];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3145
                  png_uint_16 gray16  = (png_uint_16)((rc*red_1 + gc*green_1
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3146
                      + bc*blue_1 + 16384)>>15);
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3147
                  w = png_ptr->gamma_16_from_1[(gray16 & 0xff) >>
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3148
                      png_ptr->gamma_shift][gray16 >> 8];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3149
                  rgb_error |= 1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3150
               }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3151
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3152
               *(dp++) = (png_byte)((w>>8) & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3153
               *(dp++) = (png_byte)(w & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3154
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3155
               if (have_alpha != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3156
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3157
                  *(dp++) = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3158
                  *(dp++) = *(sp++);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
         }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3162
         else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3163
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3165
            png_bytep sp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3166
            png_bytep dp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3167
            png_uint_32 i;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3168
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3169
            for (i = 0; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3171
               png_uint_16 red, green, blue, gray16;
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3172
               png_byte hi,lo;
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3173
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3174
               hi=*(sp)++; lo=*(sp)++; red   = (png_uint_16)((hi << 8) | (lo));
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3175
               hi=*(sp)++; lo=*(sp)++; green = (png_uint_16)((hi << 8) | (lo));
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3176
               hi=*(sp)++; lo=*(sp)++; blue  = (png_uint_16)((hi << 8) | (lo));
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3177
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3178
               if (red != green || red != blue)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3179
                  rgb_error |= 1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3180
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3181
               /* From 1.5.5 in the 16-bit case do the accurate conversion even
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3182
                * in the 'fast' case - this is because this is where the code
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3183
                * ends up when handling linear 16-bit data.
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3184
                */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3185
               gray16  = (png_uint_16)((rc*red + gc*green + bc*blue + 16384) >>
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3186
                  15);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3187
               *(dp++) = (png_byte)((gray16 >> 8) & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3188
               *(dp++) = (png_byte)(gray16 & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3189
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3190
               if (have_alpha != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
                  *(dp++) = *(sp++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
                  *(dp++) = *(sp++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
      }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3198
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3199
      row_info->channels = (png_byte)(row_info->channels - 2);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3200
      row_info->color_type = (png_byte)(row_info->color_type &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3201
          ~PNG_COLOR_MASK_COLOR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
      row_info->pixel_depth = (png_byte)(row_info->channels *
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3203
          row_info->bit_depth);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3204
      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
   return rgb_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
#endif
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3209
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3210
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3211
   defined(PNG_READ_ALPHA_MODE_SUPPORTED)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
/* Replace any alpha or transparency with the supplied background color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
 * "background" is already in the screen gamma, while "background_1" is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
 * at a gamma of 1.0.  Paletted files have already been taken care of.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3216
static void
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3217
png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3219
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3220
   png_const_bytep gamma_table = png_ptr->gamma_table;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3221
   png_const_bytep gamma_from_1 = png_ptr->gamma_from_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3222
   png_const_bytep gamma_to_1 = png_ptr->gamma_to_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3223
   png_const_uint_16pp gamma_16 = png_ptr->gamma_16_table;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3224
   png_const_uint_16pp gamma_16_from_1 = png_ptr->gamma_16_from_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3225
   png_const_uint_16pp gamma_16_to_1 = png_ptr->gamma_16_to_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3226
   int gamma_shift = png_ptr->gamma_shift;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3227
   int optimize = (png_ptr->flags & PNG_FLAG_OPTIMIZE_ALPHA) != 0;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3228
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3229
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3230
   png_bytep sp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
   png_uint_32 i;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3232
   png_uint_32 row_width = row_info->width;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
   int shift;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3235
   png_debug(1, "in png_do_compose");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3236
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
      switch (row_info->color_type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
         case PNG_COLOR_TYPE_GRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
            switch (row_info->bit_depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
               case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
                  sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
                  shift = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
                  for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
                     if ((png_uint_16)((*sp >> shift) & 0x01)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3251
                        == png_ptr->trans_color.gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
                     {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3253
                        unsigned int tmp = *sp & (0x7f7f >> (7 - shift));
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3254
                        tmp |= png_ptr->background.gray << shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3255
                        *sp = (png_byte)(tmp & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3257
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3258
                     if (shift == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
                        shift = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
                        sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3263
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
                        shift--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3269
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
               case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
               {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3272
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
                  if (gamma_table != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
                     sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
                     shift = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
                     for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
                        if ((png_uint_16)((*sp >> shift) & 0x03)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3280
                            == png_ptr->trans_color.gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
                        {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3282
                           unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3283
                           tmp |= png_ptr->background.gray << shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3284
                           *sp = (png_byte)(tmp & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3286
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
                        {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3289
                           unsigned int p = (*sp >> shift) & 0x03;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3290
                           unsigned int g = (gamma_table [p | (p << 2) |
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3291
                               (p << 4) | (p << 6)] >> 6) & 0x03;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3292
                           unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3293
                           tmp |= g << shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3294
                           *sp = (png_byte)(tmp & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3296
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3297
                        if (shift == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
                           shift = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
                           sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3302
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
                           shift -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3307
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
                     sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
                     shift = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
                     for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
                        if ((png_uint_16)((*sp >> shift) & 0x03)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3316
                            == png_ptr->trans_color.gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
                        {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3318
                           unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3319
                           tmp |= png_ptr->background.gray << shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3320
                           *sp = (png_byte)(tmp & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3322
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3323
                        if (shift == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
                           shift = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
                           sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3328
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
                           shift -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3335
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
               case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
               {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3338
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
                  if (gamma_table != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
                     sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
                     shift = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
                     for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
                        if ((png_uint_16)((*sp >> shift) & 0x0f)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3346
                            == png_ptr->trans_color.gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
                        {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3348
                           unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3349
                           tmp |= png_ptr->background.gray << shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3350
                           *sp = (png_byte)(tmp & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3352
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
                        {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3355
                           unsigned int p = (*sp >> shift) & 0x0f;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3356
                           unsigned int g = (gamma_table[p | (p << 4)] >> 4) &
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3357
                              0x0f;
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3358
                           unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3359
                           tmp |= g << shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3360
                           *sp = (png_byte)(tmp & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3362
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3363
                        if (shift == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
                           shift = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
                           sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3368
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
                           shift -= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3373
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
                     sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
                     shift = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
                     for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
                        if ((png_uint_16)((*sp >> shift) & 0x0f)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3382
                            == png_ptr->trans_color.gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
                        {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3384
                           unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3385
                           tmp |= png_ptr->background.gray << shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3386
                           *sp = (png_byte)(tmp & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3388
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3389
                        if (shift == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
                           shift = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
                           sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3394
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
                           shift -= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3401
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
               case 8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
               {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3404
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
                  if (gamma_table != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
                     sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
                     for (i = 0; i < row_width; i++, sp++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3410
                        if (*sp == png_ptr->trans_color.gray)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3411
                           *sp = (png_byte)png_ptr->background.gray;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3412
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
                           *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
                     sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
                     for (i = 0; i < row_width; i++, sp++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3423
                        if (*sp == png_ptr->trans_color.gray)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3424
                           *sp = (png_byte)png_ptr->background.gray;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3429
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
               case 16:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
               {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3432
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
                  if (gamma_16 != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
                     sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
                     for (i = 0; i < row_width; i++, sp += 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
                        png_uint_16 v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
                        v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3441
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3442
                        if (v == png_ptr->trans_color.gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
                        {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3444
                           /* Background is already in screen gamma */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3445
                           *sp = (png_byte)((png_ptr->background.gray >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3446
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3447
                           *(sp + 1) = (png_byte)(png_ptr->background.gray
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3448
                                & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3450
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
                           v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
                           *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
                           *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
                     sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
                     for (i = 0; i < row_width; i++, sp += 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
                        png_uint_16 v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
                        v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3468
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3469
                        if (v == png_ptr->trans_color.gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
                        {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3471
                           *sp = (png_byte)((png_ptr->background.gray >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3472
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3473
                           *(sp + 1) = (png_byte)(png_ptr->background.gray
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3474
                                & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3480
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3481
               default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3482
                  break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3486
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
         case PNG_COLOR_TYPE_RGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
            if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3491
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
               if (gamma_table != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
                  sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
                  for (i = 0; i < row_width; i++, sp += 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
                  {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3497
                     if (*sp == png_ptr->trans_color.red &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3498
                         *(sp + 1) == png_ptr->trans_color.green &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3499
                         *(sp + 2) == png_ptr->trans_color.blue)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3501
                        *sp = (png_byte)png_ptr->background.red;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3502
                        *(sp + 1) = (png_byte)png_ptr->background.green;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3503
                        *(sp + 2) = (png_byte)png_ptr->background.blue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3505
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
                        *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
                        *(sp + 1) = gamma_table[*(sp + 1)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
                        *(sp + 2) = gamma_table[*(sp + 2)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
                  sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
                  for (i = 0; i < row_width; i++, sp += 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
                  {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3520
                     if (*sp == png_ptr->trans_color.red &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3521
                         *(sp + 1) == png_ptr->trans_color.green &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3522
                         *(sp + 2) == png_ptr->trans_color.blue)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3524
                        *sp = (png_byte)png_ptr->background.red;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3525
                        *(sp + 1) = (png_byte)png_ptr->background.green;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3526
                        *(sp + 2) = (png_byte)png_ptr->background.blue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
            else /* if (row_info->bit_depth == 16) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3533
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
               if (gamma_16 != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
                  sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
                  for (i = 0; i < row_width; i++, sp += 6)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
                     png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3540
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3541
                     png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3542
                         + *(sp + 3));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3543
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3544
                     png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3545
                         + *(sp + 5));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3546
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3547
                     if (r == png_ptr->trans_color.red &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3548
                         g == png_ptr->trans_color.green &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3549
                         b == png_ptr->trans_color.blue)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3551
                        /* Background is already in screen gamma */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3552
                        *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3553
                        *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3554
                        *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3555
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3556
                        *(sp + 3) = (png_byte)(png_ptr->background.green
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3557
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3558
                        *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3559
                                & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3560
                        *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3562
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
                        png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
                        *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
                        *(sp + 1) = (png_byte)(v & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3568
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
                        v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
                        *(sp + 2) = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
                        *(sp + 3) = (png_byte)(v & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3572
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
                        v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
                        *(sp + 4) = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
                        *(sp + 5) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3579
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3580
               else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3581
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3582
               {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3583
                  sp = row;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3584
                  for (i = 0; i < row_width; i++, sp += 6)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3585
                  {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3586
                     png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3587
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3588
                     png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3589
                         + *(sp + 3));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3590
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3591
                     png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3592
                         + *(sp + 5));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3593
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3594
                     if (r == png_ptr->trans_color.red &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3595
                         g == png_ptr->trans_color.green &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3596
                         b == png_ptr->trans_color.blue)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3597
                     {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3598
                        *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3599
                        *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3600
                        *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3601
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3602
                        *(sp + 3) = (png_byte)(png_ptr->background.green
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3603
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3604
                        *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3605
                                & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3606
                        *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3607
                     }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3608
                  }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3609
               }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3610
            }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3611
            break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3612
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3613
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3614
         case PNG_COLOR_TYPE_GRAY_ALPHA:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3615
         {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3616
            if (row_info->bit_depth == 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3617
            {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3618
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3619
               if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3620
                   gamma_table != NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3621
               {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3622
                  sp = row;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3623
                  for (i = 0; i < row_width; i++, sp += 2)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3624
                  {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3625
                     png_uint_16 a = *(sp + 1);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3626
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3627
                     if (a == 0xff)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3628
                        *sp = gamma_table[*sp];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3629
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3630
                     else if (a == 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3631
                     {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3632
                        /* Background is already in screen gamma */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3633
                        *sp = (png_byte)png_ptr->background.gray;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3634
                     }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3635
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3636
                     else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3637
                     {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3638
                        png_byte v, w;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3639
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3640
                        v = gamma_to_1[*sp];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3641
                        png_composite(w, v, a, png_ptr->background_1.gray);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3642
                        if (optimize == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3643
                           w = gamma_from_1[w];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3644
                        *sp = w;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3645
                     }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3646
                  }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3647
               }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3649
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3650
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3651
                  sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3652
                  for (i = 0; i < row_width; i++, sp += 2)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3653
                  {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3654
                     png_byte a = *(sp + 1);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3655
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3656
                     if (a == 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3657
                        *sp = (png_byte)png_ptr->background.gray;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3658
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3659
                     else if (a < 0xff)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3660
                        png_composite(*sp, *sp, a, png_ptr->background.gray);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3663
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3664
            else /* if (png_ptr->bit_depth == 16) */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3666
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3667
               if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3668
                   gamma_16_to_1 != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
                  sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3671
                  for (i = 0; i < row_width; i++, sp += 4)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3672
                  {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3673
                     png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3674
                         + *(sp + 3));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3675
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3676
                     if (a == (png_uint_16)0xffff)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3678
                        png_uint_16 v;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3679
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3680
                        v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3681
                        *sp = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3682
                        *(sp + 1) = (png_byte)(v & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3684
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
                     else if (a == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3687
                        /* Background is already in screen gamma */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3688
                        *sp = (png_byte)((png_ptr->background.gray >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3689
                                & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3690
                        *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3692
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3693
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3695
                        png_uint_16 g, v, w;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3696
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3697
                        g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3698
                        png_composite_16(v, g, a, png_ptr->background_1.gray);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3699
                        if (optimize != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3700
                           w = v;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3701
                        else
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3702
                           w = gamma_16_from_1[(v & 0xff) >>
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3703
                               gamma_shift][v >> 8];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3704
                        *sp = (png_byte)((w >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3705
                        *(sp + 1) = (png_byte)(w & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3706
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3707
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3708
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3710
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3711
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3712
                  sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3713
                  for (i = 0; i < row_width; i++, sp += 4)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3714
                  {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3715
                     png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3716
                         + *(sp + 3));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3717
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3718
                     if (a == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3719
                     {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3720
                        *sp = (png_byte)((png_ptr->background.gray >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3721
                                & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3722
                        *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3724
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3725
                     else if (a < 0xffff)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
                        png_uint_16 g, v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3728
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3729
                        g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3730
                        png_composite_16(v, g, a, png_ptr->background.gray);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3731
                        *sp = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3732
                        *(sp + 1) = (png_byte)(v & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3733
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3734
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3736
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3737
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3739
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
         case PNG_COLOR_TYPE_RGB_ALPHA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
            if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3743
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3744
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
               if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3746
                   gamma_table != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3747
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
                  sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3749
                  for (i = 0; i < row_width; i++, sp += 4)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3750
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
                     png_byte a = *(sp + 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3752
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
                     if (a == 0xff)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3754
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3755
                        *sp = gamma_table[*sp];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3756
                        *(sp + 1) = gamma_table[*(sp + 1)];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3757
                        *(sp + 2) = gamma_table[*(sp + 2)];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3758
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3759
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
                     else if (a == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3762
                        /* Background is already in screen gamma */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3763
                        *sp = (png_byte)png_ptr->background.red;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3764
                        *(sp + 1) = (png_byte)png_ptr->background.green;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3765
                        *(sp + 2) = (png_byte)png_ptr->background.blue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3767
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3770
                        png_byte v, w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3772
                        v = gamma_to_1[*sp];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3773
                        png_composite(w, v, a, png_ptr->background_1.red);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3774
                        if (optimize == 0) w = gamma_from_1[w];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3775
                        *sp = w;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3776
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3777
                        v = gamma_to_1[*(sp + 1)];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3778
                        png_composite(w, v, a, png_ptr->background_1.green);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3779
                        if (optimize == 0) w = gamma_from_1[w];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3780
                        *(sp + 1) = w;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3781
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
                        v = gamma_to_1[*(sp + 2)];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3783
                        png_composite(w, v, a, png_ptr->background_1.blue);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3784
                        if (optimize == 0) w = gamma_from_1[w];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3785
                        *(sp + 2) = w;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3788
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3789
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3790
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3791
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3792
                  sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3793
                  for (i = 0; i < row_width; i++, sp += 4)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3794
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3795
                     png_byte a = *(sp + 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3797
                     if (a == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3799
                        *sp = (png_byte)png_ptr->background.red;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3800
                        *(sp + 1) = (png_byte)png_ptr->background.green;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3801
                        *(sp + 2) = (png_byte)png_ptr->background.blue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3802
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3803
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3804
                     else if (a < 0xff)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3805
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3806
                        png_composite(*sp, *sp, a, png_ptr->background.red);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3807
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3808
                        png_composite(*(sp + 1), *(sp + 1), a,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3809
                            png_ptr->background.green);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3810
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3811
                        png_composite(*(sp + 2), *(sp + 2), a,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3812
                            png_ptr->background.blue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3816
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
            else /* if (row_info->bit_depth == 16) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3819
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
               if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
                   gamma_16_to_1 != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
                  sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3824
                  for (i = 0; i < row_width; i++, sp += 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3825
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
                     png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
                         << 8) + (png_uint_16)(*(sp + 7)));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3828
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
                     if (a == (png_uint_16)0xffff)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
                        png_uint_16 v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3832
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3833
                        v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3834
                        *sp = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3835
                        *(sp + 1) = (png_byte)(v & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3836
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
                        v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3838
                        *(sp + 2) = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3839
                        *(sp + 3) = (png_byte)(v & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3840
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
                        v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3842
                        *(sp + 4) = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3843
                        *(sp + 5) = (png_byte)(v & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3845
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3846
                     else if (a == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3847
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3848
                        /* Background is already in screen gamma */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3849
                        *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3850
                        *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3851
                        *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3852
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3853
                        *(sp + 3) = (png_byte)(png_ptr->background.green
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3854
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3855
                        *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3856
                                & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3857
                        *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3859
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3862
                        png_uint_16 v, w;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
                        v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3865
                        png_composite_16(w, v, a, png_ptr->background_1.red);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3866
                        if (optimize == 0)
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3867
                           w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3868
                                8];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3869
                        *sp = (png_byte)((w >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3870
                        *(sp + 1) = (png_byte)(w & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3871
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
                        v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3873
                        png_composite_16(w, v, a, png_ptr->background_1.green);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3874
                        if (optimize == 0)
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3875
                           w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3876
                                8];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3877
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3878
                        *(sp + 2) = (png_byte)((w >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3879
                        *(sp + 3) = (png_byte)(w & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3880
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
                        v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3882
                        png_composite_16(w, v, a, png_ptr->background_1.blue);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3883
                        if (optimize == 0)
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3884
                           w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3885
                                8];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3886
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3887
                        *(sp + 4) = (png_byte)((w >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3888
                        *(sp + 5) = (png_byte)(w & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3892
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3894
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
                  sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3897
                  for (i = 0; i < row_width; i++, sp += 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3899
                     png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3900
                         << 8) + (png_uint_16)(*(sp + 7)));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3901
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3902
                     if (a == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3903
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3904
                        *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3905
                        *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3906
                        *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3907
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3908
                        *(sp + 3) = (png_byte)(png_ptr->background.green
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3909
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3910
                        *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3911
                                & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3912
                        *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3914
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3915
                     else if (a < 0xffff)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
                        png_uint_16 v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
                        png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
                        png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
                            + *(sp + 3));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
                        png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
                            + *(sp + 5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3924
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3925
                        png_composite_16(v, r, a, png_ptr->background.red);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3926
                        *sp = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3927
                        *(sp + 1) = (png_byte)(v & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3928
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3929
                        png_composite_16(v, g, a, png_ptr->background.green);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3930
                        *(sp + 2) = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3931
                        *(sp + 3) = (png_byte)(v & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3932
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3933
                        png_composite_16(v, b, a, png_ptr->background.blue);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3934
                        *(sp + 4) = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3935
                        *(sp + 5) = (png_byte)(v & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3936
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3937
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3938
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3939
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3940
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3941
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3942
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3943
         default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3944
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3945
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3946
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3947
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3948
#endif /* READ_BACKGROUND || READ_ALPHA_MODE */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3949
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3950
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3951
/* Gamma correct the image, avoiding the alpha channel.  Make sure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3952
 * you do this after you deal with the transparency issue on grayscale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3953
 * or RGB images. If your bit depth is 8, use gamma_table, if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3954
 * is 16, use gamma_16_table and gamma_shift.  Build these with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3955
 * build_gamma_table().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3956
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3957
static void
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3958
png_do_gamma(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3959
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3960
   png_const_bytep gamma_table = png_ptr->gamma_table;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3961
   png_const_uint_16pp gamma_16_table = png_ptr->gamma_16_table;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3962
   int gamma_shift = png_ptr->gamma_shift;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3963
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3964
   png_bytep sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3965
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3966
   png_uint_32 row_width=row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3967
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3968
   png_debug(1, "in png_do_gamma");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3969
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3970
   if (((row_info->bit_depth <= 8 && gamma_table != NULL) ||
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3971
       (row_info->bit_depth == 16 && gamma_16_table != NULL)))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3972
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
      switch (row_info->color_type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
         case PNG_COLOR_TYPE_RGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3976
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3977
            if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3990
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
            else /* if (row_info->bit_depth == 16) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
                  png_uint_16 v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3999
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4000
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
                  sp += 2;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4002
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4003
                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4004
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4005
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4006
                  sp += 2;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4007
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4008
                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4009
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4010
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4011
                  sp += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4012
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4013
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4014
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4015
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4016
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4017
         case PNG_COLOR_TYPE_RGB_ALPHA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4018
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4019
            if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4020
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4021
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4022
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4023
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4024
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4025
                  sp++;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4026
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4027
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4028
                  sp++;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4029
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4030
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4031
                  sp++;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4032
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4033
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4034
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4035
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4036
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4037
            else /* if (row_info->bit_depth == 16) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4038
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4039
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4040
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4041
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4042
                  png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4043
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4044
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4045
                  sp += 2;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4046
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4047
                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4048
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4049
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4050
                  sp += 2;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4051
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4052
                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4053
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4054
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4055
                  sp += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4056
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4057
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4058
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4059
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4060
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4061
         case PNG_COLOR_TYPE_GRAY_ALPHA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4062
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4063
            if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4064
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4065
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4066
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4067
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4068
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4069
                  sp += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4070
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4071
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4072
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4073
            else /* if (row_info->bit_depth == 16) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4074
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4075
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4076
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4077
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4078
                  png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4079
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4080
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4081
                  sp += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4082
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4083
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4084
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4085
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4086
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4087
         case PNG_COLOR_TYPE_GRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4088
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4089
            if (row_info->bit_depth == 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4090
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4091
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4092
               for (i = 0; i < row_width; i += 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4093
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4094
                  int a = *sp & 0xc0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4095
                  int b = *sp & 0x30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4096
                  int c = *sp & 0x0c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4097
                  int d = *sp & 0x03;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4099
                  *sp = (png_byte)(
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4100
                      ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)])   ) & 0xc0)|
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4101
                      ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4102
                      ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4103
                      ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4104
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4105
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4106
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4107
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4108
            if (row_info->bit_depth == 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4109
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4110
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4111
               for (i = 0; i < row_width; i += 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4112
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4113
                  int msb = *sp & 0xf0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4114
                  int lsb = *sp & 0x0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4116
                  *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4117
                      | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4118
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4119
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4120
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4121
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4122
            else if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4123
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4124
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4125
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4126
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4127
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4128
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4129
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4130
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4131
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4132
            else if (row_info->bit_depth == 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4133
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4134
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4135
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4136
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4137
                  png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4138
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4139
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4140
                  sp += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4141
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4142
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4143
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4144
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4145
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4146
         default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4147
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4148
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4149
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4150
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4151
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4152
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4153
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4154
/* Encode the alpha channel to the output gamma (the input channel is always
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4155
 * linear.)  Called only with color types that have an alpha channel.  Needs the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4156
 * from_1 tables.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4157
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4158
static void
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4159
png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4160
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4161
   png_uint_32 row_width = row_info->width;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4162
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4163
   png_debug(1, "in png_do_encode_alpha");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4164
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4165
   if ((row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4166
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4167
      if (row_info->bit_depth == 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4168
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4169
         PNG_CONST png_bytep table = png_ptr->gamma_from_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4170
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4171
         if (table != NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4172
         {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4173
            PNG_CONST int step =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4174
               (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 4 : 2;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4175
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4176
            /* The alpha channel is the last component: */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4177
            row += step - 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4178
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4179
            for (; row_width > 0; --row_width, row += step)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4180
               *row = table[*row];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4181
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4182
            return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4183
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4184
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4185
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4186
      else if (row_info->bit_depth == 16)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4187
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4188
         PNG_CONST png_uint_16pp table = png_ptr->gamma_16_from_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4189
         PNG_CONST int gamma_shift = png_ptr->gamma_shift;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4190
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4191
         if (table != NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4192
         {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4193
            PNG_CONST int step =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4194
               (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 8 : 4;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4195
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4196
            /* The alpha channel is the last component: */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4197
            row += step - 2;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4198
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4199
            for (; row_width > 0; --row_width, row += step)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4200
            {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4201
               png_uint_16 v;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4202
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4203
               v = table[*(row + 1) >> gamma_shift][*row];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4204
               *row = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4205
               *(row + 1) = (png_byte)(v & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4206
            }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4207
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4208
            return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4209
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4210
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4211
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4212
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4213
   /* Only get to here if called with a weird row_info; no harm has been done,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4214
    * so just issue a warning.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4215
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4216
   png_warning(png_ptr, "png_do_encode_alpha: unexpected call");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4217
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4218
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4219
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4220
#ifdef PNG_READ_EXPAND_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4221
/* Expands a palette row to an RGB or RGBA row depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4222
 * upon whether you supply trans and num_trans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4223
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4224
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4225
png_do_expand_palette(png_row_infop row_info, png_bytep row,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4226
   png_const_colorp palette, png_const_bytep trans_alpha, int num_trans)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4227
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4228
   int shift, value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4229
   png_bytep sp, dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4230
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4231
   png_uint_32 row_width=row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4232
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4233
   png_debug(1, "in png_do_expand_palette");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4234
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4235
   if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4236
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4237
      if (row_info->bit_depth < 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4238
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4239
         switch (row_info->bit_depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4240
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4241
            case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4242
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4243
               sp = row + (png_size_t)((row_width - 1) >> 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4244
               dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4245
               shift = 7 - (int)((row_width + 7) & 0x07);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4246
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4247
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4248
                  if ((*sp >> shift) & 0x01)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4249
                     *dp = 1;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4250
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4251
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4252
                     *dp = 0;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4253
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4254
                  if (shift == 7)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4255
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4256
                     shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4257
                     sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4258
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4259
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4260
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4261
                     shift++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4263
                  dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4264
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4265
               break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4266
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4267
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4268
            case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4269
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4270
               sp = row + (png_size_t)((row_width - 1) >> 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4271
               dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4272
               shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4273
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4274
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4275
                  value = (*sp >> shift) & 0x03;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4276
                  *dp = (png_byte)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4277
                  if (shift == 6)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4278
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4279
                     shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4280
                     sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4281
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4282
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4283
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4284
                     shift += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4286
                  dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4287
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4288
               break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4290
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4291
            case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4292
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4293
               sp = row + (png_size_t)((row_width - 1) >> 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4294
               dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4295
               shift = (int)((row_width & 0x01) << 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4296
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4297
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4298
                  value = (*sp >> shift) & 0x0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4299
                  *dp = (png_byte)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
                  if (shift == 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4301
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4302
                     shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4303
                     sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4304
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4305
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4306
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4307
                     shift += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4309
                  dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4310
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4311
               break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4312
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4313
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4314
            default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4315
               break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4316
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4317
         row_info->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4318
         row_info->pixel_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4319
         row_info->rowbytes = row_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4320
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4321
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4322
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4323
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4324
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4325
            if (num_trans > 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4326
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4327
               sp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4328
               dp = row + (png_size_t)(row_width << 2) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4330
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4331
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4332
                  if ((int)(*sp) >= num_trans)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4333
                     *dp-- = 0xff;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4334
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4335
                  else
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4336
                     *dp-- = trans_alpha[*sp];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4337
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4338
                  *dp-- = palette[*sp].blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4339
                  *dp-- = palette[*sp].green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4340
                  *dp-- = palette[*sp].red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4341
                  sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4342
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4343
               row_info->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4344
               row_info->pixel_depth = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4345
               row_info->rowbytes = row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4346
               row_info->color_type = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4347
               row_info->channels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4348
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4349
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4350
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4351
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4352
               sp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4353
               dp = row + (png_size_t)(row_width * 3) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4355
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4356
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4357
                  *dp-- = palette[*sp].blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4358
                  *dp-- = palette[*sp].green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4359
                  *dp-- = palette[*sp].red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
                  sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4361
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4362
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4363
               row_info->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4364
               row_info->pixel_depth = 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4365
               row_info->rowbytes = row_width * 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4366
               row_info->color_type = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
               row_info->channels = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4368
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4369
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4370
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4371
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4374
/* If the bit depth < 8, it is expanded to 8.  Also, if the already
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4375
 * expanded transparency value is supplied, an alpha channel is built.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4376
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4377
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4378
png_do_expand(png_row_infop row_info, png_bytep row,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4379
    png_const_color_16p trans_color)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4380
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4381
   int shift, value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4382
   png_bytep sp, dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4383
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4384
   png_uint_32 row_width=row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4385
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4386
   png_debug(1, "in png_do_expand");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4387
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4388
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4389
      if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4390
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4391
         unsigned int gray = trans_color != NULL ? trans_color->gray : 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4393
         if (row_info->bit_depth < 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4394
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4395
            switch (row_info->bit_depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4396
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4397
               case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4398
               {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4399
                  gray = (gray & 0x01) * 0xff;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4400
                  sp = row + (png_size_t)((row_width - 1) >> 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4401
                  dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4402
                  shift = 7 - (int)((row_width + 7) & 0x07);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4403
                  for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4404
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4405
                     if ((*sp >> shift) & 0x01)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4406
                        *dp = 0xff;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4407
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4408
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4409
                        *dp = 0;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4410
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4411
                     if (shift == 7)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4412
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4413
                        shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4414
                        sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4415
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4416
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4417
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4418
                        shift++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4420
                     dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4421
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4422
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4423
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4424
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4425
               case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4426
               {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4427
                  gray = (gray & 0x03) * 0x55;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4428
                  sp = row + (png_size_t)((row_width - 1) >> 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4429
                  dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4430
                  shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4431
                  for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4432
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4433
                     value = (*sp >> shift) & 0x03;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4434
                     *dp = (png_byte)(value | (value << 2) | (value << 4) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4435
                        (value << 6));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4436
                     if (shift == 6)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4437
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4438
                        shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4439
                        sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4440
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4441
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4442
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4443
                        shift += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4445
                     dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4446
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4447
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4448
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4449
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4450
               case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4451
               {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4452
                  gray = (gray & 0x0f) * 0x11;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4453
                  sp = row + (png_size_t)((row_width - 1) >> 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4454
                  dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4455
                  shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4456
                  for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4457
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4458
                     value = (*sp >> shift) & 0x0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4459
                     *dp = (png_byte)(value | (value << 4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4460
                     if (shift == 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4461
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4462
                        shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4463
                        sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4464
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4465
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4466
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4467
                        shift = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4469
                     dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4470
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4471
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4472
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4473
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4474
               default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4475
                  break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4476
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4477
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4478
            row_info->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4479
            row_info->pixel_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4480
            row_info->rowbytes = row_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4481
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4482
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4483
         if (trans_color != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4484
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4485
            if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4486
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4487
               gray = gray & 0xff;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4488
               sp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4489
               dp = row + (png_size_t)(row_width << 1) - 1;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4490
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4491
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4492
               {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  4493
                  if ((*sp & 0xffU) == gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4494
                     *dp-- = 0;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4495
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4496
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4497
                     *dp-- = 0xff;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4498
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4499
                  *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4500
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4501
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4502
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4503
            else if (row_info->bit_depth == 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4504
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4505
               unsigned int gray_high = (gray >> 8) & 0xff;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4506
               unsigned int gray_low = gray & 0xff;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4507
               sp = row + row_info->rowbytes - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4508
               dp = row + (row_info->rowbytes << 1) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4509
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4510
               {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  4511
                  if ((*(sp - 1) & 0xffU) == gray_high &&
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  4512
                      (*(sp) & 0xffU) == gray_low)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4513
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4514
                     *dp-- = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4515
                     *dp-- = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4516
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4517
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4518
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4519
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4520
                     *dp-- = 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4521
                     *dp-- = 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4522
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4523
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4524
                  *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4525
                  *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4526
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4527
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4528
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4529
            row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4530
            row_info->channels = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4531
            row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4532
            row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4533
               row_width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4534
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4535
      }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4536
      else if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4537
          trans_color != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4538
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4539
         if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4540
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4541
            png_byte red = (png_byte)(trans_color->red & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4542
            png_byte green = (png_byte)(trans_color->green & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4543
            png_byte blue = (png_byte)(trans_color->blue & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4544
            sp = row + (png_size_t)row_info->rowbytes - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4545
            dp = row + (png_size_t)(row_width << 2) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4546
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4547
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4548
               if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4549
                  *dp-- = 0;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4550
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4551
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4552
                  *dp-- = 0xff;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4553
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4554
               *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4555
               *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4556
               *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4557
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4558
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4559
         else if (row_info->bit_depth == 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4560
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4561
            png_byte red_high = (png_byte)((trans_color->red >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4562
            png_byte green_high = (png_byte)((trans_color->green >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4563
            png_byte blue_high = (png_byte)((trans_color->blue >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4564
            png_byte red_low = (png_byte)(trans_color->red & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4565
            png_byte green_low = (png_byte)(trans_color->green & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4566
            png_byte blue_low = (png_byte)(trans_color->blue & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4567
            sp = row + row_info->rowbytes - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4568
            dp = row + (png_size_t)(row_width << 3) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4569
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4570
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4571
               if (*(sp - 5) == red_high &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4572
                   *(sp - 4) == red_low &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4573
                   *(sp - 3) == green_high &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4574
                   *(sp - 2) == green_low &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4575
                   *(sp - 1) == blue_high &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4576
                   *(sp    ) == blue_low)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4577
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4578
                  *dp-- = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4579
                  *dp-- = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4580
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4581
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4582
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4583
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4584
                  *dp-- = 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4585
                  *dp-- = 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4586
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4587
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4588
               *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4589
               *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4590
               *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4591
               *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4592
               *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4593
               *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4594
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4595
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4596
         row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4597
         row_info->channels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4598
         row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4599
         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4600
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4601
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4602
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4603
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4604
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4605
#ifdef PNG_READ_EXPAND_16_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4606
/* If the bit depth is 8 and the color type is not a palette type expand the
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4607
 * whole row to 16 bits.  Has no effect otherwise.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4608
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4609
static void
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4610
png_do_expand_16(png_row_infop row_info, png_bytep row)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4611
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4612
   if (row_info->bit_depth == 8 &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4613
      row_info->color_type != PNG_COLOR_TYPE_PALETTE)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4614
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4615
      /* The row have a sequence of bytes containing [0..255] and we need
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4616
       * to turn it into another row containing [0..65535], to do this we
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4617
       * calculate:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4618
       *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4619
       *  (input / 255) * 65535
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4620
       *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4621
       *  Which happens to be exactly input * 257 and this can be achieved
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4622
       *  simply by byte replication in place (copying backwards).
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4623
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4624
      png_byte *sp = row + row_info->rowbytes; /* source, last byte + 1 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4625
      png_byte *dp = sp + row_info->rowbytes;  /* destination, end + 1 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4626
      while (dp > sp)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4627
         dp[-2] = dp[-1] = *--sp, dp -= 2;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4628
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4629
      row_info->rowbytes *= 2;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4630
      row_info->bit_depth = 16;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4631
      row_info->pixel_depth = (png_byte)(row_info->channels * 16);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4632
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4633
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4634
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4635
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4636
#ifdef PNG_READ_QUANTIZE_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4637
static void
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4638
png_do_quantize(png_row_infop row_info, png_bytep row,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4639
    png_const_bytep palette_lookup, png_const_bytep quantize_lookup)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4640
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4641
   png_bytep sp, dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4642
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4643
   png_uint_32 row_width=row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4644
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4645
   png_debug(1, "in png_do_quantize");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4646
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4647
   if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4648
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4649
      if (row_info->color_type == PNG_COLOR_TYPE_RGB && palette_lookup)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4650
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4651
         int r, g, b, p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4652
         sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4653
         dp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4654
         for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4655
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4656
            r = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4657
            g = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4658
            b = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4659
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4660
            /* This looks real messy, but the compiler will reduce
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4661
             * it down to a reasonable formula.  For example, with
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4662
             * 5 bits per color, we get:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4663
             * p = (((r >> 3) & 0x1f) << 10) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4664
             *    (((g >> 3) & 0x1f) << 5) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4665
             *    ((b >> 3) & 0x1f);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4666
             */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4667
            p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4668
                ((1 << PNG_QUANTIZE_RED_BITS) - 1)) <<
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4669
                (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4670
                (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4671
                ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) <<
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4672
                (PNG_QUANTIZE_BLUE_BITS)) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4673
                ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4674
                ((1 << PNG_QUANTIZE_BLUE_BITS) - 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4675
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4676
            *dp++ = palette_lookup[p];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4677
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4678
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4679
         row_info->color_type = PNG_COLOR_TYPE_PALETTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4680
         row_info->channels = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4681
         row_info->pixel_depth = row_info->bit_depth;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4682
         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4683
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4684
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4685
      else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4686
         palette_lookup != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4687
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4688
         int r, g, b, p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4689
         sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4690
         dp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4691
         for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4692
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4693
            r = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4694
            g = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4695
            b = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4696
            sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4697
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4698
            p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4699
                ((1 << PNG_QUANTIZE_RED_BITS) - 1)) <<
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4700
                (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4701
                (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4702
                ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) <<
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4703
                (PNG_QUANTIZE_BLUE_BITS)) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4704
                ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4705
                ((1 << PNG_QUANTIZE_BLUE_BITS) - 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4706
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4707
            *dp++ = palette_lookup[p];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4708
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4709
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4710
         row_info->color_type = PNG_COLOR_TYPE_PALETTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4711
         row_info->channels = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4712
         row_info->pixel_depth = row_info->bit_depth;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4713
         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4714
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4715
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4716
      else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4717
         quantize_lookup)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4718
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4719
         sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4720
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4721
         for (i = 0; i < row_width; i++, sp++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4722
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4723
            *sp = quantize_lookup[*sp];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4724
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4725
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4726
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4727
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4728
#endif /* READ_QUANTIZE */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4729
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4730
/* Transform the row.  The order of transformations is significant,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4731
 * and is very touchy.  If you add a transformation, take care to
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4732
 * decide how it fits in with the other transformations here.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4733
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4734
void /* PRIVATE */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4735
png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4736
{
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4737
   png_debug(1, "in png_do_read_transformations");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4738
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4739
   if (png_ptr->row_buf == NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4740
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4741
      /* Prior to 1.5.4 this output row/pass where the NULL pointer is, but this
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4742
       * error is incredibly rare and incredibly easy to debug without this
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4743
       * information.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4744
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4745
      png_error(png_ptr, "NULL row buffer");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4746
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4747
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4748
   /* The following is debugging; prior to 1.5.4 the code was never compiled in;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4749
    * in 1.5.4 PNG_FLAG_DETECT_UNINITIALIZED was added and the macro
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4750
    * PNG_WARN_UNINITIALIZED_ROW removed.  In 1.6 the new flag is set only for
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4751
    * all transformations, however in practice the ROW_INIT always gets done on
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4752
    * demand, if necessary.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4753
    */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4754
   if ((png_ptr->flags & PNG_FLAG_DETECT_UNINITIALIZED) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4755
       (png_ptr->flags & PNG_FLAG_ROW_INIT) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4756
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4757
      /* Application has failed to call either png_read_start_image() or
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4758
       * png_read_update_info() after setting transforms that expand pixels.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4759
       * This check added to libpng-1.2.19 (but not enabled until 1.5.4).
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4760
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4761
      png_error(png_ptr, "Uninitialized row");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4762
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4763
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4764
#ifdef PNG_READ_EXPAND_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4765
   if ((png_ptr->transformations & PNG_EXPAND) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4766
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4767
      if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4768
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4769
         png_do_expand_palette(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4770
             png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4771
      }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4772
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4773
      else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4774
      {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4775
         if (png_ptr->num_trans != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4776
             (png_ptr->transformations & PNG_EXPAND_tRNS) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4777
            png_do_expand(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4778
                &(png_ptr->trans_color));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4779
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4780
         else
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4781
            png_do_expand(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4782
                NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4783
      }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4784
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4785
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4786
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4787
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4788
   if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4789
       (png_ptr->transformations & PNG_COMPOSE) == 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4790
       (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4791
       row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4792
      png_do_strip_channel(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4793
         0 /* at_start == false, because SWAP_ALPHA happens later */);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4794
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4795
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4796
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4797
   if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4798
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4799
      int rgb_error =
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4800
          png_do_rgb_to_gray(png_ptr, row_info,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4801
              png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4802
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4803
      if (rgb_error != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4804
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4805
         png_ptr->rgb_to_gray_status=1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4806
         if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4807
             PNG_RGB_TO_GRAY_WARN)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4808
            png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4809
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4810
         if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4811
             PNG_RGB_TO_GRAY_ERR)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4812
            png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4813
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4814
   }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4815
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4816
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4817
/* From Andreas Dilger e-mail to png-implement, 26 March 1998:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4818
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4819
 *   In most cases, the "simple transparency" should be done prior to doing
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4820
 *   gray-to-RGB, or you will have to test 3x as many bytes to check if a
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4821
 *   pixel is transparent.  You would also need to make sure that the
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4822
 *   transparency information is upgraded to RGB.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4823
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4824
 *   To summarize, the current flow is:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4825
 *   - Gray + simple transparency -> compare 1 or 2 gray bytes and composite
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4826
 *                                   with background "in place" if transparent,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4827
 *                                   convert to RGB if necessary
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4828
 *   - Gray + alpha -> composite with gray background and remove alpha bytes,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4829
 *                                   convert to RGB if necessary
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4830
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4831
 *   To support RGB backgrounds for gray images we need:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4832
 *   - Gray + simple transparency -> convert to RGB + simple transparency,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4833
 *                                   compare 3 or 6 bytes and composite with
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4834
 *                                   background "in place" if transparent
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4835
 *                                   (3x compare/pixel compared to doing
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4836
 *                                   composite with gray bkgrnd)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4837
 *   - Gray + alpha -> convert to RGB + alpha, composite with background and
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4838
 *                                   remove alpha bytes (3x float
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4839
 *                                   operations/pixel compared with composite
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4840
 *                                   on gray background)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4841
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4842
 *  Greg's change will do this.  The reason it wasn't done before is for
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4843
 *  performance, as this increases the per-pixel operations.  If we would check
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4844
 *  in advance if the background was gray or RGB, and position the gray-to-RGB
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4845
 *  transform appropriately, then it would save a lot of work/time.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4846
 */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4847
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4848
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4849
   /* If gray -> RGB, do so now only if background is non-gray; else do later
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4850
    * for performance reasons
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4851
    */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4852
   if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4853
       (png_ptr->mode & PNG_BACKGROUND_IS_GRAY) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4854
      png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4855
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4856
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4857
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4858
   defined(PNG_READ_ALPHA_MODE_SUPPORTED)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4859
   if ((png_ptr->transformations & PNG_COMPOSE) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4860
      png_do_compose(row_info, png_ptr->row_buf + 1, png_ptr);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4861
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4862
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4863
#ifdef PNG_READ_GAMMA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4864
   if ((png_ptr->transformations & PNG_GAMMA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4865
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4866
      /* Because RGB_TO_GRAY does the gamma transform. */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4867
      (png_ptr->transformations & PNG_RGB_TO_GRAY) == 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4868
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4869
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4870
   defined(PNG_READ_ALPHA_MODE_SUPPORTED)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4871
      /* Because PNG_COMPOSE does the gamma transform if there is something to
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4872
       * do (if there is an alpha channel or transparency.)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4873
       */
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  4874
       !((png_ptr->transformations & PNG_COMPOSE) != 0 &&
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4875
       ((png_ptr->num_trans != 0) ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4876
       (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)) &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4877
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4878
      /* Because png_init_read_transformations transforms the palette, unless
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4879
       * RGB_TO_GRAY will do the transform.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4880
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4881
       (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4882
      png_do_gamma(row_info, png_ptr->row_buf + 1, png_ptr);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4883
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4884
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4885
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4886
   if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4887
       (png_ptr->transformations & PNG_COMPOSE) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4888
       (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4889
       row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4890
      png_do_strip_channel(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4891
          0 /* at_start == false, because SWAP_ALPHA happens later */);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4892
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4893
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4894
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4895
   if ((png_ptr->transformations & PNG_ENCODE_ALPHA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4896
       (row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4897
      png_do_encode_alpha(row_info, png_ptr->row_buf + 1, png_ptr);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4898
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4899
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4900
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4901
   if ((png_ptr->transformations & PNG_SCALE_16_TO_8) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4902
      png_do_scale_16_to_8(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4903
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4904
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4905
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4906
   /* There is no harm in doing both of these because only one has any effect,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4907
    * by putting the 'scale' option first if the app asks for scale (either by
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4908
    * calling the API or in a TRANSFORM flag) this is what happens.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4909
    */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4910
   if ((png_ptr->transformations & PNG_16_TO_8) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4911
      png_do_chop(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4912
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4914
#ifdef PNG_READ_QUANTIZE_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4915
   if ((png_ptr->transformations & PNG_QUANTIZE) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4916
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4917
      png_do_quantize(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4918
          png_ptr->palette_lookup, png_ptr->quantize_index);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4919
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4920
      if (row_info->rowbytes == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4921
         png_error(png_ptr, "png_do_quantize returned rowbytes=0");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4922
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4923
#endif /* READ_QUANTIZE */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4924
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4925
#ifdef PNG_READ_EXPAND_16_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4926
   /* Do the expansion now, after all the arithmetic has been done.  Notice
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4927
    * that previous transformations can handle the PNG_EXPAND_16 flag if this
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4928
    * is efficient (particularly true in the case of gamma correction, where
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4929
    * better accuracy results faster!)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4930
    */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4931
   if ((png_ptr->transformations & PNG_EXPAND_16) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4932
      png_do_expand_16(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4933
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4934
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4935
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4936
   /* NOTE: moved here in 1.5.4 (from much later in this list.) */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4937
   if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4938
       (png_ptr->mode & PNG_BACKGROUND_IS_GRAY) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4939
      png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4940
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4941
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4942
#ifdef PNG_READ_INVERT_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4943
   if ((png_ptr->transformations & PNG_INVERT_MONO) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4944
      png_do_invert(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4945
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4946
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4947
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4948
   if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4949
      png_do_read_invert_alpha(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4950
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4951
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4952
#ifdef PNG_READ_SHIFT_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4953
   if ((png_ptr->transformations & PNG_SHIFT) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4954
      png_do_unshift(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4955
          &(png_ptr->shift));
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4956
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4957
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4958
#ifdef PNG_READ_PACK_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4959
   if ((png_ptr->transformations & PNG_PACK) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4960
      png_do_unpack(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4961
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4962
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4963
#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4964
   /* Added at libpng-1.5.10 */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4965
   if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4966
       png_ptr->num_palette_max >= 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4967
      png_do_check_palette_indexes(png_ptr, row_info);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4968
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4969
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4970
#ifdef PNG_READ_BGR_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4971
   if ((png_ptr->transformations & PNG_BGR) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4972
      png_do_bgr(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4973
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4974
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4975
#ifdef PNG_READ_PACKSWAP_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4976
   if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4977
      png_do_packswap(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4978
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4979
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4980
#ifdef PNG_READ_FILLER_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4981
   if ((png_ptr->transformations & PNG_FILLER) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4982
      png_do_read_filler(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4983
          (png_uint_32)png_ptr->filler, png_ptr->flags);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4984
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4985
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4986
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4987
   if ((png_ptr->transformations & PNG_SWAP_ALPHA) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4988
      png_do_read_swap_alpha(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4989
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4990
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4991
#ifdef PNG_READ_16BIT_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4992
#ifdef PNG_READ_SWAP_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4993
   if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4994
      png_do_swap(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4995
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4996
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4997
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4998
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4999
   if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5000
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5001
      if (png_ptr->read_user_transform_fn != NULL)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5002
         (*(png_ptr->read_user_transform_fn)) /* User read transform function */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5003
             (png_ptr,     /* png_ptr */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5004
             row_info,     /* row_info: */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5005
                /*  png_uint_32 width;       width of row */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5006
                /*  png_size_t rowbytes;     number of bytes in row */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5007
                /*  png_byte color_type;     color type of pixels */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5008
                /*  png_byte bit_depth;      bit depth of samples */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5009
                /*  png_byte channels;       number of channels (1-4) */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5010
                /*  png_byte pixel_depth;    bits per pixel (depth*channels) */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5011
             png_ptr->row_buf + 1);    /* start of pixel data for row */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5012
#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5013
      if (png_ptr->user_transform_depth != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5014
         row_info->bit_depth = png_ptr->user_transform_depth;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5015
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5016
      if (png_ptr->user_transform_channels != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5017
         row_info->channels = png_ptr->user_transform_channels;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5018
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5019
      row_info->pixel_depth = (png_byte)(row_info->bit_depth *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5020
          row_info->channels);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5021
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5022
      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_info->width);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5023
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5024
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5025
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5026
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5027
#endif /* READ_TRANSFORMS */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5028
#endif /* READ */