1 | #[repr (C)] |
2 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
3 | #[cfg_attr (feature = "defmt-03" , derive(defmt::Format))] |
4 | #[derive (Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)] |
5 | /// A `Grayscale` pixel (rgb crate v0.8) |
6 | #[allow (non_camel_case_types)] |
7 | pub struct Gray_v08<T>( |
8 | /// Grayscale Component. This field will be renamed to `v`. |
9 | pub T, |
10 | ); |
11 | |
12 | impl<T: Copy> Gray_v08<T> { |
13 | /// Reads the `.0` field |
14 | /// |
15 | /// This function isn't necessary, but it is forwards-compatible with the next major version of the RGB crate. |
16 | pub fn value(self) -> T { |
17 | self.0 |
18 | } |
19 | |
20 | /// Exposes the `.0` field for writing |
21 | /// |
22 | /// This function isn't necessary, but it is forwards-compatible with the next major version of the RGB crate. |
23 | pub fn value_mut(&mut self) -> &mut T { |
24 | &mut self.0 |
25 | } |
26 | |
27 | /// Add alpha component to this pixel |
28 | #[allow (deprecated)] |
29 | pub fn with_alpha(self, add_alpha_value: T) -> crate::formats::gray_alpha::GrayAlpha_v08<T> { |
30 | crate::formats::gray_alpha::GrayAlpha_v08(self.0, add_alpha_value) |
31 | } |
32 | } |
33 | |
34 | #[cfg (feature = "unstable-experimental" )] |
35 | /// A `Grayscale` pixel (rgb crate v0.9) |
36 | /// |
37 | /// This is the new gray pixel type as opposed to the legacy gray type |
38 | /// (`rgb::Gray`) which is kept for backwards-compatibility. |
39 | /// |
40 | /// # Examples |
41 | /// |
42 | /// ``` |
43 | /// use rgb::Gray; |
44 | /// |
45 | /// let pixel: Gray<u8> = Gray { v: 0 }; |
46 | /// ``` |
47 | #[allow (non_camel_case_types)] |
48 | #[repr (C)] |
49 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
50 | #[cfg_attr (feature = "defmt-03" , derive(defmt::Format))] |
51 | #[derive (Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)] |
52 | #[doc (alias = "Luma" )] |
53 | pub struct Gray_v09<T> { |
54 | /// Grayscale Component |
55 | pub v: T, |
56 | } |
57 | |
58 | #[cfg (feature = "unstable-experimental" )] |
59 | impl<T> core::ops::Deref for Gray_v08<T> { |
60 | type Target = Gray_v09<T>; |
61 | |
62 | fn deref(&self) -> &Gray_v09<T> { |
63 | unsafe { |
64 | &*(self as *const Self as *const Gray_v09::<T>) |
65 | } |
66 | } |
67 | } |
68 | |
69 | #[cfg (feature = "unstable-experimental" )] |
70 | impl<T: Copy> Gray_v09<T> { |
71 | /// Reads the `.v` field |
72 | /// |
73 | /// This function isn't necessary, but it is forwards-compatible with the next major version of the RGB crate. |
74 | pub fn value(self) -> T { |
75 | self.v |
76 | } |
77 | |
78 | /// Exposes the `.v` field for writing |
79 | /// |
80 | /// This function isn't necessary, but it is forwards-compatible with the next major version of the RGB crate. |
81 | pub fn value_mut(&mut self) -> &mut T { |
82 | &mut self.v |
83 | } |
84 | |
85 | /// Add alpha component to this pixel |
86 | pub fn with_alpha(self, add_alpha_value: T) -> crate::formats::gray_a::GrayA<T> { |
87 | crate::formats::gray_a::GrayA { v: self.v, a: add_alpha_value } |
88 | } |
89 | } |
90 | |
91 | #[test ] |
92 | #[cfg (feature = "unstable-experimental" )] |
93 | fn swizzle() { |
94 | let g = Gray_v08(10u8); |
95 | assert_eq!(10, g.v); |
96 | assert_eq!(10, g.0); |
97 | } |
98 | |