src/java.desktop/share/native/libsplashscreen/libpng/pngrtran.c
author serb
Wed, 12 Jun 2019 13:50:37 -0700
changeset 57618 53154e45385a
parent 51304 66d9993dd4ad
permissions -rw-r--r--
8217676: Upgrade libpng to 1.6.37 Reviewed-by: prr, jdv, kcr
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
 *
57618
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
    32
 * Copyright (c) 2018-2019 Cosmin Truta
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
    33
 * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
57618
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
    34
 * Copyright (c) 1996-1997 Andreas Dilger
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
    35
 * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
2
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
57618
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
    49
#ifdef PNG_ARM_NEON_IMPLEMENTATION
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
    50
#  if PNG_ARM_NEON_IMPLEMENTATION == 1
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
    51
#    define PNG_ARM_NEON_INTRINSICS_AVAILABLE
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
    52
#    if defined(_MSC_VER) && defined(_M_ARM64)
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
    53
#      include <arm64_neon.h>
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
    54
#    else
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
    55
#      include <arm_neon.h>
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
    56
#    endif
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
    57
#  endif
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
    58
#endif
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
    59
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    60
#ifdef PNG_READ_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
/* Set the action on getting a CRC error for an ancillary or critical chunk. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
    64
png_set_crc_action(png_structrp png_ptr, int crit_action, int ancil_action)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    66
   png_debug(1, "in png_set_crc_action");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    67
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    68
   if (png_ptr == NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    69
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    70
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
   /* Tell libpng how we react to CRC errors in critical chunks */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
   switch (crit_action)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    74
      case PNG_CRC_NO_CHANGE:                        /* Leave setting as is */
2
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_USE:                               /* Warn/use data */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
         png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
         png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
         break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    81
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    82
      case PNG_CRC_QUIET_USE:                             /* Quiet/use data */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
         png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
         png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                           PNG_FLAG_CRC_CRITICAL_IGNORE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
         break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    87
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    88
      case PNG_CRC_WARN_DISCARD:    /* Not a valid action for critical data */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    89
         png_warning(png_ptr,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
    90
             "Can't discard critical data on CRC error");
48280
791d551bcdb8 8183960: Upgrade to libpng 1.6.34
prr
parents: 47216
diff changeset
    91
         /* FALLTHROUGH */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    92
      case PNG_CRC_ERROR_QUIT:                                /* Error/quit */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
    93
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
      case PNG_CRC_DEFAULT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
      default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
         png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
         break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   100
   /* Tell libpng how we react to CRC errors in ancillary chunks */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
   switch (ancil_action)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   103
      case PNG_CRC_NO_CHANGE:                       /* Leave setting as is */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
         break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   105
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   106
      case PNG_CRC_WARN_USE:                              /* Warn/use data */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
         png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
         break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   110
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   111
      case PNG_CRC_QUIET_USE:                            /* Quiet/use data */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
         png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
         png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                           PNG_FLAG_CRC_ANCILLARY_NOWARN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
         break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   116
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   117
      case PNG_CRC_ERROR_QUIT:                               /* Error/quit */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
         png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
         png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
         break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   121
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   122
      case PNG_CRC_WARN_DISCARD:                      /* Warn/discard data */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   123
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
      case PNG_CRC_DEFAULT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
      default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
         break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   131
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   132
/* 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
   133
 * 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
   134
 * to have been read in all cases; the need_IHDR parameter allows for this
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   135
 * check too.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   136
 */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   137
