re_types/datatypes/
pixel_format.rs

1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/rust/api.rs
2// Based on "crates/store/re_types/definitions/rerun/datatypes/pixel_format.fbs".
3
4#![allow(unused_braces)]
5#![allow(unused_imports)]
6#![allow(unused_parens)]
7#![allow(clippy::clone_on_copy)]
8#![allow(clippy::cloned_instead_of_copied)]
9#![allow(clippy::map_flatten)]
10#![allow(clippy::needless_question_mark)]
11#![allow(clippy::new_without_default)]
12#![allow(clippy::redundant_closure)]
13#![allow(clippy::too_many_arguments)]
14#![allow(clippy::too_many_lines)]
15#![allow(non_camel_case_types)]
16
17use ::re_types_core::try_serialize_field;
18use ::re_types_core::SerializationResult;
19use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
20use ::re_types_core::{ComponentDescriptor, ComponentType};
21use ::re_types_core::{DeserializationError, DeserializationResult};
22
23/// **Datatype**: Specifieds a particular format of an [`archetypes::Image`][crate::archetypes::Image].
24///
25/// Most images can be described by a [`datatypes::ColorModel`][crate::datatypes::ColorModel] and a [`datatypes::ChannelDatatype`][crate::datatypes::ChannelDatatype],
26/// e.g. `RGB` and `U8` respectively.
27///
28/// However, some image formats has chroma downsampling and/or
29/// use differing number of bits per channel, and that is what this [`datatypes::PixelFormat`][crate::datatypes::PixelFormat] is for.
30///
31/// All these formats support random access.
32///
33/// For more compressed image formats, see [`archetypes::EncodedImage`][crate::archetypes::EncodedImage].
34#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)]
35#[repr(u8)]
36pub enum PixelFormat {
37    /// `Y_U_V12` is a YUV 4:2:0 fully planar YUV format without chroma downsampling, also known as `I420`.
38    ///
39    /// This uses limited range YUV, i.e. Y is expected to be within [16, 235] and U/V within [16, 240].
40    ///
41    /// First comes entire image in Y in one plane, followed by the U and V planes, which each only have half
42    /// the resolution of the Y plane.
43    #[allow(clippy::upper_case_acronyms)]
44    Y_U_V12_LimitedRange = 20,
45
46    /// `NV12` (aka `Y_UV12`) is a YUV 4:2:0 chroma downsampled form at with 12 bits per pixel and 8 bits per channel.
47    ///
48    /// This uses limited range YUV, i.e. Y is expected to be within [16, 235] and U/V within [16, 240].
49    ///
50    /// First comes entire image in Y in one plane,
51    /// followed by a plane with interleaved lines ordered as U0, V0, U1, V1, etc.
52    #[default]
53    #[allow(clippy::upper_case_acronyms)]
54    NV12 = 26,
55
56    /// `YUY2` (aka 'YUYV', 'YUYV16' or 'NV21'), is a YUV 4:2:2 chroma downsampled format with 16 bits per pixel and 8 bits per channel.
57    ///
58    /// This uses limited range YUV, i.e. Y is expected to be within [16, 235] and U/V within [16, 240].
59    ///
60    /// The order of the channels is Y0, U0, Y1, V0, all in the same plane.
61    #[allow(clippy::upper_case_acronyms)]
62    YUY2 = 27,
63
64    /// Monochrome Y plane only, essentially a YUV 4:0:0 planar format.
65    ///
66    /// Also known as just "gray". This is virtually identical to a 8bit luminance/grayscale (see [`datatypes::ColorModel`][crate::datatypes::ColorModel]).
67    ///
68    /// This uses entire range YUV, i.e. Y is expected to be within [0, 255].
69    /// (as opposed to "limited range" YUV as used e.g. in NV12).
70    #[allow(clippy::upper_case_acronyms)]
71    Y8_FullRange = 30,
72
73    /// `Y_U_V24` is a YUV 4:4:4 fully planar YUV format without chroma downsampling, also known as `I444`.
74    ///
75    /// This uses limited range YUV, i.e. Y is expected to be within [16, 235] and U/V within [16, 240].
76    ///
77    /// First comes entire image in Y in one plane, followed by the U and V planes.
78    #[allow(clippy::upper_case_acronyms)]
79    Y_U_V24_LimitedRange = 39,
80
81    /// `Y_U_V24` is a YUV 4:4:4 fully planar YUV format without chroma downsampling, also known as `I444`.
82    ///
83    /// This uses full range YUV with all components ranging from 0 to 255
84    /// (as opposed to "limited range" YUV as used e.g. in NV12).
85    ///
86    /// First comes entire image in Y in one plane, followed by the U and V planes.
87    #[allow(clippy::upper_case_acronyms)]
88    Y_U_V24_FullRange = 40,
89
90    /// Monochrome Y plane only, essentially a YUV 4:0:0 planar format.
91    ///
92    /// Also known as just "gray".
93    ///
94    /// This uses limited range YUV, i.e. Y is expected to be within [16, 235].
95    /// If not for this range limitation/remapping, this is almost identical to 8bit luminace/grayscale (see [`datatypes::ColorModel`][crate::datatypes::ColorModel]).
96    #[allow(clippy::upper_case_acronyms)]
97    Y8_LimitedRange = 41,
98
99    /// `Y_U_V12` is a YUV 4:2:0 fully planar YUV format without chroma downsampling, also known as `I420`.
100    ///
101    /// This uses full range YUV with all components ranging from 0 to 255
102    /// (as opposed to "limited range" YUV as used e.g. in NV12).
103    ///
104    /// First comes entire image in Y in one plane, followed by the U and V planes, which each only have half
105    /// the resolution of the Y plane.
106    #[allow(clippy::upper_case_acronyms)]
107    Y_U_V12_FullRange = 44,
108
109    /// `Y_U_V16` is a YUV 4:2:2 fully planar YUV format without chroma downsampling, also known as `I422`.
110    ///
111    /// This uses limited range YUV, i.e. Y is expected to be within [16, 235] and U/V within [16, 240].
112    ///
113    /// First comes entire image in Y in one plane, followed by the U and V planes, which each only have half
114    /// the horizontal resolution of the Y plane.
115    #[allow(clippy::upper_case_acronyms)]
116    Y_U_V16_LimitedRange = 49,
117
118    /// `Y_U_V16` is a YUV 4:2:2 fully planar YUV format without chroma downsampling, also known as `I422`.
119    ///
120    /// This uses full range YUV with all components ranging from 0 to 255
121    /// (as opposed to "limited range" YUV as used e.g. in NV12).
122    ///
123    /// First comes entire image in Y in one plane, followed by the U and V planes, which each only have half
124    /// the horizontal resolution of the Y plane.
125    #[allow(clippy::upper_case_acronyms)]
126    Y_U_V16_FullRange = 50,
127}
128
129::re_types_core::macros::impl_into_cow!(PixelFormat);
130
131impl ::re_types_core::Loggable for PixelFormat {
132    #[inline]
133    fn arrow_datatype() -> arrow::datatypes::DataType {
134        #![allow(clippy::wildcard_imports)]
135        use arrow::datatypes::*;
136        DataType::UInt8
137    }
138
139    fn to_arrow_opt<'a>(
140        data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
141    ) -> SerializationResult<arrow::array::ArrayRef>
142    where
143        Self: Clone + 'a,
144    {
145        #![allow(clippy::wildcard_imports)]
146        #![allow(clippy::manual_is_variant_and)]
147        use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
148        use arrow::{array::*, buffer::*, datatypes::*};
149        Ok({
150            let (somes, data0): (Vec<_>, Vec<_>) = data
151                .into_iter()
152                .map(|datum| {
153                    let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
154                    let datum = datum.map(|datum| *datum as u8);
155                    (datum.is_some(), datum)
156                })
157                .unzip();
158            let data0_validity: Option<arrow::buffer::NullBuffer> = {
159                let any_nones = somes.iter().any(|some| !*some);
160                any_nones.then(|| somes.into())
161            };
162            as_array_ref(PrimitiveArray::<UInt8Type>::new(
163                ScalarBuffer::from(
164                    data0
165                        .into_iter()
166                        .map(|v| v.unwrap_or_default())
167                        .collect::<Vec<_>>(),
168                ),
169                data0_validity,
170            ))
171        })
172    }
173
174    fn from_arrow_opt(
175        arrow_data: &dyn arrow::array::Array,
176    ) -> DeserializationResult<Vec<Option<Self>>>
177    where
178        Self: Sized,
179    {
180        #![allow(clippy::wildcard_imports)]
181        use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
182        use arrow::{array::*, buffer::*, datatypes::*};
183        Ok(arrow_data
184            .as_any()
185            .downcast_ref::<UInt8Array>()
186            .ok_or_else(|| {
187                let expected = Self::arrow_datatype();
188                let actual = arrow_data.data_type().clone();
189                DeserializationError::datatype_mismatch(expected, actual)
190            })
191            .with_context("rerun.datatypes.PixelFormat#enum")?
192            .into_iter()
193            .map(|typ| match typ {
194                Some(20) => Ok(Some(Self::Y_U_V12_LimitedRange)),
195                Some(26) => Ok(Some(Self::NV12)),
196                Some(27) => Ok(Some(Self::YUY2)),
197                Some(30) => Ok(Some(Self::Y8_FullRange)),
198                Some(39) => Ok(Some(Self::Y_U_V24_LimitedRange)),
199                Some(40) => Ok(Some(Self::Y_U_V24_FullRange)),
200                Some(41) => Ok(Some(Self::Y8_LimitedRange)),
201                Some(44) => Ok(Some(Self::Y_U_V12_FullRange)),
202                Some(49) => Ok(Some(Self::Y_U_V16_LimitedRange)),
203                Some(50) => Ok(Some(Self::Y_U_V16_FullRange)),
204                None => Ok(None),
205                Some(invalid) => Err(DeserializationError::missing_union_arm(
206                    Self::arrow_datatype(),
207                    "<invalid>",
208                    invalid as _,
209                )),
210            })
211            .collect::<DeserializationResult<Vec<Option<_>>>>()
212            .with_context("rerun.datatypes.PixelFormat")?)
213    }
214}
215
216impl std::fmt::Display for PixelFormat {
217    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
218        match self {
219            Self::Y_U_V12_LimitedRange => write!(f, "Y_U_V12_LimitedRange"),
220            Self::NV12 => write!(f, "NV12"),
221            Self::YUY2 => write!(f, "YUY2"),
222            Self::Y8_FullRange => write!(f, "Y8_FullRange"),
223            Self::Y_U_V24_LimitedRange => write!(f, "Y_U_V24_LimitedRange"),
224            Self::Y_U_V24_FullRange => write!(f, "Y_U_V24_FullRange"),
225            Self::Y8_LimitedRange => write!(f, "Y8_LimitedRange"),
226            Self::Y_U_V12_FullRange => write!(f, "Y_U_V12_FullRange"),
227            Self::Y_U_V16_LimitedRange => write!(f, "Y_U_V16_LimitedRange"),
228            Self::Y_U_V16_FullRange => write!(f, "Y_U_V16_FullRange"),
229        }
230    }
231}
232
233impl ::re_types_core::reflection::Enum for PixelFormat {
234    #[inline]
235    fn variants() -> &'static [Self] {
236        &[
237            Self::Y_U_V12_LimitedRange,
238            Self::NV12,
239            Self::YUY2,
240            Self::Y8_FullRange,
241            Self::Y_U_V24_LimitedRange,
242            Self::Y_U_V24_FullRange,
243            Self::Y8_LimitedRange,
244            Self::Y_U_V12_FullRange,
245            Self::Y_U_V16_LimitedRange,
246            Self::Y_U_V16_FullRange,
247        ]
248    }
249
250    #[inline]
251    fn docstring_md(self) -> &'static str {
252        match self {
253            Self::Y_U_V12_LimitedRange => {
254                "`Y_U_V12` is a YUV 4:2:0 fully planar YUV format without chroma downsampling, also known as `I420`.\n\nThis uses limited range YUV, i.e. Y is expected to be within [16, 235] and U/V within [16, 240].\n\nFirst comes entire image in Y in one plane, followed by the U and V planes, which each only have half\nthe resolution of the Y plane."
255            }
256            Self::NV12 => {
257                "`NV12` (aka `Y_UV12`) is a YUV 4:2:0 chroma downsampled form at with 12 bits per pixel and 8 bits per channel.\n\nThis uses limited range YUV, i.e. Y is expected to be within [16, 235] and U/V within [16, 240].\n\nFirst comes entire image in Y in one plane,\nfollowed by a plane with interleaved lines ordered as U0, V0, U1, V1, etc."
258            }
259            Self::YUY2 => {
260                "`YUY2` (aka 'YUYV', 'YUYV16' or 'NV21'), is a YUV 4:2:2 chroma downsampled format with 16 bits per pixel and 8 bits per channel.\n\nThis uses limited range YUV, i.e. Y is expected to be within [16, 235] and U/V within [16, 240].\n\nThe order of the channels is Y0, U0, Y1, V0, all in the same plane."
261            }
262            Self::Y8_FullRange => {
263                "Monochrome Y plane only, essentially a YUV 4:0:0 planar format.\n\nAlso known as just \"gray\". This is virtually identical to a 8bit luminance/grayscale (see [`datatypes.ColorModel`](https://rerun.io/docs/reference/types/datatypes/color_model)).\n\nThis uses entire range YUV, i.e. Y is expected to be within [0, 255].\n(as opposed to \"limited range\" YUV as used e.g. in NV12)."
264            }
265            Self::Y_U_V24_LimitedRange => {
266                "`Y_U_V24` is a YUV 4:4:4 fully planar YUV format without chroma downsampling, also known as `I444`.\n\nThis uses limited range YUV, i.e. Y is expected to be within [16, 235] and U/V within [16, 240].\n\nFirst comes entire image in Y in one plane, followed by the U and V planes."
267            }
268            Self::Y_U_V24_FullRange => {
269                "`Y_U_V24` is a YUV 4:4:4 fully planar YUV format without chroma downsampling, also known as `I444`.\n\nThis uses full range YUV with all components ranging from 0 to 255\n(as opposed to \"limited range\" YUV as used e.g. in NV12).\n\nFirst comes entire image in Y in one plane, followed by the U and V planes."
270            }
271            Self::Y8_LimitedRange => {
272                "Monochrome Y plane only, essentially a YUV 4:0:0 planar format.\n\nAlso known as just \"gray\".\n\nThis uses limited range YUV, i.e. Y is expected to be within [16, 235].\nIf not for this range limitation/remapping, this is almost identical to 8bit luminace/grayscale (see [`datatypes.ColorModel`](https://rerun.io/docs/reference/types/datatypes/color_model))."
273            }
274            Self::Y_U_V12_FullRange => {
275                "`Y_U_V12` is a YUV 4:2:0 fully planar YUV format without chroma downsampling, also known as `I420`.\n\nThis uses full range YUV with all components ranging from 0 to 255\n(as opposed to \"limited range\" YUV as used e.g. in NV12).\n\nFirst comes entire image in Y in one plane, followed by the U and V planes, which each only have half\nthe resolution of the Y plane."
276            }
277            Self::Y_U_V16_LimitedRange => {
278                "`Y_U_V16` is a YUV 4:2:2 fully planar YUV format without chroma downsampling, also known as `I422`.\n\nThis uses limited range YUV, i.e. Y is expected to be within [16, 235] and U/V within [16, 240].\n\nFirst comes entire image in Y in one plane, followed by the U and V planes, which each only have half\nthe horizontal resolution of the Y plane."
279            }
280            Self::Y_U_V16_FullRange => {
281                "`Y_U_V16` is a YUV 4:2:2 fully planar YUV format without chroma downsampling, also known as `I422`.\n\nThis uses full range YUV with all components ranging from 0 to 255\n(as opposed to \"limited range\" YUV as used e.g. in NV12).\n\nFirst comes entire image in Y in one plane, followed by the U and V planes, which each only have half\nthe horizontal resolution of the Y plane."
282            }
283        }
284    }
285}
286
287impl ::re_byte_size::SizeBytes for PixelFormat {
288    #[inline]
289    fn heap_size_bytes(&self) -> u64 {
290        0
291    }
292
293    #[inline]
294    fn is_pod() -> bool {
295        true
296    }
297}