Skip to main content

edgefirst_codec/
options.rs

1// SPDX-FileCopyrightText: Copyright 2026 Au-Zone Technologies
2// SPDX-License-Identifier: Apache-2.0
3
4//! Decode options and output metadata.
5
6use edgefirst_tensor::PixelFormat;
7
8/// Options controlling how an image is decoded.
9#[derive(Debug, Clone)]
10pub struct DecodeOptions {
11    /// Desired output pixel format. `None` uses the native format from the
12    /// file (typically RGB for JPEG, RGB/RGBA for PNG).
13    pub format: Option<PixelFormat>,
14
15    /// Whether to apply EXIF orientation metadata. Default: `true`.
16    ///
17    /// Set to `false` when the caller will handle rotation/flip externally
18    /// (e.g. via [`ImageProcessor::convert()`]).
19    pub apply_exif: bool,
20}
21
22impl Default for DecodeOptions {
23    fn default() -> Self {
24        Self {
25            format: None,
26            apply_exif: true,
27        }
28    }
29}
30
31impl DecodeOptions {
32    /// Set the desired output pixel format.
33    #[must_use]
34    pub fn with_format(mut self, format: PixelFormat) -> Self {
35        self.format = Some(format);
36        self
37    }
38
39    /// Set whether to apply EXIF orientation.
40    #[must_use]
41    pub fn with_exif(mut self, apply: bool) -> Self {
42        self.apply_exif = apply;
43        self
44    }
45}
46
47/// Metadata returned after a successful image decode.
48#[derive(Debug, Clone, Copy)]
49pub struct ImageInfo {
50    /// Width of the decoded image in pixels.
51    pub width: usize,
52    /// Height of the decoded image in pixels.
53    pub height: usize,
54    /// Pixel format of the decoded data written to the tensor.
55    pub format: PixelFormat,
56    /// Row stride in bytes used when writing into the tensor.
57    pub row_stride: usize,
58}