re_types/datatypes/
pixel_format.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/rust/api.rs
// Based on "crates/store/re_types/definitions/rerun/datatypes/pixel_format.fbs".

#![allow(unused_imports)]
#![allow(unused_parens)]
#![allow(clippy::clone_on_copy)]
#![allow(clippy::cloned_instead_of_copied)]
#![allow(clippy::map_flatten)]
#![allow(clippy::needless_question_mark)]
#![allow(clippy::new_without_default)]
#![allow(clippy::redundant_closure)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::too_many_lines)]
#![allow(non_camel_case_types)]

use ::re_types_core::external::arrow2;
use ::re_types_core::ComponentName;
use ::re_types_core::SerializationResult;
use ::re_types_core::{ComponentBatch, MaybeOwnedComponentBatch};
use ::re_types_core::{DeserializationError, DeserializationResult};

/// **Datatype**: Specifieds a particular format of an [`archetypes::Image`][crate::archetypes::Image].
///
/// Most images can be described by a [`datatypes::ColorModel`][crate::datatypes::ColorModel] and a [`datatypes::ChannelDatatype`][crate::datatypes::ChannelDatatype],
/// e.g. `RGB` and `U8` respectively.
///
/// However, some image formats has chroma downsampling and/or
/// use differing number of bits per channel, and that is what this [`datatypes::PixelFormat`][crate::datatypes::PixelFormat] is for.
///
/// All these formats support random access.
///
/// For more compressed image formats, see [`archetypes::EncodedImage`][crate::archetypes::EncodedImage].
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum PixelFormat {
    /// `Y_U_V12` is a YUV 4:2:0 fully planar YUV format without chroma downsampling, also known as `I420`.
    ///
    /// This uses limited range YUV, i.e. Y is expected to be within [16, 235] and U/V within [16, 240].
    ///
    /// First comes entire image in Y in one plane, followed by the U and V planes, which each only have half
    /// the resolution of the Y plane.
    #[allow(clippy::upper_case_acronyms)]
    Y_U_V12_LimitedRange = 20,

    /// `NV12` (aka `Y_UV12`) is a YUV 4:2:0 chroma downsampled form at with 12 bits per pixel and 8 bits per channel.
    ///
    /// This uses limited range YUV, i.e. Y is expected to be within [16, 235] and U/V within [16, 240].
    ///
    /// First comes entire image in Y in one plane,
    /// followed by a plane with interleaved lines ordered as U0, V0, U1, V1, etc.
    #[default]
    #[allow(clippy::upper_case_acronyms)]
    NV12 = 26,

    /// `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.
    ///
    /// This uses limited range YUV, i.e. Y is expected to be within [16, 235] and U/V within [16, 240].
    ///
    /// The order of the channels is Y0, U0, Y1, V0, all in the same plane.
    #[allow(clippy::upper_case_acronyms)]
    YUY2 = 27,

    /// Monochrome Y plane only, essentially a YUV 4:0:0 planar format.
    ///
    /// Also known as just "gray". This is virtually identical to a 8bit luminance/grayscale (see [`datatypes::ColorModel`][crate::datatypes::ColorModel]).
    ///
    /// This uses entire range YUV, i.e. Y is expected to be within [0, 255].
    /// (as opposed to "limited range" YUV as used e.g. in NV12).
    #[allow(clippy::upper_case_acronyms)]
    Y8_FullRange = 30,

    /// `Y_U_V24` is a YUV 4:4:4 fully planar YUV format without chroma downsampling, also known as `I444`.
    ///
    /// This uses limited range YUV, i.e. Y is expected to be within [16, 235] and U/V within [16, 240].
    ///
    /// First comes entire image in Y in one plane, followed by the U and V planes.
    #[allow(clippy::upper_case_acronyms)]
    Y_U_V24_LimitedRange = 39,

    /// `Y_U_V24` is a YUV 4:4:4 fully planar YUV format without chroma downsampling, also known as `I444`.
    ///
    /// This uses full range YUV with all components ranging from 0 to 255
    /// (as opposed to "limited range" YUV as used e.g. in NV12).
    ///
    /// First comes entire image in Y in one plane, followed by the U and V planes.
    #[allow(clippy::upper_case_acronyms)]
    Y_U_V24_FullRange = 40,

    /// Monochrome Y plane only, essentially a YUV 4:0:0 planar format.
    ///
    /// Also known as just "gray".
    ///
    /// This uses limited range YUV, i.e. Y is expected to be within [16, 235].
    /// If not for this range limitation/remapping, this is almost identical to 8bit luminace/grayscale (see [`datatypes::ColorModel`][crate::datatypes::ColorModel]).
    #[allow(clippy::upper_case_acronyms)]
    Y8_LimitedRange = 41,

    /// `Y_U_V12` is a YUV 4:2:0 fully planar YUV format without chroma downsampling, also known as `I420`.
    ///
    /// This uses full range YUV with all components ranging from 0 to 255
    /// (as opposed to "limited range" YUV as used e.g. in NV12).
    ///
    /// First comes entire image in Y in one plane, followed by the U and V planes, which each only have half
    /// the resolution of the Y plane.
    #[allow(clippy::upper_case_acronyms)]
    Y_U_V12_FullRange = 44,

    /// `Y_U_V16` is a YUV 4:2:2 fully planar YUV format without chroma downsampling, also known as `I422`.
    ///
    /// This uses limited range YUV, i.e. Y is expected to be within [16, 235] and U/V within [16, 240].
    ///
    /// First comes entire image in Y in one plane, followed by the U and V planes, which each only have half
    /// the horizontal resolution of the Y plane.
    #[allow(clippy::upper_case_acronyms)]
    Y_U_V16_LimitedRange = 49,

    /// `Y_U_V16` is a YUV 4:2:2 fully planar YUV format without chroma downsampling, also known as `I422`.
    ///
    /// This uses full range YUV with all components ranging from 0 to 255
    /// (as opposed to "limited range" YUV as used e.g. in NV12).
    ///
    /// First comes entire image in Y in one plane, followed by the U and V planes, which each only have half
    /// the horizontal resolution of the Y plane.
    #[allow(clippy::upper_case_acronyms)]
    Y_U_V16_FullRange = 50,
}

