jdk/src/java.desktop/share/native/libsplashscreen/libpng/pngwrite.c
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 10576 jdk/src/share/native/sun/awt/libpng/pngwrite.c@db3409425573
child 29913 95258013e132
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
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
/* pngwrite.c - general routines to write a PNG file
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
 *
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    32
 * Last changed in libpng 1.5.4 [July 7, 2011]
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    33
 * Copyright (c) 1998-2011 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.)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    36
 *
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    37
 * This code is released under the libpng license.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    38
 * For conditions of distribution and use, see the disclaimer
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    39
 * and license in png.h
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    42
#include "pngpriv.h"
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    43
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#ifdef PNG_WRITE_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/* Writes all the PNG information.  This is the suggested way to use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * library.  If you have a new chunk to add, make a function to write it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * and put it in the correct location here.  If you want the chunk written
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * after the image data, put it in png_write_end().  I strongly encourage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * you to supply a PNG_INFO_ flag, and check info_ptr->valid before writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * the chunk, as that will keep the code from breaking if you want to just
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * write a plain PNG file.  If you have long comments, I suggest writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * them in png_write_end(), and compressing them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    58
   png_debug(1, "in png_write_info_before_PLTE");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    59
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
   if (png_ptr == NULL || info_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
      return;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    62
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
   if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    65
   /* Write PNG signature */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    66
   png_write_sig(png_ptr);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    67
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    68
#ifdef PNG_MNG_FEATURES_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    69
   if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) && \
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    70
       (png_ptr->mng_features_permitted))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    72
      png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    73
      png_ptr->mng_features_permitted = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    76
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    77
   /* Write IHDR information. */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
   png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    79
       info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    80
       info_ptr->filter_type,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    81
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    82
       info_ptr->interlace_type);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
