File tree Expand file tree Collapse file tree 2 files changed +25
-7
lines changed
Expand file tree Collapse file tree 2 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -140,6 +140,30 @@ it implements a subset of its features:
140140The ` SPNG_CTX_IGNORE_ADLER32 ` context flag has the same effect as ` PNG_IGNORE_ADLER32 `
141141used with ` png_set_option() ` .
142142
143+ ## Memory usage
144+
145+ The library will always allocate a context buffer,
146+ if the input PNG is a stream or file it will also create a read buffer.
147+
148+ Decoding an image requires at least 2 rows to be kept in memory,
149+ 3 if the image is interlaced.
150+
151+ Gamma correction requires an additional 128KB for a lookup table if
152+ the output format has 16 bits per channel (e.g. ` SPNG_FMT_RGBA16 ` ).
153+
154+ To limit memory usage for image decoding use ` spng_set_image_limits() `
155+ to set an image width/height limit.
156+ This is the equivalent of ` png_set_user_limits() ` .
157+
158+ Moreover the size calculated by ` spng_decoded_image_size() ` can be checked
159+ against a hard limit before allocating memory for the output image.
160+
161+ Chunks of arbitrary length (e.g. text, color profiles) take up additional memory,
162+ ` spng_set_chunk_limits() ` is used to set hard limits on chunk length- and cache limits,
163+ note that reaching either limit is handled as a fatal error.
164+
165+ This function combines the functionality of libpng's ` png_set_chunk_cache_max() ` and ` png_set_chunk_malloc_max() ` .
166+
143167# API
144168
145169# spng_set_png_buffer()
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ spng_ctx_free(ctx);
2626
2727```
2828
29- For a complete example see [example.c](https://github.com/randy408/libspng/blob/v0.6.3/examples/example.c)
29+ For a complete example see [example.c](https://github.com/randy408/libspng/blob/v0.6.3/examples/example.c).
3030
3131
3232## Decoding untrusted files
@@ -42,9 +42,3 @@ To decode untrusted files safely it is required to at least:
4242 to avoid running out of memory. Note that exceeding either limit is
4343 handled as an out-of-memory error since v0.6.0.
4444
45- ### Notes on memory use
46-
47- The library allocates 2 to 3 times the width of the PNG image for decoding.
48-
49- Gamma correction requires an additional 128KB for a lookup table if
50- the output format has 16-bits per channel (e.g. `SPNG_FMT_RGBA16`).
You can’t perform that action at this time.
0 commit comments