#[non_exhaustive]#[repr(u16)]pub enum PixelFormat {
Show 70 variants
Yuv420P = 0,
Yuv422P = 1,
Yuv444P = 2,
Rgb24 = 3,
Rgba = 4,
Gray8 = 5,
Pal8 = 6,
Bgr24 = 7,
Bgra = 8,
Argb = 9,
Abgr = 10,
Rgb48Le = 11,
Rgba64Le = 12,
Gray16Le = 13,
Gray10Le = 14,
Gray12Le = 15,
Yuv420P10Le = 16,
Yuv422P10Le = 17,
Yuv444P10Le = 18,
Yuv420P12Le = 19,
Yuv422P12Le = 20,
Yuv444P12Le = 21,
YuvJ420P = 22,
YuvJ422P = 23,
YuvJ444P = 24,
Nv12 = 25,
Nv21 = 26,
Ya8 = 27,
Yuva420P = 28,
MonoBlack = 29,
MonoWhite = 30,
Yuyv422 = 31,
Uyvy422 = 32,
Cmyk = 33,
Yuv411P = 34,
Gbrp10Le = 35,
Gbrap10Le = 36,
Gbrp12Le = 37,
Gbrap12Le = 38,
Gbrp14Le = 39,
Gbrap14Le = 40,
Yuv420P16Le = 41,
Yuv422P16Le = 42,
Yuv444P16Le = 43,
Yuva422P = 44,
Yuva444P = 45,
Yuva422P10Le = 46,
Yuva422P12Le = 47,
Yuva444P10Le = 48,
Yuva444P12Le = 49,
Yuva422P16Le = 50,
Yuva444P16Le = 51,
Gbrp8 = 52,
Gbrp16Le = 53,
Gbrap16Le = 54,
Yuva420P10Le = 55,
Yuva420P12Le = 56,
Yuva420P16Le = 57,
Gbrap8 = 58,
Ya16Le = 59,
CmykInverted = 60,
Yuv440P = 61,
Yuv440P10Le = 62,
Yuv440P12Le = 63,
Yuv440P16Le = 64,
GrayF32Le = 65,
RgbF32Le = 66,
RgbaF32Le = 67,
GbrpF32Le = 68,
GbrapF32Le = 69,
}Expand description
Video pixel format.
Variants carry stable explicit discriminants — the integer value
of PixelFormat::Yuv420P as u16 is part of the public ABI. Add new
variants only at the end with a fresh number; never reorder, renumber,
or remove. #[non_exhaustive] lets the enum grow without breaking
downstream match statements; pinned discriminants additionally let
the format round-trip through any byte-stable serialization
(config files, capability blobs, IPC, on-disk caches) without losing
meaning across crate versions, and prevent inserts in the middle of
the enum from shifting every later variant’s number (which
cargo-semver-checks rightly flags as a breaking change).
The first six variants (Yuv420P through Gray8) are the original
formats produced by the early codec crates. Everything beyond that
is additional surface handled by oxideav-pixfmt and the still-image
codecs (PNG, GIF, still-JPEG).
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Yuv420P = 0
8-bit YUV 4:2:0, planar (Y, U, V).
Yuv422P = 1
8-bit YUV 4:2:2, planar.
Yuv444P = 2
8-bit YUV 4:4:4, planar.
Rgb24 = 3
Packed 8-bit RGB, 3 bytes/pixel.
Rgba = 4
Packed 8-bit RGBA, 4 bytes/pixel.
Gray8 = 5
Packed 8-bit grayscale.
Pal8 = 6
8-bit palette indices — companion palette carried out of band.
Bgr24 = 7
Packed 8-bit BGR, 3 bytes/pixel.
Bgra = 8
Packed 8-bit BGRA, 4 bytes/pixel.
Argb = 9
Packed 8-bit ARGB, 4 bytes/pixel (alpha first).
Abgr = 10
Packed 8-bit ABGR, 4 bytes/pixel.
Rgb48Le = 11
Packed 16-bit-per-channel RGB, little-endian, 6 bytes/pixel.
Rgba64Le = 12
Packed 16-bit-per-channel RGBA, little-endian, 8 bytes/pixel.
Gray16Le = 13
16-bit little-endian grayscale.
Gray10Le = 14
10-bit grayscale in a 16-bit little-endian word.
Gray12Le = 15
12-bit grayscale in a 16-bit little-endian word.
Yuv420P10Le = 16
10-bit YUV 4:2:0 planar, little-endian 16-bit storage.
Yuv422P10Le = 17
10-bit YUV 4:2:2 planar, little-endian 16-bit storage.
Yuv444P10Le = 18
10-bit YUV 4:4:4 planar, little-endian 16-bit storage.
Yuv420P12Le = 19
12-bit YUV 4:2:0 planar, little-endian 16-bit storage.
Yuv422P12Le = 20
12-bit YUV 4:2:2 planar, little-endian 16-bit storage.
Yuv444P12Le = 21
12-bit YUV 4:4:4 planar, little-endian 16-bit storage.
YuvJ420P = 22
JPEG/full-range YUV 4:2:0 planar.
YuvJ422P = 23
JPEG/full-range YUV 4:2:2 planar.
YuvJ444P = 24
JPEG/full-range YUV 4:4:4 planar.
Nv12 = 25
YUV 4:2:0, planar Y + interleaved UV (NV12).
Nv21 = 26
YUV 4:2:0, planar Y + interleaved VU (NV21).
Ya8 = 27
Packed grayscale + alpha, 2 bytes/pixel (Y, A).
Yuva420P = 28
Yuv420P with an additional full-resolution alpha plane.
MonoBlack = 29
1 bit per pixel, packed MSB-first, 0 = black.
MonoWhite = 30
1 bit per pixel, packed MSB-first, 0 = white.
Yuyv422 = 31
Packed 4:2:2, byte order Y0 U0 Y1 V0.
Uyvy422 = 32
Packed 4:2:2, byte order U0 Y0 V0 Y1.
Cmyk = 33
Packed 8-bit CMYK, 4 bytes/pixel in byte order C, M, Y, K.
“Regular” convention: C=0 means no cyan ink (white), C=255 means
full cyan. Used by JPEG 4-component scans from non-Adobe encoders
and by many print-side image toolchains. Adobe Photoshop’s
inverted CMYK (where 0 = full ink) is the separate
CmykInverted variant.
Yuv411P = 34
8-bit YUV 4:1:1, planar (Y, U, V). Luma at full resolution; chroma horizontally subsampled by 4 (each chroma sample covers a 4×1 luma block), no vertical subsampling. Native sampling of NTSC DV-25 and a legal JPEG sampling layout (luma H=4, V=1; chroma H=V=1) emitted by some real-world JPEG corpora.
Gbrp10Le = 35
10-bit planar GBR, little-endian 16-bit storage. 3 planes ordered G, B, R; each sample uses the low 10 bits of a 16-bit word.
Gbrap10Le = 36
10-bit planar GBR + alpha, little-endian 16-bit storage. 4 planes ordered G, B, R, A; each sample uses the low 10 bits of a 16-bit word.
Gbrp12Le = 37
12-bit planar GBR, little-endian 16-bit storage. 3 planes ordered G, B, R; each sample uses the low 12 bits of a 16-bit word.
Gbrap12Le = 38
12-bit planar GBR + alpha, little-endian 16-bit storage. 4 planes ordered G, B, R, A; each sample uses the low 12 bits of a 16-bit word.
Gbrp14Le = 39
14-bit planar GBR, little-endian 16-bit storage. 3 planes ordered G, B, R; each sample uses the low 14 bits of a 16-bit word.
Gbrap14Le = 40
14-bit planar GBR + alpha, little-endian 16-bit storage. 4 planes ordered G, B, R, A; each sample uses the low 14 bits of a 16-bit word.
Yuv420P16Le = 41
16-bit YUV 4:2:0 planar, little-endian 16-bit storage. All 16 bits of each sample word are significant.
Yuv422P16Le = 42
16-bit YUV 4:2:2 planar, little-endian 16-bit storage. All 16 bits of each sample word are significant.
Yuv444P16Le = 43
16-bit YUV 4:4:4 planar, little-endian 16-bit storage. All 16 bits of each sample word are significant.
Yuva422P = 44
Yuv422P with an additional full-resolution alpha plane.
Yuva444P = 45
Yuv444P with an additional full-resolution alpha plane.
Yuva422P10Le = 46
10-bit YUV 4:2:2 planar + full-resolution alpha, little-endian 16-bit storage. 4 planes ordered Y, U, V, A; each sample uses the low 10 bits of a 16-bit word.
Yuva422P12Le = 47
12-bit YUV 4:2:2 planar + full-resolution alpha, little-endian 16-bit storage. 4 planes ordered Y, U, V, A; each sample uses the low 12 bits of a 16-bit word.
Yuva444P10Le = 48
10-bit YUV 4:4:4 planar + full-resolution alpha, little-endian 16-bit storage. 4 planes ordered Y, U, V, A; each sample uses the low 10 bits of a 16-bit word.
Yuva444P12Le = 49
12-bit YUV 4:4:4 planar + full-resolution alpha, little-endian 16-bit storage. 4 planes ordered Y, U, V, A; each sample uses the low 12 bits of a 16-bit word.
Yuva422P16Le = 50
16-bit YUV 4:2:2 planar + full-resolution alpha, little-endian 16-bit storage. 4 planes ordered Y, U, V, A; all 16 bits of each sample word are significant.
Yuva444P16Le = 51
16-bit YUV 4:4:4 planar + full-resolution alpha, little-endian 16-bit storage. 4 planes ordered Y, U, V, A; all 16 bits of each sample word are significant.
Gbrp8 = 52
8-bit planar GBR. 3 planes ordered G, B, R; one byte per sample, all 8 bits significant.
Gbrp16Le = 53
16-bit planar GBR, little-endian 16-bit storage. 3 planes ordered G, B, R; all 16 bits of each sample word are significant.
Gbrap16Le = 54
16-bit planar GBR + alpha, little-endian 16-bit storage. 4 planes ordered G, B, R, A; all 16 bits of each sample word are significant.
Yuva420P10Le = 55
10-bit YUV 4:2:0 planar + full-resolution alpha, little-endian 16-bit storage. 4 planes ordered Y, U, V, A; each sample uses the low 10 bits of a 16-bit word.
Yuva420P12Le = 56
12-bit YUV 4:2:0 planar + full-resolution alpha, little-endian 16-bit storage. 4 planes ordered Y, U, V, A; each sample uses the low 12 bits of a 16-bit word.
Yuva420P16Le = 57
16-bit YUV 4:2:0 planar + full-resolution alpha, little-endian 16-bit storage. 4 planes ordered Y, U, V, A; all 16 bits of each sample word are significant.
Gbrap8 = 58
8-bit planar GBR + alpha. 4 planes ordered G, B, R, A; one byte per sample, all 8 bits significant.
Ya16Le = 59
Packed 16-bit grayscale + alpha, little-endian, 4 bytes/pixel (Y, A). All 16 bits of each sample word are significant.
CmykInverted = 60
Packed 8-bit inverted CMYK, 4 bytes/pixel in byte order C, M,
Y, K. Inverted-ink convention: C=0 means full cyan ink, C=255
means no cyan (white) — the complement of Cmyk.
Yuv440P = 61
8-bit YUV 4:4:0, planar (Y, U, V). Chroma at full width, half height (ssx = 0, ssy = 1).
Yuv440P10Le = 62
10-bit YUV 4:4:0 planar, little-endian 16-bit storage. Each sample uses the low 10 bits of a 16-bit word.
Yuv440P12Le = 63
12-bit YUV 4:4:0 planar, little-endian 16-bit storage. Each sample uses the low 12 bits of a 16-bit word.
Yuv440P16Le = 64
16-bit YUV 4:4:0 planar, little-endian 16-bit storage. All 16 bits of each sample word are significant.
GrayF32Le = 65
Packed 32-bit float grayscale, little-endian, 4 bytes/pixel. Scene-referred linear light.
RgbF32Le = 66
Packed 32-bit float RGB, little-endian, 12 bytes/pixel in component order R, G, B. Scene-referred linear light.
RgbaF32Le = 67
Packed 32-bit float RGBA, little-endian, 16 bytes/pixel in component order R, G, B, A. Scene-referred linear light; alpha is straight (non-premultiplied), nominal range [0, 1].
GbrpF32Le = 68
32-bit float planar GBR, little-endian. 3 planes ordered G, B, R; one 4-byte word per sample. Scene-referred linear light.
GbrapF32Le = 69
32-bit float planar GBR + alpha, little-endian. 4 planes ordered G, B, R, A; one 4-byte word per sample; the alpha plane is at full resolution as plane index 3, straight (non-premultiplied), nominal range [0, 1].
Implementations§
Source§impl PixelFormat
impl PixelFormat
Sourcepub fn is_palette(&self) -> bool
pub fn is_palette(&self) -> bool
True if the format is a palette index format (Pal8).
Sourcepub fn is_float(&self) -> bool
pub fn is_float(&self) -> bool
True for the 32-bit IEEE-float variants, packed or planar. Float formats are scene-referred: samples carry linear light with no integer full-scale — 1.0 is the nominal diffuse-white anchor and values outside [0, 1] are legal.
Sourcepub fn plane_count(&self) -> usize
pub fn plane_count(&self) -> usize
Number of planes in the stored layout. Packed and palette formats
return 1; NV12/NV21 return 2; planar YUV without alpha and the
Gbrp* variants return 3; YuvA and Gbrap* variants return 4.
Sourcepub fn bits_per_pixel_approx(&self) -> u32
pub fn bits_per_pixel_approx(&self) -> u32
Rough bits-per-pixel estimate, useful for buffer sizing. Not exact for chroma-subsampled YUV — intended for worst-case preallocation rather than wire-accurate accounting.
Sourcepub fn chroma_subsampling(&self) -> Option<(u32, u32)>
pub fn chroma_subsampling(&self) -> Option<(u32, u32)>
Log2 chroma-subsampling shifts (ssx, ssy) relative to the
luma grid, for formats that carry chroma on a subsampled (or
potentially subsampled) grid. The chroma sample grid is the
luma grid right-shifted by ssx horizontally and ssy
vertically, with ceiling division for odd luma sizes (see
plane_dimensions).
| sampling | (ssx, ssy) | chroma geometry |
|---|---|---|
| 4:2:0 | (1, 1) | half width, half height |
| 4:2:2 | (1, 0) | half width, full height |
| 4:4:4 | (0, 0) | full resolution |
| 4:1:1 | (2, 0) | quarter width, full height |
| 4:4:0 | (0, 1) | full width, half height |
Returns None for formats without a distinct chroma grid
(grayscale, RGB/GBR in any layout, palette, mono, CMYK).
Packed 4:2:2 (Yuyv422/Uyvy422) and semi-planar 4:2:0
(Nv12/Nv21) report their sampling even though the chroma
samples don’t live in standalone planes.
use oxideav_core::PixelFormat;
// 4:4:0: full-width, half-height chroma.
assert_eq!(PixelFormat::Yuv440P.chroma_subsampling(), Some((0, 1)));
// 4:2:0: subsampled on both axes.
assert_eq!(PixelFormat::Yuv420P.chroma_subsampling(), Some((1, 1)));
// RGB has no chroma grid.
assert_eq!(PixelFormat::Rgba.chroma_subsampling(), None);Sourcepub fn plane_dimensions(
&self,
plane: usize,
width: u32,
height: u32,
) -> Option<(u32, u32)>
pub fn plane_dimensions( &self, plane: usize, width: u32, height: u32, ) -> Option<(u32, u32)>
Sample-grid dimensions of plane plane for a width ×
height picture, with ceiling division on subsampled axes so
odd luma sizes still cover every pixel.
Conventions:
- Plane 0 (luma / the packed plane) is always
(width, height). - Chroma planes (indices 1 and 2 of planar YUV, index 1 of the
semi-planar formats) are the luma grid right-shifted by the
chroma_subsamplingfactors. Semi-planar chroma dimensions are in chroma positions — each position stores two interleaved samples, whichplane_row_bytesaccounts for. - Alpha planes (index 3) and all planar-RGB planes are at full resolution.
- Packed, palette, and bit-packed mono formats report pixel
dimensions for their single plane; per-row byte cost comes
from
plane_row_bytes.
Returns None when plane >= plane_count().
use oxideav_core::PixelFormat;
// 4:4:0 chroma: full width, half height (odd height rounds up).
assert_eq!(
PixelFormat::Yuv440P.plane_dimensions(1, 640, 481),
Some((640, 241))
);
// Alpha plane of a deep YUVA format stays at full resolution.
assert_eq!(
PixelFormat::Yuva420P10Le.plane_dimensions(3, 7, 5),
Some((7, 5))
);
assert_eq!(PixelFormat::Rgb24.plane_dimensions(1, 8, 8), None);Sourcepub fn plane_row_bytes(&self, plane: usize, width: u32) -> Option<usize>
pub fn plane_row_bytes(&self, plane: usize, width: u32) -> Option<usize>
Tightly-packed byte count of one row of plane plane for a
picture width pixels wide — no stride padding or alignment.
Real codecs frequently over-allocate rows for alignment; this
is the minimum a row occupies.
Returns None when plane >= plane_count() or the byte count
overflows usize.
Sourcepub fn plane_size_bytes(
&self,
plane: usize,
width: u32,
height: u32,
) -> Option<usize>
pub fn plane_size_bytes( &self, plane: usize, width: u32, height: u32, ) -> Option<usize>
Tightly-packed byte size of plane plane for a width ×
height picture:
plane_row_bytes × the plane’s row
count from plane_dimensions.
Returns None when plane >= plane_count() or the size
overflows usize.
Sourcepub fn frame_size_bytes(&self, width: u32, height: u32) -> Option<usize>
pub fn frame_size_bytes(&self, width: u32, height: u32) -> Option<usize>
Tightly-packed byte size of a whole width × height frame in
this format — the sum of
plane_size_bytes over every plane,
with no stride padding or inter-plane alignment. Out-of-band
side data (the Pal8 palette table, significant-bits records)
is not included.
Returns None on usize overflow.
use oxideav_core::PixelFormat;
// 4:2:0 at 4×4: 16 luma + 4 + 4 chroma bytes.
assert_eq!(PixelFormat::Yuv420P.frame_size_bytes(4, 4), Some(24));
// 4:4:0 at 6×5: 30 luma + 2 × (6 × 3) chroma bytes.
assert_eq!(PixelFormat::Yuv440P.frame_size_bytes(6, 5), Some(66));
// Packed float RGBA: 16 bytes per pixel.
assert_eq!(PixelFormat::RgbaF32Le.frame_size_bytes(3, 3), Some(144));Trait Implementations§
Source§impl Clone for PixelFormat
impl Clone for PixelFormat
Source§fn clone(&self) -> PixelFormat
fn clone(&self) -> PixelFormat
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more