| 1 | |
| 2 | use crate::formats::gray::Gray_v08; |
| 3 | use crate::{Abgr, Argb, Bgr, Bgra, Grb, Rgb, Rgba, alt::GrayAlpha}; |
| 4 | |
| 5 | #[cfg(feature = "unstable-experimental")] |
| 6 | use crate::GrayA; |
| 7 | #[cfg(feature = "unstable-experimental")] |
| 8 | use crate::formats::gray::Gray_v09; |
| 9 | |
| 10 | macro_rules! tuple_conversion { |
| 11 | ($name:ident, 1, [$($bit:tt:$num:tt),*]) => { |
| 12 | impl<R, S> From<$name<R>> for (S,) where R: Into<S> { |
| 13 | #[allow(deprecated)] |
| 14 | fn from(value: $name<R>) -> Self { |
| 15 | ($(value.$bit.into()),*,) |
| 16 | } |
| 17 | } |
| 18 | }; |
| 19 | ($name:ident, 2, [$($bit:tt:$num:tt),*]) => { |
| 20 | impl<R, S> From<$name<R>> for (S, S) where R: Into<S> { |
| 21 | #[allow(deprecated)] |
| 22 | fn from(value: $name<R>) -> Self { |
| 23 | ($(value.$bit.into()),*) |
| 24 | } |
| 25 | } |
| 26 | impl<R, S> From<(R, R)> for $name<S> where R: Into<S> { |
| 27 | #[allow(deprecated)] |
| 28 | fn from(value: (R, R)) -> Self { |
| 29 | Self{$($bit: value.$num.into()),*} |
| 30 | } |
| 31 | } |
| 32 | }; |
| 33 | ($name:ident, 3, [$($bit:tt:$num:tt),*]) => { |
| 34 | impl<R, S> From<$name<R>> for (S, S, S) where R: Into<S> { |
| 35 | fn from(value: $name<R>) -> Self { |
| 36 | ($(value.$bit.into()),*) |
| 37 | } |
| 38 | } |
| 39 | impl<R, S> From<(R, R, R)> for $name<S> where R: Into<S> { |
| 40 | fn from(value: (R, R, R)) -> Self { |
| 41 | Self{$($bit: value.$num.into()),*} |
| 42 | } |
| 43 | } |
| 44 | }; |
| 45 | ($name:ident, 4, [$($bit:tt:$num:tt),*]) => { |
| 46 | impl<R, S> From<$name<R>> for (S, S, S, S) where R: Into<S> { |
| 47 | fn from(value: $name<R>) -> Self { |
| 48 | ($(value.$bit.into()),*) |
| 49 | } |
| 50 | } |
| 51 | impl<R, S> From<(R, R, R, R)> for $name<S> where R: Into<S> { |
| 52 | fn from(value: (R, R, R, R)) -> Self { |
| 53 | Self{$($bit: value.$num.into()),*} |
| 54 | } |
| 55 | } |
| 56 | }; |
| 57 | } |
| 58 | |
| 59 | |
| 60 | tuple_conversion!(Rgb, 3, [r:0, g:1, b:2]); |
| 61 | tuple_conversion!(Bgr, 3, [b:0, g:1, r:2]); |
| 62 | tuple_conversion!(Grb, 3, [g:0, r:1, b:2]); |
| 63 | #[cfg(feature = "unstable-experimental")] |
| 64 | tuple_conversion!(Gray_v09, 1, [v:0]); |
| 65 | |
| 66 | |
| 67 | tuple_conversion!(Rgba, 4, [r:0, g:1, b:2, a:3]); |
| 68 | tuple_conversion!(Argb, 4, [a:0, r:1, g:2, b:3]); |
| 69 | tuple_conversion!(Bgra, 4, [b:0, g:1, r:2, a:3]); |
| 70 | tuple_conversion!(Abgr, 4, [a:0, b:1, g:2, r:3]); |
| 71 | #[cfg(feature = "unstable-experimental")] |
| 72 | tuple_conversion!(GrayA, 2, [v:0, a:1]); |
| 73 | |
| 74 | tuple_conversion!(Gray_v08, 1, [0:0]); |
| 75 | tuple_conversion!(GrayAlpha, 2, [0:0, 1:1]); |
| 76 |