strawberry_x264/colorspace.rs
1use x264::*;
2
3#[derive(Debug, Hash, Eq, PartialEq, Copy, Clone)]
4#[repr(u32)]
5/// The colorspace of an image, which details how its colors are represented.
6pub enum Colorspace {
7 /// A Y plane followed by 2x2 subsampled U and V planes.
8 I420 = X264_CSP_I420,
9 /// A Y plane followed by 2x2 subsampled V and U planes.
10 YV12 = X264_CSP_YV12,
11 /// A Y plane followed by a packed 2x2 subsampled UV plane.
12 NV12 = X264_CSP_NV12,
13 /// A Y plane followed by a packed 2x2 subsampled VU plane.
14 NV21 = X264_CSP_NV21,
15 /// A Y plane followed by 2x1 subsampled U and V planes.
16 I422 = X264_CSP_I422,
17 /// A Y plane followed by 2x1 subsampled V and U planes.
18 YV16 = X264_CSP_YV16,
19 /// A Y plane followed by a packed 2x1 subsampled UV plane.
20 NV16 = X264_CSP_NV16,
21 /// A single plane whose bytes follow the pattern YUYV pattern, which means
22 /// the U and V parts are 2x1 subsampled.
23 #[cfg(yuyv)]
24 YUYV = X264_CSP_YUYV,
25 /// A single plane whose bytes follow the pattern UYVY pattern, which means
26 /// the U and V parts are 2x1 subsampled.
27 #[cfg(yuyv)]
28 UYVY = X264_CSP_UYVY,
29 /// A packed 32-bit UYVY plane with 10-bit components, and 2 padding bits.
30 V210 = X264_CSP_V210,
31 /// A Y plane followed by U and V planes.
32 I444 = X264_CSP_I444,
33 /// A Y plane followed by V and U planes.
34 YV24 = X264_CSP_YV24,
35 /// A packed 24-bit BGR plane.
36 BGR = X264_CSP_BGR,
37 /// A packed 32-bit BGR plane, where the latter byte is padding.
38 BGRA = X264_CSP_BGRA,
39 /// A packed 24-bit RGB plane.
40 RGB = X264_CSP_RGB,
41}
42
43#[derive(Debug, Hash, Eq, PartialEq, Copy, Clone)]
44/// The image's colorspace plus some extra encoding options.
45pub struct Encoding {
46 raw: i32,
47}
48
49impl Encoding {
50 /// Add an encoding option.
51 pub fn add_modifier(mut self, modifier: Modifier) -> Self {
52 self.raw |= modifier as i32;
53 self
54 }
55
56 /// Remove an encoding option.
57 pub fn remove_modifier(mut self, modifier: Modifier) -> Self {
58 self.raw &= !(modifier as i32);
59 self
60 }
61
62 /// Check if an encoding option has been set.
63 pub fn has_modifier(self, modifier: Modifier) -> bool {
64 self.raw & modifier as i32 != 0
65 }
66
67 /// Gets the colorspace of the encoding.
68 pub fn colorspace(self) -> Colorspace {
69 use core::mem;
70 unsafe { mem::transmute(self.raw as u32 % X264_CSP_MAX) }
71 }
72
73 #[doc(hidden)]
74 pub fn into_raw(self) -> i32 {
75 self.raw
76 }
77
78 #[doc(hidden)]
79 pub unsafe fn from_raw(raw: i32) -> Self {
80 Self { raw }
81 }
82}
83
84impl From<Colorspace> for Encoding {
85 fn from(csp: Colorspace) -> Self {
86 Self { raw: csp as i32 }
87 }
88}
89
90#[repr(i32)]
91/// Some extra encoding options.
92pub enum Modifier {
93 /// Doubles the pixel depth, from 8 to 16 bits per pixel.
94 HighDepth = X264_CSP_HIGH_DEPTH as i32,
95 /// Vertically flips the image.
96 VerticalFlip = X264_CSP_VFLIP as i32,
97}