@revizly/sharp-libvips-dev 1.0.52 → 1.0.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +2 -0
  2. package/include/brotli/decode.h +409 -0
  3. package/include/brotli/encode.h +505 -0
  4. package/include/brotli/port.h +302 -0
  5. package/include/brotli/shared_dictionary.h +100 -0
  6. package/include/brotli/types.h +83 -0
  7. package/include/expat.h +72 -27
  8. package/include/expat_config.h +3 -7
  9. package/include/expat_external.h +3 -0
  10. package/include/glib-2.0/glib/gutils.h +1 -1
  11. package/include/harfbuzz/hb-version.h +2 -2
  12. package/include/jxl/cms.h +24 -0
  13. package/include/jxl/cms_interface.h +255 -0
  14. package/include/jxl/codestream_header.h +433 -0
  15. package/include/jxl/color_encoding.h +161 -0
  16. package/include/jxl/compressed_icc.h +75 -0
  17. package/include/jxl/decode.h +1475 -0
  18. package/include/jxl/decode_cxx.h +58 -0
  19. package/include/jxl/encode.h +1629 -0
  20. package/include/jxl/encode_cxx.h +58 -0
  21. package/include/jxl/gain_map.h +129 -0
  22. package/include/jxl/jxl_cms_export.h +42 -0
  23. package/include/jxl/jxl_export.h +42 -0
  24. package/include/jxl/jxl_threads_export.h +42 -0
  25. package/include/jxl/memory_manager.h +73 -0
  26. package/include/jxl/parallel_runner.h +164 -0
  27. package/include/jxl/resizable_parallel_runner.h +77 -0
  28. package/include/jxl/resizable_parallel_runner_cxx.h +65 -0
  29. package/include/jxl/stats.h +103 -0
  30. package/include/jxl/thread_parallel_runner.h +71 -0
  31. package/include/jxl/thread_parallel_runner_cxx.h +66 -0
  32. package/include/jxl/types.h +154 -0
  33. package/include/jxl/version.h +44 -0
  34. package/include/libheif/heif_context.h +7 -4
  35. package/include/libheif/heif_encoding.h +5 -0
  36. package/include/libheif/heif_error.h +7 -0
  37. package/include/libheif/heif_image.h +10 -0
  38. package/include/libheif/heif_tiling.h +12 -0
  39. package/include/libheif/heif_version.h +2 -2
  40. package/include/libpng16/png.h +7 -7
  41. package/include/libpng16/pngconf.h +1 -1
  42. package/include/libpng16/pnglibconf.h +1 -1
  43. package/include/png.h +7 -7
  44. package/include/pngconf.h +1 -1
  45. package/include/pnglibconf.h +1 -1
  46. package/include/vips/version.h +1 -1
  47. package/package.json +1 -1
  48. package/versions.json +8 -6
@@ -0,0 +1,1475 @@
1
+ /* Copyright (c) the JPEG XL Project Authors. All rights reserved.
2
+ *
3
+ * Use of this source code is governed by a BSD-style
4
+ * license that can be found in the LICENSE file.
5
+ */
6
+
7
+ /** @addtogroup libjxl_decoder
8
+ * @{
9
+ * @file decode.h
10
+ * @brief Decoding API for JPEG XL.
11
+ */
12
+
13
+ #ifndef JXL_DECODE_H_
14
+ #define JXL_DECODE_H_
15
+
16
+ #include <jxl/cms_interface.h>
17
+ #include <jxl/codestream_header.h>
18
+ #include <jxl/color_encoding.h>
19
+ #include <jxl/jxl_export.h>
20
+ #include <jxl/memory_manager.h>
21
+ #include <jxl/parallel_runner.h>
22
+ #include <jxl/types.h>
23
+ #include <jxl/version.h> // TODO(eustas): remove before v1.0
24
+ #include <stddef.h>
25
+ #include <stdint.h>
26
+
27
+ #ifdef __cplusplus
28
+ extern "C" {
29
+ #endif
30
+
31
+ /**
32
+ * Decoder library version.
33
+ *
34
+ * @return the decoder library version as an integer:
35
+ * MAJOR_VERSION * 1000000 + MINOR_VERSION * 1000 + PATCH_VERSION. For example,
36
+ * version 1.2.3 would return 1002003.
37
+ */
38
+ JXL_EXPORT uint32_t JxlDecoderVersion(void);
39
+
40
+ /** The result of @ref JxlSignatureCheck.
41
+ */
42
+ typedef enum {
43
+ /** Not enough bytes were passed to determine if a valid signature was found.
44
+ */
45
+ JXL_SIG_NOT_ENOUGH_BYTES = 0,
46
+
47
+ /** No valid JPEG XL header was found. */
48
+ JXL_SIG_INVALID = 1,
49
+
50
+ /** A valid JPEG XL codestream signature was found, that is a JPEG XL image
51
+ * without container.
52
+ */
53
+ JXL_SIG_CODESTREAM = 2,
54
+
55
+ /** A valid container signature was found, that is a JPEG XL image embedded
56
+ * in a box format container.
57
+ */
58
+ JXL_SIG_CONTAINER = 3,
59
+ } JxlSignature;
60
+
61
+ /**
62
+ * JPEG XL signature identification.
63
+ *
64
+ * Checks if the passed buffer contains a valid JPEG XL signature. The passed @p
65
+ * buf of size
66
+ * @p size doesn't need to be a full image, only the beginning of the file.
67
+ *
68
+ * @return a flag indicating if a JPEG XL signature was found and what type.
69
+ * - ::JXL_SIG_NOT_ENOUGH_BYTES if not enough bytes were passed to
70
+ * determine if a valid signature is there.
71
+ * - ::JXL_SIG_INVALID if no valid signature found for JPEG XL decoding.
72
+ * - ::JXL_SIG_CODESTREAM if a valid JPEG XL codestream signature was
73
+ * found.
74
+ * - ::JXL_SIG_CONTAINER if a valid JPEG XL container signature was found.
75
+ */
76
+ JXL_EXPORT JxlSignature JxlSignatureCheck(const uint8_t* buf, size_t len);
77
+
78
+ /**
79
+ * Opaque structure that holds the JPEG XL decoder.
80
+ *
81
+ * Allocated and initialized with @ref JxlDecoderCreate().
82
+ * Cleaned up and deallocated with @ref JxlDecoderDestroy().
83
+ */
84
+ typedef struct JxlDecoder JxlDecoder;
85
+
86
+ /**
87
+ * Creates an instance of @ref JxlDecoder and initializes it.
88
+ *
89
+ * @p memory_manager will be used for all the library dynamic allocations made
90
+ * from this instance. The parameter may be NULL, in which case the default
91
+ * allocator will be used. See jxl/memory_manager.h for details.
92
+ *
93
+ * @param memory_manager custom allocator function. It may be NULL. The memory
94
+ * manager will be copied internally.
95
+ * @return @c NULL if the instance can not be allocated or initialized
96
+ * @return pointer to initialized @ref JxlDecoder otherwise
97
+ */
98
+ JXL_EXPORT JxlDecoder* JxlDecoderCreate(const JxlMemoryManager* memory_manager);
99
+
100
+ /**
101
+ * Re-initializes a @ref JxlDecoder instance, so it can be re-used for decoding
102
+ * another image. All state and settings are reset as if the object was
103
+ * newly created with @ref JxlDecoderCreate, but the memory manager is kept.
104
+ *
105
+ * @param dec instance to be re-initialized.
106
+ */
107
+ JXL_EXPORT void JxlDecoderReset(JxlDecoder* dec);
108
+
109
+ /**
110
+ * Deinitializes and frees @ref JxlDecoder instance.
111
+ *
112
+ * @param dec instance to be cleaned up and deallocated.
113
+ */
114
+ JXL_EXPORT void JxlDecoderDestroy(JxlDecoder* dec);
115
+
116
+ /**
117
+ * Return value for @ref JxlDecoderProcessInput.
118
+ * The values from ::JXL_DEC_BASIC_INFO onwards are optional informative
119
+ * events that can be subscribed to, they are never returned if they
120
+ * have not been registered with @ref JxlDecoderSubscribeEvents.
121
+ */
122
+ typedef enum {
123
+ /** Function call finished successfully, or decoding is finished and there is
124
+ * nothing more to be done.
125
+ *
126
+ * Note that @ref JxlDecoderProcessInput will return ::JXL_DEC_SUCCESS if
127
+ * all events that were registered with @ref JxlDecoderSubscribeEvents were
128
+ * processed, even before the end of the JPEG XL codestream.
129
+ *
130
+ * In this case, the return value @ref JxlDecoderReleaseInput will be the same
131
+ * as it was at the last signaled event. E.g. if ::JXL_DEC_FULL_IMAGE was
132
+ * subscribed to, then all bytes from the end of the JPEG XL codestream
133
+ * (including possible boxes needed for jpeg reconstruction) will be returned
134
+ * as unprocessed.
135
+ */
136
+ JXL_DEC_SUCCESS = 0,
137
+
138
+ /** An error occurred, for example invalid input file or out of memory.
139
+ * TODO(lode): add function to get error information from decoder.
140
+ */
141
+ JXL_DEC_ERROR = 1,
142
+
143
+ /** The decoder needs more input bytes to continue. Before the next @ref
144
+ * JxlDecoderProcessInput call, more input data must be set, by calling @ref
145
+ * JxlDecoderReleaseInput (if input was set previously) and then calling @ref
146
+ * JxlDecoderSetInput. @ref JxlDecoderReleaseInput returns how many bytes
147
+ * are not yet processed, before a next call to @ref JxlDecoderProcessInput
148
+ * all unprocessed bytes must be provided again (the address need not match,
149
+ * but the contents must), and more bytes must be concatenated after the
150
+ * unprocessed bytes.
151
+ * In most cases, @ref JxlDecoderReleaseInput will return no unprocessed bytes
152
+ * at this event, the only exceptions are if the previously set input ended
153
+ * within (a) the raw codestream signature, (b) the signature box, (c) a box
154
+ * header, or (d) the first 4 bytes of a `brob`, `ftyp`, or `jxlp` box. In any
155
+ * of these cases the number of unprocessed bytes is less than 20.
156
+ */
157
+ JXL_DEC_NEED_MORE_INPUT = 2,
158
+
159
+ /** The decoder is able to decode a preview image and requests setting a
160
+ * preview output buffer using @ref JxlDecoderSetPreviewOutBuffer. This occurs
161
+ * if ::JXL_DEC_PREVIEW_IMAGE is requested and it is possible to decode a
162
+ * preview image from the codestream. There is maximum one preview image in
163
+ * a codestream. In this case, @ref JxlDecoderReleaseInput will return all
164
+ * bytes from the end of the frame header (including ToC) of the preview frame
165
+ * as unprocessed.
166
+ */
167
+ JXL_DEC_NEED_PREVIEW_OUT_BUFFER = 3,
168
+
169
+ /** The decoder requests an output buffer to store the full resolution image,
170
+ * which can be set with @ref JxlDecoderSetImageOutBuffer or with @ref
171
+ * JxlDecoderSetImageOutCallback. This event re-occurs for new frames if
172
+ * there are multiple animation frames and requires setting an output again.
173
+ * In this case, @ref JxlDecoderReleaseInput will return all bytes from the
174
+ * end of the frame header (including ToC) as unprocessed.
175
+ */
176
+ JXL_DEC_NEED_IMAGE_OUT_BUFFER = 5,
177
+
178
+ /** The JPEG reconstruction buffer is too small for reconstructed JPEG
179
+ * codestream to fit. @ref JxlDecoderSetJPEGBuffer must be called again to
180
+ * make room for remaining bytes. This event may occur multiple times
181
+ * after ::JXL_DEC_JPEG_RECONSTRUCTION.
182
+ */
183
+ JXL_DEC_JPEG_NEED_MORE_OUTPUT = 6,
184
+
185
+ /** The box contents output buffer is too small. @ref JxlDecoderSetBoxBuffer
186
+ * must be called again to make room for remaining bytes. This event may occur
187
+ * multiple times after ::JXL_DEC_BOX.
188
+ */
189
+ JXL_DEC_BOX_NEED_MORE_OUTPUT = 7,
190
+
191
+ /** Informative event by @ref JxlDecoderProcessInput
192
+ * "JxlDecoderProcessInput": Basic information such as image dimensions and
193
+ * extra channels. This event occurs max once per image.
194
+ * In this case, @ref JxlDecoderReleaseInput will return all bytes from the
195
+ * end of the basic info as unprocessed (including the last byte of basic info
196
+ * if it did not end on a byte boundary).
197
+ */
198
+ JXL_DEC_BASIC_INFO = 0x40,
199
+
200
+ /** Informative event by @ref JxlDecoderProcessInput
201
+ * "JxlDecoderProcessInput": Color encoding or ICC profile from the
202
+ * codestream header. This event occurs max once per image and always later
203
+ * than ::JXL_DEC_BASIC_INFO and earlier than any pixel data.
204
+ * In this case, @ref JxlDecoderReleaseInput will return all bytes from the
205
+ * end of the image header (which is the start of the first frame) as
206
+ * unprocessed.
207
+ */
208
+ JXL_DEC_COLOR_ENCODING = 0x100,
209
+
210
+ /** Informative event by @ref JxlDecoderProcessInput
211
+ * "JxlDecoderProcessInput": Preview image, a small frame, decoded. This
212
+ * event can only happen if the image has a preview frame encoded. This event
213
+ * occurs max once for the codestream and always later than @ref
214
+ * JXL_DEC_COLOR_ENCODING and before ::JXL_DEC_FRAME.
215
+ * In this case, @ref JxlDecoderReleaseInput will return all bytes from the
216
+ * end of the preview frame as unprocessed.
217
+ */
218
+ JXL_DEC_PREVIEW_IMAGE = 0x200,
219
+
220
+ /** Informative event by @ref JxlDecoderProcessInput
221
+ * "JxlDecoderProcessInput": Beginning of a frame. @ref
222
+ * JxlDecoderGetFrameHeader can be used at this point. A note on frames:
223
+ * a JPEG XL image can have internal frames that are not intended to be
224
+ * displayed (e.g. used for compositing a final frame), but this only returns
225
+ * displayed frames, unless @ref JxlDecoderSetCoalescing was set to @ref
226
+ * JXL_FALSE "JXL_FALSE": in that case, the individual layers are returned,
227
+ * without blending. Note that even when coalescing is disabled, only frames
228
+ * of type kRegularFrame are returned; frames of type kReferenceOnly
229
+ * and kLfFrame are always for internal purposes only and cannot be accessed.
230
+ * A displayed frame either has an animation duration or is the only or last
231
+ * frame in the image. This event occurs max once per displayed frame, always
232
+ * later than ::JXL_DEC_COLOR_ENCODING, and always earlier than any pixel
233
+ * data. While JPEG XL supports encoding a single frame as the composition of
234
+ * multiple internal sub-frames also called frames, this event is not
235
+ * indicated for the internal frames. In this case, @ref
236
+ * JxlDecoderReleaseInput will return all bytes from the end of the frame
237
+ * header (including ToC) as unprocessed.
238
+ */
239
+ JXL_DEC_FRAME = 0x400,
240
+
241
+ /** Informative event by @ref JxlDecoderProcessInput
242
+ * "JxlDecoderProcessInput": full frame (or layer, in case coalescing is
243
+ * disabled) is decoded. @ref JxlDecoderSetImageOutBuffer must be used after
244
+ * getting the basic image information to be able to get the image pixels, if
245
+ * not this return status only indicates we're past this point in the
246
+ * codestream. This event occurs max once per frame.
247
+ * In this case, @ref JxlDecoderReleaseInput will return all bytes from the
248
+ * end of the frame (or if ::JXL_DEC_JPEG_RECONSTRUCTION is subscribed to,
249
+ * from the end of the last box that is needed for jpeg reconstruction) as
250
+ * unprocessed.
251
+ */
252
+ JXL_DEC_FULL_IMAGE = 0x1000,
253
+
254
+ /** Informative event by @ref JxlDecoderProcessInput
255
+ * "JxlDecoderProcessInput": JPEG reconstruction data decoded. @ref
256
+ * JxlDecoderSetJPEGBuffer may be used to set a JPEG reconstruction buffer
257
+ * after getting the JPEG reconstruction data. If a JPEG reconstruction buffer
258
+ * is set a byte stream identical to the JPEG codestream used to encode the
259
+ * image will be written to the JPEG reconstruction buffer instead of pixels
260
+ * to the image out buffer. This event occurs max once per image and always
261
+ * before ::JXL_DEC_FULL_IMAGE.
262
+ * In this case, @ref JxlDecoderReleaseInput will return all bytes from the
263
+ * end of the `jbrd` box as unprocessed.
264
+ */
265
+ JXL_DEC_JPEG_RECONSTRUCTION = 0x2000,
266
+
267
+ /** Informative event by @ref JxlDecoderProcessInput
268
+ * "JxlDecoderProcessInput": The header of a box of the container format
269
+ * (BMFF) is decoded. The following API functions related to boxes can be used
270
+ * after this event:
271
+ * - @ref JxlDecoderSetBoxBuffer and @ref JxlDecoderReleaseBoxBuffer
272
+ * "JxlDecoderReleaseBoxBuffer": set and release a buffer to get the box
273
+ * data.
274
+ * - @ref JxlDecoderGetBoxType get the 4-character box typename.
275
+ * - @ref JxlDecoderGetBoxSizeRaw get the size of the box as it appears in
276
+ * the container file, not decompressed.
277
+ * - @ref JxlDecoderSetDecompressBoxes to configure whether to get the box
278
+ * data decompressed, or possibly compressed.
279
+ *
280
+ * Boxes can be compressed. This is so when their box type is
281
+ * "brob". In that case, they have an underlying decompressed box
282
+ * type and decompressed data. @ref JxlDecoderSetDecompressBoxes allows
283
+ * configuring which data to get. Decompressing requires
284
+ * Brotli. @ref JxlDecoderGetBoxType has a flag to get the compressed box
285
+ * type, which can be "brob", or the decompressed box type. If a box
286
+ * is not compressed (its compressed type is not "brob"), then
287
+ * the output decompressed box type and data is independent of what
288
+ * setting is configured.
289
+ *
290
+ * The buffer set with @ref JxlDecoderSetBoxBuffer must be set again for each
291
+ * next box to be obtained, or can be left unset to skip outputting this box.
292
+ * The output buffer contains the full box data when the
293
+ * ::JXL_DEC_BOX_COMPLETE (if subscribed to) or subsequent ::JXL_DEC_SUCCESS
294
+ * or ::JXL_DEC_BOX event occurs. ::JXL_DEC_BOX occurs for all boxes,
295
+ * including non-metadata boxes such as the signature box or codestream boxes.
296
+ * To check whether the box is a metadata type for respectively EXIF, XMP or
297
+ * JUMBF, use @ref JxlDecoderGetBoxType and check for types "Exif", "xml " and
298
+ * "jumb" respectively.
299
+ *
300
+ * In this case, @ref JxlDecoderReleaseInput will return all bytes from the
301
+ * start of the box header as unprocessed.
302
+ */
303
+ JXL_DEC_BOX = 0x4000,
304
+
305
+ /** Informative event by @ref JxlDecoderProcessInput
306
+ * "JxlDecoderProcessInput": a progressive step in decoding the frame is
307
+ * reached. When calling @ref JxlDecoderFlushImage at this point, the flushed
308
+ * image will correspond exactly to this point in decoding, and not yet
309
+ * contain partial results (such as partially more fine detail) of a next
310
+ * step. By default, this event will trigger maximum once per frame, when a
311
+ * 8x8th resolution (DC) image is ready (the image data is still returned at
312
+ * full resolution, giving upscaled DC). Use @ref
313
+ * JxlDecoderSetProgressiveDetail to configure more fine-grainedness. The
314
+ * event is not guaranteed to trigger, not all images have progressive steps
315
+ * or DC encoded.
316
+ * In this case, @ref JxlDecoderReleaseInput will return all bytes from the
317
+ * end of the section that was needed to produce this progressive event as
318
+ * unprocessed.
319
+ */
320
+ JXL_DEC_FRAME_PROGRESSION = 0x8000,
321
+
322
+ /** The box being decoded is now complete. This is only emitted if a buffer
323
+ * was set for the box.
324
+ */
325
+ JXL_DEC_BOX_COMPLETE = 0x10000,
326
+ } JxlDecoderStatus;
327
+
328
+ /** Types of progressive detail.
329
+ * Setting a progressive detail with value N implies all progressive details
330
+ * with smaller or equal value. Currently only the following level of
331
+ * progressive detail is implemented:
332
+ * - @ref kDC (which implies kFrames)
333
+ * - @ref kLastPasses (which implies @ref kDC and @ref kFrames)
334
+ * - @ref kPasses (which implies @ref kLastPasses, kDC and @ref kFrames)
335
+ */
336
+ typedef enum {
337
+ /**
338
+ * after completed kRegularFrames
339
+ */
340
+ kFrames = 0,
341
+ /**
342
+ * after completed DC (1:8)
343
+ */
344
+ kDC = 1,
345
+ /**
346
+ * after completed AC passes that are the last pass for their resolution
347
+ * target.
348
+ */
349
+ kLastPasses = 2,
350
+ /**
351
+ * after completed AC passes that are not the last pass for their resolution
352
+ * target.
353
+ */
354
+ kPasses = 3,
355
+ /**
356
+ * during DC frame when lower resolution are completed (1:32, 1:16)
357
+ */
358
+ kDCProgressive = 4,
359
+ /**
360
+ * after completed groups
361
+ */
362
+ kDCGroups = 5,
363
+ /**
364
+ * after completed groups
365
+ */
366
+ kGroups = 6,
367
+ } JxlProgressiveDetail;
368
+
369
+ /** Rewinds decoder to the beginning. The same input must be given again from
370
+ * the beginning of the file and the decoder will emit events from the beginning
371
+ * again. When rewinding (as opposed to @ref JxlDecoderReset), the decoder can
372
+ * keep state about the image, which it can use to skip to a requested frame
373
+ * more efficiently with @ref JxlDecoderSkipFrames. Settings such as parallel
374
+ * runner or subscribed events are kept. After rewind, @ref
375
+ * JxlDecoderSubscribeEvents can be used again, and it is feasible to leave out
376
+ * events that were already handled before, such as ::JXL_DEC_BASIC_INFO
377
+ * and ::JXL_DEC_COLOR_ENCODING, since they will provide the same information
378
+ * as before.
379
+ * The difference to @ref JxlDecoderReset is that some state is kept, namely
380
+ * settings set by a call to
381
+ * - @ref JxlDecoderSetCoalescing,
382
+ * - @ref JxlDecoderSetDesiredIntensityTarget,
383
+ * - @ref JxlDecoderSetDecompressBoxes,
384
+ * - @ref JxlDecoderSetKeepOrientation,
385
+ * - @ref JxlDecoderSetUnpremultiplyAlpha,
386
+ * - @ref JxlDecoderSetParallelRunner,
387
+ * - @ref JxlDecoderSetRenderSpotcolors, and
388
+ * - @ref JxlDecoderSubscribeEvents.
389
+ *
390
+ * @param dec decoder object
391
+ */
392
+ JXL_EXPORT void JxlDecoderRewind(JxlDecoder* dec);
393
+
394
+ /** Makes the decoder skip the next `amount` frames. It still needs to process
395
+ * the input, but will not output the frame events. It can be more efficient
396
+ * when skipping frames, and even more so when using this after @ref
397
+ * JxlDecoderRewind. If the decoder is already processing a frame (could
398
+ * have emitted ::JXL_DEC_FRAME but not yet ::JXL_DEC_FULL_IMAGE), it
399
+ * starts skipping from the next frame. If the amount is larger than the amount
400
+ * of frames remaining in the image, all remaining frames are skipped. Calling
401
+ * this function multiple times adds the amount to skip to the already existing
402
+ * amount.
403
+ *
404
+ * A frame here is defined as a frame that without skipping emits events such
405
+ * as ::JXL_DEC_FRAME and ::JXL_DEC_FULL_IMAGE, frames that are internal
406
+ * to the file format but are not rendered as part of an animation, or are not
407
+ * the final still frame of a still image, are not counted.
408
+ *
409
+ * @param dec decoder object
410
+ * @param amount the amount of frames to skip
411
+ */
412
+ JXL_EXPORT void JxlDecoderSkipFrames(JxlDecoder* dec, size_t amount);
413
+
414
+ /**
415
+ * Skips processing the current frame. Can be called after frame processing
416
+ * already started, signaled by a ::JXL_DEC_NEED_IMAGE_OUT_BUFFER event,
417
+ * but before the corresponding ::JXL_DEC_FULL_IMAGE event. The next signaled
418
+ * event will be another ::JXL_DEC_FRAME, or ::JXL_DEC_SUCCESS if there
419
+ * are no more frames. If pixel data is required from the already processed part
420
+ * of the frame, @ref JxlDecoderFlushImage must be called before this.
421
+ *
422
+ * @param dec decoder object
423
+ * @return ::JXL_DEC_SUCCESS if there is a frame to skip, and @ref
424
+ * JXL_DEC_ERROR if the function was not called during frame processing.
425
+ */
426
+ JXL_EXPORT JxlDecoderStatus JxlDecoderSkipCurrentFrame(JxlDecoder* dec);
427
+
428
+ /**
429
+ * Set the parallel runner for multithreading. May only be set before starting
430
+ * decoding.
431
+ *
432
+ * @param dec decoder object
433
+ * @param parallel_runner function pointer to runner for multithreading. It may
434
+ * be NULL to use the default, single-threaded, runner. A multithreaded
435
+ * runner should be set to reach fast performance.
436
+ * @param parallel_runner_opaque opaque pointer for parallel_runner.
437
+ * @return ::JXL_DEC_SUCCESS if the runner was set, ::JXL_DEC_ERROR
438
+ * otherwise (the previous runner remains set).
439
+ */
440
+ JXL_EXPORT JxlDecoderStatus
441
+ JxlDecoderSetParallelRunner(JxlDecoder* dec, JxlParallelRunner parallel_runner,
442
+ void* parallel_runner_opaque);
443
+
444
+ /**
445
+ * Returns a hint indicating how many more bytes the decoder is expected to
446
+ * need to make @ref JxlDecoderGetBasicInfo available after the next @ref
447
+ * JxlDecoderProcessInput call. This is a suggested large enough value for
448
+ * the amount of bytes to provide in the next @ref JxlDecoderSetInput call, but
449
+ * it is not guaranteed to be an upper bound nor a lower bound. This number does
450
+ * not include bytes that have already been released from the input. Can be used
451
+ * before the first @ref JxlDecoderProcessInput call, and is correct the first
452
+ * time in most cases. If not, @ref JxlDecoderSizeHintBasicInfo can be called
453
+ * again to get an updated hint.
454
+ *
455
+ * @param dec decoder object
456
+ * @return the size hint in bytes if the basic info is not yet fully decoded.
457
+ * @return 0 when the basic info is already available.
458
+ */
459
+ JXL_EXPORT size_t JxlDecoderSizeHintBasicInfo(const JxlDecoder* dec);
460
+
461
+ /** Select for which informative events, i.e. ::JXL_DEC_BASIC_INFO, etc., the
462
+ * decoder should return with a status. It is not required to subscribe to any
463
+ * events, data can still be requested from the decoder as soon as it available.
464
+ * By default, the decoder is subscribed to no events (events_wanted == 0), and
465
+ * the decoder will then only return when it cannot continue because it needs
466
+ * more input data or more output buffer. This function may only be be called
467
+ * before using @ref JxlDecoderProcessInput.
468
+ *
469
+ * @param dec decoder object
470
+ * @param events_wanted bitfield of desired events.
471
+ * @return ::JXL_DEC_SUCCESS if no error, ::JXL_DEC_ERROR otherwise.
472
+ */
473
+ JXL_EXPORT JxlDecoderStatus JxlDecoderSubscribeEvents(JxlDecoder* dec,
474
+ int events_wanted);
475
+
476
+ /** Enables or disables preserving of as-in-bitstream pixeldata
477
+ * orientation. Some images are encoded with an Orientation tag
478
+ * indicating that the decoder must perform a rotation and/or
479
+ * mirroring to the encoded image data.
480
+ *
481
+ * - If skip_reorientation is ::JXL_FALSE (the default): the decoder
482
+ * will apply the transformation from the orientation setting, hence
483
+ * rendering the image according to its specified intent. When
484
+ * producing a @ref JxlBasicInfo, the decoder will always set the
485
+ * orientation field to JXL_ORIENT_IDENTITY (matching the returned
486
+ * pixel data) and also align xsize and ysize so that they correspond
487
+ * to the width and the height of the returned pixel data.
488
+ * - If skip_reorientation is ::JXL_TRUE "JXL_TRUE": the decoder will skip
489
+ * applying the transformation from the orientation setting, returning
490
+ * the image in the as-in-bitstream pixeldata orientation.
491
+ * This may be faster to decode since the decoder doesn't have to apply the
492
+ * transformation, but can cause wrong display of the image if the
493
+ * orientation tag is not correctly taken into account by the user.
494
+ *
495
+ * By default, this option is disabled, and the returned pixel data is
496
+ * re-oriented according to the image's Orientation setting.
497
+ *
498
+ * This function must be called at the beginning, before decoding is performed.
499
+ *
500
+ * @see JxlBasicInfo for the orientation field, and @ref JxlOrientation for the
501
+ * possible values.
502
+ *
503
+ * @param dec decoder object
504
+ * @param skip_reorientation JXL_TRUE to enable, JXL_FALSE to disable.
505
+ * @return ::JXL_DEC_SUCCESS if no error, ::JXL_DEC_ERROR otherwise.
506
+ */
507
+ JXL_EXPORT JxlDecoderStatus
508
+ JxlDecoderSetKeepOrientation(JxlDecoder* dec, JXL_BOOL skip_reorientation);
509
+
510
+ /**
511
+ * Enables or disables preserving of associated alpha channels. If
512
+ * unpremul_alpha is set to ::JXL_FALSE then for associated alpha channel,
513
+ * the pixel data is returned with premultiplied colors. If it is set to @ref
514
+ * JXL_TRUE, The colors will be unpremultiplied based on the alpha channel. This
515
+ * function has no effect if the image does not have an associated alpha
516
+ * channel.
517
+ *
518
+ * By default, this option is disabled, and the returned pixel data "as is".
519
+ *
520
+ * This function must be called at the beginning, before decoding is performed.
521
+ *
522
+ * @param dec decoder object
523
+ * @param unpremul_alpha JXL_TRUE to enable, JXL_FALSE to disable.
524
+ * @return ::JXL_DEC_SUCCESS if no error, ::JXL_DEC_ERROR otherwise.
525
+ */
526
+ JXL_EXPORT JxlDecoderStatus
527
+ JxlDecoderSetUnpremultiplyAlpha(JxlDecoder* dec, JXL_BOOL unpremul_alpha);
528
+
529
+ /** Enables or disables rendering spot colors. By default, spot colors
530
+ * are rendered, which is OK for viewing the decoded image. If render_spotcolors
531
+ * is ::JXL_FALSE, then spot colors are not rendered, and have to be
532
+ * retrieved separately using @ref JxlDecoderSetExtraChannelBuffer. This is
533
+ * useful for e.g. printing applications.
534
+ *
535
+ * @param dec decoder object
536
+ * @param render_spotcolors JXL_TRUE to enable (default), JXL_FALSE to disable.
537
+ * @return ::JXL_DEC_SUCCESS if no error, ::JXL_DEC_ERROR otherwise.
538
+ */
539
+ JXL_EXPORT JxlDecoderStatus
540
+ JxlDecoderSetRenderSpotcolors(JxlDecoder* dec, JXL_BOOL render_spotcolors);
541
+
542
+ /** Enables or disables coalescing of zero-duration frames. By default, frames
543
+ * are returned with coalescing enabled, i.e. all frames have the image
544
+ * dimensions, and are blended if needed. When coalescing is disabled, frames
545
+ * can have arbitrary dimensions, a non-zero crop offset, and blending is not
546
+ * performed. For display, coalescing is recommended. For loading a multi-layer
547
+ * still image as separate layers (as opposed to the merged image), coalescing
548
+ * has to be disabled.
549
+ *
550
+ * @param dec decoder object
551
+ * @param coalescing JXL_TRUE to enable coalescing (default), JXL_FALSE to
552
+ * disable it.
553
+ * @return ::JXL_DEC_SUCCESS if no error, ::JXL_DEC_ERROR otherwise.
554
+ */
555
+ JXL_EXPORT JxlDecoderStatus JxlDecoderSetCoalescing(JxlDecoder* dec,
556
+ JXL_BOOL coalescing);
557
+
558
+ /**
559
+ * Decodes JPEG XL file using the available bytes. Requires input has been
560
+ * set with @ref JxlDecoderSetInput. After @ref JxlDecoderProcessInput, input
561
+ * can optionally be released with @ref JxlDecoderReleaseInput and then set
562
+ * again to next bytes in the stream. @ref JxlDecoderReleaseInput returns how
563
+ * many bytes are not yet processed, before a next call to @ref
564
+ * JxlDecoderProcessInput all unprocessed bytes must be provided again (the
565
+ * address need not match, but the contents must), and more bytes may be
566
+ * concatenated after the unprocessed bytes.
567
+ *
568
+ * The returned status indicates whether the decoder needs more input bytes, or
569
+ * more output buffer for a certain type of output data. No matter what the
570
+ * returned status is (other than ::JXL_DEC_ERROR), new information, such
571
+ * as @ref JxlDecoderGetBasicInfo, may have become available after this call.
572
+ * When the return value is not ::JXL_DEC_ERROR or ::JXL_DEC_SUCCESS, the
573
+ * decoding requires more @ref JxlDecoderProcessInput calls to continue.
574
+ *
575
+ * @param dec decoder object
576
+ * @return ::JXL_DEC_SUCCESS when decoding finished and all events handled.
577
+ * If you still have more unprocessed input data anyway, then you can still
578
+ * continue by using @ref JxlDecoderSetInput and calling @ref
579
+ * JxlDecoderProcessInput again, similar to handling @ref
580
+ * JXL_DEC_NEED_MORE_INPUT. ::JXL_DEC_SUCCESS can occur instead of @ref
581
+ * JXL_DEC_NEED_MORE_INPUT when, for example, the input data ended right at
582
+ * the boundary of a box of the container format, all essential codestream
583
+ * boxes were already decoded, but extra metadata boxes are still present in
584
+ * the next data. @ref JxlDecoderProcessInput cannot return success if all
585
+ * codestream boxes have not been seen yet.
586
+ * @return ::JXL_DEC_ERROR when decoding failed, e.g. invalid codestream.
587
+ * TODO(lode): document the input data mechanism
588
+ * @return ::JXL_DEC_NEED_MORE_INPUT when more input data is necessary.
589
+ * @return ::JXL_DEC_BASIC_INFO when basic info such as image dimensions is
590
+ * available and this informative event is subscribed to.
591
+ * @return ::JXL_DEC_COLOR_ENCODING when color profile information is
592
+ * available and this informative event is subscribed to.
593
+ * @return ::JXL_DEC_PREVIEW_IMAGE when preview pixel information is
594
+ * available and output in the preview buffer.
595
+ * @return ::JXL_DEC_FULL_IMAGE when all pixel information at highest detail
596
+ * is available and has been output in the pixel buffer.
597
+ */
598
+ JXL_EXPORT JxlDecoderStatus JxlDecoderProcessInput(JxlDecoder* dec);
599
+
600
+ /**
601
+ * Sets input data for @ref JxlDecoderProcessInput. The data is owned by the
602
+ * caller and may be used by the decoder until @ref JxlDecoderReleaseInput is
603
+ * called or the decoder is destroyed or reset so must be kept alive until then.
604
+ * Cannot be called if @ref JxlDecoderSetInput was already called and @ref
605
+ * JxlDecoderReleaseInput was not yet called, and cannot be called after @ref
606
+ * JxlDecoderCloseInput indicating the end of input was called.
607
+ *
608
+ * @param dec decoder object
609
+ * @param data pointer to next bytes to read from
610
+ * @param size amount of bytes available starting from data
611
+ * @return ::JXL_DEC_ERROR if input was already set without releasing or @ref
612
+ * JxlDecoderCloseInput was already called, ::JXL_DEC_SUCCESS otherwise.
613
+ */
614
+ JXL_EXPORT JxlDecoderStatus JxlDecoderSetInput(JxlDecoder* dec,
615
+ const uint8_t* data,
616
+ size_t size);
617
+
618
+ /**
619
+ * Releases input which was provided with @ref JxlDecoderSetInput. Between @ref
620
+ * JxlDecoderProcessInput and @ref JxlDecoderReleaseInput, the user may not
621
+ * alter the data in the buffer. Calling @ref JxlDecoderReleaseInput is required
622
+ * whenever any input is already set and new input needs to be added with @ref
623
+ * JxlDecoderSetInput, but is not required before @ref JxlDecoderDestroy or @ref
624
+ * JxlDecoderReset. Calling @ref JxlDecoderReleaseInput when no input is set is
625
+ * not an error and returns `0`.
626
+ *
627
+ * @param dec decoder object
628
+ * @return The amount of bytes the decoder has not yet processed that are still
629
+ * remaining in the data set by @ref JxlDecoderSetInput, or `0` if no input
630
+ * is set or @ref JxlDecoderReleaseInput was already called. For a next call to
631
+ * @ref JxlDecoderProcessInput, the buffer must start with these unprocessed
632
+ * bytes. From this value it is possible to infer the position of certain JPEG
633
+ * XL codestream elements (e.g. end of headers, frame start/end). See the
634
+ * documentation of individual values of @ref JxlDecoderStatus for more
635
+ * information.
636
+ */
637
+ JXL_EXPORT size_t JxlDecoderReleaseInput(JxlDecoder* dec);
638
+
639
+ /**
640
+ * Marks the input as finished, indicates that no more @ref JxlDecoderSetInput
641
+ * will be called. This function allows the decoder to determine correctly if it
642
+ * should return success, need more input or error in certain cases. For
643
+ * backwards compatibility with a previous version of the API, using this
644
+ * function is optional when not using the ::JXL_DEC_BOX event (the decoder
645
+ * is able to determine the end of the image frames without marking the end),
646
+ * but using this function is required when using ::JXL_DEC_BOX for getting
647
+ * metadata box contents. This function does not replace @ref
648
+ * JxlDecoderReleaseInput, that function should still be called if its return
649
+ * value is needed.
650
+ *
651
+ * @ref JxlDecoderCloseInput should be called as soon as all known input bytes
652
+ * are set (e.g. at the beginning when not streaming but setting all input
653
+ * at once), before the final @ref JxlDecoderProcessInput calls.
654
+ *
655
+ * @param dec decoder object
656
+ */
657
+ JXL_EXPORT void JxlDecoderCloseInput(JxlDecoder* dec);
658
+
659
+ /**
660
+ * Outputs the basic image information, such as image dimensions, bit depth and
661
+ * all other JxlBasicInfo fields, if available.
662
+ *
663
+ * @param dec decoder object
664
+ * @param info struct to copy the information into, or NULL to only check
665
+ * whether the information is available through the return value.
666
+ * @return ::JXL_DEC_SUCCESS if the value is available, @ref
667
+ * JXL_DEC_NEED_MORE_INPUT if not yet available, ::JXL_DEC_ERROR
668
+ * in case of other error conditions.
669
+ */
670
+ JXL_EXPORT JxlDecoderStatus JxlDecoderGetBasicInfo(const JxlDecoder* dec,
671
+ JxlBasicInfo* info);
672
+
673
+ /**
674
+ * Outputs information for extra channel at the given index. The index must be
675
+ * smaller than num_extra_channels in the associated @ref JxlBasicInfo.
676
+ *
677
+ * @param dec decoder object
678
+ * @param index index of the extra channel to query.
679
+ * @param info struct to copy the information into, or NULL to only check
680
+ * whether the information is available through the return value.
681
+ * @return ::JXL_DEC_SUCCESS if the value is available, @ref
682
+ * JXL_DEC_NEED_MORE_INPUT if not yet available, ::JXL_DEC_ERROR
683
+ * in case of other error conditions.
684
+ */
685
+ JXL_EXPORT JxlDecoderStatus JxlDecoderGetExtraChannelInfo(
686
+ const JxlDecoder* dec, size_t index, JxlExtraChannelInfo* info);
687
+
688
+ /**
689
+ * Outputs name for extra channel at the given index in UTF-8. The index must be
690
+ * smaller than `num_extra_channels` in the associated @ref JxlBasicInfo. The
691
+ * buffer for name must have at least `name_length + 1` bytes allocated, gotten
692
+ * from the associated @ref JxlExtraChannelInfo.
693
+ *
694
+ * @param dec decoder object
695
+ * @param index index of the extra channel to query.
696
+ * @param name buffer to copy the name into
697
+ * @param size size of the name buffer in bytes
698
+ * @return ::JXL_DEC_SUCCESS if the value is available, @ref
699
+ * JXL_DEC_NEED_MORE_INPUT if not yet available, ::JXL_DEC_ERROR
700
+ * in case of other error conditions.
701
+ */
702
+ JXL_EXPORT JxlDecoderStatus JxlDecoderGetExtraChannelName(const JxlDecoder* dec,
703
+ size_t index,
704
+ char* name,
705
+ size_t size);
706
+
707
+ /** Defines which color profile to get: the profile from the codestream
708
+ * metadata header, which represents the color profile of the original image,
709
+ * or the color profile from the pixel data produced by the decoder. Both are
710
+ * the same if the JxlBasicInfo has uses_original_profile set.
711
+ */
712
+ typedef enum {
713
+ /** Get the color profile of the original image from the metadata.
714
+ */
715
+ JXL_COLOR_PROFILE_TARGET_ORIGINAL = 0,
716
+
717
+ /** Get the color profile of the pixel data the decoder outputs. */
718
+ JXL_COLOR_PROFILE_TARGET_DATA = 1,
719
+ } JxlColorProfileTarget;
720
+
721
+ /**
722
+ * Outputs the color profile as JPEG XL encoded structured data, if available.
723
+ * This is an alternative to an ICC Profile, which can represent a more limited
724
+ * amount of color spaces, but represents them exactly through enum values.
725
+ *
726
+ * It is often possible to use @ref JxlDecoderGetColorAsICCProfile as an
727
+ * alternative anyway. The following scenarios are possible:
728
+ * - The JPEG XL image has an attached ICC Profile, in that case, the encoded
729
+ * structured data is not available and this function will return an error
730
+ * status. @ref JxlDecoderGetColorAsICCProfile should be called instead.
731
+ * - The JPEG XL image has an encoded structured color profile, and it
732
+ * represents an RGB or grayscale color space. This function will return it.
733
+ * You can still use @ref JxlDecoderGetColorAsICCProfile as well as an
734
+ * alternative if desired, though depending on which RGB color space is
735
+ * represented, the ICC profile may be a close approximation. It is also not
736
+ * always feasible to deduce from an ICC profile which named color space it
737
+ * exactly represents, if any, as it can represent any arbitrary space.
738
+ * HDR color spaces such as those using PQ and HLG are also potentially
739
+ * problematic, in that: while ICC profiles can encode a transfer function
740
+ * that happens to approximate those of PQ and HLG (HLG for only one given
741
+ * system gamma at a time, and necessitating a 3D LUT if gamma is to be
742
+ * different from `1`), they cannot (before ICCv4.4) semantically signal that
743
+ * this is the color space that they represent. Therefore, they will
744
+ * typically not actually be interpreted as representing an HDR color space.
745
+ * This is especially detrimental to PQ which will then be interpreted as if
746
+ * the maximum signal value represented SDR white instead of 10000 cd/m^2,
747
+ * meaning that the image will be displayed two orders of magnitude (5-7 EV)
748
+ * too dim.
749
+ * - The JPEG XL image has an encoded structured color profile, and it
750
+ * indicates an unknown or xyb color space. In that case, @ref
751
+ * JxlDecoderGetColorAsICCProfile is not available.
752
+ *
753
+ * When rendering an image on a system where ICC-based color management is used,
754
+ * @ref JxlDecoderGetColorAsICCProfile should generally be used first as it will
755
+ * return a ready-to-use profile (with the aforementioned caveat about HDR).
756
+ * When knowledge about the nominal color space is desired if available, @ref
757
+ * JxlDecoderGetColorAsEncodedProfile should be used first.
758
+ *
759
+ * @param dec decoder object
760
+ * @param target whether to get the original color profile from the metadata
761
+ * or the color profile of the decoded pixels.
762
+ * @param color_encoding struct to copy the information into, or NULL to only
763
+ * check whether the information is available through the return value.
764
+ * @return ::JXL_DEC_SUCCESS if the data is available and returned, @ref
765
+ * JXL_DEC_NEED_MORE_INPUT if not yet available, ::JXL_DEC_ERROR in
766
+ * case the encoded structured color profile does not exist in the
767
+ * codestream.
768
+ */
769
+ JXL_EXPORT JxlDecoderStatus JxlDecoderGetColorAsEncodedProfile(
770
+ const JxlDecoder* dec, JxlColorProfileTarget target,
771
+ JxlColorEncoding* color_encoding);
772
+
773
+ /**
774
+ * Outputs the size in bytes of the ICC profile returned by @ref
775
+ * JxlDecoderGetColorAsICCProfile, if available, or indicates there is none
776
+ * available. In most cases, the image will have an ICC profile available, but
777
+ * if it does not, @ref JxlDecoderGetColorAsEncodedProfile must be used instead.
778
+ *
779
+ * @see JxlDecoderGetColorAsEncodedProfile for more information. The ICC
780
+ * profile is either the exact ICC profile attached to the codestream metadata,
781
+ * or a close approximation generated from JPEG XL encoded structured data,
782
+ * depending of what is encoded in the codestream.
783
+ *
784
+ * @param dec decoder object
785
+ * @param target whether to get the original color profile from the metadata
786
+ * or the color profile of the decoded pixels.
787
+ * @param size variable to output the size into, or NULL to only check the
788
+ * return status.
789
+ * @return ::JXL_DEC_SUCCESS if the ICC profile is available, @ref
790
+ * JXL_DEC_NEED_MORE_INPUT if the decoder has not yet received enough
791
+ * input data to determine whether an ICC profile is available or what its
792
+ * size is, ::JXL_DEC_ERROR in case the ICC profile is not available and
793
+ * cannot be generated.
794
+ */
795
+ JXL_EXPORT JxlDecoderStatus JxlDecoderGetICCProfileSize(
796
+ const JxlDecoder* dec, JxlColorProfileTarget target, size_t* size);
797
+
798
+ /**
799
+ * Outputs ICC profile if available. The profile is only available if @ref
800
+ * JxlDecoderGetICCProfileSize returns success. The output buffer must have
801
+ * at least as many bytes as given by @ref JxlDecoderGetICCProfileSize.
802
+ *
803
+ * @param dec decoder object
804
+ * @param target whether to get the original color profile from the metadata
805
+ * or the color profile of the decoded pixels.
806
+ * @param icc_profile buffer to copy the ICC profile into
807
+ * @param size size of the icc_profile buffer in bytes
808
+ * @return ::JXL_DEC_SUCCESS if the profile was successfully returned,
809
+ * ::JXL_DEC_NEED_MORE_INPUT if not yet available, @ref
810
+ * JXL_DEC_ERROR if the profile doesn't exist or the output size is not
811
+ * large enough.
812
+ */
813
+ JXL_EXPORT JxlDecoderStatus JxlDecoderGetColorAsICCProfile(
814
+ const JxlDecoder* dec, JxlColorProfileTarget target, uint8_t* icc_profile,
815
+ size_t size);
816
+
817
+ /** Sets the desired output color profile of the decoded image by calling
818
+ * @ref JxlDecoderSetOutputColorProfile, passing on @c color_encoding and
819
+ * setting @c icc_data to NULL. See @ref JxlDecoderSetOutputColorProfile for
820
+ * details.
821
+ *
822
+ * @param dec decoder object
823
+ * @param color_encoding the default color encoding to set
824
+ * @return ::JXL_DEC_SUCCESS if the preference was set successfully, @ref
825
+ * JXL_DEC_ERROR otherwise.
826
+ */
827
+ JXL_EXPORT JxlDecoderStatus JxlDecoderSetPreferredColorProfile(
828
+ JxlDecoder* dec, const JxlColorEncoding* color_encoding);
829
+
830
+ /** Requests that the decoder perform tone mapping to the peak display luminance
831
+ * passed as @c desired_intensity_target, if appropriate.
832
+ * @note This is provided for convenience and the exact tone mapping that is
833
+ * performed is not meant to be considered authoritative in any way. It may
834
+ * change from version to version.
835
+ * @param dec decoder object
836
+ * @param desired_intensity_target the intended target peak luminance
837
+ * @return ::JXL_DEC_SUCCESS if the preference was set successfully, @ref
838
+ * JXL_DEC_ERROR otherwise.
839
+ */
840
+ JXL_EXPORT JxlDecoderStatus JxlDecoderSetDesiredIntensityTarget(
841
+ JxlDecoder* dec, float desired_intensity_target);
842
+
843
+ /**
844
+ * Sets the desired output color profile of the decoded image either from a
845
+ * color encoding or an ICC profile. Valid calls of this function have either @c
846
+ * color_encoding or @c icc_data set to NULL and @c icc_size must be `0` if and
847
+ * only if @c icc_data is NULL.
848
+ *
849
+ * Depending on whether a color management system (CMS) has been set the
850
+ * behavior is as follows:
851
+ *
852
+ * If a color management system (CMS) has been set with @ref JxlDecoderSetCms,
853
+ * and the CMS supports output to the desired color encoding or ICC profile,
854
+ * then it will provide the output in that color encoding or ICC profile. If the
855
+ * desired color encoding or the ICC is not supported, then an error will be
856
+ * returned.
857
+ *
858
+ * If no CMS has been set with @ref JxlDecoderSetCms, there are two cases:
859
+ *
860
+ * (1) Calling this function with a color encoding will convert XYB images to
861
+ * the desired color encoding. In this case, if the requested color encoding has
862
+ * a narrower gamut, or the white points differ, then the resulting image can
863
+ * have significant color distortion. Non-XYB images will not be converted to
864
+ * the desired color space.
865
+ *
866
+ * (2) Calling this function with an ICC profile will result in an error.
867
+ *
868
+ * If called with an ICC profile (after a call to @ref JxlDecoderSetCms), the
869
+ * ICC profile has to be a valid RGB or grayscale color profile.
870
+ *
871
+ * Can only be set after the ::JXL_DEC_COLOR_ENCODING event occurred and
872
+ * before any other event occurred, and should be used before getting
873
+ * ::JXL_COLOR_PROFILE_TARGET_DATA.
874
+ *
875
+ * This function must not be called before @ref JxlDecoderSetCms.
876
+ *
877
+ * @param dec decoder object
878
+ * @param color_encoding the output color encoding
879
+ * @param icc_data bytes of the icc profile
880
+ * @param icc_size size of the icc profile in bytes
881
+ * @return ::JXL_DEC_SUCCESS if the color profile was set successfully, @ref
882
+ * JXL_DEC_ERROR otherwise.
883
+ */
884
+ JXL_EXPORT JxlDecoderStatus JxlDecoderSetOutputColorProfile(
885
+ JxlDecoder* dec, const JxlColorEncoding* color_encoding,
886
+ const uint8_t* icc_data, size_t icc_size);
887
+
888
+ /**
889
+ * Sets the color management system (CMS) that will be used for color
890
+ * conversion (if applicable) during decoding. May only be set before starting
891
+ * decoding and must not be called after @ref JxlDecoderSetOutputColorProfile.
892
+ *
893
+ * See @ref JxlDecoderSetOutputColorProfile for how color conversions are done
894
+ * depending on whether or not a CMS has been set with @ref JxlDecoderSetCms.
895
+ *
896
+ * @param dec decoder object.
897
+ * @param cms structure representing a CMS implementation. See @ref
898
+ * JxlCmsInterface for more details.
899
+ */
900
+ JXL_EXPORT JxlDecoderStatus JxlDecoderSetCms(JxlDecoder* dec,
901
+ JxlCmsInterface cms);
902
+ // TODO(firsching): add a function JxlDecoderSetDefaultCms() for setting a
903
+ // default in case libjxl is build with a CMS.
904
+
905
+ /**
906
+ * Returns the minimum size in bytes of the preview image output pixel buffer
907
+ * for the given format. This is the buffer for @ref
908
+ * JxlDecoderSetPreviewOutBuffer. Requires the preview header information is
909
+ * available in the decoder.
910
+ *
911
+ * @param dec decoder object
912
+ * @param format format of pixels
913
+ * @param size output value, buffer size in bytes
914
+ * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such as
915
+ * information not available yet.
916
+ */
917
+ JXL_EXPORT JxlDecoderStatus JxlDecoderPreviewOutBufferSize(
918
+ const JxlDecoder* dec, const JxlPixelFormat* format, size_t* size);
919
+
920
+ /**
921
+ * Sets the buffer to write the low-resolution preview image to. This must be
922
+ * set when the ::JXL_DEC_NEED_PREVIEW_OUT_BUFFER event occurs. The size of
923
+ * the buffer must be at least as large as given by @ref
924
+ * JxlDecoderPreviewOutBufferSize. The buffer follows the format described
925
+ * by @ref JxlPixelFormat. The preview image dimensions are given by the
926
+ * @ref JxlPreviewHeader. The buffer is owned by the caller. Attempt to set
927
+ * preview buffer before ::JXL_DEC_NEED_PREVIEW_OUT_BUFFER or after
928
+ * ::JXL_DEC_PREVIEW_IMAGE will fail.
929
+ *
930
+ * @param dec decoder object
931
+ * @param format format of pixels. Object owned by user and its contents are
932
+ * copied internally.
933
+ * @param buffer buffer type to output the pixel data to
934
+ * @param size size of buffer in bytes
935
+ * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such as
936
+ * size too small.
937
+ */
938
+ JXL_EXPORT JxlDecoderStatus JxlDecoderSetPreviewOutBuffer(
939
+ JxlDecoder* dec, const JxlPixelFormat* format, void* buffer, size_t size);
940
+
941
+ /**
942
+ * Outputs the information from the frame, such as duration when have_animation.
943
+ * This function can be called when ::JXL_DEC_FRAME occurred for the current
944
+ * frame, even when have_animation in the JxlBasicInfo is JXL_FALSE.
945
+ *
946
+ * @param dec decoder object
947
+ * @param header struct to copy the information into, or NULL to only check
948
+ * whether the information is available through the return value.
949
+ * @return ::JXL_DEC_SUCCESS if the value is available, @ref
950
+ * JXL_DEC_NEED_MORE_INPUT if not yet available, ::JXL_DEC_ERROR in
951
+ * case of other error conditions.
952
+ */
953
+ JXL_EXPORT JxlDecoderStatus JxlDecoderGetFrameHeader(const JxlDecoder* dec,
954
+ JxlFrameHeader* header);
955
+
956
+ /**
957
+ * Outputs name for the current frame. The buffer for name must have at least
958
+ * `name_length + 1` bytes allocated, gotten from the associated JxlFrameHeader.
959
+ *
960
+ * @param dec decoder object
961
+ * @param name buffer to copy the name into
962
+ * @param size size of the name buffer in bytes, including zero termination
963
+ * character, so this must be at least @ref JxlFrameHeader.name_length + 1.
964
+ * @return ::JXL_DEC_SUCCESS if the value is available, @ref
965
+ * JXL_DEC_NEED_MORE_INPUT if not yet available, ::JXL_DEC_ERROR in
966
+ * case of other error conditions.
967
+ */
968
+ JXL_EXPORT JxlDecoderStatus JxlDecoderGetFrameName(const JxlDecoder* dec,
969
+ char* name, size_t size);
970
+
971
+ /**
972
+ * Outputs the blend information for the current frame for a specific extra
973
+ * channel. This function can be called once the ::JXL_DEC_FRAME event occurred
974
+ * for the current frame, even if the `have_animation` field in the @ref
975
+ * JxlBasicInfo is @ref JXL_FALSE. This information is only useful if coalescing
976
+ * is disabled; otherwise the decoder will have performed blending already.
977
+ *
978
+ * @param dec decoder object
979
+ * @param index the index of the extra channel
980
+ * @param blend_info struct to copy the information into
981
+ * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error
982
+ */
983
+ JXL_EXPORT JxlDecoderStatus JxlDecoderGetExtraChannelBlendInfo(
984
+ const JxlDecoder* dec, size_t index, JxlBlendInfo* blend_info);
985
+
986
+ /**
987
+ * Returns the minimum size in bytes of the image output pixel buffer for the
988
+ * given format. This is the buffer for @ref JxlDecoderSetImageOutBuffer.
989
+ * Requires that the basic image information is available in the decoder in the
990
+ * case of coalescing enabled (default). In case coalescing is disabled, this
991
+ * can only be called after the ::JXL_DEC_FRAME event occurs. In that case,
992
+ * it will return the size required to store the possibly cropped frame (which
993
+ * can be larger or smaller than the image dimensions).
994
+ *
995
+ * @param dec decoder object
996
+ * @param format format of the pixels.
997
+ * @param size output value, buffer size in bytes
998
+ * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such as
999
+ * information not available yet.
1000
+ */
1001
+ JXL_EXPORT JxlDecoderStatus JxlDecoderImageOutBufferSize(
1002
+ const JxlDecoder* dec, const JxlPixelFormat* format, size_t* size);
1003
+
1004
+ /**
1005
+ * Sets the buffer to write the full resolution image to. This can be set when
1006
+ * the ::JXL_DEC_FRAME event occurs, must be set when the
1007
+ * ::JXL_DEC_NEED_IMAGE_OUT_BUFFER event occurs, and applies only for the
1008
+ * current frame. The size of the buffer must be at least as large as given
1009
+ * by @ref JxlDecoderImageOutBufferSize. The buffer follows the format described
1010
+ * by @ref JxlPixelFormat. The buffer is owned by the caller. Attempt to set
1011
+ * image buffer while preview buffer is expected will fail.
1012
+ *
1013
+ * @param dec decoder object
1014
+ * @param format format of the pixels. Object owned by user and its contents
1015
+ * are copied internally.
1016
+ * @param buffer buffer type to output the pixel data to
1017
+ * @param size size of buffer in bytes
1018
+ * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such as
1019
+ * size too small.
1020
+ */
1021
+ JXL_EXPORT JxlDecoderStatus JxlDecoderSetImageOutBuffer(
1022
+ JxlDecoder* dec, const JxlPixelFormat* format, void* buffer, size_t size);
1023
+
1024
+ /**
1025
+ * Function type for @ref JxlDecoderSetImageOutCallback.
1026
+ *
1027
+ * The callback may be called simultaneously by different threads when using a
1028
+ * threaded parallel runner, on different pixels.
1029
+ *
1030
+ * @param opaque optional user data, as given to @ref
1031
+ * JxlDecoderSetImageOutCallback.
1032
+ * @param x horizontal position of leftmost pixel of the pixel data.
1033
+ * @param y vertical position of the pixel data.
1034
+ * @param num_pixels amount of pixels included in the pixel data, horizontally.
1035
+ * This is not the same as xsize of the full image, it may be smaller.
1036
+ * @param pixels pixel data as a horizontal stripe, in the format passed to @ref
1037
+ * JxlDecoderSetImageOutCallback. The memory is not owned by the user, and
1038
+ * is only valid during the time the callback is running.
1039
+ */
1040
+ typedef void (*JxlImageOutCallback)(void* opaque, size_t x, size_t y,
1041
+ size_t num_pixels, const void* pixels);
1042
+
1043
+ /**
1044
+ * Initialization callback for @ref JxlDecoderSetMultithreadedImageOutCallback.
1045
+ *
1046
+ * @param init_opaque optional user data, as given to @ref
1047
+ * JxlDecoderSetMultithreadedImageOutCallback.
1048
+ * @param num_threads maximum number of threads that will call the @c run
1049
+ * callback concurrently.
1050
+ * @param num_pixels_per_thread maximum number of pixels that will be passed in
1051
+ * one call to @c run.
1052
+ * @return a pointer to data that will be passed to the @c run callback, or
1053
+ * @c NULL if initialization failed.
1054
+ */
1055
+ typedef void* (*JxlImageOutInitCallback)(void* init_opaque, size_t num_threads,
1056
+ size_t num_pixels_per_thread);
1057
+
1058
+ /**
1059
+ * Worker callback for @ref JxlDecoderSetMultithreadedImageOutCallback.
1060
+ *
1061
+ * @param run_opaque user data returned by the @c init callback.
1062
+ * @param thread_id number in `[0, num_threads)` identifying the thread of the
1063
+ * current invocation of the callback.
1064
+ * @param x horizontal position of the first (leftmost) pixel of the pixel data.
1065
+ * @param y vertical position of the pixel data.
1066
+ * @param num_pixels number of pixels in the pixel data. May be less than the
1067
+ * full @c xsize of the image, and will be at most equal to the @c
1068
+ * num_pixels_per_thread that was passed to @c init.
1069
+ * @param pixels pixel data as a horizontal stripe, in the format passed to @ref
1070
+ * JxlDecoderSetMultithreadedImageOutCallback. The data pointed to
1071
+ * remains owned by the caller and is only guaranteed to outlive the current
1072
+ * callback invocation.
1073
+ */
1074
+ typedef void (*JxlImageOutRunCallback)(void* run_opaque, size_t thread_id,
1075
+ size_t x, size_t y, size_t num_pixels,
1076
+ const void* pixels);
1077
+
1078
+ /**
1079
+ * Destruction callback for @ref JxlDecoderSetMultithreadedImageOutCallback,
1080
+ * called after all invocations of the @c run callback to perform any
1081
+ * appropriate clean-up of the @c run_opaque data returned by @c init.
1082
+ *
1083
+ * @param run_opaque user data returned by the @c init callback.
1084
+ */
1085
+ typedef void (*JxlImageOutDestroyCallback)(void* run_opaque);
1086
+
1087
+ /**
1088
+ * Sets pixel output callback. This is an alternative to @ref
1089
+ * JxlDecoderSetImageOutBuffer. This can be set when the ::JXL_DEC_FRAME
1090
+ * event occurs, must be set when the ::JXL_DEC_NEED_IMAGE_OUT_BUFFER event
1091
+ * occurs, and applies only for the current frame. Only one of @ref
1092
+ * JxlDecoderSetImageOutBuffer or @ref JxlDecoderSetImageOutCallback may be used
1093
+ * for the same frame, not both at the same time.
1094
+ *
1095
+ * The callback will be called multiple times, to receive the image
1096
+ * data in small chunks. The callback receives a horizontal stripe of pixel
1097
+ * data, `1` pixel high, xsize pixels wide, called a scanline. The xsize here is
1098
+ * not the same as the full image width, the scanline may be a partial section,
1099
+ * and xsize may differ between calls. The user can then process and/or copy the
1100
+ * partial scanline to an image buffer. The callback may be called
1101
+ * simultaneously by different threads when using a threaded parallel runner, on
1102
+ * different pixels.
1103
+ *
1104
+ * If @ref JxlDecoderFlushImage is not used, then each pixel will be visited
1105
+ * exactly once by the different callback calls, during processing with one or
1106
+ * more @ref JxlDecoderProcessInput calls. These pixels are decoded to full
1107
+ * detail, they are not part of a lower resolution or lower quality progressive
1108
+ * pass, but the final pass.
1109
+ *
1110
+ * If @ref JxlDecoderFlushImage is used, then in addition each pixel will be
1111
+ * visited zero or one times during the blocking @ref JxlDecoderFlushImage call.
1112
+ * Pixels visited as a result of @ref JxlDecoderFlushImage may represent a lower
1113
+ * resolution or lower quality intermediate progressive pass of the image. Any
1114
+ * visited pixel will be of a quality at least as good or better than previous
1115
+ * visits of this pixel. A pixel may be visited zero times if it cannot be
1116
+ * decoded yet or if it was already decoded to full precision (this behavior is
1117
+ * not guaranteed).
1118
+ *
1119
+ * @param dec decoder object
1120
+ * @param format format of the pixels. Object owned by user; its contents are
1121
+ * copied internally.
1122
+ * @param callback the callback function receiving partial scanlines of pixel
1123
+ * data.
1124
+ * @param opaque optional user data, which will be passed on to the callback,
1125
+ * may be NULL.
1126
+ * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such
1127
+ * as @ref JxlDecoderSetImageOutBuffer already set.
1128
+ */
1129
+ JXL_EXPORT JxlDecoderStatus
1130
+ JxlDecoderSetImageOutCallback(JxlDecoder* dec, const JxlPixelFormat* format,
1131
+ JxlImageOutCallback callback, void* opaque);
1132
+
1133
+ /** Similar to @ref JxlDecoderSetImageOutCallback except that the callback is
1134
+ * allowed an initialization phase during which it is informed of how many
1135
+ * threads will call it concurrently, and those calls are further informed of
1136
+ * which thread they are occurring in.
1137
+ *
1138
+ * @param dec decoder object
1139
+ * @param format format of the pixels. Object owned by user; its contents are
1140
+ * copied internally.
1141
+ * @param init_callback initialization callback.
1142
+ * @param run_callback the callback function receiving partial scanlines of
1143
+ * pixel data.
1144
+ * @param destroy_callback clean-up callback invoked after all calls to @c
1145
+ * run_callback. May be NULL if no clean-up is necessary.
1146
+ * @param init_opaque optional user data passed to @c init_callback, may be NULL
1147
+ * (unlike the return value from @c init_callback which may only be NULL if
1148
+ * initialization failed).
1149
+ * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such
1150
+ * as @ref JxlDecoderSetImageOutBuffer having already been called.
1151
+ */
1152
+ JXL_EXPORT JxlDecoderStatus JxlDecoderSetMultithreadedImageOutCallback(
1153
+ JxlDecoder* dec, const JxlPixelFormat* format,
1154
+ JxlImageOutInitCallback init_callback, JxlImageOutRunCallback run_callback,
1155
+ JxlImageOutDestroyCallback destroy_callback, void* init_opaque);
1156
+
1157
+ /**
1158
+ * Returns the minimum size in bytes of an extra channel pixel buffer for the
1159
+ * given format. This is the buffer for @ref JxlDecoderSetExtraChannelBuffer.
1160
+ * Requires the basic image information is available in the decoder.
1161
+ *
1162
+ * @param dec decoder object
1163
+ * @param format format of the pixels. The num_channels value is ignored and is
1164
+ * always treated to be `1`.
1165
+ * @param size output value, buffer size in bytes
1166
+ * @param index which extra channel to get, matching the index used in @ref
1167
+ * JxlDecoderGetExtraChannelInfo. Must be smaller than num_extra_channels in
1168
+ * the associated @ref JxlBasicInfo.
1169
+ * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such as
1170
+ * information not available yet or invalid index.
1171
+ */
1172
+ JXL_EXPORT JxlDecoderStatus JxlDecoderExtraChannelBufferSize(
1173
+ const JxlDecoder* dec, const JxlPixelFormat* format, size_t* size,
1174
+ uint32_t index);
1175
+
1176
+ /**
1177
+ * Sets the buffer to write an extra channel to. This can be set when
1178
+ * the ::JXL_DEC_FRAME or ::JXL_DEC_NEED_IMAGE_OUT_BUFFER event occurs,
1179
+ * and applies only for the current frame. The size of the buffer must be at
1180
+ * least as large as given by @ref JxlDecoderExtraChannelBufferSize. The buffer
1181
+ * follows the format described by @ref JxlPixelFormat, but where num_channels
1182
+ * is `1`. The buffer is owned by the caller. The amount of extra channels is
1183
+ * given by the num_extra_channels field in the associated @ref JxlBasicInfo,
1184
+ * and the information of individual extra channels can be queried with @ref
1185
+ * JxlDecoderGetExtraChannelInfo. To get multiple extra channels, this function
1186
+ * must be called multiple times, once for each wanted index. Not all images
1187
+ * have extra channels. The alpha channel is an extra channel and can be gotten
1188
+ * as part of the color channels when using an RGBA pixel buffer with @ref
1189
+ * JxlDecoderSetImageOutBuffer, but additionally also can be gotten
1190
+ * separately as extra channel. The color channels themselves cannot be gotten
1191
+ * this way.
1192
+ *
1193
+ *
1194
+ * @param dec decoder object
1195
+ * @param format format of the pixels. Object owned by user and its contents
1196
+ * are copied internally. The num_channels value is ignored and is always
1197
+ * treated to be `1`.
1198
+ * @param buffer buffer type to output the pixel data to
1199
+ * @param size size of buffer in bytes
1200
+ * @param index which extra channel to get, matching the index used in @ref
1201
+ * JxlDecoderGetExtraChannelInfo. Must be smaller than num_extra_channels in
1202
+ * the associated @ref JxlBasicInfo.
1203
+ * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such as
1204
+ * size too small or invalid index.
1205
+ */
1206
+ JXL_EXPORT JxlDecoderStatus
1207
+ JxlDecoderSetExtraChannelBuffer(JxlDecoder* dec, const JxlPixelFormat* format,
1208
+ void* buffer, size_t size, uint32_t index);
1209
+
1210
+ /**
1211
+ * Sets output buffer for reconstructed JPEG codestream.
1212
+ *
1213
+ * The data is owned by the caller and may be used by the decoder until @ref
1214
+ * JxlDecoderReleaseJPEGBuffer is called or the decoder is destroyed or
1215
+ * reset so must be kept alive until then.
1216
+ *
1217
+ * If a JPEG buffer was set before and released with @ref
1218
+ * JxlDecoderReleaseJPEGBuffer, bytes that the decoder has already output
1219
+ * should not be included, only the remaining bytes output must be set.
1220
+ *
1221
+ * @param dec decoder object
1222
+ * @param data pointer to next bytes to write to
1223
+ * @param size amount of bytes available starting from data
1224
+ * @return ::JXL_DEC_ERROR if output buffer was already set and @ref
1225
+ * JxlDecoderReleaseJPEGBuffer was not called on it, ::JXL_DEC_SUCCESS
1226
+ * otherwise
1227
+ */
1228
+ JXL_EXPORT JxlDecoderStatus JxlDecoderSetJPEGBuffer(JxlDecoder* dec,
1229
+ uint8_t* data, size_t size);
1230
+
1231
+ /**
1232
+ * Releases buffer which was provided with @ref JxlDecoderSetJPEGBuffer.
1233
+ *
1234
+ * Calling @ref JxlDecoderReleaseJPEGBuffer is required whenever
1235
+ * a buffer is already set and a new buffer needs to be added with @ref
1236
+ * JxlDecoderSetJPEGBuffer, but is not required before @ref
1237
+ * JxlDecoderDestroy or @ref JxlDecoderReset.
1238
+ *
1239
+ * Calling @ref JxlDecoderReleaseJPEGBuffer when no buffer is set is
1240
+ * not an error and returns `0`.
1241
+ *
1242
+ * @param dec decoder object
1243
+ * @return the amount of bytes the decoder has not yet written to of the data
1244
+ * set by @ref JxlDecoderSetJPEGBuffer, or `0` if no buffer is set or @ref
1245
+ * JxlDecoderReleaseJPEGBuffer was already called.
1246
+ */
1247
+ JXL_EXPORT size_t JxlDecoderReleaseJPEGBuffer(JxlDecoder* dec);
1248
+
1249
+ /**
1250
+ * Sets output buffer for box output codestream.
1251
+ *
1252
+ * The data is owned by the caller and may be used by the decoder until @ref
1253
+ * JxlDecoderReleaseBoxBuffer is called or the decoder is destroyed or
1254
+ * reset so must be kept alive until then.
1255
+ *
1256
+ * If for the current box a box buffer was set before and released with @ref
1257
+ * JxlDecoderReleaseBoxBuffer, bytes that the decoder has already output
1258
+ * should not be included, only the remaining bytes output must be set.
1259
+ *
1260
+ * The @ref JxlDecoderReleaseBoxBuffer must be used at the next ::JXL_DEC_BOX
1261
+ * event or final ::JXL_DEC_SUCCESS event to compute the size of the output
1262
+ * box bytes.
1263
+ *
1264
+ * @param dec decoder object
1265
+ * @param data pointer to next bytes to write to
1266
+ * @param size amount of bytes available starting from data
1267
+ * @return ::JXL_DEC_ERROR if output buffer was already set and @ref
1268
+ * JxlDecoderReleaseBoxBuffer was not called on it, ::JXL_DEC_SUCCESS
1269
+ * otherwise
1270
+ */
1271
+ JXL_EXPORT JxlDecoderStatus JxlDecoderSetBoxBuffer(JxlDecoder* dec,
1272
+ uint8_t* data, size_t size);
1273
+
1274
+ /**
1275
+ * Releases buffer which was provided with @ref JxlDecoderSetBoxBuffer.
1276
+ *
1277
+ * Calling @ref JxlDecoderReleaseBoxBuffer is required whenever
1278
+ * a buffer is already set and a new buffer needs to be added with @ref
1279
+ * JxlDecoderSetBoxBuffer, but is not required before @ref
1280
+ * JxlDecoderDestroy or @ref JxlDecoderReset.
1281
+ *
1282
+ * Calling @ref JxlDecoderReleaseBoxBuffer when no buffer is set is
1283
+ * not an error and returns `0`.
1284
+ *
1285
+ * @param dec decoder object
1286
+ * @return the amount of bytes the decoder has not yet written to of the data
1287
+ * set by @ref JxlDecoderSetBoxBuffer, or `0` if no buffer is set or @ref
1288
+ * JxlDecoderReleaseBoxBuffer was already called.
1289
+ */
1290
+ JXL_EXPORT size_t JxlDecoderReleaseBoxBuffer(JxlDecoder* dec);
1291
+
1292
+ /**
1293
+ * Configures whether to get boxes in raw mode or in decompressed mode. In raw
1294
+ * mode, boxes are output as their bytes appear in the container file, which may
1295
+ * be decompressed, or compressed if their type is "brob". In decompressed mode,
1296
+ * "brob" boxes are decompressed with Brotli before outputting them. The size of
1297
+ * the decompressed stream is not known before the decompression has already
1298
+ * finished.
1299
+ *
1300
+ * The default mode is raw. This setting can only be changed before decoding, or
1301
+ * directly after a ::JXL_DEC_BOX event, and is remembered until the decoder
1302
+ * is reset or destroyed.
1303
+ *
1304
+ * Enabling decompressed mode requires Brotli support from the library.
1305
+ *
1306
+ * @param dec decoder object
1307
+ * @param decompress ::JXL_TRUE to transparently decompress, ::JXL_FALSE
1308
+ * to get boxes in raw mode.
1309
+ * @return ::JXL_DEC_ERROR if decompressed mode is set and Brotli is not
1310
+ * available, ::JXL_DEC_SUCCESS otherwise.
1311
+ */
1312
+ JXL_EXPORT JxlDecoderStatus JxlDecoderSetDecompressBoxes(JxlDecoder* dec,
1313
+ JXL_BOOL decompress);
1314
+
1315
+ /**
1316
+ * Outputs the type of the current box, after a ::JXL_DEC_BOX event occurred,
1317
+ * as `4` characters without null termination character. In case of a compressed
1318
+ * "brob" box, this will return "brob" if the decompressed argument is
1319
+ * JXL_FALSE, or the underlying box type if the decompressed argument is
1320
+ * JXL_TRUE.
1321
+ *
1322
+ * The following box types are currently described in ISO/IEC 18181-2:
1323
+ * - "Exif": a box with EXIF metadata. Starts with a 4-byte tiff header offset
1324
+ * (big-endian uint32) that indicates the start of the actual EXIF data
1325
+ * (which starts with a tiff header). Usually the offset will be zero and the
1326
+ * EXIF data starts immediately after the offset field. The Exif orientation
1327
+ * should be ignored by applications; the JPEG XL codestream orientation
1328
+ * takes precedence and libjxl will by default apply the correct orientation
1329
+ * automatically (see @ref JxlDecoderSetKeepOrientation).
1330
+ * - "xml ": a box with XML data, in particular XMP metadata.
1331
+ * - "jumb": a JUMBF superbox (JPEG Universal Metadata Box Format, ISO/IEC
1332
+ * 19566-5).
1333
+ * - "JXL ": mandatory signature box, must come first, `12` bytes long
1334
+ * including the box header
1335
+ * - "ftyp": a second mandatory signature box, must come second, `20` bytes
1336
+ * long including the box header
1337
+ * - "jxll": a JXL level box. This indicates if the codestream is level `5` or
1338
+ * level `10` compatible. If not present, it is level `5`. Level `10` allows
1339
+ * more features such as very high image resolution and bit-depths above `16`
1340
+ * bits per channel. Added automatically by the encoder when
1341
+ * @ref JxlEncoderSetCodestreamLevel is used
1342
+ * - "jxlc": a box with the image codestream, in case the codestream is not
1343
+ * split across multiple boxes. The codestream contains the JPEG XL image
1344
+ * itself, including the basic info such as image dimensions, ICC color
1345
+ * profile, and all the pixel data of all the image frames.
1346
+ * - "jxlp": a codestream box in case it is split across multiple boxes.
1347
+ * The contents are the same as in case of a jxlc box, when concatenated.
1348
+ * - "brob": a Brotli-compressed box, which otherwise represents an existing
1349
+ * type of box such as Exif or "xml ". When @ref JxlDecoderSetDecompressBoxes
1350
+ * is set to JXL_TRUE, these boxes will be transparently decompressed by the
1351
+ * decoder.
1352
+ * - "jxli": frame index box, can list the keyframes in case of a JPEG XL
1353
+ * animation allowing the decoder to jump to individual frames more
1354
+ * efficiently.
1355
+ * - "jbrd": JPEG reconstruction box, contains the information required to
1356
+ * byte-for-byte losslessly reconstruct a JPEG-1 image. The JPEG DCT
1357
+ * coefficients (pixel content) themselves as well as the ICC profile are
1358
+ * encoded in the JXL codestream (jxlc or jxlp) itself. EXIF, XMP and JUMBF
1359
+ * metadata is encoded in the corresponding boxes. The jbrd box itself
1360
+ * contains information such as the remaining app markers of the JPEG-1 file
1361
+ * and everything else required to fit the information together into the
1362
+ * exact original JPEG file.
1363
+ *
1364
+ * Other application-specific boxes can exist. Their typename should not begin
1365
+ * with "jxl" or "JXL" or conflict with other existing typenames.
1366
+ *
1367
+ * The signature, jxl* and jbrd boxes are processed by the decoder and would
1368
+ * typically be ignored by applications. The typical way to use this function is
1369
+ * to check if an encountered box contains metadata that the application is
1370
+ * interested in (e.g. EXIF or XMP metadata), in order to conditionally set a
1371
+ * box buffer.
1372
+ *
1373
+ * @param dec decoder object
1374
+ * @param type buffer to copy the type into
1375
+ * @param decompressed which box type to get: JXL_FALSE to get the raw box type,
1376
+ * which can be "brob", JXL_TRUE, get the underlying box type.
1377
+ * @return ::JXL_DEC_SUCCESS if the value is available, ::JXL_DEC_ERROR if
1378
+ * not, for example the JPEG XL file does not use the container format.
1379
+ */
1380
+ JXL_EXPORT JxlDecoderStatus JxlDecoderGetBoxType(JxlDecoder* dec,
1381
+ JxlBoxType type,
1382
+ JXL_BOOL decompressed);
1383
+
1384
+ /**
1385
+ * Returns the size of a box as it appears in the container file, after the @ref
1386
+ * JXL_DEC_BOX event. This includes all the box headers.
1387
+ *
1388
+ * @param dec decoder object
1389
+ * @param size raw size of the box in bytes
1390
+ * @return ::JXL_DEC_ERROR if no box size is available, ::JXL_DEC_SUCCESS
1391
+ * otherwise.
1392
+ */
1393
+ JXL_EXPORT JxlDecoderStatus JxlDecoderGetBoxSizeRaw(const JxlDecoder* dec,
1394
+ uint64_t* size);
1395
+
1396
+ /**
1397
+ * Returns the size of the contents of a box, after the @ref
1398
+ * JXL_DEC_BOX event. This does not include any of the headers of the box. For
1399
+ * compressed "brob" boxes, this is the size of the compressed content. Even
1400
+ * when @ref JxlDecoderSetDecompressBoxes is enabled, the return value of
1401
+ * function does not change, and the decompressed size is not known before it
1402
+ * has already been decompressed and output.
1403
+ *
1404
+ * @param dec decoder object
1405
+ * @param size size of the payload of the box in bytes
1406
+ * @return @ref JXL_DEC_ERROR if no box size is available, @ref JXL_DEC_SUCCESS
1407
+ * otherwise.
1408
+ */
1409
+ JXL_EXPORT JxlDecoderStatus JxlDecoderGetBoxSizeContents(const JxlDecoder* dec,
1410
+ uint64_t* size);
1411
+
1412
+ /**
1413
+ * Configures at which progressive steps in frame decoding these @ref
1414
+ * JXL_DEC_FRAME_PROGRESSION event occurs. The default value for the level
1415
+ * of detail if this function is never called is `kDC`.
1416
+ *
1417
+ * @param dec decoder object
1418
+ * @param detail at which level of detail to trigger @ref
1419
+ * JXL_DEC_FRAME_PROGRESSION
1420
+ * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such as
1421
+ * an invalid value for the progressive detail.
1422
+ */
1423
+ JXL_EXPORT JxlDecoderStatus
1424
+ JxlDecoderSetProgressiveDetail(JxlDecoder* dec, JxlProgressiveDetail detail);
1425
+
1426
+ /**
1427
+ * Returns the intended downsampling ratio for the progressive frame produced
1428
+ * by @ref JxlDecoderFlushImage after the latest ::JXL_DEC_FRAME_PROGRESSION
1429
+ * event.
1430
+ *
1431
+ * @param dec decoder object
1432
+ * @return The intended downsampling ratio, can be `1`, `2`, `4` or `8`.
1433
+ */
1434
+ JXL_EXPORT size_t JxlDecoderGetIntendedDownsamplingRatio(JxlDecoder* dec);
1435
+
1436
+ /**
1437
+ * Outputs progressive step towards the decoded image so far when only partial
1438
+ * input was received. If the flush was successful, the buffer set with @ref
1439
+ * JxlDecoderSetImageOutBuffer will contain partial image data.
1440
+ *
1441
+ * Can be called when @ref JxlDecoderProcessInput returns @ref
1442
+ * JXL_DEC_NEED_MORE_INPUT, after the ::JXL_DEC_FRAME event already occurred
1443
+ * and before the ::JXL_DEC_FULL_IMAGE event occurred for a frame.
1444
+ *
1445
+ * @param dec decoder object
1446
+ * @return ::JXL_DEC_SUCCESS if image data was flushed to the output buffer,
1447
+ * or ::JXL_DEC_ERROR when no flush was done, e.g. if not enough image
1448
+ * data was available yet even for flush, or no output buffer was set yet.
1449
+ * This error is not fatal, it only indicates no flushed image is available
1450
+ * right now. Regular decoding can still be performed.
1451
+ */
1452
+ JXL_EXPORT JxlDecoderStatus JxlDecoderFlushImage(JxlDecoder* dec);
1453
+
1454
+ /**
1455
+ * Sets the bit depth of the output buffer or callback.
1456
+ *
1457
+ * Can be called after @ref JxlDecoderSetImageOutBuffer or @ref
1458
+ * JxlDecoderSetImageOutCallback. For float pixel data types, only the default
1459
+ * ::JXL_BIT_DEPTH_FROM_PIXEL_FORMAT setting is supported.
1460
+ *
1461
+ * @param dec decoder object
1462
+ * @param bit_depth the bit depth setting of the pixel output
1463
+ * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such as
1464
+ * incompatible custom bit depth and pixel data type.
1465
+ */
1466
+ JXL_EXPORT JxlDecoderStatus
1467
+ JxlDecoderSetImageOutBitDepth(JxlDecoder* dec, const JxlBitDepth* bit_depth);
1468
+
1469
+ #ifdef __cplusplus
1470
+ }
1471
+ #endif
1472
+
1473
+ #endif /* JXL_DECODE_H_ */
1474
+
1475
+ /** @}*/