@@ -16,24 +16,108 @@ typedef struct spng_ctx spng_ctx;
1616``` c
1717enum spng_ctx_flags
1818{
19- SPNG_CTX_IGNORE_ADLER32 = 1 /* ignore checksum in DEFLATE streams */
19+ SPNG_CTX_IGNORE_ADLER32 = 1, /* Ignore checksum in DEFLATE streams */
20+ SPNG_CTX_ENCODER = 2 /* Create an encoder context */
2021};
2122```
2223
23- # spng_crc_action
24+ # spng_read_fn
25+ ``` c
26+ typedef int spng_read_fn (spng_ctx * ctx, void * user, void * dest, size_t length)
27+ ```
28+
29+ Type definition for callback passed to `spng_set_png_stream()` for decoders.
30+
31+ A read callback function should copy `length` bytes to `dest` and return 0 or
32+ `SPNG_IO_EOF`/`SPNG_IO_ERROR` on error.
33+
34+
35+ # spng_write_fn
36+ ```c
37+ typedef int spng_write_fn(spng_ctx *ctx, void *user, void *src, size_t length)
38+ ```
39+
40+ Type definition for callback passed to ` spng_set_png_stream() ` for encoders.
41+
42+ The write callback should process ` length ` bytes and return 0 or ` SPNG_IO_ERROR ` on error.
43+
44+
45+ # spng_format
46+ ``` c
47+ enum spng_format
48+ {
49+ SPNG_FMT_RGBA8 = 1,
50+ SPNG_FMT_RGBA16 = 2,
51+ SPNG_FMT_RGB8 = 4,
52+
53+ SPNG_FMT_GA8 = 16,
54+ SPNG_FMT_GA16 = 32,
55+ SPNG_FMT_G8 = 64,
56+
57+ /* No conversion or scaling */
58+ SPNG_FMT_PNG = 256, /* host-endian */
59+ SPNG_FMT_RAW = 512 /* big-endian */
60+ };
61+ ```
62+
63+ The channels are always in [ byte-order] ( https://en.wikipedia.org/wiki/RGBA_color_model#RGBA8888 ) representation.
64+
65+ # spng_filter
66+ ``` c
67+ enum spng_filter
68+ {
69+ SPNG_FILTER_NONE = 0,
70+ SPNG_FILTER_SUB = 1,
71+ SPNG_FILTER_UP = 2,
72+ SPNG_FILTER_AVERAGE = 3,
73+ SPNG_FILTER_PAETH = 4
74+ };
75+ ```
2476
77+ # spng_row_info
2578``` c
26- enum spng_crc_action
79+ struct spng_row_info
2780{
28- /* Default for critical chunks */
29- SPNG_CRC_ERROR = 0,
81+ uint32_t scanline_idx;
82+ uint32_t row_num;
83+ int pass;
84+ uint8_t filter;
85+ };
86+ ```
87+
88+ Contains row and scanline information, used for progressive decoding and encoding.
89+
90+ # spng_option
91+ ``` c
92+ enum spng_option
93+ {
94+ SPNG_KEEP_UNKNOWN_CHUNKS = 1,
3095
31- /* Discard chunk, invalid for critical chunks,
32- since v0.6.2: default for ancillary chunks */
33- SPNG_CRC_DISCARD = 1,
96+ SPNG_IMG_COMPRESSION_LEVEL,
97+ SPNG_IMG_WINDOW_BITS,
98+ SPNG_IMG_MEM_LEVEL,
99+ SPNG_IMG_COMPRESSION_STRATEGY,
34100
35- /* Ignore and don't calculate checksum */
36- SPNG_CRC_USE = 2
101+ SPNG_TEXT_COMPRESSION_LEVEL,
102+ SPNG_TEXT_WINDOW_BITS,
103+ SPNG_TEXT_MEM_LEVEL,
104+ SPNG_TEXT_COMPRESSION_STRATEGY,
105+
106+ SPNG_FILTER_CHOICE,
107+ };
108+ ```
109+
110+ # spng_filter_choice
111+ ``` c
112+ enum spng_filter_choice
113+ {
114+ SPNG_DISABLE_FILTERING = 0,
115+ SPNG_FILTER_CHOICE_NONE = 8,
116+ SPNG_FILTER_CHOICE_SUB = 16,
117+ SPNG_FILTER_CHOICE_UP = 32,
118+ SPNG_FILTER_CHOICE_AVG = 64,
119+ SPNG_FILTER_CHOICE_PAETH = 128,
120+ SPNG_FILTER_CHOICE_ALL = (8|16|32|64|128)
37121};
38122```
39123
@@ -62,6 +146,27 @@ void spng_ctx_free(spng_ctx *ctx)
62146
63147Releases context resources.
64148
149+ # spng_set_png_stream()
150+ ```c
151+ int spng_set_png_stream(spng_ctx *ctx, spng_rw_fn *rw_func, void *user)
152+ ```
153+
154+ Set input PNG stream or output PNG stream, depending on context type.
155+
156+ This can only be done once per context.
157+
158+ !!! info
159+ PNG's are read up to the file end marker, this is identical behavior to libpng.
160+
161+ # spng_set_png_file()
162+ ``` c
163+ int spng_set_png_file (spng_ctx * ctx, FILE * file)
164+ ```
165+
166+ Set input PNG file or output PNG file, depending on context type.
167+
168+ This can only be done once per context.
169+
65170# spng_set_image_limits()
66171```c
67172int spng_set_image_limits(spng_ctx *ctx, uint32_t width, uint32_t height)
@@ -78,13 +183,6 @@ Get image width and height limits.
78183
79184`width` and `height` must be non-NULL.
80185
81- # spng_set_crc_action()
82- ```c
83- int spng_set_crc_action(spng_ctx *ctx, int critical, int ancillary)
84- ```
85-
86- Set how chunk CRC errors should be handled for critical and ancillary chunks.
87-
88186# spng_set_chunk_limits()
89187```c
90188int spng_set_chunk_limits(spng_ctx *ctx, size_t chunk_size, size_t cache_limit)
@@ -105,3 +203,24 @@ int spng_get_chunk_limits(spng_ctx *ctx, size_t *chunk_size, size_t *cache_limit
105203```
106204
107205Get chunk size and chunk cache limits.
206+
207+ # spng_get_row_info()
208+ ```c
209+ int spng_get_row_info(spng_ctx *ctx, struct spng_row_info *row_info)
210+ ```
211+
212+ Copies the current, to-be-decoded (or to-be-encoded) row's information to ` row_info ` .
213+
214+ # spng_set_option()
215+ ``` c
216+ int spng_set_option (spng_ctx * ctx, enum spng_option option, int value)
217+ ```
218+
219+ Set `option` to the specified `value`.
220+
221+ # spng_get_option()
222+ ```c
223+ int spng_get_option(spng_ctx *ctx, enum spng_option option, int *value)
224+ ```
225+
226+ Get the value for the specified ` option ` .
0 commit comments