| @@ -93,7 +93,6 @@ namespace pnglibNamespace | |||
| #define PNG_ALIGNED_MEMORY_SUPPORTED | |||
| #define PNG_BENIGN_ERRORS_SUPPORTED | |||
| #define PNG_BENIGN_READ_ERRORS_SUPPORTED | |||
| #define PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED | |||
| #define PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED | |||
| #define PNG_COLORSPACE_SUPPORTED | |||
| #define PNG_CONSOLE_IO_SUPPORTED | |||
| @@ -109,7 +108,6 @@ namespace pnglibNamespace | |||
| #define PNG_INCH_CONVERSIONS_SUPPORTED | |||
| #define PNG_INFO_IMAGE_SUPPORTED | |||
| #define PNG_IO_STATE_SUPPORTED | |||
| #define PNG_MNG_FEATURES_SUPPORTED | |||
| #define PNG_POINTER_INDEXING_SUPPORTED | |||
| #define PNG_PROGRESSIVE_READ_SUPPORTED | |||
| #define PNG_READ_16BIT_SUPPORTED | |||
| @@ -273,6 +271,19 @@ namespace pnglibNamespace | |||
| #define PNG_sCAL_PRECISION 5 | |||
| #define PNG_sRGB_PROFILE_CHECKS 2 | |||
| #define PNG_LINKAGE_API extern | |||
| #define PNG_LINKAGE_FUNCTION extern | |||
| #define PNG_ARM_NEON_OPT 0 | |||
| #if ! defined (PNG_USER_WIDTH_MAX) | |||
| #define PNG_USER_WIDTH_MAX 1000000 | |||
| #endif | |||
| #if ! defined (PNG_USER_HEIGHT_MAX) | |||
| #define PNG_USER_HEIGHT_MAX 1000000 | |||
| #endif | |||
| #define png_debug(a, b) | |||
| #define png_debug1(a, b, c) | |||
| #define png_debug2(a, b, c, d) | |||
| @@ -288,6 +299,24 @@ namespace pnglibNamespace | |||
| #include "pnglib/pngread.c" | |||
| #include "pnglib/pngpread.c" | |||
| #include "pnglib/pngrio.c" | |||
| void png_do_expand_palette (png_row_infop, png_bytep, png_const_colorp, png_const_bytep, int); | |||
| void png_do_expand (png_row_infop, png_bytep, png_const_color_16p); | |||
| void png_do_chop (png_row_infop, png_bytep); | |||
| void png_do_quantize (png_row_infop, png_bytep, png_const_bytep, png_const_bytep); | |||
| void png_do_gray_to_rgb (png_row_infop, png_bytep); | |||
| void png_do_unshift (png_row_infop, png_bytep, png_const_color_8p); | |||
| void png_do_unpack (png_row_infop, png_bytep); | |||
| int png_do_rgb_to_gray (png_structrp, png_row_infop, png_bytep); | |||
| void png_do_compose (png_row_infop, png_bytep, png_structrp); | |||
| void png_do_gamma (png_row_infop, png_bytep, png_structrp); | |||
| void png_do_encode_alpha (png_row_infop, png_bytep, png_structrp); | |||
| void png_do_scale_16_to_8 (png_row_infop, png_bytep); | |||
| void png_do_expand_16 (png_row_infop, png_bytep); | |||
| void png_do_read_filler (png_row_infop, png_bytep, png_uint_32, png_uint_32); | |||
| void png_do_read_invert_alpha (png_row_infop, png_bytep); | |||
| void png_do_read_swap_alpha (png_row_infop, png_bytep); | |||
| #include "pnglib/pngrtran.c" | |||
| #include "pnglib/pngrutil.c" | |||
| #include "pnglib/pngset.c" | |||
| @@ -1,109 +1,134 @@ | |||
| This copy of the libpng notices is provided for your convenience. In case of | |||
| any discrepancy between this copy and the notices in the file png.h that is | |||
| included in the libpng distribution, the latter shall prevail. | |||
| COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: | |||
| If you modify libpng you may insert additional notices immediately following | |||
| this sentence. | |||
| libpng versions 1.2.6, August 15, 2004, through 1.2.21, October 4, 2007, are | |||
| Copyright (c) 2004, 2006-2007 Glenn Randers-Pehrson, and are | |||
| distributed according to the same disclaimer and license as libpng-1.2.5 | |||
| with the following individual added to the list of Contributing Authors | |||
| Cosmin Truta | |||
| libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are | |||
| Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are | |||
| distributed according to the same disclaimer and license as libpng-1.0.6 | |||
| with the following individuals added to the list of Contributing Authors | |||
| Simon-Pierre Cadieux | |||
| Eric S. Raymond | |||
| Gilles Vollant | |||
| COPYRIGHT NOTICE, DISCLAIMER, and LICENSE | |||
| ========================================= | |||
| PNG Reference Library License version 2 | |||
| --------------------------------------- | |||
| * Copyright (c) 1995-2019 The PNG Reference Library Authors. | |||
| * Copyright (c) 2018-2019 Cosmin Truta. | |||
| * Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson. | |||
| * Copyright (c) 1996-1997 Andreas Dilger. | |||
| * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. | |||
| The software is supplied "as is", without warranty of any kind, | |||
| express or implied, including, without limitation, the warranties | |||
| of merchantability, fitness for a particular purpose, title, and | |||
| non-infringement. In no event shall the Copyright owners, or | |||
| anyone distributing the software, be liable for any damages or | |||
| other liability, whether in contract, tort or otherwise, arising | |||
| from, out of, or in connection with the software, or the use or | |||
| other dealings in the software, even if advised of the possibility | |||
| of such damage. | |||
| Permission is hereby granted to use, copy, modify, and distribute | |||
| this software, or portions hereof, for any purpose, without fee, | |||
| subject to the following restrictions: | |||
| 1. The origin of this software must not be misrepresented; you | |||
| must not claim that you wrote the original software. If you | |||
| use this software in a product, an acknowledgment in the product | |||
| documentation would be appreciated, but is not required. | |||
| 2. Altered source versions must be plainly marked as such, and must | |||
| not be misrepresented as being the original software. | |||
| 3. This Copyright notice may not be removed or altered from any | |||
| source or altered source distribution. | |||
| PNG Reference Library License version 1 (for libpng 0.5 through 1.6.35) | |||
| ----------------------------------------------------------------------- | |||
| libpng versions 1.0.7, July 1, 2000, through 1.6.35, July 15, 2018 are | |||
| Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson, are | |||
| derived from libpng-1.0.6, and are distributed according to the same | |||
| disclaimer and license as libpng-1.0.6 with the following individuals | |||
| added to the list of Contributing Authors: | |||
| Simon-Pierre Cadieux | |||
| Eric S. Raymond | |||
| Mans Rullgard | |||
| Cosmin Truta | |||
| Gilles Vollant | |||
| James Yu | |||
| Mandar Sahastrabuddhe | |||
| Google Inc. | |||
| Vadim Barkov | |||
| and with the following additions to the disclaimer: | |||
| There is no warranty against interference with your enjoyment of the | |||
| library or against infringement. There is no warranty that our | |||
| efforts or the library will fulfill any of your particular purposes | |||
| or needs. This library is provided with all faults, and the entire | |||
| risk of satisfactory quality, performance, accuracy, and effort is with | |||
| the user. | |||
| There is no warranty against interference with your enjoyment of | |||
| the library or against infringement. There is no warranty that our | |||
| efforts or the library will fulfill any of your particular purposes | |||
| or needs. This library is provided with all faults, and the entire | |||
| risk of satisfactory quality, performance, accuracy, and effort is | |||
| with the user. | |||
| Some files in the "contrib" directory and some configure-generated | |||
| files that are distributed with libpng have other copyright owners, and | |||
| are released under other open source licenses. | |||
| libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are | |||
| Copyright (c) 1998, 1999 Glenn Randers-Pehrson, and are | |||
| distributed according to the same disclaimer and license as libpng-0.96, | |||
| with the following individuals added to the list of Contributing Authors: | |||
| Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from | |||
| libpng-0.96, and are distributed according to the same disclaimer and | |||
| license as libpng-0.96, with the following individuals added to the | |||
| list of Contributing Authors: | |||
| Tom Lane | |||
| Glenn Randers-Pehrson | |||
| Willem van Schaik | |||
| Tom Lane | |||
| Glenn Randers-Pehrson | |||
| Willem van Schaik | |||
| libpng versions 0.89, June 1996, through 0.96, May 1997, are | |||
| Copyright (c) 1996, 1997 Andreas Dilger | |||
| Distributed according to the same disclaimer and license as libpng-0.88, | |||
| with the following individuals added to the list of Contributing Authors: | |||
| Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88, | |||
| and are distributed according to the same disclaimer and license as | |||
| libpng-0.88, with the following individuals added to the list of | |||
| Contributing Authors: | |||
| John Bowler | |||
| Kevin Bracey | |||
| Sam Bushell | |||
| Magnus Holmgren | |||
| Greg Roelofs | |||
| Tom Tanner | |||
| John Bowler | |||
| Kevin Bracey | |||
| Sam Bushell | |||
| Magnus Holmgren | |||
| Greg Roelofs | |||
| Tom Tanner | |||
| Some files in the "scripts" directory have other copyright owners, | |||
| but are released under this license. | |||
| libpng versions 0.5, May 1995, through 0.88, January 1996, are | |||
| Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. | |||
| Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. | |||
| For the purposes of this copyright and license, "Contributing Authors" | |||
| is defined as the following set of individuals: | |||
| Andreas Dilger | |||
| Dave Martindale | |||
| Guy Eric Schalnat | |||
| Paul Schmidt | |||
| Tim Wegner | |||
| The PNG Reference Library is supplied "AS IS". The Contributing Authors | |||
| and Group 42, Inc. disclaim all warranties, expressed or implied, | |||
| including, without limitation, the warranties of merchantability and of | |||
| fitness for any purpose. The Contributing Authors and Group 42, Inc. | |||
| assume no liability for direct, indirect, incidental, special, exemplary, | |||
| or consequential damages, which may result from the use of the PNG | |||
| Reference Library, even if advised of the possibility of such damage. | |||
| Andreas Dilger | |||
| Dave Martindale | |||
| Guy Eric Schalnat | |||
| Paul Schmidt | |||
| Tim Wegner | |||
| The PNG Reference Library is supplied "AS IS". The Contributing | |||
| Authors and Group 42, Inc. disclaim all warranties, expressed or | |||
| implied, including, without limitation, the warranties of | |||
| merchantability and of fitness for any purpose. The Contributing | |||
| Authors and Group 42, Inc. assume no liability for direct, indirect, | |||
| incidental, special, exemplary, or consequential damages, which may | |||
| result from the use of the PNG Reference Library, even if advised of | |||
| the possibility of such damage. | |||
| Permission is hereby granted to use, copy, modify, and distribute this | |||
| source code, or portions hereof, for any purpose, without fee, subject | |||
| to the following restrictions: | |||
| 1. The origin of this source code must not be misrepresented. | |||
| 2. Altered versions must be plainly marked as such and must not | |||
| be misrepresented as being the original source. | |||
| 3. This Copyright notice may not be removed or altered from any | |||
| source or altered source distribution. | |||
| The Contributing Authors and Group 42, Inc. specifically permit, without | |||
| fee, and encourage the use of this source code as a component to | |||
| supporting the PNG file format in commercial products. If you use this | |||
| source code in a product, acknowledgment is not required but would be | |||
| appreciated. | |||
| A "png_get_copyright" function is available, for convenient use in "about" | |||
| boxes and the like: | |||
| printf("%s",png_get_copyright(NULL)); | |||
| 1. The origin of this source code must not be misrepresented. | |||
| Also, the PNG logo (in PNG format, of course) is supplied in the | |||
| files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31). | |||
| 2. Altered versions must be plainly marked as such and must not | |||
| be misrepresented as being the original source. | |||
| Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a | |||
| certification mark of the Open Source Initiative. | |||
| 3. This Copyright notice may not be removed or altered from any | |||
| source or altered source distribution. | |||
| Glenn Randers-Pehrson | |||
| glennrp at users.sourceforge.net | |||
| October 4, 2007 | |||
| The Contributing Authors and Group 42, Inc. specifically permit, | |||
| without fee, and encourage the use of this source code as a component | |||
| to supporting the PNG file format in commercial products. If you use | |||
| this source code in a product, acknowledgment is not required but would | |||
| be appreciated. | |||
| @@ -0,0 +1,153 @@ | |||
| /* pngdebug.h - Debugging macros for libpng, also used in pngtest.c | |||
| * | |||
| * Copyright (c) 2018 Cosmin Truta | |||
| * Copyright (c) 1998-2002,2004,2006-2013 Glenn Randers-Pehrson | |||
| * Copyright (c) 1996-1997 Andreas Dilger | |||
| * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. | |||
| * | |||
| * This code is released under the libpng license. | |||
| * For conditions of distribution and use, see the disclaimer | |||
| * and license in png.h | |||
| */ | |||
| /* Define PNG_DEBUG at compile time for debugging information. Higher | |||
| * numbers for PNG_DEBUG mean more debugging information. This has | |||
| * only been added since version 0.95 so it is not implemented throughout | |||
| * libpng yet, but more support will be added as needed. | |||
| * | |||
| * png_debug[1-2]?(level, message ,arg{0-2}) | |||
| * Expands to a statement (either a simple expression or a compound | |||
| * do..while(0) statement) that outputs a message with parameter | |||
| * substitution if PNG_DEBUG is defined to 2 or more. If PNG_DEBUG | |||
| * is undefined, 0 or 1 every png_debug expands to a simple expression | |||
| * (actually ((void)0)). | |||
| * | |||
| * level: level of detail of message, starting at 0. A level 'n' | |||
| * message is preceded by 'n' 3-space indentations (not implemented | |||
| * on Microsoft compilers unless PNG_DEBUG_FILE is also | |||
| * defined, to allow debug DLL compilation with no standard IO). | |||
| * message: a printf(3) style text string. A trailing '\n' is added | |||
| * to the message. | |||
| * arg: 0 to 2 arguments for printf(3) style substitution in message. | |||
| */ | |||
| #ifndef PNGDEBUG_H | |||
| #define PNGDEBUG_H | |||
| /* These settings control the formatting of messages in png.c and pngerror.c */ | |||
| /* Moved to pngdebug.h at 1.5.0 */ | |||
| # ifndef PNG_LITERAL_SHARP | |||
| # define PNG_LITERAL_SHARP 0x23 | |||
| # endif | |||
| # ifndef PNG_LITERAL_LEFT_SQUARE_BRACKET | |||
| # define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5b | |||
| # endif | |||
| # ifndef PNG_LITERAL_RIGHT_SQUARE_BRACKET | |||
| # define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5d | |||
| # endif | |||
| # ifndef PNG_STRING_NEWLINE | |||
| # define PNG_STRING_NEWLINE "\n" | |||
| # endif | |||
| #ifdef PNG_DEBUG | |||
| # if (PNG_DEBUG > 0) | |||
| # if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER) | |||
| # include <crtdbg.h> | |||
| # if (PNG_DEBUG > 1) | |||
| # ifndef _DEBUG | |||
| # define _DEBUG | |||
| # endif | |||
| # ifndef png_debug | |||
| # define png_debug(l,m) _RPT0(_CRT_WARN,m PNG_STRING_NEWLINE) | |||
| # endif | |||
| # ifndef png_debug1 | |||
| # define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m PNG_STRING_NEWLINE,p1) | |||
| # endif | |||
| # ifndef png_debug2 | |||
| # define png_debug2(l,m,p1,p2) \ | |||
| _RPT2(_CRT_WARN,m PNG_STRING_NEWLINE,p1,p2) | |||
| # endif | |||
| # endif | |||
| # else /* PNG_DEBUG_FILE || !_MSC_VER */ | |||
| # ifndef PNG_STDIO_SUPPORTED | |||
| # include <stdio.h> /* not included yet */ | |||
| # endif | |||
| # ifndef PNG_DEBUG_FILE | |||
| # define PNG_DEBUG_FILE stderr | |||
| # endif /* PNG_DEBUG_FILE */ | |||
| # if (PNG_DEBUG > 1) | |||
| # ifdef __STDC__ | |||
| # ifndef png_debug | |||
| # define png_debug(l,m) \ | |||
| do { \ | |||
| int num_tabs=l; \ | |||
| fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \ | |||
| (num_tabs==2 ? " " : (num_tabs>2 ? " " : "")))); \ | |||
| } while (0) | |||
| # endif | |||
| # ifndef png_debug1 | |||
| # define png_debug1(l,m,p1) \ | |||
| do { \ | |||
| int num_tabs=l; \ | |||
| fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \ | |||
| (num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1); \ | |||
| } while (0) | |||
| # endif | |||
| # ifndef png_debug2 | |||
| # define png_debug2(l,m,p1,p2) \ | |||
| do { \ | |||
| int num_tabs=l; \ | |||
| fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \ | |||
| (num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1,p2);\ | |||
| } while (0) | |||
| # endif | |||
| # else /* __STDC __ */ | |||
| # ifndef png_debug | |||
| # define png_debug(l,m) \ | |||
| do { \ | |||
| int num_tabs=l; \ | |||
| char format[256]; \ | |||
| snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ | |||
| (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ | |||
| m,PNG_STRING_NEWLINE); \ | |||
| fprintf(PNG_DEBUG_FILE,format); \ | |||
| } while (0) | |||
| # endif | |||
| # ifndef png_debug1 | |||
| # define png_debug1(l,m,p1) \ | |||
| do { \ | |||
| int num_tabs=l; \ | |||
| char format[256]; \ | |||
| snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ | |||
| (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ | |||
| m,PNG_STRING_NEWLINE); \ | |||
| fprintf(PNG_DEBUG_FILE,format,p1); \ | |||
| } while (0) | |||
| # endif | |||
| # ifndef png_debug2 | |||
| # define png_debug2(l,m,p1,p2) \ | |||
| do { \ | |||
| int num_tabs=l; \ | |||
| char format[256]; \ | |||
| snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ | |||
| (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ | |||
| m,PNG_STRING_NEWLINE); \ | |||
| fprintf(PNG_DEBUG_FILE,format,p1,p2); \ | |||
| } while (0) | |||
| # endif | |||
| # endif /* __STDC __ */ | |||
| # endif /* (PNG_DEBUG > 1) */ | |||
| # endif /* _MSC_VER */ | |||
| # endif /* (PNG_DEBUG > 0) */ | |||
| #endif /* PNG_DEBUG */ | |||
| #ifndef png_debug | |||
| # define png_debug(l, m) ((void)0) | |||
| #endif | |||
| #ifndef png_debug1 | |||
| # define png_debug1(l, m, p1) ((void)0) | |||
| #endif | |||
| #ifndef png_debug2 | |||
| # define png_debug2(l, m, p1, p2) ((void)0) | |||
| #endif | |||
| #endif /* PNGDEBUG_H */ | |||
| @@ -1,260 +1,267 @@ | |||
| /* pnginfo.h - header file for PNG reference library | |||
| * | |||
| * Copyright (c) 1998-2013 Glenn Randers-Pehrson | |||
| * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | |||
| * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | |||
| * | |||
| * Last changed in libpng 1.6.1 [March 28, 2013] | |||
| * | |||
| * This code is released under the libpng license. | |||
| * For conditions of distribution and use, see the disclaimer | |||
| * and license in png.h | |||
| */ | |||
| /* png_info is a structure that holds the information in a PNG file so | |||
| * that the application can find out the characteristics of the image. | |||
| * If you are reading the file, this structure will tell you what is | |||
| * in the PNG file. If you are writing the file, fill in the information | |||
| * you want to put into the PNG file, using png_set_*() functions, then | |||
| * call png_write_info(). | |||
| * | |||
| * The names chosen should be very close to the PNG specification, so | |||
| * consult that document for information about the meaning of each field. | |||
| * | |||
| * With libpng < 0.95, it was only possible to directly set and read the | |||
| * the values in the png_info_struct, which meant that the contents and | |||
| * order of the values had to remain fixed. With libpng 0.95 and later, | |||
| * however, there are now functions that abstract the contents of | |||
| * png_info_struct from the application, so this makes it easier to use | |||
| * libpng with dynamic libraries, and even makes it possible to use | |||
| * libraries that don't have all of the libpng ancillary chunk-handing | |||
| * functionality. In libpng-1.5.0 this was moved into a separate private | |||
| * file that is not visible to applications. | |||
| * | |||
| * The following members may have allocated storage attached that should be | |||
| * cleaned up before the structure is discarded: palette, trans, text, | |||
| * pcal_purpose, pcal_units, pcal_params, hist, iccp_name, iccp_profile, | |||
| * splt_palettes, scal_unit, row_pointers, and unknowns. By default, these | |||
| * are automatically freed when the info structure is deallocated, if they were | |||
| * allocated internally by libpng. This behavior can be changed by means | |||
| * of the png_data_freer() function. | |||
| * | |||
| * More allocation details: all the chunk-reading functions that | |||
| * change these members go through the corresponding png_set_* | |||
| * functions. A function to clear these members is available: see | |||
| * png_free_data(). The png_set_* functions do not depend on being | |||
| * able to point info structure members to any of the storage they are | |||
| * passed (they make their own copies), EXCEPT that the png_set_text | |||
| * functions use the same storage passed to them in the text_ptr or | |||
| * itxt_ptr structure argument, and the png_set_rows and png_set_unknowns | |||
| * functions do not make their own copies. | |||
| */ | |||
| #ifndef PNGINFO_H | |||
| #define PNGINFO_H | |||
| struct png_info_def | |||
| { | |||
| /* The following are necessary for every PNG file */ | |||
| png_uint_32 width; /* width of image in pixels (from IHDR) */ | |||
| png_uint_32 height; /* height of image in pixels (from IHDR) */ | |||
| png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */ | |||
| png_size_t rowbytes; /* bytes needed to hold an untransformed row */ | |||
| png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */ | |||
| png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */ | |||
| png_uint_16 num_trans; /* number of transparent palette color (tRNS) */ | |||
| png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */ | |||
| png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */ | |||
| /* The following three should have been named *_method not *_type */ | |||
| png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */ | |||
| png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */ | |||
| png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */ | |||
| /* The following are set by png_set_IHDR, called from the application on | |||
| * write, but the are never actually used by the write code. | |||
| */ | |||
| png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */ | |||
| png_byte pixel_depth; /* number of bits per pixel */ | |||
| png_byte spare_byte; /* to align the data, and for future use */ | |||
| #ifdef PNG_READ_SUPPORTED | |||
| /* This is never set during write */ | |||
| png_byte signature[8]; /* magic bytes read by libpng from start of file */ | |||
| #endif | |||
| /* The rest of the data is optional. If you are reading, check the | |||
| * valid field to see if the information in these are valid. If you | |||
| * are writing, set the valid field to those chunks you want written, | |||
| * and initialize the appropriate fields below. | |||
| */ | |||
| #if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED) | |||
| /* png_colorspace only contains 'flags' if neither GAMMA or COLORSPACE are | |||
| * defined. When COLORSPACE is switched on all the colorspace-defining | |||
| * chunks should be enabled, when GAMMA is switched on all the gamma-defining | |||
| * chunks should be enabled. If this is not done it becomes possible to read | |||
| * inconsistent PNG files and assign a probably incorrect interpretation to | |||
| * the information. (In other words, by carefully choosing which chunks to | |||
| * recognize the system configuration can select an interpretation for PNG | |||
| * files containing ambiguous data and this will result in inconsistent | |||
| * behavior between different libpng builds!) | |||
| */ | |||
| png_colorspace colorspace; | |||
| #endif | |||
| #ifdef PNG_iCCP_SUPPORTED | |||
| /* iCCP chunk data. */ | |||
| png_charp iccp_name; /* profile name */ | |||
| png_bytep iccp_profile; /* International Color Consortium profile data */ | |||
| png_uint_32 iccp_proflen; /* ICC profile data length */ | |||
| #endif | |||
| #ifdef PNG_TEXT_SUPPORTED | |||
| /* The tEXt, and zTXt chunks contain human-readable textual data in | |||
| * uncompressed, compressed, and optionally compressed forms, respectively. | |||
| * The data in "text" is an array of pointers to uncompressed, | |||
| * null-terminated C strings. Each chunk has a keyword that describes the | |||
| * textual data contained in that chunk. Keywords are not required to be | |||
| * unique, and the text string may be empty. Any number of text chunks may | |||
| * be in an image. | |||
| */ | |||
| int num_text; /* number of comments read or comments to write */ | |||
| int max_text; /* current size of text array */ | |||
| png_textp text; /* array of comments read or comments to write */ | |||
| #endif /* PNG_TEXT_SUPPORTED */ | |||
| #ifdef PNG_tIME_SUPPORTED | |||
| /* The tIME chunk holds the last time the displayed image data was | |||
| * modified. See the png_time struct for the contents of this struct. | |||
| */ | |||
| png_time mod_time; | |||
| #endif | |||
| #ifdef PNG_sBIT_SUPPORTED | |||
| /* The sBIT chunk specifies the number of significant high-order bits | |||
| * in the pixel data. Values are in the range [1, bit_depth], and are | |||
| * only specified for the channels in the pixel data. The contents of | |||
| * the low-order bits is not specified. Data is valid if | |||
| * (valid & PNG_INFO_sBIT) is non-zero. | |||
| */ | |||
| png_color_8 sig_bit; /* significant bits in color channels */ | |||
| #endif | |||
| #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \ | |||
| defined(PNG_READ_BACKGROUND_SUPPORTED) | |||
| /* The tRNS chunk supplies transparency data for paletted images and | |||
| * other image types that don't need a full alpha channel. There are | |||
| * "num_trans" transparency values for a paletted image, stored in the | |||
| * same order as the palette colors, starting from index 0. Values | |||
| * for the data are in the range [0, 255], ranging from fully transparent | |||
| * to fully opaque, respectively. For non-paletted images, there is a | |||
| * single color specified that should be treated as fully transparent. | |||
| * Data is valid if (valid & PNG_INFO_tRNS) is non-zero. | |||
| */ | |||
| png_bytep trans_alpha; /* alpha values for paletted image */ | |||
| png_color_16 trans_color; /* transparent color for non-palette image */ | |||
| #endif | |||
| #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) | |||
| /* The bKGD chunk gives the suggested image background color if the | |||
| * display program does not have its own background color and the image | |||
| * is needs to composited onto a background before display. The colors | |||
| * in "background" are normally in the same color space/depth as the | |||
| * pixel data. Data is valid if (valid & PNG_INFO_bKGD) is non-zero. | |||
| */ | |||
| png_color_16 background; | |||
| #endif | |||
| #ifdef PNG_oFFs_SUPPORTED | |||
| /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards | |||
| * and downwards from the top-left corner of the display, page, or other | |||
| * application-specific co-ordinate space. See the PNG_OFFSET_ defines | |||
| * below for the unit types. Valid if (valid & PNG_INFO_oFFs) non-zero. | |||
| */ | |||
| png_int_32 x_offset; /* x offset on page */ | |||
| png_int_32 y_offset; /* y offset on page */ | |||
| png_byte offset_unit_type; /* offset units type */ | |||
| #endif | |||
| #ifdef PNG_pHYs_SUPPORTED | |||
| /* The pHYs chunk gives the physical pixel density of the image for | |||
| * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_ | |||
| * defines below). Data is valid if (valid & PNG_INFO_pHYs) is non-zero. | |||
| */ | |||
| png_uint_32 x_pixels_per_unit; /* horizontal pixel density */ | |||
| png_uint_32 y_pixels_per_unit; /* vertical pixel density */ | |||
| png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */ | |||
| #endif | |||
| #ifdef PNG_hIST_SUPPORTED | |||
| /* The hIST chunk contains the relative frequency or importance of the | |||
| * various palette entries, so that a viewer can intelligently select a | |||
| * reduced-color palette, if required. Data is an array of "num_palette" | |||
| * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST) | |||
| * is non-zero. | |||
| */ | |||
| png_uint_16p hist; | |||
| #endif | |||
| #ifdef PNG_pCAL_SUPPORTED | |||
| /* The pCAL chunk describes a transformation between the stored pixel | |||
| * values and original physical data values used to create the image. | |||
| * The integer range [0, 2^bit_depth - 1] maps to the floating-point | |||
| * range given by [pcal_X0, pcal_X1], and are further transformed by a | |||
| * (possibly non-linear) transformation function given by "pcal_type" | |||
| * and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_ | |||
| * defines below, and the PNG-Group's PNG extensions document for a | |||
| * complete description of the transformations and how they should be | |||
| * implemented, and for a description of the ASCII parameter strings. | |||
| * Data values are valid if (valid & PNG_INFO_pCAL) non-zero. | |||
| */ | |||
| png_charp pcal_purpose; /* pCAL chunk description string */ | |||
| png_int_32 pcal_X0; /* minimum value */ | |||
| png_int_32 pcal_X1; /* maximum value */ | |||
| png_charp pcal_units; /* Latin-1 string giving physical units */ | |||
| png_charpp pcal_params; /* ASCII strings containing parameter values */ | |||
| png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */ | |||
| png_byte pcal_nparams; /* number of parameters given in pcal_params */ | |||
| #endif | |||
| /* New members added in libpng-1.0.6 */ | |||
| png_uint_32 free_me; /* flags items libpng is responsible for freeing */ | |||
| #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED | |||
| /* Storage for unknown chunks that the library doesn't recognize. */ | |||
| png_unknown_chunkp unknown_chunks; | |||
| /* The type of this field is limited by the type of | |||
| * png_struct::user_chunk_cache_max, else overflow can occur. | |||
| */ | |||
| int unknown_chunks_num; | |||
| #endif | |||
| #ifdef PNG_sPLT_SUPPORTED | |||
| /* Data on sPLT chunks (there may be more than one). */ | |||
| png_sPLT_tp splt_palettes; | |||
| int splt_palettes_num; /* Match type returned by png_get API */ | |||
| #endif | |||
| #ifdef PNG_sCAL_SUPPORTED | |||
| /* The sCAL chunk describes the actual physical dimensions of the | |||
| * subject matter of the graphic. The chunk contains a unit specification | |||
| * a byte value, and two ASCII strings representing floating-point | |||
| * values. The values are width and height corresponsing to one pixel | |||
| * in the image. Data values are valid if (valid & PNG_INFO_sCAL) is | |||
| * non-zero. | |||
| */ | |||
| png_byte scal_unit; /* unit of physical scale */ | |||
| png_charp scal_s_width; /* string containing height */ | |||
| png_charp scal_s_height; /* string containing width */ | |||
| #endif | |||
| #ifdef PNG_INFO_IMAGE_SUPPORTED | |||
| /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS) | |||
| non-zero */ | |||
| /* Data valid if (valid & PNG_INFO_IDAT) non-zero */ | |||
| png_bytepp row_pointers; /* the image bits */ | |||
| #endif | |||
| }; | |||
| #endif /* PNGINFO_H */ | |||
| /* pnginfo.h - header file for PNG reference library | |||
| * | |||
| * Copyright (c) 2018 Cosmin Truta | |||
| * Copyright (c) 1998-2002,2004,2006-2013,2018 Glenn Randers-Pehrson | |||
| * Copyright (c) 1996-1997 Andreas Dilger | |||
| * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. | |||
| * | |||
| * This code is released under the libpng license. | |||
| * For conditions of distribution and use, see the disclaimer | |||
| * and license in png.h | |||
| */ | |||
| /* png_info is a structure that holds the information in a PNG file so | |||
| * that the application can find out the characteristics of the image. | |||
| * If you are reading the file, this structure will tell you what is | |||
| * in the PNG file. If you are writing the file, fill in the information | |||
| * you want to put into the PNG file, using png_set_*() functions, then | |||
| * call png_write_info(). | |||
| * | |||
| * The names chosen should be very close to the PNG specification, so | |||
| * consult that document for information about the meaning of each field. | |||
| * | |||
| * With libpng < 0.95, it was only possible to directly set and read the | |||
| * the values in the png_info_struct, which meant that the contents and | |||
| * order of the values had to remain fixed. With libpng 0.95 and later, | |||
| * however, there are now functions that abstract the contents of | |||
| * png_info_struct from the application, so this makes it easier to use | |||
| * libpng with dynamic libraries, and even makes it possible to use | |||
| * libraries that don't have all of the libpng ancillary chunk-handing | |||
| * functionality. In libpng-1.5.0 this was moved into a separate private | |||
| * file that is not visible to applications. | |||
| * | |||
| * The following members may have allocated storage attached that should be | |||
| * cleaned up before the structure is discarded: palette, trans, text, | |||
| * pcal_purpose, pcal_units, pcal_params, hist, iccp_name, iccp_profile, | |||
| * splt_palettes, scal_unit, row_pointers, and unknowns. By default, these | |||
| * are automatically freed when the info structure is deallocated, if they were | |||
| * allocated internally by libpng. This behavior can be changed by means | |||
| * of the png_data_freer() function. | |||
| * | |||
| * More allocation details: all the chunk-reading functions that | |||
| * change these members go through the corresponding png_set_* | |||
| * functions. A function to clear these members is available: see | |||
| * png_free_data(). The png_set_* functions do not depend on being | |||
| * able to point info structure members to any of the storage they are | |||
| * passed (they make their own copies), EXCEPT that the png_set_text | |||
| * functions use the same storage passed to them in the text_ptr or | |||
| * itxt_ptr structure argument, and the png_set_rows and png_set_unknowns | |||
| * functions do not make their own copies. | |||
| */ | |||
| #ifndef PNGINFO_H | |||
| #define PNGINFO_H | |||
| struct png_info_def | |||
| { | |||
| /* The following are necessary for every PNG file */ | |||
| png_uint_32 width; /* width of image in pixels (from IHDR) */ | |||
| png_uint_32 height; /* height of image in pixels (from IHDR) */ | |||
| png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */ | |||
| size_t rowbytes; /* bytes needed to hold an untransformed row */ | |||
| png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */ | |||
| png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */ | |||
| png_uint_16 num_trans; /* number of transparent palette color (tRNS) */ | |||
| png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */ | |||
| png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */ | |||
| /* The following three should have been named *_method not *_type */ | |||
| png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */ | |||
| png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */ | |||
| png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */ | |||
| /* The following are set by png_set_IHDR, called from the application on | |||
| * write, but the are never actually used by the write code. | |||
| */ | |||
| png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */ | |||
| png_byte pixel_depth; /* number of bits per pixel */ | |||
| png_byte spare_byte; /* to align the data, and for future use */ | |||
| #ifdef PNG_READ_SUPPORTED | |||
| /* This is never set during write */ | |||
| png_byte signature[8]; /* magic bytes read by libpng from start of file */ | |||
| #endif | |||
| /* The rest of the data is optional. If you are reading, check the | |||
| * valid field to see if the information in these are valid. If you | |||
| * are writing, set the valid field to those chunks you want written, | |||
| * and initialize the appropriate fields below. | |||
| */ | |||
| #if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED) | |||
| /* png_colorspace only contains 'flags' if neither GAMMA or COLORSPACE are | |||
| * defined. When COLORSPACE is switched on all the colorspace-defining | |||
| * chunks should be enabled, when GAMMA is switched on all the gamma-defining | |||
| * chunks should be enabled. If this is not done it becomes possible to read | |||
| * inconsistent PNG files and assign a probably incorrect interpretation to | |||
| * the information. (In other words, by carefully choosing which chunks to | |||
| * recognize the system configuration can select an interpretation for PNG | |||
| * files containing ambiguous data and this will result in inconsistent | |||
| * behavior between different libpng builds!) | |||
| */ | |||
| png_colorspace colorspace; | |||
| #endif | |||
| #ifdef PNG_iCCP_SUPPORTED | |||
| /* iCCP chunk data. */ | |||
| png_charp iccp_name; /* profile name */ | |||
| png_bytep iccp_profile; /* International Color Consortium profile data */ | |||
| png_uint_32 iccp_proflen; /* ICC profile data length */ | |||
| #endif | |||
| #ifdef PNG_TEXT_SUPPORTED | |||
| /* The tEXt, and zTXt chunks contain human-readable textual data in | |||
| * uncompressed, compressed, and optionally compressed forms, respectively. | |||
| * The data in "text" is an array of pointers to uncompressed, | |||
| * null-terminated C strings. Each chunk has a keyword that describes the | |||
| * textual data contained in that chunk. Keywords are not required to be | |||
| * unique, and the text string may be empty. Any number of text chunks may | |||
| * be in an image. | |||
| */ | |||
| int num_text; /* number of comments read or comments to write */ | |||
| int max_text; /* current size of text array */ | |||
| png_textp text; /* array of comments read or comments to write */ | |||
| #endif /* TEXT */ | |||
| #ifdef PNG_tIME_SUPPORTED | |||
| /* The tIME chunk holds the last time the displayed image data was | |||
| * modified. See the png_time struct for the contents of this struct. | |||
| */ | |||
| png_time mod_time; | |||
| #endif | |||
| #ifdef PNG_sBIT_SUPPORTED | |||
| /* The sBIT chunk specifies the number of significant high-order bits | |||
| * in the pixel data. Values are in the range [1, bit_depth], and are | |||
| * only specified for the channels in the pixel data. The contents of | |||
| * the low-order bits is not specified. Data is valid if | |||
| * (valid & PNG_INFO_sBIT) is non-zero. | |||
| */ | |||
| png_color_8 sig_bit; /* significant bits in color channels */ | |||
| #endif | |||
| #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \ | |||
| defined(PNG_READ_BACKGROUND_SUPPORTED) | |||
| /* The tRNS chunk supplies transparency data for paletted images and | |||
| * other image types that don't need a full alpha channel. There are | |||
| * "num_trans" transparency values for a paletted image, stored in the | |||
| * same order as the palette colors, starting from index 0. Values | |||
| * for the data are in the range [0, 255], ranging from fully transparent | |||
| * to fully opaque, respectively. For non-paletted images, there is a | |||
| * single color specified that should be treated as fully transparent. | |||
| * Data is valid if (valid & PNG_INFO_tRNS) is non-zero. | |||
| */ | |||
| png_bytep trans_alpha; /* alpha values for paletted image */ | |||
| png_color_16 trans_color; /* transparent color for non-palette image */ | |||
| #endif | |||
| #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) | |||
| /* The bKGD chunk gives the suggested image background color if the | |||
| * display program does not have its own background color and the image | |||
| * is needs to composited onto a background before display. The colors | |||
| * in "background" are normally in the same color space/depth as the | |||
| * pixel data. Data is valid if (valid & PNG_INFO_bKGD) is non-zero. | |||
| */ | |||
| png_color_16 background; | |||
| #endif | |||
| #ifdef PNG_oFFs_SUPPORTED | |||
| /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards | |||
| * and downwards from the top-left corner of the display, page, or other | |||
| * application-specific co-ordinate space. See the PNG_OFFSET_ defines | |||
| * below for the unit types. Valid if (valid & PNG_INFO_oFFs) non-zero. | |||
| */ | |||
| png_int_32 x_offset; /* x offset on page */ | |||
| png_int_32 y_offset; /* y offset on page */ | |||
| png_byte offset_unit_type; /* offset units type */ | |||
| #endif | |||
| #ifdef PNG_pHYs_SUPPORTED | |||
| /* The pHYs chunk gives the physical pixel density of the image for | |||
| * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_ | |||
| * defines below). Data is valid if (valid & PNG_INFO_pHYs) is non-zero. | |||
| */ | |||
| png_uint_32 x_pixels_per_unit; /* horizontal pixel density */ | |||
| png_uint_32 y_pixels_per_unit; /* vertical pixel density */ | |||
| png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */ | |||
| #endif | |||
| #ifdef PNG_eXIf_SUPPORTED | |||
| int num_exif; /* Added at libpng-1.6.31 */ | |||
| png_bytep exif; | |||
| # ifdef PNG_READ_eXIf_SUPPORTED | |||
| png_bytep eXIf_buf; /* Added at libpng-1.6.32 */ | |||
| # endif | |||
| #endif | |||
| #ifdef PNG_hIST_SUPPORTED | |||
| /* The hIST chunk contains the relative frequency or importance of the | |||
| * various palette entries, so that a viewer can intelligently select a | |||
| * reduced-color palette, if required. Data is an array of "num_palette" | |||
| * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST) | |||
| * is non-zero. | |||
| */ | |||
| png_uint_16p hist; | |||
| #endif | |||
| #ifdef PNG_pCAL_SUPPORTED | |||
| /* The pCAL chunk describes a transformation between the stored pixel | |||
| * values and original physical data values used to create the image. | |||
| * The integer range [0, 2^bit_depth - 1] maps to the floating-point | |||
| * range given by [pcal_X0, pcal_X1], and are further transformed by a | |||
| * (possibly non-linear) transformation function given by "pcal_type" | |||
| * and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_ | |||
| * defines below, and the PNG-Group's PNG extensions document for a | |||
| * complete description of the transformations and how they should be | |||
| * implemented, and for a description of the ASCII parameter strings. | |||
| * Data values are valid if (valid & PNG_INFO_pCAL) non-zero. | |||
| */ | |||
| png_charp pcal_purpose; /* pCAL chunk description string */ | |||
| png_int_32 pcal_X0; /* minimum value */ | |||
| png_int_32 pcal_X1; /* maximum value */ | |||
| png_charp pcal_units; /* Latin-1 string giving physical units */ | |||
| png_charpp pcal_params; /* ASCII strings containing parameter values */ | |||
| png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */ | |||
| png_byte pcal_nparams; /* number of parameters given in pcal_params */ | |||
| #endif | |||
| /* New members added in libpng-1.0.6 */ | |||
| png_uint_32 free_me; /* flags items libpng is responsible for freeing */ | |||
| #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED | |||
| /* Storage for unknown chunks that the library doesn't recognize. */ | |||
| png_unknown_chunkp unknown_chunks; | |||
| /* The type of this field is limited by the type of | |||
| * png_struct::user_chunk_cache_max, else overflow can occur. | |||
| */ | |||
| int unknown_chunks_num; | |||
| #endif | |||
| #ifdef PNG_sPLT_SUPPORTED | |||
| /* Data on sPLT chunks (there may be more than one). */ | |||
| png_sPLT_tp splt_palettes; | |||
| int splt_palettes_num; /* Match type returned by png_get API */ | |||
| #endif | |||
| #ifdef PNG_sCAL_SUPPORTED | |||
| /* The sCAL chunk describes the actual physical dimensions of the | |||
| * subject matter of the graphic. The chunk contains a unit specification | |||
| * a byte value, and two ASCII strings representing floating-point | |||
| * values. The values are width and height corresponding to one pixel | |||
| * in the image. Data values are valid if (valid & PNG_INFO_sCAL) is | |||
| * non-zero. | |||
| */ | |||
| png_byte scal_unit; /* unit of physical scale */ | |||
| png_charp scal_s_width; /* string containing height */ | |||
| png_charp scal_s_height; /* string containing width */ | |||
| #endif | |||
| #ifdef PNG_INFO_IMAGE_SUPPORTED | |||
| /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS) | |||
| non-zero */ | |||
| /* Data valid if (valid & PNG_INFO_IDAT) non-zero */ | |||
| png_bytepp row_pointers; /* the image bits */ | |||
| #endif | |||
| }; | |||
| #endif /* PNGINFO_H */ | |||
| @@ -1,277 +1,284 @@ | |||
| /* pngmem.c - stub functions for memory allocation | |||
| * | |||
| * Last changed in libpng 1.6.0 [February 14, 2013] | |||
| * Copyright (c) 1998-2013 Glenn Randers-Pehrson | |||
| * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | |||
| * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | |||
| * | |||
| * This code is released under the libpng license. | |||
| * For conditions of distribution and use, see the disclaimer | |||
| * and license in png.h | |||
| * | |||
| * This file provides a location for all memory allocation. Users who | |||
| * need special memory handling are expected to supply replacement | |||
| * functions for png_malloc() and png_free(), and to use | |||
| * png_create_read_struct_2() and png_create_write_struct_2() to | |||
| * identify the replacement functions. | |||
| */ | |||
| #include "pngpriv.h" | |||
| #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) | |||
| /* Free a png_struct */ | |||
| void /* PRIVATE */ | |||
| png_destroy_png_struct(png_structrp png_ptr) | |||
| { | |||
| if (png_ptr != NULL) | |||
| { | |||
| /* png_free might call png_error and may certainly call | |||
| * png_get_mem_ptr, so fake a temporary png_struct to support this. | |||
| */ | |||
| png_struct dummy_struct = *png_ptr; | |||
| memset(png_ptr, 0, (sizeof *png_ptr)); | |||
| png_free(&dummy_struct, png_ptr); | |||
| # ifdef PNG_SETJMP_SUPPORTED | |||
| /* We may have a jmp_buf left to deallocate. */ | |||
| png_free_jmpbuf(&dummy_struct); | |||
| # endif | |||
| } | |||
| } | |||
| /* Allocate memory. For reasonable files, size should never exceed | |||
| * 64K. However, zlib may allocate more then 64K if you don't tell | |||
| * it not to. See zconf.h and png.h for more information. zlib does | |||
| * need to allocate exactly 64K, so whatever you call here must | |||
| * have the ability to do that. | |||
| */ | |||
| PNG_FUNCTION(png_voidp,PNGAPI | |||
| png_calloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) | |||
| { | |||
| png_voidp ret; | |||
| ret = png_malloc(png_ptr, size); | |||
| if (ret != NULL) | |||
| memset(ret, 0, size); | |||
| return ret; | |||
| } | |||
| /* png_malloc_base, an internal function added at libpng 1.6.0, does the work of | |||
| * allocating memory, taking into account limits and PNG_USER_MEM_SUPPORTED. | |||
| * Checking and error handling must happen outside this routine; it returns NULL | |||
| * if the allocation cannot be done (for any reason.) | |||
| */ | |||
| PNG_FUNCTION(png_voidp /* PRIVATE */, | |||
| png_malloc_base,(png_const_structrp, png_alloc_size_t size), | |||
| PNG_ALLOCATED) | |||
| { | |||
| /* Moved to png_malloc_base from png_malloc_default in 1.6.0; the DOS | |||
| * allocators have also been removed in 1.6.0, so any 16-bit system now has | |||
| * to implement a user memory handler. This checks to be sure it isn't | |||
| * called with big numbers. | |||
| */ | |||
| #ifdef PNG_USER_MEM_SUPPORTED | |||
| PNG_UNUSED(png_ptr) | |||
| #endif | |||
| if (size > 0 && size <= PNG_SIZE_MAX | |||
| # ifdef PNG_MAX_MALLOC_64K | |||
| && size <= 65536U | |||
| # endif | |||
| ) | |||
| { | |||
| #ifdef PNG_USER_MEM_SUPPORTED | |||
| if (png_ptr != NULL && png_ptr->malloc_fn != NULL) | |||
| return png_ptr->malloc_fn(png_constcast(png_structrp,png_ptr), size); | |||
| else | |||
| #endif | |||
| return malloc((size_t)size); /* checked for truncation above */ | |||
| } | |||
| else | |||
| return NULL; | |||
| } | |||
| /* This is really here only to work round a spurious warning in GCC 4.6 and 4.7 | |||
| * that arises because of the checks in png_realloc_array that are repeated in | |||
| * png_malloc_array. | |||
| */ | |||
| static png_voidp | |||
| png_malloc_array_checked(png_const_structrp png_ptr, int nelements, | |||
| size_t element_size) | |||
| { | |||
| png_alloc_size_t req = nelements; /* known to be > 0 */ | |||
| if (req <= PNG_SIZE_MAX/element_size) | |||
| return png_malloc_base(png_ptr, req * element_size); | |||
| /* The failure case when the request is too large */ | |||
| return NULL; | |||
| } | |||
| PNG_FUNCTION(png_voidp /* PRIVATE */, | |||
| png_malloc_array,(png_const_structrp png_ptr, int nelements, | |||
| size_t element_size),PNG_ALLOCATED) | |||
| { | |||
| if (nelements <= 0 || element_size == 0) | |||
| png_error(png_ptr, "internal error: array alloc"); | |||
| return png_malloc_array_checked(png_ptr, nelements, element_size); | |||
| } | |||
| PNG_FUNCTION(png_voidp /* PRIVATE */, | |||
| png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array, | |||
| int old_elements, int add_elements, size_t element_size),PNG_ALLOCATED) | |||
| { | |||
| /* These are internal errors: */ | |||
| if (add_elements <= 0 || element_size == 0 || old_elements < 0 || | |||
| (old_array == NULL && old_elements > 0)) | |||
| png_error(png_ptr, "internal error: array realloc"); | |||
| /* Check for overflow on the elements count (so the caller does not have to | |||
| * check.) | |||
| */ | |||
| if (add_elements <= INT_MAX - old_elements) | |||
| { | |||
| png_voidp new_array = png_malloc_array_checked(png_ptr, | |||
| old_elements+add_elements, element_size); | |||
| if (new_array != NULL) | |||
| { | |||
| /* Because png_malloc_array worked the size calculations below cannot | |||
| * overflow. | |||
| */ | |||
| if (old_elements > 0) | |||
| memcpy(new_array, old_array, element_size*(unsigned)old_elements); | |||
| memset((char*)new_array + element_size*(unsigned)old_elements, 0, | |||
| element_size*(unsigned)add_elements); | |||
| return new_array; | |||
| } | |||
| } | |||
| return NULL; /* error */ | |||
| } | |||
| /* Various functions that have different error handling are derived from this. | |||
| * png_malloc always exists, but if PNG_USER_MEM_SUPPORTED is defined a separate | |||
| * function png_malloc_default is also provided. | |||
| */ | |||
| PNG_FUNCTION(png_voidp,PNGAPI | |||
| png_malloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) | |||
| { | |||
| png_voidp ret; | |||
| if (png_ptr == NULL) | |||
| return NULL; | |||
| ret = png_malloc_base(png_ptr, size); | |||
| if (ret == NULL) | |||
| png_error(png_ptr, "Out of memory"); /* 'm' means png_malloc */ | |||
| return ret; | |||
| } | |||
| #ifdef PNG_USER_MEM_SUPPORTED | |||
| PNG_FUNCTION(png_voidp,PNGAPI | |||
| png_malloc_default,(png_const_structrp png_ptr, png_alloc_size_t size), | |||
| PNG_ALLOCATED PNG_DEPRECATED) | |||
| { | |||
| png_voidp ret; | |||
| if (png_ptr == NULL) | |||
| return NULL; | |||
| /* Passing 'NULL' here bypasses the application provided memory handler. */ | |||
| ret = png_malloc_base(NULL/*use malloc*/, size); | |||
| if (ret == NULL) | |||
| png_error(png_ptr, "Out of Memory"); /* 'M' means png_malloc_default */ | |||
| return ret; | |||
| } | |||
| #endif /* PNG_USER_MEM_SUPPORTED */ | |||
| /* This function was added at libpng version 1.2.3. The png_malloc_warn() | |||
| * function will issue a png_warning and return NULL instead of issuing a | |||
| * png_error, if it fails to allocate the requested memory. | |||
| */ | |||
| PNG_FUNCTION(png_voidp,PNGAPI | |||
| png_malloc_warn,(png_const_structrp png_ptr, png_alloc_size_t size), | |||
| PNG_ALLOCATED) | |||
| { | |||
| if (png_ptr != NULL) | |||
| { | |||
| png_voidp ret = png_malloc_base(png_ptr, size); | |||
| if (ret != NULL) | |||
| return ret; | |||
| png_warning(png_ptr, "Out of memory"); | |||
| } | |||
| return NULL; | |||
| } | |||
| /* Free a pointer allocated by png_malloc(). If ptr is NULL, return | |||
| * without taking any action. | |||
| */ | |||
| void PNGAPI | |||
| png_free(png_const_structrp png_ptr, png_voidp ptr) | |||
| { | |||
| if (png_ptr == NULL || ptr == NULL) | |||
| return; | |||
| #ifdef PNG_USER_MEM_SUPPORTED | |||
| if (png_ptr->free_fn != NULL) | |||
| png_ptr->free_fn(png_constcast(png_structrp,png_ptr), ptr); | |||
| else | |||
| png_free_default(png_ptr, ptr); | |||
| } | |||
| PNG_FUNCTION(void,PNGAPI | |||
| png_free_default,(png_const_structrp png_ptr, png_voidp ptr),PNG_DEPRECATED) | |||
| { | |||
| if (png_ptr == NULL || ptr == NULL) | |||
| return; | |||
| #endif /* PNG_USER_MEM_SUPPORTED */ | |||
| free(ptr); | |||
| } | |||
| #ifdef PNG_USER_MEM_SUPPORTED | |||
| /* This function is called when the application wants to use another method | |||
| * of allocating and freeing memory. | |||
| */ | |||
| void PNGAPI | |||
| png_set_mem_fn(png_structrp png_ptr, png_voidp mem_ptr, png_malloc_ptr | |||
| malloc_fn, png_free_ptr free_fn) | |||
| { | |||
| if (png_ptr != NULL) | |||
| { | |||
| png_ptr->mem_ptr = mem_ptr; | |||
| png_ptr->malloc_fn = malloc_fn; | |||
| png_ptr->free_fn = free_fn; | |||
| } | |||
| } | |||
| /* This function returns a pointer to the mem_ptr associated with the user | |||
| * functions. The application should free any memory associated with this | |||
| * pointer before png_write_destroy and png_read_destroy are called. | |||
| */ | |||
| png_voidp PNGAPI | |||
| png_get_mem_ptr(png_const_structrp png_ptr) | |||
| { | |||
| if (png_ptr == NULL) | |||
| return NULL; | |||
| return png_ptr->mem_ptr; | |||
| } | |||
| #endif /* PNG_USER_MEM_SUPPORTED */ | |||
| #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ | |||
| /* pngmem.c - stub functions for memory allocation | |||
| * | |||
| * Copyright (c) 2018 Cosmin Truta | |||
| * Copyright (c) 1998-2002,2004,2006-2014,2016 Glenn Randers-Pehrson | |||
| * Copyright (c) 1996-1997 Andreas Dilger | |||
| * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. | |||
| * | |||
| * This code is released under the libpng license. | |||
| * For conditions of distribution and use, see the disclaimer | |||
| * and license in png.h | |||
| * | |||
| * This file provides a location for all memory allocation. Users who | |||
| * need special memory handling are expected to supply replacement | |||
| * functions for png_malloc() and png_free(), and to use | |||
| * png_create_read_struct_2() and png_create_write_struct_2() to | |||
| * identify the replacement functions. | |||
| */ | |||
| #include "pngpriv.h" | |||
| #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) | |||
| /* Free a png_struct */ | |||
| void /* PRIVATE */ | |||
| png_destroy_png_struct(png_structrp png_ptr) | |||
| { | |||
| if (png_ptr != NULL) | |||
| { | |||
| /* png_free might call png_error and may certainly call | |||
| * png_get_mem_ptr, so fake a temporary png_struct to support this. | |||
| */ | |||
| png_struct dummy_struct = *png_ptr; | |||
| memset(png_ptr, 0, (sizeof *png_ptr)); | |||
| png_free(&dummy_struct, png_ptr); | |||
| # ifdef PNG_SETJMP_SUPPORTED | |||
| /* We may have a jmp_buf left to deallocate. */ | |||
| png_free_jmpbuf(&dummy_struct); | |||
| # endif | |||
| } | |||
| } | |||
| /* Allocate memory. For reasonable files, size should never exceed | |||
| * 64K. However, zlib may allocate more than 64K if you don't tell | |||
| * it not to. See zconf.h and png.h for more information. zlib does | |||
| * need to allocate exactly 64K, so whatever you call here must | |||
| * have the ability to do that. | |||
| */ | |||
| PNG_FUNCTION(png_voidp,PNGAPI | |||
| png_calloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) | |||
| { | |||
| png_voidp ret; | |||
| ret = png_malloc(png_ptr, size); | |||
| if (ret != NULL) | |||
| memset(ret, 0, size); | |||
| return ret; | |||
| } | |||
| /* png_malloc_base, an internal function added at libpng 1.6.0, does the work of | |||
| * allocating memory, taking into account limits and PNG_USER_MEM_SUPPORTED. | |||
| * Checking and error handling must happen outside this routine; it returns NULL | |||
| * if the allocation cannot be done (for any reason.) | |||
| */ | |||
| PNG_FUNCTION(png_voidp /* PRIVATE */, | |||
| png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size), | |||
| PNG_ALLOCATED) | |||
| { | |||
| /* Moved to png_malloc_base from png_malloc_default in 1.6.0; the DOS | |||
| * allocators have also been removed in 1.6.0, so any 16-bit system now has | |||
| * to implement a user memory handler. This checks to be sure it isn't | |||
| * called with big numbers. | |||
| */ | |||
| #ifndef PNG_USER_MEM_SUPPORTED | |||
| PNG_UNUSED(png_ptr) | |||
| #endif | |||
| /* Some compilers complain that this is always true. However, it | |||
| * can be false when integer overflow happens. | |||
| */ | |||
| if (size > 0 && size <= PNG_SIZE_MAX | |||
| # ifdef PNG_MAX_MALLOC_64K | |||
| && size <= 65536U | |||
| # endif | |||
| ) | |||
| { | |||
| #ifdef PNG_USER_MEM_SUPPORTED | |||
| if (png_ptr != NULL && png_ptr->malloc_fn != NULL) | |||
| return png_ptr->malloc_fn(png_constcast(png_structrp,png_ptr), size); | |||
| else | |||
| #endif | |||
| return malloc((size_t)size); /* checked for truncation above */ | |||
| } | |||
| else | |||
| return NULL; | |||
| } | |||
| #if defined(PNG_TEXT_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) ||\ | |||
| defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) | |||
| /* This is really here only to work round a spurious warning in GCC 4.6 and 4.7 | |||
| * that arises because of the checks in png_realloc_array that are repeated in | |||
| * png_malloc_array. | |||
| */ | |||
| static png_voidp | |||
| png_malloc_array_checked(png_const_structrp png_ptr, int nelements, | |||
| size_t element_size) | |||
| { | |||
| png_alloc_size_t req = (png_alloc_size_t)nelements; /* known to be > 0 */ | |||
| if (req <= PNG_SIZE_MAX/element_size) | |||
| return png_malloc_base(png_ptr, req * element_size); | |||
| /* The failure case when the request is too large */ | |||
| return NULL; | |||
| } | |||
| PNG_FUNCTION(png_voidp /* PRIVATE */, | |||
| png_malloc_array,(png_const_structrp png_ptr, int nelements, | |||
| size_t element_size),PNG_ALLOCATED) | |||
| { | |||
| if (nelements <= 0 || element_size == 0) | |||
| png_error(png_ptr, "internal error: array alloc"); | |||
| return png_malloc_array_checked(png_ptr, nelements, element_size); | |||
| } | |||
| PNG_FUNCTION(png_voidp /* PRIVATE */, | |||
| png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array, | |||
| int old_elements, int add_elements, size_t element_size),PNG_ALLOCATED) | |||
| { | |||
| /* These are internal errors: */ | |||
| if (add_elements <= 0 || element_size == 0 || old_elements < 0 || | |||
| (old_array == NULL && old_elements > 0)) | |||
| png_error(png_ptr, "internal error: array realloc"); | |||
| /* Check for overflow on the elements count (so the caller does not have to | |||
| * check.) | |||
| */ | |||
| if (add_elements <= INT_MAX - old_elements) | |||
| { | |||
| png_voidp new_array = png_malloc_array_checked(png_ptr, | |||
| old_elements+add_elements, element_size); | |||
| if (new_array != NULL) | |||
| { | |||
| /* Because png_malloc_array worked the size calculations below cannot | |||
| * overflow. | |||
| */ | |||
| if (old_elements > 0) | |||
| memcpy(new_array, old_array, element_size*(unsigned)old_elements); | |||
| memset((char*)new_array + element_size*(unsigned)old_elements, 0, | |||
| element_size*(unsigned)add_elements); | |||
| return new_array; | |||
| } | |||
| } | |||
| return NULL; /* error */ | |||
| } | |||
| #endif /* TEXT || sPLT || STORE_UNKNOWN_CHUNKS */ | |||
| /* Various functions that have different error handling are derived from this. | |||
| * png_malloc always exists, but if PNG_USER_MEM_SUPPORTED is defined a separate | |||
| * function png_malloc_default is also provided. | |||
| */ | |||
| PNG_FUNCTION(png_voidp,PNGAPI | |||
| png_malloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) | |||
| { | |||
| png_voidp ret; | |||
| if (png_ptr == NULL) | |||
| return NULL; | |||
| ret = png_malloc_base(png_ptr, size); | |||
| if (ret == NULL) | |||
| png_error(png_ptr, "Out of memory"); /* 'm' means png_malloc */ | |||
| return ret; | |||
| } | |||
| #ifdef PNG_USER_MEM_SUPPORTED | |||
| PNG_FUNCTION(png_voidp,PNGAPI | |||
| png_malloc_default,(png_const_structrp png_ptr, png_alloc_size_t size), | |||
| PNG_ALLOCATED PNG_DEPRECATED) | |||
| { | |||
| png_voidp ret; | |||
| if (png_ptr == NULL) | |||
| return NULL; | |||
| /* Passing 'NULL' here bypasses the application provided memory handler. */ | |||
| ret = png_malloc_base(NULL/*use malloc*/, size); | |||
| if (ret == NULL) | |||
| png_error(png_ptr, "Out of Memory"); /* 'M' means png_malloc_default */ | |||
| return ret; | |||
| } | |||
| #endif /* USER_MEM */ | |||
| /* This function was added at libpng version 1.2.3. The png_malloc_warn() | |||
| * function will issue a png_warning and return NULL instead of issuing a | |||
| * png_error, if it fails to allocate the requested memory. | |||
| */ | |||
| PNG_FUNCTION(png_voidp,PNGAPI | |||
| png_malloc_warn,(png_const_structrp png_ptr, png_alloc_size_t size), | |||
| PNG_ALLOCATED) | |||
| { | |||
| if (png_ptr != NULL) | |||
| { | |||
| png_voidp ret = png_malloc_base(png_ptr, size); | |||
| if (ret != NULL) | |||
| return ret; | |||
| png_warning(png_ptr, "Out of memory"); | |||
| } | |||
| return NULL; | |||
| } | |||
| /* Free a pointer allocated by png_malloc(). If ptr is NULL, return | |||
| * without taking any action. | |||
| */ | |||
| void PNGAPI | |||
| png_free(png_const_structrp png_ptr, png_voidp ptr) | |||
| { | |||
| if (png_ptr == NULL || ptr == NULL) | |||
| return; | |||
| #ifdef PNG_USER_MEM_SUPPORTED | |||
| if (png_ptr->free_fn != NULL) | |||
| png_ptr->free_fn(png_constcast(png_structrp,png_ptr), ptr); | |||
| else | |||
| png_free_default(png_ptr, ptr); | |||
| } | |||
| PNG_FUNCTION(void,PNGAPI | |||
| png_free_default,(png_const_structrp png_ptr, png_voidp ptr),PNG_DEPRECATED) | |||
| { | |||
| if (png_ptr == NULL || ptr == NULL) | |||
| return; | |||
| #endif /* USER_MEM */ | |||
| free(ptr); | |||
| } | |||
| #ifdef PNG_USER_MEM_SUPPORTED | |||
| /* This function is called when the application wants to use another method | |||
| * of allocating and freeing memory. | |||
| */ | |||
| void PNGAPI | |||
| png_set_mem_fn(png_structrp png_ptr, png_voidp mem_ptr, png_malloc_ptr | |||
| malloc_fn, png_free_ptr free_fn) | |||
| { | |||
| if (png_ptr != NULL) | |||
| { | |||
| png_ptr->mem_ptr = mem_ptr; | |||
| png_ptr->malloc_fn = malloc_fn; | |||
| png_ptr->free_fn = free_fn; | |||
| } | |||
| } | |||
| /* This function returns a pointer to the mem_ptr associated with the user | |||
| * functions. The application should free any memory associated with this | |||
| * pointer before png_write_destroy and png_read_destroy are called. | |||
| */ | |||
| png_voidp PNGAPI | |||
| png_get_mem_ptr(png_const_structrp png_ptr) | |||
| { | |||
| if (png_ptr == NULL) | |||
| return NULL; | |||
| return png_ptr->mem_ptr; | |||
| } | |||
| #endif /* USER_MEM */ | |||
| #endif /* READ || WRITE */ | |||
| @@ -1,118 +1,120 @@ | |||
| /* pngrio.c - functions for data input | |||
| * | |||
| * Last changed in libpng 1.6.0 [February 14, 2013] | |||
| * Copyright (c) 1998-2013 Glenn Randers-Pehrson | |||
| * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | |||
| * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | |||
| * | |||
| * This code is released under the libpng license. | |||
| * For conditions of distribution and use, see the disclaimer | |||
| * and license in png.h | |||
| * | |||
| * This file provides a location for all input. Users who need | |||
| * special handling are expected to write a function that has the same | |||
| * arguments as this and performs a similar function, but that possibly | |||
| * has a different input method. Note that you shouldn't change this | |||
| * function, but rather write a replacement function and then make | |||
| * libpng use it at run time with png_set_read_fn(...). | |||
| */ | |||
| #include "pngpriv.h" | |||
| #ifdef PNG_READ_SUPPORTED | |||
| /* Read the data from whatever input you are using. The default routine | |||
| * reads from a file pointer. Note that this routine sometimes gets called | |||
| * with very small lengths, so you should implement some kind of simple | |||
| * buffering if you are using unbuffered reads. This should never be asked | |||
| * to read more then 64K on a 16 bit machine. | |||
| */ | |||
| void /* PRIVATE */ | |||
| png_read_data(png_structrp png_ptr, png_bytep data, png_size_t length) | |||
| { | |||
| png_debug1(4, "reading %d bytes", (int)length); | |||
| if (png_ptr->read_data_fn != NULL) | |||
| (*(png_ptr->read_data_fn))(png_ptr, data, length); | |||
| else | |||
| png_error(png_ptr, "Call to NULL read function"); | |||
| } | |||
| #ifdef PNG_STDIO_SUPPORTED | |||
| /* This is the function that does the actual reading of data. If you are | |||
| * not reading from a standard C stream, you should create a replacement | |||
| * read_data function and use it at run time with png_set_read_fn(), rather | |||
| * than changing the library. | |||
| */ | |||
| void PNGCBAPI | |||
| png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) | |||
| { | |||
| png_size_t check; | |||
| if (png_ptr == NULL) | |||
| return; | |||
| /* fread() returns 0 on error, so it is OK to store this in a png_size_t | |||
| * instead of an int, which is what fread() actually returns. | |||
| */ | |||
| check = fread(data, 1, length, png_voidcast(png_FILE_p, png_ptr->io_ptr)); | |||
| if (check != length) | |||
| png_error(png_ptr, "Read Error"); | |||
| } | |||
| #endif | |||
| /* This function allows the application to supply a new input function | |||
| * for libpng if standard C streams aren't being used. | |||
| * | |||
| * This function takes as its arguments: | |||
| * | |||
| * png_ptr - pointer to a png input data structure | |||
| * | |||
| * io_ptr - pointer to user supplied structure containing info about | |||
| * the input functions. May be NULL. | |||
| * | |||
| * read_data_fn - pointer to a new input function that takes as its | |||
| * arguments a pointer to a png_struct, a pointer to | |||
| * a location where input data can be stored, and a 32-bit | |||
| * unsigned int that is the number of bytes to be read. | |||
| * To exit and output any fatal error messages the new write | |||
| * function should call png_error(png_ptr, "Error msg"). | |||
| * May be NULL, in which case libpng's default function will | |||
| * be used. | |||
| */ | |||
| void PNGAPI | |||
| png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr, | |||
| png_rw_ptr read_data_fn) | |||
| { | |||
| if (png_ptr == NULL) | |||
| return; | |||
| png_ptr->io_ptr = io_ptr; | |||
| #ifdef PNG_STDIO_SUPPORTED | |||
| if (read_data_fn != NULL) | |||
| png_ptr->read_data_fn = read_data_fn; | |||
| else | |||
| png_ptr->read_data_fn = png_default_read_data; | |||
| #else | |||
| png_ptr->read_data_fn = read_data_fn; | |||
| #endif | |||
| /* It is an error to write to a read device */ | |||
| if (png_ptr->write_data_fn != NULL) | |||
| { | |||
| png_ptr->write_data_fn = NULL; | |||
| png_warning(png_ptr, | |||
| "Can't set both read_data_fn and write_data_fn in the" | |||
| " same structure"); | |||
| } | |||
| #ifdef PNG_WRITE_FLUSH_SUPPORTED | |||
| png_ptr->output_flush_fn = NULL; | |||
| #endif | |||
| } | |||
| #endif /* PNG_READ_SUPPORTED */ | |||
| /* pngrio.c - functions for data input | |||
| * | |||
| * Copyright (c) 2018 Cosmin Truta | |||
| * Copyright (c) 1998-2002,2004,2006-2016,2018 Glenn Randers-Pehrson | |||
| * Copyright (c) 1996-1997 Andreas Dilger | |||
| * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. | |||
| * | |||
| * This code is released under the libpng license. | |||
| * For conditions of distribution and use, see the disclaimer | |||
| * and license in png.h | |||
| * | |||
| * This file provides a location for all input. Users who need | |||
| * special handling are expected to write a function that has the same | |||
| * arguments as this and performs a similar function, but that possibly | |||
| * has a different input method. Note that you shouldn't change this | |||
| * function, but rather write a replacement function and then make | |||
| * libpng use it at run time with png_set_read_fn(...). | |||
| */ | |||
| #include "pngpriv.h" | |||
| #ifdef PNG_READ_SUPPORTED | |||
| /* Read the data from whatever input you are using. The default routine | |||
| * reads from a file pointer. Note that this routine sometimes gets called | |||
| * with very small lengths, so you should implement some kind of simple | |||
| * buffering if you are using unbuffered reads. This should never be asked | |||
| * to read more than 64K on a 16-bit machine. | |||
| */ | |||
| void /* PRIVATE */ | |||
| png_read_data(png_structrp png_ptr, png_bytep data, size_t length) | |||
| { | |||
| png_debug1(4, "reading %d bytes", (int)length); | |||
| if (png_ptr->read_data_fn != NULL) | |||
| (*(png_ptr->read_data_fn))(png_ptr, data, length); | |||
| else | |||
| png_error(png_ptr, "Call to NULL read function"); | |||
| } | |||
| #ifdef PNG_STDIO_SUPPORTED | |||
| /* This is the function that does the actual reading of data. If you are | |||
| * not reading from a standard C stream, you should create a replacement | |||
| * read_data function and use it at run time with png_set_read_fn(), rather | |||
| * than changing the library. | |||
| */ | |||
| void PNGCBAPI | |||
| png_default_read_data(png_structp png_ptr, png_bytep data, size_t length) | |||
| { | |||
| size_t check; | |||
| if (png_ptr == NULL) | |||
| return; | |||
| /* fread() returns 0 on error, so it is OK to store this in a size_t | |||
| * instead of an int, which is what fread() actually returns. | |||
| */ | |||
| check = fread(data, 1, length, png_voidcast(png_FILE_p, png_ptr->io_ptr)); | |||
| if (check != length) | |||
| png_error(png_ptr, "Read Error"); | |||
| } | |||
| #endif | |||
| /* This function allows the application to supply a new input function | |||
| * for libpng if standard C streams aren't being used. | |||
| * | |||
| * This function takes as its arguments: | |||
| * | |||
| * png_ptr - pointer to a png input data structure | |||
| * | |||
| * io_ptr - pointer to user supplied structure containing info about | |||
| * the input functions. May be NULL. | |||
| * | |||
| * read_data_fn - pointer to a new input function that takes as its | |||
| * arguments a pointer to a png_struct, a pointer to | |||
| * a location where input data can be stored, and a 32-bit | |||
| * unsigned int that is the number of bytes to be read. | |||
| * To exit and output any fatal error messages the new write | |||
| * function should call png_error(png_ptr, "Error msg"). | |||
| * May be NULL, in which case libpng's default function will | |||
| * be used. | |||
| */ | |||
| void PNGAPI | |||
| png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr, | |||
| png_rw_ptr read_data_fn) | |||
| { | |||
| if (png_ptr == NULL) | |||
| return; | |||
| png_ptr->io_ptr = io_ptr; | |||
| #ifdef PNG_STDIO_SUPPORTED | |||
| if (read_data_fn != NULL) | |||
| png_ptr->read_data_fn = read_data_fn; | |||
| else | |||
| png_ptr->read_data_fn = png_default_read_data; | |||
| #else | |||
| png_ptr->read_data_fn = read_data_fn; | |||
| #endif | |||
| #ifdef PNG_WRITE_SUPPORTED | |||
| /* It is an error to write to a read device */ | |||
| if (png_ptr->write_data_fn != NULL) | |||
| { | |||
| png_ptr->write_data_fn = NULL; | |||
| png_warning(png_ptr, | |||
| "Can't set both read_data_fn and write_data_fn in the" | |||
| " same structure"); | |||
| } | |||
| #endif | |||
| #ifdef PNG_WRITE_FLUSH_SUPPORTED | |||
| png_ptr->output_flush_fn = NULL; | |||
| #endif | |||
| } | |||
| #endif /* READ */ | |||
| @@ -1,489 +1,491 @@ | |||
| /* pngstruct.h - header file for PNG reference library | |||
| * | |||
| * Copyright (c) 1998-2013 Glenn Randers-Pehrson | |||
| * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | |||
| * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | |||
| * | |||
| * Last changed in libpng 1.6.1 [March 28, 2013] | |||
| * | |||
| * This code is released under the libpng license. | |||
| * For conditions of distribution and use, see the disclaimer | |||
| * and license in png.h | |||
| */ | |||
| /* The structure that holds the information to read and write PNG files. | |||
| * The only people who need to care about what is inside of this are the | |||
| * people who will be modifying the library for their own special needs. | |||
| * It should NOT be accessed directly by an application. | |||
| */ | |||
| #ifndef PNGSTRUCT_H | |||
| #define PNGSTRUCT_H | |||
| /* zlib.h defines the structure z_stream, an instance of which is included | |||
| * in this structure and is required for decompressing the LZ compressed | |||
| * data in PNG files. | |||
| */ | |||
| #ifndef ZLIB_CONST | |||
| /* We must ensure that zlib uses 'const' in declarations. */ | |||
| # define ZLIB_CONST | |||
| #endif | |||
| #include "../../../juce_core/zip/zlib/zlib.h" | |||
| #ifdef const | |||
| /* zlib.h sometimes #defines const to nothing, undo this. */ | |||
| # undef const | |||
| #endif | |||
| /* zlib.h has mediocre z_const use before 1.2.6, this stuff is for compatibility | |||
| * with older builds. | |||
| */ | |||
| #if ZLIB_VERNUM < 0x1260 | |||
| # define PNGZ_MSG_CAST(s) png_constcast(char*,s) | |||
| # define PNGZ_INPUT_CAST(b) png_constcast(png_bytep,b) | |||
| #else | |||
| # define PNGZ_MSG_CAST(s) (s) | |||
| # define PNGZ_INPUT_CAST(b) (b) | |||
| #endif | |||
| /* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib | |||
| * can handle at once. This type need be no larger than 16 bits (so maximum of | |||
| * 65535), this define allows us to discover how big it is, but limited by the | |||
| * maximuum for png_size_t. The value can be overriden in a library build | |||
| * (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably | |||
| * lower value (e.g. 255 works). A lower value may help memory usage (slightly) | |||
| * and may even improve performance on some systems (and degrade it on others.) | |||
| */ | |||
| #ifndef ZLIB_IO_MAX | |||
| # define ZLIB_IO_MAX ((uInt)-1) | |||
| #endif | |||
| #ifdef PNG_WRITE_SUPPORTED | |||
| /* The type of a compression buffer list used by the write code. */ | |||
| typedef struct png_compression_buffer | |||
| { | |||
| struct png_compression_buffer *next; | |||
| png_byte output[1]; /* actually zbuf_size */ | |||
| } png_compression_buffer, *png_compression_bufferp; | |||
| #define PNG_COMPRESSION_BUFFER_SIZE(pp)\ | |||
| (offsetof(png_compression_buffer, output) + (pp)->zbuffer_size) | |||
| #endif | |||
| /* Colorspace support; structures used in png_struct, png_info and in internal | |||
| * functions to hold and communicate information about the color space. | |||
| * | |||
| * PNG_COLORSPACE_SUPPORTED is only required if the application will perform | |||
| * colorspace corrections, otherwise all the colorspace information can be | |||
| * skipped and the size of libpng can be reduced (significantly) by compiling | |||
| * out the colorspace support. | |||
| */ | |||
| #ifdef PNG_COLORSPACE_SUPPORTED | |||
| /* The chromaticities of the red, green and blue colorants and the chromaticity | |||
| * of the corresponding white point (i.e. of rgb(1.0,1.0,1.0)). | |||
| */ | |||
| typedef struct png_xy | |||
| { | |||
| png_fixed_point redx, redy; | |||
| png_fixed_point greenx, greeny; | |||
| png_fixed_point bluex, bluey; | |||
| png_fixed_point whitex, whitey; | |||
| } png_xy; | |||
| /* The same data as above but encoded as CIE XYZ values. When this data comes | |||
| * from chromaticities the sum of the Y values is assumed to be 1.0 | |||
| */ | |||
| typedef struct png_XYZ | |||
| { | |||
| png_fixed_point red_X, red_Y, red_Z; | |||
| png_fixed_point green_X, green_Y, green_Z; | |||
| png_fixed_point blue_X, blue_Y, blue_Z; | |||
| } png_XYZ; | |||
| #endif /* COLORSPACE */ | |||
| #if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED) | |||
| /* A colorspace is all the above plus, potentially, profile information, | |||
| * however at present libpng does not use the profile internally so it is only | |||
| * stored in the png_info struct (if iCCP is supported.) The rendering intent | |||
| * is retained here and is checked. | |||
| * | |||
| * The file gamma encoding information is also stored here and gamma correction | |||
| * is done by libpng, whereas color correction must currently be done by the | |||
| * application. | |||
| */ | |||
| typedef struct png_colorspace | |||
| { | |||
| #ifdef PNG_GAMMA_SUPPORTED | |||
| png_fixed_point gamma; /* File gamma */ | |||
| #endif | |||
| #ifdef PNG_COLORSPACE_SUPPORTED | |||
| png_xy end_points_xy; /* End points as chromaticities */ | |||
| png_XYZ end_points_XYZ; /* End points as CIE XYZ colorant values */ | |||
| png_uint_16 rendering_intent; /* Rendering intent of a profile */ | |||
| #endif | |||
| /* Flags are always defined to simplify the code. */ | |||
| png_uint_16 flags; /* As defined below */ | |||
| } png_colorspace, * PNG_RESTRICT png_colorspacerp; | |||
| typedef const png_colorspace * PNG_RESTRICT png_const_colorspacerp; | |||
| /* General flags for the 'flags' field */ | |||
| #define PNG_COLORSPACE_HAVE_GAMMA 0x0001 | |||
| #define PNG_COLORSPACE_HAVE_ENDPOINTS 0x0002 | |||
| #define PNG_COLORSPACE_HAVE_INTENT 0x0004 | |||
| #define PNG_COLORSPACE_FROM_gAMA 0x0008 | |||
| #define PNG_COLORSPACE_FROM_cHRM 0x0010 | |||
| #define PNG_COLORSPACE_FROM_sRGB 0x0020 | |||
| #define PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB 0x0040 | |||
| #define PNG_COLORSPACE_MATCHES_sRGB 0x0080 /* exact match on profile */ | |||
| #define PNG_COLORSPACE_INVALID 0x8000 | |||
| #define PNG_COLORSPACE_CANCEL(flags) (0xffff ^ (flags)) | |||
| #endif /* COLORSPACE || GAMMA */ | |||
| struct png_struct_def | |||
| { | |||
| #ifdef PNG_SETJMP_SUPPORTED | |||
| jmp_buf jmp_buf_local; /* New name in 1.6.0 for jmp_buf in png_struct */ | |||
| png_longjmp_ptr longjmp_fn;/* setjmp non-local goto function. */ | |||
| jmp_buf *jmp_buf_ptr; /* passed to longjmp_fn */ | |||
| size_t jmp_buf_size; /* size of the above, if allocated */ | |||
| #endif | |||
| png_error_ptr error_fn; /* function for printing errors and aborting */ | |||
| #ifdef PNG_WARNINGS_SUPPORTED | |||
| png_error_ptr warning_fn; /* function for printing warnings */ | |||
| #endif | |||
| png_voidp error_ptr; /* user supplied struct for error functions */ | |||
| png_rw_ptr write_data_fn; /* function for writing output data */ | |||
| png_rw_ptr read_data_fn; /* function for reading input data */ | |||
| png_voidp io_ptr; /* ptr to application struct for I/O functions */ | |||
| #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED | |||
| png_user_transform_ptr read_user_transform_fn; /* user read transform */ | |||
| #endif | |||
| #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED | |||
| png_user_transform_ptr write_user_transform_fn; /* user write transform */ | |||
| #endif | |||
| /* These were added in libpng-1.0.2 */ | |||
| #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED | |||
| #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ | |||
| defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) | |||
| png_voidp user_transform_ptr; /* user supplied struct for user transform */ | |||
| png_byte user_transform_depth; /* bit depth of user transformed pixels */ | |||
| png_byte user_transform_channels; /* channels in user transformed pixels */ | |||
| #endif | |||
| #endif | |||
| png_uint_32 mode; /* tells us where we are in the PNG file */ | |||
| png_uint_32 flags; /* flags indicating various things to libpng */ | |||
| png_uint_32 transformations; /* which transformations to perform */ | |||
| png_uint_32 zowner; /* ID (chunk type) of zstream owner, 0 if none */ | |||
| z_stream zstream; /* decompression structure */ | |||
| #ifdef PNG_WRITE_SUPPORTED | |||
| png_compression_bufferp zbuffer_list; /* Created on demand during write */ | |||
| uInt zbuffer_size; /* size of the actual buffer */ | |||
| int zlib_level; /* holds zlib compression level */ | |||
| int zlib_method; /* holds zlib compression method */ | |||
| int zlib_window_bits; /* holds zlib compression window bits */ | |||
| int zlib_mem_level; /* holds zlib compression memory level */ | |||
| int zlib_strategy; /* holds zlib compression strategy */ | |||
| #endif | |||
| /* Added at libpng 1.5.4 */ | |||
| #ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED | |||
| int zlib_text_level; /* holds zlib compression level */ | |||
| int zlib_text_method; /* holds zlib compression method */ | |||
| int zlib_text_window_bits; /* holds zlib compression window bits */ | |||
| int zlib_text_mem_level; /* holds zlib compression memory level */ | |||
| int zlib_text_strategy; /* holds zlib compression strategy */ | |||
| #endif | |||
| /* End of material added at libpng 1.5.4 */ | |||
| /* Added at libpng 1.6.0 */ | |||
| #ifdef PNG_WRITE_SUPPORTED | |||
| int zlib_set_level; /* Actual values set into the zstream on write */ | |||
| int zlib_set_method; | |||
| int zlib_set_window_bits; | |||
| int zlib_set_mem_level; | |||
| int zlib_set_strategy; | |||
| #endif | |||
| png_uint_32 width; /* width of image in pixels */ | |||
| png_uint_32 height; /* height of image in pixels */ | |||
| png_uint_32 num_rows; /* number of rows in current pass */ | |||
| png_uint_32 usr_width; /* width of row at start of write */ | |||
| png_size_t rowbytes; /* size of row in bytes */ | |||
| png_uint_32 iwidth; /* width of current interlaced row in pixels */ | |||
| png_uint_32 row_number; /* current row in interlace pass */ | |||
| png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */ | |||
| png_bytep prev_row; /* buffer to save previous (unfiltered) row. | |||
| * This is a pointer into big_prev_row | |||
| */ | |||
| png_bytep row_buf; /* buffer to save current (unfiltered) row. | |||
| * This is a pointer into big_row_buf | |||
| */ | |||
| #ifdef PNG_WRITE_SUPPORTED | |||
| png_bytep sub_row; /* buffer to save "sub" row when filtering */ | |||
| png_bytep up_row; /* buffer to save "up" row when filtering */ | |||
| png_bytep avg_row; /* buffer to save "avg" row when filtering */ | |||
| png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */ | |||
| #endif | |||
| png_size_t info_rowbytes; /* Added in 1.5.4: cache of updated row bytes */ | |||
| png_uint_32 idat_size; /* current IDAT size for read */ | |||
| png_uint_32 crc; /* current chunk CRC value */ | |||
| png_colorp palette; /* palette from the input file */ | |||
| png_uint_16 num_palette; /* number of color entries in palette */ | |||
| /* Added at libpng-1.5.10 */ | |||
| #ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED | |||
| int num_palette_max; /* maximum palette index found in IDAT */ | |||
| #endif | |||
| png_uint_16 num_trans; /* number of transparency values */ | |||
| png_byte compression; /* file compression type (always 0) */ | |||
| png_byte filter; /* file filter type (always 0) */ | |||
| png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */ | |||
| png_byte pass; /* current interlace pass (0 - 6) */ | |||
| png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */ | |||
| png_byte color_type; /* color type of file */ | |||
| png_byte bit_depth; /* bit depth of file */ | |||
| png_byte usr_bit_depth; /* bit depth of users row: write only */ | |||
| png_byte pixel_depth; /* number of bits per pixel */ | |||
| png_byte channels; /* number of channels in file */ | |||
| #ifdef PNG_WRITE_SUPPORTED | |||
| png_byte usr_channels; /* channels at start of write: write only */ | |||
| #endif | |||
| png_byte sig_bytes; /* magic bytes read/written from start of file */ | |||
| png_byte maximum_pixel_depth; | |||
| /* pixel depth used for the row buffers */ | |||
| png_byte transformed_pixel_depth; | |||
| /* pixel depth after read/write transforms */ | |||
| #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) | |||
| png_uint_16 filler; /* filler bytes for pixel expansion */ | |||
| #endif | |||
| #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ | |||
| defined(PNG_READ_ALPHA_MODE_SUPPORTED) | |||
| png_byte background_gamma_type; | |||
| png_fixed_point background_gamma; | |||
| png_color_16 background; /* background color in screen gamma space */ | |||
| #ifdef PNG_READ_GAMMA_SUPPORTED | |||
| png_color_16 background_1; /* background normalized to gamma 1.0 */ | |||
| #endif | |||
| #endif /* PNG_bKGD_SUPPORTED */ | |||
| #ifdef PNG_WRITE_FLUSH_SUPPORTED | |||
| png_flush_ptr output_flush_fn; /* Function for flushing output */ | |||
| png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */ | |||
| png_uint_32 flush_rows; /* number of rows written since last flush */ | |||
| #endif | |||
| #ifdef PNG_READ_GAMMA_SUPPORTED | |||
| int gamma_shift; /* number of "insignificant" bits in 16-bit gamma */ | |||
| png_fixed_point screen_gamma; /* screen gamma value (display_exponent) */ | |||
| png_bytep gamma_table; /* gamma table for 8-bit depth files */ | |||
| png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */ | |||
| #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ | |||
| defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ | |||
| defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) | |||
| png_bytep gamma_from_1; /* converts from 1.0 to screen */ | |||
| png_bytep gamma_to_1; /* converts from file to 1.0 */ | |||
| png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */ | |||
| png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */ | |||
| #endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ | |||
| #endif | |||
| #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED) | |||
| png_color_8 sig_bit; /* significant bits in each available channel */ | |||
| #endif | |||
| #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) | |||
| png_color_8 shift; /* shift for significant bit tranformation */ | |||
| #endif | |||
| #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \ | |||
| || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) | |||
| png_bytep trans_alpha; /* alpha values for paletted files */ | |||
| png_color_16 trans_color; /* transparent color for non-paletted files */ | |||
| #endif | |||
| png_read_status_ptr read_row_fn; /* called after each row is decoded */ | |||
| png_write_status_ptr write_row_fn; /* called after each row is encoded */ | |||
| #ifdef PNG_PROGRESSIVE_READ_SUPPORTED | |||
| png_progressive_info_ptr info_fn; /* called after header data fully read */ | |||
| png_progressive_row_ptr row_fn; /* called after a prog. row is decoded */ | |||
| png_progressive_end_ptr end_fn; /* called after image is complete */ | |||
| png_bytep save_buffer_ptr; /* current location in save_buffer */ | |||
| png_bytep save_buffer; /* buffer for previously read data */ | |||
| png_bytep current_buffer_ptr; /* current location in current_buffer */ | |||
| png_bytep current_buffer; /* buffer for recently used data */ | |||
| png_uint_32 push_length; /* size of current input chunk */ | |||
| png_uint_32 skip_length; /* bytes to skip in input data */ | |||
| png_size_t save_buffer_size; /* amount of data now in save_buffer */ | |||
| png_size_t save_buffer_max; /* total size of save_buffer */ | |||
| png_size_t buffer_size; /* total amount of available input data */ | |||
| png_size_t current_buffer_size; /* amount of data now in current_buffer */ | |||
| int process_mode; /* what push library is currently doing */ | |||
| int cur_palette; /* current push library palette index */ | |||
| #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ | |||
| #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) | |||
| /* For the Borland special 64K segment handler */ | |||
| png_bytepp offset_table_ptr; | |||
| png_bytep offset_table; | |||
| png_uint_16 offset_table_number; | |||
| png_uint_16 offset_table_count; | |||
| png_uint_16 offset_table_count_free; | |||
| #endif | |||
| #ifdef PNG_READ_QUANTIZE_SUPPORTED | |||
| png_bytep palette_lookup; /* lookup table for quantizing */ | |||
| png_bytep quantize_index; /* index translation for palette files */ | |||
| #endif | |||
| #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED | |||
| png_byte heuristic_method; /* heuristic for row filter selection */ | |||
| png_byte num_prev_filters; /* number of weights for previous rows */ | |||
| png_bytep prev_filters; /* filter type(s) of previous row(s) */ | |||
| png_uint_16p filter_weights; /* weight(s) for previous line(s) */ | |||
| png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */ | |||
| png_uint_16p filter_costs; /* relative filter calculation cost */ | |||
| png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */ | |||
| #endif | |||
| /* Options */ | |||
| #ifdef PNG_SET_OPTION_SUPPORTED | |||
| png_byte options; /* On/off state (up to 4 options) */ | |||
| #endif | |||
| #if PNG_LIBPNG_VER < 10700 | |||
| /* To do: remove this from libpng-1.7 */ | |||
| #ifdef PNG_TIME_RFC1123_SUPPORTED | |||
| char time_buffer[29]; /* String to hold RFC 1123 time text */ | |||
| #endif | |||
| #endif | |||
| /* New members added in libpng-1.0.6 */ | |||
| png_uint_32 free_me; /* flags items libpng is responsible for freeing */ | |||
| #ifdef PNG_USER_CHUNKS_SUPPORTED | |||
| png_voidp user_chunk_ptr; | |||
| #ifdef PNG_READ_USER_CHUNKS_SUPPORTED | |||
| png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */ | |||
| #endif | |||
| #endif | |||
| #ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED | |||
| int unknown_default; /* As PNG_HANDLE_* */ | |||
| unsigned int num_chunk_list; /* Number of entries in the list */ | |||
| png_bytep chunk_list; /* List of png_byte[5]; the textual chunk name | |||
| * followed by a PNG_HANDLE_* byte */ | |||
| #endif | |||
| /* New members added in libpng-1.0.3 */ | |||
| #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED | |||
| png_byte rgb_to_gray_status; | |||
| /* Added in libpng 1.5.5 to record setting of coefficients: */ | |||
| png_byte rgb_to_gray_coefficients_set; | |||
| /* These were changed from png_byte in libpng-1.0.6 */ | |||
| png_uint_16 rgb_to_gray_red_coeff; | |||
| png_uint_16 rgb_to_gray_green_coeff; | |||
| /* deleted in 1.5.5: rgb_to_gray_blue_coeff; */ | |||
| #endif | |||
| /* New member added in libpng-1.0.4 (renamed in 1.0.9) */ | |||
| #if defined(PNG_MNG_FEATURES_SUPPORTED) | |||
| /* Changed from png_byte to png_uint_32 at version 1.2.0 */ | |||
| png_uint_32 mng_features_permitted; | |||
| #endif | |||
| /* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */ | |||
| #ifdef PNG_MNG_FEATURES_SUPPORTED | |||
| png_byte filter_type; | |||
| #endif | |||
| /* New members added in libpng-1.2.0 */ | |||
| /* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */ | |||
| #ifdef PNG_USER_MEM_SUPPORTED | |||
| png_voidp mem_ptr; /* user supplied struct for mem functions */ | |||
| png_malloc_ptr malloc_fn; /* function for allocating memory */ | |||
| png_free_ptr free_fn; /* function for freeing memory */ | |||
| #endif | |||
| /* New member added in libpng-1.0.13 and 1.2.0 */ | |||
| png_bytep big_row_buf; /* buffer to save current (unfiltered) row */ | |||
| #ifdef PNG_READ_QUANTIZE_SUPPORTED | |||
| /* The following three members were added at version 1.0.14 and 1.2.4 */ | |||
| png_bytep quantize_sort; /* working sort array */ | |||
| png_bytep index_to_palette; /* where the original index currently is | |||
| in the palette */ | |||
| png_bytep palette_to_index; /* which original index points to this | |||
| palette color */ | |||
| #endif | |||
| /* New members added in libpng-1.0.16 and 1.2.6 */ | |||
| png_byte compression_type; | |||
| #ifdef PNG_USER_LIMITS_SUPPORTED | |||
| png_uint_32 user_width_max; | |||
| png_uint_32 user_height_max; | |||
| /* Added in libpng-1.4.0: Total number of sPLT, text, and unknown | |||
| * chunks that can be stored (0 means unlimited). | |||
| */ | |||
| png_uint_32 user_chunk_cache_max; | |||
| /* Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk | |||
| * can occupy when decompressed. 0 means unlimited. | |||
| */ | |||
| png_alloc_size_t user_chunk_malloc_max; | |||
| #endif | |||
| /* New member added in libpng-1.0.25 and 1.2.17 */ | |||
| #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED | |||
| /* Temporary storage for unknown chunk that the library doesn't recognize, | |||
| * used while reading the chunk. | |||
| */ | |||
| png_unknown_chunk unknown_chunk; | |||
| #endif | |||
| /* New member added in libpng-1.2.26 */ | |||
| png_size_t old_big_row_buf_size; | |||
| #ifdef PNG_READ_SUPPORTED | |||
| /* New member added in libpng-1.2.30 */ | |||
| png_bytep read_buffer; /* buffer for reading chunk data */ | |||
| png_alloc_size_t read_buffer_size; /* current size of the buffer */ | |||
| #endif | |||
| #ifdef PNG_SEQUENTIAL_READ_SUPPORTED | |||
| uInt IDAT_read_size; /* limit on read buffer size for IDAT */ | |||
| #endif | |||
| #ifdef PNG_IO_STATE_SUPPORTED | |||
| /* New member added in libpng-1.4.0 */ | |||
| png_uint_32 io_state; | |||
| #endif | |||
| /* New member added in libpng-1.5.6 */ | |||
| png_bytep big_prev_row; | |||
| /* New member added in libpng-1.5.7 */ | |||
| void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_row_infop row_info, | |||
| png_bytep row, png_const_bytep prev_row); | |||
| #ifdef PNG_READ_SUPPORTED | |||
| #if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED) | |||
| png_colorspace colorspace; | |||
| #endif | |||
| #endif | |||
| }; | |||
| #endif /* PNGSTRUCT_H */ | |||
| /* pngstruct.h - header file for PNG reference library | |||
| * | |||
| * Copyright (c) 2018-2019 Cosmin Truta | |||
| * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson | |||
| * Copyright (c) 1996-1997 Andreas Dilger | |||
| * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. | |||
| * | |||
| * This code is released under the libpng license. | |||
| * For conditions of distribution and use, see the disclaimer | |||
| * and license in png.h | |||
| */ | |||
| /* The structure that holds the information to read and write PNG files. | |||
| * The only people who need to care about what is inside of this are the | |||
| * people who will be modifying the library for their own special needs. | |||
| * It should NOT be accessed directly by an application. | |||
| */ | |||
| #ifndef PNGSTRUCT_H | |||
| #define PNGSTRUCT_H | |||
| /* zlib.h defines the structure z_stream, an instance of which is included | |||
| * in this structure and is required for decompressing the LZ compressed | |||
| * data in PNG files. | |||
| */ | |||
| #ifndef ZLIB_CONST | |||
| /* We must ensure that zlib uses 'const' in declarations. */ | |||
| # define ZLIB_CONST | |||
| #endif | |||
| #if ! JUCE_INCLUDE_ZLIB_CODE | |||
| #include "zlib.h" | |||
| #endif | |||
| #ifdef const | |||
| /* zlib.h sometimes #defines const to nothing, undo this. */ | |||
| # undef const | |||
| #endif | |||
| /* zlib.h has mediocre z_const use before 1.2.6, this stuff is for compatibility | |||
| * with older builds. | |||
| */ | |||
| #if ZLIB_VERNUM < 0x1260 | |||
| # define PNGZ_MSG_CAST(s) png_constcast(char*,s) | |||
| # define PNGZ_INPUT_CAST(b) png_constcast(png_bytep,b) | |||
| #else | |||
| # define PNGZ_MSG_CAST(s) (s) | |||
| # define PNGZ_INPUT_CAST(b) (b) | |||
| #endif | |||
| /* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib | |||
| * can handle at once. This type need be no larger than 16 bits (so maximum of | |||
| * 65535), this define allows us to discover how big it is, but limited by the | |||
| * maximum for size_t. The value can be overridden in a library build | |||
| * (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably | |||
| * lower value (e.g. 255 works). A lower value may help memory usage (slightly) | |||
| * and may even improve performance on some systems (and degrade it on others.) | |||
| */ | |||
| #ifndef ZLIB_IO_MAX | |||
| # define ZLIB_IO_MAX ((uInt)-1) | |||
| #endif | |||
| #ifdef PNG_WRITE_SUPPORTED | |||
| /* The type of a compression buffer list used by the write code. */ | |||
| typedef struct png_compression_buffer | |||
| { | |||
| struct png_compression_buffer *next; | |||
| png_byte output[1]; /* actually zbuf_size */ | |||
| } png_compression_buffer, *png_compression_bufferp; | |||
| #define PNG_COMPRESSION_BUFFER_SIZE(pp)\ | |||
| (offsetof(png_compression_buffer, output) + (pp)->zbuffer_size) | |||
| #endif | |||
| /* Colorspace support; structures used in png_struct, png_info and in internal | |||
| * functions to hold and communicate information about the color space. | |||
| * | |||
| * PNG_COLORSPACE_SUPPORTED is only required if the application will perform | |||
| * colorspace corrections, otherwise all the colorspace information can be | |||
| * skipped and the size of libpng can be reduced (significantly) by compiling | |||
| * out the colorspace support. | |||
| */ | |||
| #ifdef PNG_COLORSPACE_SUPPORTED | |||
| /* The chromaticities of the red, green and blue colorants and the chromaticity | |||
| * of the corresponding white point (i.e. of rgb(1.0,1.0,1.0)). | |||
| */ | |||
| typedef struct png_xy | |||
| { | |||
| png_fixed_point redx, redy; | |||
| png_fixed_point greenx, greeny; | |||
| png_fixed_point bluex, bluey; | |||
| png_fixed_point whitex, whitey; | |||
| } png_xy; | |||
| /* The same data as above but encoded as CIE XYZ values. When this data comes | |||
| * from chromaticities the sum of the Y values is assumed to be 1.0 | |||
| */ | |||
| typedef struct png_XYZ | |||
| { | |||
| png_fixed_point red_X, red_Y, red_Z; | |||
| png_fixed_point green_X, green_Y, green_Z; | |||
| png_fixed_point blue_X, blue_Y, blue_Z; | |||
| } png_XYZ; | |||
| #endif /* COLORSPACE */ | |||
| #if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED) | |||
| /* A colorspace is all the above plus, potentially, profile information; | |||
| * however at present libpng does not use the profile internally so it is only | |||
| * stored in the png_info struct (if iCCP is supported.) The rendering intent | |||
| * is retained here and is checked. | |||
| * | |||
| * The file gamma encoding information is also stored here and gamma correction | |||
| * is done by libpng, whereas color correction must currently be done by the | |||
| * application. | |||
| */ | |||
| typedef struct png_colorspace | |||
| { | |||
| #ifdef PNG_GAMMA_SUPPORTED | |||
| png_fixed_point gamma; /* File gamma */ | |||
| #endif | |||
| #ifdef PNG_COLORSPACE_SUPPORTED | |||
| png_xy end_points_xy; /* End points as chromaticities */ | |||
| png_XYZ end_points_XYZ; /* End points as CIE XYZ colorant values */ | |||
| png_uint_16 rendering_intent; /* Rendering intent of a profile */ | |||
| #endif | |||
| /* Flags are always defined to simplify the code. */ | |||
| png_uint_16 flags; /* As defined below */ | |||
| } png_colorspace, * PNG_RESTRICT png_colorspacerp; | |||
| typedef const png_colorspace * PNG_RESTRICT png_const_colorspacerp; | |||
| /* General flags for the 'flags' field */ | |||
| #define PNG_COLORSPACE_HAVE_GAMMA 0x0001 | |||
| #define PNG_COLORSPACE_HAVE_ENDPOINTS 0x0002 | |||
| #define PNG_COLORSPACE_HAVE_INTENT 0x0004 | |||
| #define PNG_COLORSPACE_FROM_gAMA 0x0008 | |||
| #define PNG_COLORSPACE_FROM_cHRM 0x0010 | |||
| #define PNG_COLORSPACE_FROM_sRGB 0x0020 | |||
| #define PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB 0x0040 | |||
| #define PNG_COLORSPACE_MATCHES_sRGB 0x0080 /* exact match on profile */ | |||
| #define PNG_COLORSPACE_INVALID 0x8000 | |||
| #define PNG_COLORSPACE_CANCEL(flags) (0xffff ^ (flags)) | |||
| #endif /* COLORSPACE || GAMMA */ | |||
| struct png_struct_def | |||
| { | |||
| #ifdef PNG_SETJMP_SUPPORTED | |||
| jmp_buf jmp_buf_local; /* New name in 1.6.0 for jmp_buf in png_struct */ | |||
| png_longjmp_ptr longjmp_fn;/* setjmp non-local goto function. */ | |||
| jmp_buf *jmp_buf_ptr; /* passed to longjmp_fn */ | |||
| size_t jmp_buf_size; /* size of the above, if allocated */ | |||
| #endif | |||
| png_error_ptr error_fn; /* function for printing errors and aborting */ | |||
| #ifdef PNG_WARNINGS_SUPPORTED | |||
| png_error_ptr warning_fn; /* function for printing warnings */ | |||
| #endif | |||
| png_voidp error_ptr; /* user supplied struct for error functions */ | |||
| png_rw_ptr write_data_fn; /* function for writing output data */ | |||
| png_rw_ptr read_data_fn; /* function for reading input data */ | |||
| png_voidp io_ptr; /* ptr to application struct for I/O functions */ | |||
| #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED | |||
| png_user_transform_ptr read_user_transform_fn; /* user read transform */ | |||
| #endif | |||
| #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED | |||
| png_user_transform_ptr write_user_transform_fn; /* user write transform */ | |||
| #endif | |||
| /* These were added in libpng-1.0.2 */ | |||
| #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED | |||
| #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ | |||
| defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) | |||
| png_voidp user_transform_ptr; /* user supplied struct for user transform */ | |||
| png_byte user_transform_depth; /* bit depth of user transformed pixels */ | |||
| png_byte user_transform_channels; /* channels in user transformed pixels */ | |||
| #endif | |||
| #endif | |||
| png_uint_32 mode; /* tells us where we are in the PNG file */ | |||
| png_uint_32 flags; /* flags indicating various things to libpng */ | |||
| png_uint_32 transformations; /* which transformations to perform */ | |||
| png_uint_32 zowner; /* ID (chunk type) of zstream owner, 0 if none */ | |||
| z_stream zstream; /* decompression structure */ | |||
| #ifdef PNG_WRITE_SUPPORTED | |||
| png_compression_bufferp zbuffer_list; /* Created on demand during write */ | |||
| uInt zbuffer_size; /* size of the actual buffer */ | |||
| int zlib_level; /* holds zlib compression level */ | |||
| int zlib_method; /* holds zlib compression method */ | |||
| int zlib_window_bits; /* holds zlib compression window bits */ | |||
| int zlib_mem_level; /* holds zlib compression memory level */ | |||
| int zlib_strategy; /* holds zlib compression strategy */ | |||
| #endif | |||
| /* Added at libpng 1.5.4 */ | |||
| #ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED | |||
| int zlib_text_level; /* holds zlib compression level */ | |||
| int zlib_text_method; /* holds zlib compression method */ | |||
| int zlib_text_window_bits; /* holds zlib compression window bits */ | |||
| int zlib_text_mem_level; /* holds zlib compression memory level */ | |||
| int zlib_text_strategy; /* holds zlib compression strategy */ | |||
| #endif | |||
| /* End of material added at libpng 1.5.4 */ | |||
| /* Added at libpng 1.6.0 */ | |||
| #ifdef PNG_WRITE_SUPPORTED | |||
| int zlib_set_level; /* Actual values set into the zstream on write */ | |||
| int zlib_set_method; | |||
| int zlib_set_window_bits; | |||
| int zlib_set_mem_level; | |||
| int zlib_set_strategy; | |||
| #endif | |||
| png_uint_32 width; /* width of image in pixels */ | |||
| png_uint_32 height; /* height of image in pixels */ | |||
| png_uint_32 num_rows; /* number of rows in current pass */ | |||
| png_uint_32 usr_width; /* width of row at start of write */ | |||
| size_t rowbytes; /* size of row in bytes */ | |||
| png_uint_32 iwidth; /* width of current interlaced row in pixels */ | |||
| png_uint_32 row_number; /* current row in interlace pass */ | |||
| png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */ | |||
| png_bytep prev_row; /* buffer to save previous (unfiltered) row. | |||
| * While reading this is a pointer into | |||
| * big_prev_row; while writing it is separately | |||
| * allocated if needed. | |||
| */ | |||
| png_bytep row_buf; /* buffer to save current (unfiltered) row. | |||
| * While reading, this is a pointer into | |||
| * big_row_buf; while writing it is separately | |||
| * allocated. | |||
| */ | |||
| #ifdef PNG_WRITE_FILTER_SUPPORTED | |||
| png_bytep try_row; /* buffer to save trial row when filtering */ | |||
| png_bytep tst_row; /* buffer to save best trial row when filtering */ | |||
| #endif | |||
| size_t info_rowbytes; /* Added in 1.5.4: cache of updated row bytes */ | |||
| png_uint_32 idat_size; /* current IDAT size for read */ | |||
| png_uint_32 crc; /* current chunk CRC value */ | |||
| png_colorp palette; /* palette from the input file */ | |||
| png_uint_16 num_palette; /* number of color entries in palette */ | |||
| /* Added at libpng-1.5.10 */ | |||
| #ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED | |||
| int num_palette_max; /* maximum palette index found in IDAT */ | |||
| #endif | |||
| png_uint_16 num_trans; /* number of transparency values */ | |||
| png_byte compression; /* file compression type (always 0) */ | |||
| png_byte filter; /* file filter type (always 0) */ | |||
| png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */ | |||
| png_byte pass; /* current interlace pass (0 - 6) */ | |||
| png_byte do_filter; /* row filter flags (see PNG_FILTER_ in png.h ) */ | |||
| png_byte color_type; /* color type of file */ | |||
| png_byte bit_depth; /* bit depth of file */ | |||
| png_byte usr_bit_depth; /* bit depth of users row: write only */ | |||
| png_byte pixel_depth; /* number of bits per pixel */ | |||
| png_byte channels; /* number of channels in file */ | |||
| #ifdef PNG_WRITE_SUPPORTED | |||
| png_byte usr_channels; /* channels at start of write: write only */ | |||
| #endif | |||
| png_byte sig_bytes; /* magic bytes read/written from start of file */ | |||
| png_byte maximum_pixel_depth; | |||
| /* pixel depth used for the row buffers */ | |||
| png_byte transformed_pixel_depth; | |||
| /* pixel depth after read/write transforms */ | |||
| #if ZLIB_VERNUM >= 0x1240 | |||
| png_byte zstream_start; /* at start of an input zlib stream */ | |||
| #endif /* Zlib >= 1.2.4 */ | |||
| #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) | |||
| png_uint_16 filler; /* filler bytes for pixel expansion */ | |||
| #endif | |||
| #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ | |||
| defined(PNG_READ_ALPHA_MODE_SUPPORTED) | |||
| png_byte background_gamma_type; | |||
| png_fixed_point background_gamma; | |||
| png_color_16 background; /* background color in screen gamma space */ | |||
| #ifdef PNG_READ_GAMMA_SUPPORTED | |||
| png_color_16 background_1; /* background normalized to gamma 1.0 */ | |||
| #endif | |||
| #endif /* bKGD */ | |||
| #ifdef PNG_WRITE_FLUSH_SUPPORTED | |||
| png_flush_ptr output_flush_fn; /* Function for flushing output */ | |||
| png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */ | |||
| png_uint_32 flush_rows; /* number of rows written since last flush */ | |||
| #endif | |||
| #ifdef PNG_READ_GAMMA_SUPPORTED | |||
| int gamma_shift; /* number of "insignificant" bits in 16-bit gamma */ | |||
| png_fixed_point screen_gamma; /* screen gamma value (display_exponent) */ | |||
| png_bytep gamma_table; /* gamma table for 8-bit depth files */ | |||
| png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */ | |||
| #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ | |||
| defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ | |||
| defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) | |||
| png_bytep gamma_from_1; /* converts from 1.0 to screen */ | |||
| png_bytep gamma_to_1; /* converts from file to 1.0 */ | |||
| png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */ | |||
| png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */ | |||
| #endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ | |||
| #endif | |||
| #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED) | |||
| png_color_8 sig_bit; /* significant bits in each available channel */ | |||
| #endif | |||
| #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) | |||
| png_color_8 shift; /* shift for significant bit transformation */ | |||
| #endif | |||
| #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \ | |||
| || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) | |||
| png_bytep trans_alpha; /* alpha values for paletted files */ | |||
| png_color_16 trans_color; /* transparent color for non-paletted files */ | |||
| #endif | |||
| png_read_status_ptr read_row_fn; /* called after each row is decoded */ | |||
| png_write_status_ptr write_row_fn; /* called after each row is encoded */ | |||
| #ifdef PNG_PROGRESSIVE_READ_SUPPORTED | |||
| png_progressive_info_ptr info_fn; /* called after header data fully read */ | |||
| png_progressive_row_ptr row_fn; /* called after a prog. row is decoded */ | |||
| png_progressive_end_ptr end_fn; /* called after image is complete */ | |||
| png_bytep save_buffer_ptr; /* current location in save_buffer */ | |||
| png_bytep save_buffer; /* buffer for previously read data */ | |||
| png_bytep current_buffer_ptr; /* current location in current_buffer */ | |||
| png_bytep current_buffer; /* buffer for recently used data */ | |||
| png_uint_32 push_length; /* size of current input chunk */ | |||
| png_uint_32 skip_length; /* bytes to skip in input data */ | |||
| size_t save_buffer_size; /* amount of data now in save_buffer */ | |||
| size_t save_buffer_max; /* total size of save_buffer */ | |||
| size_t buffer_size; /* total amount of available input data */ | |||
| size_t current_buffer_size; /* amount of data now in current_buffer */ | |||
| int process_mode; /* what push library is currently doing */ | |||
| int cur_palette; /* current push library palette index */ | |||
| #endif /* PROGRESSIVE_READ */ | |||
| #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) | |||
| /* For the Borland special 64K segment handler */ | |||
| png_bytepp offset_table_ptr; | |||
| png_bytep offset_table; | |||
| png_uint_16 offset_table_number; | |||
| png_uint_16 offset_table_count; | |||
| png_uint_16 offset_table_count_free; | |||
| #endif | |||
| #ifdef PNG_READ_QUANTIZE_SUPPORTED | |||
| png_bytep palette_lookup; /* lookup table for quantizing */ | |||
| png_bytep quantize_index; /* index translation for palette files */ | |||
| #endif | |||
| /* Options */ | |||
| #ifdef PNG_SET_OPTION_SUPPORTED | |||
| png_uint_32 options; /* On/off state (up to 16 options) */ | |||
| #endif | |||
| #if PNG_LIBPNG_VER < 10700 | |||
| /* To do: remove this from libpng-1.7 */ | |||
| #ifdef PNG_TIME_RFC1123_SUPPORTED | |||
| char time_buffer[29]; /* String to hold RFC 1123 time text */ | |||
| #endif | |||
| #endif | |||
| /* New members added in libpng-1.0.6 */ | |||
| png_uint_32 free_me; /* flags items libpng is responsible for freeing */ | |||
| #ifdef PNG_USER_CHUNKS_SUPPORTED | |||
| png_voidp user_chunk_ptr; | |||
| #ifdef PNG_READ_USER_CHUNKS_SUPPORTED | |||
| png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */ | |||
| #endif | |||
| #endif | |||
| #ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED | |||
| int unknown_default; /* As PNG_HANDLE_* */ | |||
| unsigned int num_chunk_list; /* Number of entries in the list */ | |||
| png_bytep chunk_list; /* List of png_byte[5]; the textual chunk name | |||
| * followed by a PNG_HANDLE_* byte */ | |||
| #endif | |||
| /* New members added in libpng-1.0.3 */ | |||
| #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED | |||
| png_byte rgb_to_gray_status; | |||
| /* Added in libpng 1.5.5 to record setting of coefficients: */ | |||
| png_byte rgb_to_gray_coefficients_set; | |||
| /* These were changed from png_byte in libpng-1.0.6 */ | |||
| png_uint_16 rgb_to_gray_red_coeff; | |||
| png_uint_16 rgb_to_gray_green_coeff; | |||
| /* deleted in 1.5.5: rgb_to_gray_blue_coeff; */ | |||
| #endif | |||
| /* New member added in libpng-1.6.36 */ | |||
| #if defined(PNG_READ_EXPAND_SUPPORTED) && \ | |||
| defined(PNG_ARM_NEON_IMPLEMENTATION) | |||
| png_bytep riffled_palette; /* buffer for accelerated palette expansion */ | |||
| #endif | |||
| /* New member added in libpng-1.0.4 (renamed in 1.0.9) */ | |||
| #if defined(PNG_MNG_FEATURES_SUPPORTED) | |||
| /* Changed from png_byte to png_uint_32 at version 1.2.0 */ | |||
| png_uint_32 mng_features_permitted; | |||
| #endif | |||
| /* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */ | |||
| #ifdef PNG_MNG_FEATURES_SUPPORTED | |||
| png_byte filter_type; | |||
| #endif | |||
| /* New members added in libpng-1.2.0 */ | |||
| /* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */ | |||
| #ifdef PNG_USER_MEM_SUPPORTED | |||
| png_voidp mem_ptr; /* user supplied struct for mem functions */ | |||
| png_malloc_ptr malloc_fn; /* function for allocating memory */ | |||
| png_free_ptr free_fn; /* function for freeing memory */ | |||
| #endif | |||
| /* New member added in libpng-1.0.13 and 1.2.0 */ | |||
| png_bytep big_row_buf; /* buffer to save current (unfiltered) row */ | |||
| #ifdef PNG_READ_QUANTIZE_SUPPORTED | |||
| /* The following three members were added at version 1.0.14 and 1.2.4 */ | |||
| png_bytep quantize_sort; /* working sort array */ | |||
| png_bytep index_to_palette; /* where the original index currently is | |||
| in the palette */ | |||
| png_bytep palette_to_index; /* which original index points to this | |||
| palette color */ | |||
| #endif | |||
| /* New members added in libpng-1.0.16 and 1.2.6 */ | |||
| png_byte compression_type; | |||
| #ifdef PNG_USER_LIMITS_SUPPORTED | |||
| png_uint_32 user_width_max; | |||
| png_uint_32 user_height_max; | |||
| /* Added in libpng-1.4.0: Total number of sPLT, text, and unknown | |||
| * chunks that can be stored (0 means unlimited). | |||
| */ | |||
| png_uint_32 user_chunk_cache_max; | |||
| /* Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk | |||
| * can occupy when decompressed. 0 means unlimited. | |||
| */ | |||
| png_alloc_size_t user_chunk_malloc_max; | |||
| #endif | |||
| /* New member added in libpng-1.0.25 and 1.2.17 */ | |||
| #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED | |||
| /* Temporary storage for unknown chunk that the library doesn't recognize, | |||
| * used while reading the chunk. | |||
| */ | |||
| png_unknown_chunk unknown_chunk; | |||
| #endif | |||
| /* New member added in libpng-1.2.26 */ | |||
| size_t old_big_row_buf_size; | |||
| #ifdef PNG_READ_SUPPORTED | |||
| /* New member added in libpng-1.2.30 */ | |||
| png_bytep read_buffer; /* buffer for reading chunk data */ | |||
| png_alloc_size_t read_buffer_size; /* current size of the buffer */ | |||
| #endif | |||
| #ifdef PNG_SEQUENTIAL_READ_SUPPORTED | |||
| uInt IDAT_read_size; /* limit on read buffer size for IDAT */ | |||
| #endif | |||
| #ifdef PNG_IO_STATE_SUPPORTED | |||
| /* New member added in libpng-1.4.0 */ | |||
| png_uint_32 io_state; | |||
| #endif | |||
| /* New member added in libpng-1.5.6 */ | |||
| png_bytep big_prev_row; | |||
| /* New member added in libpng-1.5.7 */ | |||
| void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_row_infop row_info, | |||
| png_bytep row, png_const_bytep prev_row); | |||
| #ifdef PNG_READ_SUPPORTED | |||
| #if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED) | |||
| png_colorspace colorspace; | |||
| #endif | |||
| #endif | |||
| }; | |||
| #endif /* PNGSTRUCT_H */ | |||
| @@ -1,164 +1,168 @@ | |||
| /* pngwio.c - functions for data output | |||
| * | |||
| * Last changed in libpng 1.6.0 [February 14, 2013] | |||
| * Copyright (c) 1998-2013 Glenn Randers-Pehrson | |||
| * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | |||
| * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | |||
| * | |||
| * This code is released under the libpng license. | |||
| * For conditions of distribution and use, see the disclaimer | |||
| * and license in png.h | |||
| * | |||
| * This file provides a location for all output. Users who need | |||
| * special handling are expected to write functions that have the same | |||
| * arguments as these and perform similar functions, but that possibly | |||
| * use different output methods. Note that you shouldn't change these | |||
| * functions, but rather write replacement functions and then change | |||
| * them at run time with png_set_write_fn(...). | |||
| */ | |||
| #include "pngpriv.h" | |||
| #ifdef PNG_WRITE_SUPPORTED | |||
| /* Write the data to whatever output you are using. The default routine | |||
| * writes to a file pointer. Note that this routine sometimes gets called | |||
| * with very small lengths, so you should implement some kind of simple | |||
| * buffering if you are using unbuffered writes. This should never be asked | |||
| * to write more than 64K on a 16 bit machine. | |||
| */ | |||
| void /* PRIVATE */ | |||
| png_write_data(png_structrp png_ptr, png_const_bytep data, png_size_t length) | |||
| { | |||
| /* NOTE: write_data_fn must not change the buffer! */ | |||
| if (png_ptr->write_data_fn != NULL ) | |||
| (*(png_ptr->write_data_fn))(png_ptr, png_constcast(png_bytep,data), | |||
| length); | |||
| else | |||
| png_error(png_ptr, "Call to NULL write function"); | |||
| } | |||
| #ifdef PNG_STDIO_SUPPORTED | |||
| /* This is the function that does the actual writing of data. If you are | |||
| * not writing to a standard C stream, you should create a replacement | |||
| * write_data function and use it at run time with png_set_write_fn(), rather | |||
| * than changing the library. | |||
| */ | |||
| void PNGCBAPI | |||
| png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) | |||
| { | |||
| png_size_t check; | |||
| if (png_ptr == NULL) | |||
| return; | |||
| check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr)); | |||
| if (check != length) | |||
| png_error(png_ptr, "Write Error"); | |||
| } | |||
| #endif | |||
| /* This function is called to output any data pending writing (normally | |||
| * to disk). After png_flush is called, there should be no data pending | |||
| * writing in any buffers. | |||
| */ | |||
| #ifdef PNG_WRITE_FLUSH_SUPPORTED | |||
| void /* PRIVATE */ | |||
| png_flush(png_structrp png_ptr) | |||
| { | |||
| if (png_ptr->output_flush_fn != NULL) | |||
| (*(png_ptr->output_flush_fn))(png_ptr); | |||
| } | |||
| # ifdef PNG_STDIO_SUPPORTED | |||
| void PNGCBAPI | |||
| png_default_flush(png_structp png_ptr) | |||
| { | |||
| png_FILE_p io_ptr; | |||
| if (png_ptr == NULL) | |||
| return; | |||
| io_ptr = png_voidcast(png_FILE_p, (png_ptr->io_ptr)); | |||
| fflush(io_ptr); | |||
| } | |||
| # endif | |||
| #endif | |||
| /* This function allows the application to supply new output functions for | |||
| * libpng if standard C streams aren't being used. | |||
| * | |||
| * This function takes as its arguments: | |||
| * png_ptr - pointer to a png output data structure | |||
| * io_ptr - pointer to user supplied structure containing info about | |||
| * the output functions. May be NULL. | |||
| * write_data_fn - pointer to a new output function that takes as its | |||
| * arguments a pointer to a png_struct, a pointer to | |||
| * data to be written, and a 32-bit unsigned int that is | |||
| * the number of bytes to be written. The new write | |||
| * function should call png_error(png_ptr, "Error msg") | |||
| * to exit and output any fatal error messages. May be | |||
| * NULL, in which case libpng's default function will | |||
| * be used. | |||
| * flush_data_fn - pointer to a new flush function that takes as its | |||
| * arguments a pointer to a png_struct. After a call to | |||
| * the flush function, there should be no data in any buffers | |||
| * or pending transmission. If the output method doesn't do | |||
| * any buffering of output, a function prototype must still be | |||
| * supplied although it doesn't have to do anything. If | |||
| * PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile | |||
| * time, output_flush_fn will be ignored, although it must be | |||
| * supplied for compatibility. May be NULL, in which case | |||
| * libpng's default function will be used, if | |||
| * PNG_WRITE_FLUSH_SUPPORTED is defined. This is not | |||
| * a good idea if io_ptr does not point to a standard | |||
| * *FILE structure. | |||
| */ | |||
| void PNGAPI | |||
| png_set_write_fn(png_structrp png_ptr, png_voidp io_ptr, | |||
| png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn) | |||
| { | |||
| if (png_ptr == NULL) | |||
| return; | |||
| png_ptr->io_ptr = io_ptr; | |||
| #ifdef PNG_STDIO_SUPPORTED | |||
| if (write_data_fn != NULL) | |||
| png_ptr->write_data_fn = write_data_fn; | |||
| else | |||
| png_ptr->write_data_fn = png_default_write_data; | |||
| #else | |||
| png_ptr->write_data_fn = write_data_fn; | |||
| #endif | |||
| #ifdef PNG_WRITE_FLUSH_SUPPORTED | |||
| # ifdef PNG_STDIO_SUPPORTED | |||
| if (output_flush_fn != NULL) | |||
| png_ptr->output_flush_fn = output_flush_fn; | |||
| else | |||
| png_ptr->output_flush_fn = png_default_flush; | |||
| # else | |||
| png_ptr->output_flush_fn = output_flush_fn; | |||
| # endif | |||
| #endif /* PNG_WRITE_FLUSH_SUPPORTED */ | |||
| /* It is an error to read while writing a png file */ | |||
| if (png_ptr->read_data_fn != NULL) | |||
| { | |||
| png_ptr->read_data_fn = NULL; | |||
| png_warning(png_ptr, | |||
| "Can't set both read_data_fn and write_data_fn in the" | |||
| " same structure"); | |||
| } | |||
| } | |||
| #endif /* PNG_WRITE_SUPPORTED */ | |||
| /* pngwio.c - functions for data output | |||
| * | |||
| * Copyright (c) 2018 Cosmin Truta | |||
| * Copyright (c) 1998-2002,2004,2006-2014,2016,2018 Glenn Randers-Pehrson | |||
| * Copyright (c) 1996-1997 Andreas Dilger | |||
| * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. | |||
| * | |||
| * This code is released under the libpng license. | |||
| * For conditions of distribution and use, see the disclaimer | |||
| * and license in png.h | |||
| * | |||
| * This file provides a location for all output. Users who need | |||
| * special handling are expected to write functions that have the same | |||
| * arguments as these and perform similar functions, but that possibly | |||
| * use different output methods. Note that you shouldn't change these | |||
| * functions, but rather write replacement functions and then change | |||
| * them at run time with png_set_write_fn(...). | |||
| */ | |||
| #include "pngpriv.h" | |||
| #ifdef PNG_WRITE_SUPPORTED | |||
| /* Write the data to whatever output you are using. The default routine | |||
| * writes to a file pointer. Note that this routine sometimes gets called | |||
| * with very small lengths, so you should implement some kind of simple | |||
| * buffering if you are using unbuffered writes. This should never be asked | |||
| * to write more than 64K on a 16-bit machine. | |||
| */ | |||
| void /* PRIVATE */ | |||
| png_write_data(png_structrp png_ptr, png_const_bytep data, size_t length) | |||
| { | |||
| /* NOTE: write_data_fn must not change the buffer! */ | |||
| if (png_ptr->write_data_fn != NULL ) | |||
| (*(png_ptr->write_data_fn))(png_ptr, png_constcast(png_bytep,data), | |||
| length); | |||
| else | |||
| png_error(png_ptr, "Call to NULL write function"); | |||
| } | |||
| #ifdef PNG_STDIO_SUPPORTED | |||
| /* This is the function that does the actual writing of data. If you are | |||
| * not writing to a standard C stream, you should create a replacement | |||
| * write_data function and use it at run time with png_set_write_fn(), rather | |||
| * than changing the library. | |||
| */ | |||
| void PNGCBAPI | |||
| png_default_write_data(png_structp png_ptr, png_bytep data, size_t length) | |||
| { | |||
| size_t check; | |||
| if (png_ptr == NULL) | |||
| return; | |||
| check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr)); | |||
| if (check != length) | |||
| png_error(png_ptr, "Write Error"); | |||
| } | |||
| #endif | |||
| /* This function is called to output any data pending writing (normally | |||
| * to disk). After png_flush is called, there should be no data pending | |||
| * writing in any buffers. | |||
| */ | |||
| #ifdef PNG_WRITE_FLUSH_SUPPORTED | |||
| void /* PRIVATE */ | |||
| png_flush(png_structrp png_ptr) | |||
| { | |||
| if (png_ptr->output_flush_fn != NULL) | |||
| (*(png_ptr->output_flush_fn))(png_ptr); | |||
| } | |||
| # ifdef PNG_STDIO_SUPPORTED | |||
| void PNGCBAPI | |||
| png_default_flush(png_structp png_ptr) | |||
| { | |||
| png_FILE_p io_ptr; | |||
| if (png_ptr == NULL) | |||
| return; | |||
| io_ptr = png_voidcast(png_FILE_p, (png_ptr->io_ptr)); | |||
| fflush(io_ptr); | |||
| } | |||
| # endif | |||
| #endif | |||
| /* This function allows the application to supply new output functions for | |||
| * libpng if standard C streams aren't being used. | |||
| * | |||
| * This function takes as its arguments: | |||
| * png_ptr - pointer to a png output data structure | |||
| * io_ptr - pointer to user supplied structure containing info about | |||
| * the output functions. May be NULL. | |||
| * write_data_fn - pointer to a new output function that takes as its | |||
| * arguments a pointer to a png_struct, a pointer to | |||
| * data to be written, and a 32-bit unsigned int that is | |||
| * the number of bytes to be written. The new write | |||
| * function should call png_error(png_ptr, "Error msg") | |||
| * to exit and output any fatal error messages. May be | |||
| * NULL, in which case libpng's default function will | |||
| * be used. | |||
| * flush_data_fn - pointer to a new flush function that takes as its | |||
| * arguments a pointer to a png_struct. After a call to | |||
| * the flush function, there should be no data in any buffers | |||
| * or pending transmission. If the output method doesn't do | |||
| * any buffering of output, a function prototype must still be | |||
| * supplied although it doesn't have to do anything. If | |||
| * PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile | |||
| * time, output_flush_fn will be ignored, although it must be | |||
| * supplied for compatibility. May be NULL, in which case | |||
| * libpng's default function will be used, if | |||
| * PNG_WRITE_FLUSH_SUPPORTED is defined. This is not | |||
| * a good idea if io_ptr does not point to a standard | |||
| * *FILE structure. | |||
| */ | |||
| void PNGAPI | |||
| png_set_write_fn(png_structrp png_ptr, png_voidp io_ptr, | |||
| png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn) | |||
| { | |||
| if (png_ptr == NULL) | |||
| return; | |||
| png_ptr->io_ptr = io_ptr; | |||
| #ifdef PNG_STDIO_SUPPORTED | |||
| if (write_data_fn != NULL) | |||
| png_ptr->write_data_fn = write_data_fn; | |||
| else | |||
| png_ptr->write_data_fn = png_default_write_data; | |||
| #else | |||
| png_ptr->write_data_fn = write_data_fn; | |||
| #endif | |||
| #ifdef PNG_WRITE_FLUSH_SUPPORTED | |||
| # ifdef PNG_STDIO_SUPPORTED | |||
| if (output_flush_fn != NULL) | |||
| png_ptr->output_flush_fn = output_flush_fn; | |||
| else | |||
| png_ptr->output_flush_fn = png_default_flush; | |||
| # else | |||
| png_ptr->output_flush_fn = output_flush_fn; | |||
| # endif | |||
| #else | |||
| PNG_UNUSED(output_flush_fn) | |||
| #endif /* WRITE_FLUSH */ | |||
| #ifdef PNG_READ_SUPPORTED | |||
| /* It is an error to read while writing a png file */ | |||
| if (png_ptr->read_data_fn != NULL) | |||
| { | |||
| png_ptr->read_data_fn = NULL; | |||
| png_warning(png_ptr, | |||
| "Can't set both read_data_fn and write_data_fn in the" | |||
| " same structure"); | |||
| } | |||
| #endif | |||
| } | |||
| #endif /* WRITE */ | |||