impl ::re_types_core::reflection::Enum for PixelFormat {
    #[inline]
    fn variants() -> &'static [Self] {
        &[
            Self::Y_U_V12_LimitedRange,
            Self::NV12,
            Self::YUY2,
            Self::Y8_FullRange,
            Self::Y_U_V24_LimitedRange,
            Self::Y_U_V24_FullRange,
            Self::Y8_LimitedRange,
            Self::Y_U_V12_FullRange,
            Self::Y_U_V16_LimitedRange,
            Self::Y_U_V16_FullRange,
        ]
    }

    #[inline]
    fn docstring_md(self) -> &'static str {
        match self {
            Self::Y_U_V12_LimitedRange => {
                "`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."
            }
            Self::NV12 => {
                "`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."
            }
            Self::YUY2 => {
                "`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."
            }
            Self::Y8_FullRange => {
                "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`][crate::datatypes::ColorModel]).\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)."
            }
            Self::Y_U_V24_LimitedRange => {
                "`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."
            }
            Self::Y_U_V24_FullRange => {
                "`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."
            }
            Self::Y8_LimitedRange => {
                "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`][crate::datatypes::ColorModel])."
            }
            Self::Y_U_V12_FullRange => {
                "`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."
            }
            Self::Y_U_V16_LimitedRange => {
                "`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."
            }
            Self::Y_U_V16_FullRange => {
                "`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."
            }
        }
    }
}

impl ::re_types_core::SizeBytes for PixelFormat {
    #[inline]
    fn heap_size_bytes(&self) -> u64 {
        0
    }

    #[inline]
    fn is_pod() -> bool {
        true
    }
}

