alpha2_native_gpu/import.rs
1//! Platform-neutral descriptions used while importing native image planes.
2
3/// Supported decoded plane organizations.
4#[derive(Copy, Clone, Debug, Eq, PartialEq)]
5pub enum NativePlaneLayout {
6 /// Three independent 8-bit R8 images.
7 I420,
8 /// 8-bit R8 luma plus one interleaved RG8 chroma image.
9 Nv12,
10 /// 10-bit R16 luma plus one interleaved RG16 chroma image, left-aligned in
11 /// 16-bit containers.
12 P010,
13}
14
15impl NativePlaneLayout {
16 /// Significant bits per component.
17 #[must_use]
18 pub const fn bit_depth(self) -> u8 {
19 match self {
20 Self::I420 | Self::Nv12 => 8,
21 Self::P010 => 10,
22 }
23 }
24
25 /// Bytes one coded pixel occupies across all planes of this layout, as a
26 /// numerator over 2: 4:2:0 stores 1.5 samples a pixel.
27 #[must_use]
28 pub const fn bytes_per_pixel_numerator(self) -> u64 {
29 match self {
30 // 4:2:0 stores 1.5 samples per pixel; 10-bit doubles the container.
31 Self::I420 | Self::Nv12 => 3,
32 Self::P010 => 6,
33 }
34 }
35}
36
37/// One opaque native plane before it is wrapped by the active GPU backend.
38#[derive(Copy, Clone, Debug, Eq, PartialEq)]
39pub struct ImportedPlaneDescriptor {
40 /// Backend-native image handle.
41 pub image: u64,
42 /// Backend-native image format.
43 pub format: u32,
44 /// Plane width in samples.
45 pub width: u32,
46 /// Plane height in samples.
47 pub height: u32,
48}