static int
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   138
png_rtran_ok(png_structrp png_ptr, int need_IHDR)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   139
{
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   140
   if (png_ptr != NULL)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   141
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   142
      if ((png_ptr->flags & PNG_FLAG_ROW_INIT) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   143
         png_app_error(png_ptr,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
   144
             "invalid after png_start_read_image or png_read_update_info");
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   145
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   146
      else if (need_IHDR && (png_ptr->mode & PNG_HAVE_IHDR) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   147
         png_app_error(png_ptr, "invalid before the PNG header has been read");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   148
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   149
      else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   150
      {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   151
         /* Turn on failure to initialize correctly for all transforms. */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   152
         png_ptr->flags |= PNG_FLAG_DETECT_UNINITIALIZED;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   153
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   154
         return 1; /* Ok */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   155
      }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   156
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   157
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   158
   return 0; /* no png_error possible! */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   159
}
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   160
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   161
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   162
#ifdef PNG_READ_BACKGROUND_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   163
/* Handle alpha and tRNS via a background color */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   164
void PNGFAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   165
png_set_background_fixed(png_structrp png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   166
    png_const_color_16p background_color, int background_gamma_code,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   167
    int need_expand, png_fixed_point background_gamma)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   169
   png_debug(1, "in png_set_background_fixed");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   170
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   171
   if (png_rtran_ok(png_ptr, 0) == 0 || background_color == NULL)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   172
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   173
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
   if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
      png_warning(png_ptr, "Application must supply a known background gamma");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   180
   png_ptr->transformations |= PNG_COMPOSE | PNG_STRIP_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   181
   png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   182
   png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   183
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   184
   png_ptr->background = *background_color;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   185
   png_ptr->background_gamma = background_gamma;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
   png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   187
   if (need_expand != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   188
      png_ptr->transformations |= PNG_BACKGROUND_EXPAND;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   189
   else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   190
      png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   191
}
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
#  ifdef PNG_FLOATING_POINT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   194
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   195
png_set_background(png_structrp png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   196
    png_const_color_16p background_color, int background_gamma_code,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   197
    int need_expand, double background_gamma)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   198
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   199
   png_set_background_fixed(png_ptr, background_color, background_gamma_code,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   200
      need_expand, png_fixed(png_ptr, background_gamma, "png_set_background"));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   201
}
40436
94ae0ede53a5 8155690: Update libPNG library to the latest up-to-date
azvegint
parents: 35692
diff changeset
   202
#  endif /* FLOATING_POINT */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   203
#endif /* READ_BACKGROUND */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   204
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   205
/* 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
   206
 * 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
   207
 * TRANSFORM and API behavior to be somewhat consistent, and it's simpler.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   208
 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   209
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   210
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   211
png_set_scale_16(png_structrp png_ptr)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   212
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   213
   png_debug(1, "in png_set_scale_16");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   214
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   215
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   216
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   217
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   218
   png_ptr->transformations |= PNG_SCALE_16_TO_8;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   222
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   223
/* Chop 16-bit depth files to 8-bit depth */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   225
png_set_strip_16(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   227
   png_debug(1, "in png_set_strip_16");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   228
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   229
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   230
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   231
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
   png_ptr->transformations |= PNG_16_TO_8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   236
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   238
png_set_strip_alpha(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   240
   png_debug(1, "in png_set_strip_alpha");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   241
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   242
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   243
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   244
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   245
   png_ptr->transformations |= PNG_STRIP_ALPHA;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   249
#if defined(PNG_READ_ALPHA_MODE_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   250
static png_fixed_point
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   251
translate_gamma_flags(png_structrp png_ptr, png_fixed_point output_gamma,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
   252
    int is_screen)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   253
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   254
   /* 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
   255
    * 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
   256
    * value is from Apple documentation - a working Mac system is needed to
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   257
    * discover the value!
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   258
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   259
   if (output_gamma == PNG_DEFAULT_sRGB ||
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   260
      output_gamma == PNG_FP_1 / PNG_DEFAULT_sRGB)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   261
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   262
      /* 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
   263
       * sRGB value.  (This is a side effect of using this function!)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   264
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   265
#     ifdef PNG_READ_sRGB_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   266
         png_ptr->flags |= PNG_FLAG_ASSUME_sRGB;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   267
#     else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   268
         PNG_UNUSED(png_ptr)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   269
#     endif
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   270
      if (is_screen != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   271
         output_gamma = PNG_GAMMA_sRGB;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   272
      else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   273
         output_gamma = PNG_GAMMA_sRGB_INVERSE;
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
   else if (output_gamma == PNG_GAMMA_MAC_18 ||
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   277
      output_gamma == PNG_FP_1 / PNG_GAMMA_MAC_18)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   278
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   279
      if (is_screen != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   280
         output_gamma = PNG_GAMMA_MAC_OLD;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   281
      else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   282
         output_gamma = PNG_GAMMA_MAC_INVERSE;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   283
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   284
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   285
   return output_gamma;
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
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   288
#  ifdef PNG_FLOATING_POINT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   289
static png_fixed_point
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   290
convert_gamma_value(png_structrp png_ptr, double output_gamma)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   291
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   292
   /* The following silently ignores cases where fixed point (times 100,000)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   293
    * 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
   294
    * means the fixed point constants work just fine with the floating point
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   295
    * API.  The alternative would just lead to undetected errors and spurious
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   296
    * bug reports.  Negative values fail inside the _fixed API unless they
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   297
    * correspond to the flag values.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   298
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   299
   if (output_gamma > 0 && output_gamma < 128)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   300
      output_gamma *= PNG_FP_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   301
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   302
   /* This preserves -1 and -2 exactly: */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   303
   output_gamma = floor(output_gamma + .5);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   304
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   305
   if (output_gamma > PNG_FP_MAX || output_gamma < PNG_FP_MIN)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   306
      png_fixed_error(png_ptr, "gamma value");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   307
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   308
   return (png_fixed_point)output_gamma;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   309
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   310
#  endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   311
#endif /* READ_ALPHA_MODE || READ_GAMMA */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   312
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   313
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   314
void PNGFAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   315
png_set_alpha_mode_fixed(png_structrp png_ptr, int mode,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
   316
    png_fixed_point output_gamma)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   317
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   318
   int compose = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   319
   png_fixed_point file_gamma;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   320
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   321
   png_debug(1, "in png_set_alpha_mode");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   322
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   323
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   324
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   325
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   326
   output_gamma = translate_gamma_flags(png_ptr, output_gamma, 1/*screen*/);
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
   /* 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
   329
    * 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
   330
    * 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
   331
    * who use the inverse of the gamma value accidentally!  Since some of these
40436
94ae0ede53a5 8155690: Update libPNG library to the latest up-to-date
azvegint
parents: 35692
diff changeset
   332
    * values are reasonable this may have to be changed:
94ae0ede53a5 8155690: Update libPNG library to the latest up-to-date
azvegint
parents: 35692
diff changeset
   333
    *
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
   334
    * 1.6.x: changed from 0.07..3 to 0.01..100 (to accommodate the optimal 16-bit
40436
94ae0ede53a5 8155690: Update libPNG library to the latest up-to-date
azvegint
parents: 35692
diff changeset
   335
    * gamma of 36, and its reciprocal.)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   336
    */
40436
94ae0ede53a5 8155690: Update libPNG library to the latest up-to-date
azvegint
parents: 35692
diff changeset
   337
   if (output_gamma < 1000 || output_gamma > 10000000)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   338
      png_error(png_ptr, "output gamma out of expected range");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   339
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   340
   /* The default file gamma is the inverse of the output gamma; the output
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   341
    * gamma may be changed below so get the file value first:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   342
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   343
   file_gamma = png_reciprocal(output_gamma);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   344
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   345
   /* There are really 8 possibilities here, composed of any combination
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   346
    * of:
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
    *    premultiply the color channels
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   349
    *    do not encode non-opaque pixels
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   350
    *    encode the alpha as well as the color channels
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   351
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   352
    * The differences disappear if the input/output ('screen') gamma is 1.0,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   353
    * 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
   354
    * premultiplying the color channels or not.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   355
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   356
    * png_set_alpha_mode and png_set_background interact because both use
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   357
    * png_compose to do the work.  Calling both is only useful when
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   358
    * 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
   359
    * with a default gamma value.  Otherwise PNG_COMPOSE must not be set.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   360
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   361
   switch (mode)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   362
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   363
      case PNG_ALPHA_PNG:        /* default: png standard */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   364
         /* No compose, but it may be set by png_set_background! */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   365
         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   366
         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
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_ASSOCIATED: /* color channels premultiplied */
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
         /* The output is linear: */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   374
         output_gamma = PNG_FP_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   375
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   376
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   377
      case PNG_ALPHA_OPTIMIZED:  /* associated, non-opaque pixels linear */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   378
         compose = 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   379
         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   380
         png_ptr->flags |= PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   381
         /* output_gamma records the encoding of opaque pixels! */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   382
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   383
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   384
      case PNG_ALPHA_BROKEN:     /* associated, non-linear, alpha encoded */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   385
         compose = 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   386
         png_ptr->transformations |= PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   387
         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   388
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   389
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   390
      default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   391
         png_error(png_ptr, "invalid alpha mode");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   392
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   393
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   394
   /* 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
   395
    * 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
   396
    * be ignored.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   397
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   398
   if (png_ptr->colorspace.gamma == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   399
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   400
      png_ptr->colorspace.gamma = file_gamma;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   401
      png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   402
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   403
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   404
   /* But always set the output gamma: */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   405
   png_ptr->screen_gamma = output_gamma;
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
   /* Finally, if pre-multiplying, set the background fields to achieve the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   408
    * desired result.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   409
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   410
   if (compose != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   411
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   412
      /* And obtain alpha pre-multiplication by composing on black: */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   413
      memset(&png_ptr->background, 0, (sizeof png_ptr->background));
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   414
      png_ptr->background_gamma = png_ptr->colorspace.gamma; /* just in case */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   415
      png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_FILE;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   416
      png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   417
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   418
      if ((png_ptr->transformations & PNG_COMPOSE) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   419
         png_error(png_ptr,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
   420
             "conflicting calls to set alpha mode and background");
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   421
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   422
      png_ptr->transformations |= PNG_COMPOSE;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   423
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   424
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   425
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   426
#  ifdef PNG_FLOATING_POINT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   427
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   428
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
   429
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   430
   png_set_alpha_mode_fixed(png_ptr, mode, convert_gamma_value(png_ptr,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
   431
       output_gamma));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   432
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   433
#  endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   434
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   435
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   436
#ifdef PNG_READ_QUANTIZE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   437
/* Dither file to 8-bit.  Supply a palette, the current number
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
 * of elements in the palette, the maximum number of elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
 * allowed, and a histogram if possible.  If the current number
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
   440
 * 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
   441
 * modified to fit in the maximum number.  "full_quantize" indicates
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   442
 * whether we need a quantizing cube set up for RGB images, or if we
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
 * simply are reducing the number of colors in a paletted image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
typedef struct png_dsort_struct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
{
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   448
   struct png_dsort_struct * next;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
   png_byte left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
   png_byte right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
} png_dsort;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   452
typedef png_dsort *   png_dsortp;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   453
typedef png_dsort * * png_dsortpp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   456
png_set_quantize(png_structrp png_ptr, png_colorp palette,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   457
    int num_palette, int maximum_colors, png_const_uint_16p histogram,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   458
    int full_quantize)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   460
   png_debug(1, "in png_set_quantize");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   461
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   462
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   463
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   464
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   465
   png_ptr->transformations |= PNG_QUANTIZE;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   466
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   467
   if (full_quantize == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
      int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   471
      png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr,
48280
791d551bcdb8 8183960: Upgrade to libpng 1.6.34
prr
parents: 47216
diff changeset
   472
          (png_alloc_size_t)((png_uint_32)num_palette * (sizeof (png_byte))));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
      for (i = 0; i < num_palette; i++)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   474
         png_ptr->quantize_index[i] = (png_byte)i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
   if (num_palette > maximum_colors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
      if (histogram != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
         /* This is easy enough, just throw out the least used colors.
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   482
          * Perhaps not the best solution, but good enough.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   483
          */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
         int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   487
         /* Initialize an array to sort colors */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   488
         png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr,
48280
791d551bcdb8 8183960: Upgrade to libpng 1.6.34
prr
parents: 47216
diff changeset
   489
             (png_alloc_size_t)((png_uint_32)num_palette * (sizeof (png_byte))));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   490
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   491
         /* Initialize the quantize_sort array */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
         for (i = 0; i < num_palette; i++)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   493
            png_ptr->quantize_sort[i] = (png_byte)i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
         /* Find the least used palette entries by starting a
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   496
          * bubble sort, and running it until we have sorted
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   497
          * out enough colors.  Note that we don't care about
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   498
          * sorting all the colors, just finding which are
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   499
          * least used.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   500
          */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
         for (i = num_palette - 1; i >= maximum_colors; i--)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   504
            int done; /* To stop early if the list is pre-sorted */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            done = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            for (j = 0; j < i; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   510
               if (histogram[png_ptr->quantize_sort[j]]
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   511
                   < histogram[png_ptr->quantize_sort[j + 1]])
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                  png_byte t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   515
                  t = png_ptr->quantize_sort[j];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   516
                  png_ptr->quantize_sort[j] = png_ptr->quantize_sort[j + 1];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   517
                  png_ptr->quantize_sort[j + 1] = t;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                  done = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   521
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   522
            if (done != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
               break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   526
         /* Swap the palette around, and set up a table, if necessary */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   527
         if (full_quantize != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            int j = num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   531
            /* Put all the useful colors within the max, but don't
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   532
             * move the others.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   533
             */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            for (i = 0; i < maximum_colors; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   536
               if ((int)png_ptr->quantize_sort[i] >= maximum_colors)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                  do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                     j--;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   540
                  while ((int)png_ptr->quantize_sort[j] >= maximum_colors);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   541
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                  palette[i] = palette[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            int j = num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   550
            /* Move all the used colors inside the max limit, and
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   551
             * develop a translation table.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   552
             */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            for (i = 0; i < maximum_colors; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   555
               /* Only move the colors we need to */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   556
               if ((int)png_ptr->quantize_sort[i] >= maximum_colors)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                  png_color tmp_color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                  do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                     j--;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   562
                  while ((int)png_ptr->quantize_sort[j] >= maximum_colors);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                  tmp_color = palette[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                  palette[j] = palette[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                  palette[i] = tmp_color;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   567
                  /* Indicate where the color went */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   568
                  png_ptr->quantize_index[j] = (png_byte)i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   569
                  png_ptr->quantize_index[i] = (png_byte)j;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   573
            /* Find closest color for those colors we are not using */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            for (i = 0; i < num_palette; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   576
               if ((int)png_ptr->quantize_index[i] >= maximum_colors)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                  int min_d, k, min_k, d_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   580
                  /* Find the closest color to one we threw out */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   581
                  d_index = png_ptr->quantize_index[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                  min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                  for (k = 1, min_k = 0; k < maximum_colors; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                     int d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                     d = PNG_COLOR_DIST(palette[d_index], palette[k]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                     if (d < min_d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                        min_d = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                        min_k = k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   595
                  /* Point to closest color */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   596
                  png_ptr->quantize_index[i] = (png_byte)min_k;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   600
         png_free(png_ptr, png_ptr->quantize_sort);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   601
         png_ptr->quantize_sort = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
         /* This is much harder to do simply (and quickly).  Perhaps
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   606
          * we need to go through a median cut routine, but those
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   607
          * don't always behave themselves with only a few colors
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   608
          * as input.  So we will just find the closest two colors,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   609
          * and throw out one of them (chosen somewhat randomly).
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   610
          * [We don't understand this at all, so if someone wants to
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   611
          *  work on improving it, be our guest - AED, GRP]
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   612
          */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
         int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
         int max_d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
         int num_new_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
         png_dsortp t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
         png_dsortpp hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   619
         t = NULL;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   620
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   621
         /* Initialize palette index arrays */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
         png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
48280
791d551bcdb8 8183960: Upgrade to libpng 1.6.34
prr
parents: 47216
diff changeset
   623
             (png_alloc_size_t)((png_uint_32)num_palette *
791d551bcdb8 8183960: Upgrade to libpng 1.6.34
prr
parents: 47216
diff changeset
   624
             (sizeof (png_byte))));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
         png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
48280
791d551bcdb8 8183960: Upgrade to libpng 1.6.34
prr
parents: 47216
diff changeset
   626
             (png_alloc_size_t)((png_uint_32)num_palette *
791d551bcdb8 8183960: Upgrade to libpng 1.6.34
prr
parents: 47216
diff changeset
   627
             (sizeof (png_byte))));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   628
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   629
         /* Initialize the sort array */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
         for (i = 0; i < num_palette; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            png_ptr->index_to_palette[i] = (png_byte)i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            png_ptr->palette_to_index[i] = (png_byte)i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
48280
791d551bcdb8 8183960: Upgrade to libpng 1.6.34
prr
parents: 47216
diff changeset
   636
         hash = (png_dsortpp)png_calloc(png_ptr, (png_alloc_size_t)(769 *
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   637
             (sizeof (png_dsortp))));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
         num_new_palette = num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   641
         /* Initial wild guess at how far apart the farthest pixel
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   642
          * pair we will be eliminating will be.  Larger
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   643
          * numbers mean more areas will be allocated, Smaller
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   644
          * numbers run the risk of not saving enough data, and
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   645
          * having to do this all over again.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   646
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   647
          * I have not done extensive checking on this number.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   648
          */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
         max_d = 96;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
         while (num_new_palette > maximum_colors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            for (i = 0; i < num_new_palette - 1; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
               int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
               for (j = i + 1; j < num_new_palette; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                  int d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                  d = PNG_COLOR_DIST(palette[i], palette[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                  if (d <= max_d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                     t = (png_dsortp)png_malloc_warn(png_ptr,
48280
791d551bcdb8 8183960: Upgrade to libpng 1.6.34
prr
parents: 47216
diff changeset
   667
                         (png_alloc_size_t)(sizeof (png_dsort)));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   668
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                     if (t == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                         break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   671
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                     t->next = hash[d];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                     t->left = (png_byte)i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                     t->right = (png_byte)j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                     hash[d] = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
               if (t == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            if (t != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            for (i = 0; i <= max_d; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
               if (hash[i] != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                  png_dsortp p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                  for (p = hash[i]; p; p = p->next)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                     if ((int)png_ptr->index_to_palette[p->left]
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   692
                         < num_new_palette &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   693
                         (int)png_ptr->index_to_palette[p->right]
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   694
                         < num_new_palette)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                        int j, next_j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                        if (num_new_palette & 0x01)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                           j = p->left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                           next_j = p->right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                           j = p->right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                           next_j = p->left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                        num_new_palette--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                        palette[png_ptr->index_to_palette[j]]
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   711
                            = palette[num_new_palette];
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   712
                        if (full_quantize == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                           int k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                           for (k = 0; k < num_palette; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                           {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   718
                              if (png_ptr->quantize_index[k] ==
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_ptr->quantize_index[k] =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   721
                                     png_ptr->index_to_palette[next_j];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   722
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   723
                              if ((int)png_ptr->quantize_index[k] ==
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   724
                                  num_new_palette)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   725
                                 png_ptr->quantize_index[k] =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   726
                                     png_ptr->index_to_palette[j];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                        png_ptr->index_to_palette[png_ptr->palette_to_index
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   731
                            [num_new_palette]] = png_ptr->index_to_palette[j];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   732
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                        png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   734
                            = png_ptr->palette_to_index[num_new_palette];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   735
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   736
                        png_ptr->index_to_palette[j] =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   737
                            (png_byte)num_new_palette;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   738
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   739
                        png_ptr->palette_to_index[num_new_palette] =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   740
                            (png_byte)j;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                     if (num_new_palette <= maximum_colors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                  if (num_new_palette <= maximum_colors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                     break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            for (i = 0; i < 769; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
               if (hash[i] != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                  png_dsortp p = hash[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                  while (p)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                     t = p->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                     png_free(png_ptr, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                     p = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
               hash[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            max_d += 96;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
         png_free(png_ptr, hash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
         png_free(png_ptr, png_ptr->palette_to_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
         png_free(png_ptr, png_ptr->index_to_palette);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   769
         png_ptr->palette_to_index = NULL;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   770
         png_ptr->index_to_palette = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
      num_palette = maximum_colors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
   if (png_ptr->palette == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
      png_ptr->palette = palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
   png_ptr->num_palette = (png_uint_16)num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   780
   if (full_quantize != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
      int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
      png_bytep distance;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   784
      int total_bits = PNG_QUANTIZE_RED_BITS + PNG_QUANTIZE_GREEN_BITS +
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   785
          PNG_QUANTIZE_BLUE_BITS;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   786
      int num_red = (1 << PNG_QUANTIZE_RED_BITS);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   787
      int num_green = (1 << PNG_QUANTIZE_GREEN_BITS);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   788
      int num_blue = (1 << PNG_QUANTIZE_BLUE_BITS);
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
   789
      size_t num_entries = ((size_t)1 << total_bits);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   791
      png_ptr->palette_lookup = (png_bytep)png_calloc(png_ptr,
48280
791d551bcdb8 8183960: Upgrade to libpng 1.6.34
prr
parents: 47216
diff changeset
   792
          (png_alloc_size_t)(num_entries * (sizeof (png_byte))));
791d551bcdb8 8183960: Upgrade to libpng 1.6.34
prr
parents: 47216
diff changeset
   793
791d551bcdb8 8183960: Upgrade to libpng 1.6.34
prr
parents: 47216
diff changeset
   794
      distance = (png_bytep)png_malloc(png_ptr, (png_alloc_size_t)(num_entries *
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   795
          (sizeof (png_byte))));
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   796
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   797
      memset(distance, 0xff, num_entries * (sizeof (png_byte)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
      for (i = 0; i < num_palette; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
         int ir, ig, ib;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   802
         int r = (palette[i].red >> (8 - PNG_QUANTIZE_RED_BITS));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   803
         int g = (palette[i].green >> (8 - PNG_QUANTIZE_GREEN_BITS));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   804
         int b = (palette[i].blue >> (8 - PNG_QUANTIZE_BLUE_BITS));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
         for (ir = 0; ir < num_red; ir++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            /* int dr = abs(ir - r); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            int dr = ((ir > r) ? ir - r : r - ir);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   810
            int index_r = (ir << (PNG_QUANTIZE_BLUE_BITS +
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   811
                PNG_QUANTIZE_GREEN_BITS));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            for (ig = 0; ig < num_green; ig++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
               /* int dg = abs(ig - g); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
               int dg = ((ig > g) ? ig - g : g - ig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
               int dt = dr + dg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
               int dm = ((dr > dg) ? dr : dg);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   819
               int index_g = index_r | (ig << PNG_QUANTIZE_BLUE_BITS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
               for (ib = 0; ib < num_blue; ib++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                  int d_index = index_g | ib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                  /* int db = abs(ib - b); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                  int db = ((ib > b) ? ib - b : b - ib);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                  int dmax = ((dm > db) ? dm : db);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                  int d = dmax + dt + db;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                  if (d < (int)distance[d_index])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                     distance[d_index] = (png_byte)d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                     png_ptr->palette_lookup[d_index] = (png_byte)i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
      png_free(png_ptr, distance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   842
#endif /* READ_QUANTIZE */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   843
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   844
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   845
void PNGFAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   846
png_set_gamma_fixed(png_structrp png_ptr, png_fixed_point scrn_gamma,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
   847
    png_fixed_point file_gamma)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   848
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   849
   png_debug(1, "in png_set_gamma_fixed");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   850
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   851
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   852
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   853
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   854
   /* New in libpng-1.5.4 - reserve particular negative values as flags. */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   855
   scrn_gamma = translate_gamma_flags(png_ptr, scrn_gamma, 1/*screen*/);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   856
   file_gamma = translate_gamma_flags(png_ptr, file_gamma, 0/*file*/);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   857
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   858
   /* 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
   859
    * premultiplied alpha support; this actually hides an undocumented feature
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   860
    * of the previous implementation which allowed gamma processing to be
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   861
    * disabled in background handling.  There is no evidence (so far) that this
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   862
    * was being used; however, png_set_background itself accepted and must still
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   863
    * 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
   864
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   865
    * 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
   866
    * undocumented API feature) the following checks were only enabled in
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   867
    * libpng-1.6.0.
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   868
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   869
   if (file_gamma <= 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   870
      png_error(png_ptr, "invalid file gamma in png_set_gamma");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   871
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   872
   if (scrn_gamma <= 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   873
      png_error(png_ptr, "invalid screen gamma in png_set_gamma");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   875
   /* Set the gamma values unconditionally - this overrides the value in the PNG
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   876
    * 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
   877
    * different, easier, way to default the file gamma.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   878
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   879
   png_ptr->colorspace.gamma = file_gamma;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   880
   png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   881
   png_ptr->screen_gamma = scrn_gamma;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   882
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   883
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   884
#  ifdef PNG_FLOATING_POINT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   886
png_set_gamma(png_structrp png_ptr, double scrn_gamma, double file_gamma)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   888
   png_set_gamma_fixed(png_ptr, convert_gamma_value(png_ptr, scrn_gamma),
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
   889
       convert_gamma_value(png_ptr, file_gamma));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   891
#  endif /* FLOATING_POINT */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   892
#endif /* READ_GAMMA */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   893
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   894
#ifdef PNG_READ_EXPAND_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
/* Expand paletted images to RGB, expand grayscale images of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
 * less than 8-bit depth to 8-bit depth, and expand tRNS chunks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
 * to alpha channels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   900
png_set_expand(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   902
   png_debug(1, "in png_set_expand");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   903
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   904
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   905
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   906
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
   png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
/* GRR 19990627:  the following three functions currently are identical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
 *  to png_set_expand().  However, it is entirely reasonable that someone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
 *  might wish to expand an indexed image to RGB but *not* expand a single,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
 *  fully transparent palette entry to a full alpha channel--perhaps instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
 *  convert tRNS to the grayscale/RGB format (16-bit RGB value), or replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
 *  the transparent color with a particular RGB value, or drop tRNS entirely.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
 *  IOW, a future version of the library may make the transformations flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
 *  a bit more fine-grained, with separate bits for each of these three
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
 *  functions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
 *  More to the point, these functions make it obvious what libpng will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
 *  doing, whereas "expand" can (and does) mean any number of things.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
 *
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   923
 *  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
   924
 *  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
   925
 *  and its name was changed to png_set_expand_gray_1_2_4_to_8().
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
/* Expand paletted images to RGB. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   930
png_set_palette_to_rgb(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   932
   png_debug(1, "in png_set_palette_to_rgb");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   933
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   934
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   935
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   936
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
   png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
/* Expand grayscale images of less than 8-bit depth to 8 bits. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   942
png_set_expand_gray_1_2_4_to_8(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   944
   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
   945
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   946
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   947
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   948
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
   png_ptr->transformations |= PNG_EXPAND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
}
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   951
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
/* Expand tRNS chunks to alpha channels. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   954
png_set_tRNS_to_alpha(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   956
   png_debug(1, "in png_set_tRNS_to_alpha");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   957
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   958
   if (png_rtran_ok(png_ptr, 0) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   959
      return;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   960
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
   png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   963
#endif /* READ_EXPAND */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   965
#ifdef PNG_READ_EXPAND_16_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   966
/* Expand to 16-bit channels, expand the tRNS chunk too (because otherwise
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   967
 * it may not work correctly.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   968
 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   969
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   970
png_set_expand_16(png_structrp png_ptr)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   971
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   972
   png_debug(1, "in png_set_expand_16");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   973
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   974
   if (png_rtran_ok(png_ptr, 0) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   975
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   976
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   977
   png_ptr->transformations |= (PNG_EXPAND_16 | PNG_EXPAND | PNG_EXPAND_tRNS);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   978
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   979
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   980
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   981
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   983
png_set_gray_to_rgb(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   985
   png_debug(1, "in png_set_gray_to_rgb");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   986
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   987
   if (png_rtran_ok(png_ptr, 0) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   988
      return;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   989
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   990
   /* Because rgb must be 8 bits or more: */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   991
   png_set_expand_gray_1_2_4_to_8(png_ptr);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   992
   png_ptr->transformations |= PNG_GRAY_TO_RGB;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   996
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
   997
void PNGFAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   998
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
   999
    png_fixed_point red, png_fixed_point green)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1000
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1001
   png_debug(1, "in png_set_rgb_to_gray");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1002
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1003
   /* Need the IHDR here because of the check on color_type below. */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1004
   /* TODO: fix this */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1005
   if (png_rtran_ok(png_ptr, 1) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1006
      return;
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
   switch (error_action)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1009
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1010
      case PNG_ERROR_ACTION_NONE:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1011
         png_ptr->transformations |= PNG_RGB_TO_GRAY;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1012
         break;
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
      case PNG_ERROR_ACTION_WARN:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1015
         png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1016
         break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1017
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1018
      case PNG_ERROR_ACTION_ERROR:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1019
         png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1020
         break;
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
      default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1023
         png_error(png_ptr, "invalid error action to rgb_to_gray");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1024
   }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1025
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1026
   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1027
#ifdef PNG_READ_EXPAND_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1028
      png_ptr->transformations |= PNG_EXPAND;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1029
#else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1030
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1031
      /* Make this an error in 1.6 because otherwise the application may assume
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1032
       * that it just worked and get a memory overwrite.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1033
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1034
      png_error(png_ptr,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  1035
          "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED");
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1036
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1037
      /* png_ptr->transformations &= ~PNG_RGB_TO_GRAY; */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1038
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1039
#endif
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
      if (red >= 0 && green >= 0 && red + green <= PNG_FP_1)
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
         png_uint_16 red_int, green_int;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1044
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1045
         /* NOTE: this calculation does not round, but this behavior is retained
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1046
          * for consistency; the inaccuracy is very small.  The code here always
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1047
          * overwrites the coefficients, regardless of whether they have been
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1048
          * defaulted or set already.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1049
          */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1050
         red_int = (png_uint_16)(((png_uint_32)red*32768)/100000);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1051
         green_int = (png_uint_16)(((png_uint_32)green*32768)/100000);
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
         png_ptr->rgb_to_gray_red_coeff   = red_int;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1054
         png_ptr->rgb_to_gray_green_coeff = green_int;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1055
         png_ptr->rgb_to_gray_coefficients_set = 1;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1056
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1057
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1058
      else
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
         if (red >= 0 && green >= 0)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1061
            png_app_warning(png_ptr,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  1062
                "ignoring out of range rgb_to_gray coefficients");
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1063
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1064
         /* Use the defaults, from the cHRM chunk if set, else the historical
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1065
          * values which are close to the sRGB/HDTV/ITU-Rec 709 values.  See
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1066
          * png_do_rgb_to_gray for more discussion of the values.  In this case
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1067
          * the coefficients are not marked as 'set' and are not overwritten if
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1068
          * something has already provided a default.
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1069
          */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1070
         if (png_ptr->rgb_to_gray_red_coeff == 0 &&
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  1071
             png_ptr->rgb_to_gray_green_coeff == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1072
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1073
            png_ptr->rgb_to_gray_red_coeff   = 6968;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1074
            png_ptr->rgb_to_gray_green_coeff = 23434;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1075
            /* png_ptr->rgb_to_gray_blue_coeff  = 2366; */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1076
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1077
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1078
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1079
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1080
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1081
#ifdef PNG_FLOATING_POINT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
/* Convert a RGB image to a grayscale of the same width.  This allows us,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
 * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1087
png_set_rgb_to_gray(png_structrp png_ptr, int error_action, double red,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  1088
    double green)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1090
   png_set_rgb_to_gray_fixed(png_ptr, error_action,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  1091
       png_fixed(png_ptr, red, "rgb to gray red coefficient"),
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1092
      png_fixed(png_ptr, green, "rgb to gray green coefficient"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
}
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1094
#endif /* FLOATING POINT */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1095
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1096
#endif /* RGB_TO_GRAY */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1099
    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1101
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
  1102
    read_user_transform_fn)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1104
   png_debug(1, "in png_set_read_user_transform_fn");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1105
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1106
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
   png_ptr->transformations |= PNG_USER_TRANSFORM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
   png_ptr->read_user_transform_fn = read_user_transform_fn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1110
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1112
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1113
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1114
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1115
/* In the case of gamma transformations only do transformations on images where
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1116
 * the [file] gamma and screen_gamma are not close reciprocals, otherwise it
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1117
 * slows things down slightly, and also needlessly introduces small errors.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1118
 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1119
static int /* PRIVATE */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1120
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
  1121
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1122
   /* PNG_GAMMA_THRESHOLD is the threshold for performing gamma
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1123
    * correction as a difference of the overall transform from 1.0
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1124
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1125
    * 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
  1126
    * overflow here it is because of wacky gamma values so we
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1127
    * turn on processing anyway.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1128
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1129
   png_fixed_point gtest;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1130
   return !png_muldiv(&gtest, screen_gamma, file_gamma, PNG_FP_1) ||
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1131
       png_gamma_significant(gtest);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
/* Initialize everything needed for the read.  This includes modifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
 * the palette.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
 */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1138
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1139
/* For the moment 'png_init_palette_transformations' and
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1140
 * 'png_init_rgb_transformations' only do some flag canceling optimizations.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1141
 * 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
  1142
 * extracted from 'png_init_read_transformations'.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1143
 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1144
static void /* PRIVATE */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1145
png_init_palette_transformations(png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1147
   /* Called to handle the (input) palette case.  In png_do_read_transformations
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1148
    * 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
  1149
    * 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
  1150
    * palette expansion, or only do them if there is no expansion.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1151
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1152
    * 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
  1153
    * to 0.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1154
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1155
   int input_has_alpha = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1156
   int input_has_transparency = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1157
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1158
   if (png_ptr->num_trans > 0)
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
      int i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1161
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1162
      /* Ignore if all the entries are opaque (unlikely!) */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1163
      for (i=0; i<png_ptr->num_trans; ++i)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1164
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1165
         if (png_ptr->trans_alpha[i] == 255)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1166
            continue;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1167
         else if (png_ptr->trans_alpha[i] == 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1168
            input_has_transparency = 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1169
         else
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1170
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1171
            input_has_transparency = 1;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1172
            input_has_alpha = 1;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1173
            break;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1174
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1175
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1176
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1177
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1178
   /* If no alpha we can optimize. */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1179
   if (input_has_alpha == 0)
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
      /* Any alpha means background and associative alpha processing is
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1182
       * 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
  1183
       * and ENCODE_ALPHA are irrelevant.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1184
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1185
      png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1186
      png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1187
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1188
      if (input_has_transparency == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1189
         png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1190
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1193
   /* png_set_background handling - deals with the complexity of whether the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1194
    * 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
  1195
    * where an 'expand' will happen.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
    */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1197
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1198
   /* The following code cannot be entered in the alpha pre-multiplication case
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1199
    * because PNG_BACKGROUND_EXPAND is cancelled below.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1200
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1201
   if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1202
       (png_ptr->transformations & PNG_EXPAND) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1205
         png_ptr->background.red   =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1206
             png_ptr->palette[png_ptr->background.index].red;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1207
         png_ptr->background.green =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1208
             png_ptr->palette[png_ptr->background.index].green;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1209
         png_ptr->background.blue  =
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1210
             png_ptr->palette[png_ptr->background.index].blue;
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
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
57618
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  1213
         if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0)
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  1214
         {
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  1215
            if ((png_ptr->transformations & PNG_EXPAND_tRNS) == 0)
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  1216
            {
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  1217
               /* Invert the alpha channel (in tRNS) unless the pixels are
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  1218
                * going to be expanded, in which case leave it for later
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  1219
                */
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  1220
               int i, istop = png_ptr->num_trans;
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  1221
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  1222
               for (i = 0; i < istop; i++)
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  1223
                  png_ptr->trans_alpha[i] =
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  1224
                      (png_byte)(255 - png_ptr->trans_alpha[i]);
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  1225
            }
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  1226
         }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1227
#endif /* READ_INVERT_ALPHA */
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
   } /* background expand and (therefore) no alpha association. */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1230
#endif /* READ_EXPAND && READ_BACKGROUND */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1231
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1232
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1233
static void /* PRIVATE */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1234
png_init_rgb_transformations(png_structrp png_ptr)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1235
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1236
   /* 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
  1237
    * is any alpha or transparency in the image and simply cancel the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1238
    * background and alpha mode stuff if there isn't.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1239
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1240
   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
  1241
   int input_has_transparency = png_ptr->num_trans > 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1242
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1243
   /* If no alpha we can optimize. */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1244
   if (input_has_alpha == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1245
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1246
      /* Any alpha means background and associative alpha processing is
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1247
       * 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
  1248
       * and ENCODE_ALPHA are irrelevant.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1249
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1250
#     ifdef PNG_READ_ALPHA_MODE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1251
         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1252
         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1253
#     endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1254
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1255
      if (input_has_transparency == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1256
         png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1257
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1258
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1259
#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1260
   /* png_set_background handling - deals with the complexity of whether the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1261
    * 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
  1262
    * where an 'expand' will happen.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1263
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1264
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1265
   /* The following code cannot be entered in the alpha pre-multiplication case
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1266
    * because PNG_BACKGROUND_EXPAND is cancelled below.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1267
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1268
   if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1269
       (png_ptr->transformations & PNG_EXPAND) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1270
       (png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1271
       /* i.e., GRAY or GRAY_ALPHA */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1272
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1273
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1274
         /* Expand background and tRNS chunks */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1275
         int gray = png_ptr->background.gray;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1276
         int trans_gray = png_ptr->trans_color.gray;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1277
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
         switch (png_ptr->bit_depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            case 1:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1281
               gray *= 0xff;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1282
               trans_gray *= 0xff;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
               break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1284
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            case 2:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1286
               gray *= 0x55;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1287
               trans_gray *= 0x55;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
               break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1289
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
            case 4:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1291
               gray *= 0x11;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1292
               trans_gray *= 0x11;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
               break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1294
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1295
            default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1296
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            case 8:
48280
791d551bcdb8 8183960: Upgrade to libpng 1.6.34
prr
parents: 47216
diff changeset
  1298
               /* FALLTHROUGH */ /*  (Already 8 bits) */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1299
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
            case 16:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1301
               /* Already a full 16 bits */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
               break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
         }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1304
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1305
         png_ptr->background.red = png_ptr->background.green =
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1306
            png_ptr->background.blue = (png_uint_16)gray;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1307
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1308
         if ((png_ptr->transformations & PNG_EXPAND_tRNS) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1309
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1310
            png_ptr->trans_color.red = png_ptr->trans_color.green =
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1311
               png_ptr->trans_color.blue = (png_uint_16)trans_gray;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1312
         }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1314
   } /* background expand and (therefore) no alpha association. */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1315
#endif /* READ_EXPAND && READ_BACKGROUND */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1316
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1317
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1318
void /* PRIVATE */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1319
png_init_read_transformations(png_structrp png_ptr)
10576
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
   png_debug(1, "in png_init_read_transformations");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1322
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1323
   /* 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
  1324
    * 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
  1325
    * in here can change or update the transformations flags.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1326
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1327
    * 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
  1328
    * being processed.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1329
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1330
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1331
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1332
   /* 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
  1333
    * 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
  1334
    * 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
  1335
    * 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
  1336
    * longer necessary (and doesn't seem to have been necessary before.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1337
    */
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
      /* The following temporary indicates if overall gamma correction is
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1340
       * required.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1341
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1342
      int gamma_correction = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1343
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1344
      if (png_ptr->colorspace.gamma != 0) /* has been set */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1346
         if (png_ptr->screen_gamma != 0) /* screen set too */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1347
            gamma_correction = png_gamma_threshold(png_ptr->colorspace.gamma,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  1348
                png_ptr->screen_gamma);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1349
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1350
         else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1351
            /* Assume the output matches the input; a long time default behavior
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1352
             * of libpng, although the standard has nothing to say about this.
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_reciprocal(png_ptr->colorspace.gamma);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1355
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1356
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1357
      else if (png_ptr->screen_gamma != 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1358
         /* The converse - assume the file matches the screen, note that this
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  1359
          * perhaps undesirable default can (from 1.5.4) be changed by calling
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1360
          * 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
  1361
          * or isn't changed from the default.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1362
          */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1363
         png_ptr->colorspace.gamma = png_reciprocal(png_ptr->screen_gamma);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1364
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1365
      else /* neither are set */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1366
         /* Just in case the following prevents any processing - file and screen
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1367
          * 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
  1368
          * third gamma value other than png_set_background with 'UNIQUE', and,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1369
          * prior to 1.5.4
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1370
          */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1371
         png_ptr->screen_gamma = png_ptr->colorspace.gamma = PNG_FP_1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1372
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1373
      /* We have a gamma value now. */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1374
      png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1375
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1376
      /* Now turn the gamma transformation on or off as appropriate.  Notice
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1377
       * that PNG_GAMMA just refers to the file->screen correction.  Alpha
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1378
       * composition may independently cause gamma correction because it needs
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1379
       * 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
  1380
       * 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
  1381
       * the code immediately below if the transform can be handled outside the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1382
       * row loop.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1383
       */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1384
      if (gamma_correction != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1385
         png_ptr->transformations |= PNG_GAMMA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1386
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1387
      else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1388
         png_ptr->transformations &= ~PNG_GAMMA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1389
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1391
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1392
   /* Certain transformations have the effect of preventing other
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1393
    * transformations that happen afterward in png_do_read_transformations;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1394
    * resolve the interdependencies here.  From the code of
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1395
    * png_do_read_transformations the order is:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1396
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1397
    *  1) PNG_EXPAND (including PNG_EXPAND_tRNS)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1398
    *  2) PNG_STRIP_ALPHA (if no compose)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1399
    *  3) PNG_RGB_TO_GRAY
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1400
    *  4) PNG_GRAY_TO_RGB iff !PNG_BACKGROUND_IS_GRAY
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1401
    *  5) PNG_COMPOSE
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1402
    *  6) PNG_GAMMA
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1403
    *  7) PNG_STRIP_ALPHA (if compose)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1404
    *  8) PNG_ENCODE_ALPHA
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1405
    *  9) PNG_SCALE_16_TO_8
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1406
    * 10) PNG_16_TO_8
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1407
    * 11) PNG_QUANTIZE (converts to palette)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1408
    * 12) PNG_EXPAND_16
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1409
    * 13) PNG_GRAY_TO_RGB iff PNG_BACKGROUND_IS_GRAY
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1410
    * 14) PNG_INVERT_MONO
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1411
    * 15) PNG_INVERT_ALPHA
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1412
    * 16) PNG_SHIFT
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1413
    * 17) PNG_PACK
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1414
    * 18) PNG_BGR
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1415
    * 19) PNG_PACKSWAP
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1416
    * 20) PNG_FILLER (includes PNG_ADD_ALPHA)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1417
    * 21) PNG_SWAP_ALPHA
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1418
    * 22) PNG_SWAP_BYTES
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1419
    * 23) PNG_USER_TRANSFORM [must be last]
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1420
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1421
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1422
   if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1423
       (png_ptr->transformations & PNG_COMPOSE) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1424
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1425
      /* Stripping the alpha channel happens immediately after the 'expand'
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1426
       * transformations, before all other transformation, so it cancels out
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1427
       * the alpha handling.  It has the side effect negating the effect of
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1428
       * PNG_EXPAND_tRNS too:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1429
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1430
      png_ptr->transformations &= ~(PNG_BACKGROUND_EXPAND | PNG_ENCODE_ALPHA |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1431
         PNG_EXPAND_tRNS);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1432
      png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
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
      /* 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
  1435
       * so transparency information would remain just so long as it wasn't
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1436
       * expanded.  This produces unexpected API changes if the set of things
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1437
       * that do PNG_EXPAND_tRNS changes (perfectly possible given the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1438
       * documentation - which says ask for what you want, accept what you
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1439
       * get.)  This makes the behavior consistent from 1.5.4:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1440
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1441
      png_ptr->num_trans = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1442
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1443
#endif /* STRIP_ALPHA supported, no COMPOSE */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1444
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1445
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1446
   /* 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
  1447
    * settings will have no effect.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1448
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1449
   if (png_gamma_significant(png_ptr->screen_gamma) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1450
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1451
      png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1452
      png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1456
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1457
   /* Make sure the coefficients for the rgb to gray conversion are set
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1458
    * appropriately.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1459
    */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1460
   if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1461
      png_colorspace_set_rgb_coefficients(png_ptr);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1462
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1463
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1464
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1465
#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1466
   /* Detect gray background and attempt to enable optimization for
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1467
    * gray --> RGB case.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1468
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1469
    * 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
  1470
    * RGB_ALPHA (in which case need_expand is superfluous anyway), the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1471
    * background color might actually be gray yet not be flagged as such.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1472
    * This is not a problem for the current code, which uses
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1473
    * PNG_BACKGROUND_IS_GRAY only to decide when to do the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1474
    * png_do_gray_to_rgb() transformation.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1475
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1476
    * TODO: this code needs to be revised to avoid the complexity and
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1477
    * interdependencies.  The color type of the background should be recorded in
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1478
    * 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
  1479
    * of exactly what color space the background is currently in.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1480
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1481
   if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1482
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1483
      /* PNG_BACKGROUND_EXPAND: the background is in the file color space, so if
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1484
       * the file was grayscale the background value is gray.
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1485
       */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1486
      if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1487
         png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
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
   else if ((png_ptr->transformations & PNG_COMPOSE) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1491
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1492
      /* PNG_COMPOSE: png_set_background was called with need_expand false,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1493
       * 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
  1494
       * 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
  1495
       * happens before GRAY_TO_RGB.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1496
       */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1497
      if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0)
10576
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
         if (png_ptr->background.red == png_ptr->background.green &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1500
             png_ptr->background.red == png_ptr->background.blue)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1501
         {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1502
            png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1503
            png_ptr->background.gray = png_ptr->background.red;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1504
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1505
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1506
   }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1507
#endif /* READ_EXPAND && READ_BACKGROUND */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1508
#endif /* READ_GRAY_TO_RGB */
10576
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
   /* For indexed PNG data (PNG_COLOR_TYPE_PALETTE) many of the transformations
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1511
    * 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
  1512
    * can be optimized inside the palette.  This is particularly true of the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1513
    * composite (background and alpha) stuff, which can be pretty much all done
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1514
    * 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
  1515
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1516
    * 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
  1517
    * 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
  1518
    * 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
  1519
    * updated.
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
   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1522
      png_init_palette_transformations(png_ptr);
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
   else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1525
      png_init_rgb_transformations(png_ptr);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1526
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1527
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1528
   defined(PNG_READ_EXPAND_16_SUPPORTED)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1529
   if ((png_ptr->transformations & PNG_EXPAND_16) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1530
       (png_ptr->transformations & PNG_COMPOSE) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1531
       (png_ptr->transformations & PNG_BACKGROUND_EXPAND) == 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1532
       png_ptr->bit_depth != 16)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1534
      /* TODO: fix this.  Because the expand_16 operation is after the compose
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1535
       * 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
  1536
       * application will supply a 16-bit value so reduce it here.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1537
       *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1538
       * 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
  1539
       * present, so that case is ok (until do_expand_16 is moved.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1540
       *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1541
       * NOTE: this discards the low 16 bits of the user supplied background
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1542
       * color, but until expand_16 works properly there is no choice!
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1543
       */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1544
#     define CHOP(x) (x)=((png_uint_16)PNG_DIV257(x))
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1545
      CHOP(png_ptr->background.red);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1546
      CHOP(png_ptr->background.green);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1547
      CHOP(png_ptr->background.blue);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1548
      CHOP(png_ptr->background.gray);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1549
#     undef CHOP
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
   }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1551
#endif /* READ_BACKGROUND && READ_EXPAND_16 */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1552
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1553
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1554
   (defined(PNG_READ_SCALE_16_TO_8_SUPPORTED) || \
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1555
   defined(PNG_READ_STRIP_16_TO_8_SUPPORTED))
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1556
   if ((png_ptr->transformations & (PNG_16_TO_8|PNG_SCALE_16_TO_8)) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1557
       (png_ptr->transformations & PNG_COMPOSE) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1558
       (png_ptr->transformations & PNG_BACKGROUND_EXPAND) == 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1559
       png_ptr->bit_depth == 16)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1560
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1561
      /* 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
  1562
       * component this will also happen after PNG_COMPOSE and so the background
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1563
       * color must be pre-expanded here.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1564
       *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1565
       * TODO: fix this too.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1566
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1567
      png_ptr->background.red = (png_uint_16)(png_ptr->background.red * 257);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1568
      png_ptr->background.green =
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1569
         (png_uint_16)(png_ptr->background.green * 257);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1570
      png_ptr->background.blue = (png_uint_16)(png_ptr->background.blue * 257);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1571
      png_ptr->background.gray = (png_uint_16)(png_ptr->background.gray * 257);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1572
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1573
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1574
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1575
   /* 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
  1576
    * background support (see the comments in scripts/pnglibconf.dfa), this
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1577
    * allows pre-multiplication of the alpha channel to be implemented as
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1578
    * 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
  1579
    * 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
  1580
    * implement the new API quickly, without lots of internal changes.)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1581
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1582
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1583
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1584
#  ifdef PNG_READ_BACKGROUND_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1585
      /* Includes ALPHA_MODE */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1586
      png_ptr->background_1 = png_ptr->background;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1587
#  endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1588
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1589
   /* 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
  1590
    * 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
  1591
    * each palette entry directly.  Also, the test is too tricky - why check
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1592
    * 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
  1593
    * 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
  1594
    * PNG_COMPOSE case, so apparently if there is no *overall* gamma correction
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1595
    * 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
  1596
    * gamma encoded value.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1597
    *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1598
    * 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
  1599
    * 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
  1600
    * tables.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1601
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1602
   if ((png_ptr->transformations & PNG_GAMMA) != 0 ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1603
       ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1604
        (png_gamma_significant(png_ptr->colorspace.gamma) != 0 ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1605
         png_gamma_significant(png_ptr->screen_gamma) != 0)) ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1606
        ((png_ptr->transformations & PNG_COMPOSE) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1607
         (png_gamma_significant(png_ptr->colorspace.gamma) != 0 ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1608
          png_gamma_significant(png_ptr->screen_gamma) != 0
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1609
#  ifdef PNG_READ_BACKGROUND_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1610
         || (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_UNIQUE &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1611
           png_gamma_significant(png_ptr->background_gamma) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1612
#  endif
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1613
        )) || ((png_ptr->transformations & PNG_ENCODE_ALPHA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1614
       png_gamma_significant(png_ptr->screen_gamma) != 0))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1616
      png_build_gamma_table(png_ptr, png_ptr->bit_depth);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1617
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1618
#ifdef PNG_READ_BACKGROUND_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1619
      if ((png_ptr->transformations & PNG_COMPOSE) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1621
         /* Issue a warning about this combination: because RGB_TO_GRAY is
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1622
          * optimized to do the gamma transform if present yet do_background has
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1623
          * to do the same thing if both options are set a
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1624
          * double-gamma-correction happens.  This is true in all versions of
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1625
          * libpng to date.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1626
          */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1627
         if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1628
            png_warning(png_ptr,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  1629
                "libpng does not support gamma+background+rgb_to_gray");
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1630
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1631
         if ((png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1633
            /* 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
  1634
             * entries - see the checking code at the start of this function.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1635
             */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
            png_color back, back_1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
            png_colorp palette = png_ptr->palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
            int num_palette = png_ptr->num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
            if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1642
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
               back.red = png_ptr->gamma_table[png_ptr->background.red];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
               back.green = png_ptr->gamma_table[png_ptr->background.green];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
               back.blue = png_ptr->gamma_table[png_ptr->background.blue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
               back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
               back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
               back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1653
               png_fixed_point g, gs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
               switch (png_ptr->background_gamma_type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                  case PNG_BACKGROUND_GAMMA_SCREEN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
                     g = (png_ptr->screen_gamma);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1659
                     gs = PNG_FP_1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
                     break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1661
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
                  case PNG_BACKGROUND_GAMMA_FILE:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1663
                     g = png_reciprocal(png_ptr->colorspace.gamma);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1664
                     gs = png_reciprocal2(png_ptr->colorspace.gamma,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  1665
                         png_ptr->screen_gamma);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                     break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1667
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                  case PNG_BACKGROUND_GAMMA_UNIQUE:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1669
                     g = png_reciprocal(png_ptr->background_gamma);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1670
                     gs = png_reciprocal2(png_ptr->background_gamma,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  1671
                         png_ptr->screen_gamma);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
                     break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
                  default:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1674
                     g = PNG_FP_1;    /* back_1 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1675
                     gs = PNG_FP_1;   /* back */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1676
                     break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1679
               if (png_gamma_significant(gs) != 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.red = png_gamma_8bit_correct(png_ptr->background.red,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1682
                      gs);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1683
                  back.green = png_gamma_8bit_correct(png_ptr->background.green,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1684
                      gs);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1685
                  back.blue = png_gamma_8bit_correct(png_ptr->background.blue,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1686
                      gs);
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
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1689
               else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
                  back.red   = (png_byte)png_ptr->background.red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
                  back.green = (png_byte)png_ptr->background.green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
                  back.blue  = (png_byte)png_ptr->background.blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1695
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1696
               if (png_gamma_significant(g) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1697
               {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1698
                  back_1.red = png_gamma_8bit_correct(png_ptr->background.red,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  1699
                      g);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1700
                  back_1.green = png_gamma_8bit_correct(
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  1701
                      png_ptr->background.green, g);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1702
                  back_1.blue = png_gamma_8bit_correct(png_ptr->background.blue,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  1703
                      g);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1704
               }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1705
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
               {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1708
                  back_1.red   = (png_byte)png_ptr->background.red;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1709
                  back_1.green = (png_byte)png_ptr->background.green;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1710
                  back_1.blue  = (png_byte)png_ptr->background.blue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1713
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
            for (i = 0; i < num_palette; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
            {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1716
               if (i < (int)png_ptr->num_trans &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1717
                   png_ptr->trans_alpha[i] != 0xff)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
               {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1719
                  if (png_ptr->trans_alpha[i] == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
                     palette[i] = back;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1723
                  else /* if (png_ptr->trans_alpha[i] != 0xff) */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
                     png_byte v, w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
                     v = png_ptr->gamma_to_1[palette[i].red];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1728
                     png_composite(w, v, png_ptr->trans_alpha[i], back_1.red);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
                     palette[i].red = png_ptr->gamma_from_1[w];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
                     v = png_ptr->gamma_to_1[palette[i].green];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1732
                     png_composite(w, v, png_ptr->trans_alpha[i], back_1.green);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
                     palette[i].green = png_ptr->gamma_from_1[w];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
                     v = png_ptr->gamma_to_1[palette[i].blue];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1736
                     png_composite(w, v, png_ptr->trans_alpha[i], back_1.blue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
                     palette[i].blue = png_ptr->gamma_from_1[w];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
                  palette[i].red = png_ptr->gamma_table[palette[i].red];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
                  palette[i].green = png_ptr->gamma_table[palette[i].green];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
                  palette[i].blue = png_ptr->gamma_table[palette[i].blue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1747
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1748
            /* Prevent the transformations being done again.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1749
             *
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1750
             * NOTE: this is highly dubious; it removes the transformations in
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1751
             * place.  This seems inconsistent with the general treatment of the
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1752
             * transformations elsewhere.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1753
             */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1754
            png_ptr->transformations &= ~(PNG_COMPOSE | PNG_GAMMA);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1755
         } /* color_type == PNG_COLOR_TYPE_PALETTE */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1756
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
         /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1758
         else /* color_type != PNG_COLOR_TYPE_PALETTE */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1760
            int gs_sig, g_sig;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1761
            png_fixed_point g = PNG_FP_1;  /* Correction to linear */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1762
            png_fixed_point gs = PNG_FP_1; /* Correction to screen */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
            switch (png_ptr->background_gamma_type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
               case PNG_BACKGROUND_GAMMA_SCREEN:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1767
                  g = png_ptr->screen_gamma;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1768
                  /* gs = PNG_FP_1; */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                  break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1770
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
               case PNG_BACKGROUND_GAMMA_FILE:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1772
                  g = png_reciprocal(png_ptr->colorspace.gamma);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1773
                  gs = png_reciprocal2(png_ptr->colorspace.gamma,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  1774
                      png_ptr->screen_gamma);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
                  break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1776
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
               case PNG_BACKGROUND_GAMMA_UNIQUE:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1778
                  g = png_reciprocal(png_ptr->background_gamma);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1779
                  gs = png_reciprocal2(png_ptr->background_gamma,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1780
                      png_ptr->screen_gamma);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
                  break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1782
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1783
               default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1784
                  png_error(png_ptr, "invalid background gamma type");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1787
            g_sig = png_gamma_significant(g);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1788
            gs_sig = png_gamma_significant(gs);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1789
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1790
            if (g_sig != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1791
               png_ptr->background_1.gray = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1792
                   png_ptr->background.gray, g);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1793
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1794
            if (gs_sig != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1795
               png_ptr->background.gray = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1796
                   png_ptr->background.gray, gs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
            if ((png_ptr->background.red != png_ptr->background.green) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
                (png_ptr->background.red != png_ptr->background.blue) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
                (png_ptr->background.red != png_ptr->background.gray))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
               /* RGB or RGBA with color background */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1803
               if (g_sig != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1804
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1805
                  png_ptr->background_1.red = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1806
                      png_ptr->background.red, g);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1807
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1808
                  png_ptr->background_1.green = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1809
                      png_ptr->background.green, g);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1810
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1811
                  png_ptr->background_1.blue = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1812
                      png_ptr->background.blue, g);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1813
               }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1814
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1815
               if (gs_sig != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1816
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1817
                  png_ptr->background.red = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1818
                      png_ptr->background.red, gs);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1819
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1820
                  png_ptr->background.green = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1821
                      png_ptr->background.green, gs);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1822
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1823
                  png_ptr->background.blue = png_gamma_correct(png_ptr,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1824
                      png_ptr->background.blue, gs);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1825
               }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1827
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
               /* GRAY, GRAY ALPHA, RGB, or RGBA with gray background */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
               png_ptr->background_1.red = png_ptr->background_1.green
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1832
                   = png_ptr->background_1.blue = png_ptr->background_1.gray;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1833
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
               png_ptr->background.red = png_ptr->background.green
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1835
                   = png_ptr->background.blue = png_ptr->background.gray;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
            }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1837
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1838
            /* The background is now in screen gamma: */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1839
            png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_SCREEN;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1840
         } /* color_type != PNG_COLOR_TYPE_PALETTE */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1841
      }/* png_ptr->transformations & PNG_BACKGROUND */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1842
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
      else
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1844
      /* Transformation does not include PNG_BACKGROUND */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1845
#endif /* READ_BACKGROUND */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1846
      if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1847
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1848
         /* RGB_TO_GRAY needs to have non-gamma-corrected values! */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1849
         && ((png_ptr->transformations & PNG_EXPAND) == 0 ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1850
         (png_ptr->transformations & PNG_RGB_TO_GRAY) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1851
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1852
         )
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
         png_colorp palette = png_ptr->palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
         int num_palette = png_ptr->num_palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
         int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1858
         /* NOTE: there are other transformations that should probably be in
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1859
          * here too.
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1860
          */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
         for (i = 0; i < num_palette; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
            palette[i].red = png_ptr->gamma_table[palette[i].red];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
            palette[i].green = png_ptr->gamma_table[palette[i].green];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
            palette[i].blue = png_ptr->gamma_table[palette[i].blue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1867
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1868
         /* Done the gamma correction. */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1869
         png_ptr->transformations &= ~PNG_GAMMA;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1870
      } /* color_type == PALETTE && !PNG_BACKGROUND transformation */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1872
#ifdef PNG_READ_BACKGROUND_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
#endif
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1875
#endif /* READ_GAMMA */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1876
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1877
#ifdef PNG_READ_BACKGROUND_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1878
   /* No GAMMA transformation (see the hanging else 4 lines above) */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1879
   if ((png_ptr->transformations & PNG_COMPOSE) != 0 &&
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1880
       (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
      int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
      int istop = (int)png_ptr->num_trans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
      png_color back;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
      png_colorp palette = png_ptr->palette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
      back.red   = (png_byte)png_ptr->background.red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
      back.green = (png_byte)png_ptr->background.green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
      back.blue  = (png_byte)png_ptr->background.blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
      for (i = 0; i < istop; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1893
         if (png_ptr->trans_alpha[i] == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
            palette[i] = back;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1897
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1898
         else if (png_ptr->trans_alpha[i] != 0xff)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
            /* The png_composite() macro is defined in png.h */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
            png_composite(palette[i].red, palette[i].red,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1902
                png_ptr->trans_alpha[i], back.red);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1903
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
            png_composite(palette[i].green, palette[i].green,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1905
                png_ptr->trans_alpha[i], back.green);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1906
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
            png_composite(palette[i].blue, palette[i].blue,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1908
                png_ptr->trans_alpha[i], back.blue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1911
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1912
      png_ptr->transformations &= ~PNG_COMPOSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
   }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1914
#endif /* READ_BACKGROUND */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1916
#ifdef PNG_READ_SHIFT_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1917
   if ((png_ptr->transformations & PNG_SHIFT) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1918
       (png_ptr->transformations & PNG_EXPAND) == 0 &&
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1919
       (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1921
      int i;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1922
      int istop = png_ptr->num_palette;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1923
      int shift = 8 - png_ptr->sig_bit.red;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1924
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1925
      png_ptr->transformations &= ~PNG_SHIFT;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1926
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  1927
      /* significant bits can be in the range 1 to 7 for a meaningful result, if
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1928
       * 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
  1929
       * error condition which is silently ignored.)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1930
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1931
      if (shift > 0 && shift < 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1932
         for (i=0; i<istop; ++i)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1933
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1934
            int component = png_ptr->palette[i].red;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1935
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1936
            component >>= shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1937
            png_ptr->palette[i].red = (png_byte)component;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1938
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1939
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1940
      shift = 8 - png_ptr->sig_bit.green;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1941
      if (shift > 0 && shift < 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1942
         for (i=0; i<istop; ++i)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1943
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1944
            int component = png_ptr->palette[i].green;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1945
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1946
            component >>= shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1947
            png_ptr->palette[i].green = (png_byte)component;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1948
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1949
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1950
      shift = 8 - png_ptr->sig_bit.blue;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1951
      if (shift > 0 && shift < 8)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1952
         for (i=0; i<istop; ++i)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1953
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1954
            int component = png_ptr->palette[i].blue;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1955
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1956
            component >>= shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1957
            png_ptr->palette[i].blue = (png_byte)component;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1958
         }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
   }
40436
94ae0ede53a5 8155690: Update libPNG library to the latest up-to-date
azvegint
parents: 35692
diff changeset
  1960
#endif /* READ_SHIFT */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
/* Modify the info structure to reflect the transformations.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
 * info should be updated so a PNG file could be written with it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
 * assuming the transformations result in valid PNG data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
void /* PRIVATE */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1968
png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1970
   png_debug(1, "in png_read_transform_info");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1971
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1972
#ifdef PNG_READ_EXPAND_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1973
   if ((png_ptr->transformations & PNG_EXPAND) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1977
         /* This check must match what actually happens in
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1978
          * 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
  1979
          * 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
  1980
          */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1981
         if (png_ptr->num_trans > 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
            info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1983
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
            info_ptr->color_type = PNG_COLOR_TYPE_RGB;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1986
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
         info_ptr->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
         info_ptr->num_trans = 0;
23903
3e78d4a02113 8031352: Enhance PNG handling
serb
parents: 10576
diff changeset
  1989
3e78d4a02113 8031352: Enhance PNG handling
serb
parents: 10576
diff changeset
  1990
         if (png_ptr->palette == NULL)
3e78d4a02113 8031352: Enhance PNG handling
serb
parents: 10576
diff changeset
  1991
            png_error (png_ptr, "Palette is NULL in indexed image");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1995
         if (png_ptr->num_trans != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  1997
            if ((png_ptr->transformations & PNG_EXPAND_tRNS) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  1998
               info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
         if (info_ptr->bit_depth < 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
            info_ptr->bit_depth = 8;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2002
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
         info_ptr->num_trans = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2008
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2009
   defined(PNG_READ_ALPHA_MODE_SUPPORTED)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2010
   /* The following is almost certainly wrong unless the background value is in
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2011
    * the screen space!
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2012
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2013
   if ((png_ptr->transformations & PNG_COMPOSE) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
      info_ptr->background = png_ptr->background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2017
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2018
   /* 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
  2019
    * 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
  2020
    * 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
  2021
    * sometimes does the gamma transform and cancels the flag.
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2022
    *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2023
    * 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
  2024
    * the screen_gamma value.  The following probably results in weirdness if
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2025
    * 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
  2026
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2027
   info_ptr->colorspace.gamma = png_ptr->colorspace.gamma;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2028
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2029
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2030
   if (info_ptr->bit_depth == 16)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2032
#  ifdef PNG_READ_16BIT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2033
#     ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2034
         if ((png_ptr->transformations & PNG_SCALE_16_TO_8) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2035
            info_ptr->bit_depth = 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2036
#     endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2037
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2038
#     ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2039
         if ((png_ptr->transformations & PNG_16_TO_8) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2040
            info_ptr->bit_depth = 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2041
#     endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2042
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2043
#  else
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2044
      /* 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
  2045
       * 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
  2046
       * correct scaling to use.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2047
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2048
#     ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2049
         /* For compatibility with previous versions use the strip method by
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2050
          * 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
  2051
          * set the code below will do that in preference to the chop.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2052
          */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2053
         png_ptr->transformations |= PNG_16_TO_8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2054
         info_ptr->bit_depth = 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2055
#     else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2056
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2057
#        ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2058
            png_ptr->transformations |= PNG_SCALE_16_TO_8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2059
            info_ptr->bit_depth = 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2060
#        else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2061
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2062
            CONFIGURATION ERROR: you must enable at least one 16 to 8 method
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2063
#        endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2064
#    endif
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2065
#endif /* !READ_16BIT */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2067
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2068
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2069
   if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2070
      info_ptr->color_type = (png_byte)(info_ptr->color_type |
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2071
         PNG_COLOR_MASK_COLOR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2074
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2075
   if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2076
      info_ptr->color_type = (png_byte)(info_ptr->color_type &
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2077
         ~PNG_COLOR_MASK_COLOR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2080
#ifdef PNG_READ_QUANTIZE_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2081
   if ((png_ptr->transformations & PNG_QUANTIZE) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
      if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2084
          (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2085
          png_ptr->palette_lookup != 0 && info_ptr->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
         info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2092
#ifdef PNG_READ_EXPAND_16_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2093
   if ((png_ptr->transformations & PNG_EXPAND_16) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2094
       info_ptr->bit_depth == 8 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2095
       info_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2096
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2097
      info_ptr->bit_depth = 16;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2098
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2099
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2100
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2101
#ifdef PNG_READ_PACK_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2102
   if ((png_ptr->transformations & PNG_PACK) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2103
       (info_ptr->bit_depth < 8))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
      info_ptr->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
   if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
      info_ptr->channels = 1;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2109
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2110
   else if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
      info_ptr->channels = 3;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2112
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
      info_ptr->channels = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2116
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2117
   if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2118
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2119
      info_ptr->color_type = (png_byte)(info_ptr->color_type &
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2120
         ~PNG_COLOR_MASK_ALPHA);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2121
      info_ptr->num_trans = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2122
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2125
   if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
      info_ptr->channels++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2128
#ifdef PNG_READ_FILLER_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
   /* STRIP_ALPHA and FILLER allowed:  MASK_ALPHA bit stripped above */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2130
   if ((png_ptr->transformations & PNG_FILLER) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2131
       (info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2132
       info_ptr->color_type == PNG_COLOR_TYPE_GRAY))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
      info_ptr->channels++;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2135
      /* If adding a true alpha channel not just filler */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2136
      if ((png_ptr->transformations & PNG_ADD_ALPHA) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2137
         info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2143
   if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2144
   {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2145
      if (png_ptr->user_transform_depth != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
         info_ptr->bit_depth = png_ptr->user_transform_depth;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2147
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2148
      if (png_ptr->user_transform_channels != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
         info_ptr->channels = png_ptr->user_transform_channels;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2150
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
   info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2154
       info_ptr->bit_depth);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2155
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2156
   info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, info_ptr->width);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2157
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2158
   /* 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
  2159
    * 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
  2160
    * 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
  2161
    * 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
  2162
    * right itself.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2163
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2164
   png_ptr->info_rowbytes = info_ptr->rowbytes;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2165
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2166
#ifndef PNG_READ_EXPAND_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2167
   if (png_ptr != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2172
#ifdef PNG_READ_PACK_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
/* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
 * without changing the actual values.  Thus, if you had a row with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
 * a bit depth of 1, you would end up with bytes that only contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
 * the numbers 0 or 1.  If you would rather they contain 0 and 255, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
 * png_do_shift() after this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2179
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
png_do_unpack(png_row_infop row_info, png_bytep row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2182
   png_debug(1, "in png_do_unpack");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2183
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
   if (row_info->bit_depth < 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
      png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
      png_uint_32 row_width=row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
      switch (row_info->bit_depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
         case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
         {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2193
            png_bytep sp = row + (size_t)((row_width - 1) >> 3);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2194
            png_bytep dp = row + (size_t)row_width - 1;
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  2195
            png_uint_32 shift = 7U - ((row_width + 7U) & 0x07);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
               *dp = (png_byte)((*sp >> shift) & 0x01);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2199
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
               if (shift == 7)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
                  shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
                  sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2205
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
                  shift++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
               dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2213
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
         case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2217
            png_bytep sp = row + (size_t)((row_width - 1) >> 2);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2218
            png_bytep dp = row + (size_t)row_width - 1;
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  2219
            png_uint_32 shift = ((3U - ((row_width + 3U) & 0x03)) << 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
               *dp = (png_byte)((*sp >> shift) & 0x03);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2223
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
               if (shift == 6)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
                  shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
                  sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2229
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
                  shift += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
               dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2237
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
         case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
         {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2240
            png_bytep sp = row + (size_t)((row_width - 1) >> 1);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2241
            png_bytep dp = row + (size_t)row_width - 1;
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  2242
            png_uint_32 shift = ((1U - ((row_width + 1U) & 0x01)) << 2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
               *dp = (png_byte)((*sp >> shift) & 0x0f);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2246
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
               if (shift == 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
                  shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
                  sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2252
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
                  shift = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
               dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2260
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2261
         default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2262
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
      row_info->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
      row_info->pixel_depth = (png_byte)(8 * row_info->channels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
      row_info->rowbytes = row_width * row_info->channels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2271
#ifdef PNG_READ_SHIFT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
/* Reverse the effects of png_do_shift.  This routine merely shifts the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
 * pixels back to their significant bits values.  Thus, if you have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
 * a row of bit depth 8, but only 5 are significant, this will shift
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
 * the values back to 0 through 31.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2277
static void
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2278
png_do_unshift(png_row_infop row_info, png_bytep row,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2279
    png_const_color_8p sig_bits)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
{
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2281
   int color_type;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2282
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2283
   png_debug(1, "in png_do_unshift");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2284
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2285
   /* The palette case has already been handled in the _init routine. */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2286
   color_type = row_info->color_type;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2287
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2288
   if (color_type != PNG_COLOR_TYPE_PALETTE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
      int shift[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
      int channels = 0;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2292
      int bit_depth = row_info->bit_depth;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2293
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2294
      if ((color_type & PNG_COLOR_MASK_COLOR) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2296
         shift[channels++] = bit_depth - sig_bits->red;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2297
         shift[channels++] = bit_depth - sig_bits->green;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2298
         shift[channels++] = bit_depth - sig_bits->blue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2300
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2303
         shift[channels++] = bit_depth - sig_bits->gray;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2305
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2306
      if ((color_type & PNG_COLOR_MASK_ALPHA) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2308
         shift[channels++] = bit_depth - sig_bits->alpha;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2312
         int c, have_shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2313
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2314
         for (c = have_shift = 0; c < channels; ++c)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2315
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2316
            /* A shift of more than the bit depth is an error condition but it
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2317
             * gets ignored here.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2318
             */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2319
            if (shift[c] <= 0 || shift[c] >= bit_depth)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2320
               shift[c] = 0;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2321
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2322
            else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2323
               have_shift = 1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2324
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2325
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2326
         if (have_shift == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2327
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2330
      switch (bit_depth)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2332
         default:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2333
         /* Must be 1bpp gray: should not be here! */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2334
            /* NOTREACHED */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2335
            break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2336
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
         case 2:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2338
         /* Must be 2bpp gray */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2339
         /* assert(channels == 1 && shift[0] == 1) */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2341
            png_bytep bp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2342
            png_bytep bp_end = bp + row_info->rowbytes;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2343
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2344
            while (bp < bp_end)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2346
               int b = (*bp >> 1) & 0x55;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2347
               *bp++ = (png_byte)b;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2351
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
         case 4:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2353
         /* Must be 4bpp gray */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2354
         /* assert(channels == 1) */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
            png_bytep bp = row;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2357
            png_bytep bp_end = bp + row_info->rowbytes;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2358
            int gray_shift = shift[0];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2359
            int mask =  0xf >> gray_shift;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2360
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2361
            mask |= mask << 4;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2362
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2363
            while (bp < bp_end)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2365
               int b = (*bp >> gray_shift) & mask;
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
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
         case 8:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2372
         /* Single byte components, G, GA, RGB, RGBA */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
            png_bytep bp = row;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2375
            png_bytep bp_end = bp + row_info->rowbytes;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2376
            int channel = 0;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2377
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2378
            while (bp < bp_end)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2380
               int b = *bp >> shift[channel];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2381
               if (++channel >= channels)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2382
                  channel = 0;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2383
               *bp++ = (png_byte)b;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2387
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2388
#ifdef PNG_READ_16BIT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
         case 16:
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2390
         /* Double byte components, G, GA, RGB, RGBA */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
            png_bytep bp = row;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2393
            png_bytep bp_end = bp + row_info->rowbytes;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2394
            int channel = 0;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2395
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2396
            while (bp < bp_end)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2398
               int value = (bp[0] << 8) + bp[1];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2399
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2400
               value >>= shift[channel];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2401
               if (++channel >= channels)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2402
                  channel = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
               *bp++ = (png_byte)(value >> 8);
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2404
               *bp++ = (png_byte)value;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2408
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2414
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2415
/* Scale rows of bit depth 16 down to 8 accurately */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2416
static void
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2417
png_do_scale_16_to_8(png_row_infop row_info, png_bytep row)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2419
   png_debug(1, "in png_do_scale_16_to_8");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2420
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
   if (row_info->bit_depth == 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2423
      png_bytep sp = row; /* source */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2424
      png_bytep dp = row; /* destination */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2425
      png_bytep ep = sp + row_info->rowbytes; /* end+1 */
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
      while (sp < ep)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
      {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2429
         /* The input is an array of 16-bit components, these must be scaled to
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2430
          * 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
  2431
          * specification) is:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2432
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2433
          *    (V * 255) / 65535
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2434
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2435
          * This reduces to round(V / 257), or floor((V + 128.5)/257)
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
          * 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
  2438
          * 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
  2439
          * 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
          *    error = floor(((V-vhi.vhi) + 128.5) / 257)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2442
          *          = floor(((vlo-vhi) + 128.5) / 257)
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
          * This can be approximated using integer arithmetic (and a signed
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2445
          * shift):
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2446
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2447
          *    error = (vlo-vhi+128) >> 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2448
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2449
          * The approximate differs from the exact answer only when (vlo-vhi) is
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2450
          * 128; it then gives a correction of +1 when the exact correction is
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2451
          * 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
  2452
          * input values) is:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2453
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2454
          *    error = (vlo-vhi+128)*65535 >> 24;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2455
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2456
          * An alternative arithmetic calculation which also gives no errors is:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2457
          *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2458
          *    (V * 255 + 32895) >> 16
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2459
          */
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_int_32 tmp = *sp++; /* must be signed! */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2462
         tmp += (((int)*sp++ - tmp + 128) * 65535) >> 24;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2463
         *dp++ = (png_byte)tmp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2465
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
      row_info->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
      row_info->pixel_depth = (png_byte)(8 * row_info->channels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
      row_info->rowbytes = row_info->width * row_info->channels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2473
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2474
static void
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2475
/* Simply discard the low byte.  This was the default behavior prior
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2476
 * to libpng-1.5.4.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2477
 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2478
png_do_chop(png_row_infop row_info, png_bytep row)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2479
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2480
   png_debug(1, "in png_do_chop");
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
   if (row_info->bit_depth == 16)
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
      png_bytep sp = row; /* source */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2485
      png_bytep dp = row; /* destination */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2486
      png_bytep ep = sp + row_info->rowbytes; /* end+1 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2487
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2488
      while (sp < ep)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2489
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2490
         *dp++ = *sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2491
         sp += 2; /* skip low byte */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2492
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2493
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2494
      row_info->bit_depth = 8;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2495
      row_info->pixel_depth = (png_byte)(8 * row_info->channels);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2496
      row_info->rowbytes = row_info->width * row_info->channels;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2497
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2498
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2499
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2500
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2501
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2502
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
{
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2505
   png_uint_32 row_width = row_info->width;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2506
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2507
   png_debug(1, "in png_do_read_swap_alpha");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2508
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2509
   if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
   {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2511
      /* This converts from RGBA to ARGB */
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2512
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
      {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2514
         png_bytep sp = row + row_info->rowbytes;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2515
         png_bytep dp = sp;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2516
         png_byte save;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2517
         png_uint_32 i;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2518
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2519
         for (i = 0; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
         {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2521
            save = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2522
            *(--dp) = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2523
            *(--dp) = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2524
            *(--dp) = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2525
            *(--dp) = save;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
         }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2527
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2528
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2529
#ifdef PNG_READ_16BIT_SUPPORTED
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2530
      /* This converts from RRGGBBAA to AARRGGBB */
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2531
      else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2532
      {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2533
         png_bytep sp = row + row_info->rowbytes;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2534
         png_bytep dp = sp;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2535
         png_byte save[2];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2536
         png_uint_32 i;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2537
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2538
         for (i = 0; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
         {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2540
            save[0] = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2541
            save[1] = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2542
            *(--dp) = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2543
            *(--dp) = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2544
            *(--dp) = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2545
            *(--dp) = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2546
            *(--dp) = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2547
            *(--dp) = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2548
            *(--dp) = save[0];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2549
            *(--dp) = save[1];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
         }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2551
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2552
#endif
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2553
   }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2554
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2555
   else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2556
   {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2557
      /* This converts from GA to AG */
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2558
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
      {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2560
         png_bytep sp = row + row_info->rowbytes;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2561
         png_bytep dp = sp;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2562
         png_byte save;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2563
         png_uint_32 i;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2564
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2565
         for (i = 0; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
         {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2567
            save = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2568
            *(--dp) = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2569
            *(--dp) = save;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
         }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2571
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2572
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2573
#ifdef PNG_READ_16BIT_SUPPORTED
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2574
      /* This converts from GGAA to AAGG */
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2575
      else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2576
      {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2577
         png_bytep sp = row + row_info->rowbytes;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2578
         png_bytep dp = sp;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2579
         png_byte save[2];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2580
         png_uint_32 i;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2581
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2582
         for (i = 0; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
         {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2584
            save[0] = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2585
            save[1] = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2586
            *(--dp) = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2587
            *(--dp) = *(--sp);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2588
            *(--dp) = save[0];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2589
            *(--dp) = save[1];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
         }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2591
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2592
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2597
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2598
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2601
   png_uint_32 row_width;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2602
   png_debug(1, "in png_do_read_invert_alpha");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2603
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2604
   row_width = row_info->width;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2605
   if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2607
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
         /* This inverts the alpha channel in RGBA */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2610
         png_bytep sp = row + row_info->rowbytes;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2611
         png_bytep dp = sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2612
         png_uint_32 i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2613
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2614
         for (i = 0; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2616
            *(--dp) = (png_byte)(255 - *(--sp));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2617
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2618
/*          This does nothing:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2619
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2620
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2621
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2622
            We can replace it with:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
*/
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2624
            sp-=3;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2625
            dp=sp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2628
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2629
#ifdef PNG_READ_16BIT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2630
      /* This inverts the alpha channel in RRGGBBAA */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2631
      else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2632
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2633
         png_bytep sp = row + row_info->rowbytes;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2634
         png_bytep dp = sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2635
         png_uint_32 i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2636
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2637
         for (i = 0; i < row_width; i++)
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
            *(--dp) = (png_byte)(255 - *(--sp));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2640
            *(--dp) = (png_byte)(255 - *(--sp));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2641
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2642
/*          This does nothing:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2643
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2644
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2645
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2646
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2647
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2648
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2649
            We can replace it with:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2650
*/
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2651
            sp-=6;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2652
            dp=sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2653
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2654
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2655
#endif
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
   else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2658
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2659
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
         /* This inverts the alpha channel in GA */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2662
         png_bytep sp = row + row_info->rowbytes;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2663
         png_bytep dp = sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2664
         png_uint_32 i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2665
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2666
         for (i = 0; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
         {
10576
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
            *(--dp) = *(--sp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
      }
10576
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
#ifdef PNG_READ_16BIT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2674
      else
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
         /* This inverts the alpha channel in GGAA */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2677
         png_bytep sp  = row + row_info->rowbytes;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2678
         png_bytep dp = sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2679
         png_uint_32 i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2680
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2681
         for (i = 0; i < row_width; i++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2682
         {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2683
            *(--dp) = (png_byte)(255 - *(--sp));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2684
            *(--dp) = (png_byte)(255 - *(--sp));
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2685
/*
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2686
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2687
            *(--dp) = *(--sp);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2688
*/
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2689
            sp-=2;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2690
            dp=sp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2691
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2692
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2693
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2698
#ifdef PNG_READ_FILLER_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
/* Add filler channel if we have RGB color */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2700
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
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
  2702
    png_uint_32 filler, png_uint_32 flags)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
   png_uint_32 row_width = row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2707
#ifdef PNG_READ_16BIT_SUPPORTED
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2708
   png_byte hi_filler = (png_byte)(filler>>8);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2709
#endif
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2710
   png_byte lo_filler = (png_byte)filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2712
   png_debug(1, "in png_do_read_filler");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2713
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
   if (
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
       row_info->color_type == PNG_COLOR_TYPE_GRAY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2717
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2719
         if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
2
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 GX */
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2722
            png_bytep sp = row + (size_t)row_width;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2723
            png_bytep dp =  sp + (size_t)row_width;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
            for (i = 1; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
               *(--dp) = lo_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
            *(--dp) = lo_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
            row_info->channels = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
            row_info->pixel_depth = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
            row_info->rowbytes = row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2734
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2737
            /* This changes the data from G to XG */
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2738
            png_bytep sp = row + (size_t)row_width;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2739
            png_bytep dp = sp  + (size_t)row_width;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
               *(--dp) = lo_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
            row_info->channels = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
            row_info->pixel_depth = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
            row_info->rowbytes = row_width * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2750
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2751
#ifdef PNG_READ_16BIT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2752
      else if (row_info->bit_depth == 16)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2754
         if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2756
            /* This changes the data from GG to GGXX */
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2757
            png_bytep sp = row + (size_t)row_width * 2;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2758
            png_bytep dp = sp  + (size_t)row_width * 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
            for (i = 1; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
            {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2761
               *(--dp) = lo_filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
               *(--dp) = hi_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
            }
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
            row_info->channels = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
            row_info->pixel_depth = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
            row_info->rowbytes = row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2772
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2775
            /* This changes the data from GG to XXGG */
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2776
            png_bytep sp = row + (size_t)row_width * 2;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2777
            png_bytep dp = sp  + (size_t)row_width * 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
               *(--dp) = *(--sp);
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2782
               *(--dp) = lo_filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
               *(--dp) = hi_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
            row_info->channels = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
            row_info->pixel_depth = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
            row_info->rowbytes = row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2790
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
   } /* COLOR_TYPE == GRAY */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
   else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2794
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2796
         if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2798
            /* This changes the data from RGB to RGBX */
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2799
            png_bytep sp = row + (size_t)row_width * 3;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2800
            png_bytep dp = sp  + (size_t)row_width;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
            for (i = 1; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
               *(--dp) = lo_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
               *(--dp) = *(--sp);
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
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
            *(--dp) = lo_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
            row_info->channels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
            row_info->pixel_depth = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
            row_info->rowbytes = row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2813
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2816
            /* This changes the data from RGB to XRGB */
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2817
            png_bytep sp = row + (size_t)row_width * 3;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2818
            png_bytep dp = sp + (size_t)row_width;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
               *(--dp) = lo_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
            row_info->channels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
            row_info->pixel_depth = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
            row_info->rowbytes = row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2831
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2832
#ifdef PNG_READ_16BIT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2833
      else if (row_info->bit_depth == 16)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2835
         if ((flags & PNG_FLAG_FILLER_AFTER) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2837
            /* This changes the data from RRGGBB to RRGGBBXX */
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2838
            png_bytep sp = row + (size_t)row_width * 6;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2839
            png_bytep dp = sp  + (size_t)row_width * 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
            for (i = 1; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
            {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2842
               *(--dp) = lo_filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
               *(--dp) = hi_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
            }
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2851
            *(--dp) = lo_filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
            *(--dp) = hi_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
            row_info->channels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
            row_info->pixel_depth = 64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
            row_info->rowbytes = row_width * 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2857
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2860
            /* This changes the data from RRGGBB to XXRRGGBB */
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2861
            png_bytep sp = row + (size_t)row_width * 6;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2862
            png_bytep dp = sp  + (size_t)row_width * 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
               *(--dp) = *(--sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
               *(--dp) = *(--sp);
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  2871
               *(--dp) = lo_filler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
               *(--dp) = hi_filler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2874
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
            row_info->channels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
            row_info->pixel_depth = 64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
            row_info->rowbytes = row_width * 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2880
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
   } /* COLOR_TYPE == RGB */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2885
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2886
/* Expand grayscale files to RGB, with or without alpha */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2887
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
   png_uint_32 row_width = row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2893
   png_debug(1, "in png_do_gray_to_rgb");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2894
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
   if (row_info->bit_depth >= 8 &&
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2896
       (row_info->color_type & PNG_COLOR_MASK_COLOR) == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
      if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
         if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2902
            /* This changes G to RGB */
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2903
            png_bytep sp = row + (size_t)row_width - 1;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2904
            png_bytep dp = sp  + (size_t)row_width * 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
               *(dp--) = *sp;
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
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2912
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2915
            /* This changes GG to RRGGBB */
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2916
            png_bytep sp = row + (size_t)row_width * 2 - 1;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2917
            png_bytep dp = sp  + (size_t)row_width * 4;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
               *(dp--) = *(sp - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
               *(dp--) = *(sp - 1);
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
            }
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 if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
         if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2934
            /* This changes GA to RGBA */
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2935
            png_bytep sp = row + (size_t)row_width * 2 - 1;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2936
            png_bytep dp = sp  + (size_t)row_width * 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2945
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2948
            /* This changes GGAA to RRGGBBAA */
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2949
            png_bytep sp = row + (size_t)row_width * 4 - 1;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  2950
            png_bytep dp = sp  + (size_t)row_width * 4;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
               *(dp--) = *(sp - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
               *(dp--) = *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
               *(dp--) = *(sp - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
               *(dp--) = *(sp--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
      }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2964
      row_info->channels = (png_byte)(row_info->channels + 2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
      row_info->color_type |= PNG_COLOR_MASK_COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
      row_info->pixel_depth = (png_byte)(row_info->channels *
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2967
          row_info->bit_depth);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2968
      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2973
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2974
/* Reduce RGB files to grayscale, with or without alpha
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2975
 * using the equation given in Poynton's ColorFAQ of 1998-01-04 at
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2976
 * <http://www.inforamp.net/~poynton/>  (THIS LINK IS DEAD June 2008 but
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2977
 * versions dated 1998 through November 2002 have been archived at
48280
791d551bcdb8 8183960: Upgrade to libpng 1.6.34
prr
parents: 47216
diff changeset
  2978
 * https://web.archive.org/web/20000816232553/www.inforamp.net/
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2979
 * ~poynton/notes/colour_and_gamma/ColorFAQ.txt )
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  2980
 * Charles Poynton poynton at poynton.com
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
 *     Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
 *  which can be expressed with integers as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
 *     Y = (6969 * R + 23434 * G + 2365 * B)/32768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
 *
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2988
 * Poynton's current link (as of January 2003 through July 2011):
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2989
 * <http://www.poynton.com/notes/colour_and_gamma/>
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2990
 * has changed the numbers slightly:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2991
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2992
 *     Y = 0.2126*R + 0.7152*G + 0.0722*B
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2993
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2994
 *  which can be expressed with integers as
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2995
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2996
 *     Y = (6966 * R + 23436 * G + 2366 * B)/32768
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2997
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2998
 *  Historically, however, libpng uses numbers derived from the ITU-R Rec 709
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  2999
 *  end point chromaticities and the D65 white point.  Depending on the
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3000
 *  precision used for the D65 white point this produces a variety of different
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3001
 *  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
  3002
 *  used (0.3127,0.3290) the Y calculation would be:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3003
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3004
 *     Y = (6968 * R + 23435 * G + 2366 * B)/32768
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
 *
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3006
 *  While this is correct the rounding results in an overflow for white, because
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3007
 *  the sum of the rounded coefficients is 32769, not 32768.  Consequently
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3008
 *  libpng uses, instead, the closest non-overflowing approximation:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3009
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3010
 *     Y = (6968 * R + 23434 * G + 2366 * B)/32768
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3011
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3012
 *  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
  3013
 *  (including an sRGB chunk) then the chromaticities are used to calculate the
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3014
 *  coefficients.  See the chunk handling in pngrutil.c for more information.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3015
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3016
 *  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
  3017
 *  gamma information is available to correct the encoding of the original RGB
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3018
 *  values this results in an implicit assumption that the original PNG RGB
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3019
 *  values were linear.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3020
 *
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3021
 *  Other integer coefficients can be used via png_set_rgb_to_gray().  Because
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3022
 *  the API takes just red and green coefficients the blue coefficient is
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3023
 *  calculated to make the sum 32768.  This will result in different rounding
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3024
 *  to that used above.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3026
static int
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3027
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
  3028
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
   int rgb_error = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3031
   png_debug(1, "in png_do_rgb_to_gray");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3032
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3033
   if ((row_info->color_type & PNG_COLOR_MASK_PALETTE) == 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3034
       (row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
   {
57618
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  3036
      png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  3037
      png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  3038
      png_uint_32 bc = 32768 - rc - gc;
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  3039
      png_uint_32 row_width = row_info->width;
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  3040
      int have_alpha = (row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3041
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3042
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3044
#ifdef PNG_READ_GAMMA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3045
         /* Notice that gamma to/from 1 are not necessarily inverses (if
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3046
          * there is an overall gamma correction).  Prior to 1.5.5 this code
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3047
          * checked the linearized values for equality; this doesn't match
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3048
          * the documentation, the original values must be checked.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3049
          */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3050
         if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3052
            png_bytep sp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3053
            png_bytep dp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3054
            png_uint_32 i;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3055
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3056
            for (i = 0; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3058
               png_byte red   = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3059
               png_byte green = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3060
               png_byte blue  = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3061
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3062
               if (red != green || red != blue)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3063
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3064
                  red = png_ptr->gamma_to_1[red];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3065
                  green = png_ptr->gamma_to_1[green];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3066
                  blue = png_ptr->gamma_to_1[blue];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3067
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3068
                  rgb_error |= 1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3069
                  *(dp++) = png_ptr->gamma_from_1[
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3070
                      (rc*red + gc*green + bc*blue + 16384)>>15];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3071
               }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3072
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3073
               else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
               {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3075
                  /* If there is no overall correction the table will not be
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3076
                   * set.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3077
                   */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3078
                  if (png_ptr->gamma_table != NULL)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3079
                     red = png_ptr->gamma_table[red];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3080
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3081
                  *(dp++) = red;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3082
               }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3083
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3084
               if (have_alpha != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3085
                  *(dp++) = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3086
            }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3087
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3088
         else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3089
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3090
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3091
            png_bytep sp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3092
            png_bytep dp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3093
            png_uint_32 i;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3094
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3095
            for (i = 0; i < row_width; i++)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3096
            {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3097
               png_byte red   = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3098
               png_byte green = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3099
               png_byte blue  = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3100
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3101
               if (red != green || red != blue)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3102
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3103
                  rgb_error |= 1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3104
                  /* NOTE: this is the historical approach which simply
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3105
                   * truncates the results.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3106
                   */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3107
                  *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3108
               }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3109
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3110
               else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3111
                  *(dp++) = red;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3112
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3113
               if (have_alpha != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3114
                  *(dp++) = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3115
            }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3116
         }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3117
      }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3118
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3119
      else /* RGB bit_depth == 16 */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3120
      {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3121
#ifdef PNG_READ_GAMMA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3122
         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
  3123
         {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3124
            png_bytep sp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3125
            png_bytep dp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3126
            png_uint_32 i;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3127
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3128
            for (i = 0; i < row_width; i++)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3129
            {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3130
               png_uint_16 red, green, blue, w;
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3131
               png_byte hi,lo;
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3132
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3133
               hi=*(sp)++; lo=*(sp)++; red   = (png_uint_16)((hi << 8) | (lo));
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3134
               hi=*(sp)++; lo=*(sp)++; green = (png_uint_16)((hi << 8) | (lo));
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3135
               hi=*(sp)++; lo=*(sp)++; blue  = (png_uint_16)((hi << 8) | (lo));
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3136
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3137
               if (red == green && red == blue)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3138
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3139
                  if (png_ptr->gamma_16_table != NULL)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3140
                     w = png_ptr->gamma_16_table[(red & 0xff)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3141
                         >> png_ptr->gamma_shift][red >> 8];
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3142
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
                  else
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3144
                     w = red;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
               }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3146
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3147
               else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
               {
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3149
                  png_uint_16 red_1   = png_ptr->gamma_16_to_1[(red & 0xff)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3150
                      >> png_ptr->gamma_shift][red>>8];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3151
                  png_uint_16 green_1 =
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3152
                      png_ptr->gamma_16_to_1[(green & 0xff) >>
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3153
                      png_ptr->gamma_shift][green>>8];
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3154
                  png_uint_16 blue_1  = png_ptr->gamma_16_to_1[(blue & 0xff)
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3155
                      >> png_ptr->gamma_shift][blue>>8];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3156
                  png_uint_16 gray16  = (png_uint_16)((rc*red_1 + gc*green_1
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3157
                      + bc*blue_1 + 16384)>>15);
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3158
                  w = png_ptr->gamma_16_from_1[(gray16 & 0xff) >>
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3159
                      png_ptr->gamma_shift][gray16 >> 8];
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3160
                  rgb_error |= 1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3161
               }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3162
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3163
               *(dp++) = (png_byte)((w>>8) & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3164
               *(dp++) = (png_byte)(w & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3165
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3166
               if (have_alpha != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3167
               {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3168
                  *(dp++) = *(sp++);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3169
                  *(dp++) = *(sp++);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
         }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3173
         else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3174
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
         {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3176
            png_bytep sp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3177
            png_bytep dp = row;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3178
            png_uint_32 i;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3179
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3180
            for (i = 0; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
            {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3182
               png_uint_16 red, green, blue, gray16;
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3183
               png_byte hi,lo;
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3184
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3185
               hi=*(sp)++; lo=*(sp)++; red   = (png_uint_16)((hi << 8) | (lo));
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3186
               hi=*(sp)++; lo=*(sp)++; green = (png_uint_16)((hi << 8) | (lo));
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3187
               hi=*(sp)++; lo=*(sp)++; blue  = (png_uint_16)((hi << 8) | (lo));
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3188
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3189
               if (red != green || red != blue)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3190
                  rgb_error |= 1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3191
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3192
               /* 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
  3193
                * in the 'fast' case - this is because this is where the code
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  3194
                * ends up when handling linear 16-bit data.
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3195
                */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3196
               gray16  = (png_uint_16)((rc*red + gc*green + bc*blue + 16384) >>
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3197
                  15);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3198
               *(dp++) = (png_byte)((gray16 >> 8) & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3199
               *(dp++) = (png_byte)(gray16 & 0xff);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3200
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3201
               if (have_alpha != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
                  *(dp++) = *(sp++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
                  *(dp++) = *(sp++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
      }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3209
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3210
      row_info->channels = (png_byte)(row_info->channels - 2);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3211
      row_info->color_type = (png_byte)(row_info->color_type &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3212
          ~PNG_COLOR_MASK_COLOR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
      row_info->pixel_depth = (png_byte)(row_info->channels *
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3214
          row_info->bit_depth);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3215
      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
   return rgb_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
#endif
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3220
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3221
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3222
   defined(PNG_READ_ALPHA_MODE_SUPPORTED)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
/* Replace any alpha or transparency with the supplied background color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
 * "background" is already in the screen gamma, while "background_1" is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
 * at a gamma of 1.0.  Paletted files have already been taken care of.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3227
static void
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3228
png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3230
#ifdef PNG_READ_GAMMA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3231
   png_const_bytep gamma_table = png_ptr->gamma_table;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3232
   png_const_bytep gamma_from_1 = png_ptr->gamma_from_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3233
   png_const_bytep gamma_to_1 = png_ptr->gamma_to_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3234
   png_const_uint_16pp gamma_16 = png_ptr->gamma_16_table;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3235
   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
  3236
   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
  3237
   int gamma_shift = png_ptr->gamma_shift;
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3238
   int optimize = (png_ptr->flags & PNG_FLAG_OPTIMIZE_ALPHA) != 0;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3239
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3240
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3241
   png_bytep sp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
   png_uint_32 i;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3243
   png_uint_32 row_width = row_info->width;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
   int shift;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3246
   png_debug(1, "in png_do_compose");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3247
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3248
   switch (row_info->color_type)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
   {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3250
      case PNG_COLOR_TYPE_GRAY:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
      {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3252
         switch (row_info->bit_depth)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
         {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3254
            case 1:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
            {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3256
               sp = row;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3257
               shift = 7;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3258
               for (i = 0; i < row_width; i++)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3259
               {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3260
                  if ((png_uint_16)((*sp >> shift) & 0x01)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3261
                     == png_ptr->trans_color.gray)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3262
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3263
                     unsigned int tmp = *sp & (0x7f7f >> (7 - shift));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3264
                     tmp |=
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3265
                         (unsigned int)(png_ptr->background.gray << shift);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3266
                     *sp = (png_byte)(tmp & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3267
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3268
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3269
                  if (shift == 0)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3270
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3271
                     shift = 7;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3272
                     sp++;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3273
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3274
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3275
                  else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3276
                     shift--;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3277
               }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3278
               break;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3279
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3280
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3281
            case 2:
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3282
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3283
#ifdef PNG_READ_GAMMA_SUPPORTED
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3284
               if (gamma_table != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
                  sp = row;
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3287
                  shift = 6;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
                  for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
                  {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3290
                     if ((png_uint_16)((*sp >> shift) & 0x03)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3291
                         == png_ptr->trans_color.gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
                     {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3293
                        unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  3294
                        tmp |=
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3295
                           (unsigned int)png_ptr->background.gray << shift;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3296
                        *sp = (png_byte)(tmp & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3297
                     }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3298
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3299
                     else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3300
                     {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3301
                        unsigned int p = (*sp >> shift) & 0x03;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3302
                        unsigned int g = (gamma_table [p | (p << 2) |
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3303
                            (p << 4) | (p << 6)] >> 6) & 0x03;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3304
                        unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3305
                        tmp |= (unsigned int)(g << shift);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3306
                        *sp = (png_byte)(tmp & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3308
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3309
                     if (shift == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
                     {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3311
                        shift = 6;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
                        sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
                     }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3314
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
                     else
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3316
                        shift -= 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3319
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3320
               else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3321
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3322
               {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3323
                  sp = row;
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3324
                  shift = 6;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3325
                  for (i = 0; i < row_width; i++)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3326
                  {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3327
                     if ((png_uint_16)((*sp >> shift) & 0x03)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3328
                         == png_ptr->trans_color.gray)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3329
                     {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3330
                        unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3331
                        tmp |=
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3332
                            (unsigned int)png_ptr->background.gray << shift;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3333
                        *sp = (png_byte)(tmp & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3334
                     }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3335
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3336
                     if (shift == 0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3337
                     {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3338
                        shift = 6;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3339
                        sp++;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3340
                     }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3341
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3342
                     else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3343
                        shift -= 2;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3344
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3345
               }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3346
               break;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3347
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3348
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3349
            case 4:
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3350
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3351
#ifdef PNG_READ_GAMMA_SUPPORTED
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3352
               if (gamma_table != NULL)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3353
               {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3354
                  sp = row;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3355
                  shift = 4;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3356
                  for (i = 0; i < row_width; i++)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3357
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3358
                     if ((png_uint_16)((*sp >> shift) & 0x0f)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3359
                         == png_ptr->trans_color.gray)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3360
                     {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3361
                        unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3362
                        tmp |=
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3363
                           (unsigned int)(png_ptr->background.gray << shift);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3364
                        *sp = (png_byte)(tmp & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3365
                     }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3366
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3367
                     else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3368
                     {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3369
                        unsigned int p = (*sp >> shift) & 0x0f;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3370
                        unsigned int g = (gamma_table[p | (p << 4)] >> 4) &
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3371
                           0x0f;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3372
                        unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3373
                        tmp |= (unsigned int)(g << shift);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3374
                        *sp = (png_byte)(tmp & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3375
                     }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3376
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3377
                     if (shift == 0)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3378
                     {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3379
                        shift = 4;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3380
                        sp++;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3381
                     }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3382
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3383
                     else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3384
                        shift -= 4;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3385
                  }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3386
               }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3387
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3388
               else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3389
#endif
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3390
               {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3391
                  sp = row;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3392
                  shift = 4;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3393
                  for (i = 0; i < row_width; i++)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3394
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3395
                     if ((png_uint_16)((*sp >> shift) & 0x0f)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3396
                         == png_ptr->trans_color.gray)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3397
                     {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3398
                        unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3399
                        tmp |=
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3400
                           (unsigned int)(png_ptr->background.gray << shift);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3401
                        *sp = (png_byte)(tmp & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3402
                     }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3403
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3404
                     if (shift == 0)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3405
                     {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3406
                        shift = 4;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3407
                        sp++;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3408
                     }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3409
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3410
                     else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3411
                        shift -= 4;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3412
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3413
               }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3414
               break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3415
            }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3416
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3417
            case 8:
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3418
            {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3419
#ifdef PNG_READ_GAMMA_SUPPORTED
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3420
               if (gamma_table != NULL)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3421
               {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3422
                  sp = row;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3423
                  for (i = 0; i < row_width; i++, sp++)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3424
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3425
                     if (*sp == png_ptr->trans_color.gray)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3426
                        *sp = (png_byte)png_ptr->background.gray;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3427
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3428
                     else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3429
                        *sp = gamma_table[*sp];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3430
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3431
               }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3432
               else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3433
#endif
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3434
               {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3435
                  sp = row;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3436
                  for (i = 0; i < row_width; i++, sp++)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3437
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3438
                     if (*sp == png_ptr->trans_color.gray)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3439
                        *sp = (png_byte)png_ptr->background.gray;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3440
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3441
               }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3442
               break;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3443
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3444
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3445
            case 16:
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3446
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3447
#ifdef PNG_READ_GAMMA_SUPPORTED
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3448
               if (gamma_16 != NULL)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3449
               {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3450
                  sp = row;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3451
                  for (i = 0; i < row_width; i++, sp += 2)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3452
                  {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3453
                     png_uint_16 v;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3454
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3455
                     v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3456
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3457
                     if (v == png_ptr->trans_color.gray)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3458
                     {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3459
                        /* Background is already in screen gamma */
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3460
                        *sp = (png_byte)((png_ptr->background.gray >> 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3461
                             & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3462
                        *(sp + 1) = (png_byte)(png_ptr->background.gray
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3463
                             & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3464
                     }
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
                     else
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3467
                     {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3468
                        v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3469
                        *sp = (png_byte)((v >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3470
                        *(sp + 1) = (png_byte)(v & 0xff);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3471
                     }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3472
                  }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3473
               }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
                  sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3478
                  for (i = 0; i < row_width; i++, sp += 2)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
                  {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3480
                     png_uint_16 v;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3481
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3482
                     v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3483
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3484
                     if (v == png_ptr->trans_color.gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
                     {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3486
                        *sp = (png_byte)((png_ptr->background.gray >> 8)
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3487
                             & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3488
                        *(sp + 1) = (png_byte)(png_ptr->background.gray
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3489
                             & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
               }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3493
               break;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3494
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3495
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3496
            default:
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3497
               break;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3498
         }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3499
         break;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3500
      }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3501
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3502
      case PNG_COLOR_TYPE_RGB:
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3503
      {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3504
         if (row_info->bit_depth == 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3505
         {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3506
#ifdef PNG_READ_GAMMA_SUPPORTED
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3507
            if (gamma_table != NULL)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3508
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3509
               sp = row;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3510
               for (i = 0; i < row_width; i++, sp += 3)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3511
               {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3512
                  if (*sp == png_ptr->trans_color.red &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3513
                      *(sp + 1) == png_ptr->trans_color.green &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3514
                      *(sp + 2) == png_ptr->trans_color.blue)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3515
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3516
                     *sp = (png_byte)png_ptr->background.red;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3517
                     *(sp + 1) = (png_byte)png_ptr->background.green;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3518
                     *(sp + 2) = (png_byte)png_ptr->background.blue;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3519
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3520
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3521
                  else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3522
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3523
                     *sp = gamma_table[*sp];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3524
                     *(sp + 1) = gamma_table[*(sp + 1)];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3525
                     *(sp + 2) = gamma_table[*(sp + 2)];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3526
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3527
               }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3528
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3529
            else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
#endif
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3531
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3532
               sp = row;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3533
               for (i = 0; i < row_width; i++, sp += 3)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
               {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3535
                  if (*sp == png_ptr->trans_color.red &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3536
                      *(sp + 1) == png_ptr->trans_color.green &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3537
                      *(sp + 2) == png_ptr->trans_color.blue)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3538
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3539
                     *sp = (png_byte)png_ptr->background.red;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3540
                     *(sp + 1) = (png_byte)png_ptr->background.green;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3541
                     *(sp + 2) = (png_byte)png_ptr->background.blue;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3542
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3543
               }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3544
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3545
         }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3546
         else /* if (row_info->bit_depth == 16) */
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3547
         {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3548
#ifdef PNG_READ_GAMMA_SUPPORTED
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3549
            if (gamma_16 != NULL)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3550
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3551
               sp = row;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3552
               for (i = 0; i < row_width; i++, sp += 6)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3553
               {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3554
                  png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3555
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3556
                  png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3557
                      + *(sp + 3));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3558
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3559
                  png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3560
                      + *(sp + 5));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3561
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3562
                  if (r == png_ptr->trans_color.red &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3563
                      g == png_ptr->trans_color.green &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3564
                      b == png_ptr->trans_color.blue)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3565
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3566
                     /* Background is already in screen gamma */
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3567
                     *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3568
                     *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3569
                     *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3570
                             & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3571
                     *(sp + 3) = (png_byte)(png_ptr->background.green
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3572
                             & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3573
                     *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3574
                             & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3575
                     *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3576
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3577
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3578
                  else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
                  {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3580
                     png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3581
                     *sp = (png_byte)((v >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3582
                     *(sp + 1) = (png_byte)(v & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3583
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3584
                     v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3585
                     *(sp + 2) = (png_byte)((v >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3586
                     *(sp + 3) = (png_byte)(v & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3587
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3588
                     v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3589
                     *(sp + 4) = (png_byte)((v >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3590
                     *(sp + 5) = (png_byte)(v & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3591
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3592
               }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3593
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3594
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3595
            else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3596
#endif
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3597
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3598
               sp = row;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3599
               for (i = 0; i < row_width; i++, sp += 6)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3600
               {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3601
                  png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3602
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3603
                  png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3604
                      + *(sp + 3));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3605
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3606
                  png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3607
                      + *(sp + 5));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3608
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3609
                  if (r == png_ptr->trans_color.red &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3610
                      g == png_ptr->trans_color.green &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3611
                      b == png_ptr->trans_color.blue)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3612
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3613
                     *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3614
                     *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3615
                     *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3616
                             & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3617
                     *(sp + 3) = (png_byte)(png_ptr->background.green
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3618
                             & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3619
                     *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3620
                             & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3621
                     *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3622
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3623
               }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3624
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3625
         }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3626
         break;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3627
      }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3628
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3629
      case PNG_COLOR_TYPE_GRAY_ALPHA:
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3630
      {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3631
         if (row_info->bit_depth == 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3632
         {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3633
#ifdef PNG_READ_GAMMA_SUPPORTED
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3634
            if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3635
                gamma_table != NULL)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3636
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3637
               sp = row;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3638
               for (i = 0; i < row_width; i++, sp += 2)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3639
               {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3640
                  png_uint_16 a = *(sp + 1);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3641
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3642
                  if (a == 0xff)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3643
                     *sp = gamma_table[*sp];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3644
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3645
                  else if (a == 0)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3646
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3647
                     /* Background is already in screen gamma */
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3648
                     *sp = (png_byte)png_ptr->background.gray;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3649
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3650
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3651
                  else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3652
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3653
                     png_byte v, w;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3654
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3655
                     v = gamma_to_1[*sp];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3656
                     png_composite(w, v, a, png_ptr->background_1.gray);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3657
                     if (optimize == 0)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3658
                        w = gamma_from_1[w];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3659
                     *sp = w;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3660
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3661
               }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3662
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3663
            else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3664
#endif
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3665
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3666
               sp = row;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3667
               for (i = 0; i < row_width; i++, sp += 2)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3668
               {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3669
                  png_byte a = *(sp + 1);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3670
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3671
                  if (a == 0)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3672
                     *sp = (png_byte)png_ptr->background.gray;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3673
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3674
                  else if (a < 0xff)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3675
                     png_composite(*sp, *sp, a, png_ptr->background.gray);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3676
               }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3677
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3678
         }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3679
         else /* if (png_ptr->bit_depth == 16) */
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3680
         {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3681
#ifdef PNG_READ_GAMMA_SUPPORTED
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3682
            if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3683
                gamma_16_to_1 != NULL)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3684
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3685
               sp = row;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3686
               for (i = 0; i < row_width; i++, sp += 4)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3687
               {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3688
                  png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3689
                      + *(sp + 3));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3690
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3691
                  if (a == (png_uint_16)0xffff)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3692
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3693
                     png_uint_16 v;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3694
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3695
                     v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3696
                     *sp = (png_byte)((v >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3697
                     *(sp + 1) = (png_byte)(v & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3698
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3699
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3700
                  else if (a == 0)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3701
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3702
                     /* Background is already in screen gamma */
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3703
                     *sp = (png_byte)((png_ptr->background.gray >> 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3704
                             & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3705
                     *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3706
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3707
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3708
                  else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3709
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3710
                     png_uint_16 g, v, w;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3711
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3712
                     g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3713
                     png_composite_16(v, g, a, png_ptr->background_1.gray);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3714
                     if (optimize != 0)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3715
                        w = v;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3716
                     else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3717
                        w = gamma_16_from_1[(v & 0xff) >>
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3718
                            gamma_shift][v >> 8];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3719
                     *sp = (png_byte)((w >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3720
                     *(sp + 1) = (png_byte)(w & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3722
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
            }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3724
            else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3725
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
            {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3727
               sp = row;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3728
               for (i = 0; i < row_width; i++, sp += 4)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3729
               {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3730
                  png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3731
                      + *(sp + 3));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3732
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3733
                  if (a == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3734
                  {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3735
                     *sp = (png_byte)((png_ptr->background.gray >> 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3736
                             & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3737
                     *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3738
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3739
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3740
                  else if (a < 0xffff)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3741
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3742
                     png_uint_16 g, v;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3743
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3744
                     g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3745
                     png_composite_16(v, g, a, png_ptr->background.gray);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3746
                     *sp = (png_byte)((v >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3747
                     *(sp + 1) = (png_byte)(v & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3749
               }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3750
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3751
         }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3752
         break;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3753
      }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3754
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3755
      case PNG_COLOR_TYPE_RGB_ALPHA:
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3756
      {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3757
         if (row_info->bit_depth == 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3758
         {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3759
#ifdef PNG_READ_GAMMA_SUPPORTED
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3760
            if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3761
                gamma_table != NULL)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3762
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3763
               sp = row;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3764
               for (i = 0; i < row_width; i++, sp += 4)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3765
               {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3766
                  png_byte a = *(sp + 3);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3767
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3768
                  if (a == 0xff)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3769
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3770
                     *sp = gamma_table[*sp];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3771
                     *(sp + 1) = gamma_table[*(sp + 1)];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3772
                     *(sp + 2) = gamma_table[*(sp + 2)];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3773
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3774
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3775
                  else if (a == 0)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3776
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3777
                     /* Background is already in screen gamma */
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3778
                     *sp = (png_byte)png_ptr->background.red;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3779
                     *(sp + 1) = (png_byte)png_ptr->background.green;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3780
                     *(sp + 2) = (png_byte)png_ptr->background.blue;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3781
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3782
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3783
                  else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
                  {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3785
                     png_byte v, w;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3786
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3787
                     v = gamma_to_1[*sp];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3788
                     png_composite(w, v, a, png_ptr->background_1.red);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3789
                     if (optimize == 0) w = gamma_from_1[w];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3790
                     *sp = w;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3791
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3792
                     v = gamma_to_1[*(sp + 1)];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3793
                     png_composite(w, v, a, png_ptr->background_1.green);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3794
                     if (optimize == 0) w = gamma_from_1[w];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3795
                     *(sp + 1) = w;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3796
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3797
                     v = gamma_to_1[*(sp + 2)];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3798
                     png_composite(w, v, a, png_ptr->background_1.blue);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3799
                     if (optimize == 0) w = gamma_from_1[w];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3800
                     *(sp + 2) = w;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3801
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3802
               }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3803
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3804
            else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3805
#endif
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3806
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3807
               sp = row;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3808
               for (i = 0; i < row_width; i++, sp += 4)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3809
               {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3810
                  png_byte a = *(sp + 3);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3811
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3812
                  if (a == 0)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3813
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3814
                     *sp = (png_byte)png_ptr->background.red;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3815
                     *(sp + 1) = (png_byte)png_ptr->background.green;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3816
                     *(sp + 2) = (png_byte)png_ptr->background.blue;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3817
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3818
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3819
                  else if (a < 0xff)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3820
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3821
                     png_composite(*sp, *sp, a, png_ptr->background.red);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3822
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3823
                     png_composite(*(sp + 1), *(sp + 1), a,
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3824
                         png_ptr->background.green);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3825
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3826
                     png_composite(*(sp + 2), *(sp + 2), a,
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3827
                         png_ptr->background.blue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
         }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3832
         else /* if (row_info->bit_depth == 16) */
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3833
         {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3834
#ifdef PNG_READ_GAMMA_SUPPORTED
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3835
            if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3836
                gamma_16_to_1 != NULL)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3837
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3838
               sp = row;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3839
               for (i = 0; i < row_width; i++, sp += 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3840
               {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3841
                  png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3842
                      << 8) + (png_uint_16)(*(sp + 7)));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3843
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3844
                  if (a == (png_uint_16)0xffff)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3845
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3846
                     png_uint_16 v;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3847
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3848
                     v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3849
                     *sp = (png_byte)((v >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3850
                     *(sp + 1) = (png_byte)(v & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3851
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3852
                     v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3853
                     *(sp + 2) = (png_byte)((v >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3854
                     *(sp + 3) = (png_byte)(v & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3855
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3856
                     v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3857
                     *(sp + 4) = (png_byte)((v >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3858
                     *(sp + 5) = (png_byte)(v & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3859
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3860
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3861
                  else if (a == 0)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3862
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3863
                     /* Background is already in screen gamma */
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3864
                     *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3865
                     *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3866
                     *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3867
                             & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3868
                     *(sp + 3) = (png_byte)(png_ptr->background.green
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3869
                             & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3870
                     *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3871
                             & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3872
                     *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3873
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3874
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3875
                  else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3876
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3877
                     png_uint_16 v, w;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3878
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3879
                     v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3880
                     png_composite_16(w, v, a, png_ptr->background_1.red);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3881
                     if (optimize == 0)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3882
                        w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3883
                             8];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3884
                     *sp = (png_byte)((w >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3885
                     *(sp + 1) = (png_byte)(w & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3886
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3887
                     v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3888
                     png_composite_16(w, v, a, png_ptr->background_1.green);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3889
                     if (optimize == 0)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3890
                        w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3891
                             8];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3892
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3893
                     *(sp + 2) = (png_byte)((w >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3894
                     *(sp + 3) = (png_byte)(w & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3895
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3896
                     v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3897
                     png_composite_16(w, v, a, png_ptr->background_1.blue);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3898
                     if (optimize == 0)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3899
                        w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3900
                             8];
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3901
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3902
                     *(sp + 4) = (png_byte)((w >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3903
                     *(sp + 5) = (png_byte)(w & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3904
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3905
               }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3906
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3907
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3908
            else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3909
#endif
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3910
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3911
               sp = row;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3912
               for (i = 0; i < row_width; i++, sp += 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3913
               {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3914
                  png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3915
                      << 8) + (png_uint_16)(*(sp + 7)));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3916
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3917
                  if (a == 0)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3918
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3919
                     *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3920
                     *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3921
                     *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3922
                             & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3923
                     *(sp + 3) = (png_byte)(png_ptr->background.green
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3924
                             & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3925
                     *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3926
                             & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3927
                     *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3928
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3929
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3930
                  else if (a < 0xffff)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3931
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3932
                     png_uint_16 v;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3933
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3934
                     png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3935
                     png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3936
                         + *(sp + 3));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3937
                     png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3938
                         + *(sp + 5));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3939
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3940
                     png_composite_16(v, r, a, png_ptr->background.red);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3941
                     *sp = (png_byte)((v >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3942
                     *(sp + 1) = (png_byte)(v & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3943
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3944
                     png_composite_16(v, g, a, png_ptr->background.green);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3945
                     *(sp + 2) = (png_byte)((v >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3946
                     *(sp + 3) = (png_byte)(v & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3947
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3948
                     png_composite_16(v, b, a, png_ptr->background.blue);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3949
                     *(sp + 4) = (png_byte)((v >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3950
                     *(sp + 5) = (png_byte)(v & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3951
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3952
               }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3953
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3954
         }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3955
         break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3956
      }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3957
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3958
      default:
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  3959
         break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3960
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3961
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3962
#endif /* READ_BACKGROUND || READ_ALPHA_MODE */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3963
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3964
#ifdef PNG_READ_GAMMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3965
/* Gamma correct the image, avoiding the alpha channel.  Make sure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3966
 * you do this after you deal with the transparency issue on grayscale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3967
 * or RGB images. If your bit depth is 8, use gamma_table, if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3968
 * is 16, use gamma_16_table and gamma_shift.  Build these with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3969
 * build_gamma_table().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3970
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3971
static void
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  3972
png_do_gamma(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3974
   png_const_bytep gamma_table = png_ptr->gamma_table;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3975
   png_const_uint_16pp gamma_16_table = png_ptr->gamma_16_table;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3976
   int gamma_shift = png_ptr->gamma_shift;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3977
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
   png_bytep sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
   png_uint_32 row_width=row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3982
   png_debug(1, "in png_do_gamma");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3983
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3984
   if (((row_info->bit_depth <= 8 && gamma_table != NULL) ||
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  3985
       (row_info->bit_depth == 16 && gamma_16_table != NULL)))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
      switch (row_info->color_type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
         case PNG_COLOR_TYPE_RGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3990
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
            if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3999
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4000
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4002
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4003
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4004
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4005
            else /* if (row_info->bit_depth == 16) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4006
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4007
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4008
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4009
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4010
                  png_uint_16 v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4012
                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4013
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4014
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4015
                  sp += 2;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4016
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4017
                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4018
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4019
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4020
                  sp += 2;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4021
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4022
                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4023
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4024
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4025
                  sp += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4026
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4027
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4028
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4029
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4030
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4031
         case PNG_COLOR_TYPE_RGB_ALPHA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4032
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4033
            if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4034
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4035
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4036
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4037
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4038
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4039
                  sp++;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4040
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4041
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4042
                  sp++;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4043
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4044
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4045
                  sp++;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4046
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4047
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4048
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4049
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4050
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4051
            else /* if (row_info->bit_depth == 16) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4052
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4053
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4054
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4055
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4056
                  png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4057
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4058
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4059
                  sp += 2;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4060
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4061
                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4062
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4063
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4064
                  sp += 2;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4065
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4066
                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4067
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4068
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4069
                  sp += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4070
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4071
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4072
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4073
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4074
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4075
         case PNG_COLOR_TYPE_GRAY_ALPHA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4076
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4077
            if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4078
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4079
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4080
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4081
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4082
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4083
                  sp += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4084
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4085
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4086
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4087
            else /* if (row_info->bit_depth == 16) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4088
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4089
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4090
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4091
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4092
                  png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4093
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4094
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4095
                  sp += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4096
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4097
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4098
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4099
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4100
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4101
         case PNG_COLOR_TYPE_GRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4102
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4103
            if (row_info->bit_depth == 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4104
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4105
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4106
               for (i = 0; i < row_width; i += 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4107
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4108
                  int a = *sp & 0xc0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4109
                  int b = *sp & 0x30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4110
                  int c = *sp & 0x0c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4111
                  int d = *sp & 0x03;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4113
                  *sp = (png_byte)(
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4114
                      ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)])   ) & 0xc0)|
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4115
                      ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4116
                      ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4117
                      ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4118
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4119
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4120
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4121
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4122
            if (row_info->bit_depth == 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4123
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4124
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4125
               for (i = 0; i < row_width; i += 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4126
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4127
                  int msb = *sp & 0xf0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4128
                  int lsb = *sp & 0x0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4130
                  *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4131
                      | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4132
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4133
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4134
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4135
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4136
            else if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4137
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4138
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4139
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4140
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4141
                  *sp = gamma_table[*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4142
                  sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4143
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4144
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4145
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4146
            else if (row_info->bit_depth == 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4147
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4148
               sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4149
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4150
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4151
                  png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4152
                  *sp = (png_byte)((v >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4153
                  *(sp + 1) = (png_byte)(v & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4154
                  sp += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4155
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4157
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4158
         }
10576
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
         default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4161
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4162
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4163
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4164
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4165
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4166
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4167
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4168
/* 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
  4169
 * 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
  4170
 * from_1 tables.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4171
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4172
static void
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4173
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
  4174
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4175
   png_uint_32 row_width = row_info->width;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4176
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4177
   png_debug(1, "in png_do_encode_alpha");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4178
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4179
   if ((row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0)
10576
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
      if (row_info->bit_depth == 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4182
      {
57618
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4183
         png_bytep table = png_ptr->gamma_from_1;
10576
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
         if (table != NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4186
         {
57618
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4187
            int step = (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 4 : 2;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4188
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4189
            /* The alpha channel is the last component: */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4190
            row += step - 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4191
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4192
            for (; row_width > 0; --row_width, row += step)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4193
               *row = table[*row];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4194
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4195
            return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4196
         }
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
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4199
      else if (row_info->bit_depth == 16)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4200
      {
57618
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4201
         png_uint_16pp table = png_ptr->gamma_16_from_1;
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4202
         int gamma_shift = png_ptr->gamma_shift;
10576
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
         if (table != NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4205
         {
57618
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4206
            int step = (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 8 : 4;
10576
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
            /* The alpha channel is the last component: */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4209
            row += step - 2;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4210
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4211
            for (; row_width > 0; --row_width, row += step)
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_uint_16 v;
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
               v = table[*(row + 1) >> gamma_shift][*row];
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4216
               *row = (png_byte)((v >> 8) & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4217
               *(row + 1) = (png_byte)(v & 0xff);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4218
            }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4219
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4220
            return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4221
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4222
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4223
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4224
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4225
   /* 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
  4226
    * so just issue a warning.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4227
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4228
   png_warning(png_ptr, "png_do_encode_alpha: unexpected call");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4229
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4230
#endif
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
#ifdef PNG_READ_EXPAND_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4233
/* Expands a palette row to an RGB or RGBA row depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4234
 * upon whether you supply trans and num_trans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4235
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4236
static void
57618
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4237
png_do_expand_palette(png_structrp png_ptr, png_row_infop row_info,
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4238
    png_bytep row, png_const_colorp palette, png_const_bytep trans_alpha,
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4239
    int num_trans)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4240
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4241
   int shift, value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4242
   png_bytep sp, dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4243
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4244
   png_uint_32 row_width=row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4245
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4246
   png_debug(1, "in png_do_expand_palette");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4247
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4248
   if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4249
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4250
      if (row_info->bit_depth < 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4251
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4252
         switch (row_info->bit_depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4253
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4254
            case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4255
            {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4256
               sp = row + (size_t)((row_width - 1) >> 3);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4257
               dp = row + (size_t)row_width - 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4258
               shift = 7 - (int)((row_width + 7) & 0x07);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4259
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4260
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4261
                  if ((*sp >> shift) & 0x01)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4262
                     *dp = 1;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4263
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4264
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4265
                     *dp = 0;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4266
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4267
                  if (shift == 7)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4268
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4269
                     shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4270
                     sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4271
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4272
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4273
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4274
                     shift++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4276
                  dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4277
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4278
               break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4279
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4280
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4281
            case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4282
            {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4283
               sp = row + (size_t)((row_width - 1) >> 2);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4284
               dp = row + (size_t)row_width - 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4285
               shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4286
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4287
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4288
                  value = (*sp >> shift) & 0x03;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
                  *dp = (png_byte)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4290
                  if (shift == 6)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4291
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4292
                     shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4293
                     sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4294
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4295
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4296
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4297
                     shift += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4299
                  dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4301
               break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4302
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4303
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4304
            case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4305
            {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4306
               sp = row + (size_t)((row_width - 1) >> 1);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4307
               dp = row + (size_t)row_width - 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
               shift = (int)((row_width & 0x01) << 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4309
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4310
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4311
                  value = (*sp >> shift) & 0x0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4312
                  *dp = (png_byte)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4313
                  if (shift == 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4314
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4315
                     shift = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4316
                     sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4317
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4318
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4319
                  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4320
                     shift += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4322
                  dp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4323
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4324
               break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4325
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4326
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4327
            default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4328
               break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4329
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4330
         row_info->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4331
         row_info->pixel_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4332
         row_info->rowbytes = row_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4333
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4334
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4335
      if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4336
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4337
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4338
            if (num_trans > 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4339
            {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4340
               sp = row + (size_t)row_width - 1;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4341
               dp = row + ((size_t)row_width << 2) - 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4342
57618
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4343
               i = 0;
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4344
#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4345
               if (png_ptr->riffled_palette != NULL)
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4346
               {
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4347
                  /* The RGBA optimization works with png_ptr->bit_depth == 8
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4348
                   * but sometimes row_info->bit_depth has been changed to 8.
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4349
                   * In these cases, the palette hasn't been riffled.
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4350
                   */
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4351
                  i = png_do_expand_palette_rgba8_neon(png_ptr, row_info, row,
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4352
                      &sp, &dp);
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4353
               }
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4354
#else
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4355
               PNG_UNUSED(png_ptr)
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4356
#endif
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4357
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4358
               for (; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4359
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
                  if ((int)(*sp) >= num_trans)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4361
                     *dp-- = 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4362
                  else
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4363
                     *dp-- = trans_alpha[*sp];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4364
                  *dp-- = palette[*sp].blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4365
                  *dp-- = palette[*sp].green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4366
                  *dp-- = palette[*sp].red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
                  sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4368
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4369
               row_info->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4370
               row_info->pixel_depth = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4371
               row_info->rowbytes = row_width * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
               row_info->color_type = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
               row_info->channels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4374
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4375
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4376
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4377
            {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4378
               sp = row + (size_t)row_width - 1;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4379
               dp = row + (size_t)(row_width * 3) - 1;
57618
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4380
               i = 0;
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4381
#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4382
               i = png_do_expand_palette_rgb8_neon(png_ptr, row_info, row,
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4383
                   &sp, &dp);
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4384
#else
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4385
               PNG_UNUSED(png_ptr)
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4386
#endif
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4387
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4388
               for (; i < row_width; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4389
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4390
                  *dp-- = palette[*sp].blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4391
                  *dp-- = palette[*sp].green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4392
                  *dp-- = palette[*sp].red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4393
                  sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4394
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4395
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4396
               row_info->bit_depth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4397
               row_info->pixel_depth = 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4398
               row_info->rowbytes = row_width * 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4399
               row_info->color_type = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4400
               row_info->channels = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4401
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4402
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4403
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4404
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4405
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4407
/* If the bit depth < 8, it is expanded to 8.  Also, if the already
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4408
 * expanded transparency value is supplied, an alpha channel is built.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4409
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4410
static void
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4411
png_do_expand(png_row_infop row_info, png_bytep row,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4412
    png_const_color_16p trans_color)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4413
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4414
   int shift, value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4415
   png_bytep sp, dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4416
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4417
   png_uint_32 row_width=row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4418
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4419
   png_debug(1, "in png_do_expand");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4420
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4421
   if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4422
   {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4423
      unsigned int gray = trans_color != NULL ? trans_color->gray : 0;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4424
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4425
      if (row_info->bit_depth < 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4426
      {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4427
         switch (row_info->bit_depth)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4428
         {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4429
            case 1:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4430
            {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4431
               gray = (gray & 0x01) * 0xff;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4432
               sp = row + (size_t)((row_width - 1) >> 3);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4433
               dp = row + (size_t)row_width - 1;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4434
               shift = 7 - (int)((row_width + 7) & 0x07);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4435
               for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4436
               {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4437
                  if ((*sp >> shift) & 0x01)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4438
                     *dp = 0xff;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4439
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4440
                  else
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4441
                     *dp = 0;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4442
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4443
                  if (shift == 7)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4444
                  {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4445
                     shift = 0;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4446
                     sp--;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4447
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4448
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4449
                  else
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4450
                     shift++;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4451
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4452
                  dp--;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4453
               }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4454
               break;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4455
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4456
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4457
            case 2:
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4458
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4459
               gray = (gray & 0x03) * 0x55;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4460
               sp = row + (size_t)((row_width - 1) >> 2);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4461
               dp = row + (size_t)row_width - 1;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4462
               shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4463
               for (i = 0; i < row_width; i++)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4464
               {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4465
                  value = (*sp >> shift) & 0x03;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4466
                  *dp = (png_byte)(value | (value << 2) | (value << 4) |
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4467
                     (value << 6));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4468
                  if (shift == 6)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4469
                  {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4470
                     shift = 0;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4471
                     sp--;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4472
                  }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4473
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4474
                  else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4475
                     shift += 2;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4476
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4477
                  dp--;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4478
               }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4479
               break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4480
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4481
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4482
            case 4:
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4483
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4484
               gray = (gray & 0x0f) * 0x11;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4485
               sp = row + (size_t)((row_width - 1) >> 1);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4486
               dp = row + (size_t)row_width - 1;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4487
               shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4488
               for (i = 0; i < row_width; i++)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4489
               {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4490
                  value = (*sp >> shift) & 0x0f;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4491
                  *dp = (png_byte)(value | (value << 4));
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4492
                  if (shift == 4)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4493
                  {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4494
                     shift = 0;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4495
                     sp--;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4496
                  }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4497
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4498
                  else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4499
                     shift = 4;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4500
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4501
                  dp--;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4502
               }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4503
               break;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4504
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4505
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4506
            default:
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4507
               break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4508
         }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4509
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4510
         row_info->bit_depth = 8;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4511
         row_info->pixel_depth = 8;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4512
         row_info->rowbytes = row_width;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4513
      }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4514
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4515
      if (trans_color != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4516
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4517
         if (row_info->bit_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4518
         {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4519
            gray = gray & 0xff;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4520
            sp = row + (size_t)row_width - 1;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4521
            dp = row + ((size_t)row_width << 1) - 1;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4522
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4523
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4524
            {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4525
               if ((*sp & 0xffU) == gray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4526
                  *dp-- = 0;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4527
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4528
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4529
                  *dp-- = 0xff;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4530
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4531
               *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4532
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4533
         }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4534
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4535
         else if (row_info->bit_depth == 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4536
         {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4537
            unsigned int gray_high = (gray >> 8) & 0xff;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4538
            unsigned int gray_low = gray & 0xff;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4539
            sp = row + row_info->rowbytes - 1;
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4540
            dp = row + (row_info->rowbytes << 1) - 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4541
            for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4542
            {
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4543
               if ((*(sp - 1) & 0xffU) == gray_high &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4544
                   (*(sp) & 0xffU) == gray_low)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4545
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4546
                  *dp-- = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4547
                  *dp-- = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4548
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4549
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4550
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4551
               {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4552
                  *dp-- = 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4553
                  *dp-- = 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4554
               }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4555
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4556
               *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4557
               *dp-- = *sp--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4558
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4559
         }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4560
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4561
         row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4562
         row_info->channels = 2;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4563
         row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4564
         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4565
             row_width);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4566
      }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4567
   }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4568
   else if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4569
       trans_color != NULL)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4570
   {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4571
      if (row_info->bit_depth == 8)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4572
      {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4573
         png_byte red = (png_byte)(trans_color->red & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4574
         png_byte green = (png_byte)(trans_color->green & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4575
         png_byte blue = (png_byte)(trans_color->blue & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4576
         sp = row + (size_t)row_info->rowbytes - 1;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4577
         dp = row + ((size_t)row_width << 2) - 1;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4578
         for (i = 0; i < row_width; i++)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4579
         {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4580
            if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4581
               *dp-- = 0;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4582
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4583
            else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4584
               *dp-- = 0xff;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4585
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4586
            *dp-- = *sp--;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4587
            *dp-- = *sp--;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4588
            *dp-- = *sp--;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4589
         }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4590
      }
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4591
      else if (row_info->bit_depth == 16)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4592
      {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4593
         png_byte red_high = (png_byte)((trans_color->red >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4594
         png_byte green_high = (png_byte)((trans_color->green >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4595
         png_byte blue_high = (png_byte)((trans_color->blue >> 8) & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4596
         png_byte red_low = (png_byte)(trans_color->red & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4597
         png_byte green_low = (png_byte)(trans_color->green & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4598
         png_byte blue_low = (png_byte)(trans_color->blue & 0xff);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4599
         sp = row + row_info->rowbytes - 1;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4600
         dp = row + ((size_t)row_width << 3) - 1;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4601
         for (i = 0; i < row_width; i++)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4602
         {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4603
            if (*(sp - 5) == red_high &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4604
                *(sp - 4) == red_low &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4605
                *(sp - 3) == green_high &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4606
                *(sp - 2) == green_low &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4607
                *(sp - 1) == blue_high &&
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4608
                *(sp    ) == blue_low)
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4609
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4610
               *dp-- = 0;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4611
               *dp-- = 0;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4612
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4613
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4614
            else
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4615
            {
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4616
               *dp-- = 0xff;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4617
               *dp-- = 0xff;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4618
            }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4619
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4620
            *dp-- = *sp--;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4621
            *dp-- = *sp--;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4622
            *dp-- = *sp--;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4623
            *dp-- = *sp--;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4624
            *dp-- = *sp--;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4625
            *dp-- = *sp--;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4626
         }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4627
      }
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4628
      row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4629
      row_info->channels = 4;
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4630
      row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4631
      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4632
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4633
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4634
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4635
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4636
#ifdef PNG_READ_EXPAND_16_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4637
/* 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
  4638
 * whole row to 16 bits.  Has no effect otherwise.
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4639
 */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4640
static void
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4641
png_do_expand_16(png_row_infop row_info, png_bytep row)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4642
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4643
   if (row_info->bit_depth == 8 &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4644
      row_info->color_type != PNG_COLOR_TYPE_PALETTE)
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4645
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4646
      /* 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
  4647
       * 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
  4648
       * calculate:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4649
       *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4650
       *  (input / 255) * 65535
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4651
       *
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4652
       *  Which happens to be exactly input * 257 and this can be achieved
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4653
       *  simply by byte replication in place (copying backwards).
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4654
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4655
      png_byte *sp = row + row_info->rowbytes; /* source, last byte + 1 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4656
      png_byte *dp = sp + row_info->rowbytes;  /* destination, end + 1 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4657
      while (dp > sp)
48280
791d551bcdb8 8183960: Upgrade to libpng 1.6.34
prr
parents: 47216
diff changeset
  4658
      {
791d551bcdb8 8183960: Upgrade to libpng 1.6.34
prr
parents: 47216
diff changeset
  4659
         dp[-2] = dp[-1] = *--sp; dp -= 2;
791d551bcdb8 8183960: Upgrade to libpng 1.6.34
prr
parents: 47216
diff changeset
  4660
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4661
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4662
      row_info->rowbytes *= 2;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4663
      row_info->bit_depth = 16;
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4664
      row_info->pixel_depth = (png_byte)(row_info->channels * 16);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4665
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4666
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4667
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4668
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4669
#ifdef PNG_READ_QUANTIZE_SUPPORTED
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4670
static void
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4671
png_do_quantize(png_row_infop row_info, png_bytep row,
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4672
    png_const_bytep palette_lookup, png_const_bytep quantize_lookup)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4673
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4674
   png_bytep sp, dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4675
   png_uint_32 i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4676
   png_uint_32 row_width=row_info->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4677
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4678
   png_debug(1, "in png_do_quantize");
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4679
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4680
   if (row_info->bit_depth == 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4681
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4682
      if (row_info->color_type == PNG_COLOR_TYPE_RGB && palette_lookup)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4683
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4684
         int r, g, b, p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4685
         sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4686
         dp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4687
         for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4688
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4689
            r = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4690
            g = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4691
            b = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4692
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4693
            /* This looks real messy, but the compiler will reduce
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4694
             * it down to a reasonable formula.  For example, with
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4695
             * 5 bits per color, we get:
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4696
             * p = (((r >> 3) & 0x1f) << 10) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4697
             *    (((g >> 3) & 0x1f) << 5) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4698
             *    ((b >> 3) & 0x1f);
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4699
             */
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4700
            p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4701
                ((1 << PNG_QUANTIZE_RED_BITS) - 1)) <<
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4702
                (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4703
                (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4704
                ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) <<
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4705
                (PNG_QUANTIZE_BLUE_BITS)) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4706
                ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4707
                ((1 << PNG_QUANTIZE_BLUE_BITS) - 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4708
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4709
            *dp++ = palette_lookup[p];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4710
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4711
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4712
         row_info->color_type = PNG_COLOR_TYPE_PALETTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4713
         row_info->channels = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4714
         row_info->pixel_depth = row_info->bit_depth;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4715
         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4716
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4717
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4718
      else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4719
         palette_lookup != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4720
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4721
         int r, g, b, p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4722
         sp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4723
         dp = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4724
         for (i = 0; i < row_width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4725
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4726
            r = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4727
            g = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4728
            b = *sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4729
            sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4730
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4731
            p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4732
                ((1 << PNG_QUANTIZE_RED_BITS) - 1)) <<
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4733
                (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4734
                (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4735
                ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) <<
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4736
                (PNG_QUANTIZE_BLUE_BITS)) |
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4737
                ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) &
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4738
                ((1 << PNG_QUANTIZE_BLUE_BITS) - 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4739
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4740
            *dp++ = palette_lookup[p];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4741
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4742
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4743
         row_info->color_type = PNG_COLOR_TYPE_PALETTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4744
         row_info->channels = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4745
         row_info->pixel_depth = row_info->bit_depth;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4746
         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4747
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4748
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4749
      else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4750
         quantize_lookup)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4751
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4752
         sp = row;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4753
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4754
         for (i = 0; i < row_width; i++, sp++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4755
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4756
            *sp = quantize_lookup[*sp];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4757
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4758
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4759
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4760
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4761
#endif /* READ_QUANTIZE */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4762
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4763
/* Transform the row.  The order of transformations is significant,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4764
 * and is very touchy.  If you add a transformation, take care to
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4765
 * decide how it fits in with the other transformations here.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4766
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4767
void /* PRIVATE */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4768
png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4769
{
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4770
   png_debug(1, "in png_do_read_transformations");
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->row_buf == NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4773
   {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4774
      /* 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
  4775
       * error is incredibly rare and incredibly easy to debug without this
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4776
       * information.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4777
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4778
      png_error(png_ptr, "NULL row buffer");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4779
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4780
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4781
   /* 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
  4782
    * in 1.5.4 PNG_FLAG_DETECT_UNINITIALIZED was added and the macro
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4783
    * 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
  4784
    * all transformations, however in practice the ROW_INIT always gets done on
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4785
    * demand, if necessary.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4786
    */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4787
   if ((png_ptr->flags & PNG_FLAG_DETECT_UNINITIALIZED) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4788
       (png_ptr->flags & PNG_FLAG_ROW_INIT) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4789
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4790
      /* Application has failed to call either png_read_start_image() or
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4791
       * png_read_update_info() after setting transforms that expand pixels.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4792
       * 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
  4793
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4794
      png_error(png_ptr, "Uninitialized row");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4795
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4796
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4797
#ifdef PNG_READ_EXPAND_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4798
   if ((png_ptr->transformations & PNG_EXPAND) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4799
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4800
      if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4801
      {
57618
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4802
#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4803
         if ((png_ptr->num_trans > 0) && (png_ptr->bit_depth == 8))
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4804
         {
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4805
            if (png_ptr->riffled_palette == NULL)
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4806
            {
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4807
               /* Initialize the accelerated palette expansion. */
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4808
               png_ptr->riffled_palette =
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4809
                   (png_bytep)png_malloc(png_ptr, 256 * 4);
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4810
               png_riffle_palette_neon(png_ptr);
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4811
            }
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4812
         }
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4813
#endif
53154e45385a 8217676: Upgrade libpng to 1.6.37
serb
parents: 51304
diff changeset
  4814
         png_do_expand_palette(png_ptr, row_info, png_ptr->row_buf + 1,
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4815
             png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4816
      }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4817
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4818
      else
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4819
      {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4820
         if (png_ptr->num_trans != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4821
             (png_ptr->transformations & PNG_EXPAND_tRNS) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4822
            png_do_expand(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4823
                &(png_ptr->trans_color));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 6825
diff changeset
  4824
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4825
         else
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  4826
            png_do_expand(row_info, png_ptr->row_buf + 1, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4827
      }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4828
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4829
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4830
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4831
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4832
   if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4833
       (png_ptr->transformations & PNG_COMPOSE) == 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4834
       (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4835
       row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4836
      png_do_strip_channel(row_info, png_ptr->row_buf + 1,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
  4837
          0 /* at_start == false, because SWAP_ALPHA happens later */);
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4838
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4839
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4840
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4841
   if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4842
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4843
      int rgb_error =
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4844
          png_do_rgb_to_gray(png_ptr, row_info,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4845
              png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4846
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4847
      if (rgb_error != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4848
      {
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4849
         png_ptr->rgb_to_gray_status=1;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4850
         if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4851
             PNG_RGB_TO_GRAY_WARN)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4852
            png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4853
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4854
         if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4855
             PNG_RGB_TO_GRAY_ERR)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4856
            png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4857
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4858
   }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4859
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4860
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4861
/* From Andreas Dilger e-mail to png-implement, 26 March 1998:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4862
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4863
 *   In most cases, the "simple transparency" should be done prior to doing
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4864
 *   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
  4865
 *   pixel is transparent.  You would also need to make sure that the
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4866
 *   transparency information is upgraded to RGB.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4867
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4868
 *   To summarize, the current flow is:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4869
 *   - Gray + simple transparency -> compare 1 or 2 gray bytes and composite
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4870
 *                                   with background "in place" if transparent,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4871
 *                                   convert to RGB if necessary
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4872
 *   - Gray + alpha -> composite with gray background and remove alpha bytes,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4873
 *                                   convert to RGB if necessary
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4874
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4875
 *   To support RGB backgrounds for gray images we need:
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4876
 *   - Gray + simple transparency -> convert to RGB + simple transparency,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4877
 *                                   compare 3 or 6 bytes and composite with
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4878
 *                                   background "in place" if transparent
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4879
 *                                   (3x compare/pixel compared to doing
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4880
 *                                   composite with gray bkgrnd)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4881
 *   - Gray + alpha -> convert to RGB + alpha, composite with background and
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4882
 *                                   remove alpha bytes (3x float
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4883
 *                                   operations/pixel compared with composite
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4884
 *                                   on gray background)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4885
 *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4886
 *  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
  4887
 *  performance, as this increases the per-pixel operations.  If we would check
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4888
 *  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
  4889
 *  transform appropriately, then it would save a lot of work/time.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4890
 */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4891
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4892
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4893
   /* 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
  4894
    * for performance reasons
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4895
    */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4896
   if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4897
       (png_ptr->mode & PNG_BACKGROUND_IS_GRAY) == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4898
      png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4899
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4900
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4901
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4902
   defined(PNG_READ_ALPHA_MODE_SUPPORTED)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4903
   if ((png_ptr->transformations & PNG_COMPOSE) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4904
      png_do_compose(row_info, png_ptr->row_buf + 1, png_ptr);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4905
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4906
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4907
#ifdef PNG_READ_GAMMA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4908
   if ((png_ptr->transformations & PNG_GAMMA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4909
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4910
      /* Because RGB_TO_GRAY does the gamma transform. */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4911
      (png_ptr->transformations & PNG_RGB_TO_GRAY) == 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4912
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4913
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4914
   defined(PNG_READ_ALPHA_MODE_SUPPORTED)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4915
      /* Because PNG_COMPOSE does the gamma transform if there is something to
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4916
       * do (if there is an alpha channel or transparency.)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4917
       */
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
  4918
       !((png_ptr->transformations & PNG_COMPOSE) != 0 &&
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4919
       ((png_ptr->num_trans != 0) ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4920
       (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)) &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4921
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4922
      /* Because png_init_read_transformations transforms the palette, unless
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4923
       * RGB_TO_GRAY will do the transform.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4924
       */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4925
       (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4926
      png_do_gamma(row_info, png_ptr->row_buf + 1, png_ptr);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4927
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4928
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4929
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4930
   if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4931
       (png_ptr->transformations & PNG_COMPOSE) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4932
       (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4933
       row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4934
      png_do_strip_channel(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4935
          0 /* at_start == false, because SWAP_ALPHA happens later */);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4936
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4937
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4938
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4939
   if ((png_ptr->transformations & PNG_ENCODE_ALPHA) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4940
       (row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4941
      png_do_encode_alpha(row_info, png_ptr->row_buf + 1, png_ptr);
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_SCALE_16_TO_8_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4945
   if ((png_ptr->transformations & PNG_SCALE_16_TO_8) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4946
      png_do_scale_16_to_8(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_STRIP_16_TO_8_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4950
   /* 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
  4951
    * by putting the 'scale' option first if the app asks for scale (either by
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4952
    * calling the API or in a TRANSFORM flag) this is what happens.
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4953
    */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4954
   if ((png_ptr->transformations & PNG_16_TO_8) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4955
      png_do_chop(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4956
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4957
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4958
#ifdef PNG_READ_QUANTIZE_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4959
   if ((png_ptr->transformations & PNG_QUANTIZE) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4960
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4961
      png_do_quantize(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4962
          png_ptr->palette_lookup, png_ptr->quantize_index);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4963
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4964
      if (row_info->rowbytes == 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4965
         png_error(png_ptr, "png_do_quantize returned rowbytes=0");
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4966
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4967
#endif /* READ_QUANTIZE */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4968
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4969
#ifdef PNG_READ_EXPAND_16_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4970
   /* Do the expansion now, after all the arithmetic has been done.  Notice
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4971
    * that previous transformations can handle the PNG_EXPAND_16 flag if this
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4972
    * is efficient (particularly true in the case of gamma correction, where
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4973
    * better accuracy results faster!)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4974
    */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4975
   if ((png_ptr->transformations & PNG_EXPAND_16) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4976
      png_do_expand_16(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4977
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4978
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4979
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4980
   /* NOTE: moved here in 1.5.4 (from much later in this list.) */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4981
   if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0 &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4982
       (png_ptr->mode & PNG_BACKGROUND_IS_GRAY) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4983
      png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4984
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4985
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4986
#ifdef PNG_READ_INVERT_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4987
   if ((png_ptr->transformations & PNG_INVERT_MONO) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4988
      png_do_invert(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4989
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4990
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4991
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4992
   if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4993
      png_do_read_invert_alpha(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4994
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4995
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4996
#ifdef PNG_READ_SHIFT_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4997
   if ((png_ptr->transformations & PNG_SHIFT) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4998
      png_do_unshift(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  4999
          &(png_ptr->shift));
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5000
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5001
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5002
#ifdef PNG_READ_PACK_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5003
   if ((png_ptr->transformations & PNG_PACK) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5004
      png_do_unpack(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5005
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5006
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5007
#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5008
   /* Added at libpng-1.5.10 */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5009
   if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5010
       png_ptr->num_palette_max >= 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5011
      png_do_check_palette_indexes(png_ptr, row_info);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5012
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5013
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5014
#ifdef PNG_READ_BGR_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5015
   if ((png_ptr->transformations & PNG_BGR) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5016
      png_do_bgr(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5017
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5018
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5019
#ifdef PNG_READ_PACKSWAP_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5020
   if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5021
      png_do_packswap(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5022
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5023
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5024
#ifdef PNG_READ_FILLER_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5025
   if ((png_ptr->transformations & PNG_FILLER) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5026
      png_do_read_filler(row_info, png_ptr->row_buf + 1,
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5027
          (png_uint_32)png_ptr->filler, png_ptr->flags);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5028
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5029
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5030
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5031
   if ((png_ptr->transformations & PNG_SWAP_ALPHA) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5032
      png_do_read_swap_alpha(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5033
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5034
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5035
#ifdef PNG_READ_16BIT_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5036
#ifdef PNG_READ_SWAP_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5037
   if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5038
      png_do_swap(row_info, png_ptr->row_buf + 1);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5039
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5040
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5041
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5042
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5043
   if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5044
   {
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5045
      if (png_ptr->read_user_transform_fn != NULL)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5046
         (*(png_ptr->read_user_transform_fn)) /* User read transform function */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5047
             (png_ptr,     /* png_ptr */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5048
             row_info,     /* row_info: */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5049
                /*  png_uint_32 width;       width of row */
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 48280
diff changeset
  5050
                /*  size_t rowbytes;         number of bytes in row */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5051
                /*  png_byte color_type;     color type of pixels */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5052
                /*  png_byte bit_depth;      bit depth of samples */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5053
                /*  png_byte channels;       number of channels (1-4) */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5054
                /*  png_byte pixel_depth;    bits per pixel (depth*channels) */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5055
             png_ptr->row_buf + 1);    /* start of pixel data for row */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5056
#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5057
      if (png_ptr->user_transform_depth != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5058
         row_info->bit_depth = png_ptr->user_transform_depth;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5059
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5060
      if (png_ptr->user_transform_channels != 0)
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5061
         row_info->channels = png_ptr->user_transform_channels;
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5062
#endif
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5063
      row_info->pixel_depth = (png_byte)(row_info->bit_depth *
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5064
          row_info->channels);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5065
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5066
      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_info->width);
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5067
   }
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5068
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5069
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5070
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5071
#endif /* READ_TRANSFORMS */
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
  5072
#endif /* READ */