jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngrtran.c
author ddehaven
Thu, 21 Jan 2016 14:49:02 -0800
changeset 35692 ee66ced7896c
parent 35667 ed476aba94de
parent 35296 659e92aaf7f4
child 40436 94ae0ede53a5
permissions -rw-r--r--
Merge
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
 *
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
    32
 * Last changed in libpng 1.6.19 [November 12, 2015]
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
    33
 * Copyright (c) 1998-2015 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
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   190
#  endif  /* FLOATING_POINT */
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
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   320
    * values are reasonable this may have to be changed.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   321
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   322
   if (output_gamma < 70000 || output_gamma > 300000)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   323
      png_error(png_ptr, "output gamma out of expected range");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   324
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   325
   /* 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
   326
    * gamma may be changed below so get the file value first:
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
   file_gamma = png_reciprocal(output_gamma);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   329
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   330
   /* There are really 8 possibilities here, composed of any combination
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   331
    * of:
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
    *    premultiply the color channels
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   334
    *    do not encode non-opaque pixels
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   335
    *    encode the alpha as well as the color channels
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   336
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   337
    * The differences disappear if the input/output ('screen') gamma is 1.0,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   338
    * 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
   339
    * premultiplying the color channels or not.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   340
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   341
    * png_set_alpha_mode and png_set_background interact because both use
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   342
    * png_compose to do the work.  Calling both is only useful when
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   343
    * 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
   344
    * with a default gamma value.  Otherwise PNG_COMPOSE must not be set.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   345
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   346
   switch (mode)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   347
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   348
      case PNG_ALPHA_PNG:        /* default: png standard */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   349
         /* No compose, but it may be set by png_set_background! */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   350
         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   351
         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   352
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   353
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   354
      case PNG_ALPHA_ASSOCIATED: /* color channels premultiplied */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   355
         compose = 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   356
         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   357
         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   358
         /* The output is linear: */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   359
         output_gamma = PNG_FP_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   360
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   361
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   362
      case PNG_ALPHA_OPTIMIZED:  /* associated, non-opaque pixels linear */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   363
         compose = 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   364
         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   365
         png_ptr->flags |= PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   366
         /* output_gamma records the encoding of opaque pixels! */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   367
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   368
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   369
      case PNG_ALPHA_BROKEN:     /* associated, non-linear, alpha encoded */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   370
         compose = 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   371
         png_ptr->transformations |= PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   372
         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   373
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   374
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   375
      default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   376
         png_error(png_ptr, "invalid alpha mode");
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
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   379
   /* 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
   380
    * 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
   381
    * be ignored.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   382
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   383
   if (png_ptr->colorspace.gamma == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   384
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   385
      png_ptr->colorspace.gamma = file_gamma;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   386
      png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   387
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   388
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   389
   /* But always set the output gamma: */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   390
   png_ptr->screen_gamma = output_gamma;
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
   /* Finally, if pre-multiplying, set the background fields to achieve the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   393
    * desired result.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   394
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   395
   if (compose != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   396
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   397
      /* And obtain alpha pre-multiplication by composing on black: */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   398
      memset(&png_ptr->background, 0, (sizeof png_ptr->background));
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   399
      png_ptr->background_gamma = png_ptr->colorspace.gamma; /* just in case */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   400
      png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_FILE;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   401
      png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   402
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   403
      if ((png_ptr->transformations & PNG_COMPOSE) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   404
         png_error(png_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   405
            "conflicting calls to set alpha mode and background");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   406
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   407
      png_ptr->transformations |= PNG_COMPOSE;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   408
   }
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
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   411
#  ifdef PNG_FLOATING_POINT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   412
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   413
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
   414
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   415
   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
   416
      output_gamma));
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
#  endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   419
#endif
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
#ifdef PNG_READ_QUANTIZE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   422
/* Dither file to 8-bit.  Supply a palette, the current number
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
 * of elements in the palette, the maximum number of elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
 * allowed, and a histogram if possible.  If the current number
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
   425
 * 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
   426
 * modified to fit in the maximum number.  "full_quantize" indicates
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   427
 * whether we need a quantizing cube set up for RGB images, or if we
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
 * simply are reducing the number of colors in a paletted image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
typedef struct png_dsort_struct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
{
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   433
   struct png_dsort_struct * next;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
   png_byte left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
   png_byte right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
} png_dsort;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   437
typedef png_dsort *   png_dsortp;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   438
typedef png_dsort * * png_dsortpp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   441
png_set_quantize(png_structrp png_ptr, png_colorp palette,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   442
    int num_palette, int maximum_colors, png_const_uint_16p histogram,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   443
    int full_quantize)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   445
   png_debug(1, "in png_set_quantize");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   446
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   447
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   448
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   449
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   450
   png_ptr->transformations |= PNG_QUANTIZE;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   451
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   452
   if (full_quantize == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
      int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   456
      png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr,
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   457
          (png_uint_32)(num_palette * (sizeof (png_byte))));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
      for (i = 0; i < num_palette; i++)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   459
         png_ptr->quantize_index[i] = (png_byte)i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
   if (num_palette > maximum_colors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
      if (histogram != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
         /* This is easy enough, just throw out the least used colors.
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   467
          * Perhaps not the best solution, but good enough.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   468
          */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
         int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   472
         /* Initialize an array to sort colors */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   473
         png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr,
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   474
             (png_uint_32)(num_palette * (sizeof (png_byte))));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   475
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   476
         /* Initialize the quantize_sort array */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
         for (i = 0; i < num_palette; i++)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   478
            png_ptr->quantize_sort[i] = (png_byte)i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
         /* Find the least used palette entries by starting a
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   481
          * bubble sort, and running it until we have sorted
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   482
          * out enough colors.  Note that we don't care about
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   483
          * sorting all the colors, just finding which are
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   484
          * least used.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   485
          */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
         for (i = num_palette - 1; i >= maximum_colors; i--)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   489
            int done; /* To stop early if the list is pre-sorted */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            done = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            for (j = 0; j < i; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   495
               if (histogram[png_ptr->quantize_sort[j]]
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   496
                   < histogram[png_ptr->quantize_sort[j + 1]])
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                  png_byte t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   500
                  t = png_ptr->quantize_sort[j];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   501
                  png_ptr->quantize_sort[j] = png_ptr->quantize_sort[j + 1];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   502
                  png_ptr->quantize_sort[j + 1] = t;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                  done = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   506
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   507
            if (done != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
               break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   511
         /* Swap the palette around, and set up a table, if necessary */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   512
         if (full_quantize != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            int j = num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   516
            /* Put all the useful colors within the max, but don't
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   517
             * move the others.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   518
             */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            for (i = 0; i < maximum_colors; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   521
               if ((int)png_ptr->quantize_sort[i] >= maximum_colors)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                  do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                     j--;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   525
                  while ((int)png_ptr->quantize_sort[j] >= maximum_colors);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   526
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                  palette[i] = palette[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            int j = num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   535
            /* Move all the used colors inside the max limit, and
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   536
             * develop a translation table.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   537
             */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            for (i = 0; i < maximum_colors; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   540
               /* Only move the colors we need to */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   541
               if ((int)png_ptr->quantize_sort[i] >= maximum_colors)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                  png_color tmp_color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                  do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                     j--;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   547
                  while ((int)png_ptr->quantize_sort[j] >= maximum_colors);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                  tmp_color = palette[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                  palette[j] = palette[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                  palette[i] = tmp_color;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   552
                  /* Indicate where the color went */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   553
                  png_ptr->quantize_index[j] = (png_byte)i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   554
                  png_ptr->quantize_index[i] = (png_byte)j;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   558
            /* Find closest color for those colors we are not using */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            for (i = 0; i < num_palette; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   561
               if ((int)png_ptr->quantize_index[i] >= maximum_colors)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                  int min_d, k, min_k, d_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   565
                  /* Find the closest color to one we threw out */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   566
                  d_index = png_ptr->quantize_index[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                  min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                  for (k = 1, min_k = 0; k < maximum_colors; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                     int d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                     d = PNG_COLOR_DIST(palette[d_index], palette[k]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                     if (d < min_d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                        min_d = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                        min_k = k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   580
                  /* Point to closest color */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   581
                  png_ptr->quantize_index[i] = (png_byte)min_k;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   585
         png_free(png_ptr, png_ptr->quantize_sort);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   586
         png_ptr->quantize_sort = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
         /* This is much harder to do simply (and quickly).  Perhaps
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   591
          * we need to go through a median cut routine, but those
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   592
          * don't always behave themselves with only a few colors
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   593
          * as input.  So we will just find the closest two colors,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   594
          * and throw out one of them (chosen somewhat randomly).
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   595
          * [We don't understand this at all, so if someone wants to
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   596
          *  work on improving it, be our guest - AED, GRP]
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   597
          */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
         int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
         int max_d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
         int num_new_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
         png_dsortp t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
         png_dsortpp hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   604
         t = NULL;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   605
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   606
         /* Initialize palette index arrays */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
         png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   608
             (png_uint_32)(num_palette * (sizeof (png_byte))));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
         png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   610
             (png_uint_32)(num_palette * (sizeof (png_byte))));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   611
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   612
         /* Initialize the sort array */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
         for (i = 0; i < num_palette; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            png_ptr->index_to_palette[i] = (png_byte)i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            png_ptr->palette_to_index[i] = (png_byte)i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   619
         hash = (png_dsortpp)png_calloc(png_ptr, (png_uint_32)(769 *
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   620
             (sizeof (png_dsortp))));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
         num_new_palette = num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   624
         /* Initial wild guess at how far apart the farthest pixel
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   625
          * pair we will be eliminating will be.  Larger
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   626
          * numbers mean more areas will be allocated, Smaller
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   627
          * numbers run the risk of not saving enough data, and
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   628
          * having to do this all over again.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   629
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   630
          * I have not done extensive checking on this number.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   631
          */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
         max_d = 96;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
         while (num_new_palette > maximum_colors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            for (i = 0; i < num_new_palette - 1; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
               int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
               for (j = i + 1; j < num_new_palette; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                  int d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                  d = PNG_COLOR_DIST(palette[i], palette[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                  if (d <= max_d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                     t = (png_dsortp)png_malloc_warn(png_ptr,
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   650
                         (png_uint_32)(sizeof (png_dsort)));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   651
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                     if (t == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                         break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   654
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                     t->next = hash[d];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                     t->left = (png_byte)i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                     t->right = (png_byte)j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                     hash[d] = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
               if (t == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            if (t != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            for (i = 0; i <= max_d; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
               if (hash[i] != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                  png_dsortp p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                  for (p = hash[i]; p; p = p->next)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                     if ((int)png_ptr->index_to_palette[p->left]
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   675
                         < num_new_palette &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   676
                         (int)png_ptr->index_to_palette[p->right]
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   677
                         < num_new_palette)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                        int j, next_j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                        if (num_new_palette & 0x01)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                           j = p->left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                           next_j = p->right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                           j = p->right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                           next_j = p->left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                        num_new_palette--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                        palette[png_ptr->index_to_palette[j]]
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   694
                            = palette[num_new_palette];
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   695
                        if (full_quantize == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                           int k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                           for (k = 0; k < num_palette; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                           {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   701
                              if (png_ptr->quantize_index[k] ==
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   702
                                  png_ptr->index_to_palette[j])
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   703
                                 png_ptr->quantize_index[k] =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   704
                                     png_ptr->index_to_palette[next_j];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   705
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   706
                              if ((int)png_ptr->quantize_index[k] ==
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   707
                                  num_new_palette)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   708
                                 png_ptr->quantize_index[k] =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   709
                                     png_ptr->index_to_palette[j];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                        png_ptr->index_to_palette[png_ptr->palette_to_index
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   714
                            [num_new_palette]] = png_ptr->index_to_palette[j];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   715
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                        png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   717
                            = png_ptr->palette_to_index[num_new_palette];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   718
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   719
                        png_ptr->index_to_palette[j] =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   720
                            (png_byte)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->palette_to_index[num_new_palette] =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   723
                            (png_byte)j;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                     if (num_new_palette <= maximum_colors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                        break;
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
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            for (i = 0; i < 769; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
               if (hash[i] != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                  png_dsortp p = hash[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                  while (p)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                     t = p->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                     png_free(png_ptr, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                     p = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
               hash[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            max_d += 96;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
         png_free(png_ptr, hash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
         png_free(png_ptr, png_ptr->palette_to_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
         png_free(png_ptr, png_ptr->index_to_palette);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   752
         png_ptr->palette_to_index = NULL;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   753
         png_ptr->index_to_palette = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
      num_palette = maximum_colors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
   if (png_ptr->palette == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
      png_ptr->palette = palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
   png_ptr->num_palette = (png_uint_16)num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   763
   if (full_quantize != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
      int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
      png_bytep distance;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   767
      int total_bits = PNG_QUANTIZE_RED_BITS + PNG_QUANTIZE_GREEN_BITS +
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   768
          PNG_QUANTIZE_BLUE_BITS;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   769
      int num_red = (1 << PNG_QUANTIZE_RED_BITS);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   770
      int num_green = (1 << PNG_QUANTIZE_GREEN_BITS);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   771
      int num_blue = (1 << PNG_QUANTIZE_BLUE_BITS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
      png_size_t num_entries = ((png_size_t)1 << total_bits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   774
      png_ptr->palette_lookup = (png_bytep)png_calloc(png_ptr,
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   775
          (png_uint_32)(num_entries * (sizeof (png_byte))));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
      distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   778
          (sizeof (png_byte))));
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   779
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   780
      memset(distance, 0xff, num_entries * (sizeof (png_byte)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
      for (i = 0; i < num_palette; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
         int ir, ig, ib;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   785
         int r = (palette[i].red >> (8 - PNG_QUANTIZE_RED_BITS));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   786
         int g = (palette[i].green >> (8 - PNG_QUANTIZE_GREEN_BITS));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   787
         int b = (palette[i].blue >> (8 - PNG_QUANTIZE_BLUE_BITS));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
         for (ir = 0; ir < num_red; ir++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            /* int dr = abs(ir - r); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            int dr = ((ir > r) ? ir - r : r - ir);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   793
            int index_r = (ir << (PNG_QUANTIZE_BLUE_BITS +
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   794
                PNG_QUANTIZE_GREEN_BITS));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            for (ig = 0; ig < num_green; ig++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
               /* int dg = abs(ig - g); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
               int dg = ((ig > g) ? ig - g : g - ig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
               int dt = dr + dg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
               int dm = ((dr > dg) ? dr : dg);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   802
               int index_g = index_r | (ig << PNG_QUANTIZE_BLUE_BITS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
               for (ib = 0; ib < num_blue; ib++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                  int d_index = index_g | ib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                  /* int db = abs(ib - b); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                  int db = ((ib > b) ? ib - b : b - ib);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                  int dmax = ((dm > db) ? dm : db);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                  int d = dmax + dt + db;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                  if (d < (int)distance[d_index])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                     distance[d_index] = (png_byte)d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                     png_ptr->palette_lookup[d_index] = (png_byte)i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            }
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
      png_free(png_ptr, distance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   825
#endif /* READ_QUANTIZE */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   826
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   827
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   828
void PNGFAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   829
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
   830
   png_fixed_point file_gamma)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   831
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   832
   png_debug(1, "in png_set_gamma_fixed");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   833
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   834
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   835
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   836
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   837
   /* New in libpng-1.5.4 - reserve particular negative values as flags. */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   838
   scrn_gamma = translate_gamma_flags(png_ptr, scrn_gamma, 1/*screen*/);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   839
   file_gamma = translate_gamma_flags(png_ptr, file_gamma, 0/*file*/);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   840
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   841
   /* 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
   842
    * premultiplied alpha support; this actually hides an undocumented feature
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   843
    * of the previous implementation which allowed gamma processing to be
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   844
    * disabled in background handling.  There is no evidence (so far) that this
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   845
    * was being used; however, png_set_background itself accepted and must still
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   846
    * 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
   847
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   848
    * 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
   849
    * undocumented API feature) the following checks were only enabled in
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   850
    * libpng-1.6.0.
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   851
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   852
   if (file_gamma <= 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   853
      png_error(png_ptr, "invalid file gamma in png_set_gamma");
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 (scrn_gamma <= 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   856
      png_error(png_ptr, "invalid screen gamma in png_set_gamma");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   858
   /* Set the gamma values unconditionally - this overrides the value in the PNG
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   859
    * 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
   860
    * different, easier, way to default the file gamma.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   861
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   862
   png_ptr->colorspace.gamma = file_gamma;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   863
   png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   864
   png_ptr->screen_gamma = scrn_gamma;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   865
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   866
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   867
#  ifdef PNG_FLOATING_POINT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   869
png_set_gamma(png_structrp png_ptr, double scrn_gamma, double file_gamma)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   871
   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
   872
      convert_gamma_value(png_ptr, file_gamma));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   874
#  endif /* FLOATING_POINT */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   875
#endif /* READ_GAMMA */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   876
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   877
#ifdef PNG_READ_EXPAND_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
/* Expand paletted images to RGB, expand grayscale images of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
 * less than 8-bit depth to 8-bit depth, and expand tRNS chunks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
 * to alpha channels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   883
png_set_expand(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   885
   png_debug(1, "in png_set_expand");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   886
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   887
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   888
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   889
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
   png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
/* GRR 19990627:  the following three functions currently are identical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
 *  to png_set_expand().  However, it is entirely reasonable that someone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
 *  might wish to expand an indexed image to RGB but *not* expand a single,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
 *  fully transparent palette entry to a full alpha channel--perhaps instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
 *  convert tRNS to the grayscale/RGB format (16-bit RGB value), or replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
 *  the transparent color with a particular RGB value, or drop tRNS entirely.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
 *  IOW, a future version of the library may make the transformations flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
 *  a bit more fine-grained, with separate bits for each of these three
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
 *  functions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
 *  More to the point, these functions make it obvious what libpng will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
 *  doing, whereas "expand" can (and does) mean any number of things.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
 *
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   906
 *  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
   907
 *  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
   908
 *  and its name was changed to png_set_expand_gray_1_2_4_to_8().
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
/* Expand paletted images to RGB. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   913
png_set_palette_to_rgb(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   915
   png_debug(1, "in png_set_palette_to_rgb");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   916
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   917
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   918
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   919
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
   png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
/* Expand grayscale images of less than 8-bit depth to 8 bits. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   925
png_set_expand_gray_1_2_4_to_8(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   927
   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
   928
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   929
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   930
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   931
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
   png_ptr->transformations |= PNG_EXPAND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
}
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   934
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
/* Expand tRNS chunks to alpha channels. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   937
png_set_tRNS_to_alpha(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   939
   png_debug(1, "in png_set_tRNS_to_alpha");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   940
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   941
   if (png_rtran_ok(png_ptr, 0) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   942
      return;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   943
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
   png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   946
#endif /* READ_EXPAND */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   948
#ifdef PNG_READ_EXPAND_16_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   949
/* Expand to 16-bit channels, expand the tRNS chunk too (because otherwise
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   950
 * it may not work correctly.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   951
 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   952
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   953
png_set_expand_16(png_structrp png_ptr)
10576
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
   png_debug(1, "in png_set_expand_16");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   956
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   957
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   958
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   959
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   960
   png_ptr->transformations |= (PNG_EXPAND_16 | PNG_EXPAND | PNG_EXPAND_tRNS);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   961
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   962
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   963
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   964
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   966
png_set_gray_to_rgb(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   968
   png_debug(1, "in png_set_gray_to_rgb");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   969
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   970
   if (png_rtran_ok(png_ptr, 0) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   971
      return;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   972
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   973
   /* Because rgb must be 8 bits or more: */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   974
   png_set_expand_gray_1_2_4_to_8(png_ptr);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   975
   png_ptr->transformations |= PNG_GRAY_TO_RGB;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   979
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   980
void PNGFAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   981
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
   982
    png_fixed_point red, png_fixed_point green)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   983
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   984
   png_debug(1, "in png_set_rgb_to_gray");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   985
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   986
   /* Need the IHDR here because of the check on color_type below. */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   987
   /* TODO: fix this */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   988
   if (png_rtran_ok(png_ptr, 1) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   989
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   990
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   991
   switch (error_action)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   992
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   993
      case PNG_ERROR_ACTION_NONE:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   994
         png_ptr->transformations |= PNG_RGB_TO_GRAY;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   995
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   996
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   997
      case PNG_ERROR_ACTION_WARN:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   998
         png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   999
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1000
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1001
      case PNG_ERROR_ACTION_ERROR:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1002
         png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1003
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1004
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1005
      default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1006
         png_error(png_ptr, "invalid error action to rgb_to_gray");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1007
   }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1008
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1009
   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1010
#ifdef PNG_READ_EXPAND_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1011
      png_ptr->transformations |= PNG_EXPAND;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1012
#else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1013
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1014
      /* Make this an error in 1.6 because otherwise the application may assume
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1015
       * that it just worked and get a memory overwrite.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1016
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1017
      png_error(png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1018
        "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1019
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1020
      /* png_ptr->transformations &= ~PNG_RGB_TO_GRAY; */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1021
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1022
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1023
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1024
      if (red >= 0 && green >= 0 && red + green <= PNG_FP_1)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1025
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1026
         png_uint_16 red_int, green_int;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1027
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1028
         /* NOTE: this calculation does not round, but this behavior is retained
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1029
          * for consistency; the inaccuracy is very small.  The code here always
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1030
          * overwrites the coefficients, regardless of whether they have been
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1031
          * defaulted or set already.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1032
          */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1033
         red_int = (png_uint_16)(((png_uint_32)red*32768)/100000);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1034
         green_int = (png_uint_16)(((png_uint_32)green*32768)/100000);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1035
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1036
         png_ptr->rgb_to_gray_red_coeff   = red_int;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1037
         png_ptr->rgb_to_gray_green_coeff = green_int;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1038
         png_ptr->rgb_to_gray_coefficients_set = 1;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1039
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1040
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1041
      else
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
         if (red >= 0 && green >= 0)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1044
            png_app_warning(png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1045
               "ignoring out of range rgb_to_gray coefficients");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1046
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1047
         /* Use the defaults, from the cHRM chunk if set, else the historical
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1048
          * values which are close to the sRGB/HDTV/ITU-Rec 709 values.  See
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1049
          * png_do_rgb_to_gray for more discussion of the values.  In this case
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1050
          * the coefficients are not marked as 'set' and are not overwritten if
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1051
          * something has already provided a default.
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1052
          */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1053
         if (png_ptr->rgb_to_gray_red_coeff == 0 &&
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1054
            png_ptr->rgb_to_gray_green_coeff == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1055
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1056
            png_ptr->rgb_to_gray_red_coeff   = 6968;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1057
            png_ptr->rgb_to_gray_green_coeff = 23434;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1058
            /* png_ptr->rgb_to_gray_blue_coeff  = 2366; */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1059
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1060
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1061
   }
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
#ifdef PNG_FLOATING_POINT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
/* Convert a RGB image to a grayscale of the same width.  This allows us,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
 * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1070
png_set_rgb_to_gray(png_structrp png_ptr, int error_action, double red,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
   double green)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1073
   png_set_rgb_to_gray_fixed(png_ptr, error_action,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1074
      png_fixed(png_ptr, red, "rgb to gray red coefficient"),
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1075
      png_fixed(png_ptr, green, "rgb to gray green coefficient"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
}
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1077
#endif /* FLOATING POINT */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1078
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1079
#endif /* RGB_TO_GRAY */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1082
    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1084
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
  1085
    read_user_transform_fn)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1087
   png_debug(1, "in png_set_read_user_transform_fn");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1088
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1089
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
   png_ptr->transformations |= PNG_USER_TRANSFORM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
   png_ptr->read_user_transform_fn = read_user_transform_fn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1093
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1095
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1096
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1097
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1098
/* In the case of gamma transformations only do transformations on images where
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1099
 * the [file] gamma and screen_gamma are not close reciprocals, otherwise it
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1100
 * slows things down slightly, and also needlessly introduces small errors.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1101
 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1102
static int /* PRIVATE */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1103
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
  1104
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1105
   /* PNG_GAMMA_THRESHOLD is the threshold for performing gamma
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1106
    * correction as a difference of the overall transform from 1.0
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
    * 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
  1109
    * overflow here it is because of wacky gamma values so we
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1110
    * turn on processing anyway.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1111
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1112
   png_fixed_point gtest;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1113
   return !png_muldiv(&gtest, screen_gamma, file_gamma, PNG_FP_1) ||
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1114
       png_gamma_significant(gtest);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
/* Initialize everything needed for the read.  This includes modifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
 * the palette.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
 */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1121
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1122
/* For the moment 'png_init_palette_transformations' and
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1123
 * 'png_init_rgb_transformations' only do some flag canceling optimizations.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1124
 * 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
  1125
 * extracted from 'png_init_read_transformations'.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1126
 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1127
static void /* PRIVATE */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1128
png_init_palette_transformations(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1130
   /* Called to handle the (input) palette case.  In png_do_read_transformations
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1131
    * 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
  1132
    * 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
  1133
    * palette expansion, or only do them if there is no expansion.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1134
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1135
    * 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
  1136
    * to 0.)
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
   int input_has_alpha = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1139
   int input_has_transparency = 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
   if (png_ptr->num_trans > 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1142
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1143
      int i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1144
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1145
      /* Ignore if all the entries are opaque (unlikely!) */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1146
      for (i=0; i<png_ptr->num_trans; ++i)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1147
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1148
         if (png_ptr->trans_alpha[i] == 255)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1149
            continue;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1150
         else if (png_ptr->trans_alpha[i] == 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1151
            input_has_transparency = 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1152
         else
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1153
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1154
            input_has_transparency = 1;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1155
            input_has_alpha = 1;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1156
            break;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1157
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1158
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1159
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1160
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1161
   /* If no alpha we can optimize. */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1162
   if (input_has_alpha == 0)
10576
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
      /* Any alpha means background and associative alpha processing is
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1165
       * 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
  1166
       * and ENCODE_ALPHA are irrelevant.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1167
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1168
      png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1169
      png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1170
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1171
      if (input_has_transparency == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1172
         png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1173
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1176
   /* png_set_background handling - deals with the complexity of whether the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1177
    * 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
  1178
    * where an 'expand' will happen.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1180
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1181
   /* The following code cannot be entered in the alpha pre-multiplication case
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1182
    * because PNG_BACKGROUND_EXPAND is cancelled below.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1183
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1184
   if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1185
       (png_ptr->transformations & PNG_EXPAND) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1188
         png_ptr->background.red   =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1189
             png_ptr->palette[png_ptr->background.index].red;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1190
         png_ptr->background.green =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1191
             png_ptr->palette[png_ptr->background.index].green;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1192
         png_ptr->background.blue  =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1193
             png_ptr->palette[png_ptr->background.index].blue;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1194
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1195
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1196
        if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1197
        {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1198
           if ((png_ptr->transformations & PNG_EXPAND_tRNS) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1199
           {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1200
              /* Invert the alpha channel (in tRNS) unless the pixels are
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1201
               * going to be expanded, in which case leave it for later
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
              int i, istop = png_ptr->num_trans;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1204
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1205
              for (i=0; i<istop; i++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1206
                 png_ptr->trans_alpha[i] = (png_byte)(255 -
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1207
                    png_ptr->trans_alpha[i]);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1208
           }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1209
        }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1210
#endif /* READ_INVERT_ALPHA */
10576
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
   } /* background expand and (therefore) no alpha association. */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1213
#endif /* READ_EXPAND && READ_BACKGROUND */
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
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1216
static void /* PRIVATE */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1217
png_init_rgb_transformations(png_structrp png_ptr)
10576
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
   /* 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
  1220
    * is any alpha or transparency in the image and simply cancel the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1221
    * background and alpha mode stuff if there isn't.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1222
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1223
   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
  1224
   int input_has_transparency = png_ptr->num_trans > 0;
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
   /* If no alpha we can optimize. */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1227
   if (input_has_alpha == 0)
10576
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
      /* Any alpha means background and associative alpha processing is
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1230
       * 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
  1231
       * and ENCODE_ALPHA are irrelevant.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1232
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1233
#     ifdef PNG_READ_ALPHA_MODE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1234
         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1235
         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1236
#     endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1237
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1238
      if (input_has_transparency == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1239
         png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1240
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1241
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1242
#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1243
   /* png_set_background handling - deals with the complexity of whether the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1244
    * 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
  1245
    * where an 'expand' will happen.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1246
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1247
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1248
   /* The following code cannot be entered in the alpha pre-multiplication case
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1249
    * because PNG_BACKGROUND_EXPAND is cancelled below.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1250
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1251
   if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1252
       (png_ptr->transformations & PNG_EXPAND) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1253
       (png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1254
       /* i.e., GRAY or GRAY_ALPHA */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1255
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1256
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1257
         /* Expand background and tRNS chunks */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1258
         int gray = png_ptr->background.gray;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1259
         int trans_gray = png_ptr->trans_color.gray;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1260
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
         switch (png_ptr->bit_depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            case 1:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1264
               gray *= 0xff;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1265
               trans_gray *= 0xff;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
               break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1267
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
            case 2:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1269
               gray *= 0x55;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1270
               trans_gray *= 0x55;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
               break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1272
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            case 4:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1274
               gray *= 0x11;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1275
               trans_gray *= 0x11;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
               break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1277
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1278
            default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1279
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            case 8:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1281
               /* FALL THROUGH (Already 8 bits) */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1282
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            case 16:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1284
               /* Already a full 16 bits */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
               break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
         }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1287
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1288
         png_ptr->background.red = png_ptr->background.green =
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1289
            png_ptr->background.blue = (png_uint_16)gray;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1290
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1291
         if ((png_ptr->transformations & PNG_EXPAND_tRNS) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1292
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1293
            png_ptr->trans_color.red = png_ptr->trans_color.green =
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1294
               png_ptr->trans_color.blue = (png_uint_16)trans_gray;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1295
         }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1297
   } /* background expand and (therefore) no alpha association. */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1298
#endif /* READ_EXPAND && READ_BACKGROUND */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1299
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1300
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1301
void /* PRIVATE */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1302
png_init_read_transformations(png_structrp png_ptr)
10576
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
   png_debug(1, "in png_init_read_transformations");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1305
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1306
   /* 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
  1307
    * 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
  1308
    * in here can change or update the transformations flags.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1309
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1310
    * 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
  1311
    * being processed.
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
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1314
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1315
   /* 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
  1316
    * 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
  1317
    * 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
  1318
    * 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
  1319
    * longer necessary (and doesn't seem to have been necessary before.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1320
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1321
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1322
      /* The following temporary indicates if overall gamma correction is
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1323
       * required.
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
      int gamma_correction = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1326
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1327
      if (png_ptr->colorspace.gamma != 0) /* has been set */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1329
         if (png_ptr->screen_gamma != 0) /* screen set too */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1330
            gamma_correction = png_gamma_threshold(png_ptr->colorspace.gamma,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1331
               png_ptr->screen_gamma);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1332
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1333
         else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1334
            /* Assume the output matches the input; a long time default behavior
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1335
             * of libpng, although the standard has nothing to say about this.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1336
             */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1337
            png_ptr->screen_gamma = png_reciprocal(png_ptr->colorspace.gamma);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1338
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1339
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1340
      else if (png_ptr->screen_gamma != 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1341
         /* The converse - assume the file matches the screen, note that this
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1342
          * perhaps undesireable default can (from 1.5.4) be changed by calling
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1343
          * 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
  1344
          * or isn't changed from the default.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1345
          */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1346
         png_ptr->colorspace.gamma = png_reciprocal(png_ptr->screen_gamma);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1347
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1348
      else /* neither are set */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1349
         /* Just in case the following prevents any processing - file and screen
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1350
          * 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
  1351
          * third gamma value other than png_set_background with 'UNIQUE', and,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1352
          * prior to 1.5.4
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1353
          */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1354
         png_ptr->screen_gamma = png_ptr->colorspace.gamma = PNG_FP_1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1355
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1356
      /* We have a gamma value now. */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1357
      png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1358
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1359
      /* Now turn the gamma transformation on or off as appropriate.  Notice
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1360
       * that PNG_GAMMA just refers to the file->screen correction.  Alpha
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1361
       * composition may independently cause gamma correction because it needs
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1362
       * 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
  1363
       * 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
  1364
       * the code immediately below if the transform can be handled outside the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1365
       * row loop.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1366
       */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1367
      if (gamma_correction != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1368
         png_ptr->transformations |= PNG_GAMMA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1369
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1370
      else
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
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1374
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1375
   /* Certain transformations have the effect of preventing other
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1376
    * transformations that happen afterward in png_do_read_transformations;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1377
    * resolve the interdependencies here.  From the code of
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1378
    * png_do_read_transformations the order is:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1379
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1380
    *  1) PNG_EXPAND (including PNG_EXPAND_tRNS)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1381
    *  2) PNG_STRIP_ALPHA (if no compose)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1382
    *  3) PNG_RGB_TO_GRAY
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1383
    *  4) PNG_GRAY_TO_RGB iff !PNG_BACKGROUND_IS_GRAY
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1384
    *  5) PNG_COMPOSE
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1385
    *  6) PNG_GAMMA
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1386
    *  7) PNG_STRIP_ALPHA (if compose)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1387
    *  8) PNG_ENCODE_ALPHA
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1388
    *  9) PNG_SCALE_16_TO_8
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1389
    * 10) PNG_16_TO_8
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1390
    * 11) PNG_QUANTIZE (converts to palette)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1391
    * 12) PNG_EXPAND_16
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1392
    * 13) PNG_GRAY_TO_RGB iff PNG_BACKGROUND_IS_GRAY
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1393
    * 14) PNG_INVERT_MONO
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1394
    * 15) PNG_INVERT_ALPHA
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1395
    * 16) PNG_SHIFT
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1396
    * 17) PNG_PACK
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1397
    * 18) PNG_BGR
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1398
    * 19) PNG_PACKSWAP
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1399
    * 20) PNG_FILLER (includes PNG_ADD_ALPHA)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1400
    * 21) PNG_SWAP_ALPHA
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1401
    * 22) PNG_SWAP_BYTES
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1402
    * 23) PNG_USER_TRANSFORM [must be last]
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1403
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1404
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1405
   if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1406
       (png_ptr->transformations & PNG_COMPOSE) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1407
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1408
      /* Stripping the alpha channel happens immediately after the 'expand'
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1409
       * transformations, before all other transformation, so it cancels out
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1410
       * the alpha handling.  It has the side effect negating the effect of
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1411
       * PNG_EXPAND_tRNS too:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1412
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1413
      png_ptr->transformations &= ~(PNG_BACKGROUND_EXPAND | PNG_ENCODE_ALPHA |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1414
         PNG_EXPAND_tRNS);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1415
      png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1416
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1417
      /* 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
  1418
       * so transparency information would remain just so long as it wasn't
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1419
       * expanded.  This produces unexpected API changes if the set of things
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1420
       * that do PNG_EXPAND_tRNS changes (perfectly possible given the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1421
       * documentation - which says ask for what you want, accept what you
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1422
       * get.)  This makes the behavior consistent from 1.5.4:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1423
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1424
      png_ptr->num_trans = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1425
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1426
#endif /* STRIP_ALPHA supported, no COMPOSE */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1427
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1428
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1429
   /* 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
  1430
    * settings will have no effect.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1431
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1432
   if (png_gamma_significant(png_ptr->screen_gamma) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1433
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1434
      png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1435
      png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1439
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1440
   /* Make sure the coefficients for the rgb to gray conversion are set
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1441
    * appropriately.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1442
    */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1443
   if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1444
      png_colorspace_set_rgb_coefficients(png_ptr);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1445
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1446
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1447
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1448
#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1449
   /* Detect gray background and attempt to enable optimization for
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1450
    * gray --> RGB case.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1451
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1452
    * 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
  1453
    * RGB_ALPHA (in which case need_expand is superfluous anyway), the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1454
    * background color might actually be gray yet not be flagged as such.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1455
    * This is not a problem for the current code, which uses
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1456
    * PNG_BACKGROUND_IS_GRAY only to decide when to do the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1457
    * png_do_gray_to_rgb() transformation.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1458
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1459
    * TODO: this code needs to be revised to avoid the complexity and
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1460
    * interdependencies.  The color type of the background should be recorded in
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1461
    * 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
  1462
    * of exactly what color space the background is currently in.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1463
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1464
   if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1465
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1466
      /* PNG_BACKGROUND_EXPAND: the background is in the file color space, so if
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1467
       * the file was grayscale the background value is gray.
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1468
       */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1469
      if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1470
         png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1471
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1472
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1473
   else if ((png_ptr->transformations & PNG_COMPOSE) != 0)
10576
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
      /* PNG_COMPOSE: png_set_background was called with need_expand false,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1476
       * 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
  1477
       * 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
  1478
       * happens before GRAY_TO_RGB.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1479
       */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1480
      if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1481
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1482
         if (png_ptr->background.red == png_ptr->background.green &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1483
             png_ptr->background.red == png_ptr->background.blue)
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
            png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1486
            png_ptr->background.gray = png_ptr->background.red;
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
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1489
   }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1490
#endif /* READ_EXPAND && READ_BACKGROUND */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1491
#endif /* READ_GRAY_TO_RGB */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1492
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1493
   /* For indexed PNG data (PNG_COLOR_TYPE_PALETTE) many of the transformations
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1494
    * 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
  1495
    * can be optimized inside the palette.  This is particularly true of the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1496
    * composite (background and alpha) stuff, which can be pretty much all done
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1497
    * 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
  1498
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1499
    * 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
  1500
    * 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
  1501
    * 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
  1502
    * updated.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1503
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1504
   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1505
      png_init_palette_transformations(png_ptr);
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
   else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1508
      png_init_rgb_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
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1511
   defined(PNG_READ_EXPAND_16_SUPPORTED)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1512
   if ((png_ptr->transformations & PNG_EXPAND_16) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1513
       (png_ptr->transformations & PNG_COMPOSE) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1514
       (png_ptr->transformations & PNG_BACKGROUND_EXPAND) == 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1515
       png_ptr->bit_depth != 16)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1517
      /* TODO: fix this.  Because the expand_16 operation is after the compose
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1518
       * 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
  1519
       * application will supply a 16-bit value so reduce it here.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1520
       *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1521
       * 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
  1522
       * present, so that case is ok (until do_expand_16 is moved.)
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
       * NOTE: this discards the low 16 bits of the user supplied background
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1525
       * color, but until expand_16 works properly there is no choice!
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1526
       */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1527
#     define CHOP(x) (x)=((png_uint_16)PNG_DIV257(x))
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1528
      CHOP(png_ptr->background.red);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1529
      CHOP(png_ptr->background.green);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1530
      CHOP(png_ptr->background.blue);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1531
      CHOP(png_ptr->background.gray);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1532
#     undef CHOP
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
   }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1534
#endif /* READ_BACKGROUND && READ_EXPAND_16 */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1535
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1536
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1537
   (defined(PNG_READ_SCALE_16_TO_8_SUPPORTED) || \
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1538
   defined(PNG_READ_STRIP_16_TO_8_SUPPORTED))
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1539
   if ((png_ptr->transformations & (PNG_16_TO_8|PNG_SCALE_16_TO_8)) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1540
       (png_ptr->transformations & PNG_COMPOSE) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1541
       (png_ptr->transformations & PNG_BACKGROUND_EXPAND) == 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1542
       png_ptr->bit_depth == 16)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1543
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1544
      /* 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
  1545
       * component this will also happen after PNG_COMPOSE and so the background
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1546
       * color must be pre-expanded here.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1547
       *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1548
       * TODO: fix this too.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1549
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1550
      png_ptr->background.red = (png_uint_16)(png_ptr->background.red * 257);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1551
      png_ptr->background.green =
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1552
         (png_uint_16)(png_ptr->background.green * 257);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1553
      png_ptr->background.blue = (png_uint_16)(png_ptr->background.blue * 257);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1554
      png_ptr->background.gray = (png_uint_16)(png_ptr->background.gray * 257);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1555
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1556
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1557
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1558
   /* 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
  1559
    * background support (see the comments in scripts/pnglibconf.dfa), this
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1560
    * allows pre-multiplication of the alpha channel to be implemented as
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1561
    * 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
  1562
    * 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
  1563
    * implement the new API quickly, without lots of internal changes.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1564
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1565
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1566
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1567
#  ifdef PNG_READ_BACKGROUND_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1568
      /* Includes ALPHA_MODE */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1569
      png_ptr->background_1 = png_ptr->background;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1570
#  endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1571
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1572
   /* 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
  1573
    * 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
  1574
    * each palette entry directly.  Also, the test is too tricky - why check
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1575
    * 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
  1576
    * 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
  1577
    * PNG_COMPOSE case, so apparently if there is no *overall* gamma correction
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1578
    * 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
  1579
    * gamma encoded value.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1580
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1581
    * 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
  1582
    * 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
  1583
    * tables.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1584
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1585
   if ((png_ptr->transformations & PNG_GAMMA) != 0 ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1586
       ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1587
        (png_gamma_significant(png_ptr->colorspace.gamma) != 0 ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1588
         png_gamma_significant(png_ptr->screen_gamma) != 0)) ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1589
        ((png_ptr->transformations & PNG_COMPOSE) != 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
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1592
#  ifdef PNG_READ_BACKGROUND_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1593
         || (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_UNIQUE &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1594
           png_gamma_significant(png_ptr->background_gamma) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1595
#  endif
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1596
        )) || ((png_ptr->transformations & PNG_ENCODE_ALPHA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1597
       png_gamma_significant(png_ptr->screen_gamma) != 0))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1599
      png_build_gamma_table(png_ptr, png_ptr->bit_depth);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1600
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1601
#ifdef PNG_READ_BACKGROUND_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1602
      if ((png_ptr->transformations & PNG_COMPOSE) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1604
         /* Issue a warning about this combination: because RGB_TO_GRAY is
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1605
          * optimized to do the gamma transform if present yet do_background has
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1606
          * to do the same thing if both options are set a
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1607
          * double-gamma-correction happens.  This is true in all versions of
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1608
          * libpng to date.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1609
          */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1610
         if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1611
            png_warning(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1612
               "libpng does not support gamma+background+rgb_to_gray");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1613
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1614
         if ((png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1616
            /* 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
  1617
             * entries - see the checking code at the start of this function.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1618
             */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
            png_color back, back_1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
            png_colorp palette = png_ptr->palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
            int num_palette = png_ptr->num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
            if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1625
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
               back.red = png_ptr->gamma_table[png_ptr->background.red];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
               back.green = png_ptr->gamma_table[png_ptr->background.green];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
               back.blue = png_ptr->gamma_table[png_ptr->background.blue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
               back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
               back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
               back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1636
               png_fixed_point g, gs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
               switch (png_ptr->background_gamma_type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                  case PNG_BACKGROUND_GAMMA_SCREEN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                     g = (png_ptr->screen_gamma);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1642
                     gs = PNG_FP_1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                     break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1644
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
                  case PNG_BACKGROUND_GAMMA_FILE:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1646
                     g = png_reciprocal(png_ptr->colorspace.gamma);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1647
                     gs = png_reciprocal2(png_ptr->colorspace.gamma,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1648
                        png_ptr->screen_gamma);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                     break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1650
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
                  case PNG_BACKGROUND_GAMMA_UNIQUE:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1652
                     g = png_reciprocal(png_ptr->background_gamma);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1653
                     gs = png_reciprocal2(png_ptr->background_gamma,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1654
                        png_ptr->screen_gamma);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                     break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                  default:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1657
                     g = PNG_FP_1;    /* back_1 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1658
                     gs = PNG_FP_1;   /* back */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1659
                     break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1662
               if (png_gamma_significant(gs) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1663
               {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1664
                  back.red = png_gamma_8bit_correct(png_ptr->background.red,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1665
                      gs);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1666
                  back.green = png_gamma_8bit_correct(png_ptr->background.green,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1667
                      gs);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1668
                  back.blue = png_gamma_8bit_correct(png_ptr->background.blue,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1669
                      gs);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1670
               }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1671
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1672
               else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
                  back.red   = (png_byte)png_ptr->background.red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                  back.green = (png_byte)png_ptr->background.green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                  back.blue  = (png_byte)png_ptr->background.blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1678
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1679
               if (png_gamma_significant(g) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1680
               {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1681
                  back_1.red = png_gamma_8bit_correct(png_ptr->background.red,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1682
                     g);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1683
                  back_1.green = png_gamma_8bit_correct(
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1684
                     png_ptr->background.green, g);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1685
                  back_1.blue = png_gamma_8bit_correct(png_ptr->background.blue,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1686
                     g);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1687
               }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1688
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
               {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1691
                  back_1.red   = (png_byte)png_ptr->background.red;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1692
                  back_1.green = (png_byte)png_ptr->background.green;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1693
                  back_1.blue  = (png_byte)png_ptr->background.blue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1696
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
            for (i = 0; i < num_palette; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1699
               if (i < (int)png_ptr->num_trans &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1700
                   png_ptr->trans_alpha[i] != 0xff)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
               {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1702
                  if (png_ptr->trans_alpha[i] == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
                     palette[i] = back;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1706
                  else /* if (png_ptr->trans_alpha[i] != 0xff) */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
                     png_byte v, w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
                     v = png_ptr->gamma_to_1[palette[i].red];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1711
                     png_composite(w, v, png_ptr->trans_alpha[i], back_1.red);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
                     palette[i].red = png_ptr->gamma_from_1[w];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
                     v = png_ptr->gamma_to_1[palette[i].green];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1715
                     png_composite(w, v, png_ptr->trans_alpha[i], back_1.green);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
                     palette[i].green = png_ptr->gamma_from_1[w];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
                     v = png_ptr->gamma_to_1[palette[i].blue];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1719
                     png_composite(w, v, png_ptr->trans_alpha[i], back_1.blue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
                     palette[i].blue = png_ptr->gamma_from_1[w];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
                  palette[i].red = png_ptr->gamma_table[palette[i].red];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
                  palette[i].green = png_ptr->gamma_table[palette[i].green];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
                  palette[i].blue = png_ptr->gamma_table[palette[i].blue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1730
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1731
            /* Prevent the transformations being done again.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1732
             *
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1733
             * NOTE: this is highly dubious; it removes the transformations in
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1734
             * place.  This seems inconsistent with the general treatment of the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1735
             * transformations elsewhere.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1736
             */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1737
            png_ptr->transformations &= ~(PNG_COMPOSE | PNG_GAMMA);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1738
         } /* color_type == PNG_COLOR_TYPE_PALETTE */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1739
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
         /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1741
         else /* color_type != PNG_COLOR_TYPE_PALETTE */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1743
            int gs_sig, g_sig;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1744
            png_fixed_point g = PNG_FP_1;  /* Correction to linear */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1745
            png_fixed_point gs = PNG_FP_1; /* Correction to screen */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
            switch (png_ptr->background_gamma_type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
               case PNG_BACKGROUND_GAMMA_SCREEN:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1750
                  g = png_ptr->screen_gamma;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1751
                  /* gs = PNG_FP_1; */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
                  break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1753
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
               case PNG_BACKGROUND_GAMMA_FILE:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1755
                  g = png_reciprocal(png_ptr->colorspace.gamma);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1756
                  gs = png_reciprocal2(png_ptr->colorspace.gamma,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1757
                     png_ptr->screen_gamma);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
                  break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1759
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
               case PNG_BACKGROUND_GAMMA_UNIQUE:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1761
                  g = png_reciprocal(png_ptr->background_gamma);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1762
                  gs = png_reciprocal2(png_ptr->background_gamma,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1763
                      png_ptr->screen_gamma);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                  break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1765
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1766
               default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1767
                  png_error(png_ptr, "invalid background gamma type");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1770
            g_sig = png_gamma_significant(g);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1771
            gs_sig = png_gamma_significant(gs);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1772
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1773
            if (g_sig != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1774
               png_ptr->background_1.gray = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1775
                   png_ptr->background.gray, g);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1776
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1777
            if (gs_sig != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1778
               png_ptr->background.gray = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1779
                   png_ptr->background.gray, gs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
            if ((png_ptr->background.red != png_ptr->background.green) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
                (png_ptr->background.red != png_ptr->background.blue) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
                (png_ptr->background.red != png_ptr->background.gray))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
               /* RGB or RGBA with color background */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1786
               if (g_sig != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1787
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1788
                  png_ptr->background_1.red = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1789
                      png_ptr->background.red, g);
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.green = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1792
                      png_ptr->background.green, 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.blue = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1795
                      png_ptr->background.blue, g);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1796
               }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1797
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1798
               if (gs_sig != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1799
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1800
                  png_ptr->background.red = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1801
                      png_ptr->background.red, gs);
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.green = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1804
                      png_ptr->background.green, 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.blue = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1807
                      png_ptr->background.blue, gs);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1808
               }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1810
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
               /* GRAY, GRAY ALPHA, RGB, or RGBA with gray background */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
               png_ptr->background_1.red = png_ptr->background_1.green
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1815
                   = png_ptr->background_1.blue = png_ptr->background_1.gray;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1816
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
               png_ptr->background.red = png_ptr->background.green
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1818
                   = png_ptr->background.blue = png_ptr->background.gray;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
            }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1820
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1821
            /* The background is now in screen gamma: */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1822
            png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_SCREEN;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1823
         } /* color_type != PNG_COLOR_TYPE_PALETTE */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1824
      }/* png_ptr->transformations & PNG_BACKGROUND */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1825
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
      else
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1827
      /* Transformation does not include PNG_BACKGROUND */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1828
#endif /* READ_BACKGROUND */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1829
      if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1830
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1831
         /* RGB_TO_GRAY needs to have non-gamma-corrected values! */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1832
         && ((png_ptr->transformations & PNG_EXPAND) == 0 ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1833
         (png_ptr->transformations & PNG_RGB_TO_GRAY) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1834
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1835
         )
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
         png_colorp palette = png_ptr->palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
         int num_palette = png_ptr->num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
         int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1841
         /* NOTE: there are other transformations that should probably be in
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1842
          * here too.
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1843
          */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
         for (i = 0; i < num_palette; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
            palette[i].red = png_ptr->gamma_table[palette[i].red];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
            palette[i].green = png_ptr->gamma_table[palette[i].green];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
            palette[i].blue = png_ptr->gamma_table[palette[i].blue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1850
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1851
         /* Done the gamma correction. */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1852
         png_ptr->transformations &= ~PNG_GAMMA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1853
      } /* color_type == PALETTE && !PNG_BACKGROUND transformation */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1855
#ifdef PNG_READ_BACKGROUND_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
#endif
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1858
#endif /* READ_GAMMA */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1859
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1860
#ifdef PNG_READ_BACKGROUND_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1861
   /* No GAMMA transformation (see the hanging else 4 lines above) */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1862
   if ((png_ptr->transformations & PNG_COMPOSE) != 0 &&
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1863
       (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
      int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
      int istop = (int)png_ptr->num_trans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
      png_color back;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
      png_colorp palette = png_ptr->palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
      back.red   = (png_byte)png_ptr->background.red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
      back.green = (png_byte)png_ptr->background.green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
      back.blue  = (png_byte)png_ptr->background.blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
      for (i = 0; i < istop; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1876
         if (png_ptr->trans_alpha[i] == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
            palette[i] = back;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1880
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1881
         else if (png_ptr->trans_alpha[i] != 0xff)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
            /* The png_composite() macro is defined in png.h */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
            png_composite(palette[i].red, palette[i].red,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1885
                png_ptr->trans_alpha[i], back.red);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1886
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
            png_composite(palette[i].green, palette[i].green,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1888
                png_ptr->trans_alpha[i], back.green);
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].blue, palette[i].blue,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1891
                png_ptr->trans_alpha[i], back.blue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1894
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1895
      png_ptr->transformations &= ~PNG_COMPOSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
   }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1897
#endif /* READ_BACKGROUND */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1899
#ifdef PNG_READ_SHIFT_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1900
   if ((png_ptr->transformations & PNG_SHIFT) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1901
       (png_ptr->transformations & PNG_EXPAND) == 0 &&
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1902
       (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1904
      int i;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1905
      int istop = png_ptr->num_palette;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1906
      int shift = 8 - png_ptr->sig_bit.red;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1907
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1908
      png_ptr->transformations &= ~PNG_SHIFT;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1909
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1910
      /* 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
  1911
       * 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
  1912
       * error condition which is silently ignored.)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1913
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1914
      if (shift > 0 && shift < 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1915
         for (i=0; i<istop; ++i)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1916
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1917
            int component = png_ptr->palette[i].red;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1918
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1919
            component >>= shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1920
            png_ptr->palette[i].red = (png_byte)component;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1921
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1922
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1923
      shift = 8 - png_ptr->sig_bit.green;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1924
      if (shift > 0 && shift < 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1925
         for (i=0; i<istop; ++i)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1926
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1927
            int component = png_ptr->palette[i].green;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1928
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1929
            component >>= shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1930
            png_ptr->palette[i].green = (png_byte)component;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1931
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1932
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1933
      shift = 8 - png_ptr->sig_bit.blue;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1934
      if (shift > 0 && shift < 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1935
         for (i=0; i<istop; ++i)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1936
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1937
            int component = png_ptr->palette[i].blue;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1938
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1939
            component >>= shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1940
            png_ptr->palette[i].blue = (png_byte)component;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1941
         }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
   }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1943
#endif  /* READ_SHIFT */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
/* Modify the info structure to reflect the transformations.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
 * info should be updated so a PNG file could be written with it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
 * assuming the transformations result in valid PNG data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
void /* PRIVATE */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1951
png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1953
   png_debug(1, "in png_read_transform_info");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1954
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1955
#ifdef PNG_READ_EXPAND_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1956
   if ((png_ptr->transformations & PNG_EXPAND) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1960
         /* This check must match what actually happens in
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1961
          * 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
  1962
          * 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
  1963
          */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1964
         if (png_ptr->num_trans > 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
            info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1966
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
            info_ptr->color_type = PNG_COLOR_TYPE_RGB;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1969
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
         info_ptr->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
         info_ptr->num_trans = 0;
23903
3e78d4a02113 8031352: Enhance PNG handling
serb
parents: 10576
diff changeset
  1972
3e78d4a02113 8031352: Enhance PNG handling
serb
parents: 10576
diff changeset
  1973
         if (png_ptr->palette == NULL)
3e78d4a02113 8031352: Enhance PNG handling
serb
parents: 10576
diff changeset
  1974
            png_error (png_ptr, "Palette is NULL in indexed image");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1978
         if (png_ptr->num_trans != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1980
            if ((png_ptr->transformations & PNG_EXPAND_tRNS) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1981
               info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
         if (info_ptr->bit_depth < 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
            info_ptr->bit_depth = 8;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1985
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
         info_ptr->num_trans = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1991
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1992
   defined(PNG_READ_ALPHA_MODE_SUPPORTED)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1993
   /* The following is almost certainly wrong unless the background value is in
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1994
    * the screen space!
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1995
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1996
   if ((png_ptr->transformations & PNG_COMPOSE) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
      info_ptr->background = png_ptr->background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2000
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2001
   /* 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
  2002
    * 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
  2003
    * 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
  2004
    * sometimes does the gamma transform and cancels the flag.
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2005
    *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2006
    * 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
  2007
    * the screen_gamma value.  The following probably results in weirdness if
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2008
    * 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
  2009
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2010
   info_ptr->colorspace.gamma = png_ptr->colorspace.gamma;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2011
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2012
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2013
   if (info_ptr->bit_depth == 16)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2015
#  ifdef PNG_READ_16BIT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2016
#     ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2017
         if ((png_ptr->transformations & PNG_SCALE_16_TO_8) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2018
            info_ptr->bit_depth = 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2019
#     endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2020
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2021
#     ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2022
         if ((png_ptr->transformations & PNG_16_TO_8) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2023
            info_ptr->bit_depth = 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2024
#     endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2025
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2026
#  else
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2027
      /* 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
  2028
       * 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
  2029
       * correct scaling to use.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2030
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2031
#     ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2032
         /* For compatibility with previous versions use the strip method by
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2033
          * 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
  2034
          * set the code below will do that in preference to the chop.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2035
          */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2036
         png_ptr->transformations |= PNG_16_TO_8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2037
         info_ptr->bit_depth = 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2038
#     else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2039
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2040
#        ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2041
            png_ptr->transformations |= PNG_SCALE_16_TO_8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2042
            info_ptr->bit_depth = 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2043
#        else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2044
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2045
            CONFIGURATION ERROR: you must enable at least one 16 to 8 method
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2046
#        endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2047
#    endif
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2048
#endif /* !READ_16BIT */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2050
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2051
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2052
   if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2053
      info_ptr->color_type = (png_byte)(info_ptr->color_type |
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2054
         PNG_COLOR_MASK_COLOR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2057
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2058
   if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2059
      info_ptr->color_type = (png_byte)(info_ptr->color_type &
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2060
         ~PNG_COLOR_MASK_COLOR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2063
#ifdef PNG_READ_QUANTIZE_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2064
   if ((png_ptr->transformations & PNG_QUANTIZE) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
      if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2067
          (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2068
          png_ptr->palette_lookup != 0 && info_ptr->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
         info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2075
#ifdef PNG_READ_EXPAND_16_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2076
   if ((png_ptr->transformations & PNG_EXPAND_16) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2077
       info_ptr->bit_depth == 8 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2078
       info_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2079
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2080
      info_ptr->bit_depth = 16;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2081
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2082
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2083
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2084
#ifdef PNG_READ_PACK_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2085
   if ((png_ptr->transformations & PNG_PACK) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2086
       (info_ptr->bit_depth < 8))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
      info_ptr->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
   if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
      info_ptr->channels = 1;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2092
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2093
   else if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
      info_ptr->channels = 3;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2095
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
      info_ptr->channels = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2099
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2100
   if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2101
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2102
      info_ptr->color_type = (png_byte)(info_ptr->color_type &
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2103
         ~PNG_COLOR_MASK_ALPHA);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2104
      info_ptr->num_trans = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2105
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2108
   if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
      info_ptr->channels++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2111
#ifdef PNG_READ_FILLER_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
   /* STRIP_ALPHA and FILLER allowed:  MASK_ALPHA bit stripped above */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2113
   if ((png_ptr->transformations & PNG_FILLER) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2114
       (info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2115
       info_ptr->color_type == PNG_COLOR_TYPE_GRAY))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
      info_ptr->channels++;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2118
      /* If adding a true alpha channel not just filler */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2119
      if ((png_ptr->transformations & PNG_ADD_ALPHA) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2120
         info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2126
   if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2127
   {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2128
      if (png_ptr->user_transform_depth != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
         info_ptr->bit_depth = png_ptr->user_transform_depth;
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_channels != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
         info_ptr->channels = png_ptr->user_transform_channels;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2133
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
   info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2137
       info_ptr->bit_depth);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2138
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2139
   info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, info_ptr->width);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2140
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2141
   /* 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
  2142
    * 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
  2143
    * 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
  2144
    * 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
  2145
    * right itself.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2146
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2147
   png_ptr->info_rowbytes = info_ptr->rowbytes;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2148
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2149
#ifndef PNG_READ_EXPAND_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2150
   if (png_ptr != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2155
#ifdef PNG_READ_PACK_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
/* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
 * without changing the actual values.  Thus, if you had a row with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
 * a bit depth of 1, you would end up with bytes that only contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
 * the numbers 0 or 1.  If you would rather they contain 0 and 255, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
 * png_do_shift() after this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2162
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
png_do_unpack(png_row_infop row_info, png_bytep row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2165
   png_debug(1, "in png_do_unpack");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2166
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
   if (row_info->bit_depth < 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
      png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
      png_uint_32 row_width=row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
      switch (row_info->bit_depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
         case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
            png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
            png_bytep dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
            png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
               *dp = (png_byte)((*sp >> shift) & 0x01);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2182
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
               if (shift == 7)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
                  shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
                  sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2188
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
                  shift++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
               dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2196
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
         case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
            png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
            png_bytep dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
            png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
               *dp = (png_byte)((*sp >> shift) & 0x03);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2206
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
               if (shift == 6)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
                  shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
                  sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2212
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
                  shift += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
               dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2220
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
         case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
            png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
            png_bytep dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
            png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
               *dp = (png_byte)((*sp >> shift) & 0x0f);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2229
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
               if (shift == 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
                  shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
                  sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2235
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
                  shift = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
               dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2243
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2244
         default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2245
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
      row_info->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
      row_info->pixel_depth = (png_byte)(8 * row_info->channels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
      row_info->rowbytes = row_width * row_info->channels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2254
#ifdef PNG_READ_SHIFT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
/* Reverse the effects of png_do_shift.  This routine merely shifts the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
 * pixels back to their significant bits values.  Thus, if you have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
 * a row of bit depth 8, but only 5 are significant, this will shift
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
 * the values back to 0 through 31.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2260
static void
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2261
png_do_unshift(png_row_infop row_info, png_bytep row,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2262
    png_const_color_8p sig_bits)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
{
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2264
   int color_type;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2265
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2266
   png_debug(1, "in png_do_unshift");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2267
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2268
   /* The palette case has already been handled in the _init routine. */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2269
   color_type = row_info->color_type;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2270
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2271
   if (color_type != PNG_COLOR_TYPE_PALETTE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
      int shift[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
      int channels = 0;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2275
      int bit_depth = row_info->bit_depth;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2276
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2277
      if ((color_type & PNG_COLOR_MASK_COLOR) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2279
         shift[channels++] = bit_depth - sig_bits->red;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2280
         shift[channels++] = bit_depth - sig_bits->green;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2281
         shift[channels++] = bit_depth - sig_bits->blue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2283
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2286
         shift[channels++] = bit_depth - sig_bits->gray;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2288
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2289
      if ((color_type & PNG_COLOR_MASK_ALPHA) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2291
         shift[channels++] = bit_depth - sig_bits->alpha;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2295
         int c, have_shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2296
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2297
         for (c = have_shift = 0; c < channels; ++c)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2298
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2299
            /* A shift of more than the bit depth is an error condition but it
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2300
             * gets ignored here.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2301
             */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2302
            if (shift[c] <= 0 || shift[c] >= bit_depth)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2303
               shift[c] = 0;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2304
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2305
            else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2306
               have_shift = 1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2307
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2308
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2309
         if (have_shift == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2310
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2313
      switch (bit_depth)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2315
         default:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2316
         /* Must be 1bpp gray: should not be here! */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2317
            /* NOTREACHED */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2318
            break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2319
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
         case 2:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2321
         /* Must be 2bpp gray */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2322
         /* assert(channels == 1 && shift[0] == 1) */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2324
            png_bytep bp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2325
            png_bytep bp_end = bp + row_info->rowbytes;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2326
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2327
            while (bp < bp_end)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2329
               int b = (*bp >> 1) & 0x55;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2330
               *bp++ = (png_byte)b;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2334
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
         case 4:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2336
         /* Must be 4bpp gray */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2337
         /* assert(channels == 1) */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
            png_bytep bp = row;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2340
            png_bytep bp_end = bp + row_info->rowbytes;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2341
            int gray_shift = shift[0];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2342
            int mask =  0xf >> gray_shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2343
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2344
            mask |= mask << 4;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2345
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2346
            while (bp < bp_end)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2348
               int b = (*bp >> gray_shift) & mask;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2349
               *bp++ = (png_byte)b;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2353
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
         case 8:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2355
         /* Single byte components, G, GA, RGB, RGBA */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
            png_bytep bp = row;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2358
            png_bytep bp_end = bp + row_info->rowbytes;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2359
            int channel = 0;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2360
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2361
            while (bp < bp_end)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2363
               int b = *bp >> shift[channel];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2364
               if (++channel >= channels)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2365
                  channel = 0;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2366
               *bp++ = (png_byte)b;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2370
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2371
#ifdef PNG_READ_16BIT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
         case 16:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2373
         /* Double byte components, G, GA, RGB, RGBA */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
            png_bytep bp = row;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2376
            png_bytep bp_end = bp + row_info->rowbytes;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2377
            int channel = 0;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2378
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2379
            while (bp < bp_end)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2381
               int value = (bp[0] << 8) + bp[1];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2382
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2383
               value >>= shift[channel];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2384
               if (++channel >= channels)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2385
                  channel = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
               *bp++ = (png_byte)(value >> 8);
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2387
               *bp++ = (png_byte)value;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2391
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2397
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2398
/* Scale rows of bit depth 16 down to 8 accurately */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2399
static void
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2400
png_do_scale_16_to_8(png_row_infop row_info, png_bytep row)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2402
   png_debug(1, "in png_do_scale_16_to_8");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2403
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
   if (row_info->bit_depth == 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2406
      png_bytep sp = row; /* source */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2407
      png_bytep dp = row; /* destination */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2408
      png_bytep ep = sp + row_info->rowbytes; /* end+1 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2409
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2410
      while (sp < ep)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
      {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2412
         /* The input is an array of 16-bit components, these must be scaled to
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2413
          * 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
  2414
          * specification) is:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2415
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2416
          *    (V * 255) / 65535
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2417
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2418
          * This reduces to round(V / 257), or floor((V + 128.5)/257)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2419
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2420
          * 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
  2421
          * 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
  2422
          * is:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2423
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2424
          *    error = floor(((V-vhi.vhi) + 128.5) / 257)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2425
          *          = floor(((vlo-vhi) + 128.5) / 257)
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
          * This can be approximated using integer arithmetic (and a signed
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2428
          * shift):
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
          *    error = (vlo-vhi+128) >> 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2431
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2432
          * The approximate differs from the exact answer only when (vlo-vhi) is
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2433
          * 128; it then gives a correction of +1 when the exact correction is
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2434
          * 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
  2435
          * input values) is:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2436
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2437
          *    error = (vlo-vhi+128)*65535 >> 24;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2438
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2439
          * An alternative arithmetic calculation which also gives no errors is:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2440
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2441
          *    (V * 255 + 32895) >> 16
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2442
          */
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
         png_int_32 tmp = *sp++; /* must be signed! */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2445
         tmp += (((int)*sp++ - tmp + 128) * 65535) >> 24;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2446
         *dp++ = (png_byte)tmp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2448
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
      row_info->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
      row_info->pixel_depth = (png_byte)(8 * row_info->channels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
      row_info->rowbytes = row_info->width * row_info->channels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2456
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2457
static void
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2458
/* Simply discard the low byte.  This was the default behavior prior
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2459
 * to libpng-1.5.4.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2460
 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2461
png_do_chop(png_row_infop row_info, png_bytep row)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2462
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2463
   png_debug(1, "in png_do_chop");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2464
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2465
   if (row_info->bit_depth == 16)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2466
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2467
      png_bytep sp = row; /* source */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2468
      png_bytep dp = row; /* destination */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2469
      png_bytep ep = sp + row_info->rowbytes; /* end+1 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2470
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2471
      while (sp < ep)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2472
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2473
         *dp++ = *sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2474
         sp += 2; /* skip low byte */
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
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2477
      row_info->bit_depth = 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2478
      row_info->pixel_depth = (png_byte)(8 * row_info->channels);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2479
      row_info->rowbytes = row_info->width * row_info->channels;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2480
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2481
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2482
#endif
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
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2485
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2488
   png_debug(1, "in png_do_read_swap_alpha");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2489
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
      png_uint_32 row_width = row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
      if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
         /* This converts from RGBA to ARGB */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
         if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
            png_bytep sp = row + row_info->rowbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
            png_bytep dp = sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
            png_byte save;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
            png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
               save = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
               *(--dp) = save;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2511
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2512
#ifdef PNG_READ_16BIT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
         /* This converts from RRGGBBAA to AARRGGBB */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
            png_bytep sp = row + row_info->rowbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
            png_bytep dp = sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
            png_byte save[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
            png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
               save[0] = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
               save[1] = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
               *(--dp) = *(--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) = save[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
               *(--dp) = save[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2535
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2537
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
      else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
         /* This converts from GA to AG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
         if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
            png_bytep sp = row + row_info->rowbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
            png_bytep dp = sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
            png_byte save;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
            png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
               save = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
               *(--dp) = save;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2555
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2556
#ifdef PNG_READ_16BIT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
         /* This converts from GGAA to AAGG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
            png_bytep sp = row + row_info->rowbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
            png_bytep dp = sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
            png_byte save[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
            png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
               save[0] = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
               save[1] = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
               *(--dp) = save[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
               *(--dp) = save[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2575
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2581
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2582
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2585
   png_uint_32 row_width;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2586
   png_debug(1, "in png_do_read_invert_alpha");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2587
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2588
   row_width = row_info->width;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2589
   if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2591
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
         /* This inverts the alpha channel in RGBA */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2594
         png_bytep sp = row + row_info->rowbytes;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2595
         png_bytep dp = sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2596
         png_uint_32 i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2597
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2598
         for (i = 0; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2600
            *(--dp) = (png_byte)(255 - *(--sp));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2601
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2602
/*          This does nothing:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2603
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2604
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2605
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2606
            We can replace it with:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
*/
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2608
            sp-=3;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2609
            dp=sp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2612
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2613
#ifdef PNG_READ_16BIT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2614
      /* This inverts the alpha channel in RRGGBBAA */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2615
      else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2616
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2617
         png_bytep sp = row + row_info->rowbytes;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2618
         png_bytep dp = sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2619
         png_uint_32 i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2620
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2621
         for (i = 0; i < row_width; i++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2622
         {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2623
            *(--dp) = (png_byte)(255 - *(--sp));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2624
            *(--dp) = (png_byte)(255 - *(--sp));
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
/*          This does nothing:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2627
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2628
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2629
            *(--dp) = *(--sp);
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
            We can replace it with:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2634
*/
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2635
            sp-=6;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2636
            dp=sp;
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
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2639
#endif
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
   else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2642
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2643
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
         /* This inverts the alpha channel in GA */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2646
         png_bytep sp = row + row_info->rowbytes;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2647
         png_bytep dp = sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2648
         png_uint_32 i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2649
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2650
         for (i = 0; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2652
            *(--dp) = (png_byte)(255 - *(--sp));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2653
            *(--dp) = *(--sp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2656
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2657
#ifdef PNG_READ_16BIT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2658
      else
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
         /* This inverts the alpha channel in GGAA */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2661
         png_bytep sp  = row + row_info->rowbytes;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2662
         png_bytep dp = sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2663
         png_uint_32 i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2664
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2665
         for (i = 0; i < row_width; i++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2666
         {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2667
            *(--dp) = (png_byte)(255 - *(--sp));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2668
            *(--dp) = (png_byte)(255 - *(--sp));
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) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2671
            *(--dp) = *(--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
            sp-=2;
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
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2677
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2682
#ifdef PNG_READ_FILLER_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
/* Add filler channel if we have RGB color */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2684
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
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
  2686
    png_uint_32 filler, png_uint_32 flags)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
   png_uint_32 row_width = row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2691
#ifdef PNG_READ_16BIT_SUPPORTED
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2692
   png_byte hi_filler = (png_byte)(filler>>8);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2693
#endif
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2694
   png_byte lo_filler = (png_byte)filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2696
   png_debug(1, "in png_do_read_filler");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2697
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
   if (
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
       row_info->color_type == PNG_COLOR_TYPE_GRAY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2701
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2703
         if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2705
            /* This changes the data from G to GX */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
            png_bytep sp = row + (png_size_t)row_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
            png_bytep dp =  sp + (png_size_t)row_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
            for (i = 1; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
               *(--dp) = lo_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
               *(--dp) = *(--sp);
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
            row_info->channels = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
            row_info->pixel_depth = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
            row_info->rowbytes = row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2718
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2721
            /* This changes the data from G to XG */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
            png_bytep sp = row + (png_size_t)row_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
            png_bytep dp = sp  + (png_size_t)row_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
               *(--dp) = lo_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
            row_info->channels = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
            row_info->pixel_depth = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
            row_info->rowbytes = row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2734
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2735
#ifdef PNG_READ_16BIT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2736
      else if (row_info->bit_depth == 16)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2738
         if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2740
            /* This changes the data from GG to GGXX */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
            png_bytep sp = row + (png_size_t)row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
            png_bytep dp = sp  + (png_size_t)row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
            for (i = 1; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
            {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2745
               *(--dp) = lo_filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
               *(--dp) = hi_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
            }
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2750
            *(--dp) = lo_filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
            *(--dp) = hi_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
            row_info->channels = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
            row_info->pixel_depth = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
            row_info->rowbytes = row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2756
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2759
            /* This changes the data from GG to XXGG */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
            png_bytep sp = row + (png_size_t)row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
            png_bytep dp = sp  + (png_size_t)row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
               *(--dp) = *(--sp);
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2766
               *(--dp) = lo_filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
               *(--dp) = hi_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
            row_info->channels = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
            row_info->pixel_depth = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
            row_info->rowbytes = row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2774
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
   } /* COLOR_TYPE == GRAY */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
   else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2778
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2780
         if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2782
            /* This changes the data from RGB to RGBX */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
            png_bytep sp = row + (png_size_t)row_width * 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
            png_bytep dp = sp  + (png_size_t)row_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
            for (i = 1; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
               *(--dp) = lo_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
            *(--dp) = lo_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
            row_info->channels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
            row_info->pixel_depth = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
            row_info->rowbytes = row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2797
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2800
            /* This changes the data from RGB to XRGB */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
            png_bytep sp = row + (png_size_t)row_width * 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
            png_bytep dp = sp + (png_size_t)row_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
               *(--dp) = lo_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
            row_info->channels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
            row_info->pixel_depth = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
            row_info->rowbytes = row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2815
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2816
#ifdef PNG_READ_16BIT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2817
      else if (row_info->bit_depth == 16)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2819
         if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2821
            /* This changes the data from RRGGBB to RRGGBBXX */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
            png_bytep sp = row + (png_size_t)row_width * 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
            png_bytep dp = sp  + (png_size_t)row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
            for (i = 1; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
            {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2826
               *(--dp) = lo_filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
               *(--dp) = hi_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
               *(--dp) = *(--sp);
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
            }
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2835
            *(--dp) = lo_filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
            *(--dp) = hi_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
            row_info->channels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
            row_info->pixel_depth = 64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
            row_info->rowbytes = row_width * 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2841
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2844
            /* This changes the data from RRGGBB to XXRRGGBB */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
            png_bytep sp = row + (png_size_t)row_width * 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
            png_bytep dp = sp  + (png_size_t)row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
               *(--dp) = *(--sp);
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);
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2855
               *(--dp) = lo_filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
               *(--dp) = hi_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2858
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
            row_info->channels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
            row_info->pixel_depth = 64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
            row_info->rowbytes = row_width * 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2864
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
   } /* COLOR_TYPE == RGB */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2869
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2870
/* Expand grayscale files to RGB, with or without alpha */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2871
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
   png_uint_32 row_width = row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2877
   png_debug(1, "in png_do_gray_to_rgb");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2878
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
   if (row_info->bit_depth >= 8 &&
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2880
       (row_info->color_type & PNG_COLOR_MASK_COLOR) == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
      if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
         if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2886
            /* This changes G to RGB */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
            png_bytep sp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
            png_bytep dp = sp  + (png_size_t)row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2896
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2899
            /* This changes GG to RRGGBB */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
            png_bytep sp = row + (png_size_t)row_width * 2 - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
            png_bytep dp = sp  + (png_size_t)row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
               *(dp--) = *(sp - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
               *(dp--) = *(sp - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2913
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
      else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
         if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2918
            /* This changes GA to RGBA */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
            png_bytep sp = row + (png_size_t)row_width * 2 - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
            png_bytep dp = sp  + (png_size_t)row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2929
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2932
            /* This changes GGAA to RRGGBBAA */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
            png_bytep sp = row + (png_size_t)row_width * 4 - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
            png_bytep dp = sp  + (png_size_t)row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
               *(dp--) = *(sp - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
               *(dp--) = *(sp - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
      }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2948
      row_info->channels = (png_byte)(row_info->channels + 2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
      row_info->color_type |= PNG_COLOR_MASK_COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
      row_info->pixel_depth = (png_byte)(row_info->channels *
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2951
          row_info->bit_depth);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2952
      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2957
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2958
/* Reduce RGB files to grayscale, with or without alpha
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2959
 * using the equation given in Poynton's ColorFAQ of 1998-01-04 at
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2960
 * <http://www.inforamp.net/~poynton/>  (THIS LINK IS DEAD June 2008 but
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2961
 * versions dated 1998 through November 2002 have been archived at
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2962
 * http://web.archive.org/web/20000816232553/http://www.inforamp.net/
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2963
 * ~poynton/notes/colour_and_gamma/ColorFAQ.txt )
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2964
 * Charles Poynton poynton at poynton.com
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
 *     Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
 *  which can be expressed with integers as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
 *     Y = (6969 * R + 23434 * G + 2365 * B)/32768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
 *
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2972
 * Poynton's current link (as of January 2003 through July 2011):
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2973
 * <http://www.poynton.com/notes/colour_and_gamma/>
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2974
 * has changed the numbers slightly:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2975
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2976
 *     Y = 0.2126*R + 0.7152*G + 0.0722*B
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2977
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2978
 *  which can be expressed with integers as
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2979
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2980
 *     Y = (6966 * R + 23436 * G + 2366 * B)/32768
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2981
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2982
 *  Historically, however, libpng uses numbers derived from the ITU-R Rec 709
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2983
 *  end point chromaticities and the D65 white point.  Depending on the
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2984
 *  precision used for the D65 white point this produces a variety of different
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2985
 *  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
  2986
 *  used (0.3127,0.3290) the Y calculation would be:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2987
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2988
 *     Y = (6968 * R + 23435 * G + 2366 * B)/32768
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
 *
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2990
 *  While this is correct the rounding results in an overflow for white, because
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2991
 *  the sum of the rounded coefficients is 32769, not 32768.  Consequently
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2992
 *  libpng uses, instead, the closest non-overflowing approximation:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2993
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2994
 *     Y = (6968 * R + 23434 * G + 2366 * B)/32768
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2995
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2996
 *  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
  2997
 *  (including an sRGB chunk) then the chromaticities are used to calculate the
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2998
 *  coefficients.  See the chunk handling in pngrutil.c for more information.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2999
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3000
 *  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
  3001
 *  gamma information is available to correct the encoding of the original RGB
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3002
 *  values this results in an implicit assumption that the original PNG RGB
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3003
 *  values were linear.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3004
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3005
 *  Other integer coefficents can be used via png_set_rgb_to_gray().  Because
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3006
 *  the API takes just red and green coefficients the blue coefficient is
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3007
 *  calculated to make the sum 32768.  This will result in different rounding
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3008
 *  to that used above.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3010
static int
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3011
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
  3012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
   int rgb_error = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3016
   png_debug(1, "in png_do_rgb_to_gray");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3017
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3018
   if ((row_info->color_type & PNG_COLOR_MASK_PALETTE) == 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3019
       (row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3021
      PNG_CONST png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3022
      PNG_CONST png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3023
      PNG_CONST png_uint_32 bc = 32768 - rc - gc;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3024
      PNG_CONST png_uint_32 row_width = row_info->width;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3025
      PNG_CONST int have_alpha =
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3026
         (row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3027
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3028
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3030
#ifdef PNG_READ_GAMMA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3031
         /* Notice that gamma to/from 1 are not necessarily inverses (if
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3032
          * there is an overall gamma correction).  Prior to 1.5.5 this code
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3033
          * checked the linearized values for equality; this doesn't match
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3034
          * the documentation, the original values must be checked.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3035
          */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3036
         if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3038
            png_bytep sp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3039
            png_bytep dp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3040
            png_uint_32 i;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3041
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3042
            for (i = 0; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3044
               png_byte red   = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3045
               png_byte green = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3046
               png_byte blue  = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3047
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3048
               if (red != green || red != blue)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3049
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3050
                  red = png_ptr->gamma_to_1[red];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3051
                  green = png_ptr->gamma_to_1[green];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3052
                  blue = png_ptr->gamma_to_1[blue];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3053
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3054
                  rgb_error |= 1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3055
                  *(dp++) = png_ptr->gamma_from_1[
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3056
                      (rc*red + gc*green + bc*blue + 16384)>>15];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3057
               }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3058
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3059
               else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
               {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3061
                  /* If there is no overall correction the table will not be
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3062
                   * set.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3063
                   */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3064
                  if (png_ptr->gamma_table != NULL)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3065
                     red = png_ptr->gamma_table[red];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3066
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3067
                  *(dp++) = red;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3068
               }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3069
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3070
               if (have_alpha != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3071
                  *(dp++) = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3072
            }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3073
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3074
         else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3075
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3076
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3077
            png_bytep sp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3078
            png_bytep dp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3079
            png_uint_32 i;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3080
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3081
            for (i = 0; i < row_width; i++)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3082
            {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3083
               png_byte red   = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3084
               png_byte green = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3085
               png_byte blue  = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3086
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3087
               if (red != green || red != blue)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3088
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3089
                  rgb_error |= 1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3090
                  /* NOTE: this is the historical approach which simply
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3091
                   * truncates the results.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3092
                   */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3093
                  *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3094
               }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3095
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3096
               else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3097
                  *(dp++) = red;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3098
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3099
               if (have_alpha != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3100
                  *(dp++) = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3101
            }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3102
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3103
      }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3104
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3105
      else /* RGB bit_depth == 16 */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3106
      {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3107
#ifdef PNG_READ_GAMMA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3108
         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
  3109
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3110
            png_bytep sp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3111
            png_bytep dp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3112
            png_uint_32 i;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3113
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3114
            for (i = 0; i < row_width; i++)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3115
            {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3116
               png_uint_16 red, green, blue, w;
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3117
               png_byte hi,lo;
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3118
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3119
               hi=*(sp)++; lo=*(sp)++; red   = (png_uint_16)((hi << 8) | (lo));
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3120
               hi=*(sp)++; lo=*(sp)++; green = (png_uint_16)((hi << 8) | (lo));
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3121
               hi=*(sp)++; lo=*(sp)++; blue  = (png_uint_16)((hi << 8) | (lo));
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3122
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3123
               if (red == green && red == blue)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3124
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3125
                  if (png_ptr->gamma_16_table != NULL)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3126
                     w = png_ptr->gamma_16_table[(red & 0xff)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3127
                         >> png_ptr->gamma_shift][red >> 8];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3128
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
                  else
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3130
                     w = red;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
               }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3132
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3133
               else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
               {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3135
                  png_uint_16 red_1   = png_ptr->gamma_16_to_1[(red & 0xff)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3136
                      >> png_ptr->gamma_shift][red>>8];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3137
                  png_uint_16 green_1 =
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3138
                      png_ptr->gamma_16_to_1[(green & 0xff) >>
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3139
                      png_ptr->gamma_shift][green>>8];
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3140
                  png_uint_16 blue_1  = png_ptr->gamma_16_to_1[(blue & 0xff)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3141
                      >> png_ptr->gamma_shift][blue>>8];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3142
                  png_uint_16 gray16  = (png_uint_16)((rc*red_1 + gc*green_1
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3143
                      + bc*blue_1 + 16384)>>15);
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3144
                  w = png_ptr->gamma_16_from_1[(gray16 & 0xff) >>
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3145
                      png_ptr->gamma_shift][gray16 >> 8];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3146
                  rgb_error |= 1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3147
               }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3148
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3149
               *(dp++) = (png_byte)((w>>8) & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3150
               *(dp++) = (png_byte)(w & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3151
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3152
               if (have_alpha != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3153
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3154
                  *(dp++) = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3155
                  *(dp++) = *(sp++);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
         }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3159
         else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3160
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3162
            png_bytep sp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3163
            png_bytep dp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3164
            png_uint_32 i;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3165
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3166
            for (i = 0; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3168
               png_uint_16 red, green, blue, gray16;
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3169
               png_byte hi,lo;
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3170
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3171
               hi=*(sp)++; lo=*(sp)++; red   = (png_uint_16)((hi << 8) | (lo));
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3172
               hi=*(sp)++; lo=*(sp)++; green = (png_uint_16)((hi << 8) | (lo));
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3173
               hi=*(sp)++; lo=*(sp)++; blue  = (png_uint_16)((hi << 8) | (lo));
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3174
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3175
               if (red != green || red != blue)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3176
                  rgb_error |= 1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3177
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3178
               /* 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
  3179
                * in the 'fast' case - this is because this is where the code
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3180
                * ends up when handling linear 16-bit data.
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3181
                */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3182
               gray16  = (png_uint_16)((rc*red + gc*green + bc*blue + 16384) >>
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3183
                  15);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3184
               *(dp++) = (png_byte)((gray16 >> 8) & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3185
               *(dp++) = (png_byte)(gray16 & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3186
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3187
               if (have_alpha != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
                  *(dp++) = *(sp++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
                  *(dp++) = *(sp++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
      }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3195
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3196
      row_info->channels = (png_byte)(row_info->channels - 2);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3197
      row_info->color_type = (png_byte)(row_info->color_type &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3198
          ~PNG_COLOR_MASK_COLOR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
      row_info->pixel_depth = (png_byte)(row_info->channels *
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3200
          row_info->bit_depth);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3201
      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
   return rgb_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
#endif
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3206
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3207
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3208
   defined(PNG_READ_ALPHA_MODE_SUPPORTED)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
/* Replace any alpha or transparency with the supplied background color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
 * "background" is already in the screen gamma, while "background_1" is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
 * at a gamma of 1.0.  Paletted files have already been taken care of.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3213
static void
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3214
png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3216
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3217
   png_const_bytep gamma_table = png_ptr->gamma_table;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3218
   png_const_bytep gamma_from_1 = png_ptr->gamma_from_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3219
   png_const_bytep gamma_to_1 = png_ptr->gamma_to_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3220
   png_const_uint_16pp gamma_16 = png_ptr->gamma_16_table;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3221
   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
  3222
   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
  3223
   int gamma_shift = png_ptr->gamma_shift;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3224
   int optimize = (png_ptr->flags & PNG_FLAG_OPTIMIZE_ALPHA) != 0;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3225
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3226
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3227
   png_bytep sp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
   png_uint_32 i;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3229
   png_uint_32 row_width = row_info->width;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
   int shift;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3232
   png_debug(1, "in png_do_compose");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3233
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
      switch (row_info->color_type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
         case PNG_COLOR_TYPE_GRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
            switch (row_info->bit_depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
               case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
                  sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
                  shift = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
                  for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
                     if ((png_uint_16)((*sp >> shift) & 0x01)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3248
                        == png_ptr->trans_color.gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
                     {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3250
                        unsigned int tmp = *sp & (0x7f7f >> (7 - shift));
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3251
                        tmp |= png_ptr->background.gray << shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3252
                        *sp = (png_byte)(tmp & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3254
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3255
                     if (shift == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
                        shift = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
                        sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3260
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
                        shift--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3266
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
               case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
               {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3269
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
                  if (gamma_table != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
                     sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
                     shift = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
                     for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
                        if ((png_uint_16)((*sp >> shift) & 0x03)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3277
                            == png_ptr->trans_color.gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
                        {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3279
                           unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3280
                           tmp |= png_ptr->background.gray << shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3281
                           *sp = (png_byte)(tmp & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3283
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
                        {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3286
                           unsigned int p = (*sp >> shift) & 0x03;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3287
                           unsigned int g = (gamma_table [p | (p << 2) |
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3288
                               (p << 4) | (p << 6)] >> 6) & 0x03;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3289
                           unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3290
                           tmp |= g << shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3291
                           *sp = (png_byte)(tmp & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3293
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3294
                        if (shift == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
                           shift = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
                           sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3299
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
                           shift -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3304
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
                     sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
                     shift = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
                     for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
                        if ((png_uint_16)((*sp >> shift) & 0x03)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3313
                            == png_ptr->trans_color.gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
                        {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3315
                           unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3316
                           tmp |= png_ptr->background.gray << shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3317
                           *sp = (png_byte)(tmp & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3319
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3320
                        if (shift == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
                           shift = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
                           sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3325
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
                           shift -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3332
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
               case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
               {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3335
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
                  if (gamma_table != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
                     sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
                     shift = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
                     for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
                        if ((png_uint_16)((*sp >> shift) & 0x0f)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3343
                            == png_ptr->trans_color.gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
                        {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3345
                           unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3346
                           tmp |= png_ptr->background.gray << shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3347
                           *sp = (png_byte)(tmp & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3349
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
                        {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3352
                           unsigned int p = (*sp >> shift) & 0x0f;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3353
                           unsigned int g = (gamma_table[p | (p << 4)] >> 4) &
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3354
                              0x0f;
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3355
                           unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3356
                           tmp |= g << shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3357
                           *sp = (png_byte)(tmp & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3359
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3360
                        if (shift == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
                           shift = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
                           sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3365
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
                           shift -= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3370
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
                     sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
                     shift = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
                     for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
                        if ((png_uint_16)((*sp >> shift) & 0x0f)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3379
                            == png_ptr->trans_color.gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
                        {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3381
                           unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3382
                           tmp |= png_ptr->background.gray << shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3383
                           *sp = (png_byte)(tmp & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3385
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3386
                        if (shift == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
                           shift = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
                           sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3391
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
                           shift -= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3398
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
               case 8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
               {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3401
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
                  if (gamma_table != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
                     sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
                     for (i = 0; i < row_width; i++, sp++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3407
                        if (*sp == png_ptr->trans_color.gray)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3408
                           *sp = (png_byte)png_ptr->background.gray;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3409
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
                           *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
                     sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
                     for (i = 0; i < row_width; i++, sp++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3420
                        if (*sp == png_ptr->trans_color.gray)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3421
                           *sp = (png_byte)png_ptr->background.gray;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3426
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
               case 16:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
               {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3429
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
                  if (gamma_16 != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
                     sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
                     for (i = 0; i < row_width; i++, sp += 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
                        png_uint_16 v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
                        v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3438
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3439
                        if (v == png_ptr->trans_color.gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
                        {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3441
                           /* Background is already in screen gamma */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3442
                           *sp = (png_byte)((png_ptr->background.gray >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3443
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3444
                           *(sp + 1) = (png_byte)(png_ptr->background.gray
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3445
                                & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
                        }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3447
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
                           v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
                           *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
                           *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
                     sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
                     for (i = 0; i < row_width; i++, sp += 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
                        png_uint_16 v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
                        v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3465
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3466
                        if (v == png_ptr->trans_color.gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
                        {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3468
                           *sp = (png_byte)((png_ptr->background.gray >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3469
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3470
                           *(sp + 1) = (png_byte)(png_ptr->background.gray
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3471
                                & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3477
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3478
               default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3479
                  break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3483
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
         case PNG_COLOR_TYPE_RGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
            if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3488
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
               if (gamma_table != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
                  sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
                  for (i = 0; i < row_width; i++, sp += 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
                  {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3494
                     if (*sp == png_ptr->trans_color.red &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3495
                         *(sp + 1) == png_ptr->trans_color.green &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3496
                         *(sp + 2) == png_ptr->trans_color.blue)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3498
                        *sp = (png_byte)png_ptr->background.red;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3499
                        *(sp + 1) = (png_byte)png_ptr->background.green;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3500
                        *(sp + 2) = (png_byte)png_ptr->background.blue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3502
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
                        *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
                        *(sp + 1) = gamma_table[*(sp + 1)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
                        *(sp + 2) = gamma_table[*(sp + 2)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
                  sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
                  for (i = 0; i < row_width; i++, sp += 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
                  {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3517
                     if (*sp == png_ptr->trans_color.red &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3518
                         *(sp + 1) == png_ptr->trans_color.green &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3519
                         *(sp + 2) == png_ptr->trans_color.blue)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3521
                        *sp = (png_byte)png_ptr->background.red;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3522
                        *(sp + 1) = (png_byte)png_ptr->background.green;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3523
                        *(sp + 2) = (png_byte)png_ptr->background.blue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
            else /* if (row_info->bit_depth == 16) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3530
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
               if (gamma_16 != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
                  sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
                  for (i = 0; i < row_width; i++, sp += 6)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
                     png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3537
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3538
                     png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3539
                         + *(sp + 3));
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 b = (png_uint_16)(((*(sp + 4)) << 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3542
                         + *(sp + 5));
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
                     if (r == png_ptr->trans_color.red &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3545
                         g == png_ptr->trans_color.green &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3546
                         b == png_ptr->trans_color.blue)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3548
                        /* Background is already in screen gamma */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3549
                        *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3550
                        *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3551
                        *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3552
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3553
                        *(sp + 3) = (png_byte)(png_ptr->background.green
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3554
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3555
                        *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3556
                                & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3557
                        *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3559
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
                        png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
                        *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
                        *(sp + 1) = (png_byte)(v & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3565
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
                        v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
                        *(sp + 2) = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
                        *(sp + 3) = (png_byte)(v & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3569
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
                        v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
                        *(sp + 4) = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
                        *(sp + 5) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3577
               else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3578
#endif
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
                  sp = row;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3581
                  for (i = 0; i < row_width; i++, sp += 6)
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
                     png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3584
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3585
                     png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3586
                         + *(sp + 3));
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 b = (png_uint_16)(((*(sp + 4)) << 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3589
                         + *(sp + 5));
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
                     if (r == png_ptr->trans_color.red &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3592
                         g == png_ptr->trans_color.green &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3593
                         b == png_ptr->trans_color.blue)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3594
                     {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3595
                        *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3596
                        *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3597
                        *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3598
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3599
                        *(sp + 3) = (png_byte)(png_ptr->background.green
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3600
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3601
                        *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3602
                                & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3603
                        *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3604
                     }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3605
                  }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3606
               }
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
            break;
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
         case PNG_COLOR_TYPE_GRAY_ALPHA:
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
            if (row_info->bit_depth == 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3614
            {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3615
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3616
               if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3617
                   gamma_table != NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3618
               {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3619
                  sp = row;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3620
                  for (i = 0; i < row_width; i++, sp += 2)
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
                     png_uint_16 a = *(sp + 1);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3623
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3624
                     if (a == 0xff)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3625
                        *sp = gamma_table[*sp];
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
                     else if (a == 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3628
                     {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3629
                        /* Background is already in screen gamma */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3630
                        *sp = (png_byte)png_ptr->background.gray;
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
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3633
                     else
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
                        png_byte v, w;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3636
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3637
                        v = gamma_to_1[*sp];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3638
                        png_composite(w, v, a, png_ptr->background_1.gray);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3639
                        if (optimize == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3640
                           w = gamma_from_1[w];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3641
                        *sp = w;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3642
                     }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3643
                  }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3644
               }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3645
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3646
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3647
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
                  sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3649
                  for (i = 0; i < row_width; i++, sp += 2)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3650
                  {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3651
                     png_byte a = *(sp + 1);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3652
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3653
                     if (a == 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3654
                        *sp = (png_byte)png_ptr->background.gray;
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
                     else if (a < 0xff)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3657
                        png_composite(*sp, *sp, a, png_ptr->background.gray);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3658
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3661
            else /* if (png_ptr->bit_depth == 16) */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3663
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3664
               if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3665
                   gamma_16_to_1 != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
                  sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3668
                  for (i = 0; i < row_width; i++, sp += 4)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
                  {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3670
                     png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3671
                         + *(sp + 3));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3672
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3673
                     if (a == (png_uint_16)0xffff)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3674
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3675
                        png_uint_16 v;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3676
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3677
                        v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3678
                        *sp = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3679
                        *(sp + 1) = (png_byte)(v & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3680
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3681
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
                     else if (a == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3684
                        /* Background is already in screen gamma */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3685
                        *sp = (png_byte)((png_ptr->background.gray >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3686
                                & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3687
                        *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3689
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3692
                        png_uint_16 g, v, w;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3693
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3694
                        g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3695
                        png_composite_16(v, g, a, png_ptr->background_1.gray);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3696
                        if (optimize != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3697
                           w = v;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3698
                        else
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3699
                           w = gamma_16_from_1[(v & 0xff) >>
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3700
                               gamma_shift][v >> 8];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3701
                        *sp = (png_byte)((w >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3702
                        *(sp + 1) = (png_byte)(w & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3703
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3704
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3705
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3706
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3707
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3708
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
                  sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3710
                  for (i = 0; i < row_width; i++, sp += 4)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3711
                  {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3712
                     png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3713
                         + *(sp + 3));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3714
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3715
                     if (a == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3716
                     {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3717
                        *sp = (png_byte)((png_ptr->background.gray >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3718
                                & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3719
                        *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3720
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3721
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3722
                     else if (a < 0xffff)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3724
                        png_uint_16 g, v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
                        g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3727
                        png_composite_16(v, g, a, png_ptr->background.gray);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3728
                        *sp = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3729
                        *(sp + 1) = (png_byte)(v & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3730
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3731
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3732
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3733
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3734
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3736
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3737
         case PNG_COLOR_TYPE_RGB_ALPHA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3739
            if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3741
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
               if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3743
                   gamma_table != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3744
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
                  sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3746
                  for (i = 0; i < row_width; i++, sp += 4)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3747
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
                     png_byte a = *(sp + 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3749
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3750
                     if (a == 0xff)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3752
                        *sp = gamma_table[*sp];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3753
                        *(sp + 1) = gamma_table[*(sp + 1)];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3754
                        *(sp + 2) = gamma_table[*(sp + 2)];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3755
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3756
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3757
                     else if (a == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3758
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3759
                        /* Background is already in screen gamma */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3760
                        *sp = (png_byte)png_ptr->background.red;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3761
                        *(sp + 1) = (png_byte)png_ptr->background.green;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3762
                        *(sp + 2) = (png_byte)png_ptr->background.blue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3763
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3764
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3765
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
                        png_byte v, w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
                        v = gamma_to_1[*sp];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3770
                        png_composite(w, v, a, png_ptr->background_1.red);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3771
                        if (optimize == 0) w = gamma_from_1[w];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3772
                        *sp = w;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3773
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3774
                        v = gamma_to_1[*(sp + 1)];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3775
                        png_composite(w, v, a, png_ptr->background_1.green);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3776
                        if (optimize == 0) w = gamma_from_1[w];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3777
                        *(sp + 1) = w;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3778
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
                        v = gamma_to_1[*(sp + 2)];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3780
                        png_composite(w, v, a, png_ptr->background_1.blue);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3781
                        if (optimize == 0) w = gamma_from_1[w];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3782
                        *(sp + 2) = w;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3783
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3785
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3788
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3789
                  sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3790
                  for (i = 0; i < row_width; i++, sp += 4)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3791
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3792
                     png_byte a = *(sp + 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3793
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3794
                     if (a == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3795
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3796
                        *sp = (png_byte)png_ptr->background.red;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3797
                        *(sp + 1) = (png_byte)png_ptr->background.green;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3798
                        *(sp + 2) = (png_byte)png_ptr->background.blue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3799
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3800
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3801
                     else if (a < 0xff)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3802
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3803
                        png_composite(*sp, *sp, a, png_ptr->background.red);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3804
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3805
                        png_composite(*(sp + 1), *(sp + 1), a,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3806
                            png_ptr->background.green);
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 + 2), *(sp + 2), a,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3809
                            png_ptr->background.blue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3810
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3811
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3812
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
            else /* if (row_info->bit_depth == 16) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3816
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
               if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
                   gamma_16_to_1 != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3819
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
                  sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3821
                  for (i = 0; i < row_width; i++, sp += 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
                     png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3824
                         << 8) + (png_uint_16)(*(sp + 7)));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3825
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
                     if (a == (png_uint_16)0xffff)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
                        png_uint_16 v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
                        v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3831
                        *sp = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3832
                        *(sp + 1) = (png_byte)(v & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3833
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3834
                        v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3835
                        *(sp + 2) = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3836
                        *(sp + 3) = (png_byte)(v & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3837
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
                        v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3839
                        *(sp + 4) = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3840
                        *(sp + 5) = (png_byte)(v & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3842
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
                     else if (a == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3845
                        /* Background is already in screen gamma */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3846
                        *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3847
                        *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3848
                        *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3849
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3850
                        *(sp + 3) = (png_byte)(png_ptr->background.green
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3851
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3852
                        *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3853
                                & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3854
                        *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3855
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3856
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3857
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3859
                        png_uint_16 v, w;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
                        v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3862
                        png_composite_16(w, v, a, png_ptr->background_1.red);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3863
                        if (optimize == 0)
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3864
                           w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3865
                                8];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3866
                        *sp = (png_byte)((w >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3867
                        *(sp + 1) = (png_byte)(w & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3868
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3869
                        v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3870
                        png_composite_16(w, v, a, png_ptr->background_1.green);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3871
                        if (optimize == 0)
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3872
                           w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3873
                                8];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3874
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3875
                        *(sp + 2) = (png_byte)((w >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3876
                        *(sp + 3) = (png_byte)(w & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3877
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3878
                        v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3879
                        png_composite_16(w, v, a, png_ptr->background_1.blue);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3880
                        if (optimize == 0)
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3881
                           w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3882
                                8];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3883
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3884
                        *(sp + 4) = (png_byte)((w >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3885
                        *(sp + 5) = (png_byte)(w & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3889
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3892
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
                  sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3894
                  for (i = 0; i < row_width; i++, sp += 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
                     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
  3897
                         << 8) + (png_uint_16)(*(sp + 7)));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3898
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3899
                     if (a == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
                     {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3901
                        *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3902
                        *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3903
                        *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3904
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3905
                        *(sp + 3) = (png_byte)(png_ptr->background.green
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3906
                                & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3907
                        *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3908
                                & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3909
                        *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3911
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3912
                     else if (a < 0xffff)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3914
                        png_uint_16 v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3915
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
                        png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
                        png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
                            + *(sp + 3));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
                        png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
                            + *(sp + 5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3922
                        png_composite_16(v, r, a, png_ptr->background.red);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3923
                        *sp = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3924
                        *(sp + 1) = (png_byte)(v & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3925
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3926
                        png_composite_16(v, g, a, png_ptr->background.green);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3927
                        *(sp + 2) = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3928
                        *(sp + 3) = (png_byte)(v & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3929
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3930
                        png_composite_16(v, b, a, png_ptr->background.blue);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3931
                        *(sp + 4) = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3932
                        *(sp + 5) = (png_byte)(v & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3933
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3934
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3935
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3936
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3937
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3938
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3939
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3940
         default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3941
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3942
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3943
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3944
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3945
#endif /* READ_BACKGROUND || READ_ALPHA_MODE */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3946
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3947
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3948
/* Gamma correct the image, avoiding the alpha channel.  Make sure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3949
 * you do this after you deal with the transparency issue on grayscale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3950
 * or RGB images. If your bit depth is 8, use gamma_table, if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3951
 * is 16, use gamma_16_table and gamma_shift.  Build these with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3952
 * build_gamma_table().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3953
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3954
static void
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3955
png_do_gamma(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3956
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3957
   png_const_bytep gamma_table = png_ptr->gamma_table;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3958
   png_const_uint_16pp gamma_16_table = png_ptr->gamma_16_table;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3959
   int gamma_shift = png_ptr->gamma_shift;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3960
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3961
   png_bytep sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3962
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3963
   png_uint_32 row_width=row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3964
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3965
   png_debug(1, "in png_do_gamma");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3966
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3967
   if (((row_info->bit_depth <= 8 && gamma_table != NULL) ||
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3968
       (row_info->bit_depth == 16 && gamma_16_table != NULL)))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3969
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3970
      switch (row_info->color_type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3971
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3972
         case PNG_COLOR_TYPE_RGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
            if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3976
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3977
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3987
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
            else /* if (row_info->bit_depth == 16) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3990
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
                  png_uint_16 v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
                  sp += 2;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3999
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4000
                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4002
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4003
                  sp += 2;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4004
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4005
                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4006
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4007
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4008
                  sp += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4009
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4010
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4011
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4012
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4013
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4014
         case PNG_COLOR_TYPE_RGB_ALPHA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4015
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4016
            if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4017
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4018
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4019
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4020
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4021
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4022
                  sp++;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4023
2
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++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4031
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4032
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4033
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4034
            else /* if (row_info->bit_depth == 16) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4035
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4036
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4037
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4038
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4039
                  png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4040
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4041
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4042
                  sp += 2;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4043
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4044
                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4045
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4046
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4047
                  sp += 2;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4048
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4049
                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4050
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4051
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4052
                  sp += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4053
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4054
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4055
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4056
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4057
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4058
         case PNG_COLOR_TYPE_GRAY_ALPHA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4059
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4060
            if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4061
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4062
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4063
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4064
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4065
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4066
                  sp += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4067
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4068
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4069
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4070
            else /* if (row_info->bit_depth == 16) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4071
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4072
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4073
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4074
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4075
                  png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4076
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4077
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4078
                  sp += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4079
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4080
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4081
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4082
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4083
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4084
         case PNG_COLOR_TYPE_GRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4085
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4086
            if (row_info->bit_depth == 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4087
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4088
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4089
               for (i = 0; i < row_width; i += 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4090
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4091
                  int a = *sp & 0xc0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4092
                  int b = *sp & 0x30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4093
                  int c = *sp & 0x0c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4094
                  int d = *sp & 0x03;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4096
                  *sp = (png_byte)(
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4097
                      ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)])   ) & 0xc0)|
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4098
                      ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4099
                      ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4100
                      ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4101
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4102
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4103
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4104
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4105
            if (row_info->bit_depth == 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4106
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4107
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4108
               for (i = 0; i < row_width; i += 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4109
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4110
                  int msb = *sp & 0xf0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4111
                  int lsb = *sp & 0x0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4113
                  *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4114
                      | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4115
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4116
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4117
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4118
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4119
            else if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4120
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4121
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4122
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4123
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4124
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4125
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4126
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4127
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4128
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4129
            else if (row_info->bit_depth == 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4130
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4131
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4132
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4133
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4134
                  png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4135
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4136
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4137
                  sp += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4138
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4140
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4141
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4142
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4143
         default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4144
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4145
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4146
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4147
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4148
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4149
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4150
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4151
/* 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
  4152
 * 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
  4153
 * from_1 tables.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4154
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4155
static void
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4156
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
  4157
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4158
   png_uint_32 row_width = row_info->width;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4159
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4160
   png_debug(1, "in png_do_encode_alpha");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4161
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4162
   if ((row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4163
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4164
      if (row_info->bit_depth == 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4165
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4166
         PNG_CONST png_bytep table = png_ptr->gamma_from_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4167
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4168
         if (table != NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4169
         {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4170
            PNG_CONST int step =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4171
               (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 4 : 2;
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
            /* The alpha channel is the last component: */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4174
            row += step - 1;
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
            for (; row_width > 0; --row_width, row += step)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4177
               *row = table[*row];
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
            return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4180
         }
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
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4183
      else if (row_info->bit_depth == 16)
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
         PNG_CONST png_uint_16pp table = png_ptr->gamma_16_from_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4186
         PNG_CONST int gamma_shift = png_ptr->gamma_shift;
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
         if (table != NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4189
         {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4190
            PNG_CONST int step =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4191
               (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 8 : 4;
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
            /* The alpha channel is the last component: */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4194
            row += step - 2;
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
            for (; row_width > 0; --row_width, row += step)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4197
            {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4198
               png_uint_16 v;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4199
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4200
               v = table[*(row + 1) >> gamma_shift][*row];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4201
               *row = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4202
               *(row + 1) = (png_byte)(v & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4203
            }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4204
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4205
            return;
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
   }
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
   /* 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
  4211
    * so just issue a warning.
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
   png_warning(png_ptr, "png_do_encode_alpha: unexpected call");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4214
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4215
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4216
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4217
#ifdef PNG_READ_EXPAND_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4218
/* Expands a palette row to an RGB or RGBA row depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4219
 * upon whether you supply trans and num_trans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4220
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4221
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4222
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
  4223
   png_const_colorp palette, png_const_bytep trans_alpha, int num_trans)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4224
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4225
   int shift, value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4226
   png_bytep sp, dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4227
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4228
   png_uint_32 row_width=row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4229
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4230
   png_debug(1, "in png_do_expand_palette");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4231
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4232
   if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4233
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4234
      if (row_info->bit_depth < 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4235
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4236
         switch (row_info->bit_depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4237
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4238
            case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4239
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4240
               sp = row + (png_size_t)((row_width - 1) >> 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4241
               dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4242
               shift = 7 - (int)((row_width + 7) & 0x07);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4243
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4244
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4245
                  if ((*sp >> shift) & 0x01)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4246
                     *dp = 1;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4247
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4248
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4249
                     *dp = 0;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4250
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4251
                  if (shift == 7)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4252
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4253
                     shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4254
                     sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4255
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4256
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4257
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4258
                     shift++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4260
                  dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4261
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4262
               break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4263
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4264
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4265
            case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4266
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4267
               sp = row + (png_size_t)((row_width - 1) >> 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4268
               dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4269
               shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4270
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4271
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4272
                  value = (*sp >> shift) & 0x03;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4273
                  *dp = (png_byte)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4274
                  if (shift == 6)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4275
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4276
                     shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4277
                     sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4278
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4279
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4280
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4281
                     shift += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4283
                  dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4284
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4285
               break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4286
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4287
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4288
            case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4290
               sp = row + (png_size_t)((row_width - 1) >> 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4291
               dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4292
               shift = (int)((row_width & 0x01) << 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4293
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4294
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4295
                  value = (*sp >> shift) & 0x0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4296
                  *dp = (png_byte)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4297
                  if (shift == 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4298
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4299
                     shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
                     sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4301
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4302
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4303
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4304
                     shift += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4306
                  dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4307
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
               break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4309
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4310
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4311
            default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4312
               break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4313
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4314
         row_info->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4315
         row_info->pixel_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4316
         row_info->rowbytes = row_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4317
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4318
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4319
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4320
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4321
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4322
            if (num_trans > 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4323
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4324
               sp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4325
               dp = row + (png_size_t)(row_width << 2) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4327
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4328
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4329
                  if ((int)(*sp) >= num_trans)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4330
                     *dp-- = 0xff;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4331
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4332
                  else
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4333
                     *dp-- = trans_alpha[*sp];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4334
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4335
                  *dp-- = palette[*sp].blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4336
                  *dp-- = palette[*sp].green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4337
                  *dp-- = palette[*sp].red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4338
                  sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4339
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4340
               row_info->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4341
               row_info->pixel_depth = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4342
               row_info->rowbytes = row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4343
               row_info->color_type = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4344
               row_info->channels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4345
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4346
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4347
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4348
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4349
               sp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4350
               dp = row + (png_size_t)(row_width * 3) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4352
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4353
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4354
                  *dp-- = palette[*sp].blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4355
                  *dp-- = palette[*sp].green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4356
                  *dp-- = palette[*sp].red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4357
                  sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4358
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4359
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
               row_info->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4361
               row_info->pixel_depth = 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4362
               row_info->rowbytes = row_width * 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4363
               row_info->color_type = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4364
               row_info->channels = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4366
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
      }
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
/* If the bit depth < 8, it is expanded to 8.  Also, if the already
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
 * expanded transparency value is supplied, an alpha channel is built.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4374
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4375
png_do_expand(png_row_infop row_info, png_bytep row,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4376
    png_const_color_16p trans_color)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4377
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4378
   int shift, value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4379
   png_bytep sp, dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4380
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4381
   png_uint_32 row_width=row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4382
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4383
   png_debug(1, "in png_do_expand");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4384
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4385
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4386
      if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4387
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4388
         unsigned int gray = trans_color != NULL ? trans_color->gray : 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4390
         if (row_info->bit_depth < 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4391
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4392
            switch (row_info->bit_depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4393
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4394
               case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4395
               {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4396
                  gray = (gray & 0x01) * 0xff;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4397
                  sp = row + (png_size_t)((row_width - 1) >> 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4398
                  dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4399
                  shift = 7 - (int)((row_width + 7) & 0x07);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4400
                  for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4401
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4402
                     if ((*sp >> shift) & 0x01)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4403
                        *dp = 0xff;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4404
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4405
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4406
                        *dp = 0;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4407
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4408
                     if (shift == 7)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4409
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4410
                        shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4411
                        sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4412
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4413
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4414
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4415
                        shift++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4417
                     dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4418
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4419
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4420
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4421
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4422
               case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4423
               {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4424
                  gray = (gray & 0x03) * 0x55;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4425
                  sp = row + (png_size_t)((row_width - 1) >> 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4426
                  dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4427
                  shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4428
                  for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4429
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4430
                     value = (*sp >> shift) & 0x03;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4431
                     *dp = (png_byte)(value | (value << 2) | (value << 4) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4432
                        (value << 6));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4433
                     if (shift == 6)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4434
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4435
                        shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4436
                        sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4437
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4438
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4439
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4440
                        shift += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4441
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4442
                     dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4443
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4444
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4445
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4446
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4447
               case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4448
               {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4449
                  gray = (gray & 0x0f) * 0x11;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4450
                  sp = row + (png_size_t)((row_width - 1) >> 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4451
                  dp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4452
                  shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4453
                  for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4454
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4455
                     value = (*sp >> shift) & 0x0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4456
                     *dp = (png_byte)(value | (value << 4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4457
                     if (shift == 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4458
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4459
                        shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4460
                        sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4461
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4462
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4463
                     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4464
                        shift = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4466
                     dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4467
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4468
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4469
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4470
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4471
               default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4472
                  break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4473
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4474
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4475
            row_info->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4476
            row_info->pixel_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4477
            row_info->rowbytes = row_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4478
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4479
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4480
         if (trans_color != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4481
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4482
            if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4483
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4484
               gray = gray & 0xff;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4485
               sp = row + (png_size_t)row_width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4486
               dp = row + (png_size_t)(row_width << 1) - 1;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4487
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4488
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4489
               {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  4490
                  if ((*sp & 0xffU) == gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4491
                     *dp-- = 0;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4492
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4493
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4494
                     *dp-- = 0xff;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4495
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4496
                  *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4497
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4498
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4499
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4500
            else if (row_info->bit_depth == 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4501
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4502
               unsigned int gray_high = (gray >> 8) & 0xff;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4503
               unsigned int gray_low = gray & 0xff;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4504
               sp = row + row_info->rowbytes - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4505
               dp = row + (row_info->rowbytes << 1) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4506
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4507
               {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  4508
                  if ((*(sp - 1) & 0xffU) == gray_high &&
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  4509
                      (*(sp) & 0xffU) == gray_low)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4510
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4511
                     *dp-- = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4512
                     *dp-- = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4513
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4514
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4515
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4516
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4517
                     *dp-- = 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4518
                     *dp-- = 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4519
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4520
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4521
                  *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4522
                  *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4523
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4524
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4525
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4526
            row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4527
            row_info->channels = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4528
            row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4529
            row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4530
               row_width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4531
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4532
      }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4533
      else if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4534
          trans_color != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4535
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4536
         if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4537
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4538
            png_byte red = (png_byte)(trans_color->red & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4539
            png_byte green = (png_byte)(trans_color->green & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4540
            png_byte blue = (png_byte)(trans_color->blue & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4541
            sp = row + (png_size_t)row_info->rowbytes - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4542
            dp = row + (png_size_t)(row_width << 2) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4543
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4544
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4545
               if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4546
                  *dp-- = 0;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4547
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4548
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4549
                  *dp-- = 0xff;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4550
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4551
               *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4552
               *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4553
               *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4554
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4555
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4556
         else if (row_info->bit_depth == 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4557
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4558
            png_byte red_high = (png_byte)((trans_color->red >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4559
            png_byte green_high = (png_byte)((trans_color->green >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4560
            png_byte blue_high = (png_byte)((trans_color->blue >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4561
            png_byte red_low = (png_byte)(trans_color->red & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4562
            png_byte green_low = (png_byte)(trans_color->green & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4563
            png_byte blue_low = (png_byte)(trans_color->blue & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4564
            sp = row + row_info->rowbytes - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4565
            dp = row + (png_size_t)(row_width << 3) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4566
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4567
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4568
               if (*(sp - 5) == red_high &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4569
                   *(sp - 4) == red_low &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4570
                   *(sp - 3) == green_high &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4571
                   *(sp - 2) == green_low &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4572
                   *(sp - 1) == blue_high &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4573
                   *(sp    ) == blue_low)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4574
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4575
                  *dp-- = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4576
                  *dp-- = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4577
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4578
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4579
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4580
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4581
                  *dp-- = 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4582
                  *dp-- = 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4583
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4584
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4585
               *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4586
               *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4587
               *dp-- = *sp--;
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
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4592
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4593
         row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4594
         row_info->channels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4595
         row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4596
         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4597
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4598
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4599
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4600
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4601
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4602
#ifdef PNG_READ_EXPAND_16_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4603
/* 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
  4604
 * whole row to 16 bits.  Has no effect otherwise.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4605
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4606
static void
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4607
png_do_expand_16(png_row_infop row_info, png_bytep row)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4608
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4609
   if (row_info->bit_depth == 8 &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4610
      row_info->color_type != PNG_COLOR_TYPE_PALETTE)
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
      /* 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
  4613
       * 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
  4614
       * calculate:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4615
       *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4616
       *  (input / 255) * 65535
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4617
       *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4618
       *  Which happens to be exactly input * 257 and this can be achieved
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4619
       *  simply by byte replication in place (copying backwards).
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
      png_byte *sp = row + row_info->rowbytes; /* source, last byte + 1 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4622
      png_byte *dp = sp + row_info->rowbytes;  /* destination, end + 1 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4623
      while (dp > sp)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4624
         dp[-2] = dp[-1] = *--sp, dp -= 2;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4625
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4626
      row_info->rowbytes *= 2;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4627
      row_info->bit_depth = 16;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4628
      row_info->pixel_depth = (png_byte)(row_info->channels * 16);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4629
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4630
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4631
#endif
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
#ifdef PNG_READ_QUANTIZE_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4634
static void
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4635
png_do_quantize(png_row_infop row_info, png_bytep row,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4636
    png_const_bytep palette_lookup, png_const_bytep quantize_lookup)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4637
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4638
   png_bytep sp, dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4639
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4640
   png_uint_32 row_width=row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4641
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4642
   png_debug(1, "in png_do_quantize");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4643
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4644
   if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4645
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4646
      if (row_info->color_type == PNG_COLOR_TYPE_RGB && palette_lookup)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4647
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4648
         int r, g, b, p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4649
         sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4650
         dp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4651
         for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4652
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4653
            r = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4654
            g = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4655
            b = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4656
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4657
            /* This looks real messy, but the compiler will reduce
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4658
             * it down to a reasonable formula.  For example, with
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4659
             * 5 bits per color, we get:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4660
             * p = (((r >> 3) & 0x1f) << 10) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4661
             *    (((g >> 3) & 0x1f) << 5) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4662
             *    ((b >> 3) & 0x1f);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4663
             */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4664
            p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4665
                ((1 << PNG_QUANTIZE_RED_BITS) - 1)) <<
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4666
                (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4667
                (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4668
                ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) <<
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4669
                (PNG_QUANTIZE_BLUE_BITS)) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4670
                ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4671
                ((1 << PNG_QUANTIZE_BLUE_BITS) - 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4672
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4673
            *dp++ = palette_lookup[p];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4674
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4675
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4676
         row_info->color_type = PNG_COLOR_TYPE_PALETTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4677
         row_info->channels = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4678
         row_info->pixel_depth = row_info->bit_depth;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4679
         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4680
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4681
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4682
      else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4683
         palette_lookup != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4684
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4685
         int r, g, b, p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4686
         sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4687
         dp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4688
         for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4689
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4690
            r = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4691
            g = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4692
            b = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4693
            sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4694
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4695
            p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4696
                ((1 << PNG_QUANTIZE_RED_BITS) - 1)) <<
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4697
                (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4698
                (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4699
                ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) <<
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4700
                (PNG_QUANTIZE_BLUE_BITS)) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4701
                ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4702
                ((1 << PNG_QUANTIZE_BLUE_BITS) - 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4703
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4704
            *dp++ = palette_lookup[p];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4705
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4706
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4707
         row_info->color_type = PNG_COLOR_TYPE_PALETTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4708
         row_info->channels = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4709
         row_info->pixel_depth = row_info->bit_depth;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4710
         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4711
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4712
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4713
      else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4714
         quantize_lookup)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4715
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4716
         sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4717
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4718
         for (i = 0; i < row_width; i++, sp++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4719
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4720
            *sp = quantize_lookup[*sp];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4721
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4722
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4723
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4724
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4725
#endif /* READ_QUANTIZE */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4726
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4727
/* Transform the row.  The order of transformations is significant,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4728
 * and is very touchy.  If you add a transformation, take care to
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4729
 * decide how it fits in with the other transformations here.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4730
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4731
void /* PRIVATE */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4732
png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4733
{
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4734
   png_debug(1, "in png_do_read_transformations");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4735
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4736
   if (png_ptr->row_buf == NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4737
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4738
      /* 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
  4739
       * error is incredibly rare and incredibly easy to debug without this
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4740
       * information.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4741
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4742
      png_error(png_ptr, "NULL row buffer");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4743
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4744
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4745
   /* 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
  4746
    * in 1.5.4 PNG_FLAG_DETECT_UNINITIALIZED was added and the macro
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4747
    * 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
  4748
    * all transformations, however in practice the ROW_INIT always gets done on
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4749
    * demand, if necessary.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4750
    */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4751
   if ((png_ptr->flags & PNG_FLAG_DETECT_UNINITIALIZED) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4752
       (png_ptr->flags & PNG_FLAG_ROW_INIT) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4753
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4754
      /* Application has failed to call either png_read_start_image() or
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4755
       * png_read_update_info() after setting transforms that expand pixels.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4756
       * 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
  4757
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4758
      png_error(png_ptr, "Uninitialized row");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4759
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4760
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4761
#ifdef PNG_READ_EXPAND_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4762
   if ((png_ptr->transformations & PNG_EXPAND) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4763
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4764
      if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4765
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4766
         png_do_expand_palette(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4767
             png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4768
      }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4769
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4770
      else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4771
      {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4772
         if (png_ptr->num_trans != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4773
             (png_ptr->transformations & PNG_EXPAND_tRNS) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4774
            png_do_expand(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4775
                &(png_ptr->trans_color));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4776
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4777
         else
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4778
            png_do_expand(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4779
                NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4780
      }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4781
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4782
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4783
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4784
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4785
   if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4786
       (png_ptr->transformations & PNG_COMPOSE) == 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4787
       (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4788
       row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4789
      png_do_strip_channel(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4790
         0 /* at_start == false, because SWAP_ALPHA happens later */);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4791
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4792
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4793
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4794
   if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4795
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4796
      int rgb_error =
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4797
          png_do_rgb_to_gray(png_ptr, row_info,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4798
              png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4799
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4800
      if (rgb_error != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4801
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4802
         png_ptr->rgb_to_gray_status=1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4803
         if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4804
             PNG_RGB_TO_GRAY_WARN)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4805
            png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4806
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4807
         if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4808
             PNG_RGB_TO_GRAY_ERR)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4809
            png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4810
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4811
   }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4812
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4813
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4814
/* From Andreas Dilger e-mail to png-implement, 26 March 1998:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4815
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4816
 *   In most cases, the "simple transparency" should be done prior to doing
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4817
 *   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
  4818
 *   pixel is transparent.  You would also need to make sure that the
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4819
 *   transparency information is upgraded to RGB.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4820
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4821
 *   To summarize, the current flow is:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4822
 *   - Gray + simple transparency -> compare 1 or 2 gray bytes and composite
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4823
 *                                   with background "in place" if transparent,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4824
 *                                   convert to RGB if necessary
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4825
 *   - Gray + alpha -> composite with gray background and remove alpha bytes,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4826
 *                                   convert to RGB if necessary
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4827
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4828
 *   To support RGB backgrounds for gray images we need:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4829
 *   - Gray + simple transparency -> convert to RGB + simple transparency,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4830
 *                                   compare 3 or 6 bytes and composite with
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4831
 *                                   background "in place" if transparent
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4832
 *                                   (3x compare/pixel compared to doing
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4833
 *                                   composite with gray bkgrnd)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4834
 *   - Gray + alpha -> convert to RGB + alpha, composite with background and
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4835
 *                                   remove alpha bytes (3x float
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4836
 *                                   operations/pixel compared with composite
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4837
 *                                   on gray background)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4838
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4839
 *  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
  4840
 *  performance, as this increases the per-pixel operations.  If we would check
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4841
 *  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
  4842
 *  transform appropriately, then it would save a lot of work/time.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4843
 */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4844
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4845
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4846
   /* 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
  4847
    * for performance reasons
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4848
    */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4849
   if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4850
       (png_ptr->mode & PNG_BACKGROUND_IS_GRAY) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4851
      png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4852
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4853
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4854
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4855
   defined(PNG_READ_ALPHA_MODE_SUPPORTED)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4856
   if ((png_ptr->transformations & PNG_COMPOSE) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4857
      png_do_compose(row_info, png_ptr->row_buf + 1, png_ptr);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4858
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4859
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4860
#ifdef PNG_READ_GAMMA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4861
   if ((png_ptr->transformations & PNG_GAMMA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4862
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4863
      /* Because RGB_TO_GRAY does the gamma transform. */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4864
      (png_ptr->transformations & PNG_RGB_TO_GRAY) == 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4865
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4866
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4867
   defined(PNG_READ_ALPHA_MODE_SUPPORTED)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4868
      /* Because PNG_COMPOSE does the gamma transform if there is something to
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4869
       * do (if there is an alpha channel or transparency.)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4870
       */
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  4871
       !((png_ptr->transformations & PNG_COMPOSE) != 0 &&
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4872
       ((png_ptr->num_trans != 0) ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4873
       (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)) &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4874
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4875
      /* Because png_init_read_transformations transforms the palette, unless
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4876
       * RGB_TO_GRAY will do the transform.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4877
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4878
       (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4879
      png_do_gamma(row_info, png_ptr->row_buf + 1, png_ptr);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4880
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4881
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4882
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4883
   if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4884
       (png_ptr->transformations & PNG_COMPOSE) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4885
       (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4886
       row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4887
      png_do_strip_channel(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4888
          0 /* at_start == false, because SWAP_ALPHA happens later */);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4889
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4890
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4891
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4892
   if ((png_ptr->transformations & PNG_ENCODE_ALPHA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4893
       (row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4894
      png_do_encode_alpha(row_info, png_ptr->row_buf + 1, png_ptr);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4895
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4896
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4897
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4898
   if ((png_ptr->transformations & PNG_SCALE_16_TO_8) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4899
      png_do_scale_16_to_8(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4900
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4901
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4902
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4903
   /* 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
  4904
    * by putting the 'scale' option first if the app asks for scale (either by
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4905
    * calling the API or in a TRANSFORM flag) this is what happens.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4906
    */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4907
   if ((png_ptr->transformations & PNG_16_TO_8) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4908
      png_do_chop(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4909
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4910
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4911
#ifdef PNG_READ_QUANTIZE_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4912
   if ((png_ptr->transformations & PNG_QUANTIZE) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4913
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4914
      png_do_quantize(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4915
          png_ptr->palette_lookup, png_ptr->quantize_index);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4916
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4917
      if (row_info->rowbytes == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4918
         png_error(png_ptr, "png_do_quantize returned rowbytes=0");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4919
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4920
#endif /* READ_QUANTIZE */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4921
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4922
#ifdef PNG_READ_EXPAND_16_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4923
   /* Do the expansion now, after all the arithmetic has been done.  Notice
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4924
    * that previous transformations can handle the PNG_EXPAND_16 flag if this
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4925
    * is efficient (particularly true in the case of gamma correction, where
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4926
    * better accuracy results faster!)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4927
    */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4928
   if ((png_ptr->transformations & PNG_EXPAND_16) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4929
      png_do_expand_16(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4930
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4931
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4932
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4933
   /* NOTE: moved here in 1.5.4 (from much later in this list.) */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4934
   if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4935
       (png_ptr->mode & PNG_BACKGROUND_IS_GRAY) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4936
      png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4937
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4938
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4939
#ifdef PNG_READ_INVERT_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4940
   if ((png_ptr->transformations & PNG_INVERT_MONO) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4941
      png_do_invert(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4942
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4943
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4944
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4945
   if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4946
      png_do_read_invert_alpha(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4947
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4948
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4949
#ifdef PNG_READ_SHIFT_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4950
   if ((png_ptr->transformations & PNG_SHIFT) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4951
      png_do_unshift(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4952
          &(png_ptr->shift));
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4953
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4954
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4955
#ifdef PNG_READ_PACK_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4956
   if ((png_ptr->transformations & PNG_PACK) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4957
      png_do_unpack(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4958
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4959
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4960
#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4961
   /* Added at libpng-1.5.10 */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4962
   if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4963
       png_ptr->num_palette_max >= 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4964
      png_do_check_palette_indexes(png_ptr, row_info);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4965
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4966
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4967
#ifdef PNG_READ_BGR_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4968
   if ((png_ptr->transformations & PNG_BGR) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4969
      png_do_bgr(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4970
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4971
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4972
#ifdef PNG_READ_PACKSWAP_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4973
   if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4974
      png_do_packswap(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4975
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4976
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4977
#ifdef PNG_READ_FILLER_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4978
   if ((png_ptr->transformations & PNG_FILLER) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4979
      png_do_read_filler(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4980
          (png_uint_32)png_ptr->filler, png_ptr->flags);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4981
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4982
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4983
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4984
   if ((png_ptr->transformations & PNG_SWAP_ALPHA) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4985
      png_do_read_swap_alpha(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4986
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4987
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4988
#ifdef PNG_READ_16BIT_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4989
#ifdef PNG_READ_SWAP_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4990
   if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4991
      png_do_swap(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4992
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4993
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4994
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4995
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4996
   if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4997
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4998
      if (png_ptr->read_user_transform_fn != NULL)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4999
         (*(png_ptr->read_user_transform_fn)) /* User read transform function */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5000
             (png_ptr,     /* png_ptr */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5001
             row_info,     /* row_info: */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5002
                /*  png_uint_32 width;       width of row */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5003
                /*  png_size_t rowbytes;     number of bytes in row */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5004
                /*  png_byte color_type;     color type of pixels */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5005
                /*  png_byte bit_depth;      bit depth of samples */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5006
                /*  png_byte channels;       number of channels (1-4) */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5007
                /*  png_byte pixel_depth;    bits per pixel (depth*channels) */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5008
             png_ptr->row_buf + 1);    /* start of pixel data for row */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5009
#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5010
      if (png_ptr->user_transform_depth != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5011
         row_info->bit_depth = png_ptr->user_transform_depth;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5012
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5013
      if (png_ptr->user_transform_channels != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5014
         row_info->channels = png_ptr->user_transform_channels;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5015
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5016
      row_info->pixel_depth = (png_byte)(row_info->bit_depth *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5017
          row_info->channels);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5018
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5019
      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_info->width);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5020
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5021
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5022
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5023
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5024
#endif /* READ_TRANSFORMS */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5025
#endif /* READ */