]>
Commit | Line | Data |
---|---|---|
1 | /* pngpriv.h - private declarations for use inside libpng | |
2 | * | |
3 | * For conditions of distribution and use, see copyright notice in png.h | |
4 | * Copyright (c) 1998-2011 Glenn Randers-Pehrson | |
5 | * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | |
6 | * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | |
7 | * | |
8 | * Last changed in libpng 1.5.6 [November 3, 2011] | |
9 | * | |
10 | * This code is released under the libpng license. | |
11 | * For conditions of distribution and use, see the disclaimer | |
12 | * and license in png.h | |
13 | */ | |
14 | ||
15 | /* The symbols declared in this file (including the functions declared | |
16 | * as PNG_EXTERN) are PRIVATE. They are not part of the libpng public | |
17 | * interface, and are not recommended for use by regular applications. | |
18 | * Some of them may become public in the future; others may stay private, | |
19 | * change in an incompatible way, or even disappear. | |
20 | * Although the libpng users are not forbidden to include this header, | |
21 | * they should be well aware of the issues that may arise from doing so. | |
22 | */ | |
23 | ||
24 | #ifndef PNGPRIV_H | |
25 | #define PNGPRIV_H | |
26 | ||
27 | /* Feature Test Macros. The following are defined here to ensure that correctly | |
28 | * implemented libraries reveal the APIs libpng needs to build and hide those | |
29 | * that are not needed and potentially damaging to the compilation. | |
30 | * | |
31 | * Feature Test Macros must be defined before any system header is included (see | |
32 | * POSIX 1003.1 2.8.2 "POSIX Symbols." | |
33 | * | |
34 | * These macros only have an effect if the operating system supports either | |
35 | * POSIX 1003.1 or C99, or both. On other operating systems (particularly | |
36 | * Windows/Visual Studio) there is no effect; the OS specific tests below are | |
37 | * still required (as of 2011-05-02.) | |
38 | */ | |
39 | #define _POSIX_SOURCE 1 /* Just the POSIX 1003.1 and C89 APIs */ | |
40 | ||
41 | /* This is required for the definition of abort(), used as a last ditch | |
42 | * error handler when all else fails. | |
43 | */ | |
44 | #include <stdlib.h> | |
45 | ||
46 | /* This is used to find 'offsetof', used below for alignment tests. */ | |
47 | #include <stddef.h> | |
48 | ||
49 | #define PNGLIB_BUILD /*libpng is being built, not used*/ | |
50 | ||
51 | #ifdef PNG_USER_CONFIG | |
52 | # include "pngusr.h" | |
53 | /* These should have been defined in pngusr.h */ | |
54 | # ifndef PNG_USER_PRIVATEBUILD | |
55 | # define PNG_USER_PRIVATEBUILD "Custom libpng build" | |
56 | # endif | |
57 | # ifndef PNG_USER_DLLFNAME_POSTFIX | |
58 | # define PNG_USER_DLLFNAME_POSTFIX "Cb" | |
59 | # endif | |
60 | #endif | |
61 | ||
62 | /* Is this a build of a DLL where compilation of the object modules requires | |
63 | * different preprocessor settings to those required for a simple library? If | |
64 | * so PNG_BUILD_DLL must be set. | |
65 | * | |
66 | * If libpng is used inside a DLL but that DLL does not export the libpng APIs | |
67 | * PNG_BUILD_DLL must not be set. To avoid the code below kicking in build a | |
68 | * static library of libpng then link the DLL against that. | |
69 | */ | |
70 | #ifndef PNG_BUILD_DLL | |
71 | # ifdef DLL_EXPORT | |
72 | /* This is set by libtool when files are compiled for a DLL; libtool | |
73 | * always compiles twice, even on systems where it isn't necessary. Set | |
74 | * PNG_BUILD_DLL in case it is necessary: | |
75 | */ | |
76 | # define PNG_BUILD_DLL | |
77 | # else | |
78 | # ifdef _WINDLL | |
79 | /* This is set by the Microsoft Visual Studio IDE in projects that | |
80 | * build a DLL. It can't easily be removed from those projects (it | |
81 | * isn't visible in the Visual Studio UI) so it is a fairly reliable | |
82 | * indication that PNG_IMPEXP needs to be set to the DLL export | |
83 | * attributes. | |
84 | */ | |
85 | # define PNG_BUILD_DLL | |
86 | # else | |
87 | # ifdef __DLL__ | |
88 | /* This is set by the Borland C system when compiling for a DLL | |
89 | * (as above.) | |
90 | */ | |
91 | # define PNG_BUILD_DLL | |
92 | # else | |
93 | /* Add additional compiler cases here. */ | |
94 | # endif | |
95 | # endif | |
96 | # endif | |
97 | #endif /* Setting PNG_BUILD_DLL if required */ | |
98 | ||
99 | /* See pngconf.h for more details: the builder of the library may set this on | |
100 | * the command line to the right thing for the specific compilation system or it | |
101 | * may be automagically set above (at present we know of no system where it does | |
102 | * need to be set on the command line.) | |
103 | * | |
104 | * PNG_IMPEXP must be set here when building the library to prevent pngconf.h | |
105 | * setting it to the "import" setting for a DLL build. | |
106 | */ | |
107 | #ifndef PNG_IMPEXP | |
108 | # ifdef PNG_BUILD_DLL | |
109 | # define PNG_IMPEXP PNG_DLL_EXPORT | |
110 | # else | |
111 | /* Not building a DLL, or the DLL doesn't require specific export | |
112 | * definitions. | |
113 | */ | |
114 | # define PNG_IMPEXP | |
115 | # endif | |
116 | #endif | |
117 | ||
118 | /* No warnings for private or deprecated functions in the build: */ | |
119 | #ifndef PNG_DEPRECATED | |
120 | # define PNG_DEPRECATED | |
121 | #endif | |
122 | #ifndef PNG_PRIVATE | |
123 | # define PNG_PRIVATE | |
124 | #endif | |
125 | ||
126 | #include "png.h" | |
127 | #include "pnginfo.h" | |
128 | #include "pngstruct.h" | |
129 | ||
130 | /* pngconf.h does not set PNG_DLL_EXPORT unless it is required, so: */ | |
131 | #ifndef PNG_DLL_EXPORT | |
132 | # define PNG_DLL_EXPORT | |
133 | #endif | |
134 | ||
135 | /* This is used for 16 bit gamma tables - only the top level pointers are const, | |
136 | * this could be changed: | |
137 | */ | |
138 | typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; | |
139 | ||
140 | /* Added at libpng-1.2.9 */ | |
141 | /* Moved to pngpriv.h at libpng-1.5.0 */ | |
142 | ||
143 | /* config.h is created by and PNG_CONFIGURE_LIBPNG is set by the "configure" | |
144 | * script. We may need it here to get the correct configuration on things | |
145 | * like limits. | |
146 | */ | |
147 | #ifdef PNG_CONFIGURE_LIBPNG | |
148 | # ifdef HAVE_CONFIG_H | |
149 | # include "config.h" | |
150 | # endif | |
151 | #endif | |
152 | ||
153 | /* Moved to pngpriv.h at libpng-1.5.0 */ | |
154 | /* NOTE: some of these may have been used in external applications as | |
155 | * these definitions were exposed in pngconf.h prior to 1.5. | |
156 | */ | |
157 | ||
158 | /* If you are running on a machine where you cannot allocate more | |
159 | * than 64K of memory at once, uncomment this. While libpng will not | |
160 | * normally need that much memory in a chunk (unless you load up a very | |
161 | * large file), zlib needs to know how big of a chunk it can use, and | |
162 | * libpng thus makes sure to check any memory allocation to verify it | |
163 | * will fit into memory. | |
164 | * | |
165 | * zlib provides 'MAXSEG_64K' which, if defined, indicates the | |
166 | * same limit and pngconf.h (already included) sets the limit | |
167 | * if certain operating systems are detected. | |
168 | */ | |
169 | #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) | |
170 | # define PNG_MAX_MALLOC_64K | |
171 | #endif | |
172 | ||
173 | #ifndef PNG_UNUSED | |
174 | /* Unused formal parameter warnings are silenced using the following macro | |
175 | * which is expected to have no bad effects on performance (optimizing | |
176 | * compilers will probably remove it entirely). Note that if you replace | |
177 | * it with something other than whitespace, you must include the terminating | |
178 | * semicolon. | |
179 | */ | |
180 | # define PNG_UNUSED(param) (void)param; | |
181 | #endif | |
182 | ||
183 | /* Just a little check that someone hasn't tried to define something | |
184 | * contradictory. | |
185 | */ | |
186 | #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K) | |
187 | # undef PNG_ZBUF_SIZE | |
188 | # define PNG_ZBUF_SIZE 65536L | |
189 | #endif | |
190 | ||
191 | /* PNG_STATIC is used to mark internal file scope functions if they need to be | |
192 | * accessed for implementation tests (see the code in tests/?*). | |
193 | */ | |
194 | #ifndef PNG_STATIC | |
195 | # define PNG_STATIC static | |
196 | #endif | |
197 | ||
198 | /* If warnings or errors are turned off the code is disabled or redirected here. | |
199 | * From 1.5.4 functions have been added to allow very limited formatting of | |
200 | * error and warning messages - this code will also be disabled here. | |
201 | */ | |
202 | #ifdef PNG_WARNINGS_SUPPORTED | |
203 | # define PNG_WARNING_PARAMETERS(p) png_warning_parameters p; | |
204 | #else | |
205 | # define png_warning(s1,s2) ((void)(s1)) | |
206 | # define png_chunk_warning(s1,s2) ((void)(s1)) | |
207 | # define png_warning_parameter(p,number,string) ((void)0) | |
208 | # define png_warning_parameter_unsigned(p,number,format,value) ((void)0) | |
209 | # define png_warning_parameter_signed(p,number,format,value) ((void)0) | |
210 | # define png_formatted_warning(pp,p,message) ((void)(pp)) | |
211 | # define PNG_WARNING_PARAMETERS(p) | |
212 | #endif | |
213 | #ifndef PNG_ERROR_TEXT_SUPPORTED | |
214 | # define png_error(s1,s2) png_err(s1) | |
215 | # define png_chunk_error(s1,s2) png_err(s1) | |
216 | # define png_fixed_error(s1,s2) png_err(s1) | |
217 | #endif | |
218 | ||
219 | #ifndef PNG_EXTERN | |
220 | /* The functions exported by PNG_EXTERN are internal functions, which | |
221 | * aren't usually used outside the library (as far as I know), so it is | |
222 | * debatable if they should be exported at all. In the future, when it | |
223 | * is possible to have run-time registry of chunk-handling functions, | |
224 | * some of these might be made available again. | |
225 | # define PNG_EXTERN extern | |
226 | */ | |
227 | # define PNG_EXTERN | |
228 | #endif | |
229 | ||
230 | /* Some fixed point APIs are still required even if not exported because | |
231 | * they get used by the corresponding floating point APIs. This magic | |
232 | * deals with this: | |
233 | */ | |
234 | #ifdef PNG_FIXED_POINT_SUPPORTED | |
235 | # define PNGFAPI PNGAPI | |
236 | #else | |
237 | # define PNGFAPI /* PRIVATE */ | |
238 | #endif | |
239 | ||
240 | /* Other defines specific to compilers can go here. Try to keep | |
241 | * them inside an appropriate ifdef/endif pair for portability. | |
242 | */ | |
243 | #if defined(PNG_FLOATING_POINT_SUPPORTED) ||\ | |
244 | defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) | |
245 | /* png.c requires the following ANSI-C constants if the conversion of | |
246 | * floating point to ASCII is implemented therein: | |
247 | * | |
248 | * DBL_DIG Maximum number of decimal digits (can be set to any constant) | |
249 | * DBL_MIN Smallest normalized fp number (can be set to an arbitrary value) | |
250 | * DBL_MAX Maximum floating point number (can be set to an arbitrary value) | |
251 | */ | |
252 | # include <float.h> | |
253 | ||
254 | # if ( ( (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \ | |
255 | defined(THINK_C) || defined(TARGET_OS_MAC) ) && !wxOSX_USE_IPHONE ) || defined(__SC__) | |
256 | /* We need to check that <math.h> hasn't already been included earlier | |
257 | * as it seems it doesn't agree with <fp.h>, yet we should really use | |
258 | * <fp.h> if possible. | |
259 | */ | |
260 | # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__) | |
261 | # include <fp.h> | |
262 | # endif | |
263 | # else | |
264 | # include <math.h> | |
265 | # endif | |
266 | # if defined(_AMIGA) && defined(__SASC) && defined(_M68881) | |
267 | /* Amiga SAS/C: We must include builtin FPU functions when compiling using | |
268 | * MATH=68881 | |
269 | */ | |
270 | # include <m68881.h> | |
271 | # endif | |
272 | #endif | |
273 | ||
274 | /* This provides the non-ANSI (far) memory allocation routines. */ | |
275 | #if defined(__TURBOC__) && defined(__MSDOS__) | |
276 | # include <mem.h> | |
277 | # include <alloc.h> | |
278 | #endif | |
279 | ||
280 | #if defined(WIN32) || defined(_Windows) || defined(_WINDOWS) || \ | |
281 | defined(_WIN32) || defined(__WIN32__) | |
282 | # include <windows.h> /* defines _WINDOWS_ macro */ | |
283 | #endif | |
284 | ||
285 | /* Moved here around 1.5.0beta36 from pngconf.h */ | |
286 | /* Users may want to use these so they are not private. Any library | |
287 | * functions that are passed far data must be model-independent. | |
288 | */ | |
289 | ||
290 | /* Memory model/platform independent fns */ | |
291 | #ifndef PNG_ABORT | |
292 | # ifdef _WINDOWS_ | |
293 | # define PNG_ABORT() ExitProcess(0) | |
294 | # else | |
295 | # define PNG_ABORT() abort() | |
296 | # endif | |
297 | #endif | |
298 | ||
299 | #ifdef USE_FAR_KEYWORD | |
300 | /* Use this to make far-to-near assignments */ | |
301 | # define CHECK 1 | |
302 | # define NOCHECK 0 | |
303 | # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK)) | |
304 | # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK)) | |
305 | # define png_strlen _fstrlen | |
306 | # define png_memcmp _fmemcmp /* SJT: added */ | |
307 | # define png_memcpy _fmemcpy | |
308 | # define png_memset _fmemset | |
309 | #else | |
310 | # ifdef _WINDOWS_ /* Favor Windows over C runtime fns */ | |
311 | # define CVT_PTR(ptr) (ptr) | |
312 | # define CVT_PTR_NOCHECK(ptr) (ptr) | |
313 | # define png_strlen lstrlenA | |
314 | # define png_memcmp memcmp | |
315 | # define png_memcpy CopyMemory | |
316 | # define png_memset memset | |
317 | # else | |
318 | # define CVT_PTR(ptr) (ptr) | |
319 | # define CVT_PTR_NOCHECK(ptr) (ptr) | |
320 | # define png_strlen strlen | |
321 | # define png_memcmp memcmp /* SJT: added */ | |
322 | # define png_memcpy memcpy | |
323 | # define png_memset memset | |
324 | # endif | |
325 | #endif | |
326 | ||
327 | /* These macros may need to be architecture dependent. */ | |
328 | #define PNG_ALIGN_NONE 0 /* do not use data alignment */ | |
329 | #define PNG_ALIGN_ALWAYS 1 /* assume unaligned accesses are OK */ | |
330 | #ifdef offsetof | |
331 | # define PNG_ALIGN_OFFSET 2 /* use offsetof to determine alignment */ | |
332 | #else | |
333 | # define PNG_ALIGN_OFFSET -1 /* prevent the use of this */ | |
334 | #endif | |
335 | #define PNG_ALIGN_SIZE 3 /* use sizeof to determine alignment */ | |
336 | ||
337 | #ifndef PNG_ALIGN_TYPE | |
338 | /* Default to using aligned access optimizations and requiring alignment to a | |
339 | * multiple of the data type size. Override in a compiler specific fashion | |
340 | * if necessary by inserting tests here: | |
341 | */ | |
342 | # define PNG_ALIGN_TYPE PNG_ALIGN_SIZE | |
343 | #endif | |
344 | ||
345 | #if PNG_ALIGN_TYPE == PNG_ALIGN_SIZE | |
346 | /* This is used because in some compiler implementations non-aligned | |
347 | * structure members are supported, so the offsetof approach below fails. | |
348 | * Set PNG_ALIGN_TO_SIZE=0 for compiler combinations where unaligned access | |
349 | * is good for performance. Do not do this unless you have tested the result | |
350 | * and understand it. | |
351 | */ | |
352 | # define png_alignof(type) (sizeof (type)) | |
353 | #else | |
354 | # if PNG_ALIGN_TYPE == PNG_ALIGN_OFFSET | |
355 | # define png_alignof(type) offsetof(struct{char c; type t;}, t) | |
356 | # else | |
357 | # if PNG_ALIGN_TYPE == PNG_ALIGN_ALWAYS | |
358 | # define png_alignof(type) (1) | |
359 | # endif | |
360 | /* Else leave png_alignof undefined to prevent use thereof */ | |
361 | # endif | |
362 | #endif | |
363 | ||
364 | /* This implicitly assumes alignment is always to a power of 2. */ | |
365 | #ifdef png_alignof | |
366 | # define png_isaligned(ptr, type)\ | |
367 | ((((const char*)ptr-(const char*)0) & (png_alignof(type)-1)) == 0) | |
368 | #else | |
369 | # define png_isaligned(ptr, type) 0 | |
370 | #endif | |
371 | ||
372 | /* End of memory model/platform independent support */ | |
373 | /* End of 1.5.0beta36 move from pngconf.h */ | |
374 | ||
375 | /* CONSTANTS and UTILITY MACROS | |
376 | * These are used internally by libpng and not exposed in the API | |
377 | */ | |
378 | ||
379 | /* Various modes of operation. Note that after an init, mode is set to | |
380 | * zero automatically when the structure is created. Three of these | |
381 | * are defined in png.h because they need to be visible to applications | |
382 | * that call png_set_unknown_chunk(). | |
383 | */ | |
384 | /* #define PNG_HAVE_IHDR 0x01 (defined in png.h) */ | |
385 | /* #define PNG_HAVE_PLTE 0x02 (defined in png.h) */ | |
386 | #define PNG_HAVE_IDAT 0x04 | |
387 | /* #define PNG_AFTER_IDAT 0x08 (defined in png.h) */ | |
388 | #define PNG_HAVE_IEND 0x10 | |
389 | #define PNG_HAVE_gAMA 0x20 | |
390 | #define PNG_HAVE_cHRM 0x40 | |
391 | #define PNG_HAVE_sRGB 0x80 | |
392 | #define PNG_HAVE_CHUNK_HEADER 0x100 | |
393 | #define PNG_WROTE_tIME 0x200 | |
394 | #define PNG_WROTE_INFO_BEFORE_PLTE 0x400 | |
395 | #define PNG_BACKGROUND_IS_GRAY 0x800 | |
396 | #define PNG_HAVE_PNG_SIGNATURE 0x1000 | |
397 | #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */ | |
398 | ||
399 | /* Flags for the transformations the PNG library does on the image data */ | |
400 | #define PNG_BGR 0x0001 | |
401 | #define PNG_INTERLACE 0x0002 | |
402 | #define PNG_PACK 0x0004 | |
403 | #define PNG_SHIFT 0x0008 | |
404 | #define PNG_SWAP_BYTES 0x0010 | |
405 | #define PNG_INVERT_MONO 0x0020 | |
406 | #define PNG_QUANTIZE 0x0040 | |
407 | #define PNG_COMPOSE 0x0080 /* Was PNG_BACKGROUND */ | |
408 | #define PNG_BACKGROUND_EXPAND 0x0100 | |
409 | #define PNG_EXPAND_16 0x0200 /* Added to libpng 1.5.2 */ | |
410 | #define PNG_16_TO_8 0x0400 /* Becomes 'chop' in 1.5.4 */ | |
411 | #define PNG_RGBA 0x0800 | |
412 | #define PNG_EXPAND 0x1000 | |
413 | #define PNG_GAMMA 0x2000 | |
414 | #define PNG_GRAY_TO_RGB 0x4000 | |
415 | #define PNG_FILLER 0x8000 | |
416 | #define PNG_PACKSWAP 0x10000 | |
417 | #define PNG_SWAP_ALPHA 0x20000 | |
418 | #define PNG_STRIP_ALPHA 0x40000 | |
419 | #define PNG_INVERT_ALPHA 0x80000 | |
420 | #define PNG_USER_TRANSFORM 0x100000 | |
421 | #define PNG_RGB_TO_GRAY_ERR 0x200000 | |
422 | #define PNG_RGB_TO_GRAY_WARN 0x400000 | |
423 | #define PNG_RGB_TO_GRAY 0x600000 /* two bits, RGB_TO_GRAY_ERR|WARN */ | |
424 | #define PNG_ENCODE_ALPHA 0x800000 /* Added to libpng-1.5.4 */ | |
425 | #define PNG_ADD_ALPHA 0x1000000 /* Added to libpng-1.2.7 */ | |
426 | #define PNG_EXPAND_tRNS 0x2000000 /* Added to libpng-1.2.9 */ | |
427 | #define PNG_SCALE_16_TO_8 0x4000000 /* Added to libpng-1.5.4 */ | |
428 | /* 0x8000000 unused */ | |
429 | /* 0x10000000 unused */ | |
430 | /* 0x20000000 unused */ | |
431 | /* 0x40000000 unused */ | |
432 | /* Flags for png_create_struct */ | |
433 | #define PNG_STRUCT_PNG 0x0001 | |
434 | #define PNG_STRUCT_INFO 0x0002 | |
435 | ||
436 | /* Scaling factor for filter heuristic weighting calculations */ | |
437 | #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT)) | |
438 | #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT)) | |
439 | ||
440 | /* Flags for the png_ptr->flags rather than declaring a byte for each one */ | |
441 | #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001 | |
442 | #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002 | |
443 | #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004 | |
444 | #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008 | |
445 | #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010 | |
446 | #define PNG_FLAG_ZLIB_FINISHED 0x0020 | |
447 | #define PNG_FLAG_ROW_INIT 0x0040 | |
448 | #define PNG_FLAG_FILLER_AFTER 0x0080 | |
449 | #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100 | |
450 | #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200 | |
451 | #define PNG_FLAG_CRC_CRITICAL_USE 0x0400 | |
452 | #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800 | |
453 | #define PNG_FLAG_ASSUME_sRGB 0x1000 /* Added to libpng-1.5.4 */ | |
454 | #define PNG_FLAG_OPTIMIZE_ALPHA 0x2000 /* Added to libpng-1.5.4 */ | |
455 | #define PNG_FLAG_DETECT_UNINITIALIZED 0x4000 /* Added to libpng-1.5.4 */ | |
456 | #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000 | |
457 | #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000 | |
458 | #define PNG_FLAG_LIBRARY_MISMATCH 0x20000 | |
459 | #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000 | |
460 | #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000 | |
461 | #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000 | |
462 | /* 0x200000 unused */ | |
463 | /* 0x400000 unused */ | |
464 | #define PNG_FLAG_BENIGN_ERRORS_WARN 0x800000 /* Added to libpng-1.4.0 */ | |
465 | #define PNG_FLAG_ZTXT_CUSTOM_STRATEGY 0x1000000 /* 5 lines added */ | |
466 | #define PNG_FLAG_ZTXT_CUSTOM_LEVEL 0x2000000 /* to libpng-1.5.4 */ | |
467 | #define PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL 0x4000000 | |
468 | #define PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS 0x8000000 | |
469 | #define PNG_FLAG_ZTXT_CUSTOM_METHOD 0x10000000 | |
470 | /* 0x20000000 unused */ | |
471 | /* 0x40000000 unused */ | |
472 | ||
473 | #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \ | |
474 | PNG_FLAG_CRC_ANCILLARY_NOWARN) | |
475 | ||
476 | #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \ | |
477 | PNG_FLAG_CRC_CRITICAL_IGNORE) | |
478 | ||
479 | #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \ | |
480 | PNG_FLAG_CRC_CRITICAL_MASK) | |
481 | ||
482 | /* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib | |
483 | * can handle at once. This type need be no larger than 16 bits (so maximum of | |
484 | * 65535), this define allows us to discover how big it is, but limited by the | |
485 | * maximuum for png_size_t. The value can be overriden in a library build | |
486 | * (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably | |
487 | * lower value (e.g. 255 works). A lower value may help memory usage (slightly) | |
488 | * and may even improve performance on some systems (and degrade it on others.) | |
489 | */ | |
490 | #ifndef ZLIB_IO_MAX | |
491 | # define ZLIB_IO_MAX ((uInt)-1) | |
492 | #endif | |
493 | ||
494 | /* Save typing and make code easier to understand */ | |
495 | ||
496 | #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \ | |
497 | abs((int)((c1).green) - (int)((c2).green)) + \ | |
498 | abs((int)((c1).blue) - (int)((c2).blue))) | |
499 | ||
500 | /* Added to libpng-1.2.6 JB */ | |
501 | #define PNG_ROWBYTES(pixel_bits, width) \ | |
502 | ((pixel_bits) >= 8 ? \ | |
503 | ((png_size_t)(width) * (((png_size_t)(pixel_bits)) >> 3)) : \ | |
504 | (( ((png_size_t)(width) * ((png_size_t)(pixel_bits))) + 7) >> 3) ) | |
505 | ||
506 | /* PNG_OUT_OF_RANGE returns true if value is outside the range | |
507 | * ideal-delta..ideal+delta. Each argument is evaluated twice. | |
508 | * "ideal" and "delta" should be constants, normally simple | |
509 | * integers, "value" a variable. Added to libpng-1.2.6 JB | |
510 | */ | |
511 | #define PNG_OUT_OF_RANGE(value, ideal, delta) \ | |
512 | ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) ) | |
513 | ||
514 | /* Conversions between fixed and floating point, only defined if | |
515 | * required (to make sure the code doesn't accidentally use float | |
516 | * when it is supposedly disabled.) | |
517 | */ | |
518 | #ifdef PNG_FLOATING_POINT_SUPPORTED | |
519 | /* The floating point conversion can't overflow, though it can and | |
520 | * does lose accuracy relative to the original fixed point value. | |
521 | * In practice this doesn't matter because png_fixed_point only | |
522 | * stores numbers with very low precision. The png_ptr and s | |
523 | * arguments are unused by default but are there in case error | |
524 | * checking becomes a requirement. | |
525 | */ | |
526 | #define png_float(png_ptr, fixed, s) (.00001 * (fixed)) | |
527 | ||
528 | /* The fixed point conversion performs range checking and evaluates | |
529 | * its argument multiple times, so must be used with care. The | |
530 | * range checking uses the PNG specification values for a signed | |
531 | * 32 bit fixed point value except that the values are deliberately | |
532 | * rounded-to-zero to an integral value - 21474 (21474.83 is roughly | |
533 | * (2^31-1) * 100000). 's' is a string that describes the value being | |
534 | * converted. | |
535 | * | |
536 | * NOTE: this macro will raise a png_error if the range check fails, | |
537 | * therefore it is normally only appropriate to use this on values | |
538 | * that come from API calls or other sources where an out of range | |
539 | * error indicates a programming error, not a data error! | |
540 | * | |
541 | * NOTE: by default this is off - the macro is not used - because the | |
542 | * function call saves a lot of code. | |
543 | */ | |
544 | #ifdef PNG_FIXED_POINT_MACRO_SUPPORTED | |
545 | #define png_fixed(png_ptr, fp, s) ((fp) <= 21474 && (fp) >= -21474 ?\ | |
546 | ((png_fixed_point)(100000 * (fp))) : (png_fixed_error(png_ptr, s),0)) | |
547 | #else | |
548 | PNG_EXTERN png_fixed_point png_fixed PNGARG((png_structp png_ptr, double fp, | |
549 | png_const_charp text)); | |
550 | #endif | |
551 | #endif | |
552 | ||
553 | /* Constants for known chunk types. If you need to add a chunk, define the name | |
554 | * here. For historical reasons these constants have the form png_<name>; i.e. | |
555 | * the prefix is lower case. Please use decimal values as the parameters to | |
556 | * match the ISO PNG specification and to avoid relying on the C locale | |
557 | * interpretation of character values. | |
558 | * | |
559 | * Prior to 1.5.6 these constants were strings, as of 1.5.6 png_uint_32 values | |
560 | * are computed and a new macro (PNG_STRING_FROM_CHUNK) added to allow a string | |
561 | * to be generated if required. | |
562 | * | |
563 | * PNG_32b correctly produces a value shifted by up to 24 bits, even on | |
564 | * architectures where (int) is only 16 bits. | |
565 | */ | |
566 | #define PNG_32b(b,s) ((png_uint_32)(b) << (s)) | |
567 | #define PNG_CHUNK(b1,b2,b3,b4) \ | |
568 | (PNG_32b(b1,24) | PNG_32b(b2,16) | PNG_32b(b3,8) | PNG_32b(b4,0)) | |
569 | ||
570 | #define png_IHDR PNG_CHUNK( 73, 72, 68, 82) | |
571 | #define png_IDAT PNG_CHUNK( 73, 68, 65, 84) | |
572 | #define png_IEND PNG_CHUNK( 73, 69, 78, 68) | |
573 | #define png_PLTE PNG_CHUNK( 80, 76, 84, 69) | |
574 | #define png_bKGD PNG_CHUNK( 98, 75, 71, 68) | |
575 | #define png_cHRM PNG_CHUNK( 99, 72, 82, 77) | |
576 | #define png_gAMA PNG_CHUNK(103, 65, 77, 65) | |
577 | #define png_hIST PNG_CHUNK(104, 73, 83, 84) | |
578 | #define png_iCCP PNG_CHUNK(105, 67, 67, 80) | |
579 | #define png_iTXt PNG_CHUNK(105, 84, 88, 116) | |
580 | #define png_oFFs PNG_CHUNK(111, 70, 70, 115) | |
581 | #define png_pCAL PNG_CHUNK(112, 67, 65, 76) | |
582 | #define png_sCAL PNG_CHUNK(115, 67, 65, 76) | |
583 | #define png_pHYs PNG_CHUNK(112, 72, 89, 115) | |
584 | #define png_sBIT PNG_CHUNK(115, 66, 73, 84) | |
585 | #define png_sPLT PNG_CHUNK(115, 80, 76, 84) | |
586 | #define png_sRGB PNG_CHUNK(115, 82, 71, 66) | |
587 | #define png_sTER PNG_CHUNK(115, 84, 69, 82) | |
588 | #define png_tEXt PNG_CHUNK(116, 69, 88, 116) | |
589 | #define png_tIME PNG_CHUNK(116, 73, 77, 69) | |
590 | #define png_tRNS PNG_CHUNK(116, 82, 78, 83) | |
591 | #define png_zTXt PNG_CHUNK(122, 84, 88, 116) | |
592 | ||
593 | /* The following will work on (signed char*) strings, whereas the get_uint_32 | |
594 | * macro will fail on top-bit-set values because of the sign extension. | |
595 | */ | |
596 | #define PNG_CHUNK_FROM_STRING(s)\ | |
597 | PNG_CHUNK(0xff&(s)[0], 0xff&(s)[1], 0xff&(s)[2], 0xff&(s)[3]) | |
598 | ||
599 | /* This uses (char), not (png_byte) to avoid warnings on systems where (char) is | |
600 | * signed and the argument is a (char[]) This macro will fail miserably on | |
601 | * systems where (char) is more than 8 bits. | |
602 | */ | |
603 | #define PNG_STRING_FROM_CHUNK(s,c)\ | |
604 | (void)(((char*)(s))[0]=(char)((c)>>24), ((char*)(s))[1]=(char)((c)>>16),\ | |
605 | ((char*)(s))[2]=(char)((c)>>8), ((char*)(s))[3]=(char)((c))) | |
606 | ||
607 | /* Do the same but terminate with a null character. */ | |
608 | #define PNG_CSTRING_FROM_CHUNK(s,c)\ | |
609 | (void)(PNG_STRING_FROM_CHUNK(s,c), ((char*)(s))[4] = 0) | |
610 | ||
611 | /* Test on flag values as defined in the spec (section 5.4): */ | |
612 | #define PNG_CHUNK_ANCILLIARY(c) (1 & ((c) >> 29)) | |
613 | #define PNG_CHUNK_CRITICAL(c) (!PNG_CHUNK_ANCILLIARY(c)) | |
614 | #define PNG_CHUNK_PRIVATE(c) (1 & ((c) >> 21)) | |
615 | #define PNG_CHUNK_RESERVED(c) (1 & ((c) >> 13)) | |
616 | #define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >> 5)) | |
617 | ||
618 | /* Gamma values (new at libpng-1.5.4): */ | |
619 | #define PNG_GAMMA_MAC_OLD 151724 /* Assume '1.8' is really 2.2/1.45! */ | |
620 | #define PNG_GAMMA_MAC_INVERSE 65909 | |
621 | #define PNG_GAMMA_sRGB_INVERSE 45455 | |
622 | ||
623 | ||
624 | /* Inhibit C++ name-mangling for libpng functions but not for system calls. */ | |
625 | #ifdef __cplusplus | |
626 | extern "C" { | |
627 | #endif /* __cplusplus */ | |
628 | ||
629 | /* These functions are used internally in the code. They generally | |
630 | * shouldn't be used unless you are writing code to add or replace some | |
631 | * functionality in libpng. More information about most functions can | |
632 | * be found in the files where the functions are located. | |
633 | */ | |
634 | ||
635 | /* Check the user version string for compatibility, returns false if the version | |
636 | * numbers aren't compatible. | |
637 | */ | |
638 | PNG_EXTERN int png_user_version_check(png_structp png_ptr, | |
639 | png_const_charp user_png_ver); | |
640 | ||
641 | /* Allocate memory for an internal libpng struct */ | |
642 | PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct,PNGARG((int type)), | |
643 | PNG_ALLOCATED); | |
644 | ||
645 | /* Free memory from internal libpng struct */ | |
646 | PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr)); | |
647 | ||
648 | PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct_2, | |
649 | PNGARG((int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)), | |
650 | PNG_ALLOCATED); | |
651 | PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr, | |
652 | png_free_ptr free_fn, png_voidp mem_ptr)); | |
653 | ||
654 | /* Free any memory that info_ptr points to and reset struct. */ | |
655 | PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr, | |
656 | png_infop info_ptr)); | |
657 | ||
658 | /* Function to allocate memory for zlib. PNGAPI is disallowed. */ | |
659 | PNG_EXTERN PNG_FUNCTION(voidpf,png_zalloc,PNGARG((voidpf png_ptr, uInt items, | |
660 | uInt size)),PNG_ALLOCATED); | |
661 | ||
662 | /* Function to free memory for zlib. PNGAPI is disallowed. */ | |
663 | PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr)); | |
664 | ||
665 | /* Next four functions are used internally as callbacks. PNGCBAPI is required | |
666 | * but not PNG_EXPORT. PNGAPI added at libpng version 1.2.3, changed to | |
667 | * PNGCBAPI at 1.5.0 | |
668 | */ | |
669 | ||
670 | PNG_EXTERN void PNGCBAPI png_default_read_data PNGARG((png_structp png_ptr, | |
671 | png_bytep data, png_size_t length)); | |
672 | ||
673 | #ifdef PNG_PROGRESSIVE_READ_SUPPORTED | |
674 | PNG_EXTERN void PNGCBAPI png_push_fill_buffer PNGARG((png_structp png_ptr, | |
675 | png_bytep buffer, png_size_t length)); | |
676 | #endif | |
677 | ||
678 | PNG_EXTERN void PNGCBAPI png_default_write_data PNGARG((png_structp png_ptr, | |
679 | png_bytep data, png_size_t length)); | |
680 | ||
681 | #ifdef PNG_WRITE_FLUSH_SUPPORTED | |
682 | # ifdef PNG_STDIO_SUPPORTED | |
683 | PNG_EXTERN void PNGCBAPI png_default_flush PNGARG((png_structp png_ptr)); | |
684 | # endif | |
685 | #endif | |
686 | ||
687 | /* Reset the CRC variable */ | |
688 | PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr)); | |
689 | ||
690 | /* Write the "data" buffer to whatever output you are using */ | |
691 | PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, | |
692 | png_const_bytep data, png_size_t length)); | |
693 | ||
694 | /* Read and check the PNG file signature */ | |
695 | PNG_EXTERN void png_read_sig PNGARG((png_structp png_ptr, png_infop info_ptr)); | |
696 | ||
697 | /* Read the chunk header (length + type name) */ | |
698 | PNG_EXTERN png_uint_32 png_read_chunk_header PNGARG((png_structp png_ptr)); | |
699 | ||
700 | /* Read data from whatever input you are using into the "data" buffer */ | |
701 | PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data, | |
702 | png_size_t length)); | |
703 | ||
704 | /* Read bytes into buf, and update png_ptr->crc */ | |
705 | PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf, | |
706 | png_size_t length)); | |
707 | ||
708 | /* Decompress data in a chunk that uses compression */ | |
709 | #if defined(PNG_READ_COMPRESSED_TEXT_SUPPORTED) | |
710 | PNG_EXTERN void png_decompress_chunk PNGARG((png_structp png_ptr, | |
711 | int comp_type, png_size_t chunklength, png_size_t prefix_length, | |
712 | png_size_t *data_length)); | |
713 | #endif | |
714 | ||
715 | /* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */ | |
716 | PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip)); | |
717 | ||
718 | /* Read the CRC from the file and compare it to the libpng calculated CRC */ | |
719 | PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr)); | |
720 | ||
721 | /* Calculate the CRC over a section of data. Note that we are only | |
722 | * passing a maximum of 64K on systems that have this as a memory limit, | |
723 | * since this is the maximum buffer size we can specify. | |
724 | */ | |
725 | PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, | |
726 | png_const_bytep ptr, png_size_t length)); | |
727 | ||
728 | #ifdef PNG_WRITE_FLUSH_SUPPORTED | |
729 | PNG_EXTERN void png_flush PNGARG((png_structp png_ptr)); | |
730 | #endif | |
731 | ||
732 | /* Write various chunks */ | |
733 | ||
734 | /* Write the IHDR chunk, and update the png_struct with the necessary | |
735 | * information. | |
736 | */ | |
737 | PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width, | |
738 | png_uint_32 height, | |
739 | int bit_depth, int color_type, int compression_method, int filter_method, | |
740 | int interlace_method)); | |
741 | ||
742 | PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, | |
743 | png_const_colorp palette, png_uint_32 num_pal)); | |
744 | ||
745 | PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data, | |
746 | png_size_t length)); | |
747 | ||
748 | PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr)); | |
749 | ||
750 | #ifdef PNG_WRITE_gAMA_SUPPORTED | |
751 | # ifdef PNG_FLOATING_POINT_SUPPORTED | |
752 | PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma)); | |
753 | # endif | |
754 | # ifdef PNG_FIXED_POINT_SUPPORTED | |
755 | PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, | |
756 | png_fixed_point file_gamma)); | |
757 | # endif | |
758 | #endif | |
759 | ||
760 | #ifdef PNG_WRITE_sBIT_SUPPORTED | |
761 | PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, | |
762 | png_const_color_8p sbit, int color_type)); | |
763 | #endif | |
764 | ||
765 | #ifdef PNG_WRITE_cHRM_SUPPORTED | |
766 | # ifdef PNG_FLOATING_POINT_SUPPORTED | |
767 | PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr, | |
768 | double white_x, double white_y, | |
769 | double red_x, double red_y, double green_x, double green_y, | |
770 | double blue_x, double blue_y)); | |
771 | # endif | |
772 | PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr, | |
773 | png_fixed_point int_white_x, png_fixed_point int_white_y, | |
774 | png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point | |
775 | int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x, | |
776 | png_fixed_point int_blue_y)); | |
777 | #endif | |
778 | ||
779 | #ifdef PNG_WRITE_sRGB_SUPPORTED | |
780 | PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr, | |
781 | int intent)); | |
782 | #endif | |
783 | ||
784 | #ifdef PNG_WRITE_iCCP_SUPPORTED | |
785 | PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr, | |
786 | png_const_charp name, int compression_type, | |
787 | png_const_charp profile, int proflen)); | |
788 | /* Note to maintainer: profile should be png_bytep */ | |
789 | #endif | |
790 | ||
791 | #ifdef PNG_WRITE_sPLT_SUPPORTED | |
792 | PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr, | |
793 | png_const_sPLT_tp palette)); | |
794 | #endif | |
795 | ||
796 | #ifdef PNG_WRITE_tRNS_SUPPORTED | |
797 | PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, | |
798 | png_const_bytep trans, png_const_color_16p values, int number, | |
799 | int color_type)); | |
800 | #endif | |
801 | ||
802 | #ifdef PNG_WRITE_bKGD_SUPPORTED | |
803 | PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr, | |
804 | png_const_color_16p values, int color_type)); | |
805 | #endif | |
806 | ||
807 | #ifdef PNG_WRITE_hIST_SUPPORTED | |
808 | PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, | |
809 | png_const_uint_16p hist, int num_hist)); | |
810 | #endif | |
811 | ||
812 | /* Chunks that have keywords */ | |
813 | #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ | |
814 | defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) | |
815 | PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr, | |
816 | png_const_charp key, png_charpp new_key)); | |
817 | #endif | |
818 | ||
819 | #ifdef PNG_WRITE_tEXt_SUPPORTED | |
820 | PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_const_charp key, | |
821 | png_const_charp text, png_size_t text_len)); | |
822 | #endif | |
823 | ||
824 | #ifdef PNG_WRITE_zTXt_SUPPORTED | |
825 | PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_const_charp key, | |
826 | png_const_charp text, png_size_t text_len, int compression)); | |
827 | #endif | |
828 | ||
829 | #ifdef PNG_WRITE_iTXt_SUPPORTED | |
830 | PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr, | |
831 | int compression, png_const_charp key, png_const_charp lang, | |
832 | png_const_charp lang_key, png_const_charp text)); | |
833 | #endif | |
834 | ||
835 | #ifdef PNG_TEXT_SUPPORTED /* Added at version 1.0.14 and 1.2.4 */ | |
836 | PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr, | |
837 | png_infop info_ptr, png_const_textp text_ptr, int num_text)); | |
838 | #endif | |
839 | ||
840 | #ifdef PNG_WRITE_oFFs_SUPPORTED | |
841 | PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr, | |
842 | png_int_32 x_offset, png_int_32 y_offset, int unit_type)); | |
843 | #endif | |
844 | ||
845 | #ifdef PNG_WRITE_pCAL_SUPPORTED | |
846 | PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose, | |
847 | png_int_32 X0, png_int_32 X1, int type, int nparams, | |
848 | png_const_charp units, png_charpp params)); | |
849 | #endif | |
850 | ||
851 | #ifdef PNG_WRITE_pHYs_SUPPORTED | |
852 | PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr, | |
853 | png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit, | |
854 | int unit_type)); | |
855 | #endif | |
856 | ||
857 | #ifdef PNG_WRITE_tIME_SUPPORTED | |
858 | PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr, | |
859 | png_const_timep mod_time)); | |
860 | #endif | |
861 | ||
862 | #ifdef PNG_WRITE_sCAL_SUPPORTED | |
863 | PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr, | |
864 | int unit, png_const_charp width, png_const_charp height)); | |
865 | #endif | |
866 | ||
867 | /* Called when finished processing a row of data */ | |
868 | PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr)); | |
869 | ||
870 | /* Internal use only. Called before first row of data */ | |
871 | PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr)); | |
872 | ||
873 | /* Combine a row of data, dealing with alpha, etc. if requested. 'row' is an | |
874 | * array of png_ptr->width pixels. If the image is not interlaced or this | |
875 | * is the final pass this just does a png_memcpy, otherwise the "display" flag | |
876 | * is used to determine whether to copy pixels that are not in the current pass. | |
877 | * | |
878 | * Because 'png_do_read_interlace' (below) replicates pixels this allows this | |
879 | * function to achieve the documented 'blocky' appearance during interlaced read | |
880 | * if display is 1 and the 'sparkle' appearance, where existing pixels in 'row' | |
881 | * are not changed if they are not in the current pass, when display is 0. | |
882 | * | |
883 | * 'display' must be 0 or 1, otherwise the memcpy will be done regardless. | |
884 | * | |
885 | * The API always reads from the png_struct row buffer and always assumes that | |
886 | * it is full width (png_do_read_interlace has already been called.) | |
887 | * | |
888 | * This function is only ever used to write to row buffers provided by the | |
889 | * caller of the relevant libpng API and the row must have already been | |
890 | * transformed by the read transformations. | |
891 | * | |
892 | * The PNG_USE_COMPILE_TIME_MASKS option causes generation of pre-computed | |
893 | * bitmasks for use within the code, otherwise runtime generated masks are used. | |
894 | * The default is compile time masks. | |
895 | */ | |
896 | #ifndef PNG_USE_COMPILE_TIME_MASKS | |
897 | # define PNG_USE_COMPILE_TIME_MASKS 1 | |
898 | #endif | |
899 | PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row, | |
900 | int display)); | |
901 | ||
902 | #ifdef PNG_READ_INTERLACING_SUPPORTED | |
903 | /* Expand an interlaced row: the 'row_info' describes the pass data that has | |
904 | * been read in and must correspond to the pixels in 'row', the pixels are | |
905 | * expanded (moved apart) in 'row' to match the final layout, when doing this | |
906 | * the pixels are *replicated* to the intervening space. This is essential for | |
907 | * the correct operation of png_combine_row, above. | |
908 | */ | |
909 | PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info, | |
910 | png_bytep row, int pass, png_uint_32 transformations)); | |
911 | #endif | |
912 | ||
913 | /* GRR TO DO (2.0 or whenever): simplify other internal calling interfaces */ | |
914 | ||
915 | #ifdef PNG_WRITE_INTERLACING_SUPPORTED | |
916 | /* Grab pixels out of a row for an interlaced pass */ | |
917 | PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info, | |
918 | png_bytep row, int pass)); | |
919 | #endif | |
920 | ||
921 | /* Unfilter a row: check the filter value before calling this, there is no point | |
922 | * calling it for PNG_FILTER_VALUE_NONE. | |
923 | */ | |
924 | PNG_EXTERN void png_read_filter_row PNGARG((png_row_infop row_info, | |
925 | png_bytep row, png_const_bytep prev_row, int filter)); | |
926 | ||
927 | /* Choose the best filter to use and filter the row data */ | |
928 | PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr, | |
929 | png_row_infop row_info)); | |
930 | ||
931 | /* Finish a row while reading, dealing with interlacing passes, etc. */ | |
932 | PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr)); | |
933 | ||
934 | /* Initialize the row buffers, etc. */ | |
935 | PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr)); | |
936 | ||
937 | #ifdef PNG_READ_TRANSFORMS_SUPPORTED | |
938 | /* Optional call to update the users info structure */ | |
939 | PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr, | |
940 | png_infop info_ptr)); | |
941 | #endif | |
942 | ||
943 | /* These are the functions that do the transformations */ | |
944 | #ifdef PNG_READ_FILLER_SUPPORTED | |
945 | PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info, | |
946 | png_bytep row, png_uint_32 filler, png_uint_32 flags)); | |
947 | #endif | |
948 | ||
949 | #ifdef PNG_READ_SWAP_ALPHA_SUPPORTED | |
950 | PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info, | |
951 | png_bytep row)); | |
952 | #endif | |
953 | ||
954 | #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED | |
955 | PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info, | |
956 | png_bytep row)); | |
957 | #endif | |
958 | ||
959 | #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED | |
960 | PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info, | |
961 | png_bytep row)); | |
962 | #endif | |
963 | ||
964 | #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED | |
965 | PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info, | |
966 | png_bytep row)); | |
967 | #endif | |
968 | ||
969 | #if defined(PNG_WRITE_FILLER_SUPPORTED) || \ | |
970 | defined(PNG_READ_STRIP_ALPHA_SUPPORTED) | |
971 | PNG_EXTERN void png_do_strip_channel PNGARG((png_row_infop row_info, | |
972 | png_bytep row, int at_start)); | |
973 | #endif | |
974 | ||
975 | #ifdef PNG_16BIT_SUPPORTED | |
976 | #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) | |
977 | PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, | |
978 | png_bytep row)); | |
979 | #endif | |
980 | #endif | |
981 | ||
982 | #if defined(PNG_READ_PACKSWAP_SUPPORTED) || \ | |
983 | defined(PNG_WRITE_PACKSWAP_SUPPORTED) | |
984 | PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, | |
985 | png_bytep row)); | |
986 | #endif | |
987 | ||
988 | #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED | |
989 | PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, | |
990 | png_row_infop row_info, png_bytep row)); | |
991 | #endif | |
992 | ||
993 | #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED | |
994 | PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info, | |
995 | png_bytep row)); | |
996 | #endif | |
997 | ||
998 | #ifdef PNG_READ_PACK_SUPPORTED | |
999 | PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, | |
1000 | png_bytep row)); | |
1001 | #endif | |
1002 | ||
1003 | #ifdef PNG_READ_SHIFT_SUPPORTED | |
1004 | PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, | |
1005 | png_bytep row, png_const_color_8p sig_bits)); | |
1006 | #endif | |
1007 | ||
1008 | #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) | |
1009 | PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, | |
1010 | png_bytep row)); | |
1011 | #endif | |
1012 | ||
1013 | #ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED | |
1014 | PNG_EXTERN void png_do_scale_16_to_8 PNGARG((png_row_infop row_info, | |
1015 | png_bytep row)); | |
1016 | #endif | |
1017 | ||
1018 | #ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED | |
1019 | PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, | |
1020 | png_bytep row)); | |
1021 | #endif | |
1022 | ||
1023 | #ifdef PNG_READ_QUANTIZE_SUPPORTED | |
1024 | PNG_EXTERN void png_do_quantize PNGARG((png_row_infop row_info, | |
1025 | png_bytep row, png_const_bytep palette_lookup, | |
1026 | png_const_bytep quantize_lookup)); | |
1027 | ||
1028 | # ifdef PNG_CORRECT_PALETTE_SUPPORTED | |
1029 | PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr, | |
1030 | png_colorp palette, int num_palette)); | |
1031 | # endif | |
1032 | #endif | |
1033 | ||
1034 | #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) | |
1035 | PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, | |
1036 | png_bytep row)); | |
1037 | #endif | |
1038 | ||
1039 | #ifdef PNG_WRITE_PACK_SUPPORTED | |
1040 | PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info, | |
1041 | png_bytep row, png_uint_32 bit_depth)); | |
1042 | #endif | |
1043 | ||
1044 | #ifdef PNG_WRITE_SHIFT_SUPPORTED | |
1045 | PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, | |
1046 | png_bytep row, png_const_color_8p bit_depth)); | |
1047 | #endif | |
1048 | ||
1049 | #if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ | |
1050 | defined(PNG_READ_ALPHA_MODE_SUPPORTED) | |
1051 | PNG_EXTERN void png_do_compose PNGARG((png_row_infop row_info, | |
1052 | png_bytep row, png_structp png_ptr)); | |
1053 | #endif | |
1054 | ||
1055 | #ifdef PNG_READ_GAMMA_SUPPORTED | |
1056 | PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, | |
1057 | png_bytep row, png_structp png_ptr)); | |
1058 | #endif | |
1059 | ||
1060 | #ifdef PNG_READ_ALPHA_MODE_SUPPORTED | |
1061 | PNG_EXTERN void png_do_encode_alpha PNGARG((png_row_infop row_info, | |
1062 | png_bytep row, png_structp png_ptr)); | |
1063 | #endif | |
1064 | ||
1065 | #ifdef PNG_READ_EXPAND_SUPPORTED | |
1066 | PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info, | |
1067 | png_bytep row, png_const_colorp palette, png_const_bytep trans, | |
1068 | int num_trans)); | |
1069 | PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info, | |
1070 | png_bytep row, png_const_color_16p trans_color)); | |
1071 | #endif | |
1072 | ||
1073 | #ifdef PNG_READ_EXPAND_16_SUPPORTED | |
1074 | PNG_EXTERN void png_do_expand_16 PNGARG((png_row_infop row_info, | |
1075 | png_bytep row)); | |
1076 | #endif | |
1077 | ||
1078 | /* The following decodes the appropriate chunks, and does error correction, | |
1079 | * then calls the appropriate callback for the chunk if it is valid. | |
1080 | */ | |
1081 | ||
1082 | /* Decode the IHDR chunk */ | |
1083 | PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1084 | png_uint_32 length)); | |
1085 | PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1086 | png_uint_32 length)); | |
1087 | PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1088 | png_uint_32 length)); | |
1089 | ||
1090 | #ifdef PNG_READ_bKGD_SUPPORTED | |
1091 | PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1092 | png_uint_32 length)); | |
1093 | #endif | |
1094 | ||
1095 | #ifdef PNG_READ_cHRM_SUPPORTED | |
1096 | PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1097 | png_uint_32 length)); | |
1098 | #endif | |
1099 | ||
1100 | #ifdef PNG_READ_gAMA_SUPPORTED | |
1101 | PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1102 | png_uint_32 length)); | |
1103 | #endif | |
1104 | ||
1105 | #ifdef PNG_READ_hIST_SUPPORTED | |
1106 | PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1107 | png_uint_32 length)); | |
1108 | #endif | |
1109 | ||
1110 | #ifdef PNG_READ_iCCP_SUPPORTED | |
1111 | PNG_EXTERN void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1112 | png_uint_32 length)); | |
1113 | #endif /* PNG_READ_iCCP_SUPPORTED */ | |
1114 | ||
1115 | #ifdef PNG_READ_iTXt_SUPPORTED | |
1116 | PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1117 | png_uint_32 length)); | |
1118 | #endif | |
1119 | ||
1120 | #ifdef PNG_READ_oFFs_SUPPORTED | |
1121 | PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1122 | png_uint_32 length)); | |
1123 | #endif | |
1124 | ||
1125 | #ifdef PNG_READ_pCAL_SUPPORTED | |
1126 | PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1127 | png_uint_32 length)); | |
1128 | #endif | |
1129 | ||
1130 | #ifdef PNG_READ_pHYs_SUPPORTED | |
1131 | PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1132 | png_uint_32 length)); | |
1133 | #endif | |
1134 | ||
1135 | #ifdef PNG_READ_sBIT_SUPPORTED | |
1136 | PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1137 | png_uint_32 length)); | |
1138 | #endif | |
1139 | ||
1140 | #ifdef PNG_READ_sCAL_SUPPORTED | |
1141 | PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1142 | png_uint_32 length)); | |
1143 | #endif | |
1144 | ||
1145 | #ifdef PNG_READ_sPLT_SUPPORTED | |
1146 | PNG_EXTERN void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1147 | png_uint_32 length)); | |
1148 | #endif /* PNG_READ_sPLT_SUPPORTED */ | |
1149 | ||
1150 | #ifdef PNG_READ_sRGB_SUPPORTED | |
1151 | PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1152 | png_uint_32 length)); | |
1153 | #endif | |
1154 | ||
1155 | #ifdef PNG_READ_tEXt_SUPPORTED | |
1156 | PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1157 | png_uint_32 length)); | |
1158 | #endif | |
1159 | ||
1160 | #ifdef PNG_READ_tIME_SUPPORTED | |
1161 | PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1162 | png_uint_32 length)); | |
1163 | #endif | |
1164 | ||
1165 | #ifdef PNG_READ_tRNS_SUPPORTED | |
1166 | PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1167 | png_uint_32 length)); | |
1168 | #endif | |
1169 | ||
1170 | #ifdef PNG_READ_zTXt_SUPPORTED | |
1171 | PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr, | |
1172 | png_uint_32 length)); | |
1173 | #endif | |
1174 | ||
1175 | #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED | |
1176 | PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr, | |
1177 | png_infop info_ptr, png_uint_32 length)); | |
1178 | #endif | |
1179 | ||
1180 | PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr, | |
1181 | png_uint_32 chunk_name)); | |
1182 | ||
1183 | #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED | |
1184 | /* Exactly as png_handle_as_unknown() except that the argument is a 32-bit chunk | |
1185 | * name, not a string. | |
1186 | */ | |
1187 | PNG_EXTERN int png_chunk_unknown_handling PNGARG((png_structp png_ptr, | |
1188 | png_uint_32 chunk_name)); | |
1189 | #endif | |
1190 | ||
1191 | /* Handle the transformations for reading and writing */ | |
1192 | #ifdef PNG_READ_TRANSFORMS_SUPPORTED | |
1193 | PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr, | |
1194 | png_row_infop row_info)); | |
1195 | #endif | |
1196 | #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED | |
1197 | PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr, | |
1198 | png_row_infop row_info)); | |
1199 | #endif | |
1200 | ||
1201 | #ifdef PNG_READ_TRANSFORMS_SUPPORTED | |
1202 | PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr)); | |
1203 | #endif | |
1204 | ||
1205 | #ifdef PNG_PROGRESSIVE_READ_SUPPORTED | |
1206 | PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr, | |
1207 | png_infop info_ptr)); | |
1208 | PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr, | |
1209 | png_infop info_ptr)); | |
1210 | PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr)); | |
1211 | PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr, | |
1212 | png_uint_32 length)); | |
1213 | PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr)); | |
1214 | PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr)); | |
1215 | PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr, | |
1216 | png_bytep buffer, png_size_t buffer_length)); | |
1217 | PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr)); | |
1218 | PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr, | |
1219 | png_bytep buffer, png_size_t buffer_length)); | |
1220 | PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr)); | |
1221 | PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr, | |
1222 | png_infop info_ptr, png_uint_32 length)); | |
1223 | PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr, | |
1224 | png_infop info_ptr)); | |
1225 | PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr, | |
1226 | png_infop info_ptr)); | |
1227 | PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row)); | |
1228 | PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr, | |
1229 | png_infop info_ptr)); | |
1230 | PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr, | |
1231 | png_infop info_ptr)); | |
1232 | PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr)); | |
1233 | # ifdef PNG_READ_tEXt_SUPPORTED | |
1234 | PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr, | |
1235 | png_infop info_ptr, png_uint_32 length)); | |
1236 | PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr, | |
1237 | png_infop info_ptr)); | |
1238 | # endif | |
1239 | # ifdef PNG_READ_zTXt_SUPPORTED | |
1240 | PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr, | |
1241 | png_infop info_ptr, png_uint_32 length)); | |
1242 | PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr, | |
1243 | png_infop info_ptr)); | |
1244 | # endif | |
1245 | # ifdef PNG_READ_iTXt_SUPPORTED | |
1246 | PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr, | |
1247 | png_infop info_ptr, png_uint_32 length)); | |
1248 | PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr, | |
1249 | png_infop info_ptr)); | |
1250 | # endif | |
1251 | ||
1252 | #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ | |
1253 | ||
1254 | #ifdef PNG_MNG_FEATURES_SUPPORTED | |
1255 | PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info, | |
1256 | png_bytep row)); | |
1257 | PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info, | |
1258 | png_bytep row)); | |
1259 | #endif | |
1260 | ||
1261 | /* Added at libpng version 1.4.0 */ | |
1262 | #ifdef PNG_CHECK_cHRM_SUPPORTED | |
1263 | PNG_EXTERN int png_check_cHRM_fixed PNGARG((png_structp png_ptr, | |
1264 | png_fixed_point int_white_x, png_fixed_point int_white_y, | |
1265 | png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point | |
1266 | int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x, | |
1267 | png_fixed_point int_blue_y)); | |
1268 | #endif | |
1269 | ||
1270 | #ifdef PNG_CHECK_cHRM_SUPPORTED | |
1271 | /* Added at libpng version 1.2.34 and 1.4.0 */ | |
1272 | /* Currently only used by png_check_cHRM_fixed */ | |
1273 | PNG_EXTERN void png_64bit_product PNGARG((long v1, long v2, | |
1274 | unsigned long *hi_product, unsigned long *lo_product)); | |
1275 | #endif | |
1276 | ||
1277 | #ifdef PNG_cHRM_SUPPORTED | |
1278 | /* Added at libpng version 1.5.5 */ | |
1279 | typedef struct png_xy | |
1280 | { | |
1281 | png_fixed_point redx, redy; | |
1282 | png_fixed_point greenx, greeny; | |
1283 | png_fixed_point bluex, bluey; | |
1284 | png_fixed_point whitex, whitey; | |
1285 | } png_xy; | |
1286 | ||
1287 | typedef struct png_XYZ | |
1288 | { | |
1289 | png_fixed_point redX, redY, redZ; | |
1290 | png_fixed_point greenX, greenY, greenZ; | |
1291 | png_fixed_point blueX, blueY, blueZ; | |
1292 | } png_XYZ; | |
1293 | ||
1294 | /* The conversion APIs return 0 on success, non-zero on a parameter error. They | |
1295 | * allow conversion between the above representations of a color encoding. When | |
1296 | * converting from XYZ end points to chromaticities the absolute magnitude of | |
1297 | * the end points is lost, when converting back the sum of the Y values of the | |
1298 | * three end points will be 1.0 | |
1299 | */ | |
1300 | PNG_EXTERN int png_xy_from_XYZ PNGARG((png_xy *xy, png_XYZ XYZ)); | |
1301 | PNG_EXTERN int png_XYZ_from_xy PNGARG((png_XYZ *XYZ, png_xy xy)); | |
1302 | PNG_EXTERN int png_XYZ_from_xy_checked PNGARG((png_structp png_ptr, | |
1303 | png_XYZ *XYZ, png_xy xy)); | |
1304 | #endif | |
1305 | ||
1306 | /* Added at libpng version 1.4.0 */ | |
1307 | PNG_EXTERN void png_check_IHDR PNGARG((png_structp png_ptr, | |
1308 | png_uint_32 width, png_uint_32 height, int bit_depth, | |
1309 | int color_type, int interlace_type, int compression_type, | |
1310 | int filter_type)); | |
1311 | ||
1312 | /* Free all memory used by the read (old method - NOT DLL EXPORTED) */ | |
1313 | PNG_EXTERN void png_read_destroy PNGARG((png_structp png_ptr, | |
1314 | png_infop info_ptr, png_infop end_info_ptr)); | |
1315 | ||
1316 | /* Free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */ | |
1317 | PNG_EXTERN void png_write_destroy PNGARG((png_structp png_ptr)); | |
1318 | ||
1319 | #ifdef USE_FAR_KEYWORD /* memory model conversion function */ | |
1320 | PNG_EXTERN void *png_far_to_near PNGARG((png_structp png_ptr, png_voidp ptr, | |
1321 | int check)); | |
1322 | #endif /* USE_FAR_KEYWORD */ | |
1323 | ||
1324 | #if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED) | |
1325 | PNG_EXTERN PNG_FUNCTION(void, png_fixed_error, (png_structp png_ptr, | |
1326 | png_const_charp name),PNG_NORETURN); | |
1327 | #endif | |
1328 | ||
1329 | /* Puts 'string' into 'buffer' at buffer[pos], taking care never to overwrite | |
1330 | * the end. Always leaves the buffer nul terminated. Never errors out (and | |
1331 | * there is no error code.) | |
1332 | */ | |
1333 | PNG_EXTERN size_t png_safecat(png_charp buffer, size_t bufsize, size_t pos, | |
1334 | png_const_charp string); | |
1335 | ||
1336 | /* Various internal functions to handle formatted warning messages, currently | |
1337 | * only implemented for warnings. | |
1338 | */ | |
1339 | #if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED) | |
1340 | /* Utility to dump an unsigned value into a buffer, given a start pointer and | |
1341 | * and end pointer (which should point just *beyond* the end of the buffer!) | |
1342 | * Returns the pointer to the start of the formatted string. This utility only | |
1343 | * does unsigned values. | |
1344 | */ | |
1345 | PNG_EXTERN png_charp png_format_number(png_const_charp start, png_charp end, | |
1346 | int format, png_alloc_size_t number); | |
1347 | ||
1348 | /* Convenience macro that takes an array: */ | |
1349 | #define PNG_FORMAT_NUMBER(buffer,format,number) \ | |
1350 | png_format_number(buffer, buffer + (sizeof buffer), format, number) | |
1351 | ||
1352 | /* Suggested size for a number buffer (enough for 64 bits and a sign!) */ | |
1353 | #define PNG_NUMBER_BUFFER_SIZE 24 | |
1354 | ||
1355 | /* These are the integer formats currently supported, the name is formed from | |
1356 | * the standard printf(3) format string. | |
1357 | */ | |
1358 | #define PNG_NUMBER_FORMAT_u 1 /* chose unsigned API! */ | |
1359 | #define PNG_NUMBER_FORMAT_02u 2 | |
1360 | #define PNG_NUMBER_FORMAT_d 1 /* chose signed API! */ | |
1361 | #define PNG_NUMBER_FORMAT_02d 2 | |
1362 | #define PNG_NUMBER_FORMAT_x 3 | |
1363 | #define PNG_NUMBER_FORMAT_02x 4 | |
1364 | #define PNG_NUMBER_FORMAT_fixed 5 /* choose the signed API */ | |
1365 | #endif | |
1366 | ||
1367 | #ifdef PNG_WARNINGS_SUPPORTED | |
1368 | /* New defines and members adding in libpng-1.5.4 */ | |
1369 | # define PNG_WARNING_PARAMETER_SIZE 32 | |
1370 | # define PNG_WARNING_PARAMETER_COUNT 8 | |
1371 | ||
1372 | /* An l-value of this type has to be passed to the APIs below to cache the | |
1373 | * values of the parameters to a formatted warning message. | |
1374 | */ | |
1375 | typedef char png_warning_parameters[PNG_WARNING_PARAMETER_COUNT][ | |
1376 | PNG_WARNING_PARAMETER_SIZE]; | |
1377 | ||
1378 | PNG_EXTERN void png_warning_parameter(png_warning_parameters p, int number, | |
1379 | png_const_charp string); | |
1380 | /* Parameters are limited in size to PNG_WARNING_PARAMETER_SIZE characters, | |
1381 | * including the trailing '\0'. | |
1382 | */ | |
1383 | PNG_EXTERN void png_warning_parameter_unsigned(png_warning_parameters p, | |
1384 | int number, int format, png_alloc_size_t value); | |
1385 | /* Use png_alloc_size_t because it is an unsigned type as big as any we | |
1386 | * need to output. Use the following for a signed value. | |
1387 | */ | |
1388 | PNG_EXTERN void png_warning_parameter_signed(png_warning_parameters p, | |
1389 | int number, int format, png_int_32 value); | |
1390 | ||
1391 | PNG_EXTERN void png_formatted_warning(png_structp png_ptr, | |
1392 | png_warning_parameters p, png_const_charp message); | |
1393 | /* 'message' follows the X/Open approach of using @1, @2 to insert | |
1394 | * parameters previously supplied using the above functions. Errors in | |
1395 | * specifying the paramters will simple result in garbage substitutions. | |
1396 | */ | |
1397 | #endif | |
1398 | ||
1399 | /* ASCII to FP interfaces, currently only implemented if sCAL | |
1400 | * support is required. | |
1401 | */ | |
1402 | #if defined(PNG_READ_sCAL_SUPPORTED) | |
1403 | /* MAX_DIGITS is actually the maximum number of characters in an sCAL | |
1404 | * width or height, derived from the precision (number of significant | |
1405 | * digits - a build time settable option) and assumpitions about the | |
1406 | * maximum ridiculous exponent. | |
1407 | */ | |
1408 | #define PNG_sCAL_MAX_DIGITS (PNG_sCAL_PRECISION+1/*.*/+1/*E*/+10/*exponent*/) | |
1409 | ||
1410 | #ifdef PNG_FLOATING_POINT_SUPPORTED | |
1411 | PNG_EXTERN void png_ascii_from_fp PNGARG((png_structp png_ptr, png_charp ascii, | |
1412 | png_size_t size, double fp, unsigned int precision)); | |
1413 | #endif /* FLOATING_POINT */ | |
1414 | ||
1415 | #ifdef PNG_FIXED_POINT_SUPPORTED | |
1416 | PNG_EXTERN void png_ascii_from_fixed PNGARG((png_structp png_ptr, | |
1417 | png_charp ascii, png_size_t size, png_fixed_point fp)); | |
1418 | #endif /* FIXED_POINT */ | |
1419 | #endif /* READ_sCAL */ | |
1420 | ||
1421 | #if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED) | |
1422 | /* An internal API to validate the format of a floating point number. | |
1423 | * The result is the index of the next character. If the number is | |
1424 | * not valid it will be the index of a character in the supposed number. | |
1425 | * | |
1426 | * The format of a number is defined in the PNG extensions specification | |
1427 | * and this API is strictly conformant to that spec, not anyone elses! | |
1428 | * | |
1429 | * The format as a regular expression is: | |
1430 | * | |
1431 | * [+-]?[0-9]+.?([Ee][+-]?[0-9]+)? | |
1432 | * | |
1433 | * or: | |
1434 | * | |
1435 | * [+-]?.[0-9]+(.[0-9]+)?([Ee][+-]?[0-9]+)? | |
1436 | * | |
1437 | * The complexity is that either integer or fraction must be present and the | |
1438 | * fraction is permitted to have no digits only if the integer is present. | |
1439 | * | |
1440 | * NOTE: The dangling E problem. | |
1441 | * There is a PNG valid floating point number in the following: | |
1442 | * | |
1443 | * PNG floating point numb1.ers are not greedy. | |
1444 | * | |
1445 | * Working this out requires *TWO* character lookahead (because of the | |
1446 | * sign), the parser does not do this - it will fail at the 'r' - this | |
1447 | * doesn't matter for PNG sCAL chunk values, but it requires more care | |
1448 | * if the value were ever to be embedded in something more complex. Use | |
1449 | * ANSI-C strtod if you need the lookahead. | |
1450 | */ | |
1451 | /* State table for the parser. */ | |
1452 | #define PNG_FP_INTEGER 0 /* before or in integer */ | |
1453 | #define PNG_FP_FRACTION 1 /* before or in fraction */ | |
1454 | #define PNG_FP_EXPONENT 2 /* before or in exponent */ | |
1455 | #define PNG_FP_STATE 3 /* mask for the above */ | |
1456 | #define PNG_FP_SAW_SIGN 4 /* Saw +/- in current state */ | |
1457 | #define PNG_FP_SAW_DIGIT 8 /* Saw a digit in current state */ | |
1458 | #define PNG_FP_SAW_DOT 16 /* Saw a dot in current state */ | |
1459 | #define PNG_FP_SAW_E 32 /* Saw an E (or e) in current state */ | |
1460 | #define PNG_FP_SAW_ANY 60 /* Saw any of the above 4 */ | |
1461 | ||
1462 | /* These three values don't affect the parser. They are set but not used. | |
1463 | */ | |
1464 | #define PNG_FP_WAS_VALID 64 /* Preceding substring is a valid fp number */ | |
1465 | #define PNG_FP_NEGATIVE 128 /* A negative number, including "-0" */ | |
1466 | #define PNG_FP_NONZERO 256 /* A non-zero value */ | |
1467 | #define PNG_FP_STICKY 448 /* The above three flags */ | |
1468 | ||
1469 | /* This is available for the caller to store in 'state' if required. Do not | |
1470 | * call the parser after setting it (the parser sometimes clears it.) | |
1471 | */ | |
1472 | #define PNG_FP_INVALID 512 /* Available for callers as a distinct value */ | |
1473 | ||
1474 | /* Result codes for the parser (boolean - true meants ok, false means | |
1475 | * not ok yet.) | |
1476 | */ | |
1477 | #define PNG_FP_MAYBE 0 /* The number may be valid in the future */ | |
1478 | #define PNG_FP_OK 1 /* The number is valid */ | |
1479 | ||
1480 | /* Tests on the sticky non-zero and negative flags. To pass these checks | |
1481 | * the state must also indicate that the whole number is valid - this is | |
1482 | * achieved by testing PNG_FP_SAW_DIGIT (see the implementation for why this | |
1483 | * is equivalent to PNG_FP_OK above.) | |
1484 | */ | |
1485 | #define PNG_FP_NZ_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NEGATIVE | PNG_FP_NONZERO) | |
1486 | /* NZ_MASK: the string is valid and a non-zero negative value */ | |
1487 | #define PNG_FP_Z_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NONZERO) | |
1488 | /* Z MASK: the string is valid and a non-zero value. */ | |
1489 | /* PNG_FP_SAW_DIGIT: the string is valid. */ | |
1490 | #define PNG_FP_IS_ZERO(state) (((state) & PNG_FP_Z_MASK) == PNG_FP_SAW_DIGIT) | |
1491 | #define PNG_FP_IS_POSITIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_Z_MASK) | |
1492 | #define PNG_FP_IS_NEGATIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_NZ_MASK) | |
1493 | ||
1494 | /* The actual parser. This can be called repeatedly, it updates | |
1495 | * the index into the string and the state variable (which must | |
1496 | * be initialzed to 0). It returns a result code, as above. There | |
1497 | * is no point calling the parser any more if it fails to advance to | |
1498 | * the end of the string - it is stuck on an invalid character (or | |
1499 | * terminated by '\0'). | |
1500 | * | |
1501 | * Note that the pointer will consume an E or even an E+ then leave | |
1502 | * a 'maybe' state even though a preceding integer.fraction is valid. | |
1503 | * The PNG_FP_WAS_VALID flag indicates that a preceding substring was | |
1504 | * a valid number. It's possible to recover from this by calling | |
1505 | * the parser again (from the start, with state 0) but with a string | |
1506 | * that omits the last character (i.e. set the size to the index of | |
1507 | * the problem character.) This has not been tested within libpng. | |
1508 | */ | |
1509 | PNG_EXTERN int png_check_fp_number PNGARG((png_const_charp string, | |
1510 | png_size_t size, int *statep, png_size_tp whereami)); | |
1511 | ||
1512 | /* This is the same but it checks a complete string and returns true | |
1513 | * only if it just contains a floating point number. As of 1.5.4 this | |
1514 | * function also returns the state at the end of parsing the number if | |
1515 | * it was valid (otherwise it returns 0.) This can be used for testing | |
1516 | * for negative or zero values using the sticky flag. | |
1517 | */ | |
1518 | PNG_EXTERN int png_check_fp_string PNGARG((png_const_charp string, | |
1519 | png_size_t size)); | |
1520 | #endif /* pCAL || sCAL */ | |
1521 | ||
1522 | #if defined(PNG_READ_GAMMA_SUPPORTED) ||\ | |
1523 | defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED) | |
1524 | /* Added at libpng version 1.5.0 */ | |
1525 | /* This is a utility to provide a*times/div (rounded) and indicate | |
1526 | * if there is an overflow. The result is a boolean - false (0) | |
1527 | * for overflow, true (1) if no overflow, in which case *res | |
1528 | * holds the result. | |
1529 | */ | |
1530 | PNG_EXTERN int png_muldiv PNGARG((png_fixed_point_p res, png_fixed_point a, | |
1531 | png_int_32 multiplied_by, png_int_32 divided_by)); | |
1532 | #endif | |
1533 | ||
1534 | #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED) | |
1535 | /* Same deal, but issue a warning on overflow and return 0. */ | |
1536 | PNG_EXTERN png_fixed_point png_muldiv_warn PNGARG((png_structp png_ptr, | |
1537 | png_fixed_point a, png_int_32 multiplied_by, png_int_32 divided_by)); | |
1538 | #endif | |
1539 | ||
1540 | #ifdef PNG_READ_GAMMA_SUPPORTED | |
1541 | /* Calculate a reciprocal - used for gamma values. This returns | |
1542 | * 0 if the argument is 0 in order to maintain an undefined value, | |
1543 | * there are no warnings. | |
1544 | */ | |
1545 | PNG_EXTERN png_fixed_point png_reciprocal PNGARG((png_fixed_point a)); | |
1546 | ||
1547 | /* The same but gives a reciprocal of the product of two fixed point | |
1548 | * values. Accuracy is suitable for gamma calculations but this is | |
1549 | * not exact - use png_muldiv for that. | |
1550 | */ | |
1551 | PNG_EXTERN png_fixed_point png_reciprocal2 PNGARG((png_fixed_point a, | |
1552 | png_fixed_point b)); | |
1553 | #endif | |
1554 | ||
1555 | #ifdef PNG_READ_GAMMA_SUPPORTED | |
1556 | /* Internal fixed point gamma correction. These APIs are called as | |
1557 | * required to convert single values - they don't need to be fast, | |
1558 | * they are not used when processing image pixel values. | |
1559 | * | |
1560 | * While the input is an 'unsigned' value it must actually be the | |
1561 | * correct bit value - 0..255 or 0..65535 as required. | |
1562 | */ | |
1563 | PNG_EXTERN png_uint_16 png_gamma_correct PNGARG((png_structp png_ptr, | |
1564 | unsigned int value, png_fixed_point gamma_value)); | |
1565 | PNG_EXTERN int png_gamma_significant PNGARG((png_fixed_point gamma_value)); | |
1566 | PNG_EXTERN png_uint_16 png_gamma_16bit_correct PNGARG((unsigned int value, | |
1567 | png_fixed_point gamma_value)); | |
1568 | PNG_EXTERN png_byte png_gamma_8bit_correct PNGARG((unsigned int value, | |
1569 | png_fixed_point gamma_value)); | |
1570 | PNG_EXTERN void png_destroy_gamma_table(png_structp png_ptr); | |
1571 | PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr, | |
1572 | int bit_depth)); | |
1573 | #endif | |
1574 | ||
1575 | /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ | |
1576 | ||
1577 | ||
1578 | #include "pngdebug.h" | |
1579 | ||
1580 | #ifdef __cplusplus | |
1581 | } | |
1582 | #endif | |
1583 | ||
1584 | #endif /* PNGPRIV_H */ |