Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/libpng/pngstruct.h
9833 views
1
/* pngstruct.h - internal structures for libpng
2
*
3
* Copyright (c) 2018-2025 Cosmin Truta
4
* Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
5
* Copyright (c) 1996-1997 Andreas Dilger
6
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
7
*
8
* This code is released under the libpng license.
9
* For conditions of distribution and use, see the disclaimer
10
* and license in png.h
11
*/
12
13
#ifndef PNGPRIV_H
14
# error This file must not be included by applications; please include <png.h>
15
#endif
16
17
#ifndef PNGSTRUCT_H
18
#define PNGSTRUCT_H
19
/* zlib.h defines the structure z_stream, an instance of which is included
20
* in this structure and is required for decompressing the LZ compressed
21
* data in PNG files.
22
*/
23
#ifndef ZLIB_CONST
24
/* We must ensure that zlib uses 'const' in declarations. */
25
# define ZLIB_CONST
26
#endif
27
#include "zlib.h"
28
#ifdef const
29
/* zlib.h sometimes #defines const to nothing, undo this. */
30
# undef const
31
#endif
32
33
/* zlib.h has mediocre z_const use before 1.2.6, this stuff is for compatibility
34
* with older builds.
35
*/
36
#if ZLIB_VERNUM < 0x1260
37
# define PNGZ_MSG_CAST(s) png_constcast(char*,s)
38
# define PNGZ_INPUT_CAST(b) png_constcast(png_bytep,b)
39
#else
40
# define PNGZ_MSG_CAST(s) (s)
41
# define PNGZ_INPUT_CAST(b) (b)
42
#endif
43
44
/* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib
45
* can handle at once. This type need be no larger than 16 bits (so maximum of
46
* 65535), this define allows us to discover how big it is, but limited by the
47
* maximum for size_t. The value can be overridden in a library build
48
* (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably
49
* lower value (e.g. 255 works). A lower value may help memory usage (slightly)
50
* and may even improve performance on some systems (and degrade it on others.)
51
*/
52
#ifndef ZLIB_IO_MAX
53
# define ZLIB_IO_MAX ((uInt)-1)
54
#endif
55
56
#ifdef PNG_WRITE_SUPPORTED
57
/* The type of a compression buffer list used by the write code. */
58
typedef struct png_compression_buffer
59
{
60
struct png_compression_buffer *next;
61
png_byte output[1]; /* actually zbuf_size */
62
} png_compression_buffer, *png_compression_bufferp;
63
64
#define PNG_COMPRESSION_BUFFER_SIZE(pp)\
65
(offsetof(png_compression_buffer, output) + (pp)->zbuffer_size)
66
#endif
67
68
/* Colorspace support; structures used in png_struct, png_info and in internal
69
* functions to hold and communicate information about the color space.
70
*/
71
/* The chromaticities of the red, green and blue colorants and the chromaticity
72
* of the corresponding white point (i.e. of rgb(1.0,1.0,1.0)).
73
*/
74
typedef struct png_xy
75
{
76
png_fixed_point redx, redy;
77
png_fixed_point greenx, greeny;
78
png_fixed_point bluex, bluey;
79
png_fixed_point whitex, whitey;
80
} png_xy;
81
82
/* The same data as above but encoded as CIE XYZ values. When this data comes
83
* from chromaticities the sum of the Y values is assumed to be 1.0
84
*/
85
typedef struct png_XYZ
86
{
87
png_fixed_point red_X, red_Y, red_Z;
88
png_fixed_point green_X, green_Y, green_Z;
89
png_fixed_point blue_X, blue_Y, blue_Z;
90
} png_XYZ;
91
92
/* Chunk index values as an enum, PNG_INDEX_unknown is also a count of the
93
* number of chunks.
94
*/
95
#define PNG_CHUNK(cHNK, i) PNG_INDEX_ ## cHNK = (i),
96
typedef enum
97
{
98
PNG_KNOWN_CHUNKS
99
PNG_INDEX_unknown
100
} png_index;
101
#undef PNG_CHUNK
102
103
/* Chunk flag values. These are (png_uint_32 values) with exactly one bit set
104
* and can be combined into a flag set with bitwise 'or'.
105
*
106
* TODO: C23: convert these macros to C23 inlines (which are static).
107
*/
108
#define png_chunk_flag_from_index(i) (0x80000000U >> (31 - (i)))
109
/* The flag coresponding to the given png_index enum value. This is defined
110
* for png_unknown as well (until it reaches the value 32) but this should
111
* not be relied on.
112
*/
113
114
#define png_file_has_chunk(png_ptr, i)\
115
(((png_ptr)->chunks & png_chunk_flag_from_index(i)) != 0)
116
/* The chunk has been recorded in png_struct */
117
118
#define png_file_add_chunk(pnt_ptr, i)\
119
((void)((png_ptr)->chunks |= png_chunk_flag_from_index(i)))
120
/* Record the chunk in the png_struct */
121
122
struct png_struct_def
123
{
124
#ifdef PNG_SETJMP_SUPPORTED
125
jmp_buf jmp_buf_local; /* New name in 1.6.0 for jmp_buf in png_struct */
126
png_longjmp_ptr longjmp_fn;/* setjmp non-local goto function. */
127
jmp_buf *jmp_buf_ptr; /* passed to longjmp_fn */
128
size_t jmp_buf_size; /* size of the above, if allocated */
129
#endif
130
png_error_ptr error_fn; /* function for printing errors and aborting */
131
#ifdef PNG_WARNINGS_SUPPORTED
132
png_error_ptr warning_fn; /* function for printing warnings */
133
#endif
134
png_voidp error_ptr; /* user supplied struct for error functions */
135
png_rw_ptr write_data_fn; /* function for writing output data */
136
png_rw_ptr read_data_fn; /* function for reading input data */
137
png_voidp io_ptr; /* ptr to application struct for I/O functions */
138
139
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
140
png_user_transform_ptr read_user_transform_fn; /* user read transform */
141
#endif
142
143
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
144
png_user_transform_ptr write_user_transform_fn; /* user write transform */
145
#endif
146
147
/* These were added in libpng-1.0.2 */
148
#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
149
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
150
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
151
png_voidp user_transform_ptr; /* user supplied struct for user transform */
152
png_byte user_transform_depth; /* bit depth of user transformed pixels */
153
png_byte user_transform_channels; /* channels in user transformed pixels */
154
#endif
155
#endif
156
157
png_uint_32 mode; /* tells us where we are in the PNG file */
158
png_uint_32 flags; /* flags indicating various things to libpng */
159
png_uint_32 transformations; /* which transformations to perform */
160
161
png_uint_32 zowner; /* ID (chunk type) of zstream owner, 0 if none */
162
z_stream zstream; /* decompression structure */
163
164
#ifdef PNG_WRITE_SUPPORTED
165
png_compression_bufferp zbuffer_list; /* Created on demand during write */
166
uInt zbuffer_size; /* size of the actual buffer */
167
168
int zlib_level; /* holds zlib compression level */
169
int zlib_method; /* holds zlib compression method */
170
int zlib_window_bits; /* holds zlib compression window bits */
171
int zlib_mem_level; /* holds zlib compression memory level */
172
int zlib_strategy; /* holds zlib compression strategy */
173
#endif
174
/* Added at libpng 1.5.4 */
175
#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
176
int zlib_text_level; /* holds zlib compression level */
177
int zlib_text_method; /* holds zlib compression method */
178
int zlib_text_window_bits; /* holds zlib compression window bits */
179
int zlib_text_mem_level; /* holds zlib compression memory level */
180
int zlib_text_strategy; /* holds zlib compression strategy */
181
#endif
182
/* End of material added at libpng 1.5.4 */
183
/* Added at libpng 1.6.0 */
184
#ifdef PNG_WRITE_SUPPORTED
185
int zlib_set_level; /* Actual values set into the zstream on write */
186
int zlib_set_method;
187
int zlib_set_window_bits;
188
int zlib_set_mem_level;
189
int zlib_set_strategy;
190
#endif
191
192
png_uint_32 chunks; /* PNG_CF_ for every chunk read or (NYI) written */
193
# define png_has_chunk(png_ptr, cHNK)\
194
png_file_has_chunk(png_ptr, PNG_INDEX_ ## cHNK)
195
/* Convenience accessor - use this to check for a known chunk by name */
196
197
png_uint_32 width; /* width of image in pixels */
198
png_uint_32 height; /* height of image in pixels */
199
png_uint_32 num_rows; /* number of rows in current pass */
200
png_uint_32 usr_width; /* width of row at start of write */
201
size_t rowbytes; /* size of row in bytes */
202
png_uint_32 iwidth; /* width of current interlaced row in pixels */
203
png_uint_32 row_number; /* current row in interlace pass */
204
png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */
205
png_bytep prev_row; /* buffer to save previous (unfiltered) row.
206
* While reading this is a pointer into
207
* big_prev_row; while writing it is separately
208
* allocated if needed.
209
*/
210
png_bytep row_buf; /* buffer to save current (unfiltered) row.
211
* While reading, this is a pointer into
212
* big_row_buf; while writing it is separately
213
* allocated.
214
*/
215
#ifdef PNG_WRITE_FILTER_SUPPORTED
216
png_bytep try_row; /* buffer to save trial row when filtering */
217
png_bytep tst_row; /* buffer to save best trial row when filtering */
218
#endif
219
size_t info_rowbytes; /* Added in 1.5.4: cache of updated row bytes */
220
221
png_uint_32 idat_size; /* current IDAT size for read */
222
png_uint_32 crc; /* current chunk CRC value */
223
png_colorp palette; /* palette from the input file */
224
png_uint_16 num_palette; /* number of color entries in palette */
225
226
/* Added at libpng-1.5.10 */
227
#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
228
int num_palette_max; /* maximum palette index found in IDAT */
229
#endif
230
231
png_uint_16 num_trans; /* number of transparency values */
232
png_byte compression; /* file compression type (always 0) */
233
png_byte filter; /* file filter type (always 0) */
234
png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
235
png_byte pass; /* current interlace pass (0 - 6) */
236
png_byte do_filter; /* row filter flags (see PNG_FILTER_ in png.h ) */
237
png_byte color_type; /* color type of file */
238
png_byte bit_depth; /* bit depth of file */
239
png_byte usr_bit_depth; /* bit depth of users row: write only */
240
png_byte pixel_depth; /* number of bits per pixel */
241
png_byte channels; /* number of channels in file */
242
#ifdef PNG_WRITE_SUPPORTED
243
png_byte usr_channels; /* channels at start of write: write only */
244
#endif
245
png_byte sig_bytes; /* magic bytes read/written from start of file */
246
png_byte maximum_pixel_depth;
247
/* pixel depth used for the row buffers */
248
png_byte transformed_pixel_depth;
249
/* pixel depth after read/write transforms */
250
#if ZLIB_VERNUM >= 0x1240
251
png_byte zstream_start; /* at start of an input zlib stream */
252
#endif /* Zlib >= 1.2.4 */
253
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
254
png_uint_16 filler; /* filler bytes for pixel expansion */
255
#endif
256
257
#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
258
defined(PNG_READ_ALPHA_MODE_SUPPORTED)
259
png_byte background_gamma_type;
260
png_fixed_point background_gamma;
261
png_color_16 background; /* background color in screen gamma space */
262
#ifdef PNG_READ_GAMMA_SUPPORTED
263
png_color_16 background_1; /* background normalized to gamma 1.0 */
264
#endif
265
#endif /* bKGD */
266
267
#ifdef PNG_WRITE_FLUSH_SUPPORTED
268
png_flush_ptr output_flush_fn; /* Function for flushing output */
269
png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
270
png_uint_32 flush_rows; /* number of rows written since last flush */
271
#endif
272
273
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
274
png_xy chromaticities; /* From mDVC, cICP, [iCCP], sRGB or cHRM */
275
#endif
276
277
#ifdef PNG_READ_GAMMA_SUPPORTED
278
int gamma_shift; /* number of "insignificant" bits in 16-bit gamma */
279
png_fixed_point screen_gamma; /* screen gamma value (display exponent) */
280
png_fixed_point file_gamma; /* file gamma value (encoding exponent) */
281
png_fixed_point chunk_gamma; /* from cICP, iCCP, sRGB or gAMA */
282
png_fixed_point default_gamma;/* from png_set_alpha_mode */
283
284
png_bytep gamma_table; /* gamma table for 8-bit depth files */
285
png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
286
#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
287
defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
288
defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
289
png_bytep gamma_from_1; /* converts from 1.0 to screen */
290
png_bytep gamma_to_1; /* converts from file to 1.0 */
291
png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
292
png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
293
#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
294
#endif /* READ_GAMMA */
295
296
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
297
png_color_8 sig_bit; /* significant bits in each available channel */
298
#endif
299
300
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
301
png_color_8 shift; /* shift for significant bit transformation */
302
#endif
303
304
#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
305
|| defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
306
png_bytep trans_alpha; /* alpha values for paletted files */
307
png_color_16 trans_color; /* transparent color for non-paletted files */
308
#endif
309
310
png_read_status_ptr read_row_fn; /* called after each row is decoded */
311
png_write_status_ptr write_row_fn; /* called after each row is encoded */
312
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
313
png_progressive_info_ptr info_fn; /* called after header data fully read */
314
png_progressive_row_ptr row_fn; /* called after a prog. row is decoded */
315
png_progressive_end_ptr end_fn; /* called after image is complete */
316
png_bytep save_buffer_ptr; /* current location in save_buffer */
317
png_bytep save_buffer; /* buffer for previously read data */
318
png_bytep current_buffer_ptr; /* current location in current_buffer */
319
png_bytep current_buffer; /* buffer for recently used data */
320
png_uint_32 push_length; /* size of current input chunk */
321
png_uint_32 skip_length; /* bytes to skip in input data */
322
size_t save_buffer_size; /* amount of data now in save_buffer */
323
size_t save_buffer_max; /* total size of save_buffer */
324
size_t buffer_size; /* total amount of available input data */
325
size_t current_buffer_size; /* amount of data now in current_buffer */
326
int process_mode; /* what push library is currently doing */
327
int cur_palette; /* current push library palette index */
328
#endif /* PROGRESSIVE_READ */
329
330
#ifdef PNG_READ_QUANTIZE_SUPPORTED
331
png_bytep palette_lookup; /* lookup table for quantizing */
332
png_bytep quantize_index; /* index translation for palette files */
333
#endif
334
335
/* Options */
336
#ifdef PNG_SET_OPTION_SUPPORTED
337
png_uint_32 options; /* On/off state (up to 16 options) */
338
#endif
339
340
#if PNG_LIBPNG_VER < 10700
341
/* To do: remove this from libpng-1.7 */
342
#ifdef PNG_TIME_RFC1123_SUPPORTED
343
char time_buffer[29]; /* String to hold RFC 1123 time text */
344
#endif /* TIME_RFC1123 */
345
#endif /* LIBPNG_VER < 10700 */
346
347
/* New members added in libpng-1.0.6 */
348
349
png_uint_32 free_me; /* flags items libpng is responsible for freeing */
350
351
#ifdef PNG_USER_CHUNKS_SUPPORTED
352
png_voidp user_chunk_ptr;
353
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
354
png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
355
#endif /* READ_USER_CHUNKS */
356
#endif /* USER_CHUNKS */
357
358
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
359
int unknown_default; /* As PNG_HANDLE_* */
360
unsigned int num_chunk_list; /* Number of entries in the list */
361
png_bytep chunk_list; /* List of png_byte[5]; the textual chunk name
362
* followed by a PNG_HANDLE_* byte */
363
#endif
364
365
/* New members added in libpng-1.0.3 */
366
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
367
png_byte rgb_to_gray_status;
368
/* Added in libpng 1.5.5 to record setting of coefficients: */
369
png_byte rgb_to_gray_coefficients_set;
370
/* These were changed from png_byte in libpng-1.0.6 */
371
png_uint_16 rgb_to_gray_red_coeff;
372
png_uint_16 rgb_to_gray_green_coeff;
373
/* deleted in 1.5.5: rgb_to_gray_blue_coeff; */
374
#endif
375
376
/* New member added in libpng-1.6.36 */
377
#if defined(PNG_READ_EXPAND_SUPPORTED) && \
378
defined(PNG_ARM_NEON_IMPLEMENTATION)
379
png_bytep riffled_palette; /* buffer for accelerated palette expansion */
380
#endif
381
382
/* New member added in libpng-1.0.4 (renamed in 1.0.9) */
383
#if defined(PNG_MNG_FEATURES_SUPPORTED)
384
/* Changed from png_byte to png_uint_32 at version 1.2.0 */
385
png_uint_32 mng_features_permitted;
386
#endif
387
388
/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */
389
#ifdef PNG_MNG_FEATURES_SUPPORTED
390
png_byte filter_type;
391
#endif
392
393
/* New members added in libpng-1.2.0 */
394
395
/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */
396
#ifdef PNG_USER_MEM_SUPPORTED
397
png_voidp mem_ptr; /* user supplied struct for mem functions */
398
png_malloc_ptr malloc_fn; /* function for allocating memory */
399
png_free_ptr free_fn; /* function for freeing memory */
400
#endif
401
402
/* New member added in libpng-1.0.13 and 1.2.0 */
403
png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
404
405
#ifdef PNG_READ_QUANTIZE_SUPPORTED
406
/* The following three members were added at version 1.0.14 and 1.2.4 */
407
png_bytep quantize_sort; /* working sort array */
408
png_bytep index_to_palette; /* where the original index currently is
409
in the palette */
410
png_bytep palette_to_index; /* which original index points to this
411
palette color */
412
#endif
413
414
/* New members added in libpng-1.0.16 and 1.2.6 */
415
png_byte compression_type;
416
417
#ifdef PNG_USER_LIMITS_SUPPORTED
418
png_uint_32 user_width_max;
419
png_uint_32 user_height_max;
420
421
/* Added in libpng-1.4.0: Total number of sPLT, text, and unknown
422
* chunks that can be stored (0 means unlimited).
423
*/
424
png_uint_32 user_chunk_cache_max;
425
426
/* Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk
427
* can occupy when decompressed. 0 means unlimited.
428
*/
429
png_alloc_size_t user_chunk_malloc_max;
430
#endif
431
432
/* New member added in libpng-1.0.25 and 1.2.17 */
433
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
434
/* Temporary storage for unknown chunk that the library doesn't recognize,
435
* used while reading the chunk.
436
*/
437
png_unknown_chunk unknown_chunk;
438
#endif
439
440
/* New member added in libpng-1.2.26 */
441
size_t old_big_row_buf_size;
442
443
#ifdef PNG_READ_SUPPORTED
444
/* New member added in libpng-1.2.30 */
445
png_bytep read_buffer; /* buffer for reading chunk data */
446
png_alloc_size_t read_buffer_size; /* current size of the buffer */
447
#endif
448
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
449
uInt IDAT_read_size; /* limit on read buffer size for IDAT */
450
#endif
451
452
#ifdef PNG_IO_STATE_SUPPORTED
453
/* New member added in libpng-1.4.0 */
454
png_uint_32 io_state;
455
#endif
456
457
/* New member added in libpng-1.5.6 */
458
png_bytep big_prev_row;
459
460
/* New member added in libpng-1.5.7 */
461
void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_row_infop row_info,
462
png_bytep row, png_const_bytep prev_row);
463
};
464
#endif /* PNGSTRUCT_H */
465
466