1 
2 /* pngpriv.h - private declarations for use inside libpng
3  *
4  * Copyright (c) 2018-2019 Cosmin Truta
5  * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
6  * Copyright (c) 1996-1997 Andreas Dilger
7  * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
8  *
9  * This code is released under the libpng license.
10  * For conditions of distribution and use, see the disclaimer
11  * and license in png.h
12  */
13 
14 #ifndef PNGPRIV_H
15 #define PNGPRIV_H
16 #ifndef _POSIX_SOURCE
17 # define _POSIX_SOURCE 1
18 #endif
19 
20 #ifndef PNG_VERSION_INFO_ONLY
21 #  include <stdlib.h>
22 #  include <string.h>
23 #endif
24 
25 #define PNGLIB_BUILD
26 #if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)
27 #  include <config.h>
28 #  define PNG_RESTRICT restrict
29 #endif
30 #ifndef PNGLCONF_H
31 #  include "pnglibconf.h"
32 #endif
33 #if defined(PNG_PREFIX) && !defined(PNGPREFIX_H)
34 #  include "pngprefix.h"
35 #endif
36 
37 #ifdef PNG_USER_CONFIG
38 #  include "pngusr.h"
39 #  ifndef PNG_USER_PRIVATEBUILD
40 #    define PNG_USER_PRIVATEBUILD "Custom libpng build"
41 #  endif
42 #  ifndef PNG_USER_DLLFNAME_POSTFIX
43 #    define PNG_USER_DLLFNAME_POSTFIX "Cb"
44 #  endif
45 #endif
46 
47 #ifndef PNG_ARM_NEON_OPT
48 #  if (defined(__ARM_NEON__) || defined(__ARM_NEON)) && \
49    defined(PNG_ALIGNED_MEMORY_SUPPORTED)
50 #     define PNG_ARM_NEON_OPT 2
51 #  else
52 #     define PNG_ARM_NEON_OPT 0
53 #  endif
54 #endif
55 
56 #if PNG_ARM_NEON_OPT > 0
57 #  define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_neon
58 
59 #  ifndef PNG_ARM_NEON_IMPLEMENTATION
60 #     if defined(__ARM_NEON__) || defined(__ARM_NEON)
61 #        if defined(__clang__)
62 #        elif defined(__GNUC__)
63 #           if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
64 #              define PNG_ARM_NEON_IMPLEMENTATION 2
65 #           endif
66 #        endif
67 #     else
68 #        if !defined(__aarch64__)
69 #          define PNG_ARM_NEON_IMPLEMENTATION 2
70 #        endif
71 #     endif
72 #  endif
73 
74 #  ifndef PNG_ARM_NEON_IMPLEMENTATION
75 #     define PNG_ARM_NEON_IMPLEMENTATION 1
76 #  endif
77 #endif
78 
79 #ifndef PNG_MIPS_MSA_OPT
80 #  if defined(__mips_msa) && (__mips_isa_rev >= 5) && defined(PNG_ALIGNED_MEMORY_SUPPORTED)
81 #     define PNG_MIPS_MSA_OPT 2
82 #  else
83 #     define PNG_MIPS_MSA_OPT 0
84 #  endif
85 #endif
86 
87 #ifndef PNG_POWERPC_VSX_OPT
88 #  if defined(__PPC64__) && defined(__ALTIVEC__) && defined(__VSX__)
89 #     define PNG_POWERPC_VSX_OPT 2
90 #  else
91 #     define PNG_POWERPC_VSX_OPT 0
92 #  endif
93 #endif
94 
95 #ifndef PNG_INTEL_SSE_OPT
96 #   ifdef PNG_INTEL_SSE
97 #     if defined(__SSE4_1__) || defined(__AVX__) || defined(__SSSE3__) || \
98        defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \
99        (defined(_M_IX86_FP) && _M_IX86_FP >= 2)
100 #         define PNG_INTEL_SSE_OPT 1
101 #      else
102 #         define PNG_INTEL_SSE_OPT 0
103 #      endif
104 #   else
105 #      define PNG_INTEL_SSE_OPT 0
106 #   endif
107 #endif
108 
109 #if PNG_INTEL_SSE_OPT > 0
110 #   ifndef PNG_INTEL_SSE_IMPLEMENTATION
111 #      if defined(__SSE4_1__) || defined(__AVX__)
112 #         define PNG_INTEL_SSE_IMPLEMENTATION 3
113 #      elif defined(__SSSE3__)
114 #         define PNG_INTEL_SSE_IMPLEMENTATION 2
115 #      elif defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \
116        (defined(_M_IX86_FP) && _M_IX86_FP >= 2)
117 #         define PNG_INTEL_SSE_IMPLEMENTATION 1
118 #      else
119 #         define PNG_INTEL_SSE_IMPLEMENTATION 0
120 #      endif
121 #   endif
122 
123 #   if PNG_INTEL_SSE_IMPLEMENTATION > 0
124 #      define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_sse2
125 #   endif
126 #else
127 #   define PNG_INTEL_SSE_IMPLEMENTATION 0
128 #endif
129 
130 #if PNG_MIPS_MSA_OPT > 0
131 #  define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_msa
132 #  ifndef PNG_MIPS_MSA_IMPLEMENTATION
133 #     if defined(__mips_msa)
134 #        if defined(__clang__)
135 #        elif defined(__GNUC__)
136 #           if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
137 #              define PNG_MIPS_MSA_IMPLEMENTATION 2
138 #           endif
139 #        endif
140 #     else
141 #        define PNG_MIPS_MSA_IMPLEMENTATION 2
142 #     endif
143 #  endif
144 
145 #  ifndef PNG_MIPS_MSA_IMPLEMENTATION
146 #     define PNG_MIPS_MSA_IMPLEMENTATION 1
147 #  endif
148 #endif
149 
150 #if PNG_POWERPC_VSX_OPT > 0
151 #  define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_vsx
152 #  define PNG_POWERPC_VSX_IMPLEMENTATION 1
153 #endif
154 
155 
156 #ifndef PNG_BUILD_DLL
157 #  ifdef DLL_EXPORT
158 #     define PNG_BUILD_DLL
159 #  else
160 #     ifdef _WINDLL
161 #        define PNG_BUILD_DLL
162 #     else
163 #        ifdef __DLL__
164 #           define PNG_BUILD_DLL
165 #        else
166 #        endif
167 #     endif
168 #  endif
169 #endif
170 #ifndef PNG_IMPEXP
171 #  ifdef PNG_BUILD_DLL
172 #     define PNG_IMPEXP PNG_DLL_EXPORT
173 #  else
174 #     define PNG_IMPEXP
175 #  endif
176 #endif
177 #ifndef PNG_DEPRECATED
178 #  define PNG_DEPRECATED
179 #endif
180 #ifndef PNG_PRIVATE
181 #  define PNG_PRIVATE
182 #endif
183 #ifndef PNG_INTERNAL_DATA
184 #  define PNG_INTERNAL_DATA(type, name, array) PNG_LINKAGE_DATA type name array
185 #endif
186 
187 #ifndef PNG_INTERNAL_FUNCTION
188 #  define PNG_INTERNAL_FUNCTION(type, name, args, attributes)\
189       PNG_LINKAGE_FUNCTION PNG_FUNCTION(type, name, args, PNG_EMPTY attributes)
190 #endif
191 
192 #ifndef PNG_INTERNAL_CALLBACK
193 #  define PNG_INTERNAL_CALLBACK(type, name, args, attributes)\
194       PNG_LINKAGE_CALLBACK PNG_FUNCTION(type, (PNGCBAPI name), args,\
195          PNG_EMPTY attributes)
196 #endif
197 
198 #ifndef PNG_FP_EXPORT
199 #  ifndef PNG_FLOATING_POINT_SUPPORTED
200 #     define PNG_FP_EXPORT(ordinal, type, name, args)\
201          PNG_INTERNAL_FUNCTION(type, name, args, PNG_EMPTY);
202 #     ifndef PNG_VERSION_INFO_ONLY
203          typedef struct png_incomplete png_double;
204          typedef png_double*           png_doublep;
205          typedef const png_double*     png_const_doublep;
206          typedef png_double**          png_doublepp;
207 #     endif
208 #  endif
209 #endif
210 #ifndef PNG_FIXED_EXPORT
211 #  ifndef PNG_FIXED_POINT_SUPPORTED
212 #     define PNG_FIXED_EXPORT(ordinal, type, name, args)\
213          PNG_INTERNAL_FUNCTION(type, name, args, PNG_EMPTY);
214 #  endif
215 #endif
216 
217 #include "png.h"
218 #ifndef PNG_DLL_EXPORT
219 #  define PNG_DLL_EXPORT
220 #endif
221 
222 #ifndef PNG_RELEASE_BUILD
223 #  define PNG_RELEASE_BUILD (PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC)
224 #endif
225 
226 #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
227 #  define PNG_MAX_MALLOC_64K
228 #endif
229 
230 #ifndef PNG_UNUSED
231 #  define PNG_UNUSED(param) (void)param;
232 #endif
233 #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
234 #  undef PNG_ZBUF_SIZE
235 #  define PNG_ZBUF_SIZE 65536L
236 #endif
237 #ifdef PNG_WARNINGS_SUPPORTED
238 #  define PNG_WARNING_PARAMETERS(p) png_warning_parameters p;
239 #else
240 #  define png_warning_parameter(p,number,string) ((void)0)
241 #  define png_warning_parameter_unsigned(p,number,format,value) ((void)0)
242 #  define png_warning_parameter_signed(p,number,format,value) ((void)0)
243 #  define png_formatted_warning(pp,p,message) ((void)(pp))
244 #  define PNG_WARNING_PARAMETERS(p)
245 #endif
246 #ifndef PNG_ERROR_TEXT_SUPPORTED
247 #  define png_fixed_error(s1,s2) png_err(s1)
248 #endif
249 #ifdef PNG_FIXED_POINT_SUPPORTED
250 #  define PNGFAPI PNGAPI
251 #else
252 #  define PNGFAPI
253 #endif
254 
255 #ifndef PNG_VERSION_INFO_ONLY
256 #ifdef __cplusplus
257 #  define png_voidcast(type, value) static_cast<type>(value)
258 #  define png_constcast(type, value) const_cast<type>(value)
259 #  define png_aligncast(type, value) \
260    static_cast<type>(static_cast<void*>(value))
261 #  define png_aligncastconst(type, value) \
262    static_cast<type>(static_cast<const void*>(value))
263 #else
264 #  define png_voidcast(type, value) (value)
265 #  ifdef _WIN64
266 #     ifdef __GNUC__
267          typedef unsigned long long png_ptruint;
268 #     else
269          typedef unsigned __int64 png_ptruint;
270 #     endif
271 #  else
272       typedef unsigned long png_ptruint;
273 #  endif
274 #  define png_constcast(type, value) ((type)(png_ptruint)(const void*)(value))
275 #  define png_aligncast(type, value) ((void*)(value))
276 #  define png_aligncastconst(type, value) ((const void*)(value))
277 #endif
278 
279 #if defined(PNG_FLOATING_POINT_SUPPORTED) ||\
280     defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
281 #  include <float.h>
282 
283 #  if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
284     defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
285 #    if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
286 #      include <fp.h>
287 #    endif
288 #  else
289 #    include <math.h>
290 #  endif
291 #  if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
292 #    include <m68881.h>
293 #  endif
294 #endif
295 #if defined(__TURBOC__) && defined(__MSDOS__)
296 #  include <mem.h>
297 #  include <alloc.h>
298 #endif
299 
300 #if defined(WIN32) || defined(_Windows) || defined(_WINDOWS) || \
301     defined(_WIN32) || defined(__WIN32__)
302 #  include <windows.h>
303 #endif
304 #endif
305 #ifndef PNG_ABORT
306 #  ifdef _WINDOWS_
307 #    define PNG_ABORT() ExitProcess(0)
308 #  else
309 #    define PNG_ABORT() abort()
310 #  endif
311 #endif
312 #define PNG_ALIGN_NONE   0
313 #define PNG_ALIGN_ALWAYS 1
314 #ifdef offsetof
315 #  define PNG_ALIGN_OFFSET 2
316 #else
317 #  define PNG_ALIGN_OFFSET -1
318 #endif
319 #define PNG_ALIGN_SIZE   3
320 
321 #ifndef PNG_ALIGN_TYPE
322 #  define PNG_ALIGN_TYPE PNG_ALIGN_SIZE
323 #endif
324 
325 #if PNG_ALIGN_TYPE == PNG_ALIGN_SIZE
326 #  define png_alignof(type) (sizeof (type))
327 #else
328 #  if PNG_ALIGN_TYPE == PNG_ALIGN_OFFSET
329 #     define png_alignof(type) offsetof(struct{char c; type t;}, t)
330 #  else
331 #     if PNG_ALIGN_TYPE == PNG_ALIGN_ALWAYS
332 #        define png_alignof(type) (1)
333 #     endif
334 #  endif
335 #endif
336 #ifdef png_alignof
337 #  define png_isaligned(ptr, type)\
338    (((type)((const char*)ptr-(const char*)0) & \
339    (type)(png_alignof(type)-1)) == 0)
340 #else
341 #  define png_isaligned(ptr, type) 0
342 #endif
343 
344 #define PNG_HAVE_IDAT               0x04U
345 #define PNG_HAVE_IEND               0x10U
346 #define PNG_HAVE_CHUNK_HEADER      0x100U
347 #define PNG_WROTE_tIME             0x200U
348 #define PNG_WROTE_INFO_BEFORE_PLTE 0x400U
349 #define PNG_BACKGROUND_IS_GRAY     0x800U
350 #define PNG_HAVE_PNG_SIGNATURE    0x1000U
351 #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000U
352 #define PNG_IS_READ_STRUCT        0x8000U
353 #define PNG_BGR                 0x0001U
354 #define PNG_INTERLACE           0x0002U
355 #define PNG_PACK                0x0004U
356 #define PNG_SHIFT               0x0008U
357 #define PNG_SWAP_BYTES          0x0010U
358 #define PNG_INVERT_MONO         0x0020U
359 #define PNG_QUANTIZE            0x0040U
360 #define PNG_COMPOSE             0x0080U
361 #define PNG_BACKGROUND_EXPAND   0x0100U
362 #define PNG_EXPAND_16           0x0200U
363 #define PNG_16_TO_8             0x0400U
364 #define PNG_RGBA                0x0800U
365 #define PNG_EXPAND              0x1000U
366 #define PNG_GAMMA               0x2000U
367 #define PNG_GRAY_TO_RGB         0x4000U
368 #define PNG_FILLER              0x8000U
369 #define PNG_PACKSWAP           0x10000U
370 #define PNG_SWAP_ALPHA         0x20000U
371 #define PNG_STRIP_ALPHA        0x40000U
372 #define PNG_INVERT_ALPHA       0x80000U
373 #define PNG_USER_TRANSFORM    0x100000U
374 #define PNG_RGB_TO_GRAY_ERR   0x200000U
375 #define PNG_RGB_TO_GRAY_WARN  0x400000U
376 #define PNG_RGB_TO_GRAY       0x600000U
377 #define PNG_ENCODE_ALPHA      0x800000U
378 #define PNG_ADD_ALPHA        0x1000000U
379 #define PNG_EXPAND_tRNS      0x2000000U
380 #define PNG_SCALE_16_TO_8    0x4000000U
381 #define PNG_STRUCT_PNG   0x0001U
382 #define PNG_STRUCT_INFO  0x0002U
383 #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY     0x0001U
384 #define PNG_FLAG_ZSTREAM_INITIALIZED      0x0002U
385 #define PNG_FLAG_ZSTREAM_ENDED            0x0008U
386 #define PNG_FLAG_ROW_INIT                 0x0040U
387 #define PNG_FLAG_FILLER_AFTER             0x0080U
388 #define PNG_FLAG_CRC_ANCILLARY_USE        0x0100U
389 #define PNG_FLAG_CRC_ANCILLARY_NOWARN     0x0200U
390 #define PNG_FLAG_CRC_CRITICAL_USE         0x0400U
391 #define PNG_FLAG_CRC_CRITICAL_IGNORE      0x0800U
392 #define PNG_FLAG_ASSUME_sRGB              0x1000U
393 #define PNG_FLAG_OPTIMIZE_ALPHA           0x2000U
394 #define PNG_FLAG_DETECT_UNINITIALIZED     0x4000U
395 #define PNG_FLAG_LIBRARY_MISMATCH        0x20000U
396 #define PNG_FLAG_STRIP_ERROR_NUMBERS     0x40000U
397 #define PNG_FLAG_STRIP_ERROR_TEXT        0x80000U
398 #define PNG_FLAG_BENIGN_ERRORS_WARN     0x100000U
399 #define PNG_FLAG_APP_WARNINGS_WARN      0x200000U
400 #define PNG_FLAG_APP_ERRORS_WARN        0x400000U
401 
402 #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
403                                      PNG_FLAG_CRC_ANCILLARY_NOWARN)
404 
405 #define PNG_FLAG_CRC_CRITICAL_MASK  (PNG_FLAG_CRC_CRITICAL_USE | \
406                                      PNG_FLAG_CRC_CRITICAL_IGNORE)
407 
408 #define PNG_FLAG_CRC_MASK           (PNG_FLAG_CRC_ANCILLARY_MASK | \
409                                      PNG_FLAG_CRC_CRITICAL_MASK)
410 
411 #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
412    abs((int)((c1).green) - (int)((c2).green)) + \
413    abs((int)((c1).blue) - (int)((c2).blue)))
414 
415 #define PNG_DIV65535(v24) (((v24) + 32895) >> 16)
416 #define PNG_DIV257(v16) PNG_DIV65535((png_uint_32)(v16) * 255)
417 #define PNG_ROWBYTES(pixel_bits, width) \
418     ((pixel_bits) >= 8 ? \
419     ((size_t)(width) * (((size_t)(pixel_bits)) >> 3)) : \
420     (( ((size_t)(width) * ((size_t)(pixel_bits))) + 7) >> 3) )
421 
422 #define PNG_TRAILBITS(pixel_bits, width) \
423     (((pixel_bits) * ((width) % (png_uint_32)8)) % 8)
424 
425 #define PNG_PADBITS(pixel_bits, width) \
426     ((8 - PNG_TRAILBITS(pixel_bits, width)) % 8)
427 #define PNG_OUT_OF_RANGE(value, ideal, delta) \
428    ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
429 #ifdef PNG_FLOATING_POINT_SUPPORTED
430 #define png_float(png_ptr, fixed, s) (.00001 * (fixed))
431 
432 #ifdef PNG_FIXED_POINT_MACRO_SUPPORTED
433 #define png_fixed(png_ptr, fp, s) ((fp) <= 21474 && (fp) >= -21474 ?\
434     ((png_fixed_point)(100000 * (fp))) : (png_fixed_error(png_ptr, s),0))
435 #endif
436 #endif
437 
438 #define PNG_32b(b,s) ((png_uint_32)(b) << (s))
439 #define PNG_U32(b1,b2,b3,b4) \
440    (PNG_32b(b1,24) | PNG_32b(b2,16) | PNG_32b(b3,8) | PNG_32b(b4,0))
441 
442 #define png_IDAT PNG_U32( 73,  68,  65,  84)
443 #define png_IEND PNG_U32( 73,  69,  78,  68)
444 #define png_IHDR PNG_U32( 73,  72,  68,  82)
445 #define png_PLTE PNG_U32( 80,  76,  84,  69)
446 #define png_bKGD PNG_U32( 98,  75,  71,  68)
447 #define png_cHRM PNG_U32( 99,  72,  82,  77)
448 #define png_eXIf PNG_U32(101,  88,  73, 102)
449 #define png_fRAc PNG_U32(102,  82,  65,  99)
450 #define png_gAMA PNG_U32(103,  65,  77,  65)
451 #define png_gIFg PNG_U32(103,  73,  70, 103)
452 #define png_gIFt PNG_U32(103,  73,  70, 116)
453 #define png_gIFx PNG_U32(103,  73,  70, 120)
454 #define png_hIST PNG_U32(104,  73,  83,  84)
455 #define png_iCCP PNG_U32(105,  67,  67,  80)
456 #define png_iTXt PNG_U32(105,  84,  88, 116)
457 #define png_oFFs PNG_U32(111,  70,  70, 115)
458 #define png_pCAL PNG_U32(112,  67,  65,  76)
459 #define png_pHYs PNG_U32(112,  72,  89, 115)
460 #define png_sBIT PNG_U32(115,  66,  73,  84)
461 #define png_sCAL PNG_U32(115,  67,  65,  76)
462 #define png_sPLT PNG_U32(115,  80,  76,  84)
463 #define png_sRGB PNG_U32(115,  82,  71,  66)
464 #define png_sTER PNG_U32(115,  84,  69,  82)
465 #define png_tEXt PNG_U32(116,  69,  88, 116)
466 #define png_tIME PNG_U32(116,  73,  77,  69)
467 #define png_tRNS PNG_U32(116,  82,  78,  83)
468 #define png_zTXt PNG_U32(122,  84,  88, 116)
469 #define PNG_CHUNK_FROM_STRING(s)\
470    PNG_U32(0xff & (s)[0], 0xff & (s)[1], 0xff & (s)[2], 0xff & (s)[3])
471 #define PNG_STRING_FROM_CHUNK(s,c)\
472    (void)(((char*)(s))[0]=(char)(((c)>>24) & 0xff), \
473    ((char*)(s))[1]=(char)(((c)>>16) & 0xff),\
474    ((char*)(s))[2]=(char)(((c)>>8) & 0xff), \
475    ((char*)(s))[3]=(char)((c & 0xff)))
476 #define PNG_CSTRING_FROM_CHUNK(s,c)\
477    (void)(PNG_STRING_FROM_CHUNK(s,c), ((char*)(s))[4] = 0)
478 #define PNG_CHUNK_ANCILLARY(c)   (1 & ((c) >> 29))
479 #define PNG_CHUNK_CRITICAL(c)     (!PNG_CHUNK_ANCILLARY(c))
480 #define PNG_CHUNK_PRIVATE(c)      (1 & ((c) >> 21))
481 #define PNG_CHUNK_RESERVED(c)     (1 & ((c) >> 13))
482 #define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >>  5))
483 #define PNG_GAMMA_MAC_OLD 151724
484 #define PNG_GAMMA_MAC_INVERSE 65909
485 #define PNG_GAMMA_sRGB_INVERSE 45455
486 #ifndef PNG_VERSION_INFO_ONLY
487 
488 #include "pngstruct.h"
489 #include "pnginfo.h"
490 #if PNG_ZLIB_VERNUM != 0 && PNG_ZLIB_VERNUM != ZLIB_VERNUM
491 #  error ZLIB_VERNUM != PNG_ZLIB_VERNUM \
492       "-I (include path) error: see the notes in pngpriv.h"
493 #endif
494 typedef const png_uint_16p * png_const_uint_16pp;
495 #if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\
496    defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
497 #ifdef PNG_SIMPLIFIED_READ_SUPPORTED
498 PNG_INTERNAL_DATA(const png_uint_16, png_sRGB_table, [256]);
499 #endif
500 
501 PNG_INTERNAL_DATA(const png_uint_16, png_sRGB_base, [512]);
502 PNG_INTERNAL_DATA(const png_byte, png_sRGB_delta, [512]);
503 
504 #define PNG_sRGB_FROM_LINEAR(linear) \
505   ((png_byte)(0xff & ((png_sRGB_base[(linear)>>15] \
506    + ((((linear) & 0x7fff)*png_sRGB_delta[(linear)>>15])>>12)) >> 8)))
507 #endif
508 #ifdef __cplusplus
509 extern "C" {
510 #endif
511 #define PNG_UNEXPECTED_ZLIB_RETURN (-7)
512 PNG_INTERNAL_FUNCTION(void, png_zstream_error,(png_structrp png_ptr, int ret),
513    PNG_EMPTY);
514 
515 #ifdef PNG_WRITE_SUPPORTED
516 PNG_INTERNAL_FUNCTION(void,png_free_buffer_list,(png_structrp png_ptr,
517    png_compression_bufferp *list),PNG_EMPTY);
518 #endif
519 
520 #if defined(PNG_FLOATING_POINT_SUPPORTED) && \
521    !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && \
522    (defined(PNG_gAMA_SUPPORTED) || defined(PNG_cHRM_SUPPORTED) || \
523    defined(PNG_sCAL_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) || \
524    defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)) || \
525    (defined(PNG_sCAL_SUPPORTED) && \
526    defined(PNG_FLOATING_ARITHMETIC_SUPPORTED))
527 PNG_INTERNAL_FUNCTION(png_fixed_point,png_fixed,(png_const_structrp png_ptr,
528    double fp, png_const_charp text),PNG_EMPTY);
529 #endif
530 PNG_INTERNAL_FUNCTION(int,png_user_version_check,(png_structrp png_ptr,
531    png_const_charp user_png_ver),PNG_EMPTY);
532 PNG_INTERNAL_FUNCTION(png_voidp,png_malloc_base,(png_const_structrp png_ptr,
533    png_alloc_size_t size),PNG_ALLOCATED);
534 
535 #if defined(PNG_TEXT_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) ||\
536    defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED)
537 PNG_INTERNAL_FUNCTION(png_voidp,png_malloc_array,(png_const_structrp png_ptr,
538    int nelements, size_t element_size),PNG_ALLOCATED);
539 PNG_INTERNAL_FUNCTION(png_voidp,png_realloc_array,(png_const_structrp png_ptr,
540    png_const_voidp array, int old_elements, int add_elements,
541    size_t element_size),PNG_ALLOCATED);
542 #endif
543 PNG_INTERNAL_FUNCTION(png_structp,png_create_png_struct,
544    (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,
545     png_error_ptr warn_fn, png_voidp mem_ptr, png_malloc_ptr malloc_fn,
546     png_free_ptr free_fn),PNG_ALLOCATED);
547 PNG_INTERNAL_FUNCTION(void,png_destroy_png_struct,(png_structrp png_ptr),
548    PNG_EMPTY);
549 PNG_INTERNAL_FUNCTION(void,png_free_jmpbuf,(png_structrp png_ptr),PNG_EMPTY);
550 PNG_INTERNAL_FUNCTION(voidpf,png_zalloc,(voidpf png_ptr, uInt items, uInt size),
551    PNG_ALLOCATED);
552 PNG_INTERNAL_FUNCTION(void,png_zfree,(voidpf png_ptr, voidpf ptr),PNG_EMPTY);
553 
554 PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_read_data,(png_structp png_ptr,
555     png_bytep data, size_t length),PNG_EMPTY);
556 
557 #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
558 PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_push_fill_buffer,(png_structp png_ptr,
559     png_bytep buffer, size_t length),PNG_EMPTY);
560 #endif
561 
562 PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_write_data,(png_structp png_ptr,
563     png_bytep data, size_t length),PNG_EMPTY);
564 
565 #ifdef PNG_WRITE_FLUSH_SUPPORTED
566 #  ifdef PNG_STDIO_SUPPORTED
567 PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_flush,(png_structp png_ptr),
568    PNG_EMPTY);
569 #  endif
570 #endif
571 PNG_INTERNAL_FUNCTION(void,png_reset_crc,(png_structrp png_ptr),PNG_EMPTY);
572 PNG_INTERNAL_FUNCTION(void,png_write_data,(png_structrp png_ptr,
573     png_const_bytep data, size_t length),PNG_EMPTY);
574 PNG_INTERNAL_FUNCTION(void,png_read_sig,(png_structrp png_ptr,
575    png_inforp info_ptr),PNG_EMPTY);
576 PNG_INTERNAL_FUNCTION(png_uint_32,png_read_chunk_header,(png_structrp png_ptr),
577    PNG_EMPTY);
578 PNG_INTERNAL_FUNCTION(void,png_read_data,(png_structrp png_ptr, png_bytep data,
579     size_t length),PNG_EMPTY);
580 PNG_INTERNAL_FUNCTION(void,png_crc_read,(png_structrp png_ptr, png_bytep buf,
581     png_uint_32 length),PNG_EMPTY);
582 PNG_INTERNAL_FUNCTION(int,png_crc_finish,(png_structrp png_ptr,
583    png_uint_32 skip),PNG_EMPTY);
584 PNG_INTERNAL_FUNCTION(int,png_crc_error,(png_structrp png_ptr),PNG_EMPTY);
585 PNG_INTERNAL_FUNCTION(void,png_calculate_crc,(png_structrp png_ptr,
586    png_const_bytep ptr, size_t length),PNG_EMPTY);
587 
588 #ifdef PNG_WRITE_FLUSH_SUPPORTED
589 PNG_INTERNAL_FUNCTION(void,png_flush,(png_structrp png_ptr),PNG_EMPTY);
590 #endif
591 PNG_INTERNAL_FUNCTION(void,png_write_IHDR,(png_structrp png_ptr,
592    png_uint_32 width, png_uint_32 height, int bit_depth, int color_type,
593    int compression_method, int filter_method, int interlace_method),PNG_EMPTY);
594 
595 PNG_INTERNAL_FUNCTION(void,png_write_PLTE,(png_structrp png_ptr,
596    png_const_colorp palette, png_uint_32 num_pal),PNG_EMPTY);
597 
598 PNG_INTERNAL_FUNCTION(void,png_compress_IDAT,(png_structrp png_ptr,
599    png_const_bytep row_data, png_alloc_size_t row_data_length, int flush),
600    PNG_EMPTY);
601 
602 PNG_INTERNAL_FUNCTION(void,png_write_IEND,(png_structrp png_ptr),PNG_EMPTY);
603 PNG_INTERNAL_FUNCTION(void,png_write_finish_row,(png_structrp png_ptr),
604     PNG_EMPTY);
605 PNG_INTERNAL_FUNCTION(void,png_write_start_row,(png_structrp png_ptr),
606     PNG_EMPTY);
607 
608 #ifndef PNG_USE_COMPILE_TIME_MASKS
609 #  define PNG_USE_COMPILE_TIME_MASKS 1
610 #endif
611 PNG_INTERNAL_FUNCTION(void,png_combine_row,(png_const_structrp png_ptr,
612     png_bytep row, int display),PNG_EMPTY);
613 PNG_INTERNAL_FUNCTION(void,png_read_filter_row,(png_structrp pp, png_row_infop
614     row_info, png_bytep row, png_const_bytep prev_row, int filter),PNG_EMPTY);
615 
616 #if PNG_ARM_NEON_OPT > 0
617 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_neon,(png_row_infop row_info,
618     png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
619 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_neon,(png_row_infop
620     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
621 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_neon,(png_row_infop
622     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
623 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_neon,(png_row_infop
624     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
625 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_neon,(png_row_infop
626     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
627 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_neon,(png_row_infop
628     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
629 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_neon,(png_row_infop
630     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
631 #endif
632 
633 #if PNG_MIPS_MSA_OPT > 0
634 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_msa,(png_row_infop row_info,
635     png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
636 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_msa,(png_row_infop
637     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
638 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_msa,(png_row_infop
639     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
640 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_msa,(png_row_infop
641     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
642 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_msa,(png_row_infop
643     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
644 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_msa,(png_row_infop
645     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
646 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_msa,(png_row_infop
647     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
648 #endif
649 
650 #if PNG_POWERPC_VSX_OPT > 0
651 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_vsx,(png_row_infop row_info,
652     png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
653 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_vsx,(png_row_infop
654     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
655 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_vsx,(png_row_infop
656     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
657 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_vsx,(png_row_infop
658     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
659 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_vsx,(png_row_infop
660     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
661 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_vsx,(png_row_infop
662     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
663 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_vsx,(png_row_infop
664     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
665 #endif
666 
667 #if PNG_INTEL_SSE_IMPLEMENTATION > 0
668 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_sse2,(png_row_infop
669     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
670 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_sse2,(png_row_infop
671     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
672 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_sse2,(png_row_infop
673     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
674 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_sse2,(png_row_infop
675     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
676 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_sse2,(png_row_infop
677     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
678 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_sse2,(png_row_infop
679     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
680 #endif
681 PNG_INTERNAL_FUNCTION(void,png_write_find_filter,(png_structrp png_ptr,
682     png_row_infop row_info),PNG_EMPTY);
683 PNG_INTERNAL_FUNCTION(void,png_read_start_row,(png_structrp png_ptr),PNG_EMPTY);
684 
685 #if ZLIB_VERNUM >= 0x1240
686 PNG_INTERNAL_FUNCTION(int,png_zlib_inflate,(png_structrp png_ptr, int flush),
687       PNG_EMPTY);
688 #  define PNG_INFLATE(pp, flush) png_zlib_inflate(pp, flush)
689 #else
690 #  define PNG_INFLATE(pp, flush) inflate(&(pp)->zstream, flush)
691 #endif
692 PNG_INTERNAL_FUNCTION(void,png_handle_IHDR,(png_structrp png_ptr,
693     png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
694 PNG_INTERNAL_FUNCTION(void,png_handle_PLTE,(png_structrp png_ptr,
695     png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
696 PNG_INTERNAL_FUNCTION(void,png_handle_IEND,(png_structrp png_ptr,
697     png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
698 
699 PNG_INTERNAL_FUNCTION(void,png_check_chunk_name,(png_const_structrp png_ptr,
700     png_uint_32 chunk_name),PNG_EMPTY);
701 
702 PNG_INTERNAL_FUNCTION(void,png_check_chunk_length,(png_const_structrp png_ptr,
703     png_uint_32 chunk_length),PNG_EMPTY);
704 
705 PNG_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr,
706     png_inforp info_ptr, png_uint_32 length, int keep),PNG_EMPTY);
707 PNG_INTERNAL_FUNCTION(void,png_check_IHDR,(png_const_structrp png_ptr,
708     png_uint_32 width, png_uint_32 height, int bit_depth,
709     int color_type, int interlace_type, int compression_type,
710     int filter_type),PNG_EMPTY);
711 PNG_INTERNAL_FUNCTION(size_t,png_safecat,(png_charp buffer, size_t bufsize,
712    size_t pos, png_const_charp string),PNG_EMPTY);
713 
714 #  define png_app_warning(pp,s) png_warning(pp,s)
715 #  define png_app_error(pp,s) png_error(pp,s)
716 
717 PNG_INTERNAL_FUNCTION(void,png_chunk_report,(png_const_structrp png_ptr,
718    png_const_charp message, int error),PNG_EMPTY);
719 #define PNG_CHUNK_WARNING     0
720 #define PNG_CHUNK_WRITE_ERROR 1
721 #define PNG_CHUNK_ERROR       2
722 #  if PNG_ARM_NEON_OPT > 0
723 PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_neon,
724    (png_structp png_ptr, unsigned int bpp), PNG_EMPTY);
725 #endif
726 
727 #if PNG_MIPS_MSA_OPT > 0
728 PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_msa,
729    (png_structp png_ptr, unsigned int bpp), PNG_EMPTY);
730 #endif
731 
732 #  if PNG_INTEL_SSE_IMPLEMENTATION > 0
733 PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_sse2,
734    (png_structp png_ptr, unsigned int bpp), PNG_EMPTY);
735 #  endif
736 
737 PNG_INTERNAL_FUNCTION(png_uint_32, png_check_keyword, (png_structrp png_ptr,
738    png_const_charp key, png_bytep new_key), PNG_EMPTY);
739 
740 #if PNG_ARM_NEON_IMPLEMENTATION == 1
741 PNG_INTERNAL_FUNCTION(void,
742                       png_riffle_palette_neon,
743                       (png_structrp),
744                       PNG_EMPTY);
745 PNG_INTERNAL_FUNCTION(int,
746                       png_do_expand_palette_rgba8_neon,
747                       (png_structrp,
748                        png_row_infop,
749                        png_const_bytep,
750                        const png_bytepp,
751                        const png_bytepp),
752                       PNG_EMPTY);
753 PNG_INTERNAL_FUNCTION(int,
754                       png_do_expand_palette_rgb8_neon,
755                       (png_structrp,
756                        png_row_infop,
757                        png_const_bytep,
758                        const png_bytepp,
759                        const png_bytepp),
760                       PNG_EMPTY);
761 #endif
762 
763 #include "pngdebug.h"
764 
765 #ifdef __cplusplus
766 }
767 #endif
768 
769 #endif
770 #endif
771