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