| 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 |
#[allow(deprecated)] |
| 21 |
pub const fn $new_fn($($var: T),*) -> Self { |
| 22 |
Self {$($field: $var),*} |
| 23 |
} |
| 24 |
} |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
inherent_impls!(Rgb, new, [r red, g green, b blue]); |
| 29 |
inherent_impls!(Bgr, new_bgr, [b blue, g green, r red]); |
| 30 |
inherent_impls!(Grb, new_grb, [g green, r red, b blue]); |
| 31 |
|
| 32 |
inherent_impls!(Gray_v08, new, [0 value]); |
| 33 |
#[cfg(feature = "unstable-experimental")] |
| 34 |
inherent_impls!(Gray_v09, new, [v value]); |
| 35 |
|
| 36 |
inherent_impls!(Rgba, new, [r red, g green, b blue, a alpha]); |
| 37 |
inherent_impls!(Argb, new_argb, [a alpha, r red, g green, b blue]); |
| 38 |
inherent_impls!(Bgra, new_bgra, [b blue, g green, r red, a alpha]); |
| 39 |
inherent_impls!(Abgr, new_abgr, [a alpha, b blue, g green, r red]); |
| 40 |
inherent_impls!(GrayA, new, [v value, a alpha]); |
| 41 |
|
| 42 |
inherent_impls!(GrayAlpha_v08, new, [0 value, 1 alpha]); |