Debian Codegraph @

src/legacy/internal/rgb.rs

raw symbols SCIP
1 #[allow(deprecated)]
2 use superrust-analyzer cargo rgb 0.8.53 legacy/internal/::pixelrust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/::ComponentSlicerust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ComponentSlice#;
3 use superrust-analyzer cargo rgb 0.8.53 legacy/internal/::pixelrust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/::{ComponentMaprust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ComponentMap#, ColorComponentMaprust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ColorComponentMap#};
4 #[cfg(feature = "as-bytes")]
5 use superrust-analyzer cargo rgb 0.8.53 legacy/internal/::pixelrust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/::ComponentBytesrust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ComponentBytes#;
6 use craterust-analyzer cargo rgb 0.8.53 crate/::altrust-analyzer cargo rgb 0.8.53 legacy/alt/::GRBrust-analyzer cargo rgb 0.8.53 formats/grb/Grb#;
7 use craterust-analyzer cargo rgb 0.8.53 crate/::altrust-analyzer cargo rgb 0.8.53 legacy/alt/::{BGRrust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#, BGRArust-analyzer cargo rgb 0.8.53 formats/bgra/Bgra#};
8 use craterust-analyzer cargo rgb 0.8.53 crate/::{RGBrust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#, RGBArust-analyzer cargo rgb 0.8.53 formats/rgba/Rgba#};
9 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/;
10
11 impl<T> BGRrust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#<T> {
12 /// Convenience function for creating a new pixel
13 /// Warning: The order of arguments is R,G,B
14 #[deprecated(note = "This function has a misleading order of arguments. Use BGR{} literal instead")]
15 pub const fn newrust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl#[`BGR<T>`]new().(r: T, g: T, b: T) -> Selfrust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl#[`BGR<T>`] {
16 Selfrust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl#[`BGR<T>`] { brust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#b., grust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#g., rrust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#r. }
17 }
18 }
19
20 macro_rules! impl_rgbrust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl_rgb! {
21 ($RGB:ident) => {
22 impl<T: Clone> $RGB<T> {
23 /// Iterate over color components (R, G, and B)
24 #[inline(always)]
25 pub fn iter(&self) -> core::iter::Cloned<core::slice::Iter<'_, T>> {
26 #[allow(deprecated)]
27 ComponentSlice::as_slice(self).iter().cloned()
28 }
29 }
30
31 impl<T: Copy, B> ComponentMap<$RGB<B>, T, B> for $RGB<T> {
32 #[inline(always)]
33 fn map<F>(&self, mut f: F) -> $RGB<B>
34 where F: FnMut(T) -> B {
35 $RGB {
36 r:f(self.r),
37 g:f(self.g),
38 b:f(self.b),
39 }
40 }
41 }
42
43 impl<T: Copy, B> ColorComponentMap<$RGB<B>, T, B> for $RGB<T> {
44 #[inline(always)]
45 fn map_colors<F>(&self, mut f: F) -> $RGB<B>
46 where F: FnMut(T) -> B {
47 $RGB {
48 r:f(self.r),
49 g:f(self.g),
50 b:f(self.b),
51 }
52 }
53 }
54
55 #[allow(deprecated)]
56 impl<T> ComponentSlice<T> for $RGB<T> {
57 #[inline(always)]
58 fn as_slice(&self) -> &[T] {
59 unsafe {
60 core::slice::from_raw_parts(self as *const Self as *const T, 3)
61 }
62 }
63
64 #[inline(always)]
65 fn as_mut_slice(&mut self) -> &mut [T] {
66 unsafe {
67 core::slice::from_raw_parts_mut(self as *mut Self as *mut T, 3)
68 }
69 }
70 }
71
72 #[allow(deprecated)]
73 impl<T> ComponentSlice<T> for [$RGB<T>] {
74 #[inline]
75 fn as_slice(&self) -> &[T] {
76 unsafe {
77 core::slice::from_raw_parts(self.as_ptr() as *const _, self.len() * 3)
78 }
79 }
80
81 #[inline]
82 fn as_mut_slice(&mut self) -> &mut [T] {
83 unsafe {
84 core::slice::from_raw_parts_mut(self.as_mut_ptr() as *mut _, self.len() * 3)
85 }
86 }
87 }
88
89 #[cfg(feature = "as-bytes")]
90 impl<T: crate::Pod> ComponentBytes<T> for [$RGB<T>] {}
91 };
92 }
93
94 macro_rules! impl_rgb_to_alpharust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl_rgb_to_alpha! {
95 ($RGB:ident, $RGBA:ident) => {
96 impl<T: Clone> $RGB<T> {
97 /// Convenience function for converting to RGBA
98 #[doc(hidden)]
99 #[deprecated(note = "use .with_alpha(a) instead; this will become a getter in the future")]
100 pub fn alpha(&self, a: T) -> $RGBA<T> {
101 self.with_alpha(a)
102 }
103
104 /// Convenience function for converting to RGBA
105 #[inline(always)]
106 #[doc(alias = "alpha")]
107 pub fn with_alpha(&self, a: T) -> $RGBA<T> {
108 $RGBA {
109 r: self.r.clone(),
110 g: self.g.clone(),
111 b: self.b.clone(),
112 a,
113 }
114 }
115
116 /// Convenience function for converting to RGBA with alpha channel of a different type than type of the pixels
117 #[inline(never)]
118 #[deprecated(note = "use .with_alpha(a) instead")]
119 pub fn new_alpha<A>(&self, a: A) -> $RGBA<T, A> {
120 $RGBA {
121 r: self.r.clone(),
122 g: self.g.clone(),
123 b: self.b.clone(),
124 a,
125 }
126 }
127 }
128 };
129 }
130
131 impl<T> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#<T> for RGBrust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#<T> {
132 /// Takes exactly 3 elements from the iterator and creates a new instance.
133 /// Panics if there are fewer elements in the iterator.
134 #[inline(always)]
135 fn from_iterrust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl#[`RGB<T>`][`FromIterator<T>`]from_iter().<I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = T>>(into_iter: I) -> Selfrust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl#[`RGB<T>`][`FromIterator<T>`] {
136 let mut iter = into_iter.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().();
137 Selfrust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl#[`RGB<T>`][`FromIterator<T>`] {
138 rrust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#r.: iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
139 grust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#g.: iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
140 brust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#b.: iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
141 }
142 }
143 }
144
145 impl_rgbrust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl_rgb!! {RGBrust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#}
146 impl_rgb_to_alpharust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl_rgb_to_alpha!! {RGBrust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#, RGBArust-analyzer cargo rgb 0.8.53 formats/rgba/Rgba#}
147 impl_rgbrust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl_rgb!! {BGRrust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#}
148 impl_rgb_to_alpharust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl_rgb_to_alpha!! {BGRrust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#, BGRArust-analyzer cargo rgb 0.8.53 formats/bgra/Bgra#}
149 impl_rgbrust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl_rgb!! {GRBrust-analyzer cargo rgb 0.8.53 formats/grb/Grb#}
150
151 impl<T: fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for RGBrust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#<T> {
152 fn fmtrust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl#[`RGB<T>`][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
153 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "rgb({},{},{})", self.rrust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#r., self.grust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#g., self.brust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#b.)
154 }
155 }
156
157 impl<T: fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::UpperHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/UpperHex#> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::UpperHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/UpperHex# for RGBrust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#<T> {
158 fn fmtrust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl#[`RGB<T>`][UpperHex]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
159 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "RGB {{ #{:02X}{:02X}{:02X} }}", self.rrust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#r., self.grust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#g., self.brust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#b.)
160 }
161 }
162
163 impl<T: fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::LowerHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/LowerHex#> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::LowerHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/LowerHex# for RGBrust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#<T> {
164 fn fmtrust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl#[`RGB<T>`][LowerHex]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
165 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "RGB {{ #{:02x}{:02x}{:02x} }}", self.rrust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#r., self.grust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#g., self.brust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#b.)
166 }
167 }
168
169 impl<T: fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for BGRrust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#<T> {
170 fn fmtrust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl#[`BGR<T>`][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
171 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "bgr({},{},{})", self.brust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#b., self.grust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#g., self.rrust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#r.)
172 }
173 }
174
175 impl<T: fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::UpperHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/UpperHex#> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::UpperHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/UpperHex# for BGRrust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#<T> {
176 fn fmtrust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl#[`BGR<T>`][UpperHex]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
177 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "BGR {{ #{:02X}{:02X}{:02X} }}", self.brust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#b., self.grust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#g., self.rrust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#r.)
178 }
179 }
180
181 impl<T: fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::LowerHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/LowerHex#> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::LowerHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/LowerHex# for BGRrust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#<T> {
182 fn fmtrust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/impl#[`BGR<T>`][LowerHex]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
183 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "BGR {{ #{:02x}{:02x}{:02x} }}", self.brust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#b., self.grust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#g., self.rrust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#r.)
184 }
185 }