/src/image/src/images/buffer.rs
Line | Count | Source (jump to first uncovered line) |
1 | | //! Contains the generic `ImageBuffer` struct. |
2 | | use num_traits::Zero; |
3 | | use std::fmt; |
4 | | use std::marker::PhantomData; |
5 | | use std::ops::{Deref, DerefMut, Index, IndexMut, Range}; |
6 | | use std::path::Path; |
7 | | use std::slice::{ChunksExact, ChunksExactMut}; |
8 | | |
9 | | use crate::color::{FromColor, Luma, LumaA, Rgb, Rgba}; |
10 | | use crate::error::ImageResult; |
11 | | use crate::flat::{FlatSamples, SampleLayout}; |
12 | | use crate::math::Rect; |
13 | | use crate::traits::{EncodableLayout, Pixel, PixelWithColorType}; |
14 | | use crate::utils::expand_packed; |
15 | | use crate::{save_buffer, save_buffer_with_format, write_buffer_with_format}; |
16 | | use crate::{DynamicImage, GenericImage, GenericImageView, ImageEncoder, ImageFormat}; |
17 | | |
18 | | /// Iterate over pixel refs. |
19 | | pub struct Pixels<'a, P: Pixel + 'a> |
20 | | where |
21 | | P::Subpixel: 'a, |
22 | | { |
23 | | chunks: ChunksExact<'a, P::Subpixel>, |
24 | | } |
25 | | |
26 | | impl<'a, P: Pixel + 'a> Iterator for Pixels<'a, P> |
27 | | where |
28 | | P::Subpixel: 'a, |
29 | | { |
30 | | type Item = &'a P; |
31 | | |
32 | | #[inline(always)] |
33 | 0 | fn next(&mut self) -> Option<&'a P> { |
34 | 0 | self.chunks.next().map(|v| <P as Pixel>::from_slice(v)) Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Rgb<f32>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Rgb<u8>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Rgb<u16>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Luma<f32>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Luma<u8>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Luma<u16>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Rgba<f32>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Rgba<u16>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::Pixels<image::color::LumaA<f32>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::Pixels<image::color::LumaA<u8>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::Pixels<image::color::LumaA<u16>> as core::iter::traits::iterator::Iterator>::next::{closure#0} |
35 | 0 | } Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Rgb<f32>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Rgb<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Rgb<u16>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Luma<f32>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Luma<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Luma<u16>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Rgba<f32>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Rgba<u16>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::Pixels<image::color::LumaA<f32>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::Pixels<image::color::LumaA<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::Pixels<image::color::LumaA<u16>> as core::iter::traits::iterator::Iterator>::next |
36 | | |
37 | | #[inline(always)] |
38 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
39 | 0 | let len = self.len(); |
40 | 0 | (len, Some(len)) |
41 | 0 | } |
42 | | } |
43 | | |
44 | | impl<'a, P: Pixel + 'a> ExactSizeIterator for Pixels<'a, P> |
45 | | where |
46 | | P::Subpixel: 'a, |
47 | | { |
48 | 0 | fn len(&self) -> usize { |
49 | 0 | self.chunks.len() |
50 | 0 | } Unexecuted instantiation: <image::images::buffer::Pixels<_> as core::iter::traits::exact_size::ExactSizeIterator>::len Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Rgb<u8>> as core::iter::traits::exact_size::ExactSizeIterator>::len Unexecuted instantiation: <image::images::buffer::Pixels<image::color::Rgba<u8>> as core::iter::traits::exact_size::ExactSizeIterator>::len |
51 | | } |
52 | | |
53 | | impl<'a, P: Pixel + 'a> DoubleEndedIterator for Pixels<'a, P> |
54 | | where |
55 | | P::Subpixel: 'a, |
56 | | { |
57 | | #[inline(always)] |
58 | 0 | fn next_back(&mut self) -> Option<&'a P> { |
59 | 0 | self.chunks.next_back().map(|v| <P as Pixel>::from_slice(v)) |
60 | 0 | } |
61 | | } |
62 | | |
63 | | impl<P: Pixel> Clone for Pixels<'_, P> { |
64 | 0 | fn clone(&self) -> Self { |
65 | 0 | Pixels { |
66 | 0 | chunks: self.chunks.clone(), |
67 | 0 | } |
68 | 0 | } |
69 | | } |
70 | | |
71 | | impl<P: Pixel> fmt::Debug for Pixels<'_, P> |
72 | | where |
73 | | P::Subpixel: fmt::Debug, |
74 | | { |
75 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
76 | 0 | f.debug_struct("Pixels") |
77 | 0 | .field("chunks", &self.chunks) |
78 | 0 | .finish() |
79 | 0 | } |
80 | | } |
81 | | |
82 | | /// Iterate over mutable pixel refs. |
83 | | pub struct PixelsMut<'a, P: Pixel + 'a> |
84 | | where |
85 | | P::Subpixel: 'a, |
86 | | { |
87 | | chunks: ChunksExactMut<'a, P::Subpixel>, |
88 | | } |
89 | | |
90 | | impl<'a, P: Pixel + 'a> Iterator for PixelsMut<'a, P> |
91 | | where |
92 | | P::Subpixel: 'a, |
93 | | { |
94 | | type Item = &'a mut P; |
95 | | |
96 | | #[inline(always)] |
97 | 3.13G | fn next(&mut self) -> Option<&'a mut P> { |
98 | 3.13G | self.chunks.next().map(|v| <P as Pixel>::from_slice_mut(v)) Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgb<f32>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgb<u8>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgb<u16>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Luma<f32>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Luma<u8>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Luma<u16>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgba<f32>> as core::iter::traits::iterator::Iterator>::next::{closure#0} <image::images::buffer::PixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Line | Count | Source | 98 | 3.13G | self.chunks.next().map(|v| <P as Pixel>::from_slice_mut(v)) |
Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgba<u16>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::LumaA<f32>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::LumaA<u8>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::LumaA<u16>> as core::iter::traits::iterator::Iterator>::next::{closure#0} |
99 | 3.13G | } Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgb<f32>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgb<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgb<u16>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Luma<f32>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Luma<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Luma<u16>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgba<f32>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgba<u16>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::LumaA<f32>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::LumaA<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::LumaA<u16>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next <image::images::buffer::PixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Line | Count | Source | 97 | 3.13G | fn next(&mut self) -> Option<&'a mut P> { | 98 | 3.13G | self.chunks.next().map(|v| <P as Pixel>::from_slice_mut(v)) | 99 | 3.13G | } |
Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::PixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next <image::images::buffer::PixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Line | Count | Source | 97 | 2.63M | fn next(&mut self) -> Option<&'a mut P> { | 98 | 2.63M | self.chunks.next().map(|v| <P as Pixel>::from_slice_mut(v)) | 99 | 2.63M | } |
|
100 | | |
101 | | #[inline(always)] |
102 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
103 | 0 | let len = self.len(); |
104 | 0 | (len, Some(len)) |
105 | 0 | } |
106 | | } |
107 | | |
108 | | impl<'a, P: Pixel + 'a> ExactSizeIterator for PixelsMut<'a, P> |
109 | | where |
110 | | P::Subpixel: 'a, |
111 | | { |
112 | 0 | fn len(&self) -> usize { |
113 | 0 | self.chunks.len() |
114 | 0 | } |
115 | | } |
116 | | |
117 | | impl<'a, P: Pixel + 'a> DoubleEndedIterator for PixelsMut<'a, P> |
118 | | where |
119 | | P::Subpixel: 'a, |
120 | | { |
121 | | #[inline(always)] |
122 | 0 | fn next_back(&mut self) -> Option<&'a mut P> { |
123 | 0 | self.chunks |
124 | 0 | .next_back() |
125 | 0 | .map(|v| <P as Pixel>::from_slice_mut(v)) |
126 | 0 | } |
127 | | } |
128 | | |
129 | | impl<P: Pixel> fmt::Debug for PixelsMut<'_, P> |
130 | | where |
131 | | P::Subpixel: fmt::Debug, |
132 | | { |
133 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
134 | 0 | f.debug_struct("PixelsMut") |
135 | 0 | .field("chunks", &self.chunks) |
136 | 0 | .finish() |
137 | 0 | } |
138 | | } |
139 | | |
140 | | /// Iterate over rows of an image |
141 | | /// |
142 | | /// This iterator is created with [`ImageBuffer::rows`]. See its document for details. |
143 | | /// |
144 | | /// [`ImageBuffer::rows`]: ../struct.ImageBuffer.html#method.rows |
145 | | pub struct Rows<'a, P: Pixel + 'a> |
146 | | where |
147 | | <P as Pixel>::Subpixel: 'a, |
148 | | { |
149 | | pixels: ChunksExact<'a, P::Subpixel>, |
150 | | } |
151 | | |
152 | | impl<'a, P: Pixel + 'a> Rows<'a, P> { |
153 | | /// Construct the iterator from image pixels. This is not public since it has a (hidden) panic |
154 | | /// condition. The `pixels` slice must be large enough so that all pixels are addressable. |
155 | 0 | fn with_image(pixels: &'a [P::Subpixel], width: u32, height: u32) -> Self { |
156 | 0 | let row_len = (width as usize) * usize::from(<P as Pixel>::CHANNEL_COUNT); |
157 | 0 | if row_len == 0 { |
158 | 0 | Rows { |
159 | 0 | pixels: [].chunks_exact(1), |
160 | 0 | } |
161 | | } else { |
162 | 0 | let pixels = pixels |
163 | 0 | .get(..row_len * height as usize) |
164 | 0 | .expect("Pixel buffer has too few subpixels"); |
165 | 0 | // Rows are physically present. In particular, height is smaller than `usize::MAX` as |
166 | 0 | // all subpixels can be indexed. |
167 | 0 | Rows { |
168 | 0 | pixels: pixels.chunks_exact(row_len), |
169 | 0 | } |
170 | | } |
171 | 0 | } |
172 | | } |
173 | | |
174 | | impl<'a, P: Pixel + 'a> Iterator for Rows<'a, P> |
175 | | where |
176 | | P::Subpixel: 'a, |
177 | | { |
178 | | type Item = Pixels<'a, P>; |
179 | | |
180 | | #[inline(always)] |
181 | 0 | fn next(&mut self) -> Option<Pixels<'a, P>> { |
182 | 0 | let row = self.pixels.next()?; |
183 | 0 | Some(Pixels { |
184 | 0 | // Note: this is not reached when CHANNEL_COUNT is 0. |
185 | 0 | chunks: row.chunks_exact(<P as Pixel>::CHANNEL_COUNT as usize), |
186 | 0 | }) |
187 | 0 | } |
188 | | |
189 | | #[inline(always)] |
190 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
191 | 0 | let len = self.len(); |
192 | 0 | (len, Some(len)) |
193 | 0 | } |
194 | | } |
195 | | |
196 | | impl<'a, P: Pixel + 'a> ExactSizeIterator for Rows<'a, P> |
197 | | where |
198 | | P::Subpixel: 'a, |
199 | | { |
200 | 0 | fn len(&self) -> usize { |
201 | 0 | self.pixels.len() |
202 | 0 | } |
203 | | } |
204 | | |
205 | | impl<'a, P: Pixel + 'a> DoubleEndedIterator for Rows<'a, P> |
206 | | where |
207 | | P::Subpixel: 'a, |
208 | | { |
209 | | #[inline(always)] |
210 | 0 | fn next_back(&mut self) -> Option<Pixels<'a, P>> { |
211 | 0 | let row = self.pixels.next_back()?; |
212 | 0 | Some(Pixels { |
213 | 0 | // Note: this is not reached when CHANNEL_COUNT is 0. |
214 | 0 | chunks: row.chunks_exact(<P as Pixel>::CHANNEL_COUNT as usize), |
215 | 0 | }) |
216 | 0 | } |
217 | | } |
218 | | |
219 | | impl<P: Pixel> Clone for Rows<'_, P> { |
220 | 0 | fn clone(&self) -> Self { |
221 | 0 | Rows { |
222 | 0 | pixels: self.pixels.clone(), |
223 | 0 | } |
224 | 0 | } |
225 | | } |
226 | | |
227 | | impl<P: Pixel> fmt::Debug for Rows<'_, P> |
228 | | where |
229 | | P::Subpixel: fmt::Debug, |
230 | | { |
231 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
232 | 0 | f.debug_struct("Rows") |
233 | 0 | .field("pixels", &self.pixels) |
234 | 0 | .finish() |
235 | 0 | } |
236 | | } |
237 | | |
238 | | /// Iterate over mutable rows of an image |
239 | | /// |
240 | | /// This iterator is created with [`ImageBuffer::rows_mut`]. See its document for details. |
241 | | /// |
242 | | /// [`ImageBuffer::rows_mut`]: ../struct.ImageBuffer.html#method.rows_mut |
243 | | pub struct RowsMut<'a, P: Pixel + 'a> |
244 | | where |
245 | | <P as Pixel>::Subpixel: 'a, |
246 | | { |
247 | | pixels: ChunksExactMut<'a, P::Subpixel>, |
248 | | } |
249 | | |
250 | | impl<'a, P: Pixel + 'a> RowsMut<'a, P> { |
251 | | /// Construct the iterator from image pixels. This is not public since it has a (hidden) panic |
252 | | /// condition. The `pixels` slice must be large enough so that all pixels are addressable. |
253 | 0 | fn with_image(pixels: &'a mut [P::Subpixel], width: u32, height: u32) -> Self { |
254 | 0 | let row_len = (width as usize) * usize::from(<P as Pixel>::CHANNEL_COUNT); |
255 | 0 | if row_len == 0 { |
256 | 0 | RowsMut { |
257 | 0 | pixels: [].chunks_exact_mut(1), |
258 | 0 | } |
259 | | } else { |
260 | 0 | let pixels = pixels |
261 | 0 | .get_mut(..row_len * height as usize) |
262 | 0 | .expect("Pixel buffer has too few subpixels"); |
263 | 0 | // Rows are physically present. In particular, height is smaller than `usize::MAX` as |
264 | 0 | // all subpixels can be indexed. |
265 | 0 | RowsMut { |
266 | 0 | pixels: pixels.chunks_exact_mut(row_len), |
267 | 0 | } |
268 | | } |
269 | 0 | } |
270 | | } |
271 | | |
272 | | impl<'a, P: Pixel + 'a> Iterator for RowsMut<'a, P> |
273 | | where |
274 | | P::Subpixel: 'a, |
275 | | { |
276 | | type Item = PixelsMut<'a, P>; |
277 | | |
278 | | #[inline(always)] |
279 | 0 | fn next(&mut self) -> Option<PixelsMut<'a, P>> { |
280 | 0 | let row = self.pixels.next()?; |
281 | 0 | Some(PixelsMut { |
282 | 0 | // Note: this is not reached when CHANNEL_COUNT is 0. |
283 | 0 | chunks: row.chunks_exact_mut(<P as Pixel>::CHANNEL_COUNT as usize), |
284 | 0 | }) |
285 | 0 | } |
286 | | |
287 | | #[inline(always)] |
288 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
289 | 0 | let len = self.len(); |
290 | 0 | (len, Some(len)) |
291 | 0 | } |
292 | | } |
293 | | |
294 | | impl<'a, P: Pixel + 'a> ExactSizeIterator for RowsMut<'a, P> |
295 | | where |
296 | | P::Subpixel: 'a, |
297 | | { |
298 | 0 | fn len(&self) -> usize { |
299 | 0 | self.pixels.len() |
300 | 0 | } |
301 | | } |
302 | | |
303 | | impl<'a, P: Pixel + 'a> DoubleEndedIterator for RowsMut<'a, P> |
304 | | where |
305 | | P::Subpixel: 'a, |
306 | | { |
307 | | #[inline(always)] |
308 | 0 | fn next_back(&mut self) -> Option<PixelsMut<'a, P>> { |
309 | 0 | let row = self.pixels.next_back()?; |
310 | 0 | Some(PixelsMut { |
311 | 0 | // Note: this is not reached when CHANNEL_COUNT is 0. |
312 | 0 | chunks: row.chunks_exact_mut(<P as Pixel>::CHANNEL_COUNT as usize), |
313 | 0 | }) |
314 | 0 | } |
315 | | } |
316 | | |
317 | | impl<P: Pixel> fmt::Debug for RowsMut<'_, P> |
318 | | where |
319 | | P::Subpixel: fmt::Debug, |
320 | | { |
321 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
322 | 0 | f.debug_struct("RowsMut") |
323 | 0 | .field("pixels", &self.pixels) |
324 | 0 | .finish() |
325 | 0 | } |
326 | | } |
327 | | |
328 | | /// Enumerate the pixels of an image. |
329 | | pub struct EnumeratePixels<'a, P: Pixel + 'a> |
330 | | where |
331 | | <P as Pixel>::Subpixel: 'a, |
332 | | { |
333 | | pixels: Pixels<'a, P>, |
334 | | x: u32, |
335 | | y: u32, |
336 | | width: u32, |
337 | | } |
338 | | |
339 | | impl<'a, P: Pixel + 'a> Iterator for EnumeratePixels<'a, P> |
340 | | where |
341 | | P::Subpixel: 'a, |
342 | | { |
343 | | type Item = (u32, u32, &'a P); |
344 | | |
345 | | #[inline(always)] |
346 | 0 | fn next(&mut self) -> Option<(u32, u32, &'a P)> { |
347 | 0 | if self.x >= self.width { |
348 | 0 | self.x = 0; |
349 | 0 | self.y += 1; |
350 | 0 | } |
351 | 0 | let (x, y) = (self.x, self.y); |
352 | 0 | self.x += 1; |
353 | 0 | self.pixels.next().map(|p| (x, y, p)) |
354 | 0 | } |
355 | | |
356 | | #[inline(always)] |
357 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
358 | 0 | let len = self.len(); |
359 | 0 | (len, Some(len)) |
360 | 0 | } |
361 | | } |
362 | | |
363 | | impl<'a, P: Pixel + 'a> ExactSizeIterator for EnumeratePixels<'a, P> |
364 | | where |
365 | | P::Subpixel: 'a, |
366 | | { |
367 | 0 | fn len(&self) -> usize { |
368 | 0 | self.pixels.len() |
369 | 0 | } |
370 | | } |
371 | | |
372 | | impl<P: Pixel> Clone for EnumeratePixels<'_, P> { |
373 | 0 | fn clone(&self) -> Self { |
374 | 0 | EnumeratePixels { |
375 | 0 | pixels: self.pixels.clone(), |
376 | 0 | ..*self |
377 | 0 | } |
378 | 0 | } |
379 | | } |
380 | | |
381 | | impl<P: Pixel> fmt::Debug for EnumeratePixels<'_, P> |
382 | | where |
383 | | P::Subpixel: fmt::Debug, |
384 | | { |
385 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
386 | 0 | f.debug_struct("EnumeratePixels") |
387 | 0 | .field("pixels", &self.pixels) |
388 | 0 | .field("x", &self.x) |
389 | 0 | .field("y", &self.y) |
390 | 0 | .field("width", &self.width) |
391 | 0 | .finish() |
392 | 0 | } |
393 | | } |
394 | | |
395 | | /// Enumerate the rows of an image. |
396 | | pub struct EnumerateRows<'a, P: Pixel + 'a> |
397 | | where |
398 | | <P as Pixel>::Subpixel: 'a, |
399 | | { |
400 | | rows: Rows<'a, P>, |
401 | | y: u32, |
402 | | width: u32, |
403 | | } |
404 | | |
405 | | impl<'a, P: Pixel + 'a> Iterator for EnumerateRows<'a, P> |
406 | | where |
407 | | P::Subpixel: 'a, |
408 | | { |
409 | | type Item = (u32, EnumeratePixels<'a, P>); |
410 | | |
411 | | #[inline(always)] |
412 | 0 | fn next(&mut self) -> Option<(u32, EnumeratePixels<'a, P>)> { |
413 | 0 | let y = self.y; |
414 | 0 | self.y += 1; |
415 | 0 | self.rows.next().map(|r| { |
416 | 0 | ( |
417 | 0 | y, |
418 | 0 | EnumeratePixels { |
419 | 0 | x: 0, |
420 | 0 | y, |
421 | 0 | width: self.width, |
422 | 0 | pixels: r, |
423 | 0 | }, |
424 | 0 | ) |
425 | 0 | }) |
426 | 0 | } |
427 | | |
428 | | #[inline(always)] |
429 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
430 | 0 | let len = self.len(); |
431 | 0 | (len, Some(len)) |
432 | 0 | } |
433 | | } |
434 | | |
435 | | impl<'a, P: Pixel + 'a> ExactSizeIterator for EnumerateRows<'a, P> |
436 | | where |
437 | | P::Subpixel: 'a, |
438 | | { |
439 | 0 | fn len(&self) -> usize { |
440 | 0 | self.rows.len() |
441 | 0 | } |
442 | | } |
443 | | |
444 | | impl<P: Pixel> Clone for EnumerateRows<'_, P> { |
445 | 0 | fn clone(&self) -> Self { |
446 | 0 | EnumerateRows { |
447 | 0 | rows: self.rows.clone(), |
448 | 0 | ..*self |
449 | 0 | } |
450 | 0 | } |
451 | | } |
452 | | |
453 | | impl<P: Pixel> fmt::Debug for EnumerateRows<'_, P> |
454 | | where |
455 | | P::Subpixel: fmt::Debug, |
456 | | { |
457 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
458 | 0 | f.debug_struct("EnumerateRows") |
459 | 0 | .field("rows", &self.rows) |
460 | 0 | .field("y", &self.y) |
461 | 0 | .field("width", &self.width) |
462 | 0 | .finish() |
463 | 0 | } |
464 | | } |
465 | | |
466 | | /// Enumerate the pixels of an image. |
467 | | pub struct EnumeratePixelsMut<'a, P: Pixel + 'a> |
468 | | where |
469 | | <P as Pixel>::Subpixel: 'a, |
470 | | { |
471 | | pixels: PixelsMut<'a, P>, |
472 | | x: u32, |
473 | | y: u32, |
474 | | width: u32, |
475 | | } |
476 | | |
477 | | impl<'a, P: Pixel + 'a> Iterator for EnumeratePixelsMut<'a, P> |
478 | | where |
479 | | P::Subpixel: 'a, |
480 | | { |
481 | | type Item = (u32, u32, &'a mut P); |
482 | | |
483 | | #[inline(always)] |
484 | 3.13G | fn next(&mut self) -> Option<(u32, u32, &'a mut P)> { |
485 | 3.13G | if self.x >= self.width { |
486 | 1.35M | self.x = 0; |
487 | 1.35M | self.y += 1; |
488 | 3.13G | } |
489 | 3.13G | let (x, y) = (self.x, self.y); |
490 | 3.13G | self.x += 1; |
491 | 3.13G | self.pixels.next().map(|p| (x, y, p)) Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgb<f32>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgb<u8>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgb<u16>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Luma<u8>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Luma<u16>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<f32>> as core::iter::traits::iterator::Iterator>::next::{closure#0} <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Line | Count | Source | 491 | 3.13G | self.pixels.next().map(|p| (x, y, p)) |
Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<u16>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::LumaA<u8>> as core::iter::traits::iterator::Iterator>::next::{closure#0} Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::LumaA<u16>> as core::iter::traits::iterator::Iterator>::next::{closure#0} |
492 | 3.13G | } Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgb<f32>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgb<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgb<u16>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Luma<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Luma<u16>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<f32>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<u16>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::LumaA<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::LumaA<u16>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Line | Count | Source | 484 | 3.13G | fn next(&mut self) -> Option<(u32, u32, &'a mut P)> { | 485 | 3.13G | if self.x >= self.width { | 486 | 1.27M | self.x = 0; | 487 | 1.27M | self.y += 1; | 488 | 3.13G | } | 489 | 3.13G | let (x, y) = (self.x, self.y); | 490 | 3.13G | self.x += 1; | 491 | 3.13G | self.pixels.next().map(|p| (x, y, p)) | 492 | 3.13G | } |
Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Line | Count | Source | 484 | 2.63M | fn next(&mut self) -> Option<(u32, u32, &'a mut P)> { | 485 | 2.63M | if self.x >= self.width { | 486 | 78.3k | self.x = 0; | 487 | 78.3k | self.y += 1; | 488 | 2.55M | } | 489 | 2.63M | let (x, y) = (self.x, self.y); | 490 | 2.63M | self.x += 1; | 491 | 2.63M | self.pixels.next().map(|p| (x, y, p)) | 492 | 2.63M | } |
|
493 | | |
494 | | #[inline(always)] |
495 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
496 | 0 | let len = self.len(); |
497 | 0 | (len, Some(len)) |
498 | 0 | } |
499 | | } |
500 | | |
501 | | impl<'a, P: Pixel + 'a> ExactSizeIterator for EnumeratePixelsMut<'a, P> |
502 | | where |
503 | | P::Subpixel: 'a, |
504 | | { |
505 | 0 | fn len(&self) -> usize { |
506 | 0 | self.pixels.len() |
507 | 0 | } |
508 | | } |
509 | | |
510 | | impl<P: Pixel> fmt::Debug for EnumeratePixelsMut<'_, P> |
511 | | where |
512 | | P::Subpixel: fmt::Debug, |
513 | | { |
514 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
515 | 0 | f.debug_struct("EnumeratePixelsMut") |
516 | 0 | .field("pixels", &self.pixels) |
517 | 0 | .field("x", &self.x) |
518 | 0 | .field("y", &self.y) |
519 | 0 | .field("width", &self.width) |
520 | 0 | .finish() |
521 | 0 | } |
522 | | } |
523 | | |
524 | | /// Enumerate the rows of an image. |
525 | | pub struct EnumerateRowsMut<'a, P: Pixel + 'a> |
526 | | where |
527 | | <P as Pixel>::Subpixel: 'a, |
528 | | { |
529 | | rows: RowsMut<'a, P>, |
530 | | y: u32, |
531 | | width: u32, |
532 | | } |
533 | | |
534 | | impl<'a, P: Pixel + 'a> Iterator for EnumerateRowsMut<'a, P> |
535 | | where |
536 | | P::Subpixel: 'a, |
537 | | { |
538 | | type Item = (u32, EnumeratePixelsMut<'a, P>); |
539 | | |
540 | | #[inline(always)] |
541 | 0 | fn next(&mut self) -> Option<(u32, EnumeratePixelsMut<'a, P>)> { |
542 | 0 | let y = self.y; |
543 | 0 | self.y += 1; |
544 | 0 | self.rows.next().map(|r| { |
545 | 0 | ( |
546 | 0 | y, |
547 | 0 | EnumeratePixelsMut { |
548 | 0 | x: 0, |
549 | 0 | y, |
550 | 0 | width: self.width, |
551 | 0 | pixels: r, |
552 | 0 | }, |
553 | 0 | ) |
554 | 0 | }) |
555 | 0 | } |
556 | | |
557 | | #[inline(always)] |
558 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
559 | 0 | let len = self.len(); |
560 | 0 | (len, Some(len)) |
561 | 0 | } |
562 | | } |
563 | | |
564 | | impl<'a, P: Pixel + 'a> ExactSizeIterator for EnumerateRowsMut<'a, P> |
565 | | where |
566 | | P::Subpixel: 'a, |
567 | | { |
568 | 0 | fn len(&self) -> usize { |
569 | 0 | self.rows.len() |
570 | 0 | } |
571 | | } |
572 | | |
573 | | impl<P: Pixel> fmt::Debug for EnumerateRowsMut<'_, P> |
574 | | where |
575 | | P::Subpixel: fmt::Debug, |
576 | | { |
577 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
578 | 0 | f.debug_struct("EnumerateRowsMut") |
579 | 0 | .field("rows", &self.rows) |
580 | 0 | .field("y", &self.y) |
581 | 0 | .field("width", &self.width) |
582 | 0 | .finish() |
583 | 0 | } |
584 | | } |
585 | | |
586 | | /// Generic image buffer |
587 | | /// |
588 | | /// This is an image parameterised by its Pixel types, represented by a width and height and a |
589 | | /// container of channel data. It provides direct access to its pixels and implements the |
590 | | /// [`GenericImageView`] and [`GenericImage`] traits. In many ways, this is the standard buffer |
591 | | /// implementing those traits. Using this concrete type instead of a generic type parameter has |
592 | | /// been shown to improve performance. |
593 | | /// |
594 | | /// The crate defines a few type aliases with regularly used pixel types for your convenience, such |
595 | | /// as [`RgbImage`], [`GrayImage`] etc. |
596 | | /// |
597 | | /// [`GenericImage`]: trait.GenericImage.html |
598 | | /// [`GenericImageView`]: trait.GenericImageView.html |
599 | | /// [`RgbImage`]: type.RgbImage.html |
600 | | /// [`GrayImage`]: type.GrayImage.html |
601 | | /// |
602 | | /// To convert between images of different Pixel types use [`DynamicImage`]. |
603 | | /// |
604 | | /// You can retrieve a complete description of the buffer's layout and contents through |
605 | | /// [`as_flat_samples`] and [`as_flat_samples_mut`]. This can be handy to also use the contents in |
606 | | /// a foreign language, map it as a GPU host buffer or other similar tasks. |
607 | | /// |
608 | | /// [`DynamicImage`]: enum.DynamicImage.html |
609 | | /// [`as_flat_samples`]: #method.as_flat_samples |
610 | | /// [`as_flat_samples_mut`]: #method.as_flat_samples_mut |
611 | | /// |
612 | | /// ## Examples |
613 | | /// |
614 | | /// Create a simple canvas and paint a small cross. |
615 | | /// |
616 | | /// ``` |
617 | | /// use image::{RgbImage, Rgb}; |
618 | | /// |
619 | | /// let mut img = RgbImage::new(32, 32); |
620 | | /// |
621 | | /// for x in 15..=17 { |
622 | | /// for y in 8..24 { |
623 | | /// img.put_pixel(x, y, Rgb([255, 0, 0])); |
624 | | /// img.put_pixel(y, x, Rgb([255, 0, 0])); |
625 | | /// } |
626 | | /// } |
627 | | /// ``` |
628 | | /// |
629 | | /// Overlays an image on top of a larger background raster. |
630 | | /// |
631 | | /// ```no_run |
632 | | /// use image::{GenericImage, GenericImageView, ImageBuffer, open}; |
633 | | /// |
634 | | /// let on_top = open("path/to/some.png").unwrap().into_rgb8(); |
635 | | /// let mut img = ImageBuffer::from_fn(512, 512, |x, y| { |
636 | | /// if (x + y) % 2 == 0 { |
637 | | /// image::Rgb([0, 0, 0]) |
638 | | /// } else { |
639 | | /// image::Rgb([255, 255, 255]) |
640 | | /// } |
641 | | /// }); |
642 | | /// |
643 | | /// image::imageops::overlay(&mut img, &on_top, 128, 128); |
644 | | /// ``` |
645 | | /// |
646 | | /// Convert an `RgbaImage` to a `GrayImage`. |
647 | | /// |
648 | | /// ```no_run |
649 | | /// use image::{open, DynamicImage}; |
650 | | /// |
651 | | /// let rgba = open("path/to/some.png").unwrap().into_rgba8(); |
652 | | /// let gray = DynamicImage::ImageRgba8(rgba).into_luma8(); |
653 | | /// ``` |
654 | | #[derive(Debug, Hash, PartialEq, Eq)] |
655 | | pub struct ImageBuffer<P: Pixel, Container> { |
656 | | width: u32, |
657 | | height: u32, |
658 | | _phantom: PhantomData<P>, |
659 | | data: Container, |
660 | | } |
661 | | |
662 | | // generic implementation, shared along all image buffers |
663 | | impl<P, Container> ImageBuffer<P, Container> |
664 | | where |
665 | | P: Pixel, |
666 | | Container: Deref<Target = [P::Subpixel]>, |
667 | | { |
668 | | /// Constructs a buffer from a generic container |
669 | | /// (for example a `Vec` or a slice) |
670 | | /// |
671 | | /// Returns `None` if the container is not big enough (including when the image dimensions |
672 | | /// necessitate an allocation of more bytes than supported by the container). |
673 | 7.11k | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { |
674 | 7.11k | if Self::check_image_fits(width, height, buf.len()) { |
675 | 7.11k | Some(ImageBuffer { |
676 | 7.11k | data: buf, |
677 | 7.11k | width, |
678 | 7.11k | height, |
679 | 7.11k | _phantom: PhantomData, |
680 | 7.11k | }) |
681 | | } else { |
682 | 0 | None |
683 | | } |
684 | 7.11k | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::from_raw <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::from_raw Line | Count | Source | 673 | 190 | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 674 | 190 | if Self::check_image_fits(width, height, buf.len()) { | 675 | 190 | Some(ImageBuffer { | 676 | 190 | data: buf, | 677 | 190 | width, | 678 | 190 | height, | 679 | 190 | _phantom: PhantomData, | 680 | 190 | }) | 681 | | } else { | 682 | 0 | None | 683 | | } | 684 | 190 | } |
<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::from_raw Line | Count | Source | 673 | 1.57k | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 674 | 1.57k | if Self::check_image_fits(width, height, buf.len()) { | 675 | 1.57k | Some(ImageBuffer { | 676 | 1.57k | data: buf, | 677 | 1.57k | width, | 678 | 1.57k | height, | 679 | 1.57k | _phantom: PhantomData, | 680 | 1.57k | }) | 681 | | } else { | 682 | 0 | None | 683 | | } | 684 | 1.57k | } |
<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::from_raw Line | Count | Source | 673 | 83 | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 674 | 83 | if Self::check_image_fits(width, height, buf.len()) { | 675 | 83 | Some(ImageBuffer { | 676 | 83 | data: buf, | 677 | 83 | width, | 678 | 83 | height, | 679 | 83 | _phantom: PhantomData, | 680 | 83 | }) | 681 | | } else { | 682 | 0 | None | 683 | | } | 684 | 83 | } |
<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::from_raw Line | Count | Source | 673 | 1.04k | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 674 | 1.04k | if Self::check_image_fits(width, height, buf.len()) { | 675 | 1.04k | Some(ImageBuffer { | 676 | 1.04k | data: buf, | 677 | 1.04k | width, | 678 | 1.04k | height, | 679 | 1.04k | _phantom: PhantomData, | 680 | 1.04k | }) | 681 | | } else { | 682 | 0 | None | 683 | | } | 684 | 1.04k | } |
<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::from_raw Line | Count | Source | 673 | 136 | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 674 | 136 | if Self::check_image_fits(width, height, buf.len()) { | 675 | 136 | Some(ImageBuffer { | 676 | 136 | data: buf, | 677 | 136 | width, | 678 | 136 | height, | 679 | 136 | _phantom: PhantomData, | 680 | 136 | }) | 681 | | } else { | 682 | 0 | None | 683 | | } | 684 | 136 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::from_raw <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::from_raw Line | Count | Source | 673 | 3.96k | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 674 | 3.96k | if Self::check_image_fits(width, height, buf.len()) { | 675 | 3.96k | Some(ImageBuffer { | 676 | 3.96k | data: buf, | 677 | 3.96k | width, | 678 | 3.96k | height, | 679 | 3.96k | _phantom: PhantomData, | 680 | 3.96k | }) | 681 | | } else { | 682 | 0 | None | 683 | | } | 684 | 3.96k | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::from_raw Line | Count | Source | 673 | 6 | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 674 | 6 | if Self::check_image_fits(width, height, buf.len()) { | 675 | 6 | Some(ImageBuffer { | 676 | 6 | data: buf, | 677 | 6 | width, | 678 | 6 | height, | 679 | 6 | _phantom: PhantomData, | 680 | 6 | }) | 681 | | } else { | 682 | 0 | None | 683 | | } | 684 | 6 | } |
<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::from_raw Line | Count | Source | 673 | 4 | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 674 | 4 | if Self::check_image_fits(width, height, buf.len()) { | 675 | 4 | Some(ImageBuffer { | 676 | 4 | data: buf, | 677 | 4 | width, | 678 | 4 | height, | 679 | 4 | _phantom: PhantomData, | 680 | 4 | }) | 681 | | } else { | 682 | 0 | None | 683 | | } | 684 | 4 | } |
<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::from_raw Line | Count | Source | 673 | 1 | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 674 | 1 | if Self::check_image_fits(width, height, buf.len()) { | 675 | 1 | Some(ImageBuffer { | 676 | 1 | data: buf, | 677 | 1 | width, | 678 | 1 | height, | 679 | 1 | _phantom: PhantomData, | 680 | 1 | }) | 681 | | } else { | 682 | 0 | None | 683 | | } | 684 | 1 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::from_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::from_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, &[u8]>>::from_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, &[u16]>>::from_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, &[u8]>>::from_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, &[u16]>>::from_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::from_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &[u8]>>::from_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, &[u16]>>::from_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, &[u8]>>::from_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, &[u16]>>::from_raw <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::from_raw Line | Count | Source | 673 | 110 | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 674 | 110 | if Self::check_image_fits(width, height, buf.len()) { | 675 | 110 | Some(ImageBuffer { | 676 | 110 | data: buf, | 677 | 110 | width, | 678 | 110 | height, | 679 | 110 | _phantom: PhantomData, | 680 | 110 | }) | 681 | | } else { | 682 | 0 | None | 683 | | } | 684 | 110 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::from_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::from_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::from_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::from_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::from_raw <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::from_raw Line | Count | Source | 673 | 2 | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 674 | 2 | if Self::check_image_fits(width, height, buf.len()) { | 675 | 2 | Some(ImageBuffer { | 676 | 2 | data: buf, | 677 | 2 | width, | 678 | 2 | height, | 679 | 2 | _phantom: PhantomData, | 680 | 2 | }) | 681 | | } else { | 682 | 0 | None | 683 | | } | 684 | 2 | } |
|
685 | | |
686 | | /// Returns the underlying raw buffer |
687 | 3.36k | pub fn into_raw(self) -> Container { |
688 | 3.36k | self.data |
689 | 3.36k | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::into_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::into_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::into_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::into_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::into_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::into_raw <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::into_raw Line | Count | Source | 687 | 3.36k | pub fn into_raw(self) -> Container { | 688 | 3.36k | self.data | 689 | 3.36k | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::into_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::into_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::into_raw |
690 | | |
691 | | /// Returns the underlying raw buffer |
692 | 0 | pub fn as_raw(&self) -> &Container { |
693 | 0 | &self.data |
694 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::as_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::as_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::as_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::as_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::as_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::as_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::as_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::as_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::as_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::as_raw |
695 | | |
696 | | /// The width and height of this image. |
697 | 0 | pub fn dimensions(&self) -> (u32, u32) { |
698 | 0 | (self.width, self.height) |
699 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, &[u8]>>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, &[u16]>>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, &[u8]>>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, &[u16]>>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, &[u16]>>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, &[u8]>>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, &[u16]>>::dimensions |
700 | | |
701 | | /// The width of this image. |
702 | 1.68k | pub fn width(&self) -> u32 { |
703 | 1.68k | self.width |
704 | 1.68k | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::width Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::width Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::width Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::width Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::width Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::width <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::width Line | Count | Source | 702 | 1.68k | pub fn width(&self) -> u32 { | 703 | 1.68k | self.width | 704 | 1.68k | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::width Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::width Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::width |
705 | | |
706 | | /// The height of this image. |
707 | 1.68k | pub fn height(&self) -> u32 { |
708 | 1.68k | self.height |
709 | 1.68k | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::height Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::height Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::height Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::height Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::height Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::height <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::height Line | Count | Source | 707 | 1.68k | pub fn height(&self) -> u32 { | 708 | 1.68k | self.height | 709 | 1.68k | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::height Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::height Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::height |
710 | | |
711 | | // TODO: choose name under which to expose. |
712 | 1.68k | pub(crate) fn inner_pixels(&self) -> &[P::Subpixel] { |
713 | 1.68k | let len = Self::image_buffer_len(self.width, self.height).unwrap(); |
714 | 1.68k | &self.data[..len] |
715 | 1.68k | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::inner_pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::inner_pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::inner_pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::inner_pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::inner_pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::inner_pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::inner_pixels <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::inner_pixels Line | Count | Source | 712 | 1.68k | pub(crate) fn inner_pixels(&self) -> &[P::Subpixel] { | 713 | 1.68k | let len = Self::image_buffer_len(self.width, self.height).unwrap(); | 714 | 1.68k | &self.data[..len] | 715 | 1.68k | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::inner_pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::inner_pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::inner_pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::inner_pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, &[u8]>>::inner_pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, &[u16]>>::inner_pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, &[u8]>>::inner_pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, &[u16]>>::inner_pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &[u8]>>::inner_pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, &[u16]>>::inner_pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, &[u8]>>::inner_pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, &[u16]>>::inner_pixels |
716 | | |
717 | | /// Returns an iterator over the pixels of this image. |
718 | | /// The iteration order is x = 0 to width then y = 0 to height |
719 | 0 | pub fn pixels(&self) -> Pixels<'_, P> { |
720 | 0 | Pixels { |
721 | 0 | chunks: self |
722 | 0 | .inner_pixels() |
723 | 0 | .chunks_exact(<P as Pixel>::CHANNEL_COUNT as usize), |
724 | 0 | } |
725 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, &[u8]>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, &[u16]>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, &[u8]>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, &[u16]>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &[u8]>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, &[u16]>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, &[u8]>>::pixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, &[u16]>>::pixels |
726 | | |
727 | | /// Returns an iterator over the rows of this image. |
728 | | /// |
729 | | /// Only non-empty rows can be iterated in this manner. In particular the iterator will not |
730 | | /// yield any item when the width of the image is `0` or a pixel type without any channels is |
731 | | /// used. This ensures that its length can always be represented by `usize`. |
732 | 0 | pub fn rows(&self) -> Rows<'_, P> { |
733 | 0 | Rows::with_image(&self.data, self.width, self.height) |
734 | 0 | } |
735 | | |
736 | | /// Enumerates over the pixels of the image. |
737 | | /// The iterator yields the coordinates of each pixel |
738 | | /// along with a reference to them. |
739 | | /// The iteration order is x = 0 to width then y = 0 to height |
740 | | /// Starting from the top left. |
741 | 0 | pub fn enumerate_pixels(&self) -> EnumeratePixels<'_, P> { |
742 | 0 | EnumeratePixels { |
743 | 0 | pixels: self.pixels(), |
744 | 0 | x: 0, |
745 | 0 | y: 0, |
746 | 0 | width: self.width, |
747 | 0 | } |
748 | 0 | } |
749 | | |
750 | | /// Enumerates over the rows of the image. |
751 | | /// The iterator yields the y-coordinate of each row |
752 | | /// along with a reference to them. |
753 | 0 | pub fn enumerate_rows(&self) -> EnumerateRows<'_, P> { |
754 | 0 | EnumerateRows { |
755 | 0 | rows: self.rows(), |
756 | 0 | y: 0, |
757 | 0 | width: self.width, |
758 | 0 | } |
759 | 0 | } |
760 | | |
761 | | /// Gets a reference to the pixel at location `(x, y)` |
762 | | /// |
763 | | /// # Panics |
764 | | /// |
765 | | /// Panics if `(x, y)` is out of the bounds `(width, height)`. |
766 | | #[inline] |
767 | | #[track_caller] |
768 | 2.62M | pub fn get_pixel(&self, x: u32, y: u32) -> &P { |
769 | 2.62M | match self.pixel_indices(x, y) { |
770 | 0 | None => panic!( |
771 | 0 | "Image index {:?} out of bounds {:?}", |
772 | 0 | (x, y), |
773 | 0 | (self.width, self.height) |
774 | 0 | ), |
775 | 2.62M | Some(pixel_indices) => <P as Pixel>::from_slice(&self.data[pixel_indices]), |
776 | 2.62M | } |
777 | 2.62M | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::get_pixel <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::get_pixel Line | Count | Source | 768 | 2.62M | pub fn get_pixel(&self, x: u32, y: u32) -> &P { | 769 | 2.62M | match self.pixel_indices(x, y) { | 770 | 0 | None => panic!( | 771 | 0 | "Image index {:?} out of bounds {:?}", | 772 | 0 | (x, y), | 773 | 0 | (self.width, self.height) | 774 | 0 | ), | 775 | 2.62M | Some(pixel_indices) => <P as Pixel>::from_slice(&self.data[pixel_indices]), | 776 | 2.62M | } | 777 | 2.62M | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, &[u8]>>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, &[u8]>>::get_pixel |
778 | | |
779 | | /// Gets a reference to the pixel at location `(x, y)` or returns `None` if |
780 | | /// the index is out of the bounds `(width, height)`. |
781 | 0 | pub fn get_pixel_checked(&self, x: u32, y: u32) -> Option<&P> { |
782 | 0 | if x >= self.width { |
783 | 0 | return None; |
784 | 0 | } |
785 | 0 | let num_channels = <P as Pixel>::CHANNEL_COUNT as usize; |
786 | 0 | let i = (y as usize) |
787 | 0 | .saturating_mul(self.width as usize) |
788 | 0 | .saturating_add(x as usize) |
789 | 0 | .saturating_mul(num_channels); |
790 | 0 |
|
791 | 0 | self.data |
792 | 0 | .get(i..i.checked_add(num_channels)?) |
793 | 0 | .map(|pixel_indices| <P as Pixel>::from_slice(pixel_indices)) |
794 | 0 | } |
795 | | |
796 | | /// Test that the image fits inside the buffer. |
797 | | /// |
798 | | /// Verifies that the maximum image of pixels inside the bounds is smaller than the provided |
799 | | /// length. Note that as a corrolary we also have that the index calculation of pixels inside |
800 | | /// the bounds will not overflow. |
801 | 7.11k | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { |
802 | 7.11k | let checked_len = Self::image_buffer_len(width, height); |
803 | 7.11k | checked_len.is_some_and(|min_len| min_len <= len) Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits::{closure#0} <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::check_image_fits::{closure#0} Line | Count | Source | 803 | 190 | checked_len.is_some_and(|min_len| min_len <= len) |
<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::check_image_fits::{closure#0} Line | Count | Source | 803 | 1.57k | checked_len.is_some_and(|min_len| min_len <= len) |
<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::check_image_fits::{closure#0} Line | Count | Source | 803 | 83 | checked_len.is_some_and(|min_len| min_len <= len) |
<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::check_image_fits::{closure#0} Line | Count | Source | 803 | 1.04k | checked_len.is_some_and(|min_len| min_len <= len) |
<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::check_image_fits::{closure#0} Line | Count | Source | 803 | 136 | checked_len.is_some_and(|min_len| min_len <= len) |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::check_image_fits::{closure#0} <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::check_image_fits::{closure#0} Line | Count | Source | 803 | 3.96k | checked_len.is_some_and(|min_len| min_len <= len) |
<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::check_image_fits::{closure#0} Line | Count | Source | 803 | 6 | checked_len.is_some_and(|min_len| min_len <= len) |
<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::check_image_fits::{closure#0} Line | Count | Source | 803 | 4 | checked_len.is_some_and(|min_len| min_len <= len) |
<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::check_image_fits::{closure#0} Line | Count | Source | 803 | 1 | checked_len.is_some_and(|min_len| min_len <= len) |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, &[u8]>>::check_image_fits::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, &[u16]>>::check_image_fits::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, &[u8]>>::check_image_fits::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, &[u16]>>::check_image_fits::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &[u8]>>::check_image_fits::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, &[u16]>>::check_image_fits::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, &[u8]>>::check_image_fits::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, &[u16]>>::check_image_fits::{closure#0} <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits::{closure#0} Line | Count | Source | 803 | 110 | checked_len.is_some_and(|min_len| min_len <= len) |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits::{closure#0} <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits::{closure#0} Line | Count | Source | 803 | 2 | checked_len.is_some_and(|min_len| min_len <= len) |
|
804 | 7.11k | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::check_image_fits Line | Count | Source | 801 | 190 | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 802 | 190 | let checked_len = Self::image_buffer_len(width, height); | 803 | 190 | checked_len.is_some_and(|min_len| min_len <= len) | 804 | 190 | } |
<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::check_image_fits Line | Count | Source | 801 | 1.57k | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 802 | 1.57k | let checked_len = Self::image_buffer_len(width, height); | 803 | 1.57k | checked_len.is_some_and(|min_len| min_len <= len) | 804 | 1.57k | } |
<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::check_image_fits Line | Count | Source | 801 | 83 | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 802 | 83 | let checked_len = Self::image_buffer_len(width, height); | 803 | 83 | checked_len.is_some_and(|min_len| min_len <= len) | 804 | 83 | } |
<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::check_image_fits Line | Count | Source | 801 | 1.04k | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 802 | 1.04k | let checked_len = Self::image_buffer_len(width, height); | 803 | 1.04k | checked_len.is_some_and(|min_len| min_len <= len) | 804 | 1.04k | } |
<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::check_image_fits Line | Count | Source | 801 | 136 | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 802 | 136 | let checked_len = Self::image_buffer_len(width, height); | 803 | 136 | checked_len.is_some_and(|min_len| min_len <= len) | 804 | 136 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::check_image_fits <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::check_image_fits Line | Count | Source | 801 | 3.96k | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 802 | 3.96k | let checked_len = Self::image_buffer_len(width, height); | 803 | 3.96k | checked_len.is_some_and(|min_len| min_len <= len) | 804 | 3.96k | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::check_image_fits Line | Count | Source | 801 | 6 | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 802 | 6 | let checked_len = Self::image_buffer_len(width, height); | 803 | 6 | checked_len.is_some_and(|min_len| min_len <= len) | 804 | 6 | } |
<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::check_image_fits Line | Count | Source | 801 | 4 | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 802 | 4 | let checked_len = Self::image_buffer_len(width, height); | 803 | 4 | checked_len.is_some_and(|min_len| min_len <= len) | 804 | 4 | } |
<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::check_image_fits Line | Count | Source | 801 | 1 | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 802 | 1 | let checked_len = Self::image_buffer_len(width, height); | 803 | 1 | checked_len.is_some_and(|min_len| min_len <= len) | 804 | 1 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, &[u8]>>::check_image_fits Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, &[u16]>>::check_image_fits Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, &[u8]>>::check_image_fits Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, &[u16]>>::check_image_fits Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &[u8]>>::check_image_fits Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, &[u16]>>::check_image_fits Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, &[u8]>>::check_image_fits Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, &[u16]>>::check_image_fits <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits Line | Count | Source | 801 | 110 | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 802 | 110 | let checked_len = Self::image_buffer_len(width, height); | 803 | 110 | checked_len.is_some_and(|min_len| min_len <= len) | 804 | 110 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits Line | Count | Source | 801 | 2 | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 802 | 2 | let checked_len = Self::image_buffer_len(width, height); | 803 | 2 | checked_len.is_some_and(|min_len| min_len <= len) | 804 | 2 | } |
|
805 | | |
806 | 8.91k | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { |
807 | 8.91k | Some(<P as Pixel>::CHANNEL_COUNT as usize) |
808 | 8.91k | .and_then(|size| size.checked_mul(width as usize)) Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#0} <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::image_buffer_len::{closure#0} Line | Count | Source | 808 | 190 | .and_then(|size| size.checked_mul(width as usize)) |
<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::image_buffer_len::{closure#0} Line | Count | Source | 808 | 1.57k | .and_then(|size| size.checked_mul(width as usize)) |
<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::image_buffer_len::{closure#0} Line | Count | Source | 808 | 83 | .and_then(|size| size.checked_mul(width as usize)) |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::image_buffer_len::{closure#0} <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::image_buffer_len::{closure#0} Line | Count | Source | 808 | 1.04k | .and_then(|size| size.checked_mul(width as usize)) |
<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::image_buffer_len::{closure#0} Line | Count | Source | 808 | 136 | .and_then(|size| size.checked_mul(width as usize)) |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::image_buffer_len::{closure#0} <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::image_buffer_len::{closure#0} Line | Count | Source | 808 | 5.64k | .and_then(|size| size.checked_mul(width as usize)) |
<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::image_buffer_len::{closure#0} Line | Count | Source | 808 | 6 | .and_then(|size| size.checked_mul(width as usize)) |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::image_buffer_len::{closure#0} <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::image_buffer_len::{closure#0} Line | Count | Source | 808 | 4 | .and_then(|size| size.checked_mul(width as usize)) |
<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::image_buffer_len::{closure#0} Line | Count | Source | 808 | 1 | .and_then(|size| size.checked_mul(width as usize)) |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, &[u8]>>::image_buffer_len::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, &[u16]>>::image_buffer_len::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, &[u8]>>::image_buffer_len::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, &[u16]>>::image_buffer_len::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &[u8]>>::image_buffer_len::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, &[u16]>>::image_buffer_len::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, &[u8]>>::image_buffer_len::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, &[u16]>>::image_buffer_len::{closure#0} <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#0} Line | Count | Source | 808 | 220 | .and_then(|size| size.checked_mul(width as usize)) |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#0} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#0} <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#0} Line | Count | Source | 808 | 4 | .and_then(|size| size.checked_mul(width as usize)) |
|
809 | 8.91k | .and_then(|size| size.checked_mul(height as usize)) Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#1} <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::image_buffer_len::{closure#1} Line | Count | Source | 809 | 190 | .and_then(|size| size.checked_mul(height as usize)) |
<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::image_buffer_len::{closure#1} Line | Count | Source | 809 | 1.57k | .and_then(|size| size.checked_mul(height as usize)) |
<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::image_buffer_len::{closure#1} Line | Count | Source | 809 | 83 | .and_then(|size| size.checked_mul(height as usize)) |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::image_buffer_len::{closure#1} <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::image_buffer_len::{closure#1} Line | Count | Source | 809 | 1.04k | .and_then(|size| size.checked_mul(height as usize)) |
<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::image_buffer_len::{closure#1} Line | Count | Source | 809 | 136 | .and_then(|size| size.checked_mul(height as usize)) |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::image_buffer_len::{closure#1} <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::image_buffer_len::{closure#1} Line | Count | Source | 809 | 5.64k | .and_then(|size| size.checked_mul(height as usize)) |
<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::image_buffer_len::{closure#1} Line | Count | Source | 809 | 6 | .and_then(|size| size.checked_mul(height as usize)) |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::image_buffer_len::{closure#1} <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::image_buffer_len::{closure#1} Line | Count | Source | 809 | 4 | .and_then(|size| size.checked_mul(height as usize)) |
<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::image_buffer_len::{closure#1} Line | Count | Source | 809 | 1 | .and_then(|size| size.checked_mul(height as usize)) |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#1} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#1} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, &[u8]>>::image_buffer_len::{closure#1} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, &[u16]>>::image_buffer_len::{closure#1} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, &[u8]>>::image_buffer_len::{closure#1} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, &[u16]>>::image_buffer_len::{closure#1} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#1} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &[u8]>>::image_buffer_len::{closure#1} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, &[u16]>>::image_buffer_len::{closure#1} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, &[u8]>>::image_buffer_len::{closure#1} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, &[u16]>>::image_buffer_len::{closure#1} <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#1} Line | Count | Source | 809 | 220 | .and_then(|size| size.checked_mul(height as usize)) |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#1} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#1} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#1} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#1} Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#1} <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#1} Line | Count | Source | 809 | 4 | .and_then(|size| size.checked_mul(height as usize)) |
|
810 | 8.91k | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::image_buffer_len Line | Count | Source | 806 | 190 | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 807 | 190 | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 808 | 190 | .and_then(|size| size.checked_mul(width as usize)) | 809 | 190 | .and_then(|size| size.checked_mul(height as usize)) | 810 | 190 | } |
<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::image_buffer_len Line | Count | Source | 806 | 1.57k | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 807 | 1.57k | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 808 | 1.57k | .and_then(|size| size.checked_mul(width as usize)) | 809 | 1.57k | .and_then(|size| size.checked_mul(height as usize)) | 810 | 1.57k | } |
<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::image_buffer_len Line | Count | Source | 806 | 83 | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 807 | 83 | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 808 | 83 | .and_then(|size| size.checked_mul(width as usize)) | 809 | 83 | .and_then(|size| size.checked_mul(height as usize)) | 810 | 83 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::image_buffer_len <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::image_buffer_len Line | Count | Source | 806 | 1.04k | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 807 | 1.04k | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 808 | 1.04k | .and_then(|size| size.checked_mul(width as usize)) | 809 | 1.04k | .and_then(|size| size.checked_mul(height as usize)) | 810 | 1.04k | } |
<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::image_buffer_len Line | Count | Source | 806 | 136 | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 807 | 136 | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 808 | 136 | .and_then(|size| size.checked_mul(width as usize)) | 809 | 136 | .and_then(|size| size.checked_mul(height as usize)) | 810 | 136 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::image_buffer_len <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::image_buffer_len Line | Count | Source | 806 | 5.64k | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 807 | 5.64k | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 808 | 5.64k | .and_then(|size| size.checked_mul(width as usize)) | 809 | 5.64k | .and_then(|size| size.checked_mul(height as usize)) | 810 | 5.64k | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::image_buffer_len Line | Count | Source | 806 | 6 | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 807 | 6 | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 808 | 6 | .and_then(|size| size.checked_mul(width as usize)) | 809 | 6 | .and_then(|size| size.checked_mul(height as usize)) | 810 | 6 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::image_buffer_len <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::image_buffer_len Line | Count | Source | 806 | 4 | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 807 | 4 | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 808 | 4 | .and_then(|size| size.checked_mul(width as usize)) | 809 | 4 | .and_then(|size| size.checked_mul(height as usize)) | 810 | 4 | } |
<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::image_buffer_len Line | Count | Source | 806 | 1 | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 807 | 1 | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 808 | 1 | .and_then(|size| size.checked_mul(width as usize)) | 809 | 1 | .and_then(|size| size.checked_mul(height as usize)) | 810 | 1 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, &[u8]>>::image_buffer_len Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, &[u16]>>::image_buffer_len Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, &[u8]>>::image_buffer_len Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, &[u16]>>::image_buffer_len Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &[u8]>>::image_buffer_len Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, &[u16]>>::image_buffer_len Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, &[u8]>>::image_buffer_len Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, &[u16]>>::image_buffer_len <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len Line | Count | Source | 806 | 220 | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 807 | 220 | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 808 | 220 | .and_then(|size| size.checked_mul(width as usize)) | 809 | 220 | .and_then(|size| size.checked_mul(height as usize)) | 810 | 220 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len Line | Count | Source | 806 | 4 | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 807 | 4 | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 808 | 4 | .and_then(|size| size.checked_mul(width as usize)) | 809 | 4 | .and_then(|size| size.checked_mul(height as usize)) | 810 | 4 | } |
|
811 | | |
812 | | #[inline(always)] |
813 | 2.62M | fn pixel_indices(&self, x: u32, y: u32) -> Option<Range<usize>> { |
814 | 2.62M | if x >= self.width || y >= self.height { |
815 | 0 | return None; |
816 | 2.62M | } |
817 | 2.62M | |
818 | 2.62M | Some(self.pixel_indices_unchecked(x, y)) |
819 | 2.62M | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::pixel_indices Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::pixel_indices Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::pixel_indices Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::pixel_indices Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::pixel_indices Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::pixel_indices <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::pixel_indices Line | Count | Source | 813 | 2.62M | fn pixel_indices(&self, x: u32, y: u32) -> Option<Range<usize>> { | 814 | 2.62M | if x >= self.width || y >= self.height { | 815 | 0 | return None; | 816 | 2.62M | } | 817 | 2.62M | | 818 | 2.62M | Some(self.pixel_indices_unchecked(x, y)) | 819 | 2.62M | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::pixel_indices Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::pixel_indices Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::pixel_indices Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, &[u8]>>::pixel_indices Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, &[u8]>>::pixel_indices |
820 | | |
821 | | #[inline(always)] |
822 | 2.62M | fn pixel_indices_unchecked(&self, x: u32, y: u32) -> Range<usize> { |
823 | 2.62M | let no_channels = <P as Pixel>::CHANNEL_COUNT as usize; |
824 | 2.62M | // If in bounds, this can't overflow as we have tested that at construction! |
825 | 2.62M | let min_index = (y as usize * self.width as usize + x as usize) * no_channels; |
826 | 2.62M | min_index..min_index + no_channels |
827 | 2.62M | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::pixel_indices_unchecked Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::pixel_indices_unchecked Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::pixel_indices_unchecked Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::pixel_indices_unchecked Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::pixel_indices_unchecked Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::pixel_indices_unchecked <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::pixel_indices_unchecked Line | Count | Source | 822 | 2.62M | fn pixel_indices_unchecked(&self, x: u32, y: u32) -> Range<usize> { | 823 | 2.62M | let no_channels = <P as Pixel>::CHANNEL_COUNT as usize; | 824 | 2.62M | // If in bounds, this can't overflow as we have tested that at construction! | 825 | 2.62M | let min_index = (y as usize * self.width as usize + x as usize) * no_channels; | 826 | 2.62M | min_index..min_index + no_channels | 827 | 2.62M | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::pixel_indices_unchecked Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::pixel_indices_unchecked Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::pixel_indices_unchecked Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, &[u8]>>::pixel_indices_unchecked Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, &[u8]>>::pixel_indices_unchecked |
828 | | |
829 | | /// Get the format of the buffer when viewed as a matrix of samples. |
830 | 0 | pub fn sample_layout(&self) -> SampleLayout { |
831 | 0 | // None of these can overflow, as all our memory is addressable. |
832 | 0 | SampleLayout::row_major_packed(<P as Pixel>::CHANNEL_COUNT, self.width, self.height) |
833 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::sample_layout Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::sample_layout Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::sample_layout Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::sample_layout Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::sample_layout Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::sample_layout Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::sample_layout Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::sample_layout Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::sample_layout Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::sample_layout |
834 | | |
835 | | /// Return the raw sample buffer with its stride an dimension information. |
836 | | /// |
837 | | /// The returned buffer is guaranteed to be well formed in all cases. It is laid out by |
838 | | /// colors, width then height, meaning `channel_stride <= width_stride <= height_stride`. All |
839 | | /// strides are in numbers of elements but those are mostly `u8` in which case the strides are |
840 | | /// also byte strides. |
841 | 0 | pub fn into_flat_samples(self) -> FlatSamples<Container> |
842 | 0 | where |
843 | 0 | Container: AsRef<[P::Subpixel]>, |
844 | 0 | { |
845 | 0 | // None of these can overflow, as all our memory is addressable. |
846 | 0 | let layout = self.sample_layout(); |
847 | 0 | FlatSamples { |
848 | 0 | samples: self.data, |
849 | 0 | layout, |
850 | 0 | color_hint: None, // TODO: the pixel type might contain P::COLOR_TYPE if it satisfies PixelWithColorType |
851 | 0 | } |
852 | 0 | } |
853 | | |
854 | | /// Return a view on the raw sample buffer. |
855 | | /// |
856 | | /// See [`into_flat_samples`](#method.into_flat_samples) for more details. |
857 | 0 | pub fn as_flat_samples(&self) -> FlatSamples<&[P::Subpixel]> |
858 | 0 | where |
859 | 0 | Container: AsRef<[P::Subpixel]>, |
860 | 0 | { |
861 | 0 | let layout = self.sample_layout(); |
862 | 0 | FlatSamples { |
863 | 0 | samples: self.data.as_ref(), |
864 | 0 | layout, |
865 | 0 | color_hint: None, // TODO: the pixel type might contain P::COLOR_TYPE if it satisfies PixelWithColorType |
866 | 0 | } |
867 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::as_flat_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::as_flat_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::as_flat_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::as_flat_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::as_flat_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::as_flat_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::as_flat_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::as_flat_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::as_flat_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::as_flat_samples |
868 | | |
869 | | /// Return a mutable view on the raw sample buffer. |
870 | | /// |
871 | | /// See [`into_flat_samples`](#method.into_flat_samples) for more details. |
872 | 0 | pub fn as_flat_samples_mut(&mut self) -> FlatSamples<&mut [P::Subpixel]> |
873 | 0 | where |
874 | 0 | Container: AsMut<[P::Subpixel]>, |
875 | 0 | { |
876 | 0 | let layout = self.sample_layout(); |
877 | 0 | FlatSamples { |
878 | 0 | samples: self.data.as_mut(), |
879 | 0 | layout, |
880 | 0 | color_hint: None, // TODO: the pixel type might contain P::COLOR_TYPE if it satisfies PixelWithColorType |
881 | 0 | } |
882 | 0 | } |
883 | | } |
884 | | |
885 | | impl<P, Container> ImageBuffer<P, Container> |
886 | | where |
887 | | P: Pixel, |
888 | | Container: Deref<Target = [P::Subpixel]> + DerefMut, |
889 | | { |
890 | | // TODO: choose name under which to expose. |
891 | 112 | pub(crate) fn inner_pixels_mut(&mut self) -> &mut [P::Subpixel] { |
892 | 112 | let len = Self::image_buffer_len(self.width, self.height).unwrap(); |
893 | 112 | &mut self.data[..len] |
894 | 112 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::inner_pixels_mut <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::inner_pixels_mut Line | Count | Source | 891 | 110 | pub(crate) fn inner_pixels_mut(&mut self) -> &mut [P::Subpixel] { | 892 | 110 | let len = Self::image_buffer_len(self.width, self.height).unwrap(); | 893 | 110 | &mut self.data[..len] | 894 | 110 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::inner_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::inner_pixels_mut <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::inner_pixels_mut Line | Count | Source | 891 | 2 | pub(crate) fn inner_pixels_mut(&mut self) -> &mut [P::Subpixel] { | 892 | 2 | let len = Self::image_buffer_len(self.width, self.height).unwrap(); | 893 | 2 | &mut self.data[..len] | 894 | 2 | } |
|
895 | | |
896 | | /// Returns an iterator over the mutable pixels of this image. |
897 | 112 | pub fn pixels_mut(&mut self) -> PixelsMut<'_, P> { |
898 | 112 | PixelsMut { |
899 | 112 | chunks: self |
900 | 112 | .inner_pixels_mut() |
901 | 112 | .chunks_exact_mut(<P as Pixel>::CHANNEL_COUNT as usize), |
902 | 112 | } |
903 | 112 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::pixels_mut <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::pixels_mut Line | Count | Source | 897 | 110 | pub fn pixels_mut(&mut self) -> PixelsMut<'_, P> { | 898 | 110 | PixelsMut { | 899 | 110 | chunks: self | 900 | 110 | .inner_pixels_mut() | 901 | 110 | .chunks_exact_mut(<P as Pixel>::CHANNEL_COUNT as usize), | 902 | 110 | } | 903 | 110 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::pixels_mut <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::pixels_mut Line | Count | Source | 897 | 2 | pub fn pixels_mut(&mut self) -> PixelsMut<'_, P> { | 898 | 2 | PixelsMut { | 899 | 2 | chunks: self | 900 | 2 | .inner_pixels_mut() | 901 | 2 | .chunks_exact_mut(<P as Pixel>::CHANNEL_COUNT as usize), | 902 | 2 | } | 903 | 2 | } |
|
904 | | |
905 | | /// Returns an iterator over the mutable rows of this image. |
906 | | /// |
907 | | /// Only non-empty rows can be iterated in this manner. In particular the iterator will not |
908 | | /// yield any item when the width of the image is `0` or a pixel type without any channels is |
909 | | /// used. This ensures that its length can always be represented by `usize`. |
910 | 0 | pub fn rows_mut(&mut self) -> RowsMut<'_, P> { |
911 | 0 | RowsMut::with_image(&mut self.data, self.width, self.height) |
912 | 0 | } |
913 | | |
914 | | /// Enumerates over the pixels of the image. |
915 | | /// The iterator yields the coordinates of each pixel |
916 | | /// along with a mutable reference to them. |
917 | 112 | pub fn enumerate_pixels_mut(&mut self) -> EnumeratePixelsMut<'_, P> { |
918 | 112 | let width = self.width; |
919 | 112 | EnumeratePixelsMut { |
920 | 112 | pixels: self.pixels_mut(), |
921 | 112 | x: 0, |
922 | 112 | y: 0, |
923 | 112 | width, |
924 | 112 | } |
925 | 112 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::enumerate_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::enumerate_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::enumerate_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::enumerate_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::enumerate_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::enumerate_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::enumerate_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::enumerate_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::enumerate_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::enumerate_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::enumerate_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::enumerate_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::enumerate_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::enumerate_pixels_mut <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::enumerate_pixels_mut Line | Count | Source | 917 | 110 | pub fn enumerate_pixels_mut(&mut self) -> EnumeratePixelsMut<'_, P> { | 918 | 110 | let width = self.width; | 919 | 110 | EnumeratePixelsMut { | 920 | 110 | pixels: self.pixels_mut(), | 921 | 110 | x: 0, | 922 | 110 | y: 0, | 923 | 110 | width, | 924 | 110 | } | 925 | 110 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::enumerate_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::enumerate_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::enumerate_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::enumerate_pixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::enumerate_pixels_mut <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::enumerate_pixels_mut Line | Count | Source | 917 | 2 | pub fn enumerate_pixels_mut(&mut self) -> EnumeratePixelsMut<'_, P> { | 918 | 2 | let width = self.width; | 919 | 2 | EnumeratePixelsMut { | 920 | 2 | pixels: self.pixels_mut(), | 921 | 2 | x: 0, | 922 | 2 | y: 0, | 923 | 2 | width, | 924 | 2 | } | 925 | 2 | } |
|
926 | | |
927 | | /// Enumerates over the rows of the image. |
928 | | /// The iterator yields the y-coordinate of each row |
929 | | /// along with a mutable reference to them. |
930 | 0 | pub fn enumerate_rows_mut(&mut self) -> EnumerateRowsMut<'_, P> { |
931 | 0 | let width = self.width; |
932 | 0 | EnumerateRowsMut { |
933 | 0 | rows: self.rows_mut(), |
934 | 0 | y: 0, |
935 | 0 | width, |
936 | 0 | } |
937 | 0 | } |
938 | | |
939 | | /// Gets a reference to the mutable pixel at location `(x, y)` |
940 | | /// |
941 | | /// # Panics |
942 | | /// |
943 | | /// Panics if `(x, y)` is out of the bounds `(width, height)`. |
944 | | #[inline] |
945 | | #[track_caller] |
946 | 0 | pub fn get_pixel_mut(&mut self, x: u32, y: u32) -> &mut P { |
947 | 0 | match self.pixel_indices(x, y) { |
948 | 0 | None => panic!( |
949 | 0 | "Image index {:?} out of bounds {:?}", |
950 | 0 | (x, y), |
951 | 0 | (self.width, self.height) |
952 | 0 | ), |
953 | 0 | Some(pixel_indices) => <P as Pixel>::from_slice_mut(&mut self.data[pixel_indices]), |
954 | 0 | } |
955 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::get_pixel_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::get_pixel_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::get_pixel_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::get_pixel_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::get_pixel_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::get_pixel_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::get_pixel_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::get_pixel_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::get_pixel_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::get_pixel_mut |
956 | | |
957 | | /// Gets a reference to the mutable pixel at location `(x, y)` or returns |
958 | | /// `None` if the index is out of the bounds `(width, height)`. |
959 | 0 | pub fn get_pixel_mut_checked(&mut self, x: u32, y: u32) -> Option<&mut P> { |
960 | 0 | if x >= self.width { |
961 | 0 | return None; |
962 | 0 | } |
963 | 0 | let num_channels = <P as Pixel>::CHANNEL_COUNT as usize; |
964 | 0 | let i = (y as usize) |
965 | 0 | .saturating_mul(self.width as usize) |
966 | 0 | .saturating_add(x as usize) |
967 | 0 | .saturating_mul(num_channels); |
968 | 0 |
|
969 | 0 | self.data |
970 | 0 | .get_mut(i..i.checked_add(num_channels)?) |
971 | 0 | .map(|pixel_indices| <P as Pixel>::from_slice_mut(pixel_indices)) |
972 | 0 | } |
973 | | |
974 | | /// Puts a pixel at location `(x, y)` |
975 | | /// |
976 | | /// # Panics |
977 | | /// |
978 | | /// Panics if `(x, y)` is out of the bounds `(width, height)`. |
979 | | #[inline] |
980 | | #[track_caller] |
981 | 0 | pub fn put_pixel(&mut self, x: u32, y: u32, pixel: P) { |
982 | 0 | *self.get_pixel_mut(x, y) = pixel; |
983 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::put_pixel |
984 | | } |
985 | | |
986 | | impl<P, Container> ImageBuffer<P, Container> |
987 | | where |
988 | | P: Pixel, |
989 | | [P::Subpixel]: EncodableLayout, |
990 | | Container: Deref<Target = [P::Subpixel]>, |
991 | | { |
992 | | /// Saves the buffer to a file at the path specified. |
993 | | /// |
994 | | /// The image format is derived from the file extension. |
995 | 0 | pub fn save<Q>(&self, path: Q) -> ImageResult<()> |
996 | 0 | where |
997 | 0 | Q: AsRef<Path>, |
998 | 0 | P: PixelWithColorType, |
999 | 0 | { |
1000 | 0 | save_buffer( |
1001 | 0 | path, |
1002 | 0 | self.inner_pixels().as_bytes(), |
1003 | 0 | self.width(), |
1004 | 0 | self.height(), |
1005 | 0 | <P as PixelWithColorType>::COLOR_TYPE, |
1006 | 0 | ) |
1007 | 0 | } |
1008 | | } |
1009 | | |
1010 | | impl<P, Container> ImageBuffer<P, Container> |
1011 | | where |
1012 | | P: Pixel, |
1013 | | [P::Subpixel]: EncodableLayout, |
1014 | | Container: Deref<Target = [P::Subpixel]>, |
1015 | | { |
1016 | | /// Saves the buffer to a file at the specified path in |
1017 | | /// the specified format. |
1018 | | /// |
1019 | | /// See [`save_buffer_with_format`](fn.save_buffer_with_format.html) for |
1020 | | /// supported types. |
1021 | 0 | pub fn save_with_format<Q>(&self, path: Q, format: ImageFormat) -> ImageResult<()> |
1022 | 0 | where |
1023 | 0 | Q: AsRef<Path>, |
1024 | 0 | P: PixelWithColorType, |
1025 | 0 | { |
1026 | 0 | // This is valid as the subpixel is u8. |
1027 | 0 | save_buffer_with_format( |
1028 | 0 | path, |
1029 | 0 | self.inner_pixels().as_bytes(), |
1030 | 0 | self.width(), |
1031 | 0 | self.height(), |
1032 | 0 | <P as PixelWithColorType>::COLOR_TYPE, |
1033 | 0 | format, |
1034 | 0 | ) |
1035 | 0 | } |
1036 | | } |
1037 | | |
1038 | | impl<P, Container> ImageBuffer<P, Container> |
1039 | | where |
1040 | | P: Pixel, |
1041 | | [P::Subpixel]: EncodableLayout, |
1042 | | Container: Deref<Target = [P::Subpixel]>, |
1043 | | { |
1044 | | /// Writes the buffer to a writer in the specified format. |
1045 | | /// |
1046 | | /// Assumes the writer is buffered. In most cases, you should wrap your writer in a `BufWriter` |
1047 | | /// for best performance. |
1048 | 1.68k | pub fn write_to<W>(&self, writer: &mut W, format: ImageFormat) -> ImageResult<()> |
1049 | 1.68k | where |
1050 | 1.68k | W: std::io::Write + std::io::Seek, |
1051 | 1.68k | P: PixelWithColorType, |
1052 | 1.68k | { |
1053 | 1.68k | // This is valid as the subpixel is u8. |
1054 | 1.68k | write_buffer_with_format( |
1055 | 1.68k | writer, |
1056 | 1.68k | self.inner_pixels().as_bytes(), |
1057 | 1.68k | self.width(), |
1058 | 1.68k | self.height(), |
1059 | 1.68k | <P as PixelWithColorType>::COLOR_TYPE, |
1060 | 1.68k | format, |
1061 | 1.68k | ) |
1062 | 1.68k | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<_, _>>::write_to::<_> <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::write_to::<std::io::cursor::Cursor<alloc::vec::Vec<u8>>> Line | Count | Source | 1048 | 1.68k | pub fn write_to<W>(&self, writer: &mut W, format: ImageFormat) -> ImageResult<()> | 1049 | 1.68k | where | 1050 | 1.68k | W: std::io::Write + std::io::Seek, | 1051 | 1.68k | P: PixelWithColorType, | 1052 | 1.68k | { | 1053 | 1.68k | // This is valid as the subpixel is u8. | 1054 | 1.68k | write_buffer_with_format( | 1055 | 1.68k | writer, | 1056 | 1.68k | self.inner_pixels().as_bytes(), | 1057 | 1.68k | self.width(), | 1058 | 1.68k | self.height(), | 1059 | 1.68k | <P as PixelWithColorType>::COLOR_TYPE, | 1060 | 1.68k | format, | 1061 | 1.68k | ) | 1062 | 1.68k | } |
|
1063 | | } |
1064 | | |
1065 | | impl<P, Container> ImageBuffer<P, Container> |
1066 | | where |
1067 | | P: Pixel, |
1068 | | [P::Subpixel]: EncodableLayout, |
1069 | | Container: Deref<Target = [P::Subpixel]>, |
1070 | | { |
1071 | | /// Writes the buffer with the given encoder. |
1072 | 0 | pub fn write_with_encoder<E>(&self, encoder: E) -> ImageResult<()> |
1073 | 0 | where |
1074 | 0 | E: ImageEncoder, |
1075 | 0 | P: PixelWithColorType, |
1076 | 0 | { |
1077 | 0 | // This is valid as the subpixel is u8. |
1078 | 0 | encoder.write_image( |
1079 | 0 | self.inner_pixels().as_bytes(), |
1080 | 0 | self.width(), |
1081 | 0 | self.height(), |
1082 | 0 | <P as PixelWithColorType>::COLOR_TYPE, |
1083 | 0 | ) |
1084 | 0 | } |
1085 | | } |
1086 | | |
1087 | | impl<P, Container> Default for ImageBuffer<P, Container> |
1088 | | where |
1089 | | P: Pixel, |
1090 | | Container: Default, |
1091 | | { |
1092 | 0 | fn default() -> Self { |
1093 | 0 | Self { |
1094 | 0 | width: 0, |
1095 | 0 | height: 0, |
1096 | 0 | _phantom: PhantomData, |
1097 | 0 | data: Default::default(), |
1098 | 0 | } |
1099 | 0 | } |
1100 | | } |
1101 | | |
1102 | | impl<P, Container> Deref for ImageBuffer<P, Container> |
1103 | | where |
1104 | | P: Pixel, |
1105 | | Container: Deref<Target = [P::Subpixel]>, |
1106 | | { |
1107 | | type Target = [P::Subpixel]; |
1108 | | |
1109 | 0 | fn deref(&self) -> &<Self as Deref>::Target { |
1110 | 0 | &self.data |
1111 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as core::ops::deref::Deref>::deref Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as core::ops::deref::Deref>::deref Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as core::ops::deref::Deref>::deref Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as core::ops::deref::Deref>::deref Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as core::ops::deref::Deref>::deref Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as core::ops::deref::Deref>::deref Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as core::ops::deref::Deref>::deref Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as core::ops::deref::Deref>::deref Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as core::ops::deref::Deref>::deref Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as core::ops::deref::Deref>::deref |
1112 | | } |
1113 | | |
1114 | | impl<P, Container> DerefMut for ImageBuffer<P, Container> |
1115 | | where |
1116 | | P: Pixel, |
1117 | | Container: Deref<Target = [P::Subpixel]> + DerefMut, |
1118 | | { |
1119 | 0 | fn deref_mut(&mut self) -> &mut <Self as Deref>::Target { |
1120 | 0 | &mut self.data |
1121 | 0 | } |
1122 | | } |
1123 | | |
1124 | | impl<P, Container> Index<(u32, u32)> for ImageBuffer<P, Container> |
1125 | | where |
1126 | | P: Pixel, |
1127 | | Container: Deref<Target = [P::Subpixel]>, |
1128 | | { |
1129 | | type Output = P; |
1130 | | |
1131 | 0 | fn index(&self, (x, y): (u32, u32)) -> &P { |
1132 | 0 | self.get_pixel(x, y) |
1133 | 0 | } |
1134 | | } |
1135 | | |
1136 | | impl<P, Container> IndexMut<(u32, u32)> for ImageBuffer<P, Container> |
1137 | | where |
1138 | | P: Pixel, |
1139 | | Container: Deref<Target = [P::Subpixel]> + DerefMut, |
1140 | | { |
1141 | 0 | fn index_mut(&mut self, (x, y): (u32, u32)) -> &mut P { |
1142 | 0 | self.get_pixel_mut(x, y) |
1143 | 0 | } |
1144 | | } |
1145 | | |
1146 | | impl<P, Container> Clone for ImageBuffer<P, Container> |
1147 | | where |
1148 | | P: Pixel, |
1149 | | Container: Deref<Target = [P::Subpixel]> + Clone, |
1150 | | { |
1151 | 0 | fn clone(&self) -> ImageBuffer<P, Container> { |
1152 | 0 | ImageBuffer { |
1153 | 0 | data: self.data.clone(), |
1154 | 0 | width: self.width, |
1155 | 0 | height: self.height, |
1156 | 0 | _phantom: PhantomData, |
1157 | 0 | } |
1158 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as core::clone::Clone>::clone Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as core::clone::Clone>::clone Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as core::clone::Clone>::clone Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as core::clone::Clone>::clone Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as core::clone::Clone>::clone Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as core::clone::Clone>::clone Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as core::clone::Clone>::clone Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as core::clone::Clone>::clone Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as core::clone::Clone>::clone Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as core::clone::Clone>::clone |
1159 | | |
1160 | 0 | fn clone_from(&mut self, source: &Self) { |
1161 | 0 | self.data.clone_from(&source.data); |
1162 | 0 | self.width = source.width; |
1163 | 0 | self.height = source.height; |
1164 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as core::clone::Clone>::clone_from Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as core::clone::Clone>::clone_from Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as core::clone::Clone>::clone_from Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as core::clone::Clone>::clone_from Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as core::clone::Clone>::clone_from Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as core::clone::Clone>::clone_from Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as core::clone::Clone>::clone_from Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as core::clone::Clone>::clone_from Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as core::clone::Clone>::clone_from Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as core::clone::Clone>::clone_from |
1165 | | } |
1166 | | |
1167 | | impl<P, Container> GenericImageView for ImageBuffer<P, Container> |
1168 | | where |
1169 | | P: Pixel, |
1170 | | Container: Deref<Target = [P::Subpixel]> + Deref, |
1171 | | { |
1172 | | type Pixel = P; |
1173 | | |
1174 | 0 | fn dimensions(&self) -> (u32, u32) { |
1175 | 0 | self.dimensions() |
1176 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImageView>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImageView>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImageView>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImageView>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImageView>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImageView>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, &[u8]> as image::images::generic_image::GenericImageView>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, &[u8]> as image::images::generic_image::GenericImageView>::dimensions |
1177 | | |
1178 | 0 | fn get_pixel(&self, x: u32, y: u32) -> P { |
1179 | 0 | *self.get_pixel(x, y) |
1180 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImageView>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImageView>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImageView>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImageView>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImageView>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImageView>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, &[u8]> as image::images::generic_image::GenericImageView>::get_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, &[u8]> as image::images::generic_image::GenericImageView>::get_pixel |
1181 | | |
1182 | | /// Returns the pixel located at (x, y), ignoring bounds checking. |
1183 | | #[inline(always)] |
1184 | 0 | unsafe fn unsafe_get_pixel(&self, x: u32, y: u32) -> P { |
1185 | 0 | let indices = self.pixel_indices_unchecked(x, y); |
1186 | 0 | *<P as Pixel>::from_slice(self.data.get_unchecked(indices)) |
1187 | 0 | } |
1188 | | } |
1189 | | |
1190 | | impl<P, Container> GenericImage for ImageBuffer<P, Container> |
1191 | | where |
1192 | | P: Pixel, |
1193 | | Container: Deref<Target = [P::Subpixel]> + DerefMut, |
1194 | | { |
1195 | 0 | fn get_pixel_mut(&mut self, x: u32, y: u32) -> &mut P { |
1196 | 0 | self.get_pixel_mut(x, y) |
1197 | 0 | } |
1198 | | |
1199 | 0 | fn put_pixel(&mut self, x: u32, y: u32, pixel: P) { |
1200 | 0 | *self.get_pixel_mut(x, y) = pixel; |
1201 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImage>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImage>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::put_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::put_pixel |
1202 | | |
1203 | | /// Puts a pixel at location (x, y), ignoring bounds checking. |
1204 | | #[inline(always)] |
1205 | 0 | unsafe fn unsafe_put_pixel(&mut self, x: u32, y: u32, pixel: P) { |
1206 | 0 | let indices = self.pixel_indices_unchecked(x, y); |
1207 | 0 | let p = <P as Pixel>::from_slice_mut(self.data.get_unchecked_mut(indices)); |
1208 | 0 | *p = pixel; |
1209 | 0 | } |
1210 | | |
1211 | | /// Put a pixel at location (x, y), taking into account alpha channels |
1212 | | /// |
1213 | | /// DEPRECATED: This method will be removed. Blend the pixel directly instead. |
1214 | 0 | fn blend_pixel(&mut self, x: u32, y: u32, p: P) { |
1215 | 0 | self.get_pixel_mut(x, y).blend(&p); |
1216 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImage>::blend_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::blend_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::blend_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::blend_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::blend_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImage>::blend_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::blend_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::blend_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::blend_pixel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::blend_pixel |
1217 | | |
1218 | 0 | fn copy_within(&mut self, source: Rect, x: u32, y: u32) -> bool { |
1219 | 0 | let Rect { |
1220 | 0 | x: sx, |
1221 | 0 | y: sy, |
1222 | 0 | width, |
1223 | 0 | height, |
1224 | 0 | } = source; |
1225 | 0 | let dx = x; |
1226 | 0 | let dy = y; |
1227 | 0 | assert!(sx < self.width() && dx < self.width()); |
1228 | 0 | assert!(sy < self.height() && dy < self.height()); |
1229 | 0 | if self.width() - dx.max(sx) < width || self.height() - dy.max(sy) < height { |
1230 | 0 | return false; |
1231 | 0 | } |
1232 | 0 |
|
1233 | 0 | if sy < dy { |
1234 | 0 | for y in (0..height).rev() { |
1235 | 0 | let sy = sy + y; |
1236 | 0 | let dy = dy + y; |
1237 | 0 | let Range { start, .. } = self.pixel_indices_unchecked(sx, sy); |
1238 | 0 | let Range { end, .. } = self.pixel_indices_unchecked(sx + width - 1, sy); |
1239 | 0 | let dst = self.pixel_indices_unchecked(dx, dy).start; |
1240 | 0 | self.data.copy_within(start..end, dst); |
1241 | 0 | } |
1242 | | } else { |
1243 | 0 | for y in 0..height { |
1244 | 0 | let sy = sy + y; |
1245 | 0 | let dy = dy + y; |
1246 | 0 | let Range { start, .. } = self.pixel_indices_unchecked(sx, sy); |
1247 | 0 | let Range { end, .. } = self.pixel_indices_unchecked(sx + width - 1, sy); |
1248 | 0 | let dst = self.pixel_indices_unchecked(dx, dy).start; |
1249 | 0 | self.data.copy_within(start..end, dst); |
1250 | 0 | } |
1251 | | } |
1252 | 0 | true |
1253 | 0 | } |
1254 | | } |
1255 | | |
1256 | | // concrete implementation for `Vec`-backed buffers |
1257 | | // TODO: I think that rustc does not "see" this impl any more: the impl with |
1258 | | // Container meets the same requirements. At least, I got compile errors that |
1259 | | // there is no such function as `into_vec`, whereas `into_raw` did work, and |
1260 | | // `into_vec` is redundant anyway, because `into_raw` will give you the vector, |
1261 | | // and it is more generic. |
1262 | | impl<P: Pixel> ImageBuffer<P, Vec<P::Subpixel>> { |
1263 | | /// Creates a new image buffer based on a `Vec<P::Subpixel>`. |
1264 | | /// |
1265 | | /// all the pixels of this image have a value of zero, regardless of the data type or number of channels. |
1266 | | /// |
1267 | | /// # Panics |
1268 | | /// |
1269 | | /// Panics when the resulting image is larger than the maximum size of a vector. |
1270 | | #[must_use] |
1271 | 0 | pub fn new(width: u32, height: u32) -> ImageBuffer<P, Vec<P::Subpixel>> { |
1272 | 0 | let size = Self::image_buffer_len(width, height) |
1273 | 0 | .expect("Buffer length in `ImageBuffer::new` overflows usize"); |
1274 | 0 | ImageBuffer { |
1275 | 0 | data: vec![Zero::zero(); size], |
1276 | 0 | width, |
1277 | 0 | height, |
1278 | 0 | _phantom: PhantomData, |
1279 | 0 | } |
1280 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::new Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::new Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::new Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::new Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::new Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::new Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::new Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::new Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::new Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::new Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::new Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::new |
1281 | | |
1282 | | /// Constructs a new `ImageBuffer` by copying a pixel |
1283 | | /// |
1284 | | /// # Panics |
1285 | | /// |
1286 | | /// Panics when the resulting image is larger than the maximum size of a vector. |
1287 | 0 | pub fn from_pixel(width: u32, height: u32, pixel: P) -> ImageBuffer<P, Vec<P::Subpixel>> { |
1288 | 0 | let mut buf = ImageBuffer::new(width, height); |
1289 | 0 | for p in buf.pixels_mut() { |
1290 | 0 | *p = pixel; |
1291 | 0 | } |
1292 | 0 | buf |
1293 | 0 | } |
1294 | | |
1295 | | /// Constructs a new `ImageBuffer` by repeated application of the supplied function. |
1296 | | /// |
1297 | | /// The arguments to the function are the pixel's x and y coordinates. |
1298 | | /// |
1299 | | /// # Panics |
1300 | | /// |
1301 | | /// Panics when the resulting image is larger than the maximum size of a vector. |
1302 | 0 | pub fn from_fn<F>(width: u32, height: u32, mut f: F) -> ImageBuffer<P, Vec<P::Subpixel>> |
1303 | 0 | where |
1304 | 0 | F: FnMut(u32, u32) -> P, |
1305 | 0 | { |
1306 | 0 | let mut buf = ImageBuffer::new(width, height); |
1307 | 0 | for (x, y, p) in buf.enumerate_pixels_mut() { |
1308 | 0 | *p = f(x, y); |
1309 | 0 | } |
1310 | 0 | buf |
1311 | 0 | } |
1312 | | |
1313 | | /// Creates an image buffer out of an existing buffer. |
1314 | | /// Returns None if the buffer is not big enough. |
1315 | | #[must_use] |
1316 | 1.68k | pub fn from_vec( |
1317 | 1.68k | width: u32, |
1318 | 1.68k | height: u32, |
1319 | 1.68k | buf: Vec<P::Subpixel>, |
1320 | 1.68k | ) -> Option<ImageBuffer<P, Vec<P::Subpixel>>> { |
1321 | 1.68k | ImageBuffer::from_raw(width, height, buf) |
1322 | 1.68k | } |
1323 | | |
1324 | | /// Consumes the image buffer and returns the underlying data |
1325 | | /// as an owned buffer |
1326 | | #[must_use] |
1327 | 1.68k | pub fn into_vec(self) -> Vec<P::Subpixel> { |
1328 | 1.68k | self.into_raw() |
1329 | 1.68k | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<_, alloc::vec::Vec<<_ as image::traits::Pixel>::Subpixel>>>::into_vec <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::into_vec Line | Count | Source | 1327 | 1.68k | pub fn into_vec(self) -> Vec<P::Subpixel> { | 1328 | 1.68k | self.into_raw() | 1329 | 1.68k | } |
|
1330 | | } |
1331 | | |
1332 | | /// Provides color conversions for whole image buffers. |
1333 | | pub trait ConvertBuffer<T> { |
1334 | | /// Converts `self` to a buffer of type T |
1335 | | /// |
1336 | | /// A generic implementation is provided to convert any image buffer to a image buffer |
1337 | | /// based on a `Vec<T>`. |
1338 | | fn convert(&self) -> T; |
1339 | | } |
1340 | | |
1341 | | // concrete implementation Luma -> Rgba |
1342 | | impl GrayImage { |
1343 | | /// Expands a color palette by re-using the existing buffer. |
1344 | | /// Assumes 8 bit per pixel. Uses an optionally transparent index to |
1345 | | /// adjust it's alpha value accordingly. |
1346 | | #[must_use] |
1347 | | pub fn expand_palette( |
1348 | | self, |
1349 | | palette: &[(u8, u8, u8)], |
1350 | | transparent_idx: Option<u8>, |
1351 | | ) -> RgbaImage { |
1352 | | let (width, height) = self.dimensions(); |
1353 | | let mut data = self.into_raw(); |
1354 | | let entries = data.len(); |
1355 | | data.resize(entries.checked_mul(4).unwrap(), 0); |
1356 | | let mut buffer = ImageBuffer::from_vec(width, height, data).unwrap(); |
1357 | 0 | expand_packed(&mut buffer, 4, 8, |idx, pixel| { |
1358 | 0 | let (r, g, b) = palette[idx as usize]; |
1359 | 0 | let a = if let Some(t_idx) = transparent_idx { |
1360 | 0 | if t_idx == idx { |
1361 | 0 | 0 |
1362 | | } else { |
1363 | 0 | 255 |
1364 | | } |
1365 | | } else { |
1366 | 0 | 255 |
1367 | | }; |
1368 | 0 | pixel[0] = r; |
1369 | 0 | pixel[1] = g; |
1370 | 0 | pixel[2] = b; |
1371 | 0 | pixel[3] = a; |
1372 | 0 | }); |
1373 | | buffer |
1374 | | } |
1375 | | } |
1376 | | |
1377 | | // TODO: Equality constraints are not yet supported in where clauses, when they |
1378 | | // are, the T parameter should be removed in favor of ToType::Subpixel, which |
1379 | | // will then be FromType::Subpixel. |
1380 | | impl<Container, FromType: Pixel, ToType: Pixel> |
1381 | | ConvertBuffer<ImageBuffer<ToType, Vec<ToType::Subpixel>>> for ImageBuffer<FromType, Container> |
1382 | | where |
1383 | | Container: Deref<Target = [FromType::Subpixel]>, |
1384 | | ToType: FromColor<FromType>, |
1385 | | { |
1386 | | /// # Examples |
1387 | | /// Convert RGB image to gray image. |
1388 | | /// ```no_run |
1389 | | /// use image::buffer::ConvertBuffer; |
1390 | | /// use image::GrayImage; |
1391 | | /// |
1392 | | /// let image_path = "examples/fractal.png"; |
1393 | | /// let image = image::open(&image_path) |
1394 | | /// .expect("Open file failed") |
1395 | | /// .to_rgba8(); |
1396 | | /// |
1397 | | /// let gray_image: GrayImage = image.convert(); |
1398 | | /// ``` |
1399 | 0 | fn convert(&self) -> ImageBuffer<ToType, Vec<ToType::Subpixel>> { |
1400 | 0 | let mut buffer: ImageBuffer<ToType, Vec<ToType::Subpixel>> = |
1401 | 0 | ImageBuffer::new(self.width, self.height); |
1402 | 0 | for (to, from) in buffer.pixels_mut().zip(self.pixels()) { |
1403 | 0 | to.from_color(from); |
1404 | 0 | } |
1405 | 0 | buffer |
1406 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, &[u16]> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, &[u8]> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, &[u16]> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, &[u16]> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, &[u8]> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>>::convert Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, &[u16]> as image::images::buffer::ConvertBuffer<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>>::convert |
1407 | | } |
1408 | | |
1409 | | /// Sendable Rgb image buffer |
1410 | | pub type RgbImage = ImageBuffer<Rgb<u8>, Vec<u8>>; |
1411 | | /// Sendable Rgb + alpha channel image buffer |
1412 | | pub type RgbaImage = ImageBuffer<Rgba<u8>, Vec<u8>>; |
1413 | | /// Sendable grayscale image buffer |
1414 | | pub type GrayImage = ImageBuffer<Luma<u8>, Vec<u8>>; |
1415 | | /// Sendable grayscale + alpha channel image buffer |
1416 | | pub type GrayAlphaImage = ImageBuffer<LumaA<u8>, Vec<u8>>; |
1417 | | /// Sendable 16-bit Rgb image buffer |
1418 | | pub(crate) type Rgb16Image = ImageBuffer<Rgb<u16>, Vec<u16>>; |
1419 | | /// Sendable 16-bit Rgb + alpha channel image buffer |
1420 | | pub(crate) type Rgba16Image = ImageBuffer<Rgba<u16>, Vec<u16>>; |
1421 | | /// Sendable 16-bit grayscale image buffer |
1422 | | pub(crate) type Gray16Image = ImageBuffer<Luma<u16>, Vec<u16>>; |
1423 | | /// Sendable 16-bit grayscale + alpha channel image buffer |
1424 | | pub(crate) type GrayAlpha16Image = ImageBuffer<LumaA<u16>, Vec<u16>>; |
1425 | | |
1426 | | /// An image buffer for 32-bit float RGB pixels, |
1427 | | /// where the backing container is a flattened vector of floats. |
1428 | | pub type Rgb32FImage = ImageBuffer<Rgb<f32>, Vec<f32>>; |
1429 | | |
1430 | | /// An image buffer for 32-bit float RGBA pixels, |
1431 | | /// where the backing container is a flattened vector of floats. |
1432 | | pub type Rgba32FImage = ImageBuffer<Rgba<f32>, Vec<f32>>; |
1433 | | |
1434 | | impl From<DynamicImage> for RgbImage { |
1435 | | fn from(value: DynamicImage) -> Self { |
1436 | | value.into_rgb8() |
1437 | | } |
1438 | | } |
1439 | | |
1440 | | impl From<DynamicImage> for RgbaImage { |
1441 | | fn from(value: DynamicImage) -> Self { |
1442 | | value.into_rgba8() |
1443 | | } |
1444 | | } |
1445 | | |
1446 | | impl From<DynamicImage> for GrayImage { |
1447 | | fn from(value: DynamicImage) -> Self { |
1448 | | value.into_luma8() |
1449 | | } |
1450 | | } |
1451 | | |
1452 | | impl From<DynamicImage> for GrayAlphaImage { |
1453 | | fn from(value: DynamicImage) -> Self { |
1454 | | value.into_luma_alpha8() |
1455 | | } |
1456 | | } |
1457 | | |
1458 | | impl From<DynamicImage> for Rgb16Image { |
1459 | | fn from(value: DynamicImage) -> Self { |
1460 | | value.into_rgb16() |
1461 | | } |
1462 | | } |
1463 | | |
1464 | | impl From<DynamicImage> for Rgba16Image { |
1465 | | fn from(value: DynamicImage) -> Self { |
1466 | | value.into_rgba16() |
1467 | | } |
1468 | | } |
1469 | | |
1470 | | impl From<DynamicImage> for Gray16Image { |
1471 | | fn from(value: DynamicImage) -> Self { |
1472 | | value.into_luma16() |
1473 | | } |
1474 | | } |
1475 | | |
1476 | | impl From<DynamicImage> for GrayAlpha16Image { |
1477 | | fn from(value: DynamicImage) -> Self { |
1478 | | value.into_luma_alpha16() |
1479 | | } |
1480 | | } |
1481 | | |
1482 | | impl From<DynamicImage> for Rgba32FImage { |
1483 | | fn from(value: DynamicImage) -> Self { |
1484 | | value.into_rgba32f() |
1485 | | } |
1486 | | } |
1487 | | |
1488 | | #[cfg(test)] |
1489 | | mod test { |
1490 | | use super::{GrayImage, ImageBuffer, RgbImage}; |
1491 | | use crate::math::Rect; |
1492 | | use crate::GenericImage as _; |
1493 | | use crate::ImageFormat; |
1494 | | use crate::{Luma, LumaA, Pixel, Rgb, Rgba}; |
1495 | | use num_traits::Zero; |
1496 | | |
1497 | | #[test] |
1498 | | /// Tests if image buffers from slices work |
1499 | | fn slice_buffer() { |
1500 | | let data = [0; 9]; |
1501 | | let buf: ImageBuffer<Luma<u8>, _> = ImageBuffer::from_raw(3, 3, &data[..]).unwrap(); |
1502 | | assert_eq!(&*buf, &data[..]); |
1503 | | } |
1504 | | |
1505 | | macro_rules! new_buffer_zero_test { |
1506 | | ($test_name:ident, $pxt:ty) => { |
1507 | | #[test] |
1508 | | fn $test_name() { |
1509 | | let buffer = ImageBuffer::<$pxt, Vec<<$pxt as Pixel>::Subpixel>>::new(2, 2); |
1510 | | assert!(buffer |
1511 | | .iter() |
1512 | | .all(|p| *p == <$pxt as Pixel>::Subpixel::zero())); |
1513 | | } |
1514 | | }; |
1515 | | } |
1516 | | |
1517 | | new_buffer_zero_test!(luma_u8_zero_test, Luma<u8>); |
1518 | | new_buffer_zero_test!(luma_u16_zero_test, Luma<u16>); |
1519 | | new_buffer_zero_test!(luma_f32_zero_test, Luma<f32>); |
1520 | | new_buffer_zero_test!(luma_a_u8_zero_test, LumaA<u8>); |
1521 | | new_buffer_zero_test!(luma_a_u16_zero_test, LumaA<u16>); |
1522 | | new_buffer_zero_test!(luma_a_f32_zero_test, LumaA<f32>); |
1523 | | new_buffer_zero_test!(rgb_u8_zero_test, Rgb<u8>); |
1524 | | new_buffer_zero_test!(rgb_u16_zero_test, Rgb<u16>); |
1525 | | new_buffer_zero_test!(rgb_f32_zero_test, Rgb<f32>); |
1526 | | new_buffer_zero_test!(rgb_a_u8_zero_test, Rgba<u8>); |
1527 | | new_buffer_zero_test!(rgb_a_u16_zero_test, Rgba<u16>); |
1528 | | new_buffer_zero_test!(rgb_a_f32_zero_test, Rgba<f32>); |
1529 | | |
1530 | | #[test] |
1531 | | fn get_pixel() { |
1532 | | let mut a: RgbImage = ImageBuffer::new(10, 10); |
1533 | | { |
1534 | | let b = a.get_mut(3 * 10).unwrap(); |
1535 | | *b = 255; |
1536 | | } |
1537 | | assert_eq!(a.get_pixel(0, 1)[0], 255); |
1538 | | } |
1539 | | |
1540 | | #[test] |
1541 | | fn get_pixel_checked() { |
1542 | | let mut a: RgbImage = ImageBuffer::new(10, 10); |
1543 | | a.get_pixel_mut_checked(0, 1).unwrap()[0] = 255; |
1544 | | |
1545 | | assert_eq!(a.get_pixel_checked(0, 1), Some(&Rgb([255, 0, 0]))); |
1546 | | assert_eq!(a.get_pixel_checked(0, 1).unwrap(), a.get_pixel(0, 1)); |
1547 | | assert_eq!(a.get_pixel_checked(10, 0), None); |
1548 | | assert_eq!(a.get_pixel_checked(0, 10), None); |
1549 | | assert_eq!(a.get_pixel_mut_checked(10, 0), None); |
1550 | | assert_eq!(a.get_pixel_mut_checked(0, 10), None); |
1551 | | |
1552 | | // From image/issues/1672 |
1553 | | const WHITE: Rgb<u8> = Rgb([255_u8, 255, 255]); |
1554 | | let mut a = RgbImage::new(2, 1); |
1555 | | a.put_pixel(1, 0, WHITE); |
1556 | | |
1557 | | assert_eq!(a.get_pixel_checked(1, 0), Some(&WHITE)); |
1558 | | assert_eq!(a.get_pixel_checked(1, 0).unwrap(), a.get_pixel(1, 0)); |
1559 | | } |
1560 | | |
1561 | | #[test] |
1562 | | fn mut_iter() { |
1563 | | let mut a: RgbImage = ImageBuffer::new(10, 10); |
1564 | | { |
1565 | | let val = a.pixels_mut().next().unwrap(); |
1566 | | *val = Rgb([42, 0, 0]); |
1567 | | } |
1568 | | assert_eq!(a.data[0], 42); |
1569 | | } |
1570 | | |
1571 | | #[test] |
1572 | | fn zero_width_zero_height() { |
1573 | | let mut image = RgbImage::new(0, 0); |
1574 | | |
1575 | | assert_eq!(image.rows_mut().count(), 0); |
1576 | | assert_eq!(image.pixels_mut().count(), 0); |
1577 | | assert_eq!(image.rows().count(), 0); |
1578 | | assert_eq!(image.pixels().count(), 0); |
1579 | | } |
1580 | | |
1581 | | #[test] |
1582 | | fn zero_width_nonzero_height() { |
1583 | | let mut image = RgbImage::new(0, 2); |
1584 | | |
1585 | | assert_eq!(image.rows_mut().count(), 0); |
1586 | | assert_eq!(image.pixels_mut().count(), 0); |
1587 | | assert_eq!(image.rows().count(), 0); |
1588 | | assert_eq!(image.pixels().count(), 0); |
1589 | | } |
1590 | | |
1591 | | #[test] |
1592 | | fn nonzero_width_zero_height() { |
1593 | | let mut image = RgbImage::new(2, 0); |
1594 | | |
1595 | | assert_eq!(image.rows_mut().count(), 0); |
1596 | | assert_eq!(image.pixels_mut().count(), 0); |
1597 | | assert_eq!(image.rows().count(), 0); |
1598 | | assert_eq!(image.pixels().count(), 0); |
1599 | | } |
1600 | | |
1601 | | #[test] |
1602 | | fn pixels_on_large_buffer() { |
1603 | | let mut image = RgbImage::from_raw(1, 1, vec![0; 6]).unwrap(); |
1604 | | |
1605 | | assert_eq!(image.pixels().count(), 1); |
1606 | | assert_eq!(image.enumerate_pixels().count(), 1); |
1607 | | assert_eq!(image.pixels_mut().count(), 1); |
1608 | | assert_eq!(image.enumerate_pixels_mut().count(), 1); |
1609 | | |
1610 | | assert_eq!(image.rows().count(), 1); |
1611 | | assert_eq!(image.rows_mut().count(), 1); |
1612 | | } |
1613 | | |
1614 | | #[test] |
1615 | | fn default() { |
1616 | | let image = ImageBuffer::<Rgb<u8>, Vec<u8>>::default(); |
1617 | | assert_eq!(image.dimensions(), (0, 0)); |
1618 | | } |
1619 | | |
1620 | | #[test] |
1621 | | #[rustfmt::skip] |
1622 | | fn test_image_buffer_copy_within_oob() { |
1623 | | let mut image: GrayImage = ImageBuffer::from_raw(4, 4, vec![0u8; 16]).unwrap(); |
1624 | | assert!(!image.copy_within(Rect { x: 0, y: 0, width: 5, height: 4 }, 0, 0)); |
1625 | | assert!(!image.copy_within(Rect { x: 0, y: 0, width: 4, height: 5 }, 0, 0)); |
1626 | | assert!(!image.copy_within(Rect { x: 1, y: 0, width: 4, height: 4 }, 0, 0)); |
1627 | | assert!(!image.copy_within(Rect { x: 0, y: 0, width: 4, height: 4 }, 1, 0)); |
1628 | | assert!(!image.copy_within(Rect { x: 0, y: 1, width: 4, height: 4 }, 0, 0)); |
1629 | | assert!(!image.copy_within(Rect { x: 0, y: 0, width: 4, height: 4 }, 0, 1)); |
1630 | | assert!(!image.copy_within(Rect { x: 1, y: 1, width: 4, height: 4 }, 0, 0)); |
1631 | | } |
1632 | | |
1633 | | #[test] |
1634 | | fn test_image_buffer_copy_within_tl() { |
1635 | | let data = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; |
1636 | | let expected = [0, 1, 2, 3, 4, 0, 1, 2, 8, 4, 5, 6, 12, 8, 9, 10]; |
1637 | | let mut image: GrayImage = ImageBuffer::from_raw(4, 4, Vec::from(&data[..])).unwrap(); |
1638 | | assert!(image.copy_within( |
1639 | | Rect { |
1640 | | x: 0, |
1641 | | y: 0, |
1642 | | width: 3, |
1643 | | height: 3 |
1644 | | }, |
1645 | | 1, |
1646 | | 1 |
1647 | | )); |
1648 | | assert_eq!(&image.into_raw(), &expected); |
1649 | | } |
1650 | | |
1651 | | #[test] |
1652 | | fn test_image_buffer_copy_within_tr() { |
1653 | | let data = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; |
1654 | | let expected = [0, 1, 2, 3, 1, 2, 3, 7, 5, 6, 7, 11, 9, 10, 11, 15]; |
1655 | | let mut image: GrayImage = ImageBuffer::from_raw(4, 4, Vec::from(&data[..])).unwrap(); |
1656 | | assert!(image.copy_within( |
1657 | | Rect { |
1658 | | x: 1, |
1659 | | y: 0, |
1660 | | width: 3, |
1661 | | height: 3 |
1662 | | }, |
1663 | | 0, |
1664 | | 1 |
1665 | | )); |
1666 | | assert_eq!(&image.into_raw(), &expected); |
1667 | | } |
1668 | | |
1669 | | #[test] |
1670 | | fn test_image_buffer_copy_within_bl() { |
1671 | | let data = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; |
1672 | | let expected = [0, 4, 5, 6, 4, 8, 9, 10, 8, 12, 13, 14, 12, 13, 14, 15]; |
1673 | | let mut image: GrayImage = ImageBuffer::from_raw(4, 4, Vec::from(&data[..])).unwrap(); |
1674 | | assert!(image.copy_within( |
1675 | | Rect { |
1676 | | x: 0, |
1677 | | y: 1, |
1678 | | width: 3, |
1679 | | height: 3 |
1680 | | }, |
1681 | | 1, |
1682 | | 0 |
1683 | | )); |
1684 | | assert_eq!(&image.into_raw(), &expected); |
1685 | | } |
1686 | | |
1687 | | #[test] |
1688 | | fn test_image_buffer_copy_within_br() { |
1689 | | let data = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; |
1690 | | let expected = [5, 6, 7, 3, 9, 10, 11, 7, 13, 14, 15, 11, 12, 13, 14, 15]; |
1691 | | let mut image: GrayImage = ImageBuffer::from_raw(4, 4, Vec::from(&data[..])).unwrap(); |
1692 | | assert!(image.copy_within( |
1693 | | Rect { |
1694 | | x: 1, |
1695 | | y: 1, |
1696 | | width: 3, |
1697 | | height: 3 |
1698 | | }, |
1699 | | 0, |
1700 | | 0 |
1701 | | )); |
1702 | | assert_eq!(&image.into_raw(), &expected); |
1703 | | } |
1704 | | |
1705 | | #[test] |
1706 | | #[cfg(feature = "png")] |
1707 | | fn write_to_with_large_buffer() { |
1708 | | // A buffer of 1 pixel, padded to 4 bytes as would be common in, e.g. BMP. |
1709 | | |
1710 | | let img: GrayImage = ImageBuffer::from_raw(1, 1, vec![0u8; 4]).unwrap(); |
1711 | | let mut buffer = std::io::Cursor::new(vec![]); |
1712 | | assert!(img.write_to(&mut buffer, ImageFormat::Png).is_ok()); |
1713 | | } |
1714 | | |
1715 | | #[test] |
1716 | | fn exact_size_iter_size_hint() { |
1717 | | // The docs for `std::iter::ExactSizeIterator` requires that the implementation of |
1718 | | // `size_hint` on the iterator returns the same value as the `len` implementation. |
1719 | | |
1720 | | // This test should work for any size image. |
1721 | | const N: u32 = 10; |
1722 | | |
1723 | | let mut image = RgbImage::from_raw(N, N, vec![0; (N * N * 3) as usize]).unwrap(); |
1724 | | |
1725 | | let iter = image.pixels(); |
1726 | | let exact_len = ExactSizeIterator::len(&iter); |
1727 | | assert_eq!(iter.size_hint(), (exact_len, Some(exact_len))); |
1728 | | |
1729 | | let iter = image.pixels_mut(); |
1730 | | let exact_len = ExactSizeIterator::len(&iter); |
1731 | | assert_eq!(iter.size_hint(), (exact_len, Some(exact_len))); |
1732 | | |
1733 | | let iter = image.rows(); |
1734 | | let exact_len = ExactSizeIterator::len(&iter); |
1735 | | assert_eq!(iter.size_hint(), (exact_len, Some(exact_len))); |
1736 | | |
1737 | | let iter = image.rows_mut(); |
1738 | | let exact_len = ExactSizeIterator::len(&iter); |
1739 | | assert_eq!(iter.size_hint(), (exact_len, Some(exact_len))); |
1740 | | |
1741 | | let iter = image.enumerate_pixels(); |
1742 | | let exact_len = ExactSizeIterator::len(&iter); |
1743 | | assert_eq!(iter.size_hint(), (exact_len, Some(exact_len))); |
1744 | | |
1745 | | let iter = image.enumerate_rows(); |
1746 | | let exact_len = ExactSizeIterator::len(&iter); |
1747 | | assert_eq!(iter.size_hint(), (exact_len, Some(exact_len))); |
1748 | | |
1749 | | let iter = image.enumerate_pixels_mut(); |
1750 | | let exact_len = ExactSizeIterator::len(&iter); |
1751 | | assert_eq!(iter.size_hint(), (exact_len, Some(exact_len))); |
1752 | | |
1753 | | let iter = image.enumerate_rows_mut(); |
1754 | | let exact_len = ExactSizeIterator::len(&iter); |
1755 | | assert_eq!(iter.size_hint(), (exact_len, Some(exact_len))); |
1756 | | } |
1757 | | } |
1758 | | |
1759 | | #[cfg(test)] |
1760 | | #[cfg(feature = "benchmarks")] |
1761 | | mod benchmarks { |
1762 | | use super::{ConvertBuffer, GrayImage, ImageBuffer, Pixel, RgbImage}; |
1763 | | |
1764 | | #[bench] |
1765 | | fn conversion(b: &mut test::Bencher) { |
1766 | | let mut a: RgbImage = ImageBuffer::new(1000, 1000); |
1767 | | for p in a.pixels_mut() { |
1768 | | let rgb = p.channels_mut(); |
1769 | | rgb[0] = 255; |
1770 | | rgb[1] = 23; |
1771 | | rgb[2] = 42; |
1772 | | } |
1773 | | assert!(a.data[0] != 0); |
1774 | | b.iter(|| { |
1775 | | let b: GrayImage = a.convert(); |
1776 | | assert!(0 != b.data[0]); |
1777 | | assert!(a.data[0] != b.data[0]); |
1778 | | test::black_box(b); |
1779 | | }); |
1780 | | b.bytes = 1000 * 1000 * 3; |
1781 | | } |
1782 | | |
1783 | | #[bench] |
1784 | | fn image_access_row_by_row(b: &mut test::Bencher) { |
1785 | | let mut a: RgbImage = ImageBuffer::new(1000, 1000); |
1786 | | for p in a.pixels_mut() { |
1787 | | let rgb = p.channels_mut(); |
1788 | | rgb[0] = 255; |
1789 | | rgb[1] = 23; |
1790 | | rgb[2] = 42; |
1791 | | } |
1792 | | |
1793 | | b.iter(move || { |
1794 | | let image: &RgbImage = test::black_box(&a); |
1795 | | let mut sum: usize = 0; |
1796 | | for y in 0..1000 { |
1797 | | for x in 0..1000 { |
1798 | | let pixel = image.get_pixel(x, y); |
1799 | | sum = sum.wrapping_add(pixel[0] as usize); |
1800 | | sum = sum.wrapping_add(pixel[1] as usize); |
1801 | | sum = sum.wrapping_add(pixel[2] as usize); |
1802 | | } |
1803 | | } |
1804 | | test::black_box(sum) |
1805 | | }); |
1806 | | |
1807 | | b.bytes = 1000 * 1000 * 3; |
1808 | | } |
1809 | | |
1810 | | #[bench] |
1811 | | fn image_access_col_by_col(b: &mut test::Bencher) { |
1812 | | let mut a: RgbImage = ImageBuffer::new(1000, 1000); |
1813 | | for p in a.pixels_mut() { |
1814 | | let rgb = p.channels_mut(); |
1815 | | rgb[0] = 255; |
1816 | | rgb[1] = 23; |
1817 | | rgb[2] = 42; |
1818 | | } |
1819 | | |
1820 | | b.iter(move || { |
1821 | | let image: &RgbImage = test::black_box(&a); |
1822 | | let mut sum: usize = 0; |
1823 | | for x in 0..1000 { |
1824 | | for y in 0..1000 { |
1825 | | let pixel = image.get_pixel(x, y); |
1826 | | sum = sum.wrapping_add(pixel[0] as usize); |
1827 | | sum = sum.wrapping_add(pixel[1] as usize); |
1828 | | sum = sum.wrapping_add(pixel[2] as usize); |
1829 | | } |
1830 | | } |
1831 | | test::black_box(sum) |
1832 | | }); |
1833 | | |
1834 | | b.bytes = 1000 * 1000 * 3; |
1835 | | } |
1836 | | } |