CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/ext/libpng17/png.h
Views: 1401
1
2
/* png.h - header file for PNG reference library
3
*
4
* libpng version 1.7.0beta90, August 28, 2017
5
*
6
* Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson
7
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
9
*
10
* This code is released under the libpng license (See LICENSE, below)
11
*
12
* Authors and maintainers:
13
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
14
* libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger
15
* libpng versions 0.97, January 1998, through 1.7.0beta90, August 28, 2017:
16
* Glenn Randers-Pehrson.
17
* See also "Contributing Authors", below.
18
*/
19
20
/*
21
* COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
22
*
23
* If you modify libpng you may insert additional notices immediately following
24
* this sentence.
25
*
26
* This code is released under the libpng license.
27
*
28
* libpng versions 1.0.7, July 1, 2000 through 1.7.0beta90, August 28, 2017 are
29
* Copyright (c) 2000-2002, 2004, 2006-2017 Glenn Randers-Pehrson, are
30
* derived from libpng-1.0.6, and are distributed according to the same
31
* disclaimer and license as libpng-1.0.6 with the following individuals
32
* added to the list of Contributing Authors:
33
*
34
* Simon-Pierre Cadieux
35
* Eric S. Raymond
36
* Mans Rullgard
37
* Cosmin Truta
38
* Gilles Vollant
39
* James Yu
40
*
41
* and with the following additions to the disclaimer:
42
*
43
* There is no warranty against interference with your enjoyment of the
44
* library or against infringement. There is no warranty that our
45
* efforts or the library will fulfill any of your particular purposes
46
* or needs. This library is provided with all faults, and the entire
47
* risk of satisfactory quality, performance, accuracy, and effort is with
48
* the user.
49
*
50
* Some files in the "contrib" directory and some configure-generated
51
* files that are distributed with libpng have other copyright owners and
52
* are released under other open source licenses.
53
*
54
* libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
55
* Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from
56
* libpng-0.96, and are distributed according to the same disclaimer and
57
* license as libpng-0.96, with the following individuals added to the list
58
* of Contributing Authors:
59
*
60
* Tom Lane
61
* Glenn Randers-Pehrson
62
* Willem van Schaik
63
*
64
* libpng versions 0.89, June 1996, through 0.96, May 1997, are
65
* Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,
66
* and are distributed according to the same disclaimer and license as
67
* libpng-0.88, with the following individuals added to the list of
68
* Contributing Authors:
69
*
70
* John Bowler
71
* Kevin Bracey
72
* Sam Bushell
73
* Magnus Holmgren
74
* Greg Roelofs
75
* Tom Tanner
76
*
77
* Some files in the "scripts" directory have other copyright owners
78
* but are released under this license.
79
*
80
* libpng versions 0.5, May 1995, through 0.88, January 1996, are
81
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
82
*
83
* For the purposes of this copyright and license, "Contributing Authors"
84
* is defined as the following set of individuals:
85
*
86
* Andreas Dilger
87
* Dave Martindale
88
* Guy Eric Schalnat
89
* Paul Schmidt
90
* Tim Wegner
91
*
92
* The PNG Reference Library is supplied "AS IS". The Contributing Authors
93
* and Group 42, Inc. disclaim all warranties, expressed or implied,
94
* including, without limitation, the warranties of merchantability and of
95
* fitness for any purpose. The Contributing Authors and Group 42, Inc.
96
* assume no liability for direct, indirect, incidental, special, exemplary,
97
* or consequential damages, which may result from the use of the PNG
98
* Reference Library, even if advised of the possibility of such damage.
99
*
100
* Permission is hereby granted to use, copy, modify, and distribute this
101
* source code, or portions hereof, for any purpose, without fee, subject
102
* to the following restrictions:
103
*
104
* 1. The origin of this source code must not be misrepresented.
105
*
106
* 2. Altered versions must be plainly marked as such and must not
107
* be misrepresented as being the original source.
108
*
109
* 3. This Copyright notice may not be removed or altered from any
110
* source or altered source distribution.
111
*
112
* The Contributing Authors and Group 42, Inc. specifically permit, without
113
* fee, and encourage the use of this source code as a component to
114
* supporting the PNG file format in commercial products. If you use this
115
* source code in a product, acknowledgment is not required but would be
116
* appreciated.
117
*
118
* END OF COPYRIGHT NOTICE, DISCLAIMER, and LICENSE.
119
*
120
* TRADEMARK:
121
*
122
* The name "libpng" has not been registered by the Copyright owner
123
* as a trademark in any jurisdiction. However, because libpng has
124
* been distributed and maintained world-wide, continually since 1995,
125
* the Copyright owner claims "common-law trademark protection" in any
126
* jurisdiction where common-law trademark is recognized.
127
*
128
* OSI CERTIFICATION:
129
*
130
* Libpng is OSI Certified Open Source Software. OSI Certified Open Source is
131
* a certification mark of the Open Source Initiative. OSI has not addressed
132
* the additional disclaimers inserted at version 1.0.7.
133
*
134
* EXPORT CONTROL:
135
*
136
* The Copyright owner believes that the Export Control Classification
137
* Number (ECCN) for libpng is EAR99, which means not subject to export
138
* controls or International Traffic in Arms Regulations (ITAR) because
139
* it is open source, publicly available software, that does not contain
140
* any encryption software. See the EAR, paragraphs 734.3(b)(3) and
141
* 734.7(b).
142
*/
143
144
/*
145
* A "png_get_copyright" function is available, for convenient use in "about"
146
* boxes and the like:
147
*
148
* printf("%s", png_get_copyright(NULL));
149
*
150
* Also, the PNG logo (in PNG format, of course) is supplied in the
151
* files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
152
*/
153
154
/*
155
* The contributing authors would like to thank all those who helped
156
* with testing, bug fixes, and patience. This wouldn't have been
157
* possible without all of you.
158
*
159
* Thanks to Frank J. T. Wojcik for helping with the documentation.
160
*/
161
162
/* Note about libpng version numbers:
163
*
164
* Due to various miscommunications, unforeseen code incompatibilities
165
* and occasional factors outside the authors' control, version numbering
166
* on the library has not always been consistent and straightforward.
167
* The following table summarizes matters since version 0.89c, which was
168
* the first widely used release:
169
*
170
* source png.h png.h shared-lib
171
* version string int version
172
* ------- ------ ----- ----------
173
* 0.89c "1.0 beta 3" 0.89 89 1.0.89
174
* 0.90 "1.0 beta 4" 0.90 90 0.90 [should have been 2.0.90]
175
* 0.95 "1.0 beta 5" 0.95 95 0.95 [should have been 2.0.95]
176
* 0.96 "1.0 beta 6" 0.96 96 0.96 [should have been 2.0.96]
177
* 0.97b "1.00.97 beta 7" 1.00.97 97 1.0.1 [should have been 2.0.97]
178
* 0.97c 0.97 97 2.0.97
179
* 0.98 0.98 98 2.0.98
180
* 0.99 0.99 98 2.0.99
181
* 0.99a-m 0.99 99 2.0.99
182
* 1.00 1.00 100 2.1.0 [100 should be 10000]
183
* 1.0.0 (from here on, the 100 2.1.0 [100 should be 10000]
184
* 1.0.1 png.h string is 10001 2.1.0
185
* 1.0.1a-e identical to the 10002 from here on, the shared library
186
* 1.0.2 source version) 10002 is 2.V where V is the source code
187
* 1.0.2a-b 10003 version, except as noted.
188
* 1.0.3 10003
189
* 1.0.3a-d 10004
190
* 1.0.4 10004
191
* 1.0.4a-f 10005
192
* 1.0.5 (+ 2 patches) 10005
193
* 1.0.5a-d 10006
194
* 1.0.5e-r 10100 (not source compatible)
195
* 1.0.5s-v 10006 (not binary compatible)
196
* 1.0.6 (+ 3 patches) 10006 (still binary incompatible)
197
* 1.0.6d-f 10007 (still binary incompatible)
198
* 1.0.6g 10007
199
* 1.0.6h 10007 10.6h (testing xy.z so-numbering)
200
* 1.0.6i 10007 10.6i
201
* 1.0.6j 10007 2.1.0.6j (incompatible with 1.0.0)
202
* 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14 (binary compatible)
203
* 1.0.7beta15-18 1 10007 2.1.0.7beta15-18 (binary compatible)
204
* 1.0.7rc1-2 1 10007 2.1.0.7rc1-2 (binary compatible)
205
* 1.0.7 1 10007 (still compatible)
206
* ...
207
* 1.0.19 10 10019 10.so.0.19[.0]
208
* ...
209
* 1.2.56 13 10253 12.so.0.53[.0]
210
* ...
211
* 1.5.27 15 10523 15.so.15.23[.0]
212
* ...
213
* 1.6.22 16 10622 16.so.16.22[.0]
214
* ...
215
* 1.7.0alpha01-10 17 10700 17.so.17.0[.0]
216
* 1.7.0beta01-84 17 10700 17.so.17.0[.0]
217
*
218
* Henceforth the source version will match the shared-library major
219
* and minor numbers; the shared-library major version number will be
220
* used for changes in backward compatibility, as it is intended. The
221
* PNG_LIBPNG_VER macro, which is not used within libpng but is available
222
* for applications, is an unsigned integer of the form xyyzz corresponding
223
* to the source version x.y.z (leading zeros in y and z). Beta versions
224
* were given the previous public release number plus a letter, until
225
* version 1.0.6j; from then on they were given the upcoming public
226
* release number plus "betaNN" or "rcNN".
227
*
228
* Binary incompatibility exists only when applications make direct access
229
* to the info_ptr or png_ptr members through png.h, and the compiled
230
* application is loaded with a different version of the library.
231
*
232
* DLLNUM will change each time there are forward or backward changes
233
* in binary compatibility (e.g., when a new feature is added).
234
*
235
* See libpng.txt or libpng.3 for more information. The PNG specification
236
* is available as a W3C Recommendation and as an ISO Specification,
237
* <https://www.w3.org/TR/2003/REC-PNG-20031110/
238
*/
239
240
/*
241
* Y2K compliance in libpng:
242
* =========================
243
*
244
* August 28, 2017
245
*
246
* Since the PNG Development group is an ad-hoc body, we can't make
247
* an official declaration.
248
*
249
* This is your unofficial assurance that libpng from version 0.71 and
250
* upward through 1.7.0beta90 are Y2K compliant. It is my belief that
251
* earlier versions were also Y2K compliant.
252
*
253
* Libpng only has two year fields. One is a 2-byte unsigned integer
254
* that will hold years up to 65535. The other, which is deprecated,
255
* holds the date in text format, and will hold years up to 9999.
256
*
257
* The integer is
258
* "png_uint_16 year" in png_time_struct.
259
*
260
* The string is
261
* "char time_buffer[29]" in png_struct. This is no longer used
262
* in libpng-1.6.x and will be removed from libpng-1.7.0.
263
*
264
* There are seven time-related functions:
265
* png.c: png_convert_to_rfc_1123_buffer() in png.c
266
* (formerly png_convert_to_rfc_1123() prior to libpng-1.5.x and
267
* png_convert_to_rfc_1152() in error prior to libpng-0.98)
268
* png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c
269
* png_convert_from_time_t() in pngwrite.c
270
* png_get_tIME() in pngget.c
271
* png_handle_tIME() in pngrutil.c, called in pngread.c
272
* png_set_tIME() in pngset.c
273
* png_write_tIME() in pngwutil.c, called in pngwrite.c
274
*
275
* All handle dates properly in a Y2K environment. The
276
* png_convert_from_time_t() function calls gmtime() to convert from system
277
* clock time, which returns (year - 1900), which we properly convert to
278
* the full 4-digit year. There is a possibility that libpng applications
279
* are not passing 4-digit years into the png_convert_to_rfc_1123_buffer()
280
* function, or that they are incorrectly passing only a 2-digit year
281
* instead of "year - 1900" into the png_convert_from_struct_tm() function,
282
* but this is not under our control. The libpng documentation has always
283
* stated that it works with 4-digit years, and the APIs have been
284
* documented as such.
285
*
286
* The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
287
* integer to hold the year, and can hold years as large as 65535.
288
*
289
* zlib, upon which libpng depends, is also Y2K compliant. It contains
290
* no date-related code.
291
*
292
* Glenn Randers-Pehrson
293
* libpng maintainer
294
* PNG Development Group
295
*/
296
297
#ifndef PNG_H
298
#define PNG_H
299
300
/* This is not the place to learn how to use libpng. The file libpng-manual.txt
301
* describes how to use libpng, and the file example.c summarizes it
302
* with some code on which to build. This file is useful for looking
303
* at the actual function definitions and structure components. If that
304
* file has been stripped from your copy of libpng, you can find it at
305
* <http://www.libpng.org/pub/png/libpng-manual.txt>
306
*
307
* If you just need to read a PNG file and don't want to read the documentation
308
* skip to the end of this file and read the section entitled 'simplified API'.
309
*/
310
311
/* Version information for png.h - this should match the version in png.c */
312
#define PNG_LIBPNG_VER_STRING "1.7.0beta90"
313
#define PNG_HEADER_VERSION_STRING " libpng version 1.7.0beta90 - August 28, 2017\n"
314
315
#define PNG_LIBPNG_VER_SONUM 17
316
#define PNG_LIBPNG_VER_DLLNUM 17
317
318
/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
319
#define PNG_LIBPNG_VER_MAJOR 1
320
#define PNG_LIBPNG_VER_MINOR 7
321
#define PNG_LIBPNG_VER_RELEASE 0
322
323
/* This should match the numeric part of the final component of
324
* PNG_LIBPNG_VER_STRING, omitting any leading zero:
325
*/
326
327
#define PNG_LIBPNG_VER_BUILD 90
328
329
/* Release Status */
330
#define PNG_LIBPNG_BUILD_ALPHA 1
331
#define PNG_LIBPNG_BUILD_BETA 2
332
#define PNG_LIBPNG_BUILD_RC 3
333
#define PNG_LIBPNG_BUILD_STABLE 4
334
#define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
335
336
/* Release-Specific Flags */
337
#define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
338
PNG_LIBPNG_BUILD_STABLE only */
339
#define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
340
PNG_LIBPNG_BUILD_SPECIAL */
341
#define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
342
PNG_LIBPNG_BUILD_PRIVATE */
343
344
#define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_BETA
345
346
/* Careful here. At one time, Guy wanted to use 082, but that would be octal.
347
* We must not include leading zeros.
348
* Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
349
* version 1.0.0 was mis-numbered 100 instead of 10000). From
350
* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release
351
*/
352
#define PNG_LIBPNG_VER 10700 /* 1.7.0 */
353
354
/* Library configuration: these options cannot be changed after
355
* the library has been built.
356
*/
357
#ifndef PNGLCONF_H
358
/* If pnglibconf.h is missing, you can
359
* copy scripts/pnglibconf.h.prebuilt to pnglibconf.h
360
*/
361
# include "pnglibconf.h"
362
#endif
363
364
#ifndef PNG_VERSION_INFO_ONLY
365
/* Machine specific configuration. */
366
# include "pngconf.h"
367
#endif
368
369
/*
370
* Added at libpng-1.2.8
371
*
372
* Ref MSDN: Private as priority over Special
373
* VS_FF_PRIVATEBUILD File *was not* built using standard release
374
* procedures. If this value is given, the StringFileInfo block must
375
* contain a PrivateBuild string.
376
*
377
* VS_FF_SPECIALBUILD File *was* built by the original company using
378
* standard release procedures but is a variation of the standard
379
* file of the same version number. If this value is given, the
380
* StringFileInfo block must contain a SpecialBuild string.
381
*/
382
383
#ifdef PNG_USER_PRIVATEBUILD /* From pnglibconf.h */
384
# define PNG_LIBPNG_BUILD_TYPE \
385
(PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
386
#else
387
# ifdef PNG_LIBPNG_SPECIALBUILD
388
# define PNG_LIBPNG_BUILD_TYPE \
389
(PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
390
# else
391
# define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
392
# endif
393
#endif
394
395
#ifndef PNG_VERSION_INFO_ONLY
396
397
/* Version information for C files, stored in png.c. This had better match
398
* the version above.
399
*/
400
#define png_libpng_ver png_get_header_ver(NULL)
401
402
/* This file is arranged in several sections:
403
*
404
* 1. ISO-PNG constants and definitions; values defined by PNG and not specific
405
* to the libpng API.
406
* 2. Any configuration options that can be specified by for the application
407
* code when it is built. (Build time configuration is in pnglibconf.h)
408
* 3. Type definitions (base types are defined in pngconf.h), structure
409
* definitions.
410
* 4. Exported library functions.
411
* 5. Simplified API.
412
* 6. Implementation options
413
*
414
* The library source code has additional files (principally pngpriv.h) that
415
* allow configuration of the library.
416
*/
417
418
/* Section 1: ISO PNG constants and macros. */
419
420
/* ISO-PNG defines byte encodings for 16 and 32-bit unsigned values and 32-bit
421
* signed values. The macros PNG_U16, PNG_U32 and PNG_S32 return values of type
422
* (png_uint_16), (png_uint_32) and (png_int_32) which are target machine
423
* specific representations of these values, using the types defined in
424
* pngconf.h. The macros take two or four byte values in the order in which
425
* they would occur in a PNG stream.
426
*
427
* These macros must return compile time constants if passed constant values -
428
* machine specific implementations are not permitted. These macros are used by
429
* default in the API functions/macros png_get_uint_16, png_get_uint_32,
430
* png_get_uint_31 and png_get_int_32 declared below: these functions or macros
431
* are the correct places for machine specific implementations (such as hardware
432
* specific instructions.)
433
*
434
* The macros defined here are generic and intended to give maximum flexibility
435
* in implementation to the compiler; only PNG_S32 contains a sequence point,
436
* there are no side effects and the expressions used permit the maximum
437
* parallelization (relevant because the four bytes may be loaded in parallel.)
438
*/
439
#define PNG_u2(b1, b2) (((unsigned int)(b1) << 8) + (b2))
440
441
#define PNG_U16(b1, b2) ((png_uint_16)/*SAFE*/PNG_u2(b1, b2))
442
#define PNG_U32(b1, b2, b3, b4)\
443
(((png_uint_32)/*SAFE*/PNG_u2(b1, b2) << 16) + PNG_u2(b3, b4))
444
445
/* ISO-PNG states that signed 32-bit values are stored in two's complement
446
* format. There is no guarantee that (png_int_32) is exactly 32 bits, so the
447
* following macro tests for a negative number and generates the machine format
448
* directly by portable arithmetic operations. The cost is that the argument
449
* 'b1' is evaluated twice.
450
*
451
* NOTE: the 0x7fffffffU BIC is there to ensure that potential overflow in the
452
* cast does not occur. This fixes the case where 1's complement machines could
453
* be forced into an overflow by an invalid value in the stream and, therefore,
454
* potentially raise an arithmetic exception; the invalid value is converted to
455
* 0 and any resultant problems will be caught later in the libpng checking.
456
*/
457
#define PNG_S32(b1, b2, b3, b4) ((b1) & 0x80\
458
? -(png_int_32)(((PNG_U32(b1, b2, b3, b4)^0xffffffffU)+1U)&0x7fffffffU)\
459
: (png_int_32)PNG_U32(b1, b2, b3, b4))
460
461
/* Constants for known chunk types.
462
*
463
* MAINTAINERS: If you need to add a chunk, define the name here.
464
* For historical reasons these constants have the form png_<name>; i.e.
465
* the prefix is lower case. Please use decimal values as the parameters to
466
* match the ISO PNG specification and to avoid relying on the C locale
467
* interpretation of character values. Please keep the list sorted.
468
*
469
* Notice that PNG_U32 is used to define a 32-bit value for the 4 byte chunk
470
* type. In fact the specification does not express chunk types this way,
471
* however using a 32-bit value means that the chunk type can be read from the
472
* stream using exactly the same code as used for a 32-bit unsigned value and
473
* can be examined far more efficiently (using one arithmetic compare).
474
*
475
* Prior to 1.5.6 the chunk type constants were expressed as C strings. The
476
* libpng API still uses strings for 'unknown' chunks and a macro,
477
* PNG_STRING_FROM_CHUNK, allows a string to be generated if required. Notice
478
* that for portable code numeric values must still be used; the string "IHDR"
479
* is not portable and neither is PNG_U32('I', 'H', 'D', 'R').
480
*
481
* In 1.7.0 the definitions were made public in png.h to avoid having to
482
* duplicate the same definitions in application code.
483
*
484
* SOURCE: http://www.libpng.org/pub/png/spec/register/
485
* "Register of PNG Public Chunks and Keywords, version 1.4.6"
486
* "Extensions to the PNG Specification, version 1.4.0"
487
*/
488
#define png_IDAT PNG_U32( 73, 68, 65, 84)
489
#define png_IEND PNG_U32( 73, 69, 78, 68)
490
#define png_IHDR PNG_U32( 73, 72, 68, 82)
491
#define png_PLTE PNG_U32( 80, 76, 84, 69)
492
#define png_bKGD PNG_U32( 98, 75, 71, 68)
493
#define png_cHRM PNG_U32( 99, 72, 82, 77)
494
#define png_dSIG PNG_U32(100, 83, 73, 71) /* separate spec */
495
#define png_fRAc PNG_U32(102, 82, 65, 99) /* registered, not defined */
496
#define png_gAMA PNG_U32(103, 65, 77, 65)
497
#define png_gIFg PNG_U32(103, 73, 70, 103)
498
#define png_gIFt PNG_U32(103, 73, 70, 116) /* deprecated */
499
#define png_gIFx PNG_U32(103, 73, 70, 120)
500
#define png_hIST PNG_U32(104, 73, 83, 84)
501
#define png_iCCP PNG_U32(105, 67, 67, 80)
502
#define png_iTXt PNG_U32(105, 84, 88, 116)
503
#define png_oFFs PNG_U32(111, 70, 70, 115)
504
#define png_pCAL PNG_U32(112, 67, 65, 76)
505
#define png_pHYs PNG_U32(112, 72, 89, 115)
506
#define png_sBIT PNG_U32(115, 66, 73, 84)
507
#define png_sCAL PNG_U32(115, 67, 65, 76)
508
#define png_sPLT PNG_U32(115, 80, 76, 84)
509
#define png_sRGB PNG_U32(115, 82, 71, 66)
510
#define png_sTER PNG_U32(115, 84, 69, 82)
511
#define png_tEXt PNG_U32(116, 69, 88, 116)
512
#define png_tIME PNG_U32(116, 73, 77, 69)
513
#define png_tRNS PNG_U32(116, 82, 78, 83)
514
#define png_zTXt PNG_U32(122, 84, 88, 116)
515
516
/* The following will work on (signed char*) strings, whereas the PNG_U32 macro
517
* used directory would fail on top-bit-set values because of the sign
518
* extension.
519
*/
520
#define PNG_CHUNK_FROM_STRING(s)\
521
PNG_U32(0xff&(s)[0], 0xff&(s)[1], 0xff&(s)[2], 0xff&(s)[3])
522
523
/* This uses (char), not (png_byte) to avoid warnings on systems where (char) is
524
* signed and the argument is a (char[]) This macro will fail miserably on
525
* systems where (char) is more than 8 bits.
526
*/
527
#define PNG_STRING_FROM_CHUNK(s,c)\
528
(void)(((char*)(s))[0]=(char)(((c)>>24) & 0xff), \
529
((char*)(s))[1]=(char)(((c)>>16) & 0xff),\
530
((char*)(s))[2]=(char)(((c)>>8) & 0xff), \
531
((char*)(s))[3]=(char)((c & 0xff)))
532
533
/* Do the same but terminate with a null character. */
534
#define PNG_CSTRING_FROM_CHUNK(s,c)\
535
(void)(PNG_STRING_FROM_CHUNK(s,c), ((char*)(s))[4] = 0)
536
537
/* Test on flag values as defined in the spec (section 5.4): */
538
#define PNG_CHUNK_ANCILLARY(c) (1 & ((c) >> 29))
539
#define PNG_CHUNK_CRITICAL(c) (!PNG_CHUNK_ANCILLARY(c))
540
#define PNG_CHUNK_PRIVATE(c) (1 & ((c) >> 21))
541
#define PNG_CHUNK_RESERVED(c) (1 & ((c) >> 13))
542
#define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >> 5))
543
544
/* Section 2: run time configuration
545
* See pnglibconf.h for build time configuration
546
*
547
* Run time configuration allows the application to choose between
548
* implementations of certain arithmetic APIs. The default is set
549
* at build time and recorded in pnglibconf.h, but it is safe to
550
* override these (and only these) settings. Note that this won't
551
* change what the library does, only application code, and the
552
* settings can (and probably should) be made on a per-file basis
553
* by setting the #defines before including png.h
554
*
555
* Use macros to read integers from PNG data or use the exported
556
* functions?
557
* PNG_USE_READ_MACROS: use the macros (see below) Note that
558
* the macros evaluate their argument multiple times.
559
* PNG_NO_USE_READ_MACROS: call the relevant library function.
560
*
561
* Use the alternative algorithm for compositing alpha samples that
562
* does not use division?
563
* PNG_READ_COMPOSITE_NODIV_SUPPORTED: use the 'no division'
564
* algorithm.
565
* PNG_NO_READ_COMPOSITE_NODIV: use the 'division' algorithm.
566
*
567
* How to handle benign errors if PNG_ALLOW_BENIGN_ERRORS is
568
* false?
569
* PNG_ALLOW_BENIGN_ERRORS: map calls to the benign error
570
* APIs to png_warning.
571
* Otherwise the calls are mapped to png_error.
572
*/
573
574
/* Inhibit C++ name-mangling for libpng functions but not for system calls. */
575
#ifdef __cplusplus
576
extern "C" {
577
#endif /* __cplusplus */
578
579
/* Section 3: type definitions, including structures and compile time
580
* constants.
581
* See pngconf.h for base types that vary by machine/system
582
*/
583
584
/* This triggers a compiler error in png.c, if png.c and png.h
585
* do not agree upon the version number.
586
*/
587
typedef char* png_libpng_version_1_7_0beta90;
588
589
/* Basic control structions. Read libpng-manual.txt or libpng.3 for more info.
590
*
591
* png_struct is the cache of information used while reading or writing a single
592
* PNG file. One of these is always required, although the simplified API
593
* (below) hides the creation and destruction of it.
594
*/
595
typedef struct png_struct_def png_struct;
596
typedef const png_struct * png_const_structp;
597
typedef png_struct * png_structp;
598
typedef png_struct * * png_structpp;
599
600
/* png_info contains information read from or to be written to a PNG file. One
601
* or more of these must exist while reading or creating a PNG file. The
602
* information is not used by libpng during read but is used to control what
603
* gets written when a PNG file is created. "png_get_" function calls read
604
* information during read and "png_set_" functions calls write information
605
* when creating a PNG.
606
* been moved into a separate header file that is not accessible to
607
* applications. Read libpng-manual.txt or libpng.3 for more info.
608
*/
609
typedef struct png_info_def png_info;
610
typedef png_info * png_infop;
611
typedef const png_info * png_const_infop;
612
typedef png_info * * png_infopp;
613
614
/* Types with names ending 'p' are pointer types. The corresponding types with
615
* names ending 'rp' are identical pointer types except that the pointer is
616
* marked 'restrict', which means that it is the only pointer to the object
617
* passed to the function. Applications should not use the 'restrict' types;
618
* it is always valid to pass 'p' to a pointer with a function argument of the
619
* corresponding 'rp' type. Different compilers have different rules with
620
* regard to type matching in the presence of 'restrict'. For backward
621
* compatibility libpng callbacks never have 'restrict' in their parameters and,
622
* consequentially, writing portable application code is extremely difficult if
623
* an attempt is made to use 'restrict'.
624
*/
625
typedef png_struct * PNG_RESTRICT png_structrp;
626
typedef const png_struct * PNG_RESTRICT png_const_structrp;
627
typedef png_info * PNG_RESTRICT png_inforp;
628
typedef const png_info * PNG_RESTRICT png_const_inforp;
629
630
/* Three color definitions. The order of the red, green, and blue, (and the
631
* exact size) is not important, although the size of the fields need to
632
* be png_byte or png_uint_16 (as defined below).
633
*/
634
typedef struct png_color_struct
635
{
636
png_byte red;
637
png_byte green;
638
png_byte blue;
639
} png_color;
640
typedef png_color * png_colorp;
641
typedef const png_color * png_const_colorp;
642
typedef png_color * * png_colorpp;
643
644
typedef struct png_color_16_struct
645
{
646
png_byte index; /* used for palette files */
647
png_uint_16 red; /* for use in red green blue files */
648
png_uint_16 green;
649
png_uint_16 blue;
650
png_uint_16 gray; /* for use in grayscale files */
651
} png_color_16;
652
typedef png_color_16 * png_color_16p;
653
typedef const png_color_16 * png_const_color_16p;
654
typedef png_color_16 * * png_color_16pp;
655
656
typedef struct png_color_8_struct
657
{
658
png_byte red; /* for use in red green blue files */
659
png_byte green;
660
png_byte blue;
661
png_byte gray; /* for use in grayscale files */
662
png_byte alpha; /* for alpha channel files */
663
} png_color_8;
664
typedef png_color_8 * png_color_8p;
665
typedef const png_color_8 * png_const_color_8p;
666
typedef png_color_8 * * png_color_8pp;
667
668
/*
669
* The following two structures are used for the in-core representation
670
* of sPLT chunks.
671
*/
672
typedef struct png_sPLT_entry_struct
673
{
674
png_uint_16 red;
675
png_uint_16 green;
676
png_uint_16 blue;
677
png_uint_16 alpha;
678
png_uint_16 frequency;
679
} png_sPLT_entry;
680
typedef png_sPLT_entry * png_sPLT_entryp;
681
typedef const png_sPLT_entry * png_const_sPLT_entryp;
682
typedef png_sPLT_entry * * png_sPLT_entrypp;
683
684
/* When the depth of the sPLT palette is 8 bits, the color and alpha samples
685
* occupy the LSB of their respective members, and the MSB of each member
686
* is zero-filled. The frequency member always occupies the full 16 bits.
687
*/
688
689
typedef struct png_sPLT_struct
690
{
691
png_charp name; /* palette name */
692
png_byte depth; /* depth of palette samples */
693
png_sPLT_entryp entries; /* palette entries */
694
png_int_32 nentries; /* number of palette entries */
695
} png_sPLT_t;
696
typedef png_sPLT_t * png_sPLT_tp;
697
typedef const png_sPLT_t * png_const_sPLT_tp;
698
typedef png_sPLT_t * * png_sPLT_tpp;
699
700
#ifdef PNG_TEXT_SUPPORTED
701
/* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file,
702
* and whether that contents is compressed or not. The "key" field
703
* points to a regular zero-terminated C string. The "text" fields can be a
704
* regular C string, an empty string, or a NULL pointer.
705
* However, the structure returned by png_get_text() will always contain
706
* the "text" field as a regular zero-terminated C string (possibly
707
* empty), never a NULL pointer, so it can be safely used in printf() and
708
* other string-handling functions. Note that the "itxt_length", "lang", and
709
* "lang_key" members of the structure only exist when the library is built
710
* with iTXt chunk support. Prior to libpng-1.4.0 the library was built by
711
* default without iTXt support. Also note that when iTXt *is* supported,
712
* the "lang" and "lang_key" fields contain NULL pointers when the
713
* "compression" field contains * PNG_TEXT_COMPRESSION_NONE or
714
* PNG_TEXT_COMPRESSION_zTXt. Note that the "compression value" is not the
715
* same as what appears in the PNG tEXt/zTXt/iTXt chunk's "compression flag"
716
* which is always 0 or 1, or its "compression method" which is always 0.
717
*
718
* The location field (added in libpng 1.7.0) records where the text chunk was
719
* found when png_get_text is used. When png_set_text is used the field in the
720
* structure passed in is ignored and, instead, the field is set to the current
721
* write position.
722
*
723
* Prior to 1.7.0 the write behavior was the same; the text fields were written
724
* (once) at the next write_info call, however the read mechanism did not record
725
* the chunk location so if an info_struct from read was passed to the write
726
* APIs the text chunks would all be written at the start (before PLTE).
727
*/
728
typedef struct png_text_struct
729
{
730
int compression; /* compression value:
731
-1: tEXt, none
732
0: zTXt, deflate
733
1: iTXt, none
734
2: iTXt, deflate */
735
png_byte location; /* 1: PNG_HAVE_IHDR
736
2: PNG_HAVE_PLTE
737
8: PNG_AFTER_IDAT */
738
png_charp key; /* keyword, 1-79 character description of "text" */
739
png_charp text; /* comment, may be an empty string (ie "")
740
or a NULL pointer */
741
size_t text_length; /* length of the text string */
742
size_t itxt_length; /* length of the itxt string */
743
png_charp lang; /* language code, 0-79 characters
744
or a NULL pointer */
745
png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
746
chars or a NULL pointer */
747
} png_text;
748
typedef png_text * png_textp;
749
typedef const png_text * png_const_textp;
750
typedef png_text * * png_textpp;
751
#endif
752
753
/* Supported compression types for text in PNG files (tEXt, and zTXt).
754
* The values of the PNG_TEXT_COMPRESSION_ defines should NOT be changed. */
755
#ifdef PNG_OLD_COMPRESSION_CODES_SUPPORTED
756
/* These values were used to prevent double write of text chunks in versions
757
* prior to 1.7.0. They are never set now; if you need them #define the
758
* _SUPPORTED macro.
759
*/
760
#define PNG_TEXT_COMPRESSION_NONE_WR -3
761
#define PNG_TEXT_COMPRESSION_zTXt_WR -2
762
#endif /* OLD_COMPRESSION_CODES */
763
#define PNG_TEXT_COMPRESSION_NONE -1
764
#define PNG_TEXT_COMPRESSION_zTXt 0
765
#define PNG_ITXT_COMPRESSION_NONE 1
766
#define PNG_ITXT_COMPRESSION_zTXt 2
767
#define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
768
769
/* png_time is a way to hold the time in an machine independent way.
770
* Two conversions are provided, both from time_t and struct tm. There
771
* is no portable way to convert to either of these structures, as far
772
* as I know. If you know of a portable way, send it to me. As a side
773
* note - PNG has always been Year 2000 compliant!
774
*/
775
typedef struct png_time_struct
776
{
777
png_uint_16 year; /* full year, as in, 1995 */
778
png_byte month; /* month of year, 1 - 12 */
779
png_byte day; /* day of month, 1 - 31 */
780
png_byte hour; /* hour of day, 0 - 23 */
781
png_byte minute; /* minute of hour, 0 - 59 */
782
png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
783
} png_time;
784
typedef png_time * png_timep;
785
typedef const png_time * png_const_timep;
786
typedef png_time * * png_timepp;
787
788
#if defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) ||\
789
defined(PNG_USER_CHUNKS_SUPPORTED)
790
/* png_unknown_chunk is a structure to hold queued chunks for which there is
791
* no specific support. The idea is that we can use this to queue
792
* up private chunks for output even though the library doesn't actually
793
* know about their semantics.
794
*
795
* The data in the structure is set by libpng on read and used on write.
796
*/
797
typedef struct png_unknown_chunk_t
798
{
799
png_byte *data; /* Data, should not be modified on read! */
800
png_uint_32 size; /* Size of data, must not exceed 0x7fffffff.
801
* API CHANGE 1.7.0: changed from 'size_t'
802
*/
803
png_byte name[5]; /* Textual chunk name with '\0' terminator */
804
805
/* On write 'location' must be set using the flag values listed below.
806
* Notice that on read it is set by libpng however the values stored have
807
* more bits set than are listed below. Always treat the value as a
808
* bitmask. On write set only one bit - setting multiple bits may cause the
809
* chunk to be written in multiple places.
810
*/
811
png_byte location; /* mode of operation at read time */
812
}
813
png_unknown_chunk;
814
815
typedef png_unknown_chunk * png_unknown_chunkp;
816
typedef const png_unknown_chunk * png_const_unknown_chunkp;
817
typedef png_unknown_chunk * * png_unknown_chunkpp;
818
#endif
819
820
/* Flag values for the chunk location byte. */
821
#define PNG_HAVE_IHDR 0x01U
822
#define PNG_HAVE_PLTE 0x02U
823
#define PNG_AFTER_IDAT 0x08U
824
825
/* Maximum positive integer used in PNG is (2^31)-1 */
826
#define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
827
#define PNG_UINT_32_MAX ((png_uint_32)(-1))
828
#define PNG_SIZE_MAX ((size_t)(-1))
829
830
/* These are constants for fixed point values encoded in the
831
* PNG specification manner (x100000)
832
*/
833
#define PNG_FP_1 100000
834
#define PNG_FP_HALF 50000
835
#define PNG_FP_MAX ((png_fixed_point)0x7fffffffL)
836
#define PNG_FP_MIN (-PNG_FP_MAX)
837
838
/* These describe the color_type field in png_info. */
839
/* color type masks */
840
#define PNG_COLOR_MASK_PALETTE 1U
841
#define PNG_COLOR_MASK_COLOR 2U
842
#define PNG_COLOR_MASK_ALPHA 4U
843
844
/* color types. Note that not all combinations are legal */
845
#define PNG_COLOR_TYPE_GRAY 0U
846
#define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
847
#define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
848
#define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
849
#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
850
/* aliases */
851
#define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
852
#define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
853
854
/* This is for compression type. PNG 1.0-1.2 only define the single type. */
855
#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
856
#define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
857
858
/* This is for filter method. PNG 1.0-1.2 only defines a single method.
859
*
860
* NOTE: CONFUSING NAME. The specification refers to a 'method', one of the
861
* defines below, and a 'type', one of the FILTER_VALUE defines.
862
* Historically libpng uses TYPE for 'method' and VALUE for 'type'.
863
*/
864
#define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
865
#define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
866
#define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
867
868
/* Filter values defined for method '0' (PNG_FILTER_TYPE_BASE) in the PNG
869
* specification.
870
*/
871
#define PNG_FILTER_VALUE_NONE 0
872
#define PNG_FILTER_VALUE_SUB 1
873
#define PNG_FILTER_VALUE_UP 2
874
#define PNG_FILTER_VALUE_AVG 3
875
#define PNG_FILTER_VALUE_PAETH 4
876
#define PNG_FILTER_VALUE_LAST 5 /* Not a valid value */
877
878
/* These are for the interlacing type. These values should NOT be changed. */
879
#define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
880
#define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
881
#define PNG_INTERLACE_LAST 2 /* Not a valid value */
882
883
/* These are for the oFFs chunk. These values should NOT be changed. */
884
#define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
885
#define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
886
#define PNG_OFFSET_LAST 2 /* Not a valid value */
887
888
/* These are for the pCAL chunk. These values should NOT be changed. */
889
#define PNG_EQUATION_LINEAR 0 /* Linear transformation */
890
#define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
891
#define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
892
#define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
893
#define PNG_EQUATION_LAST 4 /* Not a valid value */
894
895
/* These are for the sCAL chunk. These values should NOT be changed. */
896
#define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
897
#define PNG_SCALE_METER 1 /* meters per pixel */
898
#define PNG_SCALE_RADIAN 2 /* radians per pixel */
899
#define PNG_SCALE_LAST 3 /* Not a valid value */
900
901
/* These are for the pHYs chunk. These values should NOT be changed. */
902
#define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
903
#define PNG_RESOLUTION_METER 1 /* pixels/meter */
904
#define PNG_RESOLUTION_LAST 2 /* Not a valid value */
905
906
/* These are for the sRGB chunk. These values should NOT be changed. */
907
#define PNG_sRGB_INTENT_PERCEPTUAL 0
908
#define PNG_sRGB_INTENT_RELATIVE 1
909
#define PNG_sRGB_INTENT_SATURATION 2
910
#define PNG_sRGB_INTENT_ABSOLUTE 3
911
#define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
912
913
/* This is for text chunks */
914
#define PNG_KEYWORD_MAX_LENGTH 79
915
916
/* Maximum number of entries in PLTE/sPLT/tRNS arrays */
917
#define PNG_MAX_PALETTE_LENGTH 256
918
919
/* These determine if an ancillary chunk's data has been successfully read
920
* from the PNG header, or if the application has filled in the corresponding
921
* data in the info_struct to be written into the output file. The values
922
* of the PNG_INFO_<chunk> defines should NOT be changed.
923
*/
924
#define PNG_INFO_gAMA 0x0001U
925
#define PNG_INFO_sBIT 0x0002U
926
#define PNG_INFO_cHRM 0x0004U
927
#define PNG_INFO_PLTE 0x0008U
928
#define PNG_INFO_tRNS 0x0010U
929
#define PNG_INFO_bKGD 0x0020U
930
#define PNG_INFO_hIST 0x0040U
931
#define PNG_INFO_pHYs 0x0080U
932
#define PNG_INFO_oFFs 0x0100U
933
#define PNG_INFO_tIME 0x0200U
934
#define PNG_INFO_pCAL 0x0400U
935
#define PNG_INFO_sRGB 0x0800U /* GR-P, 0.96a */
936
#define PNG_INFO_iCCP 0x1000U /* ESR, 1.0.6 */
937
#define PNG_INFO_sPLT 0x2000U /* ESR, 1.0.6 */
938
#define PNG_INFO_sCAL 0x4000U /* ESR, 1.0.6 */
939
#define PNG_INFO_IDAT 0x8000U /* ESR, 1.0.6 */
940
941
/* This is used for the transformation routines, as some of them
942
* change these values for the row. It also should enable using
943
* the routines for other purposes.
944
*/
945
typedef struct png_row_info_struct
946
{
947
png_uint_32 width; /* width of row */
948
size_t rowbytes; /* number of bytes in row */
949
png_byte color_type; /* color type of row */
950
png_byte bit_depth; /* bit depth of row */
951
png_byte channels; /* number of channels (1, 2, 3, or 4) */
952
png_byte pixel_depth; /* bits per pixel (depth * channels) */
953
} png_row_info;
954
955
typedef png_row_info * png_row_infop;
956
typedef png_row_info * * png_row_infopp;
957
958
/* These are the function types for the I/O functions and for the functions
959
* that allow the user to override the default I/O functions with his or her
960
* own. The png_error_ptr type should match that of user-supplied warning
961
* and error functions, while the png_rw_ptr type should match that of the
962
* user read/write data functions. Note that the 'write' function must not
963
* modify the buffer it is passed. The 'read' function, on the other hand, is
964
* expected to return the read data in the buffer.
965
*/
966
typedef PNG_CALLBACK(void, *png_error_ptr, (png_structp, png_const_charp));
967
typedef PNG_CALLBACK(void, *png_rw_ptr, (png_structp, png_bytep, size_t));
968
typedef PNG_CALLBACK(void, *png_flush_ptr, (png_structp));
969
typedef PNG_CALLBACK(void, *png_read_status_ptr, (png_structp, png_uint_32,
970
int));
971
typedef PNG_CALLBACK(void, *png_write_status_ptr, (png_structp, png_uint_32,
972
int));
973
974
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
975
typedef PNG_CALLBACK(void, *png_progressive_info_ptr, (png_structp, png_infop));
976
typedef PNG_CALLBACK(void, *png_progressive_end_ptr, (png_structp, png_infop));
977
978
/* WARNING: the API for this callback is poorly documented and produces
979
* unexpected results when dealing with interlaced images. For non-interlaced
980
* images the parameters are straightforward:
981
*
982
* next_row: a pointer to the transformed row read from the PNG input
983
* stream, it has png_get_image_width() pixels.
984
* row_y: the y ordinate of the image; 0..png_get_image_height()-1
985
* pass: 0
986
*
987
* For interlaced images if png_set_interlace_handling has been called (libpng
988
* does *not* call this itself) the parameters are the same except that the
989
* pass will be the pass in the range 0..6 (NOTE: one less than the PNG spec)
990
* and 'next_row' will be NULL if (and only if) the row does not contribute
991
* to the output in 'blocky' display mode.
992
*
993
* pass: 0..6
994
*
995
* If 'next_row' is not NULL it is necessary for the application to combine the
996
* pixels with the output. This can most easily be done by calling
997
* png_progressive_combine_row(). Note that the 'next_row' data cannot be
998
* changed; even though the value is passed to png_progressive_combine_row the
999
* pointer is not used, it is just a flag , if it is NULL nothing will happen.
1000
*
1001
* If png_set_interlace_handling has not been called the callback only gets
1002
* called for original PNG interlaced row:
1003
*
1004
* row_y: the y ordinate in the pass; 0..PNG_PASS_ROWS()-1
1005
*
1006
* What is more if PNG_PASS_COLS() is 0 the entire pass will be skipped. The
1007
* row data is not full width and there is no guarantee that the buffer passed
1008
* in 'next_row' is able to accomodate the full width of output pixels, however
1009
* 'next_row' will never be NULL.
1010
*
1011
* Use PNG_ROW_FROM_PASS_ROW(row_y, pass) and PNG_COL_FROM_PASS_COL(col, pass)
1012
* to find the output pixel (x,y) given an interlaced sub-image pixel
1013
* (row_y,col,pass). (See below for these macros.)
1014
*
1015
* Note that in this latter case if you want to do the 'blocky' display update
1016
* method you have to work out all the details yourself with regard to which
1017
* pixels to set for each row and whether to replicate it to the following
1018
* rows of the image.
1019
*/
1020
typedef PNG_CALLBACK(void, *png_progressive_row_ptr, (png_structp,
1021
png_bytep next_row, png_uint_32 row_y, int pass));
1022
#endif
1023
1024
#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
1025
typedef PNG_CALLBACK(void, *png_user_transform_ptr, (png_structp, png_row_infop,
1026
png_bytep));
1027
#endif
1028
1029
#ifdef PNG_USER_CHUNKS_SUPPORTED
1030
typedef PNG_CALLBACK(int, *png_user_chunk_ptr, (png_structp,
1031
png_unknown_chunkp));
1032
#endif
1033
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
1034
/* not used anywhere */
1035
/* typedef PNG_CALLBACK(void, *png_unknown_chunk_ptr, (png_structp)); */
1036
#endif
1037
1038
#ifdef PNG_SETJMP_SUPPORTED
1039
/* This must match the function definition in <setjmp.h>, and the application
1040
* must include this before png.h to obtain the definition of jmp_buf. The
1041
* function is required to be PNG_NORETURN, but this is not checked. If the
1042
* function does return the application will crash via an abort() or similar
1043
* system level call.
1044
*
1045
* If you get a warning here while building the library you may need to make
1046
* changes to ensure that pnglibconf.h records the calling convention used by
1047
* your compiler. This may be very difficult - try using a different compiler
1048
* to build the library!
1049
*/
1050
PNG_FUNCTION(void, (PNGCAPI *png_longjmp_ptr), PNGARG((jmp_buf, int)), typedef);
1051
#endif
1052
1053
/* Transform masks for the high-level interface */
1054
#define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
1055
#define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
1056
#define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
1057
#define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
1058
#define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
1059
#define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
1060
#define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
1061
#define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
1062
#define PNG_TRANSFORM_BGR 0x0080 /* read and write */
1063
#define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
1064
#define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
1065
#define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
1066
#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* write only */
1067
/* Added to libpng-1.2.34 */
1068
#define PNG_TRANSFORM_STRIP_FILLER_BEFORE PNG_TRANSFORM_STRIP_FILLER
1069
#define PNG_TRANSFORM_STRIP_FILLER_AFTER 0x1000 /* write only */
1070
/* Added to libpng-1.4.0 */
1071
#define PNG_TRANSFORM_GRAY_TO_RGB 0x2000 /* read only */
1072
/* Added to libpng-1.5.4 */
1073
#define PNG_TRANSFORM_EXPAND_16 0x4000 /* read only */
1074
#define PNG_TRANSFORM_SCALE_16 0x8000 /* read only */
1075
1076
/* Flags for MNG supported features */
1077
#define PNG_FLAG_MNG_EMPTY_PLTE 0x01
1078
#define PNG_FLAG_MNG_FILTER_64 0x04
1079
#define PNG_ALL_MNG_FEATURES 0x05
1080
1081
/* NOTE: prior to 1.5 these functions had no 'API' style declaration,
1082
* this allowed the zlib default functions to be used on Windows
1083
* platforms. In 1.5 the zlib default malloc (which just calls malloc and
1084
* ignores the first argument) should be completely compatible with the
1085
* following.
1086
*/
1087
typedef PNG_CALLBACK(png_voidp, *png_malloc_ptr, (png_structp,
1088
png_alloc_size_t));
1089
typedef PNG_CALLBACK(void, *png_free_ptr, (png_structp, png_voidp));
1090
1091
/* Section 4: exported functions
1092
* Here are the function definitions most commonly used. This is not
1093
* the place to find out how to use libpng. See libpng-manual.txt for the
1094
* full explanation, see example.c for the summary. This just provides
1095
* a simple one line description of the use of each function.
1096
*
1097
* The PNG_EXPORT() and PNG_EXPORTA() macros used below are defined in
1098
* pngconf.h and in the *.dfn files in the scripts directory.
1099
*
1100
* PNG_EXPORT(ordinal, type, name, (args));
1101
*
1102
* ordinal: ordinal that is used while building
1103
* *.def files. The ordinal value is only
1104
* relevant when preprocessing png.h with
1105
* the *.dfn files for building symbol table
1106
* entries, and are removed by pngconf.h.
1107
* type: return type of the function
1108
* name: function name
1109
* args: function arguments, with types
1110
*
1111
* When we wish to append attributes to a function prototype we use
1112
* the PNG_EXPORTA() macro instead.
1113
*
1114
* PNG_EXPORTA(ordinal, type, name, (args), attributes);
1115
*
1116
* ordinal, type, name, and args: same as in PNG_EXPORT().
1117
* attributes: function attributes
1118
*/
1119
1120
/* Returns the version number of the library */
1121
PNG_EXPORT(1, png_uint_32, png_access_version_number, (void));
1122
1123
/* Tell lib we have already handled the first <num_bytes> magic bytes.
1124
* Handling more than 8 bytes from the beginning of the file is an error.
1125
*/
1126
PNG_EXPORT(2, void, png_set_sig_bytes, (png_structrp png_ptr, int num_bytes));
1127
1128
/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a
1129
* PNG file. Returns zero if the supplied bytes match the 8-byte PNG
1130
* signature, and non-zero otherwise. Having num_to_check == 0 or
1131
* start > 7 will always fail (ie return non-zero).
1132
*/
1133
PNG_EXPORT(3, int, png_sig_cmp, (png_const_bytep sig, size_t start,
1134
size_t num_to_check));
1135
1136
/* Simple signature checking function. This is the same as calling
1137
* png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n).
1138
*/
1139
#define png_check_sig(sig, n) !png_sig_cmp((sig), 0, (n))
1140
1141
/* Allocate and initialize png_ptr struct for reading, and any other memory. */
1142
PNG_EXPORTA(4, png_structp, png_create_read_struct,
1143
(png_const_charp user_png_ver, png_voidp error_ptr,
1144
png_error_ptr error_fn, png_error_ptr warn_fn),
1145
PNG_ALLOCATED);
1146
1147
/* Allocate and initialize png_ptr struct for writing, and any other memory */
1148
PNG_EXPORTA(5, png_structp, png_create_write_struct,
1149
(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,
1150
png_error_ptr warn_fn),
1151
PNG_ALLOCATED);
1152
1153
/* These APIs control the size of the buffer used for reading IDAT chunks in the
1154
* sequential read code and the size of the IDAT chunks produced when writing.
1155
* They have no effect on the progressive read code. In both read and write
1156
* cases it will be necessary to allocate at least this amount of buffer space.
1157
* The default value is PNG_IDAT_READ_SIZE on read and PNG_ZBUF_SIZE on write.
1158
*
1159
* The valid range is 1..0x7FFFFFFF on write and 1..max(uInt) on read, where
1160
* uInt is the type declared by zlib.h. On write setting the largest value will
1161
* typically cause the PNG image data to be written in one chunk; this gives the
1162
* smallest PNG and has little or no effect on applications that read the PNG.
1163
*
1164
* DEPRECATED: use png_set_IDAT_size on write and png_set_read_buffer_size on
1165
* read.
1166
*/
1167
PNG_EXPORTA(6, png_alloc_size_t, png_get_compression_buffer_size,
1168
(png_const_structrp png_ptr), PNG_DEPRECATED);
1169
PNG_EXPORTA(7, void, png_set_compression_buffer_size, (png_structrp png_ptr,
1170
png_alloc_size_t size), PNG_DEPRECATED);
1171
#define png_set_read_buffer_size(p,size) (png_setting((p),\
1172
PNG_SR_COMPRESS_buffer_size, (size), 0))
1173
/* The size of the buffer used while processing compressed data, both single
1174
* chunk data (zTXt, iTXt, iCCP) and IDAT data. With IDAT data in libpng 1.7
1175
* IDATs are read until the end or until the buffer is full; this means that
1176
* you can optimize the buffer size for the particular memory behavior of
1177
* your system and, possibly, your application.
1178
*
1179
* NOTE: the result (on success) is 0, which is actually an invalid value.
1180
* Retrieving the current value is not possible.
1181
*/
1182
1183
/* Moved from pngconf.h in 1.4.0 and modified to ensure setjmp/longjmp
1184
* match up.
1185
*/
1186
#ifdef PNG_SETJMP_SUPPORTED
1187
/* This function returns the jmp_buf built in to *png_ptr. It must be
1188
* supplied with an appropriate 'longjmp' function to use on that jmp_buf
1189
* unless the default error function is overridden in which case NULL is
1190
* acceptable. The size of the jmp_buf is checked against the actual size
1191
* allocated by the library - the call will return NULL on a mismatch
1192
* indicating an ABI mismatch.
1193
*/
1194
PNG_EXPORT(8, jmp_buf*, png_set_longjmp_fn, (png_structrp png_ptr,
1195
png_longjmp_ptr longjmp_fn, size_t jmp_buf_size));
1196
# define png_jmpbuf(png_ptr) \
1197
(*png_set_longjmp_fn((png_ptr), longjmp, (sizeof (jmp_buf))))
1198
#else
1199
# define png_jmpbuf(png_ptr) \
1200
(LIBPNG_WAS_COMPILED_WITH__PNG_NO_SETJMP)
1201
#endif
1202
/* This function should be used by libpng applications in place of
1203
* longjmp(png_ptr->jmpbuf, val). If longjmp_fn() has been set, it
1204
* will use it; otherwise it will call PNG_ABORT(). This function was
1205
* added in libpng-1.5.0.
1206
*/
1207
PNG_EXPORTA(9, void, png_longjmp, (png_const_structrp png_ptr, int val),
1208
PNG_NORETURN);
1209
1210
#ifdef PNG_READ_SUPPORTED
1211
/* Reset the compression stream -- Removed from libpng-1.7.0 */
1212
PNG_REMOVED(10, int, png_reset_zstream, (png_structrp png_ptr), PNG_DEPRECATED)
1213
#endif
1214
1215
/* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */
1216
#ifdef PNG_USER_MEM_SUPPORTED
1217
PNG_EXPORTA(11, png_structp, png_create_read_struct_2,
1218
(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,
1219
png_error_ptr warn_fn,
1220
png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn),
1221
PNG_ALLOCATED);
1222
PNG_EXPORTA(12, png_structp, png_create_write_struct_2,
1223
(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,
1224
png_error_ptr warn_fn,
1225
png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn),
1226
PNG_ALLOCATED);
1227
#endif
1228
1229
/* Write the PNG file signature. */
1230
PNG_EXPORT(13, void, png_write_sig, (png_structrp png_ptr));
1231
1232
/* Write a PNG chunk - size, type, (optional) data, CRC. */
1233
PNG_EXPORT(14, void, png_write_chunk, (png_structrp png_ptr,
1234
png_const_bytep chunk_name, png_const_voidp data, size_t length));
1235
1236
/* Write the start of a PNG chunk - length and chunk name. */
1237
PNG_EXPORT(15, void, png_write_chunk_start, (png_structrp png_ptr,
1238
png_const_bytep chunk_name, png_uint_32 length));
1239
1240
/* Write the data of a PNG chunk started with png_write_chunk_start(). */
1241
PNG_EXPORT(16, void, png_write_chunk_data, (png_structrp png_ptr,
1242
png_const_voidp data, size_t length));
1243
1244
/* Finish a chunk started with png_write_chunk_start() (includes CRC). */
1245
PNG_EXPORT(17, void, png_write_chunk_end, (png_structrp png_ptr));
1246
1247
/* Allocate and initialize the info structure */
1248
PNG_EXPORTA(18, png_infop, png_create_info_struct, (png_const_structrp png_ptr),
1249
PNG_ALLOCATED);
1250
1251
/* Removed from libpng-1.7.0 */
1252
PNG_REMOVED(19, void, png_info_init_3, (png_infopp info_ptr,
1253
size_t png_info_struct_size), PNG_DEPRECATED)
1254
1255
/* Writes all the PNG information before the image. */
1256
PNG_EXPORT(20, void, png_write_info_before_PLTE,
1257
(png_structrp png_ptr, png_const_inforp info_ptr));
1258
PNG_EXPORT(21, void, png_write_info,
1259
(png_structrp png_ptr, png_const_inforp info_ptr));
1260
1261
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1262
/* Read the information before the actual image data. */
1263
PNG_EXPORT(22, void, png_read_info,
1264
(png_structrp png_ptr, png_inforp info_ptr));
1265
#endif
1266
1267
#ifdef PNG_TIME_RFC1123_SUPPORTED
1268
/* Convert to a US string format: there is no localization support in this
1269
* routine. The original implementation used a 29 character buffer in
1270
* png_struct, this has been removed (in libpng 1.7.0).
1271
*/
1272
PNG_REMOVED(23, png_const_charp, png_convert_to_rfc1123, (png_structrp png_ptr,
1273
png_const_timep ptime),PNG_DEPRECATED)
1274
PNG_EXPORT(241, int, png_convert_to_rfc1123_buffer, (char out[29],
1275
png_const_timep ptime));
1276
#endif
1277
1278
#ifdef PNG_CONVERT_tIME_SUPPORTED
1279
/* Convert from a struct tm to png_time */
1280
PNG_EXPORT(24, PNG_DEPRECATED void, png_convert_from_struct_tm,
1281
(png_timep ptime, const struct tm * ttime));
1282
1283
/* Convert from time_t to png_time. Uses gmtime() */
1284
PNG_EXPORT(25, PNG_DEPRECATED void, png_convert_from_time_t, (png_timep ptime,
1285
time_t ttime));
1286
#endif /* CONVERT_tIME */
1287
1288
#ifdef PNG_READ_EXPAND_SUPPORTED
1289
/* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */
1290
PNG_EXPORT(26, void, png_set_expand, (png_structrp png_ptr));
1291
PNG_EXPORT(27, void, png_set_expand_gray_1_2_4_to_8, (png_structrp png_ptr));
1292
PNG_EXPORT(28, void, png_set_palette_to_rgb, (png_structrp png_ptr));
1293
PNG_EXPORT(29, void, png_set_tRNS_to_alpha, (png_structrp png_ptr));
1294
#endif
1295
1296
#ifdef PNG_READ_EXPAND_16_SUPPORTED
1297
/* Expand to 16-bit channels, forces conversion of palette to RGB and expansion
1298
* of a tRNS chunk if present.
1299
*/
1300
PNG_EXPORT(221, void, png_set_expand_16, (png_structrp png_ptr));
1301
#endif
1302
1303
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
1304
/* Use blue, green, red order for pixels. */
1305
PNG_EXPORT(30, void, png_set_bgr, (png_structrp png_ptr));
1306
#endif
1307
1308
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
1309
/* Expand the grayscale to 24-bit RGB if necessary. */
1310
PNG_EXPORT(31, void, png_set_gray_to_rgb, (png_structrp png_ptr));
1311
#endif
1312
1313
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1314
/* Reduce RGB to grayscale. */
1315
#define PNG_ERROR_ACTION_NO_CHECK 0
1316
#define PNG_ERROR_ACTION_NONE 1
1317
#define PNG_ERROR_ACTION_WARN 2
1318
#define PNG_ERROR_ACTION_ERROR 3
1319
#define PNG_RGB_TO_GRAY_DEFAULT (-1)/*for red/green coefficients*/
1320
1321
PNG_FP_EXPORT(32, void, png_set_rgb_to_gray, (png_structrp png_ptr,
1322
int error_action, double red, double green))
1323
PNG_FIXED_EXPORT(33, void, png_set_rgb_to_gray_fixed, (png_structrp png_ptr,
1324
int error_action, png_fixed_point red, png_fixed_point green))
1325
/* Convert RGB pixels to gray (CIE Y) values, the red and green value must be
1326
* less than or equal to 1, if either is negative a set of defaults
1327
* corresponding to the sRGB standard are used.
1328
*
1329
* The error action specifies whether to check for r==g==b in each pixel, if
1330
* it is 0 (PNG_ERROR_ACTION_NO_CHECK; added in libpng 1.7.0) no check will
1331
* be performed, otherwise a check is performed and the result can be
1332
* retrieved using png_get_rgb_to_gray_status (which just returns a
1333
* true if a non-gray pixel was encountered).
1334
*
1335
* Pass PNG_ERROR_ACTION_ERROR if you are confident that the image only
1336
* contains gray pixels (you have already checked); the check is still
1337
* performed but a very optimized code path is used for RGB to gray
1338
* convertion.
1339
*
1340
* If you want to extract a single channel pass PNG_FP_1 for the coefficient
1341
* for that channel and 0 for the rest (0 for both red and green to extract
1342
* blue).
1343
*
1344
* NOTE: the default coefficients used if negative values are passed for red
1345
* or green are based on the cHRM chunk if available, otherwise sRGB. The
1346
* calculation returns the Y (luminance value) corresponding to the white
1347
* point of the PNG. UNLESS THE WHITE POINT IS D50 THIS IS NOT A CIEXYZ Y
1348
* VALUE. It is the luminance of the pixel perceived by a viewer completely
1349
* adapted to the white point of the PNG, this may not be what you want
1350
* because to interpret it you have to also record the white point of the
1351
* PNG. To obtain CIEXYZ Y values read the cHRM chunk XYZ values and
1352
* chromatically adapt them to D50
1353
*/
1354
1355
PNG_EXPORT(34, png_byte, png_get_rgb_to_gray_status, (png_const_structrp
1356
png_ptr));
1357
#endif
1358
1359
#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED
1360
PNG_EXPORT(35, void, png_build_grayscale_palette, (int bit_depth,
1361
png_colorp palette));
1362
#endif
1363
1364
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
1365
/* How the alpha channel is interpreted - this affects how the color channels
1366
* of a PNG file are returned to the calling application when an alpha channel,
1367
* or a tRNS chunk in a palette file, is present.
1368
*
1369
* This has no effect on the way pixels are written into a PNG output
1370
* datastream. The color samples in a PNG datastream are never premultiplied
1371
* with the alpha samples.
1372
*
1373
* The default is to return data according to the PNG specification: the alpha
1374
* channel is a linear measure of the contribution of the pixel to the
1375
* corresponding composited pixel, and the color channels are unassociated
1376
* (not premultiplied). The gamma encoded color channels must be scaled
1377
* according to the contribution and to do this it is necessary to undo
1378
* the encoding, scale the color values, perform the composition and reencode
1379
* the values. This is the 'PNG' mode.
1380
*
1381
* The alternative is to 'associate' the alpha with the color information by
1382
* storing color channel values that have been scaled by the alpha.
1383
* image. These are the 'STANDARD', 'ASSOCIATED' or 'PREMULTIPLIED' modes
1384
* (the latter being the two common names for associated alpha color channels).
1385
*
1386
* For the 'OPTIMIZED' mode, a pixel is treated as opaque only if the alpha
1387
* value is equal to the maximum value.
1388
*
1389
* The final choice is to gamma encode the alpha channel as well. This is
1390
* broken because, in practice, no implementation that uses this choice
1391
* correctly undoes the encoding before handling alpha composition. Use this
1392
* choice only if other serious errors in the software or hardware you use
1393
* mandate it; the typical serious error is for dark halos to appear around
1394
* opaque areas of the composited PNG image because of arithmetic overflow.
1395
*
1396
* The API function png_set_alpha_mode specifies which of these choices to use
1397
* with an enumerated 'mode' value and the gamma of the required output:
1398
*/
1399
#define PNG_ALPHA_PNG 0 /* according to the PNG standard */
1400
#define PNG_ALPHA_STANDARD 1 /* according to Porter/Duff */
1401
#define PNG_ALPHA_ASSOCIATED 1 /* as above; this is the normal practice */
1402
#define PNG_ALPHA_PREMULTIPLIED 1 /* as above */
1403
#define PNG_ALPHA_OPTIMIZED 2 /* 'PNG' for opaque pixels, else 'STANDARD' */
1404
#define PNG_ALPHA_BROKEN 3 /* the alpha channel is gamma encoded */
1405
1406
PNG_FP_EXPORT(227, void, png_set_alpha_mode, (png_structrp png_ptr, int mode,
1407
double output_gamma))
1408
PNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structrp png_ptr,
1409
int mode, png_fixed_point output_gamma))
1410
#endif
1411
1412
#if defined(PNG_GAMMA_SUPPORTED) || defined(PNG_READ_ALPHA_MODE_SUPPORTED)
1413
/* The output_gamma value is a screen gamma in libpng terminology: it expresses
1414
* how to decode the output values, not how they are encoded.
1415
*/
1416
#define PNG_DEFAULT_sRGB -1 /* sRGB gamma and color space */
1417
#define PNG_GAMMA_MAC_18 -2 /* Old Mac '1.8' gamma and color space */
1418
#define PNG_GAMMA_sRGB 220000 /* Television standards--matches sRGB gamma */
1419
#define PNG_GAMMA_LINEAR PNG_FP_1 /* Linear */
1420
#endif
1421
1422
/* The following are examples of calls to png_set_alpha_mode to achieve the
1423
* required overall gamma correction and, where necessary, alpha
1424
* premultiplication.
1425
*
1426
* png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB);
1427
* This is the default libpng handling of the alpha channel - it is not
1428
* pre-multiplied into the color components. In addition the call states
1429
* that the output is for a sRGB system and causes all PNG files without gAMA
1430
* chunks to be assumed to be encoded using sRGB.
1431
*
1432
* png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC);
1433
* In this case the output is assumed to be something like an sRGB conformant
1434
* display preceeded by a power-law lookup table of power 1.45. This is how
1435
* early Mac systems behaved.
1436
*
1437
* png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_GAMMA_LINEAR);
1438
* This is the classic Jim Blinn approach and will work in academic
1439
* environments where everything is done by the book. It has the shortcoming
1440
* of assuming that input PNG data with no gamma information is linear - this
1441
* is unlikely to be correct unless the PNG files where generated locally.
1442
* Most of the time the output precision will be so low as to show
1443
* significant banding in dark areas of the image.
1444
*
1445
* png_set_expand_16(pp);
1446
* png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_DEFAULT_sRGB);
1447
* This is a somewhat more realistic Jim Blinn inspired approach. PNG files
1448
* are assumed to have the sRGB encoding if not marked with a gamma value and
1449
* the output is always 16 bits per component. This permits accurate scaling
1450
* and processing of the data. If you know that your input PNG files were
1451
* generated locally you might need to replace PNG_DEFAULT_sRGB with the
1452
* correct value for your system.
1453
*
1454
* png_set_alpha_mode(pp, PNG_ALPHA_OPTIMIZED, PNG_DEFAULT_sRGB);
1455
* If you just need to composite the PNG image onto an existing background
1456
* and if you control the code that does this you can use the optimization
1457
* setting. In this case you just copy completely opaque pixels to the
1458
* output. For pixels that are not completely transparent (you just skip
1459
* those) you do the composition math using png_composite or png_composite_16
1460
* below then encode the resultant 8-bit or 16-bit values to match the output
1461
* encoding.
1462
*
1463
* Other cases
1464
* If neither the PNG nor the standard linear encoding work for you because
1465
* of the software or hardware you use then you have a big problem. The PNG
1466
* case will probably result in halos around the image. The linear encoding
1467
* will probably result in a washed out, too bright, image (it's actually too
1468
* contrasty.) Try the ALPHA_OPTIMIZED mode above - this will probably
1469
* substantially reduce the halos. Alternatively try:
1470
*
1471
* png_set_alpha_mode(pp, PNG_ALPHA_BROKEN, PNG_DEFAULT_sRGB);
1472
* This option will also reduce the halos, but there will be slight dark
1473
* halos round the opaque parts of the image where the background is light.
1474
* In the OPTIMIZED mode the halos will be light halos where the background
1475
* is dark. Take your pick - the halos are unavoidable unless you can get
1476
* your hardware/software fixed! (The OPTIMIZED approach is slightly
1477
* faster.)
1478
*
1479
* When the default gamma of PNG files doesn't match the output gamma.
1480
* If you have PNG files with no gamma information png_set_alpha_mode allows
1481
* you to provide a default gamma, but it also sets the ouput gamma to the
1482
* matching value. If you know your PNG files have a gamma that doesn't
1483
* match the output you can take advantage of the fact that
1484
* png_set_alpha_mode always sets the output gamma but only sets the PNG
1485
* default if it is not already set:
1486
*
1487
* png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB);
1488
* png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC);
1489
* The first call sets both the default and the output gamma values, the
1490
* second call overrides the output gamma without changing the default. This
1491
* is easier than achieving the same effect with png_set_gamma. You must use
1492
* PNG_ALPHA_PNG for the first call - internal checking in png_set_alpha will
1493
* fire if more than one call to png_set_alpha_mode and png_set_background is
1494
* made in the same read operation, however multiple calls with PNG_ALPHA_PNG
1495
* are ignored.
1496
*/
1497
1498
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
1499
PNG_EXPORT(36, void, png_set_strip_alpha, (png_structrp png_ptr));
1500
#endif
1501
1502
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
1503
defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
1504
PNG_EXPORT(37, void, png_set_swap_alpha, (png_structrp png_ptr));
1505
#endif
1506
1507
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
1508
defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
1509
PNG_EXPORT(38, void, png_set_invert_alpha, (png_structrp png_ptr));
1510
#endif
1511
1512
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
1513
/* Add a filler byte to 8-bit Gray or 24-bit RGB images. */
1514
PNG_EXPORT(39, void, png_set_filler, (png_structrp png_ptr, png_uint_32 filler,
1515
int flags));
1516
/* The values of the PNG_FILLER_ defines should NOT be changed */
1517
# define PNG_FILLER_BEFORE 0
1518
# define PNG_FILLER_AFTER 1
1519
/* Add an alpha byte to 8-bit Gray or 24-bit RGB images. */
1520
PNG_EXPORT(40, void, png_set_add_alpha, (png_structrp png_ptr,
1521
png_uint_32 filler, int flags));
1522
#endif /* READ_FILLER || WRITE_FILLER */
1523
1524
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
1525
/* Swap bytes in 16-bit depth files. */
1526
PNG_EXPORT(41, void, png_set_swap, (png_structrp png_ptr));
1527
#endif
1528
1529
#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
1530
/* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */
1531
PNG_EXPORT(42, void, png_set_packing, (png_structrp png_ptr));
1532
#endif
1533
1534
#if defined(PNG_READ_PACKSWAP_SUPPORTED) || \
1535
defined(PNG_WRITE_PACKSWAP_SUPPORTED)
1536
/* Swap packing order of pixels in bytes. */
1537
PNG_EXPORT(43, void, png_set_packswap, (png_structrp png_ptr));
1538
#endif
1539
1540
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
1541
/* Converts files to legal bit depths. */
1542
PNG_EXPORT(44, void, png_set_shift, (png_structrp png_ptr, png_const_color_8p
1543
true_bits));
1544
#endif
1545
1546
#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
1547
defined(PNG_WRITE_INTERLACING_SUPPORTED)
1548
/* Have the code handle the interlacing. Returns the number of passes.
1549
* MUST be called before png_read_update_info or png_start_read_image,
1550
* otherwise it will not have the desired effect. Note that it is still
1551
* necessary to call png_read_row or png_read_rows png_get_image_height
1552
* times for each pass.
1553
*/
1554
PNG_EXPORT(45, int, png_set_interlace_handling, (png_structrp png_ptr));
1555
#endif
1556
1557
#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
1558
/* Invert monochrome files */
1559
PNG_EXPORT(46, void, png_set_invert_mono, (png_structrp png_ptr));
1560
#endif
1561
1562
#ifdef PNG_READ_BACKGROUND_SUPPORTED
1563
/* Handle alpha and tRNS by replacing with a background color. Prior to
1564
* libpng-1.5.4 this API must not be called before the PNG file header has been
1565
* read. Doing so will result in unexpected behavior and possible warnings or
1566
* errors if the PNG file contains a bKGD chunk.
1567
*/
1568
PNG_FP_EXPORT(47, void, png_set_background, (png_structrp png_ptr,
1569
png_const_color_16p background_color, int background_gamma_code,
1570
int need_expand, double background_gamma))
1571
PNG_FIXED_EXPORT(215, void, png_set_background_fixed, (png_structrp png_ptr,
1572
png_const_color_16p background_color, int background_gamma_code,
1573
int need_expand, png_fixed_point background_gamma))
1574
#endif
1575
#ifdef PNG_READ_BACKGROUND_SUPPORTED
1576
# define PNG_BACKGROUND_GAMMA_UNKNOWN 0
1577
# define PNG_BACKGROUND_GAMMA_SCREEN 1
1578
# define PNG_BACKGROUND_GAMMA_FILE 2
1579
# define PNG_BACKGROUND_GAMMA_UNIQUE 3
1580
#endif
1581
1582
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
1583
/* Scale a 16-bit depth file down to 8-bit, accurately. */
1584
PNG_EXPORT(229, void, png_set_scale_16, (png_structrp png_ptr));
1585
#endif
1586
1587
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
1588
#define PNG_READ_16_TO_8_SUPPORTED /* Name prior to 1.5.4 */
1589
/* Strip the second byte of information from a 16-bit depth file. */
1590
PNG_EXPORT(48, void, png_set_strip_16, (png_structrp png_ptr));
1591
#endif
1592
1593
#ifdef PNG_READ_QUANTIZE_SUPPORTED
1594
/* Turn on quantizing, and reduce the palette to the number of colors
1595
* available.
1596
*/
1597
PNG_EXPORT(49, void, png_set_quantize, (png_structrp png_ptr,
1598
png_colorp palette, int num_palette, int maximum_colors,
1599
png_const_uint_16p histogram, int full_quantize));
1600
#endif
1601
1602
#ifdef PNG_READ_GAMMA_SUPPORTED
1603
/* The threshold on gamma processing is configurable but hard-wired into the
1604
* library. The following is the floating point variant.
1605
*/
1606
#define PNG_GAMMA_THRESHOLD (PNG_GAMMA_THRESHOLD_FIXED*.00001)
1607
1608
/* Handle gamma correction. Screen_gamma=(display_exponent).
1609
* NOTE: this API simply sets the screen and file gamma values. It will
1610
* therefore override the value for gamma in a PNG file if it is called after
1611
* the file header has been read - use with care - call before reading the PNG
1612
* file for best results!
1613
*
1614
* These routines accept the same gamma values as png_set_alpha_mode (described
1615
* above). The PNG_GAMMA_ defines and PNG_DEFAULT_sRGB can be passed to either
1616
* API (floating point or fixed.) Notice, however, that the 'file_gamma' value
1617
* is the inverse of a 'screen gamma' value.
1618
*/
1619
PNG_FP_EXPORT(50, void, png_set_gamma, (png_structrp png_ptr,
1620
double screen_gamma, double override_file_gamma))
1621
PNG_FIXED_EXPORT(208, void, png_set_gamma_fixed, (png_structrp png_ptr,
1622
png_fixed_point screen_gamma, png_fixed_point override_file_gamma))
1623
#endif
1624
1625
#ifdef PNG_WRITE_FLUSH_SUPPORTED
1626
PNG_REMOVED(51, void, png_set_flush, (png_structrp png_ptr, int nrows),
1627
PNG_EMPTY)
1628
#define png_set_flush(p,v) (png_setting((p), PNG_SW_FLUSH, 0, (v)))
1629
/* Set how many lines between output flushes - 0 for no flushing. The result
1630
* on success is always 0.
1631
*/
1632
1633
/* Flush the current PNG output buffer */
1634
PNG_EXPORT(52, void, png_write_flush, (png_structrp png_ptr));
1635
#endif /* WRITE_FLUSH */
1636
1637
/* Optional update palette with requested transformations */
1638
PNG_EXPORT(53, void, png_start_read_image, (png_structrp png_ptr));
1639
1640
/* Optional call to update the users info structure */
1641
PNG_EXPORT(54, void, png_read_update_info, (png_structrp png_ptr,
1642
png_inforp info_ptr));
1643
1644
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1645
/* Read one or more rows of image data. */
1646
PNG_EXPORT(55, void, png_read_rows, (png_structrp png_ptr, png_bytepp row,
1647
png_bytepp display_row, png_uint_32 num_rows));
1648
#endif
1649
1650
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1651
/* Read a row of data. */
1652
PNG_EXPORT(56, void, png_read_row, (png_structrp png_ptr, png_bytep row,
1653
png_bytep display_row));
1654
#endif
1655
1656
#ifdef PNG_READ_IMAGE_SUPPORTED
1657
/* Read the whole image into memory at once. */
1658
PNG_EXPORT(57, void, png_read_image, (png_structrp png_ptr, png_bytepp image));
1659
#endif
1660
1661
/* Write a row of image data */
1662
PNG_EXPORT(58, void, png_write_row, (png_structrp png_ptr,
1663
png_const_bytep row));
1664
1665
/* Write a few rows of image data: (*row) is not written; however, the type
1666
* is declared as writeable to maintain compatibility with previous versions
1667
* of libpng and to allow the 'display_row' array from read_rows to be passed
1668
* unchanged to write_rows.
1669
*/
1670
PNG_EXPORT(59, void, png_write_rows, (png_structrp png_ptr, png_bytepp row,
1671
png_uint_32 num_rows));
1672
1673
/* Write the image data */
1674
PNG_EXPORT(60, void, png_write_image, (png_structrp png_ptr, png_bytepp image));
1675
1676
/* Write the end of the PNG file. */
1677
PNG_EXPORT(61, void, png_write_end, (png_structrp png_ptr,
1678
png_inforp info_ptr));
1679
1680
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1681
/* Read the end of the PNG file. */
1682
PNG_EXPORT(62, void, png_read_end, (png_structrp png_ptr, png_inforp info_ptr));
1683
#endif
1684
1685
/* Free any memory associated with the png_info_struct */
1686
PNG_EXPORT(63, void, png_destroy_info_struct, (png_const_structrp png_ptr,
1687
png_infopp info_ptr_ptr));
1688
1689
/* Free any memory associated with the png_struct and the png_info_structs */
1690
PNG_EXPORT(64, void, png_destroy_read_struct, (png_structpp png_ptr_ptr,
1691
png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
1692
1693
/* Free any memory associated with the png_struct and the png_info_structs */
1694
PNG_EXPORT(65, void, png_destroy_write_struct, (png_structpp png_ptr_ptr,
1695
png_infopp info_ptr_ptr));
1696
1697
/* Set the libpng method of handling chunk CRC errors on read */
1698
PNG_REMOVED(66, void, png_set_crc_action, (png_structrp png_ptr,
1699
int crit_action, int ancil_action), PNG_EMPTY)
1700
#define png_set_crc_action(png_ptr, crit, ancil)\
1701
(png_setting((png_ptr), PNG_SR_CRC_ACTION, (crit), (ancil)))
1702
1703
/* Values for png_set_crc_action() say how to handle CRC errors in
1704
* ancillary and critical chunks, and whether to use the data contained
1705
* therein. Note that it is impossible to "discard" data in a critical
1706
* chunk. For versions prior to 0.90, the action was always error/quit,
1707
* whereas in version 0.90 and later, the action for CRC errors in ancillary
1708
* chunks is warn/discard. These values should NOT be changed.
1709
*
1710
* value action:critical action:ancillary
1711
*/
1712
#define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
1713
#define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
1714
#define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
1715
#define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
1716
#define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
1717
#define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
1718
1719
/* Write image filtering and compression options.
1720
*
1721
* These settings just change the very low level encoding of a PNG. The changes
1722
* make no difference to the image or the meta-data stored in the PNG. The API
1723
* used to make these changes can be disabled in a very minimal configuration,
1724
* if it is your compiler will report undefined values when the APIs below are
1725
* used.
1726
*
1727
* Write settings defined here, in order of ease of use:
1728
*
1729
* 1) Write compression settings: whether to optimize the write and the PNG
1730
* that results for read speed, final PNG size, write speed or memory
1731
* usage.
1732
* 2) IDAT size: What size to make the IDAT chunks in the PNG.
1733
* 3) PNG row filters to consider when writing the PNG.
1734
* 4) Very low level control over the deflate compression (useful mainly for
1735
* programs that want to try every option to find which gives the smallest
1736
* PNG.)
1737
*/
1738
#ifdef PNG_WRITE_SUPPORTED
1739
/* (1) Write compression settings: */
1740
#define png_set_compression(p, v) (png_setting((p), PNG_SW_COMPRESS_png_level,\
1741
0, (v)))
1742
/* Control the write compression of all chunks. This affects five basic
1743
* pieces of behavior:
1744
*
1745
* 1) The size of the PNG produced.
1746
* 2) The amount of memory the write code takes to produce the PNG.
1747
* 3) The amount of time the write code takes to produce the PNG.
1748
* 4) The amount of memory required to read the resultant PNG.
1749
* 5) The amount of time required to read the resultant PNG.
1750
*
1751
* There is considerable interdependence between these variables. As a
1752
* result there are a limited number of options:
1753
*/
1754
# define PNG_COMPRESSION_LOW_MEMORY (1)
1755
/* Minimize the memory required both when reading (4) and writing (2) the
1756
* PNG. This results in a significantly larger PNG (which may itself have
1757
* the opposite effect of slowing down either read or write) however the
1758
* memory overhead is reduced and, apart from the extra time to read the
1759
* data, the read time is likely to be reduced too.
1760
*
1761
* Use this when both read and write will happen on a memory starved
1762
* (really, very low memory) system. Note that this sets a high deflate
1763
* compression setting because that does not affect zlib memory usage.
1764
*/
1765
# define PNG_COMPRESSION_HIGH_SPEED (2)
1766
/* Minimize the time to both read (5) and write (3) the PNG. This uses
1767
* slightly more memory on read and potentially significantly more on
1768
* write but is optimized for maximum speed in both cases.
1769
*
1770
* Use this when both read and write need to be fast and PNG size is not
1771
* likely to be an issue. An example would be if you are using PNG to
1772
* pass intermediate data between applications on the same machine.
1773
*/
1774
# define PNG_COMPRESSION_HIGH_READ_SPEED (3)
1775
/* Minimize the time to read (5) the PNG. This also reduces the amount
1776
* of memory on read, however some options which require more memory but
1777
* are likely to decrease PNG size, therefore improve read spead, are
1778
* used.
1779
*
1780
* This is one of the 'normal' options; options that are used when a
1781
* reasonably capable write machine is producing PNG files that will be
1782
* read many times. In this case the option is optimizing for speed on
1783
* read even if it increases the size of the PNG.
1784
*/
1785
# define PNG_COMPRESSION_LOW (4)
1786
/* This switches on options which do affect speed of both compression and
1787
* decompression, but biases the choice towards higher performance in both
1788
* cases. (So it is something of a compromise between all-out speed and
1789
* PNG compression).
1790
*
1791
* This is a good default to use in typical usages where PNG file size is
1792
* less of an issue than the overheads on reading a PNG file.
1793
*
1794
* Use this option when producing PNG files that are not expected to be
1795
* distributed widely or where read speed is more important than size.
1796
* This is also a good default for small images where the slight increase
1797
* in size of the compressed data doesn't change the file size much.
1798
*/
1799
# define PNG_COMPRESSION_MEDIUM (5)
1800
/* This is a compromise which switches on the options found most helpful
1801
* across a wide range of files without switching on the full range of
1802
* options which would decrease file size only a little while taking a lot
1803
* more time. PNG read memory (4) or time (5) is not a factor in the
1804
* choice of options; only write time (3).
1805
*
1806
* This is closest to the default used in prior versions of libpng. There
1807
* seems no logic to using it if the actual requirements are known and,
1808
* even if they aren't, it is probably better to guess 'LOW' or 'HIGH'.
1809
*
1810
* This is the normal libpng default.
1811
*/
1812
# define PNG_COMPRESSION_HIGH (6)
1813
/* This turns on everything which reduces file size on aggregate across a
1814
* large test set of files. It optimizes solely for the size of the
1815
* resultant PNG (1).
1816
*
1817
* This is a good default to use if file size is all important; it was the
1818
* stated original default in the PNG design, but the implementation of
1819
* libpng never used it.
1820
*
1821
* Use this setting in image authoring applications when writing the
1822
* finished image in PNG format.
1823
*
1824
* NOTE: several PNG file size optimizers exist (see the web-site
1825
* libpng.org). libpng does not perform the same functions as these
1826
* optimizers; libpng does not search for the best compression settings.
1827
* For this reason if you really want to minimize the size of the PNG files
1828
* produced use PNG_COMPRESSION_HIGH_SPEED then post-process the result
1829
* with one of the many PNG optimization programs.
1830
*/
1831
# define PNG_COMPRESSION_COMPAT (0)
1832
/* DEPRECATED: this is provided as a setting to aid transition of test
1833
* suites between major library versions (1.5 or 1.6 moving to 1.7). The
1834
* default settings change in 1.7 so, while the PNG files produced do not
1835
* change, their encoding does. Test systems that rely on constant
1836
* encoding can use this to verify that this is all that has changed.
1837
*
1838
* NOTE: the option will be removed at some point. It is difficult to
1839
* maintain and adds to libpng code size.
1840
*
1841
* NOTE: there are other changes in major and minor releases, such as
1842
* better ancillary chunk error handling, that also cause binary changes
1843
* to the PNG files libpng generates. Furthermore versions of libpng
1844
* prior to 1.7 included random data from uninitialized memory in the
1845
* image data under certain circumstances; this meant that earlier
1846
* versions were often not even consistent across two writes of the same
1847
* PNG file!
1848
*/
1849
1850
/* png_set_compression sets the default for all libpng compression operations.
1851
* While the setting is the same for all chunks it results in different
1852
* compression options for different chunks. The setting can be applied
1853
* separately to each class of chunks as follows:
1854
*/
1855
#define png_set_image_compression(p, v) (png_setting((p),\
1856
PNG_SW_COMPRESS_png_level, png_IDAT, (v)))
1857
/* Control the compression of the image data (IDAT) chunks. */
1858
1859
#define png_set_ICC_profile_compression(p, v) (png_setting((p),\
1860
PNG_SW_COMPRESS_png_level, png_iCCP, (v)))
1861
/* Control the compression of ICC profiles (iCCP chunks.) */
1862
1863
#define png_set_text_compression(p, v) (png_setting((p),\
1864
PNG_SW_COMPRESS_png_level, png_zTXt, (v)))
1865
/* Control the compression of text (png_zTXt and png_iTXt) chunks. */
1866
1867
/* (2) IDAT size: */
1868
#define png_set_IDAT_size(p, v) (png_setting((p), PNG_SW_IDAT_size, (v), 0))
1869
/* Set the maximum size of the IDAT chunks libpng writes. Valid values are
1870
* in the range 1U..0x7fffffffU, the default is 'PNG_ZBUF_SIZE' (a
1871
* historically confusing name) and this default *also* controls the size of
1872
* the buffer the read code uses when reading IDAT chunks.
1873
*
1874
* libpng has to buffer the data in the IDAT chunk before it writes any of
1875
* it, therefore this number directly controls that part of the memory
1876
* overhead while writing a PNG. There is a 12 byte per chunk overhead, so
1877
* the number also directly affects the size of the PNG. The number has no
1878
* significant effect (beyond the latter size effect) on the read code.
1879
*/
1880
#endif /* WRITE */
1881
1882
/* These functions give the user control over the scan-line filtering in
1883
* libpng and the compression methods used by zlib. These functions are
1884
* mainly useful for testing, as the defaults should work with most users.
1885
* Those users who are tight on memory or want faster performance at the
1886
* expense of compression can modify them. See the compression library
1887
* header file (zlib.h) for an explination of the compression functions.
1888
*/
1889
1890
#ifdef PNG_WRITE_FILTER_SUPPORTED
1891
/* (3) PNG row filters to consider when writing the PNG.
1892
*
1893
* Control the filtering method(s) used by libpng for the write of subsequent
1894
* rows of the image. The argument is either a single filter value (one of the
1895
* PNG_FILTER_VALUE_ defines above), in which case that filter will be used on
1896
* following rows, or a mask of filter values (logical or of the PNG_FILTER_
1897
* bit masks that follow PNG_FILTER_VALUE_*). Support for selection of a filter
1898
* from a mask with more than one bit set is dependent on
1899
* PNG_SELECT_FILTER_SUPPORTED, however support is the default configuration of
1900
* libpng. If support is not available the lowest bit set in the mask (the
1901
* lowest numbered filter) is used.
1902
*
1903
* The set of filters may be changed at any time, the new values will affect the
1904
* next row written.
1905
*
1906
* The 'method' must match that passed to png_set_IHDR; it cannot be changed and
1907
* is ignored in 1.7 and later.
1908
*
1909
* If multiple filters are enabled libpng will select one according to the
1910
* following rules:
1911
*
1912
* 1) On the first row of a pass UP is ignored if NONE is set and PAETH is
1913
* ignored if SUB is set; this is because these filter pairs are equivalent
1914
* when there is no previous row.
1915
*
1916
* 2) PNG_SELECT_FILTER_SUPPORTED:
1917
* If the PNG rows are long enough (have enough bytes) libpng will process a
1918
* row at a time; it will buffer the row if necessary. It uses a heuristic
1919
* based on the closeness of the filtered values to 0 to determine which
1920
* filter to use.
1921
*
1922
* 3) !PNG_SELECT_FILTER_SUPPORTED:
1923
* libpng selects the first filter in the list (there is no warning that this
1924
* will happen - check the #defines if you need to know.)
1925
*
1926
* The 'up', 'avg' and 'Paeth' filters require the previous image row to work.
1927
* If it is not available they are removed from the set of filters to try. The
1928
* first time the filter mask includes one of these filters libpng turns on
1929
* saving of the row. The filters do work on the first row of a pass, where
1930
* there is no previous row from the image. The PNG standard defines the
1931
* previous row as consisting of all 0 bytes in this case. That definition
1932
* causes the filters to have the following properties on the first row of a
1933
* pass:
1934
*
1935
* UP: The same as NONE (i.e. no filtering).
1936
* AVG: Uses the arithmetic (not modular arithmetc!) half of the preceding
1937
* pixel as the predictor. This is unique and not typically very
1938
* useful.
1939
* PAETH: The same as SUB.
1940
*
1941
* As a result with all versions of libpng if you want to use any of these
1942
* filters anywhere in the image you need only turn on one of them on the first
1943
* row of the image, or of a pass for interlaced images. For example if you
1944
* want to use 'sub' on the first row simply set 'sub'+'Paeth' in the mask;
1945
* libpng will automatically eliminate the Paeth algorithm from consideration
1946
* because it knows that 'sub' will rank equal or (if the filter byte is taken
1947
* into account) better.
1948
*
1949
* This approach is portable to earlier versions of libpng, however it may be
1950
* difficult to program. 1.7 allows you to directly specify whether or not to
1951
* retain the previous row. This is simpler and allows you to turn off previous
1952
* row retention if you want to.
1953
*/
1954
PNG_REMOVED(67, void, png_set_filter, (png_structrp png_ptr, int method,
1955
int filters), PNG_EMPTY)
1956
1957
#define png_set_filter(p, m, f) (png_setting((p), PNG_SW_COMPRESS_filters,\
1958
(m), (f)))
1959
/* 'm' is the method and must be 0 (PNG_FILTER_TYPE_BASE) unless MNG
1960
* processing is supported (very unusual). 'f' is either a single value,
1961
* PNG_FILTER_VALUE_* below, or a combination of one or more PNG_FILTER_MASK
1962
* values.
1963
*
1964
* This sets the filter mask (or value) for the *next* row that is written.
1965
* It may be called at any time but does not have any effect until the next
1966
* row starts to be written.
1967
*
1968
* The return value is the mask that is set (or, with PNG_SF_GET, the
1969
* currently set mask). When PNG_SELECT_FILTER_SUPPORTED is not defined this
1970
* mask will have only one bit.
1971
*
1972
* NOTE: with PNG_SF_GET the result will be PNG_UNSET if png_set_filter has
1973
* not been called before and row writing has not started.
1974
*/
1975
1976
#define png_set_row_buffers(p, onoff) (png_setting((p),\
1977
PNG_SW_COMPRESS_row_buffers, (onoff), 0))
1978
/* If you intend to change the filter list after the first row using the
1979
* previous API call png_set_row_buffers(png_ptr, 1) if you intend to use UP,
1980
* AVG or Paeth filters.
1981
*
1982
* You can turn the buffering on and off dynamically, just as with
1983
* png_set_filter.
1984
*
1985
* The second argument should be 0 (off) or 1 (on). In the future it may be
1986
* used to control the maximum number of rows buffered.
1987
*/
1988
#endif /* WRITE_FILTER */
1989
1990
/* The PNG_FILTER_VALUE_ definitions (the filter values from the base PNG spec)
1991
* are valid arguments to png_set_filter() if only a single filter is to be
1992
* used. If multiple filters are to be allowed (the default is to allow any of
1993
* them) then a combination of the following masks must be used and the low
1994
* three bits of the argument to png_set_filter must be 0.
1995
*
1996
* The resultant argument fits in a single byte in either case.
1997
*/
1998
#define PNG_FILTER_MASK(value) (0x08 << (value))
1999
#define PNG_FILTER_NONE PNG_FILTER_MASK(PNG_FILTER_VALUE_NONE)
2000
#define PNG_FILTER_SUB PNG_FILTER_MASK(PNG_FILTER_VALUE_SUB)
2001
#define PNG_FILTER_UP PNG_FILTER_MASK(PNG_FILTER_VALUE_UP)
2002
#define PNG_FILTER_AVG PNG_FILTER_MASK(PNG_FILTER_VALUE_AVG)
2003
#define PNG_FILTER_PAETH PNG_FILTER_MASK(PNG_FILTER_VALUE_PAETH)
2004
2005
/* Then three convenience values. PNG_NO_FILTERS is the same as
2006
* PNG_FILTER_VALUE_NONE, but this is harmless because they mean the same thing.
2007
*/
2008
#define PNG_NO_FILTERS 0x00
2009
#define PNG_FAST_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP)
2010
#define PNG_ALL_FILTERS (PNG_FAST_FILTERS | PNG_FILTER_AVG | PNG_FILTER_PAETH)
2011
2012
#ifdef PNG_WRITE_SUPPORTED
2013
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* DEPRECATED */
2014
PNG_REMOVED(68, void, png_set_filter_heuristics,
2015
(png_structrp png_ptr, int heuristic_method, int num_weights,
2016
png_const_doublep filter_weights, png_const_doublep filter_costs),
2017
PNG_DEPRECATED)
2018
PNG_REMOVED(209, void, png_set_filter_heuristics_fixed,
2019
(png_structrp png_ptr, int heuristic_method, int num_weights,
2020
png_const_fixed_point_p filter_weights,
2021
png_const_fixed_point_p filter_costs),
2022
PNG_DEPRECATED)
2023
/* Neither of these API calls did anything in libpng 1.6, however they were
2024
* not marked PNG_DEPRECATED, so they are converted to no-op function-like
2025
* macros here. (NOTE: the macro arguments are evaluated once each, this
2026
* will probably cause warnings with some compiler options: simply remove the
2027
* function call after ensuring that the arguments had no side effects.)
2028
*/
2029
#define png_set_filter_heuristics(p,m,w,fw,fc) ((void)(p,m,w,fw,fc))
2030
#define png_set_filter_heuristics_fixed(p,m,w,fw,fc) ((void)(p,m,w,fw,fc))
2031
#endif /* WRITE_WEIGHTED_FILTER */
2032
2033
#ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED
2034
PNG_REMOVED(69, void, png_set_compression_level, (png_structrp png_ptr,
2035
int level), PNG_EMPTY)
2036
#define png_set_compression_level(p, v) (png_setting((p),\
2037
PNG_SW_COMPRESS_zlib_level, png_IDAT, (v)))
2038
2039
PNG_REMOVED(70, void, png_set_compression_mem_level, (png_structrp png_ptr,
2040
int mem_level), PNG_EMPTY)
2041
#define png_set_compression_mem_level(p, v) (png_setting((p),\
2042
PNG_SW_COMPRESS_memLevel, png_IDAT, (v)))
2043
2044
PNG_REMOVED(71, void, png_set_compression_strategy, (png_structrp png_ptr,
2045
int strategy), PNG_EMPTY)
2046
#define png_set_compression_strategy(p, v) (png_setting((p),\
2047
PNG_SW_COMPRESS_strategy, png_IDAT, (v)))
2048
2049
PNG_REMOVED(72, void, png_set_compression_window_bits, (png_structrp png_ptr,
2050
int window_bits), PNG_EMPTY)
2051
#define png_set_compression_window_bits(p, v) (png_setting((p),\
2052
PNG_SW_COMPRESS_windowBits, png_IDAT, (v)))
2053
2054
PNG_REMOVED(73, void, png_set_compression_method, (png_structrp png_ptr,
2055
int method), PNG_EMPTY)
2056
#define png_set_compression_method(p, v) (png_setting((p),\
2057
PNG_SW_COMPRESS_method, png_IDAT, (v)))
2058
#endif /* WRITE_CUSTOMIZE_COMPRESSION */
2059
2060
#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
2061
/* Also set zlib parameters for compressing non-IDAT chunks */
2062
PNG_REMOVED(222, void, png_set_text_compression_level, (png_structrp png_ptr,
2063
int level), PNG_EMPTY)
2064
#define png_set_text_compression_level(p, v) (png_setting((p),\
2065
PNG_SW_COMPRESS_zlib_level, png_zTXt, (v)))
2066
2067
PNG_REMOVED(223, void, png_set_text_compression_mem_level,
2068
(png_structrp png_ptr, int mem_level), PNG_EMPTY)
2069
#define png_set_text_compression_mem_level(p, v) (png_setting((p),\
2070
PNG_SW_COMPRESS_memLevel, png_zTXt, (v)))
2071
2072
PNG_REMOVED(224, void, png_set_text_compression_strategy, (png_structrp png_ptr,
2073
int strategy), PNG_EMPTY)
2074
#define png_set_text_compression_strategy(p, v) (png_setting((p),\
2075
PNG_SW_COMPRESS_strategy, png_zTXt, (v)))
2076
2077
PNG_REMOVED(225, void, png_set_text_compression_window_bits,
2078
(png_structrp png_ptr, int window_bits), PNG_EMPTY)
2079
#define png_set_text_compression_window_bits(p, v) (png_setting((p),\
2080
PNG_SW_COMPRESS_windowBits, png_zTXt, (v)))
2081
2082
PNG_REMOVED(226, void, png_set_text_compression_method, (png_structrp png_ptr,
2083
int method), PNG_EMPTY)
2084
#define png_set_text_compression_method(p, v) (png_setting((p),\
2085
PNG_SW_COMPRESS_method, png_zTXt, (v)))
2086
2087
/* NOTE: in versions of libpng prior to 1.7 iCCP compression was controlled by
2088
* the text settings, hence the controls were only available if
2089
* PNG_WRITE_CUSTOMIZIZE_ZTXT_COMPRESSION_SUPPORTED. In 1.7 the text settings
2090
* no longer affect iCCP compression, the following macros must be used (if
2091
* necessary):
2092
*/
2093
#define png_set_ICC_profile_compression_level(p, v) (png_setting((p),\
2094
PNG_SW_COMPRESS_zlib_level, png_iCCP, (v)))
2095
#define png_set_ICC_profile_compression_mem_level(p, v) (png_setting((p),\
2096
PNG_SW_COMPRESS_memLevel, png_iCCP, (v)))
2097
#define png_set_ICC_profile_compression_strategy(p, v) (png_setting((p),\
2098
PNG_SW_COMPRESS_strategy, png_iCCP, (v)))
2099
#define png_set_ICC_profile_compression_window_bits(p, v) (png_setting((p),\
2100
PNG_SW_COMPRESS_windowBits, png_iCCP, (v)))
2101
#define png_set_ICC_profile_compression_method(p, v) (png_setting((p),\
2102
PNG_SW_COMPRESS_method, png_iCCP, (v)))
2103
#endif /* WRITE_CUSTOMIZE_ZTXT_COMPRESSION */
2104
#endif /* WRITE */
2105
2106
/* These next functions are called for input/output, memory, and error
2107
* handling. They are in the file pngrio.c, pngwio.c, and pngerror.c,
2108
* and call standard C I/O routines such as fread(), fwrite(), and
2109
* fprintf(). These functions can be made to use other I/O routines
2110
* at run time for those applications that need to handle I/O in a
2111
* different manner by calling png_set_???_fn(). See libpng-manual.txt for
2112
* more information.
2113
*/
2114
2115
#ifdef PNG_STDIO_SUPPORTED
2116
/* Initialize the input/output for the PNG file to the default functions. */
2117
PNG_EXPORT(74, void, png_init_io, (png_structrp png_ptr, png_FILE_p fp));
2118
#endif
2119
2120
/* Replace the (error and abort), and warning functions with user
2121
* supplied functions. If no messages are to be printed you must still
2122
* write and use replacement functions. The replacement error_fn should
2123
* still do a longjmp to the last setjmp location if you are using this
2124
* method of error handling. If error_fn or warning_fn is NULL, the
2125
* default function will be used.
2126
*/
2127
2128
PNG_EXPORT(75, void, png_set_error_fn, (png_structrp png_ptr,
2129
png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
2130
2131
/* Return the user pointer associated with the error functions */
2132
PNG_EXPORT(76, png_voidp, png_get_error_ptr, (png_const_structrp png_ptr));
2133
2134
/* Replace the default data output functions with a user supplied one(s).
2135
* If buffered output is not used, then output_flush_fn can be set to NULL.
2136
* If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time
2137
* output_flush_fn will be ignored (and thus can be NULL).
2138
* It is probably a mistake to use NULL for output_flush_fn if
2139
* write_data_fn is not also NULL unless you have built libpng with
2140
* PNG_WRITE_FLUSH_SUPPORTED undefined, because in this case libpng's
2141
* default flush function, which uses the standard *FILE structure, will
2142
* be used.
2143
*/
2144
PNG_EXPORT(77, void, png_set_write_fn, (png_structrp png_ptr, png_voidp io_ptr,
2145
png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
2146
2147
/* Replace the default data input function with a user supplied one. */
2148
PNG_EXPORT(78, void, png_set_read_fn, (png_structrp png_ptr, png_voidp io_ptr,
2149
png_rw_ptr read_data_fn));
2150
2151
/* Return the user pointer associated with the I/O functions */
2152
PNG_EXPORT(79, png_voidp, png_get_io_ptr, (png_const_structrp png_ptr));
2153
2154
PNG_EXPORT(80, void, png_set_read_status_fn, (png_structrp png_ptr,
2155
png_read_status_ptr read_row_fn));
2156
2157
PNG_EXPORT(81, void, png_set_write_status_fn, (png_structrp png_ptr,
2158
png_write_status_ptr write_row_fn));
2159
2160
#ifdef PNG_USER_MEM_SUPPORTED
2161
/* Replace the default memory allocation functions with user supplied one(s). */
2162
PNG_EXPORT(82, void, png_set_mem_fn, (png_structrp png_ptr, png_voidp mem_ptr,
2163
png_malloc_ptr malloc_fn, png_free_ptr free_fn));
2164
/* Return the user pointer associated with the memory functions */
2165
PNG_EXPORT(83, png_voidp, png_get_mem_ptr, (png_const_structrp png_ptr));
2166
#endif
2167
2168
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
2169
PNG_EXPORT(84, void, png_set_read_user_transform_fn, (png_structrp png_ptr,
2170
png_user_transform_ptr read_user_transform_fn));
2171
#endif
2172
2173
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
2174
PNG_EXPORT(85, void, png_set_write_user_transform_fn, (png_structrp png_ptr,
2175
png_user_transform_ptr write_user_transform_fn));
2176
#endif
2177
2178
#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
2179
PNG_EXPORT(86, void, png_set_user_transform_info, (png_structrp png_ptr,
2180
png_voidp user_transform_ptr, int user_transform_depth,
2181
int user_transform_channels));
2182
/* Return the user pointer associated with the user transform functions */
2183
PNG_EXPORT(87, png_voidp, png_get_user_transform_ptr,
2184
(png_const_structrp png_ptr));
2185
#endif
2186
2187
#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED
2188
/* Return information about the row currently being processed. Note that these
2189
* APIs do not fail but will return unexpected results if called outside a user
2190
* transform callback. Also note that when transforming an interlaced image the
2191
* row number is the row number within the sub-image of the interlace pass, so
2192
* the value will increase to the height of the sub-image (not the full image)
2193
* then reset to 0 for the next pass.
2194
*
2195
* Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
2196
* find the output pixel (x,y) given an interlaced sub-image pixel
2197
* (row,col,pass). (See below for these macros.)
2198
*/
2199
PNG_EXPORT(217, png_uint_32, png_get_current_row_number, (png_const_structrp));
2200
PNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structrp));
2201
#endif
2202
2203
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
2204
/* This callback is called only for *unknown* chunks. If
2205
* PNG_HANDLE_AS_UNKNOWN_SUPPORTED is set then it is possible to set known
2206
* chunks to be treated as unknown, however in this case the callback must do
2207
* any processing required by the chunk and this is not possible for any chunk
2208
* that affects the image reading (e.g. PLTE, tRNS).
2209
*
2210
* There is no write support - on write, by default, all the chunks in the
2211
* 'unknown' list are written in the specified position.
2212
*
2213
* The integer return from the callback function is interpreted thus:
2214
*
2215
* negative: An error occurred; png_chunk_error will be called.
2216
* zero: The chunk was not handled, the default unknown handling is used
2217
* (even if this was a chunk that would otherwise be known.)
2218
* NOTE: prior to libpng 1.7 handling values of
2219
* PNG_HANDLE_CHUNK_AS_DEFAULT and PNG_HANDLE_CHUNK_NEVER were
2220
* converted to PNG_HANDLE_CHUNK_IF_SAFE (libpng 1.6.0 warns if this
2221
* happens) so it was not possible to discard unknown chunk data if a
2222
* user callback was installed.
2223
* positive: The chunk was handled, libpng will ignore/discard it.
2224
*
2225
* WARNING: if this callback is set every chunk in the stream is temporarily
2226
* read into a memory buffer. This has potential performance implications,
2227
* particularly for small PNG images with large amounts of ancilliary
2228
* information.
2229
*/
2230
PNG_EXPORT(88, void, png_set_read_user_chunk_fn, (png_structrp png_ptr,
2231
png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
2232
#endif
2233
2234
#ifdef PNG_USER_CHUNKS_SUPPORTED
2235
PNG_EXPORT(89, png_voidp, png_get_user_chunk_ptr, (png_const_structrp png_ptr));
2236
#endif
2237
2238
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
2239
/* Sets the function callbacks for the push reader, and a pointer to a
2240
* user-defined structure available to the callback functions.
2241
*/
2242
PNG_EXPORT(90, void, png_set_progressive_read_fn, (png_structrp png_ptr,
2243
png_voidp progressive_ptr, png_progressive_info_ptr info_fn,
2244
png_progressive_row_ptr row_fn, png_progressive_end_ptr end_fn));
2245
2246
/* Returns the user pointer associated with the push read functions */
2247
PNG_EXPORT(91, png_voidp, png_get_progressive_ptr,
2248
(png_const_structrp png_ptr));
2249
2250
/* Function to be called when data becomes available */
2251
PNG_EXPORT(92, void, png_process_data, (png_structrp png_ptr,
2252
png_inforp info_ptr, png_bytep buffer, size_t buffer_size));
2253
2254
/* A function which may be called *only* within png_process_data to stop the
2255
* processing of any more data. The function returns the number of bytes
2256
* remaining, excluding any that libpng has cached internally. A subsequent
2257
* call to png_process_data must supply these bytes again. If the argument
2258
* 'save' is set to true the routine will first save all the pending data and
2259
* will always return 0.
2260
*/
2261
PNG_EXPORT(219, size_t, png_process_data_pause, (png_structrp, int save));
2262
2263
/* A function which may be called *only* outside (after) a call to
2264
* png_process_data. It returns the number of bytes of data to skip in the
2265
* input. Normally it will return 0, but if it returns a non-zero value the
2266
* application must skip than number of bytes of input data and pass the
2267
* following data to the next call to png_process_data.
2268
*/
2269
PNG_EXPORT(220, png_uint_32, png_process_data_skip, (png_structrp));
2270
2271
#ifdef PNG_READ_INTERLACING_SUPPORTED
2272
/* Function that combines rows. 'new_row' is a flag that should come from
2273
* the callback and be non-NULL if anything needs to be done; the library
2274
* stores its own version of the new data internally and ignores the passed
2275
* in value.
2276
*/
2277
PNG_EXPORT(93, void, png_progressive_combine_row, (png_const_structrp png_ptr,
2278
png_bytep old_row, png_const_bytep new_row));
2279
#endif /* READ_INTERLACING */
2280
#endif /* PROGRESSIVE_READ */
2281
2282
PNG_EXPORTA(94, png_voidp, png_malloc, (png_const_structrp png_ptr,
2283
png_alloc_size_t size), PNG_ALLOCATED);
2284
/* Added at libpng version 1.4.0 */
2285
PNG_EXPORTA(95, png_voidp, png_calloc, (png_const_structrp png_ptr,
2286
png_alloc_size_t size), PNG_ALLOCATED);
2287
2288
/* Added at libpng version 1.2.4 */
2289
PNG_EXPORTA(96, png_voidp, png_malloc_warn, (png_const_structrp png_ptr,
2290
png_alloc_size_t size), PNG_ALLOCATED);
2291
2292
/* Frees a pointer allocated by png_malloc() */
2293
PNG_EXPORT(97, void, png_free, (png_const_structrp png_ptr, png_voidp ptr));
2294
2295
/* Free data that was allocated internally */
2296
PNG_EXPORT(98, void, png_free_data, (png_const_structrp png_ptr,
2297
png_inforp info_ptr, png_uint_32 free_me, int num));
2298
2299
/* Reassign responsibility for freeing existing data, whether allocated
2300
* by libpng or by the application; this works on the png_info structure passed
2301
* in, it does not change the state for other png_info structures.
2302
*
2303
* It is unlikely that this function works correctly as of 1.6.0 and using it
2304
* may result either in memory leaks or double free of allocated data. It was
2305
* removed in libpng 1.7.0.
2306
*/
2307
PNG_REMOVED(99, void, png_data_freer, (png_const_structrp png_ptr,
2308
png_inforp info_ptr, int freer, png_uint_32 mask), PNG_DEPRECATED)
2309
2310
/* Flags for png_free_data */
2311
#define PNG_FREE_HIST 0x0008U
2312
#define PNG_FREE_ICCP 0x0010U
2313
#define PNG_FREE_SPLT 0x0020U
2314
#define PNG_FREE_ROWS 0x0040U
2315
#define PNG_FREE_PCAL 0x0080U
2316
#define PNG_FREE_SCAL 0x0100U
2317
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
2318
# define PNG_FREE_UNKN 0x0200U
2319
#endif
2320
/* PNG_FREE_LIST 0x0400U removed in 1.6.0 because it is ignored */
2321
#define PNG_FREE_PLTE 0x1000U
2322
#define PNG_FREE_TRNS 0x2000U
2323
#define PNG_FREE_TEXT 0x4000U
2324
#define PNG_FREE_ALL 0x7fffU
2325
#define PNG_FREE_MUL 0x4220U /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
2326
2327
#ifdef PNG_USER_MEM_SUPPORTED
2328
/* These were deprecated in libpng 1.6.0 and have been removed from libpng
2329
* 1.7.0; the functionality should be accessed by calling malloc or free
2330
* directly or, if png_error handling is required, calling png_malloc.
2331
*/
2332
PNG_REMOVED(100, png_voidp, png_malloc_default, (png_const_structrp png_ptr,
2333
png_alloc_size_t size), PNG_ALLOCATED PNG_DEPRECATED)
2334
PNG_REMOVED(101, void, png_free_default, (png_const_structrp png_ptr,
2335
png_voidp ptr), PNG_DEPRECATED)
2336
#endif
2337
2338
#ifdef PNG_ERROR_TEXT_SUPPORTED
2339
/* Fatal error in PNG image of libpng - can't continue */
2340
PNG_EXPORTA(102, void, png_error, (png_const_structrp png_ptr,
2341
png_const_charp error_message), PNG_NORETURN);
2342
#else
2343
/* Fatal error in PNG image of libpng - can't continue */
2344
PNG_EXPORTA(104, void, png_err, (png_const_structrp png_ptr), PNG_NORETURN);
2345
# define png_error(s1,s2) png_err(s1)
2346
#endif
2347
2348
#if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
2349
/* The same, but the chunk name is prepended to the error string. */
2350
PNG_EXPORTA(103, void, png_chunk_error, (png_const_structrp png_ptr,
2351
png_const_charp error_message), PNG_NORETURN);
2352
#else
2353
# define png_chunk_error(s1,s2) png_error(s1,s2)
2354
#endif
2355
2356
#ifdef PNG_WARNINGS_SUPPORTED
2357
/* Non-fatal error in libpng. Can continue, but may have a problem. */
2358
PNG_EXPORT(105, void, png_warning, (png_const_structrp png_ptr,
2359
png_const_charp warning_message));
2360
2361
/* Non-fatal error in libpng, chunk name is prepended to message. */
2362
PNG_EXPORT(106, void, png_chunk_warning, (png_const_structrp png_ptr,
2363
png_const_charp warning_message));
2364
#else
2365
# define png_warning(s1,s2) ((void)(s1))
2366
# define png_chunk_warning(s1,s2) ((void)(s1))
2367
#endif
2368
2369
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
2370
/* Benign error in libpng. Can continue, but may have a problem.
2371
* User can choose whether to handle as a fatal error or as a warning. */
2372
PNG_EXPORT(107, void, png_benign_error, (png_const_structrp png_ptr,
2373
png_const_charp warning_message));
2374
2375
#ifdef PNG_READ_SUPPORTED
2376
/* Same, chunk name is prepended to message (only during read) */
2377
PNG_EXPORT(108, void, png_chunk_benign_error, (png_const_structrp png_ptr,
2378
png_const_charp warning_message));
2379
#endif
2380
2381
#define png_set_error_action(png_ptr, what, action)\
2382
(png_setting((png_ptr), PNG_SRW_ERROR_HANDLING, (what), (action)))
2383
/* Control the handling of 'benign' errors; errors that can be handled in
2384
* some way. The action is one of the following values:
2385
*/
2386
#define PNG_IGNORE 0 /* ignore the error; no warning or error message */
2387
#define PNG_WARN 1 /* call png_warning with an appropriate error message */
2388
#define PNG_ERROR 2 /* call png_error with the error message */
2389
/* 'what' is a list (bit mask) of the errors to set: */
2390
#define PNG_BENIGN_ERRORS (1U)
2391
#define PNG_APP_WARNINGS (2U)
2392
#define PNG_APP_ERRORS (4U)
2393
#define PNG_IDAT_ERRORS (8U)
2394
#define PNG_SAFE_ERRORS (PNG_BENIGN_ERRORS+PNG_APP_WARNINGS+PNG_APP_ERRORS)
2395
#define PNG_ALL_ERRORS (PNG_SAFE_ERRORS+PNG_IDAT_ERRORS)
2396
2397
PNG_REMOVED(109, void, png_set_benign_errors,
2398
(png_structrp png_ptr, int allowed), PNG_EMPTY)
2399
#define png_set_benign_errors(png_ptr, allowed) (png_setting((png_ptr),\
2400
PNG_SRW_ERROR_HANDLING, PNG_SAFE_ERRORS,\
2401
(allowed) ? PNG_WARN : PNG_ERROR))
2402
/* Turn all errors that can be handled into warnings, or turn them back into
2403
* errors if 'allowed' is false.
2404
*/
2405
2406
#else
2407
# ifdef PNG_ALLOW_BENIGN_ERRORS
2408
# define png_benign_error(pp,e) png_warning(pp,e)
2409
# define png_chunk_benign_error(pp,e) png_chunk_warning(pp,e)
2410
# else
2411
# define png_benign_error(pp,e) png_error(pp,e)
2412
# define png_chunk_benign_error(pp,e) png_chunk_error(pp,e)
2413
# endif
2414
#endif
2415
2416
/* The png_set_<chunk> functions are for storing values in the png_info_struct.
2417
* Similarly, the png_get_<chunk> calls are used to read values from the
2418
* png_info_struct, either storing the parameters in the passed variables, or
2419
* setting pointers into the png_info_struct where the data is stored. The
2420
* png_get_<chunk> functions return a non-zero value if the data was available
2421
* in info_ptr, or return zero and do not change any of the parameters if the
2422
* data was not available.
2423
*
2424
* These functions should be used instead of directly accessing png_info
2425
* to avoid problems with future changes in the size and internal layout of
2426
* png_info_struct.
2427
*/
2428
/* Returns "flag" if chunk data is valid in info_ptr. */
2429
PNG_EXPORT(110, png_uint_32, png_get_valid, (png_const_structrp png_ptr,
2430
png_const_inforp info_ptr, png_uint_32 flag));
2431
2432
/* Returns number of bytes needed to hold a transformed row. */
2433
PNG_EXPORT(111, png_alloc_size_t, png_get_rowbytes, (png_const_structrp png_ptr,
2434
png_const_inforp info_ptr));
2435
2436
#ifdef PNG_READ_PNG_SUPPORTED
2437
/* Returns row_pointers, which is an array of pointers to scanlines that was
2438
* returned from png_read_png().
2439
*/
2440
PNG_EXPORT(112, png_bytepp, png_get_rows, (png_const_structrp png_ptr,
2441
png_const_inforp info_ptr));
2442
#endif
2443
2444
#ifdef PNG_WRITE_PNG_SUPPORTED
2445
/* Set row_pointers, which is an array of pointers to scanlines for use
2446
* by png_write_png().
2447
*/
2448
PNG_EXPORT(113, void, png_set_rows, (png_const_structrp png_ptr,
2449
png_inforp info_ptr, png_bytepp row_pointers));
2450
#endif
2451
2452
/* Returns number of color channels in image. */
2453
PNG_EXPORT(114, png_byte, png_get_channels, (png_const_structrp png_ptr,
2454
png_const_inforp info_ptr));
2455
2456
#ifdef PNG_EASY_ACCESS_SUPPORTED
2457
/* Returns image width in pixels. */
2458
PNG_EXPORT(115, png_uint_32, png_get_image_width, (png_const_structrp png_ptr,
2459
png_const_inforp info_ptr));
2460
2461
/* Returns image height in pixels. */
2462
PNG_EXPORT(116, png_uint_32, png_get_image_height, (png_const_structrp png_ptr,
2463
png_const_inforp info_ptr));
2464
2465
/* Returns image bit_depth. */
2466
PNG_EXPORT(117, png_byte, png_get_bit_depth, (png_const_structrp png_ptr,
2467
png_const_inforp info_ptr));
2468
2469
/* Returns image color_type. */
2470
PNG_EXPORT(118, png_byte, png_get_color_type, (png_const_structrp png_ptr,
2471
png_const_inforp info_ptr));
2472
2473
/* Returns image filter_type. */
2474
PNG_EXPORT(119, png_byte, png_get_filter_type, (png_const_structrp png_ptr,
2475
png_const_inforp info_ptr));
2476
2477
/* Returns image interlace_type. */
2478
PNG_EXPORT(120, png_byte, png_get_interlace_type, (png_const_structrp png_ptr,
2479
png_const_inforp info_ptr));
2480
2481
/* Returns image compression_type. */
2482
PNG_EXPORT(121, png_byte, png_get_compression_type, (png_const_structrp png_ptr,
2483
png_const_inforp info_ptr));
2484
2485
/* Returns image resolution in pixels per meter, from pHYs chunk data. */
2486
PNG_EXPORT(122, png_uint_32, png_get_pixels_per_meter,
2487
(png_const_structrp png_ptr, png_const_inforp info_ptr));
2488
PNG_EXPORT(123, png_uint_32, png_get_x_pixels_per_meter,
2489
(png_const_structrp png_ptr, png_const_inforp info_ptr));
2490
PNG_EXPORT(124, png_uint_32, png_get_y_pixels_per_meter,
2491
(png_const_structrp png_ptr, png_const_inforp info_ptr));
2492
2493
/* Returns pixel aspect ratio, computed from pHYs chunk data. */
2494
PNG_FP_EXPORT(125, float, png_get_pixel_aspect_ratio,
2495
(png_const_structrp png_ptr, png_const_inforp info_ptr))
2496
PNG_FIXED_EXPORT(210, png_fixed_point, png_get_pixel_aspect_ratio_fixed,
2497
(png_const_structrp png_ptr, png_const_inforp info_ptr))
2498
2499
/* Returns image x, y offset in pixels or microns, from oFFs chunk data. */
2500
PNG_EXPORT(126, png_int_32, png_get_x_offset_pixels,
2501
(png_const_structrp png_ptr, png_const_inforp info_ptr));
2502
PNG_EXPORT(127, png_int_32, png_get_y_offset_pixels,
2503
(png_const_structrp png_ptr, png_const_inforp info_ptr));
2504
PNG_EXPORT(128, png_int_32, png_get_x_offset_microns,
2505
(png_const_structrp png_ptr, png_const_inforp info_ptr));
2506
PNG_EXPORT(129, png_int_32, png_get_y_offset_microns,
2507
(png_const_structrp png_ptr, png_const_inforp info_ptr));
2508
2509
#endif /* EASY_ACCESS */
2510
2511
#ifdef PNG_READ_SUPPORTED
2512
/* Returns pointer to signature string read from PNG header */
2513
PNG_EXPORT(130, png_const_bytep, png_get_signature, (png_const_structrp png_ptr,
2514
png_const_inforp info_ptr));
2515
#endif
2516
2517
#ifdef PNG_bKGD_SUPPORTED
2518
PNG_EXPORT(131, png_uint_32, png_get_bKGD, (png_const_structrp png_ptr,
2519
png_inforp info_ptr, png_color_16p *background));
2520
#endif
2521
2522
#ifdef PNG_bKGD_SUPPORTED
2523
PNG_EXPORT(132, void, png_set_bKGD, (png_const_structrp png_ptr,
2524
png_inforp info_ptr, png_const_color_16p background));
2525
#endif
2526
2527
#ifdef PNG_cHRM_SUPPORTED
2528
PNG_FP_EXPORT(133, png_uint_32, png_get_cHRM, (png_const_structrp png_ptr,
2529
png_const_inforp info_ptr, double *white_x, double *white_y, double *red_x,
2530
double *red_y, double *green_x, double *green_y, double *blue_x,
2531
double *blue_y))
2532
PNG_FP_EXPORT(230, png_uint_32, png_get_cHRM_XYZ, (png_const_structrp png_ptr,
2533
png_const_inforp info_ptr, double *red_X, double *red_Y, double *red_Z,
2534
double *green_X, double *green_Y, double *green_Z, double *blue_X,
2535
double *blue_Y, double *blue_Z))
2536
PNG_FIXED_EXPORT(134, png_uint_32, png_get_cHRM_fixed,
2537
(png_const_structrp png_ptr, png_const_inforp info_ptr,
2538
png_fixed_point *int_white_x, png_fixed_point *int_white_y,
2539
png_fixed_point *int_red_x, png_fixed_point *int_red_y,
2540
png_fixed_point *int_green_x, png_fixed_point *int_green_y,
2541
png_fixed_point *int_blue_x, png_fixed_point *int_blue_y))
2542
PNG_FIXED_EXPORT(231, png_uint_32, png_get_cHRM_XYZ_fixed,
2543
(png_const_structrp png_ptr, png_const_inforp info_ptr,
2544
png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
2545
png_fixed_point *int_red_Z, png_fixed_point *int_green_X,
2546
png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,
2547
png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,
2548
png_fixed_point *int_blue_Z))
2549
#endif
2550
2551
#ifdef PNG_cHRM_SUPPORTED
2552
PNG_FP_EXPORT(135, void, png_set_cHRM, (png_const_structrp png_ptr,
2553
png_inforp info_ptr,
2554
double white_x, double white_y, double red_x, double red_y, double green_x,
2555
double green_y, double blue_x, double blue_y))
2556
PNG_FP_EXPORT(232, void, png_set_cHRM_XYZ, (png_const_structrp png_ptr,
2557
png_inforp info_ptr, double red_X, double red_Y, double red_Z,
2558
double green_X, double green_Y, double green_Z, double blue_X,
2559
double blue_Y, double blue_Z))
2560
PNG_FIXED_EXPORT(136, void, png_set_cHRM_fixed, (png_const_structrp png_ptr,
2561
png_inforp info_ptr, png_fixed_point int_white_x,
2562
png_fixed_point int_white_y, png_fixed_point int_red_x,
2563
png_fixed_point int_red_y, png_fixed_point int_green_x,
2564
png_fixed_point int_green_y, png_fixed_point int_blue_x,
2565
png_fixed_point int_blue_y))
2566
PNG_FIXED_EXPORT(233, void, png_set_cHRM_XYZ_fixed, (png_const_structrp png_ptr,
2567
png_inforp info_ptr, png_fixed_point int_red_X, png_fixed_point int_red_Y,
2568
png_fixed_point int_red_Z, png_fixed_point int_green_X,
2569
png_fixed_point int_green_Y, png_fixed_point int_green_Z,
2570
png_fixed_point int_blue_X, png_fixed_point int_blue_Y,
2571
png_fixed_point int_blue_Z))
2572
#endif
2573
2574
#ifdef PNG_gAMA_SUPPORTED
2575
PNG_FP_EXPORT(137, png_uint_32, png_get_gAMA, (png_const_structrp png_ptr,
2576
png_const_inforp info_ptr, double *file_gamma))
2577
PNG_FIXED_EXPORT(138, png_uint_32, png_get_gAMA_fixed,
2578
(png_const_structrp png_ptr, png_const_inforp info_ptr,
2579
png_fixed_point *int_file_gamma))
2580
#endif
2581
2582
#ifdef PNG_gAMA_SUPPORTED
2583
PNG_FP_EXPORT(139, void, png_set_gAMA, (png_const_structrp png_ptr,
2584
png_inforp info_ptr, double file_gamma))
2585
PNG_FIXED_EXPORT(140, void, png_set_gAMA_fixed, (png_const_structrp png_ptr,
2586
png_inforp info_ptr, png_fixed_point int_file_gamma))
2587
#endif
2588
2589
#ifdef PNG_hIST_SUPPORTED
2590
PNG_EXPORT(141, png_uint_32, png_get_hIST, (png_const_structrp png_ptr,
2591
png_inforp info_ptr, png_uint_16p *hist));
2592
#endif
2593
2594
#ifdef PNG_hIST_SUPPORTED
2595
PNG_EXPORT(142, void, png_set_hIST, (png_const_structrp png_ptr,
2596
png_inforp info_ptr, png_const_uint_16p hist));
2597
#endif
2598
2599
PNG_EXPORT(143, png_uint_32, png_get_IHDR, (png_const_structrp png_ptr,
2600
png_const_inforp info_ptr, png_uint_32 *width, png_uint_32 *height,
2601
int *bit_depth, int *color_type, int *interlace_method,
2602
int *compression_method, int *filter_method));
2603
2604
PNG_EXPORT(144, void, png_set_IHDR, (png_const_structrp png_ptr,
2605
png_inforp info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
2606
int color_type, int interlace_method, int compression_method,
2607
int filter_method));
2608
2609
#ifdef PNG_oFFs_SUPPORTED
2610
PNG_EXPORT(145, png_uint_32, png_get_oFFs, (png_const_structrp png_ptr,
2611
png_const_inforp info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
2612
int *unit_type));
2613
#endif
2614
2615
#ifdef PNG_oFFs_SUPPORTED
2616
PNG_EXPORT(146, void, png_set_oFFs, (png_const_structrp png_ptr,
2617
png_inforp info_ptr, png_int_32 offset_x, png_int_32 offset_y,
2618
int unit_type));
2619
#endif
2620
2621
#ifdef PNG_pCAL_SUPPORTED
2622
PNG_EXPORT(147, png_uint_32, png_get_pCAL, (png_const_structrp png_ptr,
2623
png_inforp info_ptr, png_charp *purpose, png_int_32 *X0,
2624
png_int_32 *X1, int *type, int *nparams, png_charp *units,
2625
png_charpp *params));
2626
#endif
2627
2628
#ifdef PNG_pCAL_SUPPORTED
2629
PNG_EXPORT(148, void, png_set_pCAL, (png_const_structrp png_ptr,
2630
png_inforp info_ptr, png_const_charp purpose, png_int_32 X0, png_int_32 X1,
2631
int type, int nparams, png_const_charp units, png_charpp params));
2632
#endif
2633
2634
#ifdef PNG_pHYs_SUPPORTED
2635
PNG_EXPORT(149, png_uint_32, png_get_pHYs, (png_const_structrp png_ptr,
2636
png_const_inforp info_ptr, png_uint_32 *res_x, png_uint_32 *res_y,
2637
int *unit_type));
2638
#endif
2639
2640
#ifdef PNG_pHYs_SUPPORTED
2641
PNG_EXPORT(150, void, png_set_pHYs, (png_const_structrp png_ptr,
2642
png_inforp info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
2643
#endif
2644
2645
PNG_EXPORT(151, png_uint_32, png_get_PLTE, (png_const_structrp png_ptr,
2646
png_inforp info_ptr, png_colorp *palette, int *num_palette));
2647
2648
PNG_EXPORT(152, void, png_set_PLTE, (png_structrp png_ptr,
2649
png_inforp info_ptr, png_const_colorp palette, int num_palette));
2650
2651
#ifdef PNG_sBIT_SUPPORTED
2652
PNG_EXPORT(153, png_uint_32, png_get_sBIT, (png_const_structrp png_ptr,
2653
png_inforp info_ptr, png_color_8p *sig_bit));
2654
#endif
2655
2656
#ifdef PNG_sBIT_SUPPORTED
2657
PNG_EXPORT(154, void, png_set_sBIT, (png_const_structrp png_ptr,
2658
png_inforp info_ptr, png_const_color_8p sig_bit));
2659
#endif
2660
2661
#ifdef PNG_sRGB_SUPPORTED
2662
PNG_EXPORT(155, png_uint_32, png_get_sRGB, (png_const_structrp png_ptr,
2663
png_const_inforp info_ptr, int *file_srgb_intent));
2664
#endif
2665
2666
#ifdef PNG_sRGB_SUPPORTED
2667
PNG_EXPORT(156, void, png_set_sRGB, (png_const_structrp png_ptr,
2668
png_inforp info_ptr, int srgb_intent));
2669
PNG_EXPORT(157, void, png_set_sRGB_gAMA_and_cHRM, (png_const_structrp png_ptr,
2670
png_inforp info_ptr, int srgb_intent));
2671
#endif
2672
2673
#ifdef PNG_iCCP_SUPPORTED
2674
PNG_EXPORT(158, png_uint_32, png_get_iCCP, (png_const_structrp png_ptr,
2675
png_inforp info_ptr, png_charpp name, int *compression_type,
2676
png_bytepp profile, png_uint_32 *proflen));
2677
#endif
2678
2679
#ifdef PNG_iCCP_SUPPORTED
2680
PNG_EXPORT(159, void, png_set_iCCP, (png_const_structrp png_ptr,
2681
png_inforp info_ptr, png_const_charp name, int compression_type,
2682
png_const_bytep profile, png_uint_32 proflen));
2683
#endif
2684
2685
#ifdef PNG_sPLT_SUPPORTED
2686
PNG_EXPORT(160, int, png_get_sPLT, (png_const_structrp png_ptr,
2687
png_inforp info_ptr, png_sPLT_tpp entries));
2688
#endif
2689
2690
#ifdef PNG_sPLT_SUPPORTED
2691
PNG_EXPORT(161, void, png_set_sPLT, (png_structrp png_ptr,
2692
png_inforp info_ptr, png_const_sPLT_tp entries, int nentries));
2693
#endif
2694
2695
#ifdef PNG_TEXT_SUPPORTED
2696
/* png_get_text also returns the number of text chunks in *num_text */
2697
PNG_EXPORT(162, int, png_get_text, (png_const_structrp png_ptr,
2698
png_inforp info_ptr, png_textp *text_ptr, int *num_text));
2699
#endif
2700
2701
/* Note while png_set_text() will accept a structure whose text,
2702
* language, and translated keywords are NULL pointers, the structure
2703
* returned by png_get_text will always contain regular
2704
* zero-terminated C strings. They might be empty strings but
2705
* they will never be NULL pointers.
2706
*/
2707
2708
#ifdef PNG_TEXT_SUPPORTED
2709
PNG_EXPORT(163, void, png_set_text, (png_structrp png_ptr,
2710
png_inforp info_ptr, png_const_textp text_ptr, int num_text));
2711
#endif
2712
2713
#ifdef PNG_tIME_SUPPORTED
2714
PNG_EXPORT(164, png_uint_32, png_get_tIME, (png_const_structrp png_ptr,
2715
png_inforp info_ptr, png_timep *mod_time));
2716
#endif
2717
2718
#ifdef PNG_tIME_SUPPORTED
2719
PNG_EXPORT(165, void, png_set_tIME, (png_const_structrp png_ptr,
2720
png_inforp info_ptr, png_const_timep mod_time));
2721
#endif
2722
2723
#ifdef PNG_tRNS_SUPPORTED
2724
PNG_EXPORT(166, png_uint_32, png_get_tRNS, (png_const_structrp png_ptr,
2725
png_inforp info_ptr, png_bytep *trans_alpha, int *num_trans,
2726
png_color_16p *trans_color));
2727
#endif
2728
2729
#ifdef PNG_tRNS_SUPPORTED
2730
PNG_EXPORT(167, void, png_set_tRNS, (png_structrp png_ptr,
2731
png_inforp info_ptr, png_const_bytep trans_alpha, int num_trans,
2732
png_const_color_16p trans_color));
2733
#endif
2734
2735
#ifdef PNG_sCAL_SUPPORTED
2736
#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2737
/* NOTE: these API are currently implemented using floating point arithmetic,
2738
* consequently they can only be used on systems with floating point support.
2739
* In any case the range of values supported by png_fixed_point is small and it
2740
* is highly recommended that png_get_sCAL_s be used instead.
2741
*/
2742
PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL, (png_const_structrp png_ptr,
2743
png_const_inforp info_ptr, int *unit, double *width, double *height))
2744
PNG_FIXED_EXPORT(214, png_uint_32, png_get_sCAL_fixed,
2745
(png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit,
2746
png_fixed_point *width, png_fixed_point *height))
2747
#endif
2748
PNG_EXPORT(169, png_uint_32, png_get_sCAL_s,
2749
(png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit,
2750
png_charpp swidth, png_charpp sheight));
2751
2752
#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2753
/* This also requires internal floating point arithmetic support - i.e. it
2754
* requires a full math library, not just floating point handling.
2755
*/
2756
PNG_FP_EXPORT(170, void, png_set_sCAL, (png_const_structrp png_ptr,
2757
png_inforp info_ptr, int unit, double width, double height))
2758
#endif
2759
PNG_FIXED_EXPORT(213, void, png_set_sCAL_fixed, (png_const_structrp png_ptr,
2760
png_inforp info_ptr, int unit, png_fixed_point width,
2761
png_fixed_point height))
2762
PNG_EXPORT(171, void, png_set_sCAL_s, (png_const_structrp png_ptr,
2763
png_inforp info_ptr, int unit,
2764
png_const_charp swidth, png_const_charp sheight));
2765
#endif /* sCAL */
2766
2767
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
2768
/* Provide the default handling for all unknown chunks or, optionally, for
2769
* specific unknown chunks.
2770
*
2771
* NOTE: prior to 1.6.0 the handling specified for particular chunks on read was
2772
* ignored and the default was used, the per-chunk setting only had an effect on
2773
* write. If you wish to have chunk-specific handling on read in code that must
2774
* work on earlier versions you must use a user chunk callback to implement the
2775
* desired handling (keep or discard.)
2776
*
2777
* NOTE: prior to 1.7.0 when a user callback returned '0', indicating that the
2778
* chunk had not been handled, libpng would preserve it regardless of the
2779
* default or per-chunk settings. For compatibility with earlier versions
2780
* simply return '1' (handled) from the callback to discard the chunk.
2781
*
2782
* The 'keep' parameter is a PNG_HANDLE_CHUNK_ value as listed below. The
2783
* parameter is interpreted as follows:
2784
*
2785
* READ:
2786
* PNG_HANDLE_CHUNK_AS_DEFAULT:
2787
* Known chunks: do normal libpng processing, do not keep the chunk (but
2788
* see the comments below about PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
2789
* Unknown chunks: for a specific chunk use the global default, when used
2790
* as the default discard the chunk data.
2791
* PNG_HANDLE_CHUNK_NEVER:
2792
* Discard the chunk data.
2793
* PNG_HANDLE_CHUNK_IF_SAFE:
2794
* Keep the chunk data if the chunk is not critical else raise a chunk
2795
* error.
2796
* PNG_HANDLE_CHUNK_ALWAYS:
2797
* Keep the chunk data.
2798
*
2799
* If the chunk data is saved it can be retrieved using png_get_unknown_chunks,
2800
* below. Notice that specifying "AS_DEFAULT" as a global default is equivalent
2801
* to specifying "NEVER", however when "AS_DEFAULT" is used for specific chunks
2802
* it simply resets the behavior to the libpng default.
2803
*
2804
* The per-chunk handling is always used when there is a png_user_chunk_ptr
2805
* callback and the callback returns 0; the chunk is then always stored *unless*
2806
* it is critical and the per-chunk setting is other than ALWAYS. Notice that
2807
* the global default is *not* used in this case. (In effect the per-chunk
2808
* value is incremented to at least IF_SAFE.)
2809
*
2810
* PNG_HANDLE_AS_UNKNOWN_SUPPORTED:
2811
* If this is *not* set known chunks will always be handled by libpng and
2812
* will never be stored in the unknown chunk list. Known chunks listed to
2813
* png_set_keep_unknown_chunks will have no effect. If it is set then known
2814
* chunks listed with a keep other than AS_DEFAULT will *never* be processed
2815
* by libpng, in addition critical chunks must either be processed by the
2816
* callback or saved.
2817
*
2818
* The IHDR and IEND chunks must not be listed. Because this turns off the
2819
* default handling for chunks that would otherwise be recognized the
2820
* behavior of libpng transformations may well become incorrect!
2821
*
2822
* WRITE:
2823
* When writing chunks the options only apply to the chunks specified by
2824
* png_set_unknown_chunks (below), libpng will *always* write known chunks
2825
* required by png_set_ calls and will always write the core critical chunks
2826
* (as required for PLTE).
2827
*
2828
* Each chunk in the png_set_unknown_chunks list is looked up in the
2829
* png_set_keep_unknown_chunks list to find the keep setting, this is then
2830
* interpreted as follows:
2831
*
2832
* PNG_HANDLE_CHUNK_AS_DEFAULT:
2833
* Write safe-to-copy chunks and write other chunks if the global
2834
* default is set to _ALWAYS, otherwise don't write this chunk.
2835
* PNG_HANDLE_CHUNK_NEVER:
2836
* Do not write the chunk.
2837
* PNG_HANDLE_CHUNK_IF_SAFE:
2838
* Write the chunk if it is safe-to-copy, otherwise do not write it.
2839
* PNG_HANDLE_CHUNK_ALWAYS:
2840
* Write the chunk.
2841
*
2842
* Note that the default behavior is effectively the opposite of the read case -
2843
* in read unknown chunks are not stored by default, in write they are written
2844
* by default. Also the behavior of PNG_HANDLE_CHUNK_IF_SAFE is very different
2845
* - on write the safe-to-copy bit is checked, on read the critical bit is
2846
* checked and on read if the chunk is critical an error will be raised.
2847
*
2848
* num_chunks:
2849
* ===========
2850
* If num_chunks is positive, then the "keep" parameter specifies the manner
2851
* for handling only those chunks appearing in the chunk_list array,
2852
* otherwise the chunk list array is ignored.
2853
*
2854
* If num_chunks is 0 the "keep" parameter specifies the default behavior for
2855
* unknown chunks, as described above.
2856
*
2857
* If num_chunks is negative, then the "keep" parameter specifies the manner
2858
* for handling all unknown chunks plus all chunks recognized by libpng
2859
* except for the IHDR, PLTE, tRNS, IDAT, and IEND chunks (which continue to
2860
* be processed by libpng.
2861
*/
2862
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
2863
PNG_EXPORT(172, void, png_set_keep_unknown_chunks, (png_structrp png_ptr,
2864
int keep, png_const_bytep chunk_list, int num_chunks));
2865
#endif /* HANDLE_AS_UNKNOWN */
2866
2867
/* The "keep" PNG_HANDLE_CHUNK_ parameter for the specified chunk is returned;
2868
* the result is therefore true (non-zero) if special handling is required,
2869
* false for the default handling.
2870
*/
2871
PNG_EXPORT(173, int, png_handle_as_unknown, (png_const_structrp png_ptr,
2872
png_const_bytep chunk_name));
2873
#endif /* SET_UNKNOWN_CHUNKS */
2874
2875
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
2876
PNG_EXPORT(174, void, png_set_unknown_chunks, (png_structrp png_ptr,
2877
png_inforp info_ptr, png_const_unknown_chunkp unknowns,
2878
int num_unknowns));
2879
/* NOTE: prior to 1.6.0 this routine set the 'location' field of the added
2880
* unknowns to the location currently stored in the png_struct. This is
2881
* invariably the wrong value on write. To fix this call the following API
2882
* for each chunk in the list with the correct location. If you know your
2883
* code won't be compiled on earlier versions you can rely on
2884
* png_set_unknown_chunks(write-ptr, png_get_unknown_chunks(read-ptr)) doing
2885
* the correct thing.
2886
*
2887
* API CHANGE: in 1.7.0 this API will not work on read unless
2888
* PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED is set; it may be necessary to change
2889
* code to check the latter SUPPORTED flag. png_set_keep_unknown_chunks
2890
* will issue a warning if it is asked to save a chunk and there is no read
2891
* support.
2892
*/
2893
2894
PNG_EXPORT(175, void, png_set_unknown_chunk_location,
2895
(png_const_structrp png_ptr, png_inforp info_ptr, int chunk, int location));
2896
2897
PNG_EXPORT(176, int, png_get_unknown_chunks, (png_const_structrp png_ptr,
2898
png_inforp info_ptr, png_unknown_chunkpp entries));
2899
#endif
2900
2901
/* Png_free_data() will turn off the "valid" flag for anything it frees.
2902
* If you need to turn it off for a chunk that your application has freed,
2903
* you can use png_set_invalid(png_ptr, info_ptr, PNG_INFO_CHNK);
2904
*/
2905
PNG_EXPORT(177, void, png_set_invalid, (png_const_structrp png_ptr,
2906
png_inforp info_ptr, int mask));
2907
2908
/* The "params" pointer is currently not used and is for future expansion. */
2909
#ifdef PNG_READ_PNG_SUPPORTED
2910
PNG_EXPORT(178, void, png_read_png, (png_structrp png_ptr, png_inforp info_ptr,
2911
int transforms, png_voidp params));
2912
#endif
2913
#ifdef PNG_WRITE_PNG_SUPPORTED
2914
PNG_EXPORT(179, void, png_write_png, (png_structrp png_ptr, png_inforp info_ptr,
2915
int transforms, png_voidp params));
2916
#endif
2917
2918
PNG_EXPORT(180, png_const_charp, png_get_copyright,
2919
(png_const_structrp png_ptr));
2920
PNG_EXPORT(181, png_const_charp, png_get_header_ver,
2921
(png_const_structrp png_ptr));
2922
PNG_EXPORT(182, png_const_charp, png_get_header_version,
2923
(png_const_structrp png_ptr));
2924
PNG_EXPORT(183, png_const_charp, png_get_libpng_ver,
2925
(png_const_structrp png_ptr));
2926
2927
#ifdef PNG_MNG_FEATURES_SUPPORTED
2928
PNG_EXPORT(184, png_uint_32, png_permit_mng_features, (png_structrp png_ptr,
2929
png_uint_32 mng_features_permitted));
2930
#endif
2931
2932
/* For use in png_set_keep_unknown, added to version 1.2.6 */
2933
#define PNG_HANDLE_CHUNK_AS_DEFAULT 0
2934
#define PNG_HANDLE_CHUNK_NEVER 1
2935
#define PNG_HANDLE_CHUNK_IF_SAFE 2
2936
#define PNG_HANDLE_CHUNK_ALWAYS 3
2937
#define PNG_HANDLE_CHUNK_LAST 4
2938
2939
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
2940
/* This was never implemented: */
2941
PNG_REMOVED(185, void, png_set_strip_error_numbers, (png_structrp png_ptr,
2942
png_uint_32 strip_mode), PNG_EMPTY)
2943
#endif
2944
2945
/* Added in libpng-1.2.6 */
2946
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
2947
PNG_EXPORT(186, void, png_set_user_limits, (png_structrp png_ptr,
2948
png_uint_32 user_width_max, png_uint_32 user_height_max));
2949
PNG_EXPORT(187, png_uint_32, png_get_user_width_max,
2950
(png_const_structrp png_ptr));
2951
PNG_EXPORT(188, png_uint_32, png_get_user_height_max,
2952
(png_const_structrp png_ptr));
2953
/* Added in libpng-1.4.0 */
2954
PNG_EXPORT(189, void, png_set_chunk_cache_max, (png_structrp png_ptr,
2955
png_uint_32 user_chunk_cache_max));
2956
PNG_EXPORT(190, png_uint_32, png_get_chunk_cache_max,
2957
(png_const_structrp png_ptr));
2958
/* Added in libpng-1.4.1 */
2959
PNG_EXPORT(191, void, png_set_chunk_malloc_max, (png_structrp png_ptr,
2960
png_alloc_size_t user_chunk_cache_max));
2961
PNG_EXPORT(192, png_alloc_size_t, png_get_chunk_malloc_max,
2962
(png_const_structrp png_ptr));
2963
#endif
2964
2965
#if defined(PNG_INCH_CONVERSIONS_SUPPORTED)
2966
PNG_EXPORT(193, png_uint_32, png_get_pixels_per_inch,
2967
(png_const_structrp png_ptr, png_const_inforp info_ptr));
2968
2969
PNG_EXPORT(194, png_uint_32, png_get_x_pixels_per_inch,
2970
(png_const_structrp png_ptr, png_const_inforp info_ptr));
2971
2972
PNG_EXPORT(195, png_uint_32, png_get_y_pixels_per_inch,
2973
(png_const_structrp png_ptr, png_const_inforp info_ptr));
2974
2975
PNG_FP_EXPORT(196, float, png_get_x_offset_inches,
2976
(png_const_structrp png_ptr, png_const_inforp info_ptr))
2977
#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */
2978
PNG_FIXED_EXPORT(211, png_fixed_point, png_get_x_offset_inches_fixed,
2979
(png_const_structrp png_ptr, png_const_inforp info_ptr))
2980
#endif
2981
2982
PNG_FP_EXPORT(197, float, png_get_y_offset_inches, (png_const_structrp png_ptr,
2983
png_const_inforp info_ptr))
2984
#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */
2985
PNG_FIXED_EXPORT(212, png_fixed_point, png_get_y_offset_inches_fixed,
2986
(png_const_structrp png_ptr, png_const_inforp info_ptr))
2987
#endif
2988
2989
# ifdef PNG_pHYs_SUPPORTED
2990
PNG_EXPORT(198, png_uint_32, png_get_pHYs_dpi, (png_const_structrp png_ptr,
2991
png_const_inforp info_ptr, png_uint_32 *res_x, png_uint_32 *res_y,
2992
int *unit_type));
2993
# endif /* pHYs */
2994
#endif /* INCH_CONVERSIONS */
2995
2996
/* Added in libpng-1.4.0 */
2997
#ifdef PNG_IO_STATE_SUPPORTED
2998
PNG_EXPORT(199, png_uint_32, png_get_io_state, (png_const_structrp png_ptr));
2999
3000
/* Removed from libpng 1.6; use png_get_io_chunk_type. */
3001
PNG_REMOVED(200, png_const_bytep, png_get_io_chunk_name, (png_structrp png_ptr),
3002
PNG_DEPRECATED)
3003
3004
PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type,
3005
(png_const_structrp png_ptr));
3006
3007
/* The flags returned by png_get_io_state() are the following: */
3008
# define PNG_IO_NONE 0x0000U /* no I/O at this moment */
3009
# define PNG_IO_READING 0x0001U /* currently reading */
3010
# define PNG_IO_WRITING 0x0002U /* currently writing */
3011
# define PNG_IO_SIGNATURE 0x0010U /* currently at the file signature */
3012
# define PNG_IO_CHUNK_HDR 0x0020U /* currently at the chunk header */
3013
# define PNG_IO_CHUNK_DATA 0x0040U /* currently at the chunk data */
3014
# define PNG_IO_CHUNK_CRC 0x0080U /* currently at the chunk crc */
3015
# define PNG_IO_MASK_OP 0x000fU /* current operation: reading/writing */
3016
# define PNG_IO_MASK_LOC 0x00f0U /* current location: sig/hdr/data/crc */
3017
#endif /* IO_STATE */
3018
3019
/* Interlace support. The following macros are always defined so that if
3020
* libpng interlace handling is turned off the macros may be used to handle
3021
* interlaced images within the application.
3022
*/
3023
#define PNG_INTERLACE_ADAM7_PASSES 7
3024
3025
/* Two macros to return the first row and first column of the original,
3026
* full, image which appears in a given pass. 'pass' is in the range 0
3027
* to 6 and the result is in the range 0 to 7.
3028
*/
3029
#define PNG_PASS_START_ROW(pass) (((1&~(pass))<<(3-((pass)>>1)))&7)
3030
#define PNG_PASS_START_COL(pass) (((1& (pass))<<(3-(((pass)+1)>>1)))&7)
3031
3032
/* A macro to return the offset between pixels in the output row for a pair of
3033
* pixels in the input - effectively the inverse of the 'COL_SHIFT' macro that
3034
* follows. Note that ROW_OFFSET is the offset from one row to the next whereas
3035
* COL_OFFSET is from one column to the next, within a row.
3036
*/
3037
#define PNG_PASS_ROW_OFFSET(pass) ((pass)>2?(8>>(((pass)-1)>>1)):8)
3038
#define PNG_PASS_COL_OFFSET(pass) (1<<((7-(pass))>>1))
3039
3040
/* Two macros to help evaluate the number of rows or columns in each
3041
* pass. This is expressed as a shift - effectively 3-log2 of the number or
3042
* rows or columns in each 8x8 tile of the original image.
3043
*/
3044
#define PNG_PASS_ROW_SHIFT(pass) ((pass)>2?(8-(pass))>>1:3)
3045
#define PNG_PASS_COL_SHIFT(pass) ((pass)>1?(7-(pass))>>1:3)
3046
3047
/* Hence two macros to determine the number of rows or columns in a given
3048
* pass of an image given its height or width. In fact these macros may
3049
* return non-zero even though the sub-image is empty, because the other
3050
* dimension may be empty for a small image.
3051
*/
3052
#define PNG_PASS_ROWS(height, pass) (((height)+(((1<<PNG_PASS_ROW_SHIFT(pass))\
3053
-1)-PNG_PASS_START_ROW(pass)))>>PNG_PASS_ROW_SHIFT(pass))
3054
#define PNG_PASS_COLS(width, pass) (((width)+(((1<<PNG_PASS_COL_SHIFT(pass))\
3055
-1)-PNG_PASS_START_COL(pass)))>>PNG_PASS_COL_SHIFT(pass))
3056
3057
/* For the reader row callbacks (both progressive and sequential) it is
3058
* necessary to find the row in the output image given a row in an interlaced
3059
* image, so two more macros:
3060
*/
3061
#define PNG_ROW_FROM_PASS_ROW(y_in, pass) \
3062
(((y_in)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass))
3063
#define PNG_COL_FROM_PASS_COL(x_in, pass) \
3064
(((x_in)<<PNG_PASS_COL_SHIFT(pass))+PNG_PASS_START_COL(pass))
3065
3066
/* Two macros which return a boolean (0 or 1) saying whether the given row
3067
* or column is in a particular pass. These use a common utility macro that
3068
* returns a mask for a given pass - the offset 'off' selects the row or
3069
* column version. The mask has the appropriate bit set for each column in
3070
* the tile.
3071
*/
3072
#define PNG_PASS_MASK(pass,off) ( \
3073
((0x110145AF>>(((7-(off))-(pass))<<2)) & 0xF) | \
3074
((0x01145AF0>>(((7-(off))-(pass))<<2)) & 0xF0))
3075
3076
#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \
3077
((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1)
3078
#define PNG_COL_IN_INTERLACE_PASS(x, pass) \
3079
((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1)
3080
3081
/* Whether the pass is in the image at all, taking into account the full image
3082
* width and height, evaluates 'pass' lots of times, but width and height at
3083
* most once each.
3084
*/
3085
#define PNG_PASS_IN_IMAGE(width, height, pass)\
3086
((height) > PNG_PASS_START_ROW(pass) && (width) > PNG_PASS_START_COL(pass))
3087
3088
/* A macro to find the last pass (in the range 0 to 6) given an image width and
3089
* height. Then two macros two find whether a given image row or column which
3090
* is present in the pass is the last row or column in the pass. Note that
3091
* these macros return 'true' for earlier rows or columns of the image that are
3092
* *not* in the pass.
3093
*/
3094
#define PNG_LAST_PASS(width, height) ((height) > 1 ? 6 : ((width) > 1 ? 5 : 0))
3095
#define PNG_LAST_PASS_ROW(y, pass, height)\
3096
((y) + PNG_PASS_ROW_OFFSET(pass) >= (height))
3097
#define PNG_LAST_PASS_COL(x, pass, width)\
3098
((x) + PNG_PASS_COL_OFFSET(pass) >= (width))
3099
3100
#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
3101
/* With these routines we avoid an integer divide, which will be slower on
3102
* most machines. However, it does take more operations than the corresponding
3103
* divide method, so it may be slower on a few RISC systems. There are two
3104
* shifts (by 8 or 16 bits) and an addition, versus a single integer divide.
3105
*
3106
* Note that the rounding factors are NOT supposed to be the same! 128 and
3107
* 32768 are correct for the NODIV code; 127 and 32767 are correct for the
3108
* standard method.
3109
*
3110
* [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]
3111
*/
3112
3113
/* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
3114
3115
# define png_composite(composite, fg, alpha, bg) \
3116
{ png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) \
3117
* (png_uint_16)(alpha) \
3118
+ (png_uint_16)(bg)*(png_uint_16)(255 \
3119
- (png_uint_16)(alpha)) + 128); \
3120
(composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
3121
3122
# define png_composite_16(composite, fg, alpha, bg) \
3123
{ png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) \
3124
* (png_uint_32)(alpha) \
3125
+ (png_uint_32)(bg)*(65535 \
3126
- (png_uint_32)(alpha)) + 32768); \
3127
(composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
3128
3129
#else /* Standard method using integer division */
3130
3131
# define png_composite(composite, fg, alpha, bg) \
3132
(composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
3133
(png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
3134
127) / 255)
3135
3136
# define png_composite_16(composite, fg, alpha, bg) \
3137
(composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
3138
(png_uint_32)(bg)*(png_uint_32)(65535 - (png_uint_32)(alpha)) + \
3139
32767) / 65535)
3140
#endif /* READ_COMPOSITE_NODIV */
3141
3142
#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED
3143
PNG_EXPORT(201, png_uint_32, png_get_uint_32, (png_const_bytep buf));
3144
PNG_EXPORT(202, png_uint_16, png_get_uint_16, (png_const_bytep buf));
3145
PNG_EXPORT(203, png_int_32, png_get_int_32, (png_const_bytep buf));
3146
#endif
3147
3148
PNG_EXPORT(204, png_uint_32, png_get_uint_31, (png_const_structrp png_ptr,
3149
png_const_bytep buf));
3150
/* No png_get_int_16 -- may be added if there's a real need for it. */
3151
3152
/* Place a 32-bit number into a buffer in PNG byte order (big-endian). */
3153
#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED
3154
PNG_EXPORT(205, void, png_save_uint_32, (png_bytep buf, png_uint_32 i));
3155
3156
/* This becomes a macro in 1.7 because the old implementation was wrong; it
3157
* failed to do the cast. ANSI C requires the cast to convert a negative number
3158
* to the 2's complement form, so this just works:
3159
*/
3160
#define png_save_int_32(b, i) png_save_uint_32(b, i);
3161
#endif /* WRITE_INT_FUNCTIONS */
3162
3163
/* Apps that used this will use the macro in 1.7. */
3164
PNG_REMOVED(206, void, png_save_int_32, (png_bytep buf, png_int_32 i),
3165
PNG_DEPRECATED)
3166
3167
/* Place a 16-bit number into a buffer in PNG byte order.
3168
* The parameter is declared unsigned int, not png_uint_16,
3169
* just to avoid potential problems on pre-ANSI C compilers.
3170
*/
3171
#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED
3172
PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i));
3173
/* No png_save_int_16 -- may be added if there's a real need for it. */
3174
#endif
3175
3176
#ifdef PNG_USE_READ_MACROS
3177
/* Inline macros to do direct reads of bytes from the input buffer.
3178
*/
3179
# define PNG_B(ptr, offset) (((png_const_bytep)(ptr))[offset])
3180
# define PNG_get_uint_32(buf) \
3181
PNG_U32(PNG_B(buf,0), PNG_B(buf,1), PNG_B(buf,2), PNG_B(buf,3))
3182
3183
/* From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
3184
* function) incorrectly returned a value of type png_uint_32.
3185
*/
3186
# define PNG_get_uint_16(buf) PNG_U16(PNG_B(buf,0), PNG_B(buf,1))
3187
3188
# define PNG_get_int_32(buf) \
3189
PNG_S32(PNG_B(buf,0), PNG_B(buf,1), PNG_B(buf,2), PNG_B(buf,3))
3190
3191
/* If PNG_PREFIX is defined the same thing as below happens in pnglibconf.h,
3192
* but defining a macro name prefixed with PNG_PREFIX.
3193
*/
3194
# ifndef PNG_PREFIX
3195
# define png_get_uint_32(buf) PNG_get_uint_32(buf)
3196
# define png_get_uint_16(buf) PNG_get_uint_16(buf)
3197
# define png_get_int_32(buf) PNG_get_int_32(buf)
3198
# endif
3199
#else
3200
# ifdef PNG_PREFIX
3201
/* No macros; revert to the (redefined) function */
3202
# define PNG_get_uint_32 (png_get_uint_32)
3203
# define PNG_get_uint_16 (png_get_uint_16)
3204
# define PNG_get_int_32 (png_get_int_32)
3205
# endif
3206
#endif
3207
3208
#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
3209
PNG_REMOVED(242, void, png_set_check_for_invalid_index,
3210
(png_structrp png_ptr, int enabled_if_greater_than_0), PNG_EMPTY)
3211
#define png_set_check_for_invalid_index(png_ptr, value)\
3212
(png_setting((png_ptr), PNG_SRW_CHECK_FOR_INVALID_INDEX, 0, (value)))
3213
/* By default the check is enabled on both read and write when the number of
3214
* entries in the palette is less than the maximum required by the bit depth
3215
* of a palette image.
3216
*
3217
* Passing 1 to 'enabled' turns the check on in all cases.
3218
* Passing -1 turns it off and the PNG may have invalid palette index values.
3219
* Passing 0 restores the default.
3220
*
3221
* On read chunk (benign) error messages are only produced with the default
3222
* setting; it is assumed that when the check is turned on explicitly the
3223
* caller will call png_get_palette_max to check the result.
3224
*
3225
* The png_setting call returns 0.
3226
*/
3227
#endif /* CHECK_FOR_INVALID_INDEX */
3228
#ifdef PNG_GET_PALETTE_MAX_SUPPORTED
3229
PNG_EXPORT(243, int, png_get_palette_max, (png_const_structrp png_ptr,
3230
png_const_inforp info_ptr));
3231
/* The info_ptr is not used, it may be NULL in 1.7.0 (not in earlier
3232
* versions). If the information is not available because
3233
* png_set_check_for_invalid_index was not used to turn it on -1 is returned.
3234
* Valid results can only be obtained after the complete image has been read,
3235
* though it may be called at any time to get the result so far.
3236
*/
3237
#endif /* GET_PALETTE_MAX */
3238
3239
/* Memory format options; these return information about the layout of the
3240
* transformed row using the Simplified API PNG_FORMAT_ values (see below for
3241
* the #defines).
3242
*
3243
* These are only relevant if read or write transforms are supported; these
3244
* may cause the memory format of pixel data to differ from that used in the
3245
* PNG file itself. Nevertheless the APIs are supported regardless of whether
3246
* transforms are applied; use these to consistently and safely determine the
3247
* layout of the image in memory.
3248
*
3249
* Some of the same information can be obtained from png_info, however this
3250
* does not record whether the byte or bit formats have been changed.
3251
*/
3252
PNG_EXPORT(246, unsigned int, png_memory_format, (png_structrp png_ptr));
3253
/* The in-memory format as a bitmask of PNG_FORMAT_FLAG_ values. All the
3254
* flags listed below are used. If PNG_FORMAT_FLAG_INVALID is set the
3255
* following caveats apply to the interpretation of PNG_FORMAT_FLAG_LINEAR:
3256
*
3257
* The gamma may differ from the sRGB (!LINEAR) or 1.0 (LINEAR). Call
3258
* png_memory_gamma to find the correct value.
3259
*
3260
* The channel depth may differ from 8 (!LINEAR) or 16 (LINEAR). Call
3261
* png_memory_channel_depth to find the correct value.
3262
*
3263
* It is only valid to call these APIS *after* either png_read_update_info
3264
* or png_start_read_image on read or after the first row of an image has
3265
* been written on write.
3266
*
3267
* To find the number of channels in each pixel from the returned value,
3268
* 'fmt' use:
3269
*
3270
* PNG_FORMAT_CHANNELS(fmt)
3271
*/
3272
3273
PNG_EXPORT(247, unsigned int, png_memory_channel_depth, (png_structrp png_ptr));
3274
/* The actual depth of each channel in the image, to determine the full pixel
3275
* depth (in bits) use:
3276
*
3277
* png_memory_channel_depth(pp) * PNG_FORMAT_CHANNELS(fmt)
3278
*/
3279
3280
#ifdef PNG_GAMMA_SUPPORTED
3281
PNG_EXPORT(248, png_fixed_point, png_memory_gamma, (png_structrp png_ptr));
3282
/* The actual gamma of the image data, scaled by 100,000. This is the
3283
* encoding gamma, e.g. 1/2.2 for sRGB. If the gamma is unknown this will
3284
* return 0.
3285
*
3286
* On write this invariably returns 0; libpng does not change the gamma of
3287
* the data on write.
3288
*
3289
* Note that this is not always the exact inverse of the 'screen gamma'
3290
* passed to png_set_gamma; internal optimizations remove attempts to make
3291
* small changes to the gamma value. This function returns the actual
3292
* output value.
3293
*/
3294
#endif /* GAMMA */
3295
3296
/*******************************************************************************
3297
* Section 5: SIMPLIFIED API
3298
*******************************************************************************
3299
*
3300
* Please read the documentation in libpng-manual.txt (TODO: write said
3301
* documentation) if you don't understand what follows.
3302
*
3303
* The simplified API hides the details of both libpng and the PNG file format
3304
* itself. It allows PNG files to be read into a very limited number of
3305
* in-memory bitmap formats or to be written from the same formats. If these
3306
* formats do not accomodate your needs then you can, and should, use the more
3307
* sophisticated APIs above - these support a wide variety of in-memory formats
3308
* and a wide variety of sophisticated transformations to those formats as well
3309
* as a wide variety of APIs to manipulate ancillary information.
3310
*
3311
* To read a PNG file using the simplified API:
3312
*
3313
* 1) Declare a 'png_image' structure (see below) on the stack and set the
3314
* version field to PNG_IMAGE_VERSION.
3315
* 2) Call the appropriate png_image_begin_read... function.
3316
* 3) Set the png_image 'format' member to the required sample format.
3317
* 4) Allocate a buffer for the image and, if required, the color-map.
3318
* 5) Call png_image_finish_read to read the image and, if required, the
3319
* color-map into your buffers.
3320
*
3321
* There are no restrictions on the format of the PNG input itself; all valid
3322
* color types, bit depths, and interlace methods are acceptable, and the
3323
* input image is transformed as necessary to the requested in-memory format
3324
* during the png_image_finish_read() step. The only caveat is that if you
3325
* request a color-mapped image from a PNG that is full-color or makes
3326
* complex use of an alpha channel the transformation is extremely lossy and the
3327
* result may look terrible.
3328
*
3329
* To write a PNG file using the simplified API:
3330
*
3331
* 1) Declare a 'png_image' structure on the stack and memset() it to all zero.
3332
* 2) Initialize the members of the structure that describe the image, setting
3333
* the 'format' member to the format of the image samples.
3334
* 3) Call the appropriate png_image_write... function with a pointer to the
3335
* image and, if necessary, the color-map to write the PNG data.
3336
*
3337
* png_image is a structure that describes the in-memory format of an image
3338
* when it is being read or defines the in-memory format of an image that you
3339
* need to write:
3340
*/
3341
#define PNG_IMAGE_VERSION 1
3342
3343
typedef struct png_control *png_controlp;
3344
typedef struct
3345
{
3346
png_controlp opaque; /* Initialize to NULL, free with png_image_free */
3347
png_uint_32 version; /* Set to PNG_IMAGE_VERSION */
3348
png_uint_32 width; /* Image width in pixels (columns) */
3349
png_uint_32 height; /* Image height in pixels (rows) */
3350
png_uint_32 format; /* Image format as defined below */
3351
png_uint_32 flags; /* A bit mask containing informational flags */
3352
png_uint_32 colormap_entries;
3353
/* Number of entries in the color-map */
3354
3355
/* In the event of an error or warning the following field will be set to a
3356
* non-zero value and the 'message' field will contain a '\0' terminated
3357
* string with the libpng error or warning message. If both warnings and
3358
* an error were encountered, only the error is recorded. If there
3359
* are multiple warnings, only the first one is recorded.
3360
*
3361
* The upper 30 bits of this value are reserved, the low two bits contain
3362
* a value as follows:
3363
*/
3364
# define PNG_IMAGE_WARNING 1
3365
# define PNG_IMAGE_ERROR 2
3366
/*
3367
* The result is a two-bit code such that a value more than 1 indicates
3368
* a failure in the API just called:
3369
*
3370
* 0 - no warning or error
3371
* 1 - warning
3372
* 2 - error
3373
* 3 - error preceded by warning
3374
*/
3375
# define PNG_IMAGE_FAILED(png_cntrl) ((((png_cntrl).warning_or_error)&0x03)>1)
3376
3377
png_uint_32 warning_or_error;
3378
3379
char message[64];
3380
} png_image, *png_imagep;
3381
3382
/* The samples of the image have one to four channels whose components have
3383
* original values in the range 0 to 1.0:
3384
*
3385
* 1: A single gray or luminance channel (G).
3386
* 2: A gray/luminance channel and an alpha channel (GA).
3387
* 3: Three red, green, blue color channels (RGB).
3388
* 4: Three color channels and an alpha channel (RGBA).
3389
*
3390
* The components are encoded in one of two ways:
3391
*
3392
* a) As a small integer, value 0..255, contained in a single byte. For the
3393
* alpha channel the original value is simply value/255. For the color or
3394
* luminance channels the value is encoded according to the sRGB specification
3395
* and matches the 8-bit format expected by typical display devices.
3396
*
3397
* The color/gray channels are not scaled (pre-multiplied) by the alpha
3398
* channel and are suitable for passing to color management software.
3399
*
3400
* b) As a value in the range 0..65535, contained in a 2-byte integer. All
3401
* channels can be converted to the original value by dividing by 65535; all
3402
* channels are linear. Color channels use the RGB encoding (RGB end-points) of
3403
* the sRGB specification. This encoding is identified by the
3404
* PNG_FORMAT_FLAG_LINEAR flag below.
3405
*
3406
* When the simplified API needs to convert between sRGB and linear colorspaces,
3407
* the actual sRGB transfer curve defined in the sRGB specification (see the
3408
* article at https://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2
3409
* approximation used elsewhere in libpng.
3410
*
3411
* When an alpha channel is present it is expected to denote pixel coverage
3412
* of the color or luminance channels and is returned as an associated alpha
3413
* channel: the color/gray channels are scaled (pre-multiplied) by the alpha
3414
* value.
3415
*
3416
* The samples are either contained directly in the image data, between 1 and 8
3417
* bytes per pixel according to the encoding, or are held in a color-map indexed
3418
* by bytes in the image data. In the case of a color-map the color-map entries
3419
* are individual samples, encoded as above, and the image data has one byte per
3420
* pixel to select the relevant sample from the color-map.
3421
*/
3422
3423
/* PNG_FORMAT_*
3424
*
3425
* #defines to be used in png_image::format. Each #define identifies a
3426
* particular layout of sample data and, if present, alpha values. There are
3427
* separate defines for each of the two component encodings.
3428
*
3429
* A format is built up using single bit flag values. All combinations are
3430
* valid. Formats can be built up from the flag values or you can use one of
3431
* the predefined values below. When testing formats always use the FORMAT_FLAG
3432
* macros to test for individual features - future versions of the library may
3433
* add new flags.
3434
*
3435
* When reading or writing color-mapped images the format should be set to the
3436
* format of the entries in the color-map then png_image_{read,write}_colormap
3437
* called to read or write the color-map and set the format correctly for the
3438
* image data. Do not set the PNG_FORMAT_FLAG_COLORMAP bit directly!
3439
*
3440
* NOTE: libpng can be built with particular features disabled, if you see
3441
* compiler errors because the definition of one of the following flags has been
3442
* compiled out it is because libpng does not have the required support. It is
3443
* possible, however, for the libpng configuration to enable the format on just
3444
* read or just write; in that case you may see an error at run time. You can
3445
* guard against this by checking for the definition of the appropriate
3446
* "_SUPPORTED" macro, one of:
3447
*
3448
* PNG_SIMPLIFIED_{READ,WRITE}_{BGR,AFIRST}_SUPPORTED
3449
*/
3450
#define PNG_FORMAT_FLAG_ALPHA 0x01U /* format with an alpha channel */
3451
#define PNG_FORMAT_FLAG_COLOR 0x02U /* color format: otherwise grayscale */
3452
#define PNG_FORMAT_FLAG_LINEAR 0x04U /* 2 byte channels else 1 byte */
3453
#define PNG_FORMAT_FLAG_COLORMAP 0x08U /* image data is color-mapped */
3454
#define PNG_FORMAT_FLAG_BGR 0x10U /* BGR colors, else order is RGB */
3455
#define PNG_FORMAT_FLAG_AFIRST 0x20U /* alpha channel comes first */
3456
/* other bits RESERVED */
3457
3458
/* The PNG color type value can be derived from a format which repesents a valid
3459
* PNG format using the following macro. Note that if any of the non-PNG
3460
* format elements are use, such as BGR or AFIRST, the color type value that
3461
* results does represent the number of channels in the format but may not
3462
* represent their order or encoding.
3463
*
3464
* NOTE: the format can encode illegal PNG formats, such as a colormap with
3465
* alpha or without color; these are legal simplified API formats which produce
3466
* data that cannot be represented as PNG regardless of channel order or
3467
* encoding.
3468
*
3469
* The macro below is the bit shift version, a multiplicative version which only
3470
* evaluates 'f' once is:
3471
*
3472
* ((((((((f) * 0x111) & 0x128) * 0x3) & 0x130) * 0x5) >> 6) & 0x7)
3473
*/
3474
#define PNG_COLOR_TYPE_FROM_FORMAT(f)\
3475
((((f) & (!((f) & PNG_FORMAT_FLAG_AFILLER))) << 2) |\
3476
(((f) & PNG_FORMAT_FLAG_COLOR) ) |\
3477
(((f) & PNG_FORMAT_FLAG_COLORMAP) >> 3))
3478
3479
/* The inverse: note that PNG_FORMAT_FLAG_LINEAR is not set by this macro and
3480
* that there is no handling for a 'filler' channel, consequently the macro must
3481
* only be used on genuine PNG color types, not the result of png_get_color_type
3482
* after transforms have been applied to the original PNG data.
3483
*/
3484
#define PNG_FORMAT_FROM_COLOR_TYPE(c)\
3485
((((c) & PNG_COLOR_MASK_ALPHA) >> 2) |\
3486
(((c) & PNG_COLOR_MASK_COLOR) ) |\
3487
(((c) & PNG_COLOR_MASK_PALETTE) << 3))
3488
3489
/* The following flags are not used by the simplified API but may be returned
3490
* by png_memory_format. Presence of any of these flags means that the values
3491
* in the image (in memory) cannot be handled 'normally'.
3492
*/
3493
#define PNG_FORMAT_FLAG_AFILLER 0x40U /* The 'alpha' channel is a filler:
3494
* PNG_FORMAT_FLAG_ALPHA is set however the value in the alpha channel
3495
* is not an alpha value and (therefore) cannot be used for alpha
3496
* computations, it is just a filler value. PNG_COLOR_TYPE_FROM_FORMAT
3497
* will return a color type *without* PNG_COLOR_MASK_ALPHA, however
3498
* PNG_FORMAT_CHANNELS will return the correct number, including the
3499
* filler channel.
3500
*/
3501
#define PNG_FORMAT_FLAG_SWAPPED 0x80U /* bytes or bits swapped:
3502
* When the bit depth is 16 this means that the bytes within the
3503
* components have been swapped, when the bit depth is less than 8
3504
* it means the pixels within the bytes have been swapped. It should
3505
* not be set for 8-bit compononents (it is meaningless). */
3506
#define PNG_FORMAT_FLAG_RANGE 0x100U /* component range not 0..bit-depth:
3507
* Low-bit-depth grayscale components have been unpacked into bytes
3508
* without scaling, or RGB[A] pixels have been shifted back to the
3509
* significant-bit range from the sBIT chunk or channels (currently
3510
* alpha or gray) have been inverted. */
3511
#define PNG_FORMAT_FLAG_INVALID 0x8000U /* Invalid simplified API channel depth:
3512
* For single channel grayscale and palette indexed image data PNG
3513
* supports bit depths of 1, 2 or 4 bits per pixel (and per channel)
3514
* packed into bytes. The simplified API macros will not work with
3515
* these formats (the simplified API always uses 8 or 16-bit channels).
3516
* In the simplified API 'linear' images always have 16-bit channels
3517
* and non-linear images are always sRGB encoded. If the INVALID flag
3518
* is set then this may not be true; it is necessary to check the
3519
* memory format bit-depth and gamma separately.
3520
*/
3521
3522
/* Commonly used formats have predefined macros.
3523
*
3524
* First the single byte (sRGB) formats:
3525
*/
3526
#define PNG_FORMAT_GRAY 0U
3527
#define PNG_FORMAT_GA PNG_FORMAT_FLAG_ALPHA
3528
#define PNG_FORMAT_AG (PNG_FORMAT_GA|PNG_FORMAT_FLAG_AFIRST)
3529
#define PNG_FORMAT_RGB PNG_FORMAT_FLAG_COLOR
3530
#define PNG_FORMAT_BGR (PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_BGR)
3531
#define PNG_FORMAT_RGBA (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_ALPHA)
3532
#define PNG_FORMAT_ARGB (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_AFIRST)
3533
#define PNG_FORMAT_BGRA (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_ALPHA)
3534
#define PNG_FORMAT_ABGR (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_AFIRST)
3535
3536
/* Then the linear 2-byte formats. When naming these "Y" is used to
3537
* indicate a luminance (gray) channel.
3538
*/
3539
#define PNG_FORMAT_LINEAR_Y PNG_FORMAT_FLAG_LINEAR
3540
#define PNG_FORMAT_LINEAR_Y_ALPHA (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_ALPHA)
3541
#define PNG_FORMAT_LINEAR_RGB (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR)
3542
#define PNG_FORMAT_LINEAR_RGB_ALPHA \
3543
(PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA)
3544
3545
/* With color-mapped formats the image data is one byte for each pixel, the byte
3546
* is an index into the color-map which is formatted as above. To obtain a
3547
* color-mapped format it is sufficient just to add the PNG_FOMAT_FLAG_COLORMAP
3548
* to one of the above definitions, or you can use one of the definitions below.
3549
*/
3550
#define PNG_FORMAT_RGB_COLORMAP (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_COLORMAP)
3551
#define PNG_FORMAT_BGR_COLORMAP (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_COLORMAP)
3552
#define PNG_FORMAT_RGBA_COLORMAP (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_COLORMAP)
3553
#define PNG_FORMAT_ARGB_COLORMAP (PNG_FORMAT_ARGB|PNG_FORMAT_FLAG_COLORMAP)
3554
#define PNG_FORMAT_BGRA_COLORMAP (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_COLORMAP)
3555
#define PNG_FORMAT_ABGR_COLORMAP (PNG_FORMAT_ABGR|PNG_FORMAT_FLAG_COLORMAP)
3556
3557
/* PNG_IMAGE macros
3558
*
3559
* These are convenience macros to derive information from a png_image
3560
* structure. The PNG_IMAGE_SAMPLE_ macros return values appropriate to the
3561
* actual image sample values - either the entries in the color-map or the
3562
* pixels in the image. The PNG_IMAGE_PIXEL_ macros return corresponding values
3563
* for the pixels and will always return 1 for color-mapped formats. The
3564
* remaining macros return information about the rows in the image and the
3565
* complete image.
3566
*
3567
* NOTE: All the macros that take a png_image::format parameter are compile time
3568
* constants if the format parameter is, itself, a constant. Therefore these
3569
* macros can be used in array declarations and case labels where required.
3570
* Similarly the macros are also pre-processor constants (sizeof is not used) so
3571
* they can be used in #if tests.
3572
*
3573
* First the information about the samples.
3574
*/
3575
#define PNG_IMAGE_SAMPLE_CHANNELS(fmt)\
3576
(((fmt)&(PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA))+1)
3577
/* Return the total number of channels in a given format: 1..4 */
3578
3579
#define PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt)\
3580
((((fmt) & PNG_FORMAT_FLAG_LINEAR) >> 2)+1)
3581
/* Return the size in bytes of a single component of a pixel or color-map
3582
* entry (as appropriate) in the image: 1 or 2.
3583
*/
3584
3585
#define PNG_IMAGE_SAMPLE_SIZE(fmt)\
3586
(PNG_IMAGE_SAMPLE_CHANNELS(fmt) * PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt))
3587
/* This is the size of the sample data for one sample. If the image is
3588
* color-mapped it is the size of one color-map entry (and image pixels are
3589
* one byte in size), otherwise it is the size of one image pixel.
3590
*/
3591
3592
#define PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(fmt)\
3593
(PNG_IMAGE_SAMPLE_CHANNELS(fmt) * 256)
3594
/* The maximum size of the color-map required by the format expressed in a
3595
* count of components. This can be used to compile-time allocate a
3596
* color-map:
3597
*
3598
* png_uint_16 colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(linear_fmt)];
3599
*
3600
* png_byte colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(sRGB_fmt)];
3601
*
3602
* Alternatively use the PNG_IMAGE_COLORMAP_SIZE macro below to use the
3603
* information from one of the png_image_begin_read_ APIs and dynamically
3604
* allocate the required memory.
3605
*/
3606
3607
/* Corresponding information about the pixels */
3608
#define PNG_IMAGE_PIXEL_(test,fmt)\
3609
(((fmt)&PNG_FORMAT_FLAG_COLORMAP)?1:test(fmt))
3610
3611
#define PNG_IMAGE_PIXEL_CHANNELS(fmt)\
3612
PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_CHANNELS,fmt)
3613
/* The number of separate channels (components) in a pixel; 1 for a
3614
* color-mapped image.
3615
*/
3616
3617
#define PNG_FORMAT_CHANNELS(fmt) PNG_IMAGE_PIXEL_CHANNELS(fmt)
3618
/* Synonym for the above for use with the result of png_get_memory_format.
3619
* This exists to avoid confusion with the PNG_IMAGE_ macros which do not
3620
* work on all possible results of png_get_memory_format.
3621
*/
3622
3623
#define PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)\
3624
PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_COMPONENT_SIZE,fmt)
3625
/* The size, in bytes, of each component in a pixel; 1 for a color-mapped
3626
* image.
3627
*/
3628
3629
#define PNG_IMAGE_PIXEL_SIZE(fmt) PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_SIZE,fmt)
3630
/* The size, in bytes, of a complete pixel; 1 for a color-mapped image. */
3631
3632
/* Information about the whole row, or whole image */
3633
#define PNG_IMAGE_ROW_STRIDE(image)\
3634
(PNG_IMAGE_PIXEL_CHANNELS((image).format) * (png_alloc_size_t)(image).width)
3635
/* Return the total number of components in a single row of the image; this
3636
* is the minimum 'row stride', the minimum count of components between each
3637
* row. For a color-mapped image this is the minimum number of bytes in a
3638
* row.
3639
*
3640
* WARNING: libpng 1.7: this macro now returns a png_alloc_size_t, previous
3641
* versions returned a png_uint_32 and could overflow for images that fit in
3642
* memory. This macro can still overflow, but if it does the row will not
3643
* fit in memory. The simplified API functions detect this and refuse to
3644
* handle the image.
3645
*/
3646
3647
#define PNG_IMAGE_BUFFER_SIZE(image, row_stride)\
3648
(PNG_IMAGE_PIXEL_COMPONENT_SIZE((image).format)*(image).height*(row_stride))
3649
/* Return the size, in bytes, of an image buffer given a png_image and a row
3650
* stride - the number of components to leave space for in each row.
3651
*
3652
* WARNING: This is the total size of the image, for large images it will
3653
* overflow on a 32-bit system. In libpng 1.7 (but not before) it returns a
3654
* png_alloc_size_t which means that the result only overflows for
3655
* ridiculously large PNG files. libpng checks and will refuse to handle
3656
* such data (the PNG is probably invalid.)
3657
*
3658
* Take great care over the type of 'row_stride'; libpng assumes that the
3659
* type is png_alloc_size_t, as returned by PNG_IMAGE_ROW_STRIDE. You can
3660
* use any type you like but libpng only checks for overflow when the type is
3661
* png_alloc_size_t. In particular for png_uint_32 on a 64-bit system you
3662
* must do your own overflow checking. Cast row_stride as (png_alloc_size_t)
3663
* to avoid this (check for overflow before the cast of course!)
3664
*/
3665
3666
#define PNG_IMAGE_SIZE(image)\
3667
PNG_IMAGE_BUFFER_SIZE(image, PNG_IMAGE_ROW_STRIDE(image))
3668
/* Return the size, in bytes, of the image in memory given just a png_image;
3669
* the row stride is the minimum stride required for the image.
3670
*/
3671
3672
#define PNG_IMAGE_COLORMAP_SIZE(image)\
3673
(PNG_IMAGE_SAMPLE_SIZE((image).format) * (image).colormap_entries)
3674
/* Return the size, in bytes, of the color-map of this image. If the image
3675
* format is not a color-map format this will return a size sufficient for
3676
* 256 entries in the given format; check PNG_FORMAT_FLAG_COLORMAP if
3677
* you don't want to allocate a color-map in this case.
3678
*/
3679
3680
/* PNG_IMAGE_FLAG_*
3681
*
3682
* Flags containing additional information about the image are held in the
3683
* 'flags' field of png_image.
3684
*/
3685
#define PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB 0x01
3686
/* This indicates the the RGB values of the in-memory bitmap do not
3687
* correspond to the red, green and blue end-points defined by sRGB.
3688
*/
3689
3690
#define PNG_IMAGE_FLAG_FAST 0x02
3691
/* On write emphasise speed over compression; the resultant PNG file will be
3692
* larger but will be produced significantly faster, particular for large
3693
* images. Do not use this option for images which will be distributed, only
3694
* used it when producing intermediate files that will be read back in
3695
* repeatedly. For a typical 24-bit image the option will double the read
3696
* speed at the cost of increasing the image size by 25%, however for many
3697
* more compressible images the PNG file can be 10 times larger with only a
3698
* slight speed gain.
3699
*/
3700
3701
#define PNG_IMAGE_FLAG_16BIT_sRGB 0x04
3702
/* On read if the image is a 16-bit per component image and there is no gAMA
3703
* or sRGB chunk assume that the components are sRGB encoded. Notice that
3704
* images output by the simplified API always have gamma information; setting
3705
* this flag only affects the interpretation of 16-bit images from an
3706
* external source. It is recommended that the application expose this flag
3707
* to the user; the user can normally easily recognize the difference between
3708
* linear and sRGB encoding. This flag has no effect on write - the data
3709
* passed to the write APIs must have the correct encoding (as defined
3710
* above.)
3711
*
3712
* If the flag is not set (the default) input 16-bit per component data is
3713
* assumed to be linear.
3714
*
3715
* NOTE: the flag can only be set after the png_image_begin_read_ call,
3716
* because that call initializes the 'flags' field.
3717
*/
3718
3719
#ifdef PNG_SIMPLIFIED_READ_SUPPORTED
3720
/* READ APIs
3721
* ---------
3722
*
3723
* The png_image passed to the read APIs must have been initialized by setting
3724
* the png_controlp field 'opaque' to NULL (or, safer, memset the whole thing.)
3725
*/
3726
#ifdef PNG_STDIO_SUPPORTED
3727
PNG_EXPORT(234, int, png_image_begin_read_from_file, (png_imagep image,
3728
const char *file_name));
3729
/* The named file is opened for read and the image header is filled in
3730
* from the PNG header in the file.
3731
*/
3732
3733
PNG_EXPORT(235, int, png_image_begin_read_from_stdio, (png_imagep image,
3734
FILE* file));
3735
/* The PNG header is read from the stdio FILE object. */
3736
#endif /* STDIO */
3737
3738
PNG_EXPORT(236, int, png_image_begin_read_from_memory, (png_imagep image,
3739
png_const_voidp memory, size_t size));
3740
/* The PNG header is read from the given memory buffer. */
3741
3742
PNG_EXPORT(237, int, png_image_finish_read, (png_imagep image,
3743
png_const_colorp background, void *buffer, ptrdiff_t row_stride,
3744
void *colormap));
3745
/* Finish reading the image into the supplied buffer and clean up the
3746
* png_image structure.
3747
*
3748
* row_stride is the step, in byte or 2-byte units as appropriate,
3749
* between adjacent rows. A positive stride indicates that the top-most row
3750
* is first in the buffer - the normal top-down arrangement. A negative
3751
* stride indicates that the bottom-most row is first in the buffer.
3752
*
3753
* background need only be supplied if an alpha channel must be removed from
3754
* a png_byte format and the removal is to be done by compositing on a solid
3755
* color; otherwise it may be NULL and any composition will be done directly
3756
* onto the buffer. The value is an sRGB color to use for the background,
3757
* for grayscale output the green channel is used.
3758
*
3759
* background must be supplied when an alpha channel must be removed from a
3760
* single byte color-mapped output format, in other words if:
3761
*
3762
* 1) The original format from png_image_begin_read_from_* had
3763
* PNG_FORMAT_FLAG_ALPHA set.
3764
* 2) The format set by the application does not.
3765
* 3) The format set by the application has PNG_FORMAT_FLAG_COLORMAP set and
3766
* PNG_FORMAT_FLAG_LINEAR *not* set.
3767
*
3768
* For linear output removing the alpha channel is always done by compositing
3769
* on black and background is ignored.
3770
*
3771
* colormap must be supplied when PNG_FORMAT_FLAG_COLORMAP is set. It must
3772
* be at least the size (in bytes) returned by PNG_IMAGE_COLORMAP_SIZE.
3773
* image->colormap_entries will be updated to the actual number of entries
3774
* written to the colormap; this may be less than the original value.
3775
*/
3776
3777
PNG_EXPORT(238, void, png_image_free, (png_imagep image));
3778
/* Free any data allocated by libpng in image->opaque, setting the pointer to
3779
* NULL. May be called at any time after the structure is initialized.
3780
*/
3781
#endif /* SIMPLIFIED_READ */
3782
3783
#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED
3784
/* WRITE APIS
3785
* ----------
3786
* For write you must initialize a png_image structure to describe the image to
3787
* be written. To do this use memset to set the whole structure to 0 then
3788
* initialize fields describing your image.
3789
*
3790
* version: must be set to PNG_IMAGE_VERSION
3791
* opaque: must be initialized to NULL
3792
* width: image width in pixels
3793
* height: image height in rows
3794
* format: the format of the data (image and color-map) you wish to write
3795
* flags: set to 0 unless one of the defined flags applies; set
3796
* PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB for color format images where the RGB
3797
* values do not correspond to the colors in sRGB.
3798
* colormap_entries: set to the number of entries in the color-map (0 to 256)
3799
*/
3800
#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED
3801
PNG_EXPORT(239, int, png_image_write_to_file, (png_imagep image,
3802
const char *file, int convert_to_8bit, const void *buffer,
3803
ptrdiff_t row_stride, const void *colormap));
3804
/* Write the image to the named file. */
3805
3806
PNG_EXPORT(240, int, png_image_write_to_stdio, (png_imagep image, FILE *file,
3807
int convert_to_8_bit, const void *buffer, ptrdiff_t row_stride,
3808
const void *colormap));
3809
/* Write the image to the given (FILE*). */
3810
#endif /* SIMPLIFIED_WRITE_STDIO */
3811
3812
/* With all write APIs if image is in one of the linear formats with 16-bit
3813
* data then setting convert_to_8_bit will cause the output to be an 8-bit PNG
3814
* gamma encoded according to the sRGB specification, otherwise a 16-bit linear
3815
* encoded PNG file is written.
3816
*
3817
* With color-mapped data formats the colormap parameter point to a color-map
3818
* with at least image->colormap_entries encoded in the specified format. If
3819
* the format is linear the written PNG color-map will be converted to sRGB
3820
* regardless of the convert_to_8_bit flag.
3821
*
3822
* With all APIs row_stride is handled as in the read APIs - it is the spacing
3823
* from one row to the next in component sized units (1 or 2 bytes) and if
3824
* negative indicates a bottom-up row layout in the buffer. If row_stride is
3825
* zero, libpng will calculate it for you from the image width and number of
3826
* channels.
3827
*
3828
* Note that the write API does not support interlacing, sub-8-bit pixels or
3829
* most ancillary chunks. If you need to write text chunks (e.g. for copyright
3830
* notices) you need to use one of the other APIs.
3831
*/
3832
3833
PNG_EXPORT(245, int, png_image_write_to_memory, (png_imagep image, void *memory,
3834
png_alloc_size_t * PNG_RESTRICT memory_bytes, int convert_to_8_bit,
3835
const void *buffer, ptrdiff_t row_stride, const void *colormap));
3836
/* Write the image to the given memory buffer. The function both writes the
3837
* whole PNG data stream to *memory and updates *memory_bytes with the count
3838
* of bytes written.
3839
*
3840
* 'memory' may be NULL. In this case *memory_bytes is not read however on
3841
* success the number of bytes which would have been written will still be
3842
* stored in *memory_bytes. On failure *memory_bytes will contain 0.
3843
*
3844
* If 'memory' is not NULL it must point to memory[*memory_bytes] of
3845
* writeable memory.
3846
*
3847
* If the function returns success memory[*memory_bytes] (if 'memory' is not
3848
* NULL) contains the written PNG data. *memory_bytes will always be less
3849
* than or equal to the original value.
3850
*
3851
* If the function returns false and *memory_bytes was not changed an error
3852
* occured during write. If *memory_bytes was changed, or is not 0 if
3853
* 'memory' was NULL, the write would have succeeded but for the memory
3854
* buffer being too small. *memory_bytes contains the required number of
3855
* bytes and will be bigger that the original value.
3856
*/
3857
3858
#define png_image_write_get_memory_size(image, size, convert_to_8_bit, buffer,\
3859
row_stride, colormap)\
3860
png_image_write_to_memory(&(image), 0, &(size), convert_to_8_bit, buffer,\
3861
row_stride, colormap)
3862
/* Return the amount of memory in 'size' required to compress this image.
3863
* The png_image structure 'image' must be filled in as in the above
3864
* function and must not be changed before the actual write call, the buffer
3865
* and all other parameters must also be identical to that in the final
3866
* write call. The 'size' variable need not be initialized.
3867
*
3868
* NOTE: the macro returns true/false, if false is returned 'size' will be
3869
* set to zero and the write failed and probably will fail if tried again.
3870
*/
3871
3872
/* You can pre-allocate the buffer by making sure it is of sufficient size
3873
* regardless of the amount of compression achieved. The buffer size will
3874
* always be bigger than the original image and it will never be filled. The
3875
* following macros are provided to assist in allocating the buffer.
3876
*/
3877
#define PNG_IMAGE_DATA_SIZE(image) (PNG_IMAGE_SIZE(image)+(image).height)
3878
/* The number of uncompressed bytes in the PNG byte encoding of the image;
3879
* uncompressing the PNG IDAT data will give this number of bytes.
3880
*/
3881
#ifndef PNG_ZLIB_MAX_SIZE
3882
# define PNG_ZLIB_MAX_SIZE(b) ((b)+(((b)+7U)>>3)+(((b)+63U)>>6)+11U)
3883
/* An upper bound on the number of compressed bytes given 'b' uncompressed
3884
* bytes. This is based on deflateBounds() in zlib; different
3885
* implementations of zlib compression may conceivably produce more data so
3886
* if your zlib implementation is not zlib itself redefine this macro
3887
* appropriately.
3888
*/
3889
#endif
3890
3891
#define PNG_IMAGE_COMPRESSED_SIZE_MAX(image)\
3892
PNG_ZLIB_MAX_SIZE((png_alloc_size_t)PNG_IMAGE_DATA_SIZE(image))
3893
/* An upper bound on the size of the data in the PNG IDAT chunks. */
3894
3895
#define PNG_IMAGE_PNG_SIZE_MAX_(image, image_size)\
3896
((8U/*sig*/+25U/*IHDR*/+16U/*gAMA*/+44U/*cHRM*/+12U/*IEND*/+\
3897
(((image).format&PNG_FORMAT_FLAG_COLORMAP)?/*colormap: PLTE, tRNS*/\
3898
12U+3U*(image).colormap_entries/*PLTE data*/+\
3899
(((image).format&PNG_FORMAT_FLAG_ALPHA)?\
3900
12U/*tRNS*/+(image).colormap_entries:0U):0U)+\
3901
12U)+(12U*((image_size)/PNG_ZBUF_SIZE))/*IDAT*/+(image_size))
3902
/* A helper for the following macro; if your compiler cannot handle the
3903
* following macro use this one with the result of
3904
* PNG_IMAGE_COMPRESSED_SIZE_MAX(image) as the second argument (most
3905
* compilers should handle this just fine.)
3906
*/
3907
3908
#define PNG_IMAGE_PNG_SIZE_MAX(image)\
3909
PNG_IMAGE_PNG_SIZE_MAX_(image, PNG_IMAGE_COMPRESSED_SIZE_MAX(image))
3910
/* An upper bound on the total length of the PNG data stream for 'image'.
3911
* The result is of type png_alloc_size_t, on 32-bit systems this may
3912
* overflow even though PNG_IMAGE_DATA_SIZE does not overflow; the write will
3913
* run out of buffer space but return a corrected size which should work.
3914
*
3915
* NOTE: while PNG_IMAGE_SIZE cannot overflow for an image in memory this
3916
* macro can because of the extra bytes used in the PNG byte encoding. You
3917
* need to avoid this macro if your image size approaches the limit of your
3918
* system memory; typically the maximum value of size_t. Use the above
3919
* function call instead.
3920
*/
3921
#endif /* SIMPLIFIED_WRITE */
3922
/*******************************************************************************
3923
* END OF SIMPLIFIED API
3924
******************************************************************************/
3925
3926
/*******************************************************************************
3927
* Section 6: IMPLEMENTATION OPTIONS
3928
*******************************************************************************
3929
*
3930
* Change of options used during read and/or write.
3931
*
3932
* A number of internal options can (but do not need to be) changed to
3933
* fine tune the implementation. These options control such things as the
3934
* precise settings for compression, the accuracy of arithmetic used internally
3935
* for image processing operations (gamma transformations) and, in some cases,
3936
* the specific implementations (hardware or software optimizations.)
3937
*
3938
* To avoid API proliferation there is a single general API (new in 1.7) to do
3939
* this. When a particular option is not supported by the build in libpng an
3940
* attempt to set it will return a failure code but will be totally ignored
3941
* unless the PNG_SF_ERROR flag is set (see below).
3942
*/
3943
PNG_EXPORT(249, png_int_32, png_setting, (png_structrp png_ptr,
3944
png_uint_32 setting, png_uint_32 parameter, png_int_32 value));
3945
/* Alter setting 'setting' using the values of 'parameter' and 'value'. The
3946
* result is either one of the following failure codes or a setting/parameter
3947
* specific result code.
3948
*
3949
* The failure codes match the POSIX 1003.1 <errno.h> values (section 2.5,
3950
* error numbers) with a preceding PNG_. (png_uint_32)result gives a number
3951
* in the range 0x80000001U to 0x8000000fU.
3952
*/
3953
# define PNG_EBADF (-0x7fffffff) /* read/write error */
3954
/* An attempt was made to apply a read setting to a write structure or
3955
* vice versa.
3956
*/
3957
# define PNG_EINVAL (-0x7ffffffe) /* invalid argument */
3958
/* 'png_ptr' was NULL or 'parameter' or 'value' is invalid for the given
3959
* setting.
3960
*/
3961
# define PNG_EDOM (-0x7ffffffd) /* out of range */
3962
/* Either 'parameter' or 'value' is out of range for the given setting
3963
* (only returned when paramter or value are used and are numeric; for
3964
* flag values PNG_EINVAL will be returned.)
3965
*/
3966
# define PNG_ENOSYS (-0x7ffffff1) /* unsupported setting/param */
3967
/* The setting was not recognized; typically this means that libpng was
3968
* built without the appropriate support.
3969
*/
3970
# define PNG_UNSUPPORTED_SETTING PNG_ENOSYS
3971
/* For backware compatibility with earlier libpng versions and
3972
* 'png_set_option' return codes.
3973
*/
3974
# define PNG_UNSET (-0x7ffffff0) /* NOT an erro code: no previous setting */
3975
/* The setting was not (previously) set. Returned when there is no built
3976
* in default for a setting. Normally this means that the default will
3977
* depend on other settings or the PNG itself.
3978
*/
3979
/* Results larger (more positive) than PNG_ENOSYS are success codes (even if
3980
* negative). The value is interpreted as follows (as defined by the
3981
* setting):
3982
*
3983
* 1) A signed 31-bit number in the range -0x7fffffef to +0x7fffffff
3984
* 2) An unsigned 31 bit number in the range 0U to 0x7fffffffU
3985
* 3) An unsigned 32 bit bit set/flag value in the range 0U to 0xfffffffU
3986
* but excluding values in the range 0x80000000U to 0x80000000FU
3987
* encoded as follows:
3988
*
3989
* if (v <= 0x7fffffffU)
3990
* v
3991
* else if (v > 0x8000000FU)
3992
* -(png_int_32)-v
3993
*
3994
* The result can be converted by to the original (png_uint_32) simply
3995
* by casting it as such.
3996
*/
3997
# define PNG_FAILED(result) ((result) <= PNG_ENOSYS)
3998
/* The setting did not take; this includes both errors making the setting
3999
* (e.g. parameter or value errors) and unsupported settings. Check the
4000
* result code itself for more information.
4001
*/
4002
# define PNG_OK(result) ((result) > PNG_ENOSYS)
4003
/* The setting succeeded; the result is a return code which depends on the
4004
* particular setting. (E.g. it might be a return code or it might be the
4005
* previous value.)
4006
*/
4007
4008
/* SETTING VALUES (generic)
4009
*
4010
* These are flag values that are added to the setting definitions below to
4011
* simplify processing inside libpng and self-document the setting behavior.
4012
* All these values have the prefix PNG_SF_
4013
*/
4014
#define PNG_SF_ERROR (0x80000000U)
4015
/* If this is set on the 'setting' argument to png_setting and a failure code
4016
* would otherwise be returned call png_error instead. This is a convenience
4017
* for applications that do not want to check the result code. It is never
4018
* set by default. The error string is cryptic.
4019
*/
4020
#define PNG_SF_GET (0x40000000U)
4021
/* Do not set the setting. With most settings this just allows for the
4022
* presence of support for the setting to be checked at run time; if the
4023
* setting is not support PNG_ENOSYS will be returned.
4024
*
4025
* With some settings checking of the parameter or value may be done, but
4026
* there is no guarantee, so always supply valid parameter and value.
4027
*
4028
* With some settings the current setting is returned. This is typically
4029
* only done when the default setting is configurable and not even always
4030
* then. If the setting does this it will document the behavior.
4031
*/
4032
#define PNG_SF_READ (0x20000000U)
4033
/* The setting may be applied to a read png_struct. If this is not set and
4034
* an attempt is made to apply the setting to a read struct
4035
* PNG_EBADF will be returned.
4036
*/
4037
#define PNG_SF_WRITE (0x10000000U)
4038
/* The setting may be applied to a write png_struct. If this is not set
4039
* and an attempt is made to apply the setting to a write struct
4040
* PNG_EBADF will be returned.
4041
*/
4042
4043
/*********************************** WRITE ************************************/
4044
/* WRITE COMPRESSION SUPPORT
4045
*
4046
* These settings are normally accessed using the macros that are defined above;
4047
* the function-like macros replace the API calls present in previous versions
4048
* of libpng.
4049
*
4050
* 'setting' is as follows, 'parameter' is a chunk name; png_IDAT for IDAT
4051
* compression, png_iCCP for iCCP chunk compression png_zTXt for zTZt *and* iTXt
4052
* text chunk compression. Other values must not be used; they will result in
4053
* PNG_ENOSYS at present but may alter compression of new chunks in the future.
4054
*
4055
* The value is the new compression setting. The result is is the old
4056
* compression setting or an error code. Compression settings are documented
4057
* in text above describing the function-like macros. PNG_UNSET is returned
4058
* when the setting was not previously set; in this case the default may vary
4059
* according to the actual data (e.g. length, PNG format).
4060
*
4061
* 0 is valid as a parameter if PNG_SF_GET is set, in that case the current or
4062
* last setting is returned.
4063
*/
4064
#define PNG_SW_COMPRESS_zlib_level (PNG_SF_WRITE + 0U)
4065
#define PNG_SW_COMPRESS_windowBits (PNG_SF_WRITE + 1U)
4066
#define PNG_SW_COMPRESS_memLevel (PNG_SF_WRITE + 2U)
4067
#define PNG_SW_COMPRESS_strategy (PNG_SF_WRITE + 3U)
4068
#define PNG_SW_COMPRESS_png_level (PNG_SF_WRITE + 4U)
4069
#define PNG_SW_COMPRESS_method (PNG_SF_WRITE + 5U)
4070
4071
/* WRITE IDAT size.
4072
*
4073
* The size of the IDAT chunks that are written (the last may be smaller).
4074
*/
4075
#define PNG_SW_IDAT_size (PNG_SF_WRITE + 6U)
4076
4077
/* WRITE FILTER CONTROL
4078
*
4079
* These settings are used by png_set_filter and png_set_row_buffers to control
4080
* the filters used during compression. The 'filters' setting has two arguments
4081
* however the first is the filter method (or type) and must be 0 for PNG.
4082
* Standards based on PNG may define additional values, as with other base file
4083
* characteristics such as the compression type, however the result would not be
4084
* a PNG.
4085
*/
4086
#define PNG_SW_COMPRESS_filters (PNG_SF_WRITE + 7U)
4087
#define PNG_SW_COMPRESS_row_buffers (PNG_SF_WRITE + 8U)
4088
4089
/* WRITE ROW FLUSH CONTROL
4090
*
4091
* This sets the number of rows between flush calls. '0' was used to indicate
4092
* no flushing (before the end). The maximum number of rows in a PNG is
4093
* actually greater than the maximum of a 31-bit integer for interlaced images,
4094
* however this doesn't matter much; the number of rows was always declared as
4095
* 'int', so it is still passed in the 'value' argument.
4096
*/
4097
#define PNG_SW_FLUSH (PNG_SF_WRITE + 9U)
4098
4099
/*********************************** READ *************************************/
4100
/* The size of the buffer used while reading IDAT chunks and, potentially, other
4101
* compressed chunks.
4102
*/
4103
#define PNG_SR_COMPRESS_buffer_size (PNG_SF_READ + 1U)
4104
/* Read compressed data buffer size, in 'parameter'. The result is 0. */
4105
4106
#define PNG_SR_GAMMA_threshold (PNG_SF_READ + 2U)
4107
#define png_set_gamma_threshold(png_ptr, threshold)\
4108
(png_setting((png_ptr), PNG_SR_GAMMA_threshold, (threshold), 0))
4109
/* SETTING: threshold below which gamma correction is not done, the default
4110
* (set when the library is built) is PNG_GAMMA_THRESHOLD_FIXED, the
4111
* 'parameter' is a png_fixed_point number, the difference from PNG_FP_1
4112
* above which gamma correction will be performed.
4113
*
4114
* The value '153' is sufficient to maintain 1% accuracy in 16-bit linear
4115
* calculations over a 655:1 range; over the maximum range possible with the
4116
* 16-bit linear representation. Reasonable values are:
4117
*
4118
* 0: always do gamma correction, even if the gamma values are
4119
* identical. The only point to this is to avoid a bug in the
4120
* optimized (no gamma correction) code path, or for testing.
4121
* 2: always do gamma correction if there is any significant
4122
* difference. Notice that '1' will result in gamma correction in
4123
* many cases when the screen gamma is the inverse of the encoding
4124
* gamma because of inaccuracies in the representation of gamma.
4125
* 153: do gamma correction if it is needed to maintain the accuracy of
4126
* 16-bit linear calculations at 1% or below.
4127
* 216: maintain 1% accuracy over a 100:1 dynamic range in 16-bit linear
4128
* calculations. This matches the widely accepted numbers for human
4129
* perception of differences within an image, however that doesn't
4130
* mean that such high accuracy is required to avoid artefacts; such
4131
* accuracy (such a low number) is only required if versions of the
4132
* same image with and without gamma correction are to be compared
4133
* visually.
4134
* 5000: this is the default from libpng 1.6 and earlier. Using this
4135
* produces changes in image contrast that are visible when suitable
4136
* images are compared side-by-side however they are not obvious and
4137
* it is inconceivable that a user would notice the change unless
4138
* the user was very familiar with the image and the viewing
4139
* environment.
4140
*
4141
* Values between 216 and 5000 produce varying very small changes in image
4142
* contrast. Values above 10,000 (10%) produce noticeable increase or
4143
* decrease in contrast which will probably change how the image is
4144
* perceived. There is an internal limit on the maximum value which is
4145
* currently 65%; PNG_EDOM will be returned for higher values.
4146
*
4147
* The result is the value that was set.
4148
*/
4149
#if 0 /*NYI*/
4150
#define PNG_SR_GAMMA_accuracy /*NYI*/
4151
/* SETTING: controls the accuracy of the gamma calculations when the results
4152
* are cached. The default is PNG_DEFAULT_GAMMA_ACCURACY. The number is 100
4153
* times the number of bits, 'b', used in the internal tables when the input
4154
* is linear, permitted values are 0..1600 however '0' causes the caching to
4155
* be skipped entirely (so gives maximum accuracy with no caching!)
4156
*
4157
* The accuracy in the linear domain for a value 'a' is:
4158
*
4159
* +/-(.5/2^a)
4160
*
4161
* so for the default-default of 665 this means the accuracy is +/-0.5% and
4162
* this ensures that almost-equal input values do not differ by more than 1%
4163
* in the output, meeting the accepted requirement for human vision.
4164
*
4165
* The default value has no effect on input narrower than 16 bits. For n-bit
4166
* input the total table size is ((n-v)+1)*(2^v), where 'v' is a/gamma and
4167
* 'gamma' is the gamma encoding of the input:
4168
*
4169
* n a gamma 'v' table size
4170
* 8 6.65 .45455 14.6 256
4171
* 16 6.65 .45455 14.6 65536
4172
* 16 6.65 1.0 6.65 1280
4173
* 16 6 1.0 6 704
4174
* 16 5 1.0 5 384
4175
*/
4176
#endif /*NYI*/
4177
4178
#define PNG_SR_CRC_ACTION (PNG_SF_READ + 4U)
4179
/* 'parameter' is what to do with critical chunks, 'value' is what to do with
4180
* ancillary ones when the CRC does not match on read. 0 is returned. See
4181
* png_set_crc_action for more information.
4182
*/
4183
4184
/*********************************** OPTIONS **********************************/
4185
/* png_set_option is implemented via png_setting to provide API compatibility
4186
* with releases prior to 1.7.0
4187
*/
4188
/* HARDWARE OPTIMIZATIONS
4189
*
4190
* Normally hardware capabilites, such as the Intel SSE instructions, are
4191
* detected at run time, however sometimes it may be impossible to do this in
4192
* user mode, in which case it is necessary to discover the capabilities in an
4193
* OS specific way. Such capabilities are listed here when libpng has support
4194
* for them and must be turned ON by the application if present. Check
4195
* pnglibconf.h for options appropriate to your hardware.
4196
*
4197
* In general 'PNG_EXTENSIONS' controls hardware optimizations; these are not
4198
* supported parts of libpng and, if there are problems with them, bugs should
4199
* be ported to the implementers. Depending on the configuration it may not be
4200
* possible to disable extensions at run time.
4201
*/
4202
#define PNG_SRW_OPTION (PNG_SF_READ+PNG_SF_WRITE + 0U)
4203
#ifdef PNG_SET_OPTION_SUPPORTED
4204
PNG_REMOVED(244, int, png_set_option, (png_structrp png_ptr, int option,
4205
int onoff), PNG_EMPTY)
4206
4207
#define png_set_option(p, opt, onoff)\
4208
(png_setting((p), PNG_SRW_OPTION, (opt), (onoff)))
4209
/* Pre 1.7 API; in 1.7 the result values have changed numerically but not by
4210
* name. For backward API compatibility this setting only returns one error
4211
* code, PNG_ENOSYS and that only for option numbers out of range, otherwise
4212
* if the option isn't supported PNG_OPTION_UNSET (PNG_UNSET) is returned.
4213
*/
4214
#endif /* SET_OPTION */
4215
#define PNG_OPTION_UNSET PNG_UNSET /* Unset - defaults to off */
4216
#define PNG_OPTION_INVALID PNG_ENOSYS /* Option number out of range */
4217
#define PNG_OPTION_OFF 0
4218
#define PNG_OPTION_ON 1
4219
4220
/* Specific options: */
4221
#define PNG_EXTENSIONS 0 /* HARDWARE: switch extensions on or off */
4222
#define PNG_MAXIMUM_INFLATE_WINDOW 2 /* SOFTWARE: force maximum window */
4223
#define PNG_SKIP_sRGB_CHECK_PROFILE 4 /* SOFTWARE: Check ICC profile for sRGB */
4224
#define PNG_OPTION_NEXT 6 /* Next option - numbers are even */
4225
4226
#define PNG_SRW_CHECK_FOR_INVALID_INDEX (PNG_SF_READ+PNG_SF_WRITE + 1U)
4227
/* Turn the palette index check on or off; see
4228
* png_set_check_for_invalid_index above.
4229
*/
4230
4231
#define PNG_SRW_ERROR_HANDLING (PNG_SF_READ+PNG_SF_WRITE + 2U)
4232
/* Change the action on issues that can be handled. */
4233
4234
/*******************************************************************************
4235
* END OF HARDWARE OPTIONS
4236
******************************************************************************/
4237
4238
/* The last ordinal number (this is the *last* one already used; the next
4239
* one to use is one more than this.) Maintainer, remember to add an entry to
4240
* scripts/symbols.def as well.
4241
*/
4242
#ifdef PNG_EXPORT_LAST_ORDINAL
4243
PNG_EXPORT_LAST_ORDINAL(249);
4244
#endif
4245
4246
#ifdef __cplusplus
4247
}
4248
#endif
4249
4250
#endif /* PNG_VERSION_INFO_ONLY */
4251
/* Do not put anything past this line */
4252
#endif /* PNG_H */
4253
4254