1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
|
# Semantics
* Chunk data is stored in `spng_ctx`.
* All `spng_get_*()` functions return 0 on success and non-zero error,
`SPNG_ECHUNKAVAIL` if the PNG does not contain that chunk or was not previously
set.
* A successful `spng_set_*()` call will replace any previously set value or list,
it does not combine chunk data from the file or multiple `spng_set_*()` calls.
The following apply to decoder contexts:
* When calling `spng_get_*()` or `spng_set_*()` functions all
chunks up to the first IDAT are read, validated then stored
with the exception of `spng_get_ihdr()`, which only reads the header.
* When calling `spng_get_*()` after the image has been decoded all
chunks up to the IEND marker are read.
* `spng_set_*()` functions replace stored chunk data for that type.
* Chunk data stored with `spng_set_*()` functions are never replaced with
input file chunk data i.e. if you set something it will stay that way.
# API
# spng_get_ihdr()
```c
int spng_get_ihdr(spng_ctx *ctx, struct spng_ihdr *ihdr)
```
Get image header
# spng_get_plte()
```c
int spng_get_plte(spng_ctx *ctx, struct spng_plte *plte)
```
Get image palette
# spng_get_trns()
```c
int spng_get_trns(spng_ctx *ctx, struct spng_trns *trns)
```
Get image transparency
# spng_get_chrm()
```c
int spng_get_chrm(spng_ctx *ctx, struct spng_chrm *chrm)
```
Get primary chromacities and white point as floating point numbers
# spng_get_chrm_int()
```c
int spng_get_chrm_int(spng_ctx *ctx, struct spng_chrm_int *chrm_int)
```
Get primary chromacities and white point in PNG's internal representation
# spng_get_gama()
```c
int spng_get_gama(spng_ctx *ctx, double *gamma)
```
Get image gamma
# spng_get_gama_int()
```c
int spng_get_gama_int(spng_ctx *ctx, uint32_t *gamma)
```
Get image gamma in PNG's internal representation
# spng_get_iccp()
```c
int spng_get_iccp(spng_ctx *ctx, struct spng_iccp *iccp)
```
Get ICC profile
!!! note
ICC profiles are not validated.
# spng_get_sbit()
```c
int spng_get_sbit(spng_ctx *ctx, struct spng_sbit *sbit)
```
Get significant bits
# spng_get_srgb()
```c
int spng_get_srgb(spng_ctx *ctx, uint8_t *rendering_intent)
```
Get rendering intent
# spng_get_text()
```c
int spng_get_text(spng_ctx *ctx, struct spng_text *text, uint32_t *n_text)
```
Copies text information to `text`.
`n_text` should be greater than or equal to the number of stored text chunks.
If `text` is NULL and `n_text` is non-NULL then `n_text` is set to the number
of stored text chunks.
Strings may be zero-length (single `'\0'` character) with the exception of `text.keyword`,
all strings are guaranteed to be non-NULL.
!!! note
Due to the structure of PNG files it is recommended to call this function
after `spng_decode_image()` to retrieve all text chunks.
!!! warning
Text data is freed when calling `spng_ctx_free()`.
# spng_get_bkgd()
```c
int spng_get_bkgd(spng_ctx *ctx, struct spng_bkgd *bkgd)
```
Get image background color
# spng_get_hist()
```c
int spng_get_hist(spng_ctx *ctx, struct spng_hist *hist)
```
Get image histogram
# spng_get_phys()
```c
int spng_get_phys(spng_ctx *ctx, struct spng_phys *phys)
```
Get physical pixel dimensions
# spng_get_splt()
```c
int spng_get_splt(spng_ctx *ctx, struct spng_splt *splt, uint32_t *n_splt)
```
Copies suggested palettes to `splt`.
`n_splt` should be greater than or equal to the number of stored sPLT chunks.
If `splt` is NULL and `n_splt` is non-NULL then `n_splt` is set to the number
of stored sPLT chunks.
!!! warning
Suggested palettes are freed when calling `spng_ctx_free()`.
# spng_get_time()
```c
int spng_get_time(spng_ctx *ctx, struct spng_time *time)
```
Get modification time
!!! note
Due to the structure of PNG files it is recommended to call this function
after `spng_decode_image()`.
# spng_get_unknown_chunks()
```c
int spng_get_unknown_chunks(spng_ctx *ctx, struct spng_unknown_chunk *chunks, uint32_t *n_chunks)
```
Copies unknown chunk information to `chunks`.
`n_chunks` should be greater than or equal to the number of stored unknown chunks.
If `chunks` is NULL and `n_chunks` is non-NULL then `n_chunks` is set to the number
of stored chunks.
!!! note
To retrieve all unknown chunks call this functions after `spng_decode_image()`.
!!! warning
Chunk data is freed when calling `spng_ctx_free()`.
# spng_get_offs()
```c
int spng_get_offs(spng_ctx *ctx, struct spng_offs *offs)
```
Get image offset
# spng_get_exif()
```c
int spng_get_exif(spng_ctx *ctx, struct spng_exif *exif)
```
Get EXIF data
!!! note
Due to the structure of PNG files it is recommended to call this function
after `spng_decode_image()`.
!!! warning
`exif.data` is freed when calling `spng_ctx_free()`.
# spng_set_ihdr()
```c
int spng_set_ihdr(spng_ctx *ctx, struct spng_ihdr *ihdr)
```
Set image header
# spng_set_plte()
```c
int spng_set_plte(spng_ctx *ctx, struct spng_plte *plte)
```
Set image palette
# spng_set_trns()
```c
int spng_set_trns(spng_ctx *ctx, struct spng_trns *trns)
```
Set transparency
# spng_set_chrm()
```c
int spng_set_chrm(spng_ctx *ctx, struct spng_chrm *chrm)
```
Set primary chromacities and white point as floating point numbers
# spng_set_chrm_int()
```c
int spng_set_chrm_int(spng_ctx *ctx, struct spng_chrm_int *chrm_int)
```
Set primary chromacities and white point in PNG's internal representation
# spng_set_gama()
```c
int spng_set_gama(spng_ctx *ctx, double gamma)
```
Set image gamma
# spng_set_gama_int()
```c
int spng_set_gama_int(spng_ctx *ctx, uint32_t gamma)
```
Set image gamma in PNG's internal representation
# spng_set_iccp()
```c
int spng_set_iccp(spng_ctx *ctx, struct spng_iccp *iccp)
```
Set ICC profile
`spng_iccp.profile_name` must only contain printable Latin-1 characters and spaces.
Leading, trailing, and consecutive spaces are not permitted.
!!! note
ICC profiles are not validated.
# spng_set_sbit()
```c
int spng_set_sbit(spng_ctx *ctx, struct spng_sbit *sbit)
```
Set significant bits
# spng_set_srgb()
```c
int spng_set_srgb(spng_ctx *ctx, uint8_t rendering_intent)
```
Set rendering intent
# spng_set_text()
```c
int spng_set_text(spng_ctx *ctx, struct spng_text *text, uint32_t n_text)
```
Set text data
`text` should point to an `spng_text` array of `n_text` elements.
`spng_text.text` must only contain Latin-1 characters.
Newlines must be a single linefeed character (decimal 10).
`spng_text.translated_keyword` must not contain linebreaks.
`spng_text.compression_method` must be zero.
# spng_set_bkgd()
```c
int spng_set_bkgd(spng_ctx *ctx, struct spng_bkgd *bkgd)
```
Set image background color
# spng_set_hist()
```c
int spng_set_hist(spng_ctx *ctx, struct spng_hist *hist)
```
Set image histogram
# spng_set_phys()
```c
int spng_set_phys(spng_ctx *ctx, struct spng_phys *phys)
```
Set physical pixel dimensions
# spng_set_splt()
```c
int spng_set_splt(spng_ctx *ctx, struct spng_splt *splt, uint32_t n_splt)
```
Set suggested palette(s).
`splt` should point to an `spng_splt` array of `n_splt` elements.
!!! note
`splt` should be a valid reference for the lifetime of the context.
# spng_set_time()
```c
int spng_set_time(spng_ctx *ctx, struct spng_time *time)
```
Set modification time
# spng_set_unknown_chunks()
```c
int spng_set_unknown_chunks(spng_ctx *ctx, struct spng_unknown_chunk *chunks, uint32_t n_chunks)
```
Set unknown chunk data.
!!! note
`chunks` should be a valid reference for the lifetime of the context.
# spng_set_offs()
```c
int spng_set_offs(spng_ctx *ctx, struct spng_offs *offs)
```
Set image offset
# spng_set_exif()
```c
int spng_set_exif(spng_ctx *ctx, struct spng_exif *exif)
```
Set EXIF data
|