libjxl

FORK: libjxl patches used on blog
git clone https://git.neptards.moe/blog/libjxl.git
Log | Files | Refs | Submodules | README | LICENSE

decode.h (70607B)


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