#else
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    84
       0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    86
   /* The rest of these check to see if the valid field has the appropriate
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    87
    * flag set, and if it does, writes the chunk.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    88
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    89
#ifdef PNG_WRITE_gAMA_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
   if (info_ptr->valid & PNG_INFO_gAMA)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    91
      png_write_gAMA_fixed(png_ptr, info_ptr->gamma);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    93
#ifdef PNG_WRITE_sRGB_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
   if (info_ptr->valid & PNG_INFO_sRGB)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
      png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    97
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    98
#ifdef PNG_WRITE_iCCP_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
   if (info_ptr->valid & PNG_INFO_iCCP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
      png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   101
          (png_charp)info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   103
#ifdef PNG_WRITE_sBIT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
   if (info_ptr->valid & PNG_INFO_sBIT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
      png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   107
#ifdef PNG_WRITE_cHRM_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
   if (info_ptr->valid & PNG_INFO_cHRM)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
      png_write_cHRM_fixed(png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   110
          info_ptr->x_white, info_ptr->y_white,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   111
          info_ptr->x_red, info_ptr->y_red,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   112
          info_ptr->x_green, info_ptr->y_green,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   113
          info_ptr->x_blue, info_ptr->y_blue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   115
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   116
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
   if (info_ptr->unknown_chunks_num)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   119
      png_unknown_chunk *up;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   120
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   121
      png_debug(5, "writing extra chunks");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   123
      for (up = info_ptr->unknown_chunks;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   124
           up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   125
           up++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   126
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   127
         int keep = png_handle_as_unknown(png_ptr, up->name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
         if (keep != PNG_HANDLE_CHUNK_NEVER &&
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   130
             up->location &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   131
             !(up->location & PNG_HAVE_PLTE) &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   132
             !(up->location & PNG_HAVE_IDAT) &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   133
             !(up->location & PNG_AFTER_IDAT) &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   134
             ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   135
             (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   137
            if (up->size == 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   138
               png_warning(png_ptr, "Writing zero-length unknown chunk");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   139
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            png_write_chunk(png_ptr, up->name, up->data, up->size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   142
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
      png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
png_write_info(png_structp png_ptr, png_infop info_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
   int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   156
   png_debug(1, "in png_write_info");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
   if (png_ptr == NULL || info_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
   png_write_info_before_PLTE(png_ptr, info_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
   if (info_ptr->valid & PNG_INFO_PLTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
      png_write_PLTE(png_ptr, info_ptr->palette,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   165
          (png_uint_32)info_ptr->num_palette);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   166
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
   else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
      png_error(png_ptr, "Valid palette required for paletted images");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   170
#ifdef PNG_WRITE_tRNS_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
   if (info_ptr->valid & PNG_INFO_tRNS)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   172
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   173
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   174
      /* Invert the alpha channel (in tRNS) */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   175
      if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   176
          info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   178
         int j;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   179
         for (j = 0; j<(int)info_ptr->num_trans; j++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   180
            info_ptr->trans_alpha[j] =
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   181
               (png_byte)(255 - info_ptr->trans_alpha[j]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   184
      png_write_tRNS(png_ptr, info_ptr->trans_alpha, &(info_ptr->trans_color),
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   185
          info_ptr->num_trans, info_ptr->color_type);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   186
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   187
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   188
#ifdef PNG_WRITE_bKGD_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
   if (info_ptr->valid & PNG_INFO_bKGD)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
      png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   192
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   193
#ifdef PNG_WRITE_hIST_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
   if (info_ptr->valid & PNG_INFO_hIST)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
      png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   197
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   198
#ifdef PNG_WRITE_oFFs_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
   if (info_ptr->valid & PNG_INFO_oFFs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
      png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   201
          info_ptr->offset_unit_type);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   203
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   204
#ifdef PNG_WRITE_pCAL_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
   if (info_ptr->valid & PNG_INFO_pCAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
      png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   207
          info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   208
          info_ptr->pcal_units, info_ptr->pcal_params);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   210
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   211
#ifdef PNG_WRITE_sCAL_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
   if (info_ptr->valid & PNG_INFO_sCAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
      png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
          info_ptr->scal_s_width, info_ptr->scal_s_height);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   215
#endif /* sCAL */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   216
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   217
#ifdef PNG_WRITE_pHYs_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
   if (info_ptr->valid & PNG_INFO_pHYs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
      png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   220
          info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   221
#endif /* pHYs */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   222
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   223
#ifdef PNG_WRITE_tIME_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
   if (info_ptr->valid & PNG_INFO_tIME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
      png_write_tIME(png_ptr, &(info_ptr->mod_time));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
      png_ptr->mode |= PNG_WROTE_tIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   229
#endif /* tIME */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   230
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   231
#ifdef PNG_WRITE_sPLT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
   if (info_ptr->valid & PNG_INFO_sPLT)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   233
      for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   234
         png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   235
#endif /* sPLT */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   236
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   237
#ifdef PNG_WRITE_TEXT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
   /* Check to see if we need to write text chunks */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
   for (i = 0; i < info_ptr->num_text; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   241
      png_debug2(2, "Writing header text chunk %d, type %d", i,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   242
          info_ptr->text[i].compression);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   243
      /* An internationalized chunk? */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
      if (info_ptr->text[i].compression > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   246
#ifdef PNG_WRITE_iTXt_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   247
         /* Write international chunk */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   248
         png_write_iTXt(png_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   249
             info_ptr->text[i].compression,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   250
             info_ptr->text[i].key,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   251
             info_ptr->text[i].lang,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   252
             info_ptr->text[i].lang_key,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   253
             info_ptr->text[i].text);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
          png_warning(png_ptr, "Unable to write international text");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
          /* Mark this chunk as written */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
          info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   260
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
      /* If we want a compressed text chunk */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
      else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   264
#ifdef PNG_WRITE_zTXt_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   265
         /* Write compressed chunk */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
         png_write_zTXt(png_ptr, info_ptr->text[i].key,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   267
             info_ptr->text[i].text, 0,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   268
             info_ptr->text[i].compression);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
         png_warning(png_ptr, "Unable to write compressed text");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
         /* Mark this chunk as written */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
         info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   275
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
      else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   278
#ifdef PNG_WRITE_tEXt_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   279
         /* Write uncompressed chunk */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
         png_write_tEXt(png_ptr, info_ptr->text[i].key,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   281
             info_ptr->text[i].text,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   282
             0);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   283
         /* Mark this chunk as written */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   284
         info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
#else
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   286
         /* Can't get here */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
         png_warning(png_ptr, "Unable to write uncompressed text");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   291
#endif /* tEXt */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   292
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   293
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
   if (info_ptr->unknown_chunks_num)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   296
      png_unknown_chunk *up;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   298
      png_debug(5, "writing extra chunks");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   300
      for (up = info_ptr->unknown_chunks;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   301
           up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   302
           up++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   303
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   304
         int keep = png_handle_as_unknown(png_ptr, up->name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
         if (keep != PNG_HANDLE_CHUNK_NEVER &&
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   306
             up->location &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   307
             (up->location & PNG_HAVE_PLTE) &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   308
             !(up->location & PNG_HAVE_IDAT) &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   309
             !(up->location & PNG_AFTER_IDAT) &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   310
             ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   311
             (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            png_write_chunk(png_ptr, up->name, up->data, up->size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   315
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
/* Writes the end of the PNG file.  If you don't want to write comments or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
 * time information, you can pass NULL for info.  If you already wrote these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
 * in png_write_info(), do not write them again here.  If you have long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
 * comments, I suggest writing them here, and compressing them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
png_write_end(png_structp png_ptr, png_infop info_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   328
   png_debug(1, "in png_write_end");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   329
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
      return;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   332
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
   if (!(png_ptr->mode & PNG_HAVE_IDAT))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
      png_error(png_ptr, "No IDATs written into file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   336
   /* See if user wants us to write information chunks */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
   if (info_ptr != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   339
#ifdef PNG_WRITE_TEXT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
      int i; /* local index variable */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   342
#ifdef PNG_WRITE_tIME_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   343
      /* Check to see if user has supplied a time chunk */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
      if ((info_ptr->valid & PNG_INFO_tIME) &&
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   345
          !(png_ptr->mode & PNG_WROTE_tIME))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         png_write_tIME(png_ptr, &(info_ptr->mod_time));
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   347
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   349
#ifdef PNG_WRITE_TEXT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   350
      /* Loop through comment chunks */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
      for (i = 0; i < info_ptr->num_text; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   353
         png_debug2(2, "Writing trailer text chunk %d, type %d", i,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            info_ptr->text[i].compression);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   355
         /* An internationalized chunk? */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
         if (info_ptr->text[i].compression > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   358
#ifdef PNG_WRITE_iTXt_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   359
            /* Write international chunk */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   360
            png_write_iTXt(png_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   361
                info_ptr->text[i].compression,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   362
                info_ptr->text[i].key,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   363
                info_ptr->text[i].lang,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   364
                info_ptr->text[i].lang_key,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   365
                info_ptr->text[i].text);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
#else
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   367
            png_warning(png_ptr, "Unable to write international text");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   369
            /* Mark this chunk as written */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   370
            info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   372
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
         else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   375
#ifdef PNG_WRITE_zTXt_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   376
            /* Write compressed chunk */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            png_write_zTXt(png_ptr, info_ptr->text[i].key,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   378
                info_ptr->text[i].text, 0,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   379
                info_ptr->text[i].compression);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            png_warning(png_ptr, "Unable to write compressed text");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            /* Mark this chunk as written */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   386
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
         else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
         {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   389
#ifdef PNG_WRITE_tEXt_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   390
            /* Write uncompressed chunk */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            png_write_tEXt(png_ptr, info_ptr->text[i].key,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   392
                info_ptr->text[i].text, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            png_warning(png_ptr, "Unable to write uncompressed text");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            /* Mark this chunk as written */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   402
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
   if (info_ptr->unknown_chunks_num)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   405
      png_unknown_chunk *up;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   407
      png_debug(5, "writing extra chunks");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   409
      for (up = info_ptr->unknown_chunks;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   410
           up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   411
           up++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   412
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   413
         int keep = png_handle_as_unknown(png_ptr, up->name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
         if (keep != PNG_HANDLE_CHUNK_NEVER &&
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   415
             up->location &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   416
             (up->location & PNG_AFTER_IDAT) &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   417
             ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   418
             (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            png_write_chunk(png_ptr, up->name, up->data, up->size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   422
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
   png_ptr->mode |= PNG_AFTER_IDAT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   429
   /* Write end of PNG file */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
   png_write_IEND(png_ptr);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   431
   /* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   432
    * and restored again in libpng-1.2.30, may cause some applications that
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   433
    * do not set png_ptr->output_flush_fn to crash.  If your application
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   434
    * experiences a problem, please try building libpng with
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   435
    * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   436
    * png-mng-implement at lists.sf.net .
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   437
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   438
#ifdef PNG_WRITE_FLUSH_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   439
#  ifdef PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
   png_flush(png_ptr);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   441
#  endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   445
#ifdef PNG_CONVERT_tIME_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   446
/* "tm" structure is not supported on WindowsCE */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
void PNGAPI
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   448
png_convert_from_struct_tm(png_timep ptime, PNG_CONST struct tm FAR * ttime)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   450
   png_debug(1, "in png_convert_from_struct_tm");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   451
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
   ptime->year = (png_uint_16)(1900 + ttime->tm_year);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
   ptime->month = (png_byte)(ttime->tm_mon + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
   ptime->day = (png_byte)ttime->tm_mday;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
   ptime->hour = (png_byte)ttime->tm_hour;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
   ptime->minute = (png_byte)ttime->tm_min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
   ptime->second = (png_byte)ttime->tm_sec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
png_convert_from_time_t(png_timep ptime, time_t ttime)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
   struct tm *tbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   465
   png_debug(1, "in png_convert_from_time_t");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   466
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
   tbuf = gmtime(&ttime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
   png_convert_from_struct_tm(ptime, tbuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
/* Initialize png_ptr structure, and allocate any memory needed */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   473
PNG_FUNCTION(png_structp,PNGAPI
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   474
png_create_write_struct,(png_const_charp user_png_ver, png_voidp error_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   475
    png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
#ifdef PNG_USER_MEM_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
   return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   479
       warn_fn, NULL, NULL, NULL));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
/* Alternate initialize png_ptr structure, and allocate any memory needed */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   483
static void png_reset_filter_heuristics(png_structp png_ptr); /* forward decl */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   484
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   485
PNG_FUNCTION(png_structp,PNGAPI
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   486
png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   487
    png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   488
    png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
#endif /* PNG_USER_MEM_SUPPORTED */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   491
   volatile int png_cleanup_needed = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   492
#ifdef PNG_SETJMP_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   493
   volatile
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   494
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
   png_structp png_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
#ifdef PNG_SETJMP_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
#ifdef USE_FAR_KEYWORD
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   498
   jmp_buf tmp_jmpbuf;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   501
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   502
   png_debug(1, "in png_create_write_struct");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   503
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
#ifdef PNG_USER_MEM_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
   png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   506
       (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
   png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
#endif /* PNG_USER_MEM_SUPPORTED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
      return (NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   513
   /* Added at libpng-1.2.6 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   515
   png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   516
   png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
#ifdef PNG_SETJMP_SUPPORTED
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   520
/* Applications that neglect to set up their own setjmp() and then
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   521
   encounter a png_error() will longjmp here.  Since the jmpbuf is
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   522
   then meaningless we abort instead of returning. */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
#ifdef USE_FAR_KEYWORD
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   524
   if (setjmp(tmp_jmpbuf))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
#else
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   526
   if (setjmp(png_jmpbuf(png_ptr))) /* sets longjmp to match setjmp */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
#ifdef USE_FAR_KEYWORD
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   529
   png_memcpy(png_jmpbuf(png_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   531
      PNG_ABORT();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
#ifdef PNG_USER_MEM_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
   png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
#endif /* PNG_USER_MEM_SUPPORTED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
   png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   539
   if (!png_user_version_check(png_ptr, user_png_ver))
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   540
      png_cleanup_needed = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   542
   /* Initialize zbuf - compression buffer */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   543
   png_ptr->zbuf_size = PNG_ZBUF_SIZE;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   544
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   545
   if (!png_cleanup_needed)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   547
      png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   548
          png_ptr->zbuf_size);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   549
      if (png_ptr->zbuf == NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   550
         png_cleanup_needed = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   553
   if (png_cleanup_needed)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   554
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   555
       /* Clean up PNG structure and deallocate any memory. */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   556
       png_free(png_ptr, png_ptr->zbuf);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   557
       png_ptr->zbuf = NULL;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   558
#ifdef PNG_USER_MEM_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   559
       png_destroy_struct_2((png_voidp)png_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   560
           (png_free_ptr)free_fn, (png_voidp)mem_ptr);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   561
#else
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   562
       png_destroy_struct((png_voidp)png_ptr);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   563
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   564
       return (NULL);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   565
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   567
   png_set_write_fn(png_ptr, NULL, NULL, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   569
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   570
   png_reset_filter_heuristics(png_ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
   return (png_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
/* Write a few rows of image data.  If the image is interlaced,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
 * either you will have to write the 7 sub images, or, if you
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
 * have called png_set_interlace_handling(), you will have to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
 * "write" the image seven times.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
png_write_rows(png_structp png_ptr, png_bytepp row,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   584
    png_uint_32 num_rows)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
   png_uint_32 i; /* row counter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
   png_bytepp rp; /* row pointer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   589
   png_debug(1, "in png_write_rows");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   594
   /* Loop through the rows */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
   for (i = 0, rp = row; i < num_rows; i++, rp++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
      png_write_row(png_ptr, *rp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
/* Write the image.  You only need to call this function once, even
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
 * if you are writing an interlaced image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
png_write_image(png_structp png_ptr, png_bytepp image)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
   png_uint_32 i; /* row index */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
   int pass, num_pass; /* pass variables */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
   png_bytepp rp; /* points to current row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   614
   png_debug(1, "in png_write_image");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   615
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   616
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   617
   /* Initialize interlace handling.  If image is not interlaced,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   618
    * this will set pass to 1
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   619
    */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
   num_pass = png_set_interlace_handling(png_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
   num_pass = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   624
   /* Loop through passes */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
   for (pass = 0; pass < num_pass; pass++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   627
      /* Loop through image */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
      for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
         png_write_row(png_ptr, *rp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   635
/* Called by user to write a row of image data */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
void PNGAPI
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   637
png_write_row(png_structp png_ptr, png_const_bytep row)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
      return;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   641
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   642
   png_debug2(1, "in png_write_row (row %u, pass %d)",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
      png_ptr->row_number, png_ptr->pass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   645
   /* Initialize transformations and other stuff if first time */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
   if (png_ptr->row_number == 0 && png_ptr->pass == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   648
      /* Make sure we wrote the header info */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   649
      if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   650
         png_error(png_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   651
             "png_write_info was never called before png_write_row");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   653
      /* Check for transforms that have been set but were defined out */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
#if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   655
      if (png_ptr->transformations & PNG_INVERT_MONO)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   656
         png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   658
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
#if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   660
      if (png_ptr->transformations & PNG_FILLER)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   661
         png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   663
#if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   664
    defined(PNG_READ_PACKSWAP_SUPPORTED)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   665
      if (png_ptr->transformations & PNG_PACKSWAP)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   666
         png_warning(png_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   667
             "PNG_WRITE_PACKSWAP_SUPPORTED is not defined");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   669
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
#if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   671
      if (png_ptr->transformations & PNG_PACK)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   672
         png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   674
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
#if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   676
      if (png_ptr->transformations & PNG_SHIFT)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   677
         png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   679
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
#if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   681
      if (png_ptr->transformations & PNG_BGR)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   682
         png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
#endif
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   684
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
#if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   686
      if (png_ptr->transformations & PNG_SWAP_BYTES)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   687
         png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
      png_write_start_row(png_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   693
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   694
   /* If interlaced and not interested in row, return */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
   if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
      switch (png_ptr->pass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
         case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            if (png_ptr->row_number & 0x07)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
               png_write_finish_row(png_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
               return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   706
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
         case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
               png_write_finish_row(png_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
               return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   714
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
         case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            if ((png_ptr->row_number & 0x07) != 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
               png_write_finish_row(png_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
               return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   722
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
         case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
               png_write_finish_row(png_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
               return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   730
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
         case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            if ((png_ptr->row_number & 0x03) != 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
               png_write_finish_row(png_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
               return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   738
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
         case 5:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
               png_write_finish_row(png_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
               return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   746
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
         case 6:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            if (!(png_ptr->row_number & 0x01))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
               png_write_finish_row(png_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
               return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            break;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   754
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   755
         default: /* error: ignore it */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   756
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   761
   /* Set up row info for transformations */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
   png_ptr->row_info.color_type = png_ptr->color_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
   png_ptr->row_info.width = png_ptr->usr_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
   png_ptr->row_info.channels = png_ptr->usr_channels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
   png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
   png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
      png_ptr->row_info.channels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
   png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
      png_ptr->row_info.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   772
   png_debug1(3, "row_info->color_type = %d", png_ptr->row_info.color_type);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   773
   png_debug1(3, "row_info->width = %u", png_ptr->row_info.width);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   774
   png_debug1(3, "row_info->channels = %d", png_ptr->row_info.channels);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   775
   png_debug1(3, "row_info->bit_depth = %d", png_ptr->row_info.bit_depth);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   776
   png_debug1(3, "row_info->pixel_depth = %d", png_ptr->row_info.pixel_depth);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   777
   png_debug1(3, "row_info->rowbytes = %lu",
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   778
       (unsigned long)png_ptr->row_info.rowbytes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
   /* Copy user's row into buffer, leaving room for filter byte. */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   781
   png_memcpy(png_ptr->row_buf + 1, row, png_ptr->row_info.rowbytes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   783
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   784
   /* Handle interlacing */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
   if (png_ptr->interlaced && png_ptr->pass < 6 &&
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   786
       (png_ptr->transformations & PNG_INTERLACE))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
      png_do_write_interlace(&(png_ptr->row_info),
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   789
          png_ptr->row_buf + 1, png_ptr->pass);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   790
      /* This should always get caught above, but still ... */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
      if (!(png_ptr->row_info.width))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
         png_write_finish_row(png_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
         return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   799
#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   800
   /* Handle other transformations */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
   if (png_ptr->transformations)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
      png_do_write_transformations(png_ptr);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   803
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   805
#ifdef PNG_MNG_FEATURES_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
   /* Write filter_method 64 (intrapixel differencing) only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    * 2. Libpng did not write a PNG signature (this filter_method is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    *    used in PNG datastreams that are embedded in MNG datastreams) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    * 3. The application called png_permit_mng_features with a mask that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    *    included PNG_FLAG_MNG_FILTER_64 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    * 4. The filter_method is 64 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    * 5. The color_type is RGB or RGBA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   815
   if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   816
       (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
      /* Intrapixel differencing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
      png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
   /* Find a filter if necessary, filter the row and write it out. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
   png_write_find_filter(png_ptr, &(png_ptr->row_info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
   if (png_ptr->write_row_fn != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
      (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   830
#ifdef PNG_WRITE_FLUSH_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
/* Set the automatic flush interval or 0 to turn flushing off */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
png_set_flush(png_structp png_ptr, int nrows)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   835
   png_debug(1, "in png_set_flush");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   836
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
      return;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   839
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
   png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   843
/* Flush the current output buffers now */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
png_write_flush(png_structp png_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
   int wrote_IDAT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   849
   png_debug(1, "in png_write_flush");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   850
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
      return;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   853
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
   /* We have already written out all of the data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
   if (png_ptr->row_number >= png_ptr->num_rows)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   856
      return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
   do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
      int ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   862
      /* Compress the data */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
      ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
      wrote_IDAT = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   866
      /* Check for compression errors */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
      if (ret != Z_OK)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
         if (png_ptr->zstream.msg != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            png_error(png_ptr, png_ptr->zstream.msg);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   871
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
         else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            png_error(png_ptr, "zlib error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
      if (!(png_ptr->zstream.avail_out))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   878
         /* Write the IDAT and reset the zlib output buffer */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   879
         png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
         wrote_IDAT = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   882
   } while (wrote_IDAT == 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
   /* If there is any data left to be output, write it into a new IDAT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
   if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   887
      /* Write the IDAT and reset the zlib output buffer */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
      png_write_IDAT(png_ptr, png_ptr->zbuf,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   889
          png_ptr->zbuf_size - png_ptr->zstream.avail_out);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
   png_ptr->flush_rows = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
   png_flush(png_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   896
/* Free all memory used by the write */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
   png_structp png_ptr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
   png_infop info_ptr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
#ifdef PNG_USER_MEM_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
   png_free_ptr free_fn = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
   png_voidp mem_ptr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   907
   png_debug(1, "in png_destroy_write_struct");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   908
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
   if (png_ptr_ptr != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
      png_ptr = *png_ptr_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
#ifdef PNG_USER_MEM_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
      free_fn = png_ptr->free_fn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
      mem_ptr = png_ptr->mem_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   918
#ifdef PNG_USER_MEM_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   919
   if (png_ptr != NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   920
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   921
      free_fn = png_ptr->free_fn;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   922
      mem_ptr = png_ptr->mem_ptr;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   923
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   924
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   925
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
   if (info_ptr_ptr != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
      info_ptr = *info_ptr_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
   if (info_ptr != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   931
      if (png_ptr != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   933
         png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   934
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   935
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   936
         if (png_ptr->num_chunk_list)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   937
         {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   938
            png_free(png_ptr, png_ptr->chunk_list);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   939
            png_ptr->num_chunk_list = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   940
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   941
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
#ifdef PNG_USER_MEM_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
      png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   946
          (png_voidp)mem_ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
      png_destroy_struct((png_voidp)info_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
      *info_ptr_ptr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
   if (png_ptr != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
      png_write_destroy(png_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
#ifdef PNG_USER_MEM_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
      png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   958
          (png_voidp)mem_ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
      png_destroy_struct((png_voidp)png_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
      *png_ptr_ptr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
/* Free any memory used in png_ptr struct (old method) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
void /* PRIVATE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
png_write_destroy(png_structp png_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
#ifdef PNG_SETJMP_SUPPORTED
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   972
   jmp_buf tmp_jmp; /* Save jump buffer */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
   png_error_ptr error_fn;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   975
#ifdef PNG_WARNINGS_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
   png_error_ptr warning_fn;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   977
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
   png_voidp error_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
#ifdef PNG_USER_MEM_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
   png_free_ptr free_fn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   983
   png_debug(1, "in png_write_destroy");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   985
   /* Free any memory zlib uses */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   986
   if (png_ptr->zlib_state != PNG_ZLIB_UNINITIALIZED)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   987
      deflateEnd(&png_ptr->zstream);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   988
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   989
   /* Free our memory.  png_free checks NULL for us. */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
   png_free(png_ptr, png_ptr->zbuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
   png_free(png_ptr, png_ptr->row_buf);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   992
#ifdef PNG_WRITE_FILTER_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
   png_free(png_ptr, png_ptr->prev_row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
   png_free(png_ptr, png_ptr->sub_row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
   png_free(png_ptr, png_ptr->up_row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
   png_free(png_ptr, png_ptr->avg_row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
   png_free(png_ptr, png_ptr->paeth_row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1000
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1001
   /* Use this to save a little code space, it doesn't free the filter_costs */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1002
   png_reset_filter_heuristics(png_ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
   png_free(png_ptr, png_ptr->filter_costs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
   png_free(png_ptr, png_ptr->inv_filter_costs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
#ifdef PNG_SETJMP_SUPPORTED
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1008
   /* Reset structure */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1009
   png_memcpy(tmp_jmp, png_ptr->longjmp_buffer, png_sizeof(jmp_buf));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
   error_fn = png_ptr->error_fn;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1013
#ifdef PNG_WARNINGS_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
   warning_fn = png_ptr->warning_fn;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1015
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
   error_ptr = png_ptr->error_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
#ifdef PNG_USER_MEM_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
   free_fn = png_ptr->free_fn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1021
   png_memset(png_ptr, 0, png_sizeof(png_struct));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
   png_ptr->error_fn = error_fn;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1024
#ifdef PNG_WARNINGS_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
   png_ptr->warning_fn = warning_fn;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1026
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
   png_ptr->error_ptr = error_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
#ifdef PNG_USER_MEM_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
   png_ptr->free_fn = free_fn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
#ifdef PNG_SETJMP_SUPPORTED
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1033
   png_memcpy(png_ptr->longjmp_buffer, tmp_jmp, png_sizeof(jmp_buf));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
/* Allow the application to select one or more row filters to use. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
png_set_filter(png_structp png_ptr, int method, int filters)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1041
   png_debug(1, "in png_set_filter");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1042
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
      return;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1045
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1046
#ifdef PNG_MNG_FEATURES_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1047
   if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1048
       (method == PNG_INTRAPIXEL_DIFFERENCING))
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1049
      method = PNG_FILTER_TYPE_BASE;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1050
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
   if (method == PNG_FILTER_TYPE_BASE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
      switch (filters & (PNG_ALL_FILTERS | 0x07))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1056
#ifdef PNG_WRITE_FILTER_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
         case 5:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
         case 6:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
         case 7: png_warning(png_ptr, "Unknown row filter for method 0");
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1060
#endif /* PNG_WRITE_FILTER_SUPPORTED */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1061
         case PNG_FILTER_VALUE_NONE:
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1062
            png_ptr->do_filter = PNG_FILTER_NONE; break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1063
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1064
#ifdef PNG_WRITE_FILTER_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1065
         case PNG_FILTER_VALUE_SUB:
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1066
            png_ptr->do_filter = PNG_FILTER_SUB; break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1067
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1068
         case PNG_FILTER_VALUE_UP:
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1069
            png_ptr->do_filter = PNG_FILTER_UP; break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1070
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1071
         case PNG_FILTER_VALUE_AVG:
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1072
            png_ptr->do_filter = PNG_FILTER_AVG; break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1073
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1074
         case PNG_FILTER_VALUE_PAETH:
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1075
            png_ptr->do_filter = PNG_FILTER_PAETH; break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1076
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1077
         default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1078
            png_ptr->do_filter = (png_byte)filters; break;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1079
#else
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1080
         default:
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1081
            png_warning(png_ptr, "Unknown row filter for method 0");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1082
#endif /* PNG_WRITE_FILTER_SUPPORTED */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
      /* If we have allocated the row_buf, this means we have already started
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
       * with the image and we should have allocated all of the filter buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
       * that have been selected.  If prev_row isn't already allocated, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
       * it is too late to start using the filters that need it, since we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
       * will be missing the data in the previous row.  If an application
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
       * wants to start and stop using particular filters during compression,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
       * it should start out with all of the filters, and then add and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
       * remove them after the start of compression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
      if (png_ptr->row_buf != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1096
#ifdef PNG_WRITE_FILTER_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
         if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1100
                (png_ptr->rowbytes + 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
         if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            if (png_ptr->prev_row == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
               png_warning(png_ptr, "Can't add Up filter after starting");
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1109
               png_ptr->do_filter = (png_byte)(png_ptr->do_filter &
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1110
                   ~PNG_FILTER_UP);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1112
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
               png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1116
                   (png_ptr->rowbytes + 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
               png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
         if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            if (png_ptr->prev_row == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
               png_warning(png_ptr, "Can't add Average filter after starting");
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1126
               png_ptr->do_filter = (png_byte)(png_ptr->do_filter &
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1127
                   ~PNG_FILTER_AVG);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1129
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
               png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1133
                   (png_ptr->rowbytes + 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
               png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
         if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
             png_ptr->paeth_row == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            if (png_ptr->prev_row == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
               png_warning(png_ptr, "Can't add Paeth filter after starting");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
               png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1146
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
               png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1150
                   (png_ptr->rowbytes + 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
               png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
         if (png_ptr->do_filter == PNG_NO_FILTERS)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1156
#endif /* PNG_WRITE_FILTER_SUPPORTED */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            png_ptr->do_filter = PNG_FILTER_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
      png_error(png_ptr, "Unknown custom filter method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
/* This allows us to influence the way in which libpng chooses the "best"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
 * filter for the current scanline.  While the "minimum-sum-of-absolute-
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
 * differences metric is relatively fast and effective, there is some
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
 * question as to whether it can be improved upon by trying to keep the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
 * filtered data going to zlib more consistent, hopefully resulting in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
 * better compression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
 */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1171
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED      /* GRR 970116 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1172
/* Convenience reset API. */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1173
static void
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1174
png_reset_filter_heuristics(png_structp png_ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1176
   /* Clear out any old values in the 'weights' - this must be done because if
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1177
    * the app calls set_filter_heuristics multiple times with different
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1178
    * 'num_weights' values we would otherwise potentially have wrong sized
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1179
    * arrays.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1180
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1181
   png_ptr->num_prev_filters = 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1182
   png_ptr->heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1183
   if (png_ptr->prev_filters != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1185
      png_bytep old = png_ptr->prev_filters;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1186
      png_ptr->prev_filters = NULL;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1187
      png_free(png_ptr, old);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1188
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1189
   if (png_ptr->filter_weights != NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1190
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1191
      png_uint_16p old = png_ptr->filter_weights;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1192
      png_ptr->filter_weights = NULL;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1193
      png_free(png_ptr, old);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1196
   if (png_ptr->inv_filter_weights != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1198
      png_uint_16p old = png_ptr->inv_filter_weights;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1199
      png_ptr->inv_filter_weights = NULL;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1200
      png_free(png_ptr, old);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1203
   /* Leave the filter_costs - this array is fixed size. */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1204
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1205
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1206
static int
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1207
png_init_filter_heuristics(png_structp png_ptr, int heuristic_method,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1208
   int num_weights)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1209
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1210
   if (png_ptr == NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1211
      return 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1213
   /* Clear out the arrays */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1214
   png_reset_filter_heuristics(png_ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1216
   /* Check arguments; the 'reset' function makes the correct settings for the
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1217
    * unweighted case, but we must handle the weight case by initializing the
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1218
    * arrays for the caller.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1219
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1220
   if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1222
      int i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1223
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1224
      if (num_weights > 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
         png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1227
             (png_uint_32)(png_sizeof(png_byte) * num_weights));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
         /* To make sure that the weighting starts out fairly */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
         for (i = 0; i < num_weights; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            png_ptr->prev_filters[i] = 255;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
         png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1236
             (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
         png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1239
             (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1240
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
         for (i = 0; i < num_weights; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
            png_ptr->inv_filter_weights[i] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
         }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1246
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1247
         /* Safe to set this now */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1248
         png_ptr->num_prev_filters = (png_byte)num_weights;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1251
      /* If, in the future, there are other filter methods, this would
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1252
       * need to be based on png_ptr->filter.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1253
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1254
      if (png_ptr->filter_costs == NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
      {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1256
         png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1257
             (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1258
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1259
         png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1260
             (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
      for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
         png_ptr->inv_filter_costs[i] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
         png_ptr->filter_costs[i] = PNG_COST_FACTOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
      }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1268
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1269
      /* All the arrays are inited, safe to set this: */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1270
      png_ptr->heuristic_method = PNG_FILTER_HEURISTIC_WEIGHTED;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1271
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1272
      /* Return the 'ok' code. */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1273
      return 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
   }
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1275
   else if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT ||
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1276
      heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1277
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1278
      return 1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1279
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1280
   else
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1281
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1282
      png_warning(png_ptr, "Unknown filter heuristic method");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1283
      return 0;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1284
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1285
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1286
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1287
/* Provide floating and fixed point APIs */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1288
#ifdef PNG_FLOATING_POINT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1289
void PNGAPI
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1290
png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1291
    int num_weights, png_const_doublep filter_weights,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1292
    png_const_doublep filter_costs)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1293
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1294
   png_debug(1, "in png_set_filter_heuristics");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1296
   /* The internal API allocates all the arrays and ensures that the elements of
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1297
    * those arrays are set to the default value.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    */
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1299
   if (!png_init_filter_heuristics(png_ptr, heuristic_method, num_weights))
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1300
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1301
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1302
   /* If using the weighted method copy in the weights. */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1303
   if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
   {
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1305
      int i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1306
      for (i = 0; i < num_weights; i++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1307
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1308
         if (filter_weights[i] <= 0.0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1309
         {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1310
            png_ptr->inv_filter_weights[i] =
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1311
            png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1312
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1313
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1314
         else
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1315
         {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1316
            png_ptr->inv_filter_weights[i] =
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1317
                (png_uint_16)(PNG_WEIGHT_FACTOR*filter_weights[i]+.5);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1318
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1319
            png_ptr->filter_weights[i] =
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1320
                (png_uint_16)(PNG_WEIGHT_FACTOR/filter_weights[i]+.5);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1321
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1322
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1323
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1324
      /* Here is where we set the relative costs of the different filters.  We
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1325
       * should take the desired compression level into account when setting
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1326
       * the costs, so that Paeth, for instance, has a high relative cost at low
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1327
       * compression levels, while it has a lower relative cost at higher
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1328
       * compression settings.  The filter types are in order of increasing
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1329
       * relative cost, so it would be possible to do this with an algorithm.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1330
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1331
      for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) if (filter_costs[i] >= 1.0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
         png_ptr->inv_filter_costs[i] =
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1334
             (png_uint_16)(PNG_COST_FACTOR / filter_costs[i] + .5);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1335
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
         png_ptr->filter_costs[i] =
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1337
             (png_uint_16)(PNG_COST_FACTOR * filter_costs[i] + .5);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
}
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1341
#endif /* FLOATING_POINT */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1342
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1343
#ifdef PNG_FIXED_POINT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1344
void PNGAPI
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1345
png_set_filter_heuristics_fixed(png_structp png_ptr, int heuristic_method,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1346
    int num_weights, png_const_fixed_point_p filter_weights,
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1347
    png_const_fixed_point_p filter_costs)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1348
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1349
   png_debug(1, "in png_set_filter_heuristics_fixed");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1350
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1351
   /* The internal API allocates all the arrays and ensures that the elements of
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1352
    * those arrays are set to the default value.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1353
    */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1354
   if (!png_init_filter_heuristics(png_ptr, heuristic_method, num_weights))
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1355
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1356
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1357
   /* If using the weighted method copy in the weights. */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1358
   if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1359
   {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1360
      int i;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1361
      for (i = 0; i < num_weights; i++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1362
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1363
         if (filter_weights[i] <= 0)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1364
         {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1365
            png_ptr->inv_filter_weights[i] =
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1366
            png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1367
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1368
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1369
         else
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1370
         {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1371
            png_ptr->inv_filter_weights[i] = (png_uint_16)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1372
               ((PNG_WEIGHT_FACTOR*filter_weights[i]+PNG_FP_HALF)/PNG_FP_1);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1373
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1374
            png_ptr->filter_weights[i] = (png_uint_16)((PNG_WEIGHT_FACTOR*
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1375
               PNG_FP_1+(filter_weights[i]/2))/filter_weights[i]);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1376
         }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1377
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1378
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1379
      /* Here is where we set the relative costs of the different filters.  We
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1380
       * should take the desired compression level into account when setting
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1381
       * the costs, so that Paeth, for instance, has a high relative cost at low
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1382
       * compression levels, while it has a lower relative cost at higher
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1383
       * compression settings.  The filter types are in order of increasing
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1384
       * relative cost, so it would be possible to do this with an algorithm.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1385
       */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1386
      for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1387
         if (filter_costs[i] >= PNG_FP_1)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1388
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1389
         png_uint_32 tmp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1390
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1391
         /* Use a 32 bit unsigned temporary here because otherwise the
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1392
          * intermediate value will be a 32 bit *signed* integer (ANSI rules)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1393
          * and this will get the wrong answer on division.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1394
          */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1395
         tmp = PNG_COST_FACTOR*PNG_FP_1 + (filter_costs[i]/2);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1396
         tmp /= filter_costs[i];
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1397
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1398
         png_ptr->inv_filter_costs[i] = (png_uint_16)tmp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1399
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1400
         tmp = PNG_COST_FACTOR * filter_costs[i] + PNG_FP_HALF;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1401
         tmp /= PNG_FP_1;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1402
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1403
         png_ptr->filter_costs[i] = (png_uint_16)tmp;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1404
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1405
   }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1406
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1407
#endif /* FIXED_POINT */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
png_set_compression_level(png_structp png_ptr, int level)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1413
   png_debug(1, "in png_set_compression_level");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1414
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
      return;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1417
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
   png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
   png_ptr->zlib_level = level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
png_set_compression_mem_level(png_structp png_ptr, int mem_level)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1425
   png_debug(1, "in png_set_compression_mem_level");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1426
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
      return;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1429
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
   png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
   png_ptr->zlib_mem_level = mem_level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
png_set_compression_strategy(png_structp png_ptr, int strategy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1437
   png_debug(1, "in png_set_compression_strategy");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1438
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
      return;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1441
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
   png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
   png_ptr->zlib_strategy = strategy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1446
/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1447
 * smaller value of window_bits if it can do so safely.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1448
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
png_set_compression_window_bits(png_structp png_ptr, int window_bits)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
      return;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1454
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
   if (window_bits > 15)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
      png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1457
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
   else if (window_bits < 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
      png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1460
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
#ifndef WBITS_8_OK
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1462
   /* Avoid libpng bug with 256-byte windows */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
   if (window_bits == 8)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1464
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1465
        png_warning(png_ptr, "Compression window is being reset to 512");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1466
        window_bits = 9;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1467
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1468
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
   png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
   png_ptr->zlib_window_bits = window_bits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
png_set_compression_method(png_structp png_ptr, int method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1477
   png_debug(1, "in png_set_compression_method");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1478
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
      return;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1481
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
   if (method != 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
      png_warning(png_ptr, "Only compression method 8 is supported by PNG");
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1484
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
   png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
   png_ptr->zlib_method = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1489
/* The following were added to libpng-1.5.4 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1490
#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1491
void PNGAPI
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1492
png_set_text_compression_level(png_structp png_ptr, int level)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1493
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1494
   png_debug(1, "in png_set_text_compression_level");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1495
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1496
   if (png_ptr == NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1497
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1498
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1499
   png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_LEVEL;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1500
   png_ptr->zlib_text_level = level;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1501
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1502
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1503
void PNGAPI
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1504
png_set_text_compression_mem_level(png_structp png_ptr, int mem_level)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1505
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1506
   png_debug(1, "in png_set_text_compression_mem_level");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1507
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1508
   if (png_ptr == NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1509
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1510
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1511
   png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1512
   png_ptr->zlib_text_mem_level = mem_level;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1513
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1514
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1515
void PNGAPI
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1516
png_set_text_compression_strategy(png_structp png_ptr, int strategy)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1517
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1518
   png_debug(1, "in png_set_text_compression_strategy");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1519
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1520
   if (png_ptr == NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1521
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1522
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1523
   png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_STRATEGY;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1524
   png_ptr->zlib_text_strategy = strategy;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1525
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1526
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1527
/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1528
 * smaller value of window_bits if it can do so safely.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1529
 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1530
void PNGAPI
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1531
png_set_text_compression_window_bits(png_structp png_ptr, int window_bits)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1532
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1533
   if (png_ptr == NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1534
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1535
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1536
   if (window_bits > 15)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1537
      png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1538
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1539
   else if (window_bits < 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1540
      png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1541
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1542
#ifndef WBITS_8_OK
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1543
   /* Avoid libpng bug with 256-byte windows */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1544
   if (window_bits == 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1545
      {
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1546
        png_warning(png_ptr, "Text compression window is being reset to 512");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1547
        window_bits = 9;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1548
      }
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1549
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1550
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1551
   png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1552
   png_ptr->zlib_text_window_bits = window_bits;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1553
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1554
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1555
void PNGAPI
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1556
png_set_text_compression_method(png_structp png_ptr, int method)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1557
{
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1558
   png_debug(1, "in png_set_text_compression_method");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1559
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1560
   if (png_ptr == NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1561
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1562
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1563
   if (method != 8)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1564
      png_warning(png_ptr, "Only compression method 8 is supported by PNG");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1565
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1566
   png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_METHOD;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1567
   png_ptr->zlib_text_method = method;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1568
}
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1569
#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1570
/* end of API added to libpng-1.5.4 */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1571
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
      return;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1577
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
   png_ptr->write_row_fn = write_row_fn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1581
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1584
    write_user_transform_fn)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1586
   png_debug(1, "in png_set_write_user_transform_fn");
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1587
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
      return;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1590
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
   png_ptr->transformations |= PNG_USER_TRANSFORM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
   png_ptr->write_user_transform_fn = write_user_transform_fn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1597
#ifdef PNG_INFO_IMAGE_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
png_write_png(png_structp png_ptr, png_infop info_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1600
    int transforms, voidp params)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
   if (png_ptr == NULL || info_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
   /* Write the file header information. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
   png_write_info(png_ptr, info_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
   /* ------ these transformations don't touch the info structure ------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1610
#ifdef PNG_WRITE_INVERT_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1611
   /* Invert monochrome pixels */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
   if (transforms & PNG_TRANSFORM_INVERT_MONO)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1613
      png_set_invert_mono(png_ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1616
#ifdef PNG_WRITE_SHIFT_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
   /* Shift the pixels up to a legal bit depth and fill in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
    * as appropriate to correctly scale the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
   if ((transforms & PNG_TRANSFORM_SHIFT)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1621
       && (info_ptr->valid & PNG_INFO_sBIT))
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1622
      png_set_shift(png_ptr, &info_ptr->sig_bit);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1625
#ifdef PNG_WRITE_PACK_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1626
   /* Pack pixels into bytes */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
   if (transforms & PNG_TRANSFORM_PACKING)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
       png_set_packing(png_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1631
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1632
   /* Swap location of alpha bytes from ARGB to RGBA */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
   if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1634
      png_set_swap_alpha(png_ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1637
#ifdef PNG_WRITE_FILLER_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1638
   /* Pack XRGB/RGBX/ARGB/RGBA into RGB (4 channels -> 3 channels) */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1639
   if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1640
      png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1641
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1642
   else if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1643
      png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1646
#ifdef PNG_WRITE_BGR_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1647
   /* Flip BGR pixels to RGB */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
   if (transforms & PNG_TRANSFORM_BGR)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1649
      png_set_bgr(png_ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1652
#ifdef PNG_WRITE_SWAP_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1653
   /* Swap bytes of 16-bit files to most significant byte first */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
   if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1655
      png_set_swap(png_ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1658
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1659
   /* Swap bits of 1, 2, 4 bit packed pixel formats */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
   if (transforms & PNG_TRANSFORM_PACKSWAP)
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1661
      png_set_packswap(png_ptr);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1662
#endif
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1663
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1664
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1665
   /* Invert the alpha channel from opacity to transparency */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1666
   if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1667
      png_set_invert_alpha(png_ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
   /* ----------------------- end of transformations ------------------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1672
   /* Write the bits */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
   if (info_ptr->valid & PNG_INFO_IDAT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
       png_write_image(png_ptr, info_ptr->row_pointers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
   /* It is REQUIRED to call this to finish writing the rest of the file */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
   png_write_end(png_ptr, info_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1679
   PNG_UNUSED(transforms)   /* Quiet compiler warnings */
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
  1680
   PNG_UNUSED(params)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
#endif /* PNG_WRITE_SUPPORTED */