impl std::fmt::Display for PixelFormat {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Y_U_V12_LimitedRange => write!(f, "Y_U_V12_LimitedRange"),
            Self::NV12 => write!(f, "NV12"),
            Self::YUY2 => write!(f, "YUY2"),
            Self::Y8_FullRange => write!(f, "Y8_FullRange"),
            Self::Y_U_V24_LimitedRange => write!(f, "Y_U_V24_LimitedRange"),
            Self::Y_U_V24_FullRange => write!(f, "Y_U_V24_FullRange"),
            Self::Y8_LimitedRange => write!(f, "Y8_LimitedRange"),
            Self::Y_U_V12_FullRange => write!(f, "Y_U_V12_FullRange"),
            Self::Y_U_V16_LimitedRange => write!(f, "Y_U_V16_LimitedRange"),
            Self::Y_U_V16_FullRange => write!(f, "Y_U_V16_FullRange"),
        }
    }
}

::re_types_core::macros::impl_into_cow!(PixelFormat);

impl ::re_types_core::Loggable for PixelFormat {
    type Name = ::re_types_core::DatatypeName;

    #[inline]
    fn name() -> Self::Name {
        "rerun.datatypes.PixelFormat".into()
    }

    #[inline]
    fn arrow_datatype() -> arrow2::datatypes::DataType {
        #![allow(clippy::wildcard_imports)]
        use arrow2::datatypes::*;
        DataType::UInt8
    }

    fn to_arrow_opt<'a>(
        data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
    ) -> SerializationResult<Box<dyn arrow2::array::Array>>
    where
        Self: Clone + 'a,
    {
        #![allow(clippy::wildcard_imports)]
        #![allow(clippy::manual_is_variant_and)]
        use ::re_types_core::{Loggable as _, ResultExt as _};
        use arrow2::{array::*, datatypes::*};
        Ok({
            let (somes, data0): (Vec<_>, Vec<_>) = data
                .into_iter()
                .map(|datum| {
                    let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
                    let datum = datum.map(|datum| *datum as u8);
                    (datum.is_some(), datum)
                })
                .unzip();
            let data0_bitmap: Option<arrow2::bitmap::Bitmap> = {
                let any_nones = somes.iter().any(|some| !*some);
                any_nones.then(|| somes.into())
            };
            PrimitiveArray::new(
                Self::arrow_datatype(),
                data0.into_iter().map(|v| v.unwrap_or_default()).collect(),
                data0_bitmap,
            )
            .boxed()
        })
    }

    fn from_arrow_opt(
        arrow_data: &dyn arrow2::array::Array,
    ) -> DeserializationResult<Vec<Option<Self>>>
    where
        Self: Sized,
    {
        #![allow(clippy::wildcard_imports)]
        use ::re_types_core::{Loggable as _, ResultExt as _};
        use arrow2::{array::*, buffer::*, datatypes::*};
        Ok(arrow_data
            .as_any()
            .downcast_ref::<UInt8Array>()
            .ok_or_else(|| {
                let expected = Self::arrow_datatype();
                let actual = arrow_data.data_type().clone();
                DeserializationError::datatype_mismatch(expected, actual)
            })
            .with_context("rerun.datatypes.PixelFormat#enum")?
            .into_iter()
            .map(|opt| opt.copied())
            .map(|typ| match typ {
                Some(20) => Ok(Some(Self::Y_U_V12_LimitedRange)),
                Some(26) => Ok(Some(Self::NV12)),
                Some(27) => Ok(Some(Self::YUY2)),
                Some(30) => Ok(Some(Self::Y8_FullRange)),
                Some(39) => Ok(Some(Self::Y_U_V24_LimitedRange)),
                Some(40) => Ok(Some(Self::Y_U_V24_FullRange)),
                Some(41) => Ok(Some(Self::Y8_LimitedRange)),
                Some(44) => Ok(Some(Self::Y_U_V12_FullRange)),
                Some(49) => Ok(Some(Self::Y_U_V16_LimitedRange)),
                Some(50) => Ok(Some(Self::Y_U_V16_FullRange)),
                None => Ok(None),
                Some(invalid) => Err(DeserializationError::missing_union_arm(
                    Self::arrow_datatype(),
                    "<invalid>",
                    invalid as _,
                )),
            })
            .collect::<DeserializationResult<Vec<Option<_>>>>()
            .with_context("rerun.datatypes.PixelFormat")?)
    }
}