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/pngstruct.h
Views: 1401
1
2
/* pngstruct.h - header file for PNG reference library
3
*
4
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
5
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
6
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8
*
9
* This code is released under the libpng license.
10
* For conditions of distribution and use, see the disclaimer
11
* and license in png.h
12
*/
13
14
/* The structure that holds the information to read and write PNG files.
15
* The only people who need to care about what is inside of this are the
16
* people who will be modifying the library for their own special needs.
17
* It should NOT be accessed directly by an application.
18
*/
19
20
#ifndef PNGSTRUCT_H
21
#define PNGSTRUCT_H
22
/* zlib.h defines the structure z_stream, an instance of which is included
23
* in this structure and is required for decompressing the LZ compressed
24
* data in PNG files.
25
*/
26
#ifndef ZLIB_CONST
27
/* We must ensure that zlib uses 'const' in declarations. */
28
# define ZLIB_CONST
29
#endif /* !ZLIB_CONST */
30
31
#include PNG_ZLIB_HEADER
32
33
#ifdef const
34
/* zlib.h sometimes #defines const to nothing, undo this. */
35
# undef const
36
#endif /* const */
37
38
/* zlib.h has mediocre z_const use before 1.2.6, this stuff is for compatibility
39
* with older builds.
40
*/
41
#if ZLIB_VERNUM < 0x1260
42
# define PNGZ_MSG_CAST(s) png_constcast(char*,s)
43
# define PNGZ_INPUT_CAST(b) png_constcast(png_bytep,b)
44
#else /* ZLIB_VERNUM >= 0x1260 */
45
# define PNGZ_MSG_CAST(s) (s)
46
# define PNGZ_INPUT_CAST(b) (b)
47
#endif /* ZLIB_VERNUM >= 0x1260 */
48
49
/* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib
50
* can handle at once. This type need be no larger than 16 bits (so maximum of
51
* 65535), this define allows us to discover how big it is, but limited by the
52
* maximum for size_t. The value can be overridden in a library build (pngusr.h,
53
* or set it in CPPFLAGS) and it works to set it to a considerably lower value
54
* (e.g. 255 works). A lower value may help memory usage (slightly) and may
55
* even improve performance on some systems (and degrade it on others.)
56
*/
57
#ifndef ZLIB_IO_MAX
58
# ifdef __COVERITY__
59
# define ZLIB_IO_MAX ((uInt)255U) /* else COVERITY whines */
60
# else /* !COVERITY */
61
# define ZLIB_IO_MAX ((uInt)-1)
62
# endif /* !COVERITY */
63
#endif /* !ZLIB_IO_MAX */
64
65
#ifdef PNG_WRITE_SUPPORTED
66
/* The write compression control (allocated on demand).
67
* TODO: use this for the read state too.
68
*/
69
typedef struct png_zlib_state *png_zlib_statep;
70
#endif /* WRITE */
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
* PNG_COLORSPACE_SUPPORTED is only required if the application will perform
76
* colorspace corrections, otherwise all the colorspace information can be
77
* skipped and the size of libpng can be reduced (significantly) by compiling
78
* out the colorspace support.
79
*/
80
#ifdef PNG_COLORSPACE_SUPPORTED
81
/* The chromaticities of the red, green and blue colorants and the chromaticity
82
* of the corresponding white point (i.e. of rgb(1.0,1.0,1.0)).
83
*/
84
typedef struct png_xy
85
{
86
png_fixed_point redx, redy;
87
png_fixed_point greenx, greeny;
88
png_fixed_point bluex, bluey;
89
png_fixed_point whitex, whitey;
90
} png_xy;
91
92
/* The same data as above but encoded as CIE XYZ values. When this data comes
93
* from chromaticities the sum of the Y values is assumed to be 1.0
94
*/
95
typedef struct png_XYZ
96
{
97
png_fixed_point red_X, red_Y, red_Z;
98
png_fixed_point green_X, green_Y, green_Z;
99
png_fixed_point blue_X, blue_Y, blue_Z;
100
} png_XYZ;
101
#endif /* COLORSPACE */
102
103
#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED)
104
/* A colorspace is all the above plus, potentially, profile information;
105
* however at present libpng does not use the profile internally so it is only
106
* stored in the png_info struct (if iCCP is supported.) The rendering intent
107
* is retained here and is checked.
108
*
109
* The file gamma encoding information is also stored here and gamma correction
110
* is done by libpng, whereas color correction must currently be done by the
111
* application.
112
*/
113
typedef struct png_colorspace
114
{
115
#ifdef PNG_GAMMA_SUPPORTED
116
png_fixed_point gamma; /* File gamma */
117
#endif /* GAMMA */
118
119
#ifdef PNG_COLORSPACE_SUPPORTED
120
png_xy end_points_xy; /* End points as chromaticities */
121
png_XYZ end_points_XYZ; /* End points as CIE XYZ colorant values */
122
png_uint_16 rendering_intent; /* Rendering intent of a profile */
123
#endif /* COLORSPACE */
124
125
/* Flags are always defined to simplify the code. */
126
png_uint_16 flags; /* As defined below */
127
} png_colorspace, * PNG_RESTRICT png_colorspacerp;
128
129
typedef const png_colorspace * PNG_RESTRICT png_const_colorspacerp;
130
131
/* General flags for the 'flags' field */
132
#define PNG_COLORSPACE_HAVE_GAMMA 0x0001U
133
#define PNG_COLORSPACE_HAVE_ENDPOINTS 0x0002U
134
#define PNG_COLORSPACE_HAVE_INTENT 0x0004U
135
#define PNG_COLORSPACE_FROM_gAMA 0x0008U
136
#define PNG_COLORSPACE_FROM_cHRM 0x0010U
137
#define PNG_COLORSPACE_FROM_sRGB 0x0020U
138
#define PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB 0x0040U
139
#define PNG_COLORSPACE_MATCHES_sRGB 0x0080U /* exact match on profile */
140
#define PNG_COLORSPACE_RGB_TO_GRAY_SET 0x0100U /* user specified coeffs */
141
#define PNG_COLORSPACE_INVALID 0x8000U
142
#define PNG_COLORSPACE_CANCEL(flags) (0xffffU - (flags))
143
#endif /* COLORSPACE || GAMMA */
144
145
#ifdef PNG_TRANSFORM_MECH_SUPPORTED
146
/***************************** READ and WRITE TRANSFORMS ***********************
147
* These structures are used in pngrtran.c, pngwtran.c and pngtrans.c to hold
148
* information about transforms in progress. This mechanism was introduced in
149
* libpng 1.7.0 to ensure reliable transform code and to fix multiple bugs in
150
* the pre-1.7 transform handling.
151
*
152
* Prior to 1.7.0 the internal transform routines took a png_row_infop, like the
153
* user transform function, but without the png_ptr because it was never used.
154
* In 1.7.0 a separate internal structure is used in place of this to allow both
155
* future development to change the structure.
156
*
157
* The values in this structure will normally be changed by transformation
158
* implementations.
159
***************************** READ and WRITE TRANSFORMS **********************/
160
typedef struct
161
{
162
png_structp png_ptr; /* png_struct for error handling and some
163
* transform parameters. May be aliased.
164
*/
165
png_const_voidp sp; /* Source; the input row. */
166
png_voidp dp; /* Output buffer for the transformed row,
167
* this may be the same as sp.
168
*/
169
/* If the row is changed the tranform routine must write the result to
170
* dp[] and set sp to dp, otherwise it must not write to dp and must leave
171
* sp unchanged. dp[] and sp[] are both 'malloc' aligned; i.e. they have
172
* the system alignment, so the data can be read as any valid ANSI-C
173
* type.
174
*/
175
png_uint_32 width; /* width of row */
176
# ifdef PNG_READ_GAMMA_SUPPORTED
177
png_fixed_point gamma; /* Current gamma of the row data */
178
/* When a row is being transformed this contains the current gamma of the
179
* data if known. During initialization the value is used to accumulate
180
* information for png_struct::row_gamma in the first step,
181
* PNG_TC_INIT_FORMAT, then used to insert the correct gamma transforms
182
* during PNG_TC_INIT_FINAL. The field is only used on read; write
183
* transforms do not modify the gamma of the data.
184
*/
185
# endif /* READ_GAMMA */
186
unsigned int format; /* As pngstruct::row_format below */
187
unsigned int range; /* Count of range transforms */
188
# define PNG_TC_CHANNELS(tc) PNG_FORMAT_CHANNELS((tc).format)
189
unsigned int bit_depth; /* bit depth of row */
190
png_byte sBIT_R;
191
png_byte sBIT_G;
192
png_byte sBIT_B;
193
png_byte sBIT_A; /* Signnificant bits in the row channels. */
194
/* The above four values are initially set to the number of bits significant
195
* in the input PNG data, R/G/B are set to the same (gray) value for
196
* grayscale input. All values are set to the bit depth if there is no sBIT
197
* chunk, if there is no alpha channel sBIT_A is set to the bit depth.
198
*
199
* When any potentially spurious bits have been cleared PNG_INFO_sBIT will be
200
* set in invalid_info. From this point on the above values record the
201
* approximate number of bits of accuracy in the channels and the lower bits
202
* should be preserved; they potentially contain useful information.
203
*/
204
# define PNG_TC_PIXEL_DEPTH(tc) (PNG_TC_CHANNELS(tc) * (tc).bit_depth)
205
# define PNG_TC_ROWBYTES(tc) PNG_ROWBYTES(PNG_TC_PIXEL_DEPTH(tc), (tc).width)
206
unsigned int invalid_info; /* PNG_INFO_* for invalidated chunks */
207
unsigned int cost; /* Cache cost */
208
# define PNG_CACHE_COST_LIMIT 0x100U
209
/* This is a runtime structure, so size doesn't matter much, and it helps
210
* code reliability to use real member names here. Feel free to experiment
211
* with integer values rather than bitfields.
212
*/
213
unsigned int init :2; /* 0 for processing, non zero for init: */
214
# define PNG_TC_INIT_FORMAT 0x01U /* Initialization step 1: just set 'format',
215
* 'bit_depth' and 'gamma' to the output
216
* values iff the transform corresponds to
217
* a user requested change to those values.
218
*/
219
# define PNG_TC_INIT_FINAL 0x03U /* Initialization step 2; set the 'format'
220
* 'bit_depth' and 'gamma' to the values the
221
* transform will actually produce (which
222
* need not be the same as the above).
223
*/
224
/* During initialization 'init' must be set and sp and dp may be NULL. If
225
* neither flag is set sp and dp must be non-NULL.
226
*
227
* When the transform runs it must update 'format', 'bit_depth' and 'gamma'
228
* to the values previously reported during PNG_TC_INIT_FINAL; not doing so
229
* may result in an affirm from a later transform.
230
*/
231
unsigned int caching :1; /* The color values are being used to
232
* generate a cache of the transforms.
233
*/
234
unsigned int palette :1; /* The values come from a PNG palette and
235
* the palette will not be expanded. The
236
* CACHE flag must be set too. A
237
* transform which causes the palette to
238
* be expanded must clear this flag.
239
*/
240
#if 0 /* NYI */
241
unsigned int interchannel:1; /* Set by a transform that combines two or
242
* more channels together; for example
243
* alpha composition or RGB to gray.
244
*/
245
#endif /* NYI */
246
unsigned int channel_add :1; /* A channel (alpha/filler) was added */
247
unsigned int strip_alpha :1; /* Set if the alpha channel will be
248
* stripped on read, this also prevents
249
* the tRNS chunk being expanded. Only
250
* some transforms check this, depending
251
* on the handling order and checks in
252
* pre-1.7 versions.
253
*/
254
unsigned int expand_tRNS :1; /* Set if the tRNS chunk should be
255
* expanded (ignored if read_strip_alpha
256
* is set). If this is *not* set
257
* transforms which do not use alpha/tRNS
258
* but would invalidate it (such as
259
* simple gamma correction) will simply
260
* mark the tRNS info as invalid.
261
*/
262
unsigned int transparent_alpha :1; /* Indicates that the alpha channel
263
* consists entirely of opaque (1.0 alpha)
264
* or completely transparent (0.0 alpha)
265
* pixels. Set when tRNS is expanded to
266
* alpha.
267
*/
268
unsigned int optimized_alpha :1; /* Meaningful only when bit_depth is
269
* 16 and gamma is 1 or unknown (0).
270
* Indicates that pixels which are opaque
271
* (alpha 1.0) have not been expanded to
272
* 16-bit linear; instead these pixels
273
* are encoded in the final format in
274
* png_struct::row_bit_depth and
275
* png_struct::row_gamma. This will
276
* invariably match the file format.
277
*/
278
} png_transform_control, *png_transform_controlp;
279
280
typedef const png_transform_control *png_const_transform_controlp;
281
typedef const png_row_info *png_const_row_infop;
282
283
typedef struct png_transform *png_transformp; /* Forward declaration */
284
typedef void (*png_transform_free_fn)(/* Function to free a transform */
285
png_const_structrp png_ptr,
286
png_transformp transform); /* pointer to this transform */
287
/* This function need not exist in a transform, it must free all the data
288
* allocated within the transform but not the transform itself. It is called
289
* from png_transform_free.
290
*/
291
typedef void (*png_transform_fn)(/* Function to implement a transform */
292
png_transformp *transform, /* pointer to this transform */
293
png_transform_controlp control); /* row information */
294
/* The transform function has two modes of operation:
295
*
296
* 1) Initialization. The list of transforms is processed from the start to
297
* the end and each function is called with one of hte PNG_TC_INIT_ flags
298
* set in control->flags, control->dp and control->sp may be NULL.
299
*
300
* For read the control structure contains the input row format and bit
301
* depth, the transform function changes this to represent what the
302
* transform will produce when it runs.
303
*
304
* For write the control structure contains the *required* output format
305
* and bit depth. The transform function changes this to the values that
306
* it needs to produce the required values.
307
*
308
* In both cases the transform function may update the 'fn' function to a
309
* new function to perform the desired transform; this allows considerable
310
* optimization on multi-row images.
311
*
312
* In both cases the caller considers the pixel bit depth changes and
313
* records the maximum required so that it can allocate a suitably sized
314
* buffer.
315
*
316
* 2) Execution.
317
*
318
* In the read case the transforms are processed in the stored order and
319
* must transform the row data appropriately *and* update the bit depth
320
* and format as before.
321
*
322
* In the write case the transforms are called in the reverse order and
323
* the input bit depth and format should match the required values.
324
*
325
* It is valid during initialization for the transform function to push
326
* another transform into the list in either the read or the write case if
327
* the transform cannot handle (read) or produce (write) the required format. * The transform pushes another transform into the list ahead of itself (at
328
* *transform) and runs that initialization; when control is returned to the
329
* caller the caller will re-run the transform initialization.
330
*
331
* It is also valid (during initialization) to push new transforms onto the
332
* list, just so long as the order of the transform is greater than the
333
* current transform (so that the caller will still call the new transform
334
* initialization.)
335
*
336
* In the write case the user transform callback might still end up producing
337
* an unexpected format, but at present this is unavoidable; the libpng API
338
* is extremely inconsistent in how a user transform reports the changes it
339
* made.
340
*
341
* TODO: fix this, probably with an API change in 1.7.0
342
*/
343
typedef struct png_transform /* Linked list of transform functions */
344
{
345
png_transformp next; /* Next transform in the list */
346
png_transform_fn fn; /* Function to implement the transform */
347
png_transform_free_fn free; /* Free allocated data, normally NULL */
348
unsigned int order; /* Order of the transform in the list. */
349
unsigned int size; /* Size of this structure (max 65535) */
350
png_uint_32 args; /* Optional transform arguments. */
351
} png_transform;
352
#endif /* TRANSFORM_MECH */
353
354
/* Action to take on CRC errors (four values) */
355
typedef enum
356
{
357
crc_error_quit = PNG_CRC_ERROR_QUIT-1,
358
crc_warn_discard = PNG_CRC_WARN_DISCARD-1,
359
crc_warn_use = PNG_CRC_WARN_USE-1,
360
crc_quiet_use = PNG_CRC_QUIET_USE-1
361
} png_crc_action;
362
363
struct png_struct_def
364
{
365
/* Rearranged in libpng 1.7 to attempt to lessen padding; in general
366
* (char), (short), (int) and pointer types are kept separate; however
367
* associated members under the control of the same #define are still
368
* together.
369
*/
370
#ifdef PNG_SETJMP_SUPPORTED
371
/* jmp_buf can have very high alignment requirements on some systems, so put
372
* it first (the other setjmp members are later as they are infrequently
373
* accessed.)
374
*/
375
jmp_buf jmp_buf_local;
376
#endif /* SETJMP */
377
378
/* Next the frequently accessed fields. Many processors perform arithmetic
379
* in the address pipeline, but frequently the amount of addition or
380
* subtraction is limited. By putting these fields at the head of png_struct
381
* the hope is that such processors will generate code that is both smaller
382
* and faster.
383
*/
384
#ifdef PNG_READ_SUPPORTED
385
png_colorp palette; /* palette from the input file */
386
#endif /* READ */
387
#ifdef PNG_READ_tRNS_SUPPORTED
388
png_bytep trans_alpha; /* alpha values for paletted files */
389
#endif /* READ_tRNS */
390
391
png_uint_32 width; /* width of image in pixels */
392
png_uint_32 height; /* height of image in pixels */
393
png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */
394
#ifdef PNG_READ_SUPPORTED
395
png_uint_32 chunk_length; /* Length (possibly remaining) in said chunk. */
396
#endif /* READ */
397
png_uint_32 crc; /* current chunk CRC value */
398
399
unsigned int mode :6; /* where we are in the PNG file */
400
unsigned int read_struct :1; /* this is a read (not write) struct */
401
unsigned int num_palette :9; /* number of color entries in palette */
402
#ifdef PNG_READ_tRNS_SUPPORTED
403
unsigned int num_trans :9; /* number of transparency values */
404
unsigned int transparent_palette :1; /* if they are all 0 or 255 */
405
#endif /* READ_tRNS */
406
#ifdef PNG_PALETTE_MAX_SUPPORTED
407
unsigned int palette_index_max :8; /* maximum palette index in IDAT */
408
unsigned int palette_index_check :2; /* one of the following: */
409
# define PNG_PALETTE_CHECK_DEFAULT 0U
410
# define PNG_PALETTE_CHECK_OFF 1U
411
# define PNG_PALETTE_CHECK_ON 2U
412
unsigned int palette_index_have_max :1; /* max is being set */
413
unsigned int palette_index_check_issued :1; /* error message output */
414
#endif /* PALETTE_MAX */
415
#ifdef PNG_READ_tRNS_SUPPORTED
416
png_color_16 trans_color; /* transparent color for non-paletted files */
417
#endif /* READ_tRNS */
418
#ifdef PNG_READ_sBIT_SUPPORTED
419
png_color_8 sig_bit; /* significant bits in each channel */
420
#endif /* READ_sBIT */
421
422
/* Single byte values, typically used either to save space or to hold 1-byte
423
* values from the PNG chunk specifications.
424
*/
425
png_byte filter_method; /* file filter type (only non-0 with MNG) */
426
png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
427
png_byte color_type; /* color type of file */
428
png_byte bit_depth; /* bit depth of file */
429
png_byte sig_bytes; /* magic bytes read/written at start of file */
430
431
#ifdef PNG_READ_SUPPORTED
432
#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED)
433
/* The png_struct colorspace structure is only required on read - on write it
434
* is in (just) the info_struct.
435
*/
436
png_colorspace colorspace;
437
#endif /* COLORSPACE || GAMMA */
438
#endif /* READ */
439
440
/* Transform handling */
441
#ifdef PNG_TRANSFORM_MECH_SUPPORTED
442
png_transformp transform_list; /* List of transformation to perform. */
443
#endif /* TRANSFORM_MECH */
444
445
/* ROW BUFFERS and CONTROL
446
*
447
* Members used for image row compression (write) or decompression (read).
448
* filter byte (which is in next_filter.) All fields are only used during
449
* IDAT processing and start of 0.
450
*/
451
#ifdef PNG_READ_SUPPORTED
452
png_bytep row_buffer; /* primary row buffer */
453
#if (defined(PNG_PROGRESSIVE_READ_SUPPORTED) ||\
454
defined(PNG_READ_INTERLACING_SUPPORTED)) &&\
455
defined(PNG_TRANSFORM_MECH_SUPPORTED)
456
png_bytep transformed_row; /* pointer to the transformed row, if
457
* required. May point to row_buffer.
458
*/
459
#endif /* (PROGRESSIVE_READ || READ_INTERLACING) && TRANSFORM_MECH */
460
461
png_alloc_size_t row_bytes_read; /* Total read in row */
462
#endif /* READ */
463
464
png_uint_32 row_number; /* current row in pass */
465
#ifdef PNG_READ_SUPPORTED
466
#ifdef PNG_READ_GAMMA_SUPPORTED
467
png_fixed_point row_gamma; /* Gamma of final output */
468
#if 0 /* NYI */
469
unsigned int gamma_accuracy;
470
/* LINEAR gamma cache table size (in bits) times 100; for non-linear
471
* tables the value used is gamma_accuracy/gamma where 'gamma' is the
472
* encoding value of the data (typically less than 1).
473
*
474
* default: PNG_DEFAULT_GAMMA_ACCURACY (665)
475
*/
476
#endif /* NYI */
477
png_uint_16 gamma_threshold;
478
/* Gamma threshold value as a fixed-point value in the range 0..1; the
479
* threshold at or below which gamma correction is skipped. '0' forces
480
* gamma correction even when there is none because the input and output
481
* gammas are equal.
482
*
483
* default: PNG_GAMMA_THRESHOLD_FIXED (153)
484
*/
485
#endif /* READ_GAMMA */
486
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
487
unsigned int invalid_info; /* PNG_INFO_* for invalidated chunks */
488
unsigned int palette_updated:1; /* png_struct::palette changed */
489
#endif /* READ_TRANSFORMS */
490
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
491
unsigned int read_started :1; /* at least one call to png_read_row */
492
#endif /* SEQUENTIAL_READ */
493
/* The next field is just used by the read IDAT process functions to store
494
* the state of IDAT processing; they should not be altered or used by other
495
* functions.
496
*/
497
unsigned int row_state :2; /* state of row parsing (internal) */
498
#endif /* READ */
499
500
#if defined (PNG_READ_INTERLACING_SUPPORTED) ||\
501
defined (PNG_WRITE_INTERLACING_SUPPORTED)
502
unsigned int do_interlace :1; /* libpng handles the interlace */
503
# endif /* R/W INTERLACING */
504
505
unsigned int pass :3; /* current (interlace) pass (0 - 6) */
506
507
/* The following fields are set by png_row_init to the pixel depths of the
508
* pixels at various states. If transforms are not supported they will
509
* always be the same value:
510
*
511
* READ WRITE
512
* input: PNG From application
513
* output: To application PNG
514
* max: Largest in transform
515
*/
516
unsigned int row_input_pixel_depth :8;
517
unsigned int row_output_pixel_depth :8;
518
unsigned int row_max_pixel_depth :8;
519
520
# define PNG_RF_BITS 9 /* Number of bits required for the row format (below) */
521
#ifdef PNG_TRANSFORM_MECH_SUPPORTED
522
/* The following fields describe the format of the user row; the output on
523
* read or the input on write, and give the maximum pixel depth, which
524
* controls the row buffer allocation size (row_allocated_bytes) above.
525
*/
526
unsigned int row_range :3; /* range error count */
527
unsigned int row_bit_depth :6; /* bits per channel (up to 32) */
528
unsigned int row_format:PNG_RF_BITS;/* format of output(R)/input(W) row: */
529
/* PNG_FORMAT_FLAG_ALPHA 0x01U format with an alpha channel
530
* PNG_FORMAT_FLAG_COLOR 0x02U color format: otherwise grayscale
531
* PNG_FORMAT_FLAG_LINEAR 0x04U NOT used (informational)
532
* PNG_FORMAT_FLAG_COLORMAP 0x08U image data is color-mapped
533
* PNG_FORMAT_FLAG_BGR 0x10U BGR colors, else order is RGB
534
* PNG_FORMAT_FLAG_AFIRST 0x20U alpha channel comes first *
535
* PNG_FORAMT_FLAG_AFILLER 0x40U The 'alpha' channel is a filler:
536
* PNG_FORMAT_FLAG_ALPHA is set however the value in the alpha channel
537
* is not an alpha value and (therefore) cannot be used for alpha
538
* computations, it is just a filler value. PNG_COLOR_TYPE_FROM_FORMAT
539
* will return a color type *without* PNG_COLOR_MASK_ALPHA, however
540
* PNG_FORMAT_CHANNELS will return the correct number, including the
541
* filler channel.
542
* PNG_FORMAT_FLAG_SWAPPED 0x80U bytes or bits swapped:
543
* When the bit depth is 16 this means that the bytes within the
544
* components have been swapped, when the bit depth is less than 8
545
* it means the pixels within the bytes have been swapped. It should
546
* not be set for 8-bit compononents (it is meaningless).
547
* PNG_FORMAT_FLAG_RANGE 0x100U component range not 0..bit-depth:
548
* Low-bit-depth grayscale components have been unpacked into bytes
549
* without scaling, or RGB[A] pixels have been shifted back to the
550
* significant-bit range from the sBIT chunk or channels (currently
551
* alpha or gray) have been inverted.
552
* PNG_FORMAT_FLAG_INVALID NOT STORED HERE
553
*/
554
#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
555
unsigned int info_format:PNG_RF_BITS;
556
/* This field is used to validate the png_info used to write the
557
* IHDR. This is a new check in 1.7.0; previously it was possible to pass
558
* a png_info from a png_read with the read tranform information in the
559
* format having manually removed the required transforms from the rows
560
* passed to png_write_row.
561
*/
562
#endif /* WRITE_TRANSFORMS */
563
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
564
unsigned int write_invert_alpha :1;
565
/* This indicates the png_set_invert_alpha was called, it is used by the
566
* write code to implement the transform without needing to run the whole
567
* transform mechanism on the PNG palette data.
568
*/
569
#endif /* WRITE_INVERT_ALPHA */
570
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
571
unsigned int rgb_to_gray_status :1;
572
/* If set an RGB pixel was encountered by the RGB to gray transform
573
* wherein !(r==g==b).
574
*/
575
#endif /* RGB_TO_GRAY */
576
#endif /* TRANSFORM_MECH */
577
578
#ifdef PNG_READ_SUPPORTED
579
/* These, and IDAT_size below, control how much input and output (at most) is
580
* available to zlib during read decompression.
581
*/
582
png_alloc_size_t read_buffer_size; /* current size of the buffer */
583
#endif /* READ */
584
585
#if defined(PNG_SEQUENTIAL_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
586
png_uint_32 IDAT_size; /* limit on IDAT read and write IDAT size */
587
#endif /* SEQUENTIAL_READ || WRITE */
588
589
/* ERROR HANDLING */
590
#ifdef PNG_SETJMP_SUPPORTED
591
jmp_buf *jmp_buf_ptr; /* passed to longjmp_fn */
592
png_longjmp_ptr longjmp_fn; /* setjmp non-local goto function. */
593
size_t jmp_buf_size; /* size of *jmp_buf_ptr, if allocated */
594
#endif /* SETJMP */
595
596
/* Error/warning callbacks */
597
png_error_ptr error_fn; /* print an error message and abort */
598
#ifdef PNG_WARNINGS_SUPPORTED
599
png_error_ptr warning_fn; /* print a warning and continue */
600
#endif /* WARNINGS */
601
png_voidp error_ptr; /* user supplied data for the above */
602
603
/* MEMORY ALLOCATION */
604
#ifdef PNG_USER_MEM_SUPPORTED
605
png_malloc_ptr malloc_fn; /* allocate memory */
606
png_free_ptr free_fn; /* free memory */
607
png_voidp mem_ptr; /* user supplied data for the above */
608
#endif /* USER_MEM */
609
610
/* IO and BASIC READ/WRITE SUPPORT */
611
png_voidp io_ptr; /* user supplied data for IO callbacks */
612
png_rw_ptr rw_data_fn; /* read/write some bytes (must succeed) */
613
614
#ifdef PNG_READ_SUPPORTED
615
png_read_status_ptr read_row_fn; /* called after each row is decoded */
616
png_bytep read_buffer; /* buffer for reading chunk data */
617
618
/* During read the following array is set up to point to the appropriate
619
* un-filter function, this allows per-image and per-processor optimization.
620
*/
621
void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_alloc_size_t row_bytes,
622
unsigned int bpp, png_bytep row, png_const_bytep prev_row,
623
png_const_bytep prev_pixels);
624
#endif /* READ */
625
626
#ifdef PNG_WRITE_SUPPORTED
627
png_write_status_ptr write_row_fn; /* called after each row is encoded */
628
629
#ifdef PNG_WRITE_FLUSH_SUPPORTED
630
png_flush_ptr output_flush_fn; /* Function for flushing output */
631
#endif /* WRITE_FLUSH */
632
#endif /* WRITE */
633
634
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
635
png_uint_32 user_width_max; /* Maximum width on read */
636
png_uint_32 user_height_max; /* Maximum height on read */
637
/* Total memory that a single zTXt, sPLT, iTXt, iCCP, or unknown chunk
638
* can occupy when decompressed. 0 means unlimited. This field is a counter
639
* - it is decremented as memory is allocated.
640
*/
641
png_alloc_size_t user_chunk_malloc_max;
642
#endif /* SET_USER_LIMITS */
643
#ifdef PNG_USER_LIMITS_SUPPORTED
644
/* limit on total *number* of sPLT, text and unknown chunks that can be
645
* stored. 0 means unlimited. This field is a counter - it is decremented
646
* as chunks are encountered.
647
*/
648
png_uint_32 user_chunk_cache_max;
649
#endif /* USER_LIMITS */
650
651
/* The progressive reader gets passed data and calls application handling
652
* functions when appropriate.
653
*/
654
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
655
png_progressive_info_ptr info_fn; /* called after header data fully read */
656
png_progressive_row_ptr row_fn; /* called after a row is decoded */
657
png_progressive_end_ptr end_fn; /* called after image is complete */
658
659
/* Progressive read control data */
660
png_bytep save_buffer_ptr; /* current location in save_buffer */
661
png_bytep save_buffer; /* buffer for previously read data */
662
png_bytep current_buffer_ptr; /* current location in current_buffer */
663
664
size_t save_buffer_size; /* amount of data now in save_buffer */
665
size_t save_buffer_max; /* total size of save_buffer */
666
size_t current_buffer_size; /* amount of data now in current_buffer */
667
size_t buffer_size; /* total amount of available input data */
668
669
unsigned int process_mode :8;
670
/* This is one or two four bit codes describing the current state of the
671
* 'push' reader. Normally the low four bits are a state code, however in
672
* some cases this may be pushed to the top four bits and replaced by a
673
* different temporary state code. The value is, in effect, a two entry
674
* stack.
675
*/
676
#endif /* PROGRESSIVE_READ */
677
678
#ifdef PNG_IO_STATE_SUPPORTED
679
png_uint_32 io_state; /* tells the app read/write progress */
680
#endif /* IO_STATE */
681
682
/* UNKNOWN CHUNK HANDLING */
683
/* TODO: this is excessively complicated, there are multiple ways of doing
684
* the same thing. It should be cleaned up, possibly by finding out which
685
* APIs applications really use.
686
*/
687
#ifdef PNG_USER_CHUNKS_SUPPORTED
688
/* General purpose pointer for all user/unknown chunk handling; points to
689
* application supplied data for use in the read_user_chunk_fn callback
690
* (currently there is no write side support - the write side must use the
691
* set_unknown_chunks interface.)
692
*/
693
png_voidp user_chunk_ptr;
694
#endif /* USER_CHUNKS */
695
696
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
697
/* This is called back from the unknown chunk handling */
698
png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
699
#endif /* READ_USER_CHUNKS */
700
701
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
702
png_uint_32 known_unknown; /* Bit mask of known chunks to be treated as
703
* unknown in the read code.
704
*/
705
#ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
706
png_uint_32 save_unknown; /* Whether to save or skip these chunks:
707
* 'save' is 'known & save', 'skip' is
708
* 'known & ~save'.
709
*/
710
# define png_IDATs_skipped(pp) (((pp)->known_unknown & ~(pp)->save_unknown)&1U)
711
#else /* !SAVE_UNKNOWN_CHUNKS */
712
# define png_IDATs_skipped(pp) ((pp)->known_unknown & 1U)
713
#endif /* !SAVE_UNKNOWN_CHUNKS */
714
#endif /* HANDLE_AS_UNKNOWN */
715
716
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
717
png_bytep chunk_list; /* List of png_byte[5]; the textual chunk name
718
* followed by a PNG_HANDLE_* byte */
719
unsigned int unknown_default :2; /* As PNG_HANDLE_* */
720
unsigned int num_chunk_list; /* Number of entries in the list */
721
#endif /* SET_UNKNOWN_CHUNKS */
722
723
/* COMPRESSION AND DECOMPRESSION SUPPORT.
724
*
725
* zlib expects a 'zstream' as the fundamental control structure, it allows
726
* all the parameters to be passed as one pointer.
727
*/
728
png_uint_32 zowner; /* ID (chunk type) of zlib owner, 0 if none */
729
# ifdef PNG_WRITE_SUPPORTED
730
png_zlib_statep zlib_state; /* State of zlib compression */
731
# endif /* WRITE */
732
# ifdef PNG_READ_SUPPORTED
733
z_stream zstream; /* decompression structure */
734
unsigned int zstream_ended:1; /* no more zlib output available [read] */
735
unsigned int zstream_error:1; /* zlib error message has been output [read] */
736
# endif /* READ */
737
# ifdef PNG_PROGRESSIVE_READ_SUPPORTED
738
unsigned int zstream_eod :1; /* all the required uncompressed data has been
739
* received; set by the zstream using code for
740
* its own purposes. [progressive read] */
741
# endif /* PROGRESSIVE_READ */
742
# ifdef PNG_BENIGN_ERRORS_SUPPORTED
743
unsigned int benign_error_action :2;
744
unsigned int app_warning_action :2;
745
unsigned int app_error_action :2;
746
# ifdef PNG_READ_SUPPORTED
747
unsigned int IDAT_error_action :2;
748
# endif /* READ */
749
# endif /* BENIGN_ERRORS */
750
# ifdef PNG_READ_SUPPORTED
751
/* CRC checking actions, one for critical chunks, one for ancillary
752
* chunks.
753
*/
754
unsigned int critical_crc :2;
755
unsigned int ancillary_crc :2;
756
unsigned int current_crc :2; /* Cache of one or other of the above */
757
# endif
758
# ifdef PNG_SET_OPTION_SUPPORTED
759
# ifdef PNG_READ_SUPPORTED
760
unsigned int maximum_inflate_window :1U;
761
# endif /* READ */
762
unsigned int skip_sRGB_profile_check :1U;
763
# endif /* SET_OPTION */
764
765
/* MNG SUPPORT */
766
#ifdef PNG_MNG_FEATURES_SUPPORTED
767
unsigned int mng_features_permitted :3;
768
#endif /* MNG_FEATURES */
769
770
/* SCRATCH buffers, used when control returns to the application or a read
771
* loop.
772
*/
773
# ifdef PNG_READ_SUPPORTED
774
png_byte scratch[PNG_ROW_BUFFER_SIZE+16U];
775
# endif /* READ */
776
};
777
#endif /* PNGSTRUCT_H */
778
779