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