1 | use crate::{Abgr, Argb, Bgr, Bgra, Grb, Rgb, Rgba}; |
2 | use crate::formats::gray_a::GrayA; |
3 | use crate::formats::gray::Gray_v08; |
4 | #[cfg (feature = "unstable-experimental" )] |
5 | use crate::formats::gray::Gray_v09; |
6 | use crate::formats::gray_alpha::GrayAlpha_v08; |
7 | |
8 | macro_rules! inherent_impls { |
9 | ($name:ident, $new_fn:ident, [$($field:tt $var:ident),*]) => { |
10 | impl<T: Copy> $name<T> { |
11 | #[doc=concat!("Creates a new [`" , stringify!($name), "`] pixel type from its components." )] |
12 | /// |
13 | /// Alternatively, you can use struct literal syntax to |
14 | /// create the new pixel type: |
15 | ///```not_rust |
16 | #[doc=concat!("use rgb::" , stringify!($name), ";" )] |
17 | /// |
18 | #[doc=concat!("let pixel = " , stringify!($name), " {" , stringify!($($field: $var),*), "};" )] |
19 | ///``` |
20 | pub const fn $new_fn($($var: T),*) -> Self { |
21 | Self {$($field: $var),*} |
22 | } |
23 | } |
24 | } |
25 | } |
26 | |
27 | inherent_impls!(Rgb, new, [r red, g green, b blue]); |
28 | inherent_impls!(Bgr, new_bgr, [b blue, g green, r red]); |
29 | inherent_impls!(Grb, new_grb, [g green, r red, b blue]); |
30 | |
31 | inherent_impls!(Gray_v08, new, [0 value]); |
32 | #[cfg (feature = "unstable-experimental" )] |
33 | inherent_impls!(Gray_v09, new, [v value]); |
34 | |
35 | inherent_impls!(Rgba, new, [r red, g green, b blue, a alpha]); |
36 | inherent_impls!(Argb, new_argb, [a alpha, r red, g green, b blue]); |
37 | inherent_impls!(Bgra, new_bgra, [b blue, g green, r red, a alpha]); |
38 | inherent_impls!(Abgr, new_abgr, [a alpha, b blue, g green, r red]); |
39 | inherent_impls!(GrayA, new, [v value, a alpha]); |
40 | |
41 | inherent_impls!(GrayAlpha_v08, new, [0 value, 1 alpha]); |
42 | |