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