tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

decode.h (70762B)


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