Skip to main content

zenjxl_decoder/api/
mod.rs

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// #![warn(missing_docs)]
7
8mod color;
9mod convenience;
10mod data_types;
11mod decoder;
12mod inner;
13mod input;
14#[cfg(feature = "cms")]
15mod moxcms_wrapper;
16mod options;
17mod signature;
18mod xyb_constants;
19
20pub use crate::image::JxlOutputBuffer;
21pub use color::*;
22pub use convenience::{JxlImage, JxlImageInfo, decode, decode_with, read_header, read_header_with};
23pub use data_types::*;
24pub use decoder::*;
25pub use enough::{Stop, Unstoppable};
26pub use inner::*;
27pub use input::*;
28#[cfg(feature = "cms")]
29pub use moxcms_wrapper::*;
30pub use options::*;
31pub use signature::*;
32
33// Error types
34pub use crate::error::{Error, Result};
35
36// Image types used by CLI/fuzz for output buffer construction
37pub use crate::image::{
38    DataTypeTag, Image, ImageDataType, ImageRect, ImageRectMut, OwnedRawImage, RawImageRect,
39    RawImageRectMut, Rect,
40};
41
42// Header types that appear in public API structs
43pub use crate::headers::color_encoding::RenderingIntent;
44pub use crate::headers::extra_channels::ExtraChannel;
45pub use crate::headers::image_metadata::Orientation;
46
47// Container box types
48pub use crate::container::gain_map::GainMapBundle;
49
50// Point type used in Error variants
51pub use crate::features::spline::Point;
52
53// Profiling (feature-gated, used by CLI)
54#[cfg(feature = "profiling")]
55pub use crate::util::profiling::print_profile_report;
56
57/// This type represents the return value of a function that reads input from a bitstream. The
58/// variant `Complete` indicates that the operation was completed successfully, and its return
59/// value is available. The variant `NeedsMoreInput` indicates that more input is needed, and the
60/// function should be called again. This variant comes with a `size_hint`, representing an
61/// estimate of the number of additional bytes needed, and a `fallback`, representing additional
62/// information that might be needed to call the function again (i.e. because it takes a decoder
63/// object by value).
64#[derive(Debug, PartialEq)]
65pub enum ProcessingResult<T, U> {
66    Complete { result: T },
67    NeedsMoreInput { size_hint: usize, fallback: U },
68}
69
70impl<T> ProcessingResult<T, ()> {
71    fn new(
72        result: Result<T, crate::error::Error>,
73    ) -> Result<ProcessingResult<T, ()>, crate::error::Error> {
74        match result {
75            Ok(v) => Ok(ProcessingResult::Complete { result: v }),
76            Err(crate::error::Error::OutOfBounds(v)) => Ok(ProcessingResult::NeedsMoreInput {
77                size_hint: v,
78                fallback: (),
79            }),
80            Err(e) => Err(e),
81        }
82    }
83}
84
85#[derive(Clone)]
86#[non_exhaustive]
87pub struct ToneMapping {
88    pub intensity_target: f32,
89    pub min_nits: f32,
90    pub relative_to_max_display: bool,
91    pub linear_below: f32,
92}
93
94#[derive(Clone)]
95#[non_exhaustive]
96pub struct JxlBasicInfo {
97    pub size: (usize, usize),
98    pub bit_depth: JxlBitDepth,
99    pub orientation: Orientation,
100    pub extra_channels: Vec<JxlExtraChannel>,
101    pub animation: Option<JxlAnimation>,
102    pub uses_original_profile: bool,
103    pub tone_mapping: ToneMapping,
104    pub preview_size: Option<(usize, usize)>,
105    /// Intrinsic display size, if different from coded size.
106    ///
107    /// When present, the image should be rendered at this `(width, height)`
108    /// rather than the coded `size`. Used for resolution-independence
109    /// (e.g. a 4000×3000 image meant to display at 2000×1500).
110    pub intrinsic_size: Option<(usize, usize)>,
111}