File tree 2 files changed +25
-7
lines changed
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:
140
140
The ` SPNG_CTX_IGNORE_ADLER32 ` context flag has the same effect as ` PNG_IGNORE_ADLER32 `
141
141
used with ` png_set_option() ` .
142
142
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
+
143
167
# API
144
168
145
169
# spng_set_png_buffer()
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ spng_ctx_free(ctx);
26
26
27
27
```
28
28
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).
30
30
31
31
32
32
## Decoding untrusted files
@@ -42,9 +42,3 @@ To decode untrusted files safely it is required to at least:
42
42
to avoid running out of memory. Note that exceeding either limit is
43
43
handled as an out-of-memory error since v0.6.0.
44
44
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