CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/ext/libpng17/pngstruct.h
Views: 1401
1/* pngstruct.h - header file for PNG reference library2*3* Last changed in libpng 1.7.0 [(PENDING RELEASE)]4* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson5* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)6* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)7*8* This code is released under the libpng license.9* For conditions of distribution and use, see the disclaimer10* and license in png.h11*/1213/* The structure that holds the information to read and write PNG files.14* The only people who need to care about what is inside of this are the15* people who will be modifying the library for their own special needs.16* It should NOT be accessed directly by an application.17*/1819#ifndef PNGSTRUCT_H20#define PNGSTRUCT_H21/* zlib.h defines the structure z_stream, an instance of which is included22* in this structure and is required for decompressing the LZ compressed23* data in PNG files.24*/25#ifndef ZLIB_CONST26/* We must ensure that zlib uses 'const' in declarations. */27# define ZLIB_CONST28#endif /* !ZLIB_CONST */2930#include PNG_ZLIB_HEADER3132#ifdef const33/* zlib.h sometimes #defines const to nothing, undo this. */34# undef const35#endif /* const */3637/* zlib.h has mediocre z_const use before 1.2.6, this stuff is for compatibility38* with older builds.39*/40#if ZLIB_VERNUM < 0x126041# define PNGZ_MSG_CAST(s) png_constcast(char*,s)42# define PNGZ_INPUT_CAST(b) png_constcast(png_bytep,b)43#else /* ZLIB_VERNUM >= 0x1260 */44# define PNGZ_MSG_CAST(s) (s)45# define PNGZ_INPUT_CAST(b) (b)46#endif /* ZLIB_VERNUM >= 0x1260 */4748/* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib49* can handle at once. This type need be no larger than 16 bits (so maximum of50* 65535), this define allows us to discover how big it is, but limited by the51* maximum for size_t. The value can be overridden in a library build (pngusr.h,52* or set it in CPPFLAGS) and it works to set it to a considerably lower value53* (e.g. 255 works). A lower value may help memory usage (slightly) and may54* even improve performance on some systems (and degrade it on others.)55*/56#ifndef ZLIB_IO_MAX57# ifdef __COVERITY__58# define ZLIB_IO_MAX ((uInt)255U) /* else COVERITY whines */59# else /* !COVERITY */60# define ZLIB_IO_MAX ((uInt)-1)61# endif /* !COVERITY */62#endif /* !ZLIB_IO_MAX */6364#ifdef PNG_WRITE_SUPPORTED65/* The write compression control (allocated on demand).66* TODO: use this for the read state too.67*/68typedef struct png_zlib_state *png_zlib_statep;69#endif /* WRITE */7071/* Colorspace support; structures used in png_struct, png_info and in internal72* functions to hold and communicate information about the color space.73*74* PNG_COLORSPACE_SUPPORTED is only required if the application will perform75* colorspace corrections, otherwise all the colorspace information can be76* skipped and the size of libpng can be reduced (significantly) by compiling77* out the colorspace support.78*/79#ifdef PNG_COLORSPACE_SUPPORTED80/* The chromaticities of the red, green and blue colorants and the chromaticity81* of the corresponding white point (i.e. of rgb(1.0,1.0,1.0)).82*/83typedef struct png_xy84{85png_fixed_point redx, redy;86png_fixed_point greenx, greeny;87png_fixed_point bluex, bluey;88png_fixed_point whitex, whitey;89} png_xy;9091/* The same data as above but encoded as CIE XYZ values. When this data comes92* from chromaticities the sum of the Y values is assumed to be 1.093*/94typedef struct png_XYZ95{96png_fixed_point red_X, red_Y, red_Z;97png_fixed_point green_X, green_Y, green_Z;98png_fixed_point blue_X, blue_Y, blue_Z;99} png_XYZ;100#endif /* COLORSPACE */101102#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED)103/* A colorspace is all the above plus, potentially, profile information;104* however at present libpng does not use the profile internally so it is only105* stored in the png_info struct (if iCCP is supported.) The rendering intent106* is retained here and is checked.107*108* The file gamma encoding information is also stored here and gamma correction109* is done by libpng, whereas color correction must currently be done by the110* application.111*/112typedef struct png_colorspace113{114#ifdef PNG_GAMMA_SUPPORTED115png_fixed_point gamma; /* File gamma */116#endif /* GAMMA */117118#ifdef PNG_COLORSPACE_SUPPORTED119png_xy end_points_xy; /* End points as chromaticities */120png_XYZ end_points_XYZ; /* End points as CIE XYZ colorant values */121png_uint_16 rendering_intent; /* Rendering intent of a profile */122#endif /* COLORSPACE */123124/* Flags are always defined to simplify the code. */125png_uint_16 flags; /* As defined below */126} png_colorspace, * PNG_RESTRICT png_colorspacerp;127128typedef const png_colorspace * PNG_RESTRICT png_const_colorspacerp;129130/* General flags for the 'flags' field */131#define PNG_COLORSPACE_HAVE_GAMMA 0x0001U132#define PNG_COLORSPACE_HAVE_ENDPOINTS 0x0002U133#define PNG_COLORSPACE_HAVE_INTENT 0x0004U134#define PNG_COLORSPACE_FROM_gAMA 0x0008U135#define PNG_COLORSPACE_FROM_cHRM 0x0010U136#define PNG_COLORSPACE_FROM_sRGB 0x0020U137#define PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB 0x0040U138#define PNG_COLORSPACE_MATCHES_sRGB 0x0080U /* exact match on profile */139#define PNG_COLORSPACE_RGB_TO_GRAY_SET 0x0100U /* user specified coeffs */140#define PNG_COLORSPACE_INVALID 0x8000U141#define PNG_COLORSPACE_CANCEL(flags) (0xffffU - (flags))142#endif /* COLORSPACE || GAMMA */143144#ifdef PNG_TRANSFORM_MECH_SUPPORTED145/***************************** READ and WRITE TRANSFORMS ***********************146* These structures are used in pngrtran.c, pngwtran.c and pngtrans.c to hold147* information about transforms in progress. This mechanism was introduced in148* libpng 1.7.0 to ensure reliable transform code and to fix multiple bugs in149* the pre-1.7 transform handling.150*151* Prior to 1.7.0 the internal transform routines took a png_row_infop, like the152* user transform function, but without the png_ptr because it was never used.153* In 1.7.0 a separate internal structure is used in place of this to allow both154* future development to change the structure.155*156* The values in this structure will normally be changed by transformation157* implementations.158***************************** READ and WRITE TRANSFORMS **********************/159typedef struct160{161png_structp png_ptr; /* png_struct for error handling and some162* transform parameters. May be aliased.163*/164png_const_voidp sp; /* Source; the input row. */165png_voidp dp; /* Output buffer for the transformed row,166* this may be the same as sp.167*/168/* If the row is changed the tranform routine must write the result to169* dp[] and set sp to dp, otherwise it must not write to dp and must leave170* sp unchanged. dp[] and sp[] are both 'malloc' aligned; i.e. they have171* the system alignment, so the data can be read as any valid ANSI-C172* type.173*/174png_uint_32 width; /* width of row */175# ifdef PNG_READ_GAMMA_SUPPORTED176png_fixed_point gamma; /* Current gamma of the row data */177/* When a row is being transformed this contains the current gamma of the178* data if known. During initialization the value is used to accumulate179* information for png_struct::row_gamma in the first step,180* PNG_TC_INIT_FORMAT, then used to insert the correct gamma transforms181* during PNG_TC_INIT_FINAL. The field is only used on read; write182* transforms do not modify the gamma of the data.183*/184# endif /* READ_GAMMA */185unsigned int format; /* As pngstruct::row_format below */186unsigned int range; /* Count of range transforms */187# define PNG_TC_CHANNELS(tc) PNG_FORMAT_CHANNELS((tc).format)188unsigned int bit_depth; /* bit depth of row */189png_byte sBIT_R;190png_byte sBIT_G;191png_byte sBIT_B;192png_byte sBIT_A; /* Signnificant bits in the row channels. */193/* The above four values are initially set to the number of bits significant194* in the input PNG data, R/G/B are set to the same (gray) value for195* grayscale input. All values are set to the bit depth if there is no sBIT196* chunk, if there is no alpha channel sBIT_A is set to the bit depth.197*198* When any potentially spurious bits have been cleared PNG_INFO_sBIT will be199* set in invalid_info. From this point on the above values record the200* approximate number of bits of accuracy in the channels and the lower bits201* should be preserved; they potentially contain useful information.202*/203# define PNG_TC_PIXEL_DEPTH(tc) (PNG_TC_CHANNELS(tc) * (tc).bit_depth)204# define PNG_TC_ROWBYTES(tc) PNG_ROWBYTES(PNG_TC_PIXEL_DEPTH(tc), (tc).width)205unsigned int invalid_info; /* PNG_INFO_* for invalidated chunks */206unsigned int cost; /* Cache cost */207# define PNG_CACHE_COST_LIMIT 0x100U208/* This is a runtime structure, so size doesn't matter much, and it helps209* code reliability to use real member names here. Feel free to experiment210* with integer values rather than bitfields.211*/212unsigned int init :2; /* 0 for processing, non zero for init: */213# define PNG_TC_INIT_FORMAT 0x01U /* Initialization step 1: just set 'format',214* 'bit_depth' and 'gamma' to the output215* values iff the transform corresponds to216* a user requested change to those values.217*/218# define PNG_TC_INIT_FINAL 0x03U /* Initialization step 2; set the 'format'219* 'bit_depth' and 'gamma' to the values the220* transform will actually produce (which221* need not be the same as the above).222*/223/* During initialization 'init' must be set and sp and dp may be NULL. If224* neither flag is set sp and dp must be non-NULL.225*226* When the transform runs it must update 'format', 'bit_depth' and 'gamma'227* to the values previously reported during PNG_TC_INIT_FINAL; not doing so228* may result in an affirm from a later transform.229*/230unsigned int caching :1; /* The color values are being used to231* generate a cache of the transforms.232*/233unsigned int palette :1; /* The values come from a PNG palette and234* the palette will not be expanded. The235* CACHE flag must be set too. A236* transform which causes the palette to237* be expanded must clear this flag.238*/239#if 0 /* NYI */240unsigned int interchannel:1; /* Set by a transform that combines two or241* more channels together; for example242* alpha composition or RGB to gray.243*/244#endif /* NYI */245unsigned int channel_add :1; /* A channel (alpha/filler) was added */246unsigned int strip_alpha :1; /* Set if the alpha channel will be247* stripped on read, this also prevents248* the tRNS chunk being expanded. Only249* some transforms check this, depending250* on the handling order and checks in251* pre-1.7 versions.252*/253unsigned int expand_tRNS :1; /* Set if the tRNS chunk should be254* expanded (ignored if read_strip_alpha255* is set). If this is *not* set256* transforms which do not use alpha/tRNS257* but would invalidate it (such as258* simple gamma correction) will simply259* mark the tRNS info as invalid.260*/261unsigned int transparent_alpha :1; /* Indicates that the alpha channel262* consists entirely of opaque (1.0 alpha)263* or completely transparent (0.0 alpha)264* pixels. Set when tRNS is expanded to265* alpha.266*/267unsigned int optimized_alpha :1; /* Meaningful only when bit_depth is268* 16 and gamma is 1 or unknown (0).269* Indicates that pixels which are opaque270* (alpha 1.0) have not been expanded to271* 16-bit linear; instead these pixels272* are encoded in the final format in273* png_struct::row_bit_depth and274* png_struct::row_gamma. This will275* invariably match the file format.276*/277} png_transform_control, *png_transform_controlp;278279typedef const png_transform_control *png_const_transform_controlp;280typedef const png_row_info *png_const_row_infop;281282typedef struct png_transform *png_transformp; /* Forward declaration */283typedef void (*png_transform_free_fn)(/* Function to free a transform */284png_const_structrp png_ptr,285png_transformp transform); /* pointer to this transform */286/* This function need not exist in a transform, it must free all the data287* allocated within the transform but not the transform itself. It is called288* from png_transform_free.289*/290typedef void (*png_transform_fn)(/* Function to implement a transform */291png_transformp *transform, /* pointer to this transform */292png_transform_controlp control); /* row information */293/* The transform function has two modes of operation:294*295* 1) Initialization. The list of transforms is processed from the start to296* the end and each function is called with one of hte PNG_TC_INIT_ flags297* set in control->flags, control->dp and control->sp may be NULL.298*299* For read the control structure contains the input row format and bit300* depth, the transform function changes this to represent what the301* transform will produce when it runs.302*303* For write the control structure contains the *required* output format304* and bit depth. The transform function changes this to the values that305* it needs to produce the required values.306*307* In both cases the transform function may update the 'fn' function to a308* new function to perform the desired transform; this allows considerable309* optimization on multi-row images.310*311* In both cases the caller considers the pixel bit depth changes and312* records the maximum required so that it can allocate a suitably sized313* buffer.314*315* 2) Execution.316*317* In the read case the transforms are processed in the stored order and318* must transform the row data appropriately *and* update the bit depth319* and format as before.320*321* In the write case the transforms are called in the reverse order and322* the input bit depth and format should match the required values.323*324* It is valid during initialization for the transform function to push325* another transform into the list in either the read or the write case if326* the transform cannot handle (read) or produce (write) the required format. * The transform pushes another transform into the list ahead of itself (at327* *transform) and runs that initialization; when control is returned to the328* caller the caller will re-run the transform initialization.329*330* It is also valid (during initialization) to push new transforms onto the331* list, just so long as the order of the transform is greater than the332* current transform (so that the caller will still call the new transform333* initialization.)334*335* In the write case the user transform callback might still end up producing336* an unexpected format, but at present this is unavoidable; the libpng API337* is extremely inconsistent in how a user transform reports the changes it338* made.339*340* TODO: fix this, probably with an API change in 1.7.0341*/342typedef struct png_transform /* Linked list of transform functions */343{344png_transformp next; /* Next transform in the list */345png_transform_fn fn; /* Function to implement the transform */346png_transform_free_fn free; /* Free allocated data, normally NULL */347unsigned int order; /* Order of the transform in the list. */348unsigned int size; /* Size of this structure (max 65535) */349png_uint_32 args; /* Optional transform arguments. */350} png_transform;351#endif /* TRANSFORM_MECH */352353/* Action to take on CRC errors (four values) */354typedef enum355{356crc_error_quit = PNG_CRC_ERROR_QUIT-1,357crc_warn_discard = PNG_CRC_WARN_DISCARD-1,358crc_warn_use = PNG_CRC_WARN_USE-1,359crc_quiet_use = PNG_CRC_QUIET_USE-1360} png_crc_action;361362struct png_struct_def363{364/* Rearranged in libpng 1.7 to attempt to lessen padding; in general365* (char), (short), (int) and pointer types are kept separate; however366* associated members under the control of the same #define are still367* together.368*/369#ifdef PNG_SETJMP_SUPPORTED370/* jmp_buf can have very high alignment requirements on some systems, so put371* it first (the other setjmp members are later as they are infrequently372* accessed.)373*/374jmp_buf jmp_buf_local;375#endif /* SETJMP */376377/* Next the frequently accessed fields. Many processors perform arithmetic378* in the address pipeline, but frequently the amount of addition or379* subtraction is limited. By putting these fields at the head of png_struct380* the hope is that such processors will generate code that is both smaller381* and faster.382*/383#ifdef PNG_READ_SUPPORTED384png_colorp palette; /* palette from the input file */385#endif /* READ */386#ifdef PNG_READ_tRNS_SUPPORTED387png_bytep trans_alpha; /* alpha values for paletted files */388#endif /* READ_tRNS */389390png_uint_32 width; /* width of image in pixels */391png_uint_32 height; /* height of image in pixels */392png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */393#ifdef PNG_READ_SUPPORTED394png_uint_32 chunk_length; /* Length (possibly remaining) in said chunk. */395#endif /* READ */396png_uint_32 crc; /* current chunk CRC value */397398unsigned int mode :6; /* where we are in the PNG file */399unsigned int read_struct :1; /* this is a read (not write) struct */400unsigned int num_palette :9; /* number of color entries in palette */401#ifdef PNG_READ_tRNS_SUPPORTED402unsigned int num_trans :9; /* number of transparency values */403unsigned int transparent_palette :1; /* if they are all 0 or 255 */404#endif /* READ_tRNS */405#ifdef PNG_PALETTE_MAX_SUPPORTED406unsigned int palette_index_max :8; /* maximum palette index in IDAT */407unsigned int palette_index_check :2; /* one of the following: */408# define PNG_PALETTE_CHECK_DEFAULT 0U409# define PNG_PALETTE_CHECK_OFF 1U410# define PNG_PALETTE_CHECK_ON 2U411unsigned int palette_index_have_max :1; /* max is being set */412unsigned int palette_index_check_issued :1; /* error message output */413#endif /* PALETTE_MAX */414#ifdef PNG_READ_tRNS_SUPPORTED415png_color_16 trans_color; /* transparent color for non-paletted files */416#endif /* READ_tRNS */417#ifdef PNG_READ_sBIT_SUPPORTED418png_color_8 sig_bit; /* significant bits in each channel */419#endif /* READ_sBIT */420421/* Single byte values, typically used either to save space or to hold 1-byte422* values from the PNG chunk specifications.423*/424png_byte filter_method; /* file filter type (only non-0 with MNG) */425png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */426png_byte color_type; /* color type of file */427png_byte bit_depth; /* bit depth of file */428png_byte sig_bytes; /* magic bytes read/written at start of file */429430#ifdef PNG_READ_SUPPORTED431#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED)432/* The png_struct colorspace structure is only required on read - on write it433* is in (just) the info_struct.434*/435png_colorspace colorspace;436#endif /* COLORSPACE || GAMMA */437#endif /* READ */438439/* Transform handling */440#ifdef PNG_TRANSFORM_MECH_SUPPORTED441png_transformp transform_list; /* List of transformation to perform. */442#endif /* TRANSFORM_MECH */443444/* ROW BUFFERS and CONTROL445*446* Members used for image row compression (write) or decompression (read).447* filter byte (which is in next_filter.) All fields are only used during448* IDAT processing and start of 0.449*/450#ifdef PNG_READ_SUPPORTED451png_bytep row_buffer; /* primary row buffer */452#if (defined(PNG_PROGRESSIVE_READ_SUPPORTED) ||\453defined(PNG_READ_INTERLACING_SUPPORTED)) &&\454defined(PNG_TRANSFORM_MECH_SUPPORTED)455png_bytep transformed_row; /* pointer to the transformed row, if456* required. May point to row_buffer.457*/458#endif /* (PROGRESSIVE_READ || READ_INTERLACING) && TRANSFORM_MECH */459460png_alloc_size_t row_bytes_read; /* Total read in row */461#endif /* READ */462463png_uint_32 row_number; /* current row in pass */464#ifdef PNG_READ_SUPPORTED465#ifdef PNG_READ_GAMMA_SUPPORTED466png_fixed_point row_gamma; /* Gamma of final output */467#if 0 /* NYI */468unsigned int gamma_accuracy;469/* LINEAR gamma cache table size (in bits) times 100; for non-linear470* tables the value used is gamma_accuracy/gamma where 'gamma' is the471* encoding value of the data (typically less than 1).472*473* default: PNG_DEFAULT_GAMMA_ACCURACY (665)474*/475#endif /* NYI */476png_uint_16 gamma_threshold;477/* Gamma threshold value as a fixed-point value in the range 0..1; the478* threshold at or below which gamma correction is skipped. '0' forces479* gamma correction even when there is none because the input and output480* gammas are equal.481*482* default: PNG_GAMMA_THRESHOLD_FIXED (153)483*/484#endif /* READ_GAMMA */485#ifdef PNG_READ_TRANSFORMS_SUPPORTED486unsigned int invalid_info; /* PNG_INFO_* for invalidated chunks */487unsigned int palette_updated:1; /* png_struct::palette changed */488#endif /* READ_TRANSFORMS */489#ifdef PNG_SEQUENTIAL_READ_SUPPORTED490unsigned int read_started :1; /* at least one call to png_read_row */491#endif /* SEQUENTIAL_READ */492/* The next field is just used by the read IDAT process functions to store493* the state of IDAT processing; they should not be altered or used by other494* functions.495*/496unsigned int row_state :2; /* state of row parsing (internal) */497#endif /* READ */498499#if defined (PNG_READ_INTERLACING_SUPPORTED) ||\500defined (PNG_WRITE_INTERLACING_SUPPORTED)501unsigned int do_interlace :1; /* libpng handles the interlace */502# endif /* R/W INTERLACING */503504unsigned int pass :3; /* current (interlace) pass (0 - 6) */505506/* The following fields are set by png_row_init to the pixel depths of the507* pixels at various states. If transforms are not supported they will508* always be the same value:509*510* READ WRITE511* input: PNG From application512* output: To application PNG513* max: Largest in transform514*/515unsigned int row_input_pixel_depth :8;516unsigned int row_output_pixel_depth :8;517unsigned int row_max_pixel_depth :8;518519# define PNG_RF_BITS 9 /* Number of bits required for the row format (below) */520#ifdef PNG_TRANSFORM_MECH_SUPPORTED521/* The following fields describe the format of the user row; the output on522* read or the input on write, and give the maximum pixel depth, which523* controls the row buffer allocation size (row_allocated_bytes) above.524*/525unsigned int row_range :3; /* range error count */526unsigned int row_bit_depth :6; /* bits per channel (up to 32) */527unsigned int row_format:PNG_RF_BITS;/* format of output(R)/input(W) row: */528/* PNG_FORMAT_FLAG_ALPHA 0x01U format with an alpha channel529* PNG_FORMAT_FLAG_COLOR 0x02U color format: otherwise grayscale530* PNG_FORMAT_FLAG_LINEAR 0x04U NOT used (informational)531* PNG_FORMAT_FLAG_COLORMAP 0x08U image data is color-mapped532* PNG_FORMAT_FLAG_BGR 0x10U BGR colors, else order is RGB533* PNG_FORMAT_FLAG_AFIRST 0x20U alpha channel comes first *534* PNG_FORAMT_FLAG_AFILLER 0x40U The 'alpha' channel is a filler:535* PNG_FORMAT_FLAG_ALPHA is set however the value in the alpha channel536* is not an alpha value and (therefore) cannot be used for alpha537* computations, it is just a filler value. PNG_COLOR_TYPE_FROM_FORMAT538* will return a color type *without* PNG_COLOR_MASK_ALPHA, however539* PNG_FORMAT_CHANNELS will return the correct number, including the540* filler channel.541* PNG_FORMAT_FLAG_SWAPPED 0x80U bytes or bits swapped:542* When the bit depth is 16 this means that the bytes within the543* components have been swapped, when the bit depth is less than 8544* it means the pixels within the bytes have been swapped. It should545* not be set for 8-bit compononents (it is meaningless).546* PNG_FORMAT_FLAG_RANGE 0x100U component range not 0..bit-depth:547* Low-bit-depth grayscale components have been unpacked into bytes548* without scaling, or RGB[A] pixels have been shifted back to the549* significant-bit range from the sBIT chunk or channels (currently550* alpha or gray) have been inverted.551* PNG_FORMAT_FLAG_INVALID NOT STORED HERE552*/553#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED554unsigned int info_format:PNG_RF_BITS;555/* This field is used to validate the png_info used to write the556* IHDR. This is a new check in 1.7.0; previously it was possible to pass557* a png_info from a png_read with the read tranform information in the558* format having manually removed the required transforms from the rows559* passed to png_write_row.560*/561#endif /* WRITE_TRANSFORMS */562#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED563unsigned int write_invert_alpha :1;564/* This indicates the png_set_invert_alpha was called, it is used by the565* write code to implement the transform without needing to run the whole566* transform mechanism on the PNG palette data.567*/568#endif /* WRITE_INVERT_ALPHA */569#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED570unsigned int rgb_to_gray_status :1;571/* If set an RGB pixel was encountered by the RGB to gray transform572* wherein !(r==g==b).573*/574#endif /* RGB_TO_GRAY */575#endif /* TRANSFORM_MECH */576577#ifdef PNG_READ_SUPPORTED578/* These, and IDAT_size below, control how much input and output (at most) is579* available to zlib during read decompression.580*/581png_alloc_size_t read_buffer_size; /* current size of the buffer */582#endif /* READ */583584#if defined(PNG_SEQUENTIAL_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)585png_uint_32 IDAT_size; /* limit on IDAT read and write IDAT size */586#endif /* SEQUENTIAL_READ || WRITE */587588/* ERROR HANDLING */589#ifdef PNG_SETJMP_SUPPORTED590jmp_buf *jmp_buf_ptr; /* passed to longjmp_fn */591png_longjmp_ptr longjmp_fn; /* setjmp non-local goto function. */592size_t jmp_buf_size; /* size of *jmp_buf_ptr, if allocated */593#endif /* SETJMP */594595/* Error/warning callbacks */596png_error_ptr error_fn; /* print an error message and abort */597#ifdef PNG_WARNINGS_SUPPORTED598png_error_ptr warning_fn; /* print a warning and continue */599#endif /* WARNINGS */600png_voidp error_ptr; /* user supplied data for the above */601602/* MEMORY ALLOCATION */603#ifdef PNG_USER_MEM_SUPPORTED604png_malloc_ptr malloc_fn; /* allocate memory */605png_free_ptr free_fn; /* free memory */606png_voidp mem_ptr; /* user supplied data for the above */607#endif /* USER_MEM */608609/* IO and BASIC READ/WRITE SUPPORT */610png_voidp io_ptr; /* user supplied data for IO callbacks */611png_rw_ptr rw_data_fn; /* read/write some bytes (must succeed) */612613#ifdef PNG_READ_SUPPORTED614png_read_status_ptr read_row_fn; /* called after each row is decoded */615png_bytep read_buffer; /* buffer for reading chunk data */616617/* During read the following array is set up to point to the appropriate618* un-filter function, this allows per-image and per-processor optimization.619*/620void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_alloc_size_t row_bytes,621unsigned int bpp, png_bytep row, png_const_bytep prev_row,622png_const_bytep prev_pixels);623#endif /* READ */624625#ifdef PNG_WRITE_SUPPORTED626png_write_status_ptr write_row_fn; /* called after each row is encoded */627628#ifdef PNG_WRITE_FLUSH_SUPPORTED629png_flush_ptr output_flush_fn; /* Function for flushing output */630#endif /* WRITE_FLUSH */631#endif /* WRITE */632633#ifdef PNG_SET_USER_LIMITS_SUPPORTED634png_uint_32 user_width_max; /* Maximum width on read */635png_uint_32 user_height_max; /* Maximum height on read */636/* Total memory that a single zTXt, sPLT, iTXt, iCCP, or unknown chunk637* can occupy when decompressed. 0 means unlimited. This field is a counter638* - it is decremented as memory is allocated.639*/640png_alloc_size_t user_chunk_malloc_max;641#endif /* SET_USER_LIMITS */642#ifdef PNG_USER_LIMITS_SUPPORTED643/* limit on total *number* of sPLT, text and unknown chunks that can be644* stored. 0 means unlimited. This field is a counter - it is decremented645* as chunks are encountered.646*/647png_uint_32 user_chunk_cache_max;648#endif /* USER_LIMITS */649650/* The progressive reader gets passed data and calls application handling651* functions when appropriate.652*/653#ifdef PNG_PROGRESSIVE_READ_SUPPORTED654png_progressive_info_ptr info_fn; /* called after header data fully read */655png_progressive_row_ptr row_fn; /* called after a row is decoded */656png_progressive_end_ptr end_fn; /* called after image is complete */657658/* Progressive read control data */659png_bytep save_buffer_ptr; /* current location in save_buffer */660png_bytep save_buffer; /* buffer for previously read data */661png_bytep current_buffer_ptr; /* current location in current_buffer */662663size_t save_buffer_size; /* amount of data now in save_buffer */664size_t save_buffer_max; /* total size of save_buffer */665size_t current_buffer_size; /* amount of data now in current_buffer */666size_t buffer_size; /* total amount of available input data */667668unsigned int process_mode :8;669/* This is one or two four bit codes describing the current state of the670* 'push' reader. Normally the low four bits are a state code, however in671* some cases this may be pushed to the top four bits and replaced by a672* different temporary state code. The value is, in effect, a two entry673* stack.674*/675#endif /* PROGRESSIVE_READ */676677#ifdef PNG_IO_STATE_SUPPORTED678png_uint_32 io_state; /* tells the app read/write progress */679#endif /* IO_STATE */680681/* UNKNOWN CHUNK HANDLING */682/* TODO: this is excessively complicated, there are multiple ways of doing683* the same thing. It should be cleaned up, possibly by finding out which684* APIs applications really use.685*/686#ifdef PNG_USER_CHUNKS_SUPPORTED687/* General purpose pointer for all user/unknown chunk handling; points to688* application supplied data for use in the read_user_chunk_fn callback689* (currently there is no write side support - the write side must use the690* set_unknown_chunks interface.)691*/692png_voidp user_chunk_ptr;693#endif /* USER_CHUNKS */694695#ifdef PNG_READ_USER_CHUNKS_SUPPORTED696/* This is called back from the unknown chunk handling */697png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */698#endif /* READ_USER_CHUNKS */699700#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED701png_uint_32 known_unknown; /* Bit mask of known chunks to be treated as702* unknown in the read code.703*/704#ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED705png_uint_32 save_unknown; /* Whether to save or skip these chunks:706* 'save' is 'known & save', 'skip' is707* 'known & ~save'.708*/709# define png_IDATs_skipped(pp) (((pp)->known_unknown & ~(pp)->save_unknown)&1U)710#else /* !SAVE_UNKNOWN_CHUNKS */711# define png_IDATs_skipped(pp) ((pp)->known_unknown & 1U)712#endif /* !SAVE_UNKNOWN_CHUNKS */713#endif /* HANDLE_AS_UNKNOWN */714715#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED716png_bytep chunk_list; /* List of png_byte[5]; the textual chunk name717* followed by a PNG_HANDLE_* byte */718unsigned int unknown_default :2; /* As PNG_HANDLE_* */719unsigned int num_chunk_list; /* Number of entries in the list */720#endif /* SET_UNKNOWN_CHUNKS */721722/* COMPRESSION AND DECOMPRESSION SUPPORT.723*724* zlib expects a 'zstream' as the fundamental control structure, it allows725* all the parameters to be passed as one pointer.726*/727png_uint_32 zowner; /* ID (chunk type) of zlib owner, 0 if none */728# ifdef PNG_WRITE_SUPPORTED729png_zlib_statep zlib_state; /* State of zlib compression */730# endif /* WRITE */731# ifdef PNG_READ_SUPPORTED732z_stream zstream; /* decompression structure */733unsigned int zstream_ended:1; /* no more zlib output available [read] */734unsigned int zstream_error:1; /* zlib error message has been output [read] */735# endif /* READ */736# ifdef PNG_PROGRESSIVE_READ_SUPPORTED737unsigned int zstream_eod :1; /* all the required uncompressed data has been738* received; set by the zstream using code for739* its own purposes. [progressive read] */740# endif /* PROGRESSIVE_READ */741# ifdef PNG_BENIGN_ERRORS_SUPPORTED742unsigned int benign_error_action :2;743unsigned int app_warning_action :2;744unsigned int app_error_action :2;745# ifdef PNG_READ_SUPPORTED746unsigned int IDAT_error_action :2;747# endif /* READ */748# endif /* BENIGN_ERRORS */749# ifdef PNG_READ_SUPPORTED750/* CRC checking actions, one for critical chunks, one for ancillary751* chunks.752*/753unsigned int critical_crc :2;754unsigned int ancillary_crc :2;755unsigned int current_crc :2; /* Cache of one or other of the above */756# endif757# ifdef PNG_SET_OPTION_SUPPORTED758# ifdef PNG_READ_SUPPORTED759unsigned int maximum_inflate_window :1U;760# endif /* READ */761unsigned int skip_sRGB_profile_check :1U;762# endif /* SET_OPTION */763764/* MNG SUPPORT */765#ifdef PNG_MNG_FEATURES_SUPPORTED766unsigned int mng_features_permitted :3;767#endif /* MNG_FEATURES */768769/* SCRATCH buffers, used when control returns to the application or a read770* loop.771*/772# ifdef PNG_READ_SUPPORTED773png_byte scratch[PNG_ROW_BUFFER_SIZE+16U];774# endif /* READ */775};776#endif /* PNGSTRUCT_H */777778779