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