src/java.desktop/share/native/libsplashscreen/libpng/pngrio.c
author prr
Tue, 31 Jul 2018 14:03:39 -0700
changeset 51304 66d9993dd4ad
parent 47216 71c04702a3d5
child 57618 53154e45385a
permissions -rw-r--r--
8208353: Upgrade JDK 11 to libpng 1.6.35 Reviewed-by: jdv, kaddepalli
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
/* pngrio.c - functions for data input
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
 *
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 47216
diff changeset
    32
 * Last changed in libpng 1.6.35 [July 15, 2018]
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 47216
diff changeset
    33
 * Copyright (c) 1998-2002,2004,2006-2016,2018 Glenn Randers-Pehrson
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 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
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    40
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This file provides a location for all input.  Users who need
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * special handling are expected to write a function that has the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * arguments as this and performs a similar function, but that possibly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * has a different input method.  Note that you shouldn't change this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * function, but rather write a replacement function and then make
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * libpng use it at run time with png_set_read_fn(...).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    49
#include "pngpriv.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    51
#ifdef PNG_READ_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/* Read the data from whatever input you are using.  The default routine
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    54
 * reads from a file pointer.  Note that this routine sometimes gets called
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    55
 * with very small lengths, so you should implement some kind of simple
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    56
 * buffering if you are using unbuffered reads.  This should never be asked
35296
659e92aaf7f4 8143941: Update splashscreen displays
azvegint
parents: 29913
diff changeset
    57
 * to read more than 64K on a 16-bit machine.
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    58
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
void /* PRIVATE */
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 47216
diff changeset
    60
png_read_data(png_structrp png_ptr, png_bytep data, size_t length)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    62
   png_debug1(4, "reading %d bytes", (int)length);
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    63
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
   if (png_ptr->read_data_fn != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
      (*(png_ptr->read_data_fn))(png_ptr, data, length);
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    66
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
      png_error(png_ptr, "Call to NULL read function");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    71
#ifdef PNG_STDIO_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
/* This is the function that does the actual reading of data.  If you are
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    73
 * not reading from a standard C stream, you should create a replacement
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    74
 * read_data function and use it at run time with png_set_read_fn(), rather
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    75
 * than changing the library.
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
void PNGCBAPI
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 47216
diff changeset
    78
png_default_read_data(png_structp png_ptr, png_bytep data, size_t length)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
{
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 47216
diff changeset
    80
   size_t check;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    82
   if (png_ptr == NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    83
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    84
51304
66d9993dd4ad 8208353: Upgrade JDK 11 to libpng 1.6.35
prr
parents: 47216
diff changeset
    85
   /* fread() returns 0 on error, so it is OK to store this in a size_t
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    * instead of an int, which is what fread() actually returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    */
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
    88
   check = fread(data, 1, length, png_voidcast(png_FILE_p, png_ptr->io_ptr));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
   if (check != length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
      png_error(png_ptr, "Read Error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
/* This function allows the application to supply a new input function
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    96
 * for libpng if standard C streams aren't being used.
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
 * This function takes as its arguments:
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
    99
 *
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   100
 * png_ptr      - pointer to a png input data structure
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   101
 *
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   102
 * io_ptr       - pointer to user supplied structure containing info about
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   103
 *                the input functions.  May be NULL.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   104
 *
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   105
 * read_data_fn - pointer to a new input function that takes as its
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   106
 *                arguments a pointer to a png_struct, a pointer to
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   107
 *                a location where input data can be stored, and a 32-bit
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   108
 *                unsigned int that is the number of bytes to be read.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   109
 *                To exit and output any fatal error messages the new write
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   110
 *                function should call png_error(png_ptr, "Error msg").
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   111
 *                May be NULL, in which case libpng's default function will
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   112
 *                be used.
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   113
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
void PNGAPI
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   115
png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr,
43321
2b8d397c03a4 8167228: Update to libpng 1.6.28
prr
parents: 40436
diff changeset
   116
    png_rw_ptr read_data_fn)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
{
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   118
   if (png_ptr == NULL)
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   119
      return;
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   120
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
   png_ptr->io_ptr = io_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   123
#ifdef PNG_STDIO_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
   if (read_data_fn != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
      png_ptr->read_data_fn = read_data_fn;
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   126
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
      png_ptr->read_data_fn = png_default_read_data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
   png_ptr->read_data_fn = read_data_fn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   133
#ifdef PNG_WRITE_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
   /* It is an error to write to a read device */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
   if (png_ptr->write_data_fn != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
      png_ptr->write_data_fn = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
      png_warning(png_ptr,
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   139
          "Can't set both read_data_fn and write_data_fn in the"
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   140
          " same structure");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
   }
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   142
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
10576
db3409425573 7088287: libpng need to be updated.
bae
parents: 5506
diff changeset
   144
#ifdef PNG_WRITE_FLUSH_SUPPORTED
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
   png_ptr->output_flush_fn = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
}
29913
95258013e132 8069198: Upgrade image library
azvegint
parents: 25859
diff changeset
   148
#endif /* READ */