/src/image/src/images/buffer.rs
Line | Count | Source |
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, FromPrimitive, Luma, LumaA, Rgb, Rgba}; |
10 | | use crate::error::{ |
11 | | ImageResult, ParameterError, ParameterErrorKind, UnsupportedError, UnsupportedErrorKind, |
12 | | }; |
13 | | use crate::flat::{FlatSamples, SampleLayout, ViewMutOfPixel, ViewOfPixel}; |
14 | | use crate::math::Rect; |
15 | | use crate::metadata::cicp::{CicpApplicable, CicpPixelCast, CicpRgb, ColorComponentForCicp}; |
16 | | use crate::traits::{EncodableLayout, Pixel, PixelWithColorType}; |
17 | | use crate::{ |
18 | | metadata::{Cicp, CicpColorPrimaries, CicpTransferCharacteristics, CicpTransform}, |
19 | | save_buffer, save_buffer_with_format, write_buffer_with_format, ImageError, |
20 | | }; |
21 | | use crate::{DynamicImage, GenericImage, GenericImageView, ImageEncoder, ImageFormat, Primitive}; |
22 | | |
23 | | /// Iterate over rows of an image |
24 | | /// |
25 | | /// This iterator is created with [`ImageBuffer::rows`]. See its document for details. |
26 | | pub struct Rows<'a, P: Pixel + 'a> { |
27 | | pixels: ChunksExact<'a, P>, |
28 | | } |
29 | | |
30 | | impl<'a, P: Pixel + 'a> Rows<'a, P> { |
31 | | /// Construct the iterator from image pixels. This is not public since it has a (hidden) panic |
32 | | /// condition. The `pixels` slice must be large enough so that all pixels are addressable. |
33 | 0 | fn with_image(pixels: &'a [P], width: u32, height: u32) -> Self { |
34 | 0 | assert_eq!( |
35 | 0 | Some(pixels.len()), |
36 | 0 | (width as usize).checked_mul(height as usize) |
37 | | ); |
38 | | |
39 | 0 | if width == 0 { |
40 | 0 | Rows { |
41 | 0 | pixels: [].chunks_exact(1), |
42 | 0 | } |
43 | | } else { |
44 | 0 | Rows { |
45 | 0 | pixels: pixels.chunks_exact(width as usize), |
46 | 0 | } |
47 | | } |
48 | 0 | } Unexecuted instantiation: <image::images::buffer::Rows<image::color::Rgba<u8>>>::with_image Unexecuted instantiation: <image::images::buffer::Rows<image::color::Rgba<u16>>>::with_image Unexecuted instantiation: <image::images::buffer::Rows<image::color::LumaA<u8>>>::with_image Unexecuted instantiation: <image::images::buffer::Rows<image::color::LumaA<u16>>>::with_image |
49 | | } |
50 | | |
51 | | impl<'a, P: Pixel + 'a> Iterator for Rows<'a, P> |
52 | | where |
53 | | P::Subpixel: 'a, |
54 | | { |
55 | | type Item = &'a [P]; |
56 | | |
57 | | #[inline(always)] |
58 | 0 | fn next(&mut self) -> Option<&'a [P]> { |
59 | 0 | self.pixels.next() |
60 | 0 | } Unexecuted instantiation: <image::images::buffer::Rows<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::Rows<image::color::Rgba<u16>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::Rows<image::color::LumaA<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::Rows<image::color::LumaA<u16>> as core::iter::traits::iterator::Iterator>::next |
61 | | |
62 | | #[inline(always)] |
63 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
64 | 0 | let len = self.len(); |
65 | 0 | (len, Some(len)) |
66 | 0 | } |
67 | | } |
68 | | |
69 | | impl<'a, P: Pixel + 'a> ExactSizeIterator for Rows<'a, P> |
70 | | where |
71 | | P::Subpixel: 'a, |
72 | | { |
73 | 0 | fn len(&self) -> usize { |
74 | 0 | self.pixels.len() |
75 | 0 | } |
76 | | } |
77 | | |
78 | | impl<'a, P: Pixel + 'a> DoubleEndedIterator for Rows<'a, P> |
79 | | where |
80 | | P::Subpixel: 'a, |
81 | | { |
82 | | #[inline(always)] |
83 | 0 | fn next_back(&mut self) -> Option<&'a [P]> { |
84 | 0 | self.pixels.next_back() |
85 | 0 | } |
86 | | } |
87 | | |
88 | | impl<P: Pixel> Clone for Rows<'_, P> { |
89 | 0 | fn clone(&self) -> Self { |
90 | 0 | Rows { |
91 | 0 | pixels: self.pixels.clone(), |
92 | 0 | } |
93 | 0 | } |
94 | | } |
95 | | |
96 | | impl<P: Pixel> fmt::Debug for Rows<'_, P> |
97 | | where |
98 | | P: fmt::Debug, |
99 | | { |
100 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
101 | 0 | f.debug_struct("Rows") |
102 | 0 | .field("pixels", &self.pixels) |
103 | 0 | .finish() |
104 | 0 | } |
105 | | } |
106 | | |
107 | | /// Iterate over mutable rows of an image |
108 | | /// |
109 | | /// This iterator is created with [`ImageBuffer::rows_mut`]. See its document for details. |
110 | | pub struct RowsMut<'a, P: Pixel + 'a> { |
111 | | pixels: ChunksExactMut<'a, P>, |
112 | | } |
113 | | |
114 | | impl<'a, P: Pixel + 'a> RowsMut<'a, P> { |
115 | | /// Construct the iterator from image pixels. This is not public since it has a (hidden) panic |
116 | | /// condition. The `pixels` slice must be large enough so that all pixels are addressable. |
117 | 0 | fn with_image(pixels: &'a mut [P], width: u32, height: u32) -> Self { |
118 | 0 | assert_eq!( |
119 | 0 | Some(pixels.len()), |
120 | 0 | (width as usize).checked_mul(height as usize) |
121 | | ); |
122 | | |
123 | 0 | if width == 0 { |
124 | 0 | RowsMut { |
125 | 0 | pixels: [].chunks_exact_mut(1), |
126 | 0 | } |
127 | | } else { |
128 | 0 | RowsMut { |
129 | 0 | pixels: pixels.chunks_exact_mut(width as usize), |
130 | 0 | } |
131 | | } |
132 | 0 | } Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Rgb<f32>>>::with_image Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Rgb<u8>>>::with_image Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Rgb<u16>>>::with_image Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Luma<f32>>>::with_image Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Luma<u8>>>::with_image Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Luma<u16>>>::with_image Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Rgba<f32>>>::with_image Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Rgba<u8>>>::with_image Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Rgba<u16>>>::with_image Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::LumaA<f32>>>::with_image Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::LumaA<u8>>>::with_image Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::LumaA<u16>>>::with_image |
133 | | } |
134 | | |
135 | | impl<'a, P: Pixel + 'a> Iterator for RowsMut<'a, P> |
136 | | where |
137 | | P::Subpixel: 'a, |
138 | | { |
139 | | type Item = &'a mut [P]; |
140 | | |
141 | | #[inline(always)] |
142 | 0 | fn next(&mut self) -> Option<&'a mut [P]> { |
143 | 0 | self.pixels.next() |
144 | 0 | } Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Rgb<f32>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Rgb<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Rgb<u16>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Luma<f32>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Luma<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Luma<u16>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Rgba<f32>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::Rgba<u16>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::LumaA<f32>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::LumaA<u8>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::RowsMut<image::color::LumaA<u16>> as core::iter::traits::iterator::Iterator>::next |
145 | | |
146 | | #[inline(always)] |
147 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
148 | 0 | let len = self.len(); |
149 | 0 | (len, Some(len)) |
150 | 0 | } |
151 | | } |
152 | | |
153 | | impl<'a, P: Pixel + 'a> ExactSizeIterator for RowsMut<'a, P> |
154 | | where |
155 | | P::Subpixel: 'a, |
156 | | { |
157 | 0 | fn len(&self) -> usize { |
158 | 0 | self.pixels.len() |
159 | 0 | } |
160 | | } |
161 | | |
162 | | impl<'a, P: Pixel + 'a> DoubleEndedIterator for RowsMut<'a, P> |
163 | | where |
164 | | P::Subpixel: 'a, |
165 | | { |
166 | | #[inline(always)] |
167 | 0 | fn next_back(&mut self) -> Option<&'a mut [P]> { |
168 | 0 | self.pixels.next_back() |
169 | 0 | } |
170 | | } |
171 | | |
172 | | impl<P: Pixel> fmt::Debug for RowsMut<'_, P> |
173 | | where |
174 | | P: fmt::Debug, |
175 | | { |
176 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
177 | 0 | f.debug_struct("RowsMut") |
178 | 0 | .field("pixels", &self.pixels) |
179 | 0 | .finish() |
180 | 0 | } |
181 | | } |
182 | | |
183 | | /// Enumerate the pixels of an image. |
184 | | pub struct EnumeratePixels<'a, P: Pixel + 'a> |
185 | | where |
186 | | <P as Pixel>::Subpixel: 'a, |
187 | | { |
188 | | pixels: std::slice::Iter<'a, P>, |
189 | | x: u32, |
190 | | y: u32, |
191 | | width: u32, |
192 | | } |
193 | | |
194 | | impl<'a, P: Pixel + 'a> Iterator for EnumeratePixels<'a, P> |
195 | | where |
196 | | P::Subpixel: 'a, |
197 | | { |
198 | | type Item = (u32, u32, &'a P); |
199 | | |
200 | | #[inline(always)] |
201 | 0 | fn next(&mut self) -> Option<(u32, u32, &'a P)> { |
202 | 0 | if self.x >= self.width { |
203 | 0 | self.x = 0; |
204 | 0 | self.y += 1; |
205 | 0 | } |
206 | 0 | let (x, y) = (self.x, self.y); |
207 | 0 | self.x += 1; |
208 | 0 | self.pixels.next().map(|p| (x, y, p)) |
209 | 0 | } |
210 | | |
211 | | #[inline(always)] |
212 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
213 | 0 | let len = self.len(); |
214 | 0 | (len, Some(len)) |
215 | 0 | } |
216 | | } |
217 | | |
218 | | impl<'a, P: Pixel + 'a> ExactSizeIterator for EnumeratePixels<'a, P> |
219 | | where |
220 | | P::Subpixel: 'a, |
221 | | { |
222 | 0 | fn len(&self) -> usize { |
223 | 0 | self.pixels.len() |
224 | 0 | } |
225 | | } |
226 | | |
227 | | impl<P: Pixel> Clone for EnumeratePixels<'_, P> { |
228 | 0 | fn clone(&self) -> Self { |
229 | 0 | EnumeratePixels { |
230 | 0 | pixels: self.pixels.clone(), |
231 | 0 | ..*self |
232 | 0 | } |
233 | 0 | } |
234 | | } |
235 | | |
236 | | impl<P: Pixel> fmt::Debug for EnumeratePixels<'_, P> |
237 | | where |
238 | | P: fmt::Debug, |
239 | | { |
240 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
241 | 0 | f.debug_struct("EnumeratePixels") |
242 | 0 | .field("pixels", &self.pixels) |
243 | 0 | .field("x", &self.x) |
244 | 0 | .field("y", &self.y) |
245 | 0 | .field("width", &self.width) |
246 | 0 | .finish() |
247 | 0 | } |
248 | | } |
249 | | |
250 | | /// Enumerate the rows of an image. |
251 | | pub struct EnumerateRows<'a, P: Pixel + 'a> |
252 | | where |
253 | | <P as Pixel>::Subpixel: 'a, |
254 | | { |
255 | | rows: Rows<'a, P>, |
256 | | y: u32, |
257 | | width: u32, |
258 | | } |
259 | | |
260 | | impl<'a, P: Pixel + 'a> Iterator for EnumerateRows<'a, P> |
261 | | where |
262 | | P::Subpixel: 'a, |
263 | | { |
264 | | type Item = (u32, EnumeratePixels<'a, P>); |
265 | | |
266 | | #[inline(always)] |
267 | 0 | fn next(&mut self) -> Option<(u32, EnumeratePixels<'a, P>)> { |
268 | 0 | let y = self.y; |
269 | 0 | self.y += 1; |
270 | 0 | self.rows.next().map(|r| { |
271 | 0 | ( |
272 | 0 | y, |
273 | 0 | EnumeratePixels { |
274 | 0 | x: 0, |
275 | 0 | y, |
276 | 0 | width: self.width, |
277 | 0 | pixels: r.iter(), |
278 | 0 | }, |
279 | 0 | ) |
280 | 0 | }) |
281 | 0 | } |
282 | | |
283 | | #[inline(always)] |
284 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
285 | 0 | let len = self.len(); |
286 | 0 | (len, Some(len)) |
287 | 0 | } |
288 | | } |
289 | | |
290 | | impl<'a, P: Pixel + 'a> ExactSizeIterator for EnumerateRows<'a, P> |
291 | | where |
292 | | P::Subpixel: 'a, |
293 | | { |
294 | 0 | fn len(&self) -> usize { |
295 | 0 | self.rows.len() |
296 | 0 | } |
297 | | } |
298 | | |
299 | | impl<P: Pixel> Clone for EnumerateRows<'_, P> { |
300 | 0 | fn clone(&self) -> Self { |
301 | 0 | EnumerateRows { |
302 | 0 | rows: self.rows.clone(), |
303 | 0 | ..*self |
304 | 0 | } |
305 | 0 | } |
306 | | } |
307 | | |
308 | | impl<P: Pixel> fmt::Debug for EnumerateRows<'_, P> |
309 | | where |
310 | | P: fmt::Debug, |
311 | | { |
312 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
313 | 0 | f.debug_struct("EnumerateRows") |
314 | 0 | .field("rows", &self.rows) |
315 | 0 | .field("y", &self.y) |
316 | 0 | .field("width", &self.width) |
317 | 0 | .finish() |
318 | 0 | } |
319 | | } |
320 | | |
321 | | /// Enumerate the pixels of an image. |
322 | | pub struct EnumeratePixelsMut<'a, P: Pixel + 'a> |
323 | | where |
324 | | <P as Pixel>::Subpixel: 'a, |
325 | | { |
326 | | pixels: std::slice::IterMut<'a, P>, |
327 | | x: u32, |
328 | | y: u32, |
329 | | width: u32, |
330 | | } |
331 | | |
332 | | impl<'a, P: Pixel + 'a> Iterator for EnumeratePixelsMut<'a, P> |
333 | | where |
334 | | P::Subpixel: 'a, |
335 | | { |
336 | | type Item = (u32, u32, &'a mut P); |
337 | | |
338 | | #[inline(always)] |
339 | 9.08G | fn next(&mut self) -> Option<(u32, u32, &'a mut P)> { |
340 | 9.08G | if self.x >= self.width { |
341 | 9.30M | self.x = 0; |
342 | 9.30M | self.y += 1; |
343 | 9.07G | } |
344 | 9.08G | let (x, y) = (self.x, self.y); |
345 | 9.08G | self.x += 1; |
346 | 9.08G | 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<f32>> 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 | 346 | 9.08G | 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<f32>> 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} |
347 | 9.08G | } <image::images::buffer::EnumeratePixelsMut<image::color::Rgba<u8>> as core::iter::traits::iterator::Iterator>::next Line | Count | Source | 339 | 9.08G | fn next(&mut self) -> Option<(u32, u32, &'a mut P)> { | 340 | 9.08G | if self.x >= self.width { | 341 | 9.30M | self.x = 0; | 342 | 9.30M | self.y += 1; | 343 | 9.07G | } | 344 | 9.08G | let (x, y) = (self.x, self.y); | 345 | 9.08G | self.x += 1; | 346 | 9.08G | self.pixels.next().map(|p| (x, y, p)) | 347 | 9.08G | } |
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<f32>> 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<u16>> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <image::images::buffer::EnumeratePixelsMut<image::color::LumaA<f32>> 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 |
348 | | |
349 | | #[inline(always)] |
350 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
351 | 0 | let len = self.len(); |
352 | 0 | (len, Some(len)) |
353 | 0 | } |
354 | | } |
355 | | |
356 | | impl<'a, P: Pixel + 'a> ExactSizeIterator for EnumeratePixelsMut<'a, P> |
357 | | where |
358 | | P::Subpixel: 'a, |
359 | | { |
360 | 0 | fn len(&self) -> usize { |
361 | 0 | self.pixels.len() |
362 | 0 | } |
363 | | } |
364 | | |
365 | | impl<P: Pixel> fmt::Debug for EnumeratePixelsMut<'_, P> |
366 | | where |
367 | | P: fmt::Debug, |
368 | | { |
369 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
370 | 0 | f.debug_struct("EnumeratePixelsMut") |
371 | 0 | .field("pixels", &self.pixels) |
372 | 0 | .field("x", &self.x) |
373 | 0 | .field("y", &self.y) |
374 | 0 | .field("width", &self.width) |
375 | 0 | .finish() |
376 | 0 | } |
377 | | } |
378 | | |
379 | | /// Enumerate the rows of an image. |
380 | | pub struct EnumerateRowsMut<'a, P: Pixel + 'a> |
381 | | where |
382 | | <P as Pixel>::Subpixel: 'a, |
383 | | { |
384 | | rows: RowsMut<'a, P>, |
385 | | y: u32, |
386 | | width: u32, |
387 | | } |
388 | | |
389 | | impl<'a, P: Pixel + 'a> Iterator for EnumerateRowsMut<'a, P> |
390 | | where |
391 | | P::Subpixel: 'a, |
392 | | { |
393 | | type Item = (u32, EnumeratePixelsMut<'a, P>); |
394 | | |
395 | | #[inline(always)] |
396 | 0 | fn next(&mut self) -> Option<(u32, EnumeratePixelsMut<'a, P>)> { |
397 | 0 | let y = self.y; |
398 | 0 | self.y += 1; |
399 | 0 | self.rows.next().map(|r| { |
400 | 0 | ( |
401 | 0 | y, |
402 | 0 | EnumeratePixelsMut { |
403 | 0 | x: 0, |
404 | 0 | y, |
405 | 0 | width: self.width, |
406 | 0 | pixels: r.iter_mut(), |
407 | 0 | }, |
408 | 0 | ) |
409 | 0 | }) |
410 | 0 | } |
411 | | |
412 | | #[inline(always)] |
413 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
414 | 0 | let len = self.len(); |
415 | 0 | (len, Some(len)) |
416 | 0 | } |
417 | | } |
418 | | |
419 | | impl<'a, P: Pixel + 'a> ExactSizeIterator for EnumerateRowsMut<'a, P> |
420 | | where |
421 | | P::Subpixel: 'a, |
422 | | { |
423 | 0 | fn len(&self) -> usize { |
424 | 0 | self.rows.len() |
425 | 0 | } |
426 | | } |
427 | | |
428 | | impl<P: Pixel> fmt::Debug for EnumerateRowsMut<'_, P> |
429 | | where |
430 | | P: fmt::Debug, |
431 | | { |
432 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
433 | 0 | f.debug_struct("EnumerateRowsMut") |
434 | 0 | .field("rows", &self.rows) |
435 | 0 | .field("y", &self.y) |
436 | 0 | .field("width", &self.width) |
437 | 0 | .finish() |
438 | 0 | } |
439 | | } |
440 | | |
441 | | /// Generic image buffer |
442 | | /// |
443 | | /// This is an image parameterised by its Pixel types, represented by a width and height and a |
444 | | /// container of channel data. It provides direct access to its pixels and implements the |
445 | | /// [`GenericImageView`] and [`GenericImage`] traits. In many ways, this is the standard buffer |
446 | | /// implementing those traits. Using this concrete type instead of a generic type parameter has |
447 | | /// been shown to improve performance. |
448 | | /// |
449 | | /// The crate defines a few type aliases with regularly used pixel types for your convenience, such |
450 | | /// as [`RgbImage`], [`GrayImage`] etc. |
451 | | /// |
452 | | /// To convert between images of different Pixel types use [`DynamicImage`]. |
453 | | /// |
454 | | /// You can retrieve a complete description of the buffer's layout and contents through |
455 | | /// [`as_flat_samples`] and [`as_flat_samples_mut`]. This can be handy to also use the contents in |
456 | | /// a foreign language, map it as a GPU host buffer or other similar tasks. |
457 | | /// |
458 | | /// [`as_flat_samples`]: Self::as_flat_samples |
459 | | /// [`as_flat_samples_mut`]: Self::as_flat_samples_mut |
460 | | /// |
461 | | /// ## Examples |
462 | | /// |
463 | | /// Create a simple canvas and paint a small cross. |
464 | | /// |
465 | | /// ``` |
466 | | /// use image::{RgbImage, Rgb}; |
467 | | /// |
468 | | /// let mut img = RgbImage::new(32, 32); |
469 | | /// |
470 | | /// for x in 15..=17 { |
471 | | /// for y in 8..24 { |
472 | | /// img.put_pixel(x, y, Rgb([255, 0, 0])); |
473 | | /// img.put_pixel(y, x, Rgb([255, 0, 0])); |
474 | | /// } |
475 | | /// } |
476 | | /// ``` |
477 | | /// |
478 | | /// Overlays an image on top of a larger background raster. |
479 | | /// |
480 | | /// ```no_run |
481 | | /// use image::{GenericImage, GenericImageView, ImageBuffer, open}; |
482 | | /// |
483 | | /// let on_top = open("path/to/some.png").unwrap().into_rgb8(); |
484 | | /// let mut img = ImageBuffer::from_fn(512, 512, |x, y| { |
485 | | /// if (x + y) % 2 == 0 { |
486 | | /// image::Rgb([0, 0, 0]) |
487 | | /// } else { |
488 | | /// image::Rgb([255, 255, 255]) |
489 | | /// } |
490 | | /// }); |
491 | | /// |
492 | | /// image::imageops::overlay(&mut img, &on_top, 128, 128); |
493 | | /// ``` |
494 | | /// |
495 | | /// Convert an `RgbaImage` to a `GrayImage`. |
496 | | /// |
497 | | /// ```no_run |
498 | | /// use image::{open, DynamicImage}; |
499 | | /// |
500 | | /// let rgba = open("path/to/some.png").unwrap().into_rgba8(); |
501 | | /// let gray = DynamicImage::ImageRgba8(rgba).into_luma8(); |
502 | | /// ``` |
503 | | #[derive(Hash, PartialEq, Eq)] |
504 | | pub struct ImageBuffer<P: Pixel, Container> { |
505 | | width: u32, |
506 | | height: u32, |
507 | | _phantom: PhantomData<P>, |
508 | | color: CicpRgb, |
509 | | data: Container, |
510 | | } |
511 | | |
512 | | // generic implementation, shared along all image buffers |
513 | | impl<P, Container> ImageBuffer<P, Container> |
514 | | where |
515 | | P: Pixel, |
516 | | Container: Deref<Target = [P::Subpixel]>, |
517 | | { |
518 | | /// Constructs a buffer from a generic container |
519 | | /// (for example a `Vec` or a slice) |
520 | | /// |
521 | | /// Returns `None` if the container is not big enough (including when the image dimensions |
522 | | /// necessitate an allocation of more bytes than supported by the container). |
523 | 11.3k | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { |
524 | 11.3k | if Self::check_image_fits(width, height, buf.len()) { |
525 | 11.3k | Some(ImageBuffer { |
526 | 11.3k | data: buf, |
527 | 11.3k | width, |
528 | 11.3k | height, |
529 | 11.3k | color: Cicp::SRGB.into_rgb(), |
530 | 11.3k | _phantom: PhantomData, |
531 | 11.3k | }) |
532 | | } else { |
533 | 0 | None |
534 | | } |
535 | 11.3k | } <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::from_raw Line | Count | Source | 523 | 149 | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 524 | 149 | if Self::check_image_fits(width, height, buf.len()) { | 525 | 149 | Some(ImageBuffer { | 526 | 149 | data: buf, | 527 | 149 | width, | 528 | 149 | height, | 529 | 149 | color: Cicp::SRGB.into_rgb(), | 530 | 149 | _phantom: PhantomData, | 531 | 149 | }) | 532 | | } else { | 533 | 0 | None | 534 | | } | 535 | 149 | } |
<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::from_raw Line | Count | Source | 523 | 2.73k | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 524 | 2.73k | if Self::check_image_fits(width, height, buf.len()) { | 525 | 2.73k | Some(ImageBuffer { | 526 | 2.73k | data: buf, | 527 | 2.73k | width, | 528 | 2.73k | height, | 529 | 2.73k | color: Cicp::SRGB.into_rgb(), | 530 | 2.73k | _phantom: PhantomData, | 531 | 2.73k | }) | 532 | | } else { | 533 | 0 | None | 534 | | } | 535 | 2.73k | } |
<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::from_raw Line | Count | Source | 523 | 52 | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 524 | 52 | if Self::check_image_fits(width, height, buf.len()) { | 525 | 52 | Some(ImageBuffer { | 526 | 52 | data: buf, | 527 | 52 | width, | 528 | 52 | height, | 529 | 52 | color: Cicp::SRGB.into_rgb(), | 530 | 52 | _phantom: PhantomData, | 531 | 52 | }) | 532 | | } else { | 533 | 0 | None | 534 | | } | 535 | 52 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::from_raw <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::from_raw Line | Count | Source | 523 | 704 | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 524 | 704 | if Self::check_image_fits(width, height, buf.len()) { | 525 | 704 | Some(ImageBuffer { | 526 | 704 | data: buf, | 527 | 704 | width, | 528 | 704 | height, | 529 | 704 | color: Cicp::SRGB.into_rgb(), | 530 | 704 | _phantom: PhantomData, | 531 | 704 | }) | 532 | | } else { | 533 | 0 | None | 534 | | } | 535 | 704 | } |
<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::from_raw Line | Count | Source | 523 | 240 | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 524 | 240 | if Self::check_image_fits(width, height, buf.len()) { | 525 | 240 | Some(ImageBuffer { | 526 | 240 | data: buf, | 527 | 240 | width, | 528 | 240 | height, | 529 | 240 | color: Cicp::SRGB.into_rgb(), | 530 | 240 | _phantom: PhantomData, | 531 | 240 | }) | 532 | | } else { | 533 | 0 | None | 534 | | } | 535 | 240 | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::from_raw Line | Count | Source | 523 | 9 | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 524 | 9 | if Self::check_image_fits(width, height, buf.len()) { | 525 | 9 | Some(ImageBuffer { | 526 | 9 | data: buf, | 527 | 9 | width, | 528 | 9 | height, | 529 | 9 | color: Cicp::SRGB.into_rgb(), | 530 | 9 | _phantom: PhantomData, | 531 | 9 | }) | 532 | | } else { | 533 | 0 | None | 534 | | } | 535 | 9 | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::from_raw Line | Count | Source | 523 | 6.36k | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 524 | 6.36k | if Self::check_image_fits(width, height, buf.len()) { | 525 | 6.36k | Some(ImageBuffer { | 526 | 6.36k | data: buf, | 527 | 6.36k | width, | 528 | 6.36k | height, | 529 | 6.36k | color: Cicp::SRGB.into_rgb(), | 530 | 6.36k | _phantom: PhantomData, | 531 | 6.36k | }) | 532 | | } else { | 533 | 0 | None | 534 | | } | 535 | 6.36k | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::from_raw Line | Count | Source | 523 | 993 | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 524 | 993 | if Self::check_image_fits(width, height, buf.len()) { | 525 | 993 | Some(ImageBuffer { | 526 | 993 | data: buf, | 527 | 993 | width, | 528 | 993 | height, | 529 | 993 | color: Cicp::SRGB.into_rgb(), | 530 | 993 | _phantom: PhantomData, | 531 | 993 | }) | 532 | | } else { | 533 | 0 | None | 534 | | } | 535 | 993 | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::from_raw Line | Count | Source | 523 | 44 | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 524 | 44 | if Self::check_image_fits(width, height, buf.len()) { | 525 | 44 | Some(ImageBuffer { | 526 | 44 | data: buf, | 527 | 44 | width, | 528 | 44 | height, | 529 | 44 | color: Cicp::SRGB.into_rgb(), | 530 | 44 | _phantom: PhantomData, | 531 | 44 | }) | 532 | | } else { | 533 | 0 | None | 534 | | } | 535 | 44 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::from_raw <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::from_raw Line | Count | Source | 523 | 26 | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 524 | 26 | if Self::check_image_fits(width, height, buf.len()) { | 525 | 26 | Some(ImageBuffer { | 526 | 26 | data: buf, | 527 | 26 | width, | 528 | 26 | height, | 529 | 26 | color: Cicp::SRGB.into_rgb(), | 530 | 26 | _phantom: PhantomData, | 531 | 26 | }) | 532 | | } else { | 533 | 0 | None | 534 | | } | 535 | 26 | } |
<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::from_raw Line | Count | Source | 523 | 37 | pub fn from_raw(width: u32, height: u32, buf: Container) -> Option<ImageBuffer<P, Container>> { | 524 | 37 | if Self::check_image_fits(width, height, buf.len()) { | 525 | 37 | Some(ImageBuffer { | 526 | 37 | data: buf, | 527 | 37 | width, | 528 | 37 | height, | 529 | 37 | color: Cicp::SRGB.into_rgb(), | 530 | 37 | _phantom: PhantomData, | 531 | 37 | }) | 532 | | } else { | 533 | 0 | None | 534 | | } | 535 | 37 | } |
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>, &[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 |
536 | | |
537 | | /// Returns the underlying raw buffer |
538 | 3.76k | pub fn into_raw(self) -> Container { |
539 | 3.76k | self.data |
540 | 3.76k | } 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<f32>, alloc::vec::Vec<f32>>>::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 | 538 | 3.76k | pub fn into_raw(self) -> Container { | 539 | 3.76k | self.data | 540 | 3.76k | } |
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<f32>, alloc::vec::Vec<f32>>>::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 |
541 | | |
542 | | /// Returns the underlying raw buffer |
543 | 0 | pub fn as_raw(&self) -> &Container { |
544 | 0 | &self.data |
545 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::as_raw Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::as_raw |
546 | | |
547 | | /// The width and height of this image. |
548 | 1 | pub fn dimensions(&self) -> (u32, u32) { |
549 | 1 | (self.width, self.height) |
550 | 1 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::dimensions <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::dimensions Line | Count | Source | 548 | 1 | pub fn dimensions(&self) -> (u32, u32) { | 549 | 1 | (self.width, self.height) | 550 | 1 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::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<f32>, alloc::vec::Vec<f32>>>::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<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 |
551 | | |
552 | | /// The width of this image. |
553 | 1.88k | pub fn width(&self) -> u32 { |
554 | 1.88k | self.width |
555 | 1.88k | } 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<f32>, alloc::vec::Vec<f32>>>::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 | 553 | 1.88k | pub fn width(&self) -> u32 { | 554 | 1.88k | self.width | 555 | 1.88k | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::width Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::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 |
556 | | |
557 | | /// The height of this image. |
558 | 1.88k | pub fn height(&self) -> u32 { |
559 | 1.88k | self.height |
560 | 1.88k | } 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<f32>, alloc::vec::Vec<f32>>>::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 | 558 | 1.88k | pub fn height(&self) -> u32 { | 559 | 1.88k | self.height | 560 | 1.88k | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::height Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::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 |
561 | | |
562 | | /// Returns a slice of the subpixels of this image. |
563 | | /// |
564 | | /// This is guaranteed to contain exactly `width * height * channels` subpixels. |
565 | | #[doc(alias = "channels")] |
566 | 3.76k | pub fn subpixels(&self) -> &[P::Subpixel] { |
567 | 3.76k | let len = Self::image_buffer_len(self.width, self.height).unwrap(); |
568 | 3.76k | &self.data[..len] |
569 | 3.76k | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::subpixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::subpixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::subpixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::subpixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::subpixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::subpixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::subpixels <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::subpixels Line | Count | Source | 566 | 3.76k | pub fn subpixels(&self) -> &[P::Subpixel] { | 567 | 3.76k | let len = Self::image_buffer_len(self.width, self.height).unwrap(); | 568 | 3.76k | &self.data[..len] | 569 | 3.76k | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::subpixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::subpixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::subpixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::subpixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, &[u8]>>::subpixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, &[u16]>>::subpixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, &[u8]>>::subpixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, &[u16]>>::subpixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &[u8]>>::subpixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, &[u16]>>::subpixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, &[u8]>>::subpixels Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, &[u16]>>::subpixels |
570 | | |
571 | | /// Returns a slice for the pixels of this image. |
572 | | /// |
573 | | /// The index order is x = 0 to width then y = 0 to height. |
574 | | /// |
575 | | /// This is guaranteed to contain exactly `width * height` subpixels. |
576 | 0 | pub fn pixels(&self) -> &[P] { |
577 | 0 | let subpixels = self.subpixels(); |
578 | 0 | <P as Pixel>::pixels_from_channels(subpixels) |
579 | 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 |
580 | | |
581 | | /// Returns an iterator over the rows of this image. |
582 | | /// |
583 | | /// Only non-empty rows can be iterated in this manner. In particular the iterator will not |
584 | | /// yield any item when the width of the image is `0` or a pixel type without any channels is |
585 | | /// used. This ensures that its length can always be represented by `usize`. |
586 | 0 | pub fn rows(&self) -> Rows<'_, P> { |
587 | 0 | Rows::with_image(self.pixels(), self.width, self.height) |
588 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::rows Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::rows Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::rows Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::rows |
589 | | |
590 | | /// Enumerates over the pixels of the image. |
591 | | /// The iterator yields the coordinates of each pixel |
592 | | /// along with a reference to them. |
593 | | /// The iteration order is x = 0 to width then y = 0 to height |
594 | | /// Starting from the top left. |
595 | 0 | pub fn enumerate_pixels(&self) -> EnumeratePixels<'_, P> { |
596 | 0 | EnumeratePixels { |
597 | 0 | pixels: self.pixels().iter(), |
598 | 0 | x: 0, |
599 | 0 | y: 0, |
600 | 0 | width: self.width, |
601 | 0 | } |
602 | 0 | } |
603 | | |
604 | | /// Enumerates over the rows of the image. |
605 | | /// The iterator yields the y-coordinate of each row |
606 | | /// along with a reference to them. |
607 | 0 | pub fn enumerate_rows(&self) -> EnumerateRows<'_, P> { |
608 | 0 | EnumerateRows { |
609 | 0 | rows: self.rows(), |
610 | 0 | y: 0, |
611 | 0 | width: self.width, |
612 | 0 | } |
613 | 0 | } |
614 | | |
615 | | /// Gets a reference to the pixel at location `(x, y)` |
616 | | /// |
617 | | /// # Panics |
618 | | /// |
619 | | /// Panics if `(x, y)` is out of the bounds `(width, height)`. |
620 | | #[inline] |
621 | | #[track_caller] |
622 | 12.3M | pub fn get_pixel(&self, x: u32, y: u32) -> &P { |
623 | 12.3M | match self.pixel_indices(x, y) { |
624 | 0 | None => panic!( |
625 | 0 | "Image index {:?} out of bounds {:?}", |
626 | 0 | (x, y), |
627 | 0 | (self.width, self.height) |
628 | | ), |
629 | 12.3M | Some(pixel_indices) => <P as Pixel>::from_slice(&self.data[pixel_indices]), |
630 | | } |
631 | 12.3M | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::get_pixel <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::get_pixel Line | Count | Source | 622 | 2 | pub fn get_pixel(&self, x: u32, y: u32) -> &P { | 623 | 2 | match self.pixel_indices(x, y) { | 624 | 0 | None => panic!( | 625 | 0 | "Image index {:?} out of bounds {:?}", | 626 | 0 | (x, y), | 627 | 0 | (self.width, self.height) | 628 | | ), | 629 | 2 | Some(pixel_indices) => <P as Pixel>::from_slice(&self.data[pixel_indices]), | 630 | | } | 631 | 2 | } |
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<f32>, alloc::vec::Vec<f32>>>::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 | 622 | 12.3M | pub fn get_pixel(&self, x: u32, y: u32) -> &P { | 623 | 12.3M | match self.pixel_indices(x, y) { | 624 | 0 | None => panic!( | 625 | 0 | "Image index {:?} out of bounds {:?}", | 626 | 0 | (x, y), | 627 | 0 | (self.width, self.height) | 628 | | ), | 629 | 12.3M | Some(pixel_indices) => <P as Pixel>::from_slice(&self.data[pixel_indices]), | 630 | | } | 631 | 12.3M | } |
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<f32>, alloc::vec::Vec<f32>>>::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 |
632 | | |
633 | | /// Gets a reference to the pixel at location `(x, y)` or returns `None` if |
634 | | /// the index is out of the bounds `(width, height)`. |
635 | 0 | pub fn get_pixel_checked(&self, x: u32, y: u32) -> Option<&P> { |
636 | 0 | let range = self.pixel_indices(x, y)?; |
637 | 0 | self.data.get(range).map(<P as Pixel>::from_slice) |
638 | 0 | } |
639 | | |
640 | | /// Test that the image fits inside the buffer. |
641 | | /// |
642 | | /// Verifies that the maximum image of pixels inside the bounds is smaller than the provided |
643 | | /// length. Note that as a corrolary we also have that the index calculation of pixels inside |
644 | | /// the bounds will not overflow. |
645 | 11.3k | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { |
646 | 11.3k | let checked_len = Self::image_buffer_len(width, height); |
647 | 11.3k | checked_len.is_some_and(|min_len| min_len <= len) <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::check_image_fits::{closure#0}Line | Count | Source | 647 | 149 | 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 | 647 | 2.73k | 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 | 647 | 52 | checked_len.is_some_and(|min_len| min_len <= len) |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::check_image_fits::{closure#0}<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::check_image_fits::{closure#0}Line | Count | Source | 647 | 704 | 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 | 647 | 240 | checked_len.is_some_and(|min_len| min_len <= len) |
<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::check_image_fits::{closure#0}Line | Count | Source | 647 | 9 | checked_len.is_some_and(|min_len| min_len <= len) |
<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::check_image_fits::{closure#0}Line | Count | Source | 647 | 6.36k | checked_len.is_some_and(|min_len| min_len <= len) |
<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits::{closure#0}Line | Count | Source | 647 | 993 | 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 | 647 | 44 | checked_len.is_some_and(|min_len| min_len <= len) |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::check_image_fits::{closure#0}<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::check_image_fits::{closure#0}Line | Count | Source | 647 | 26 | 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 | 647 | 37 | checked_len.is_some_and(|min_len| min_len <= len) |
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>, &[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} |
648 | 11.3k | } <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::check_image_fits Line | Count | Source | 645 | 149 | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 646 | 149 | let checked_len = Self::image_buffer_len(width, height); | 647 | 149 | checked_len.is_some_and(|min_len| min_len <= len) | 648 | 149 | } |
<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::check_image_fits Line | Count | Source | 645 | 2.73k | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 646 | 2.73k | let checked_len = Self::image_buffer_len(width, height); | 647 | 2.73k | checked_len.is_some_and(|min_len| min_len <= len) | 648 | 2.73k | } |
<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::check_image_fits Line | Count | Source | 645 | 52 | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 646 | 52 | let checked_len = Self::image_buffer_len(width, height); | 647 | 52 | checked_len.is_some_and(|min_len| min_len <= len) | 648 | 52 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::check_image_fits <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::check_image_fits Line | Count | Source | 645 | 704 | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 646 | 704 | let checked_len = Self::image_buffer_len(width, height); | 647 | 704 | checked_len.is_some_and(|min_len| min_len <= len) | 648 | 704 | } |
<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::check_image_fits Line | Count | Source | 645 | 240 | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 646 | 240 | let checked_len = Self::image_buffer_len(width, height); | 647 | 240 | checked_len.is_some_and(|min_len| min_len <= len) | 648 | 240 | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::check_image_fits Line | Count | Source | 645 | 9 | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 646 | 9 | let checked_len = Self::image_buffer_len(width, height); | 647 | 9 | checked_len.is_some_and(|min_len| min_len <= len) | 648 | 9 | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::check_image_fits Line | Count | Source | 645 | 6.36k | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 646 | 6.36k | let checked_len = Self::image_buffer_len(width, height); | 647 | 6.36k | checked_len.is_some_and(|min_len| min_len <= len) | 648 | 6.36k | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::check_image_fits Line | Count | Source | 645 | 993 | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 646 | 993 | let checked_len = Self::image_buffer_len(width, height); | 647 | 993 | checked_len.is_some_and(|min_len| min_len <= len) | 648 | 993 | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::check_image_fits Line | Count | Source | 645 | 44 | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 646 | 44 | let checked_len = Self::image_buffer_len(width, height); | 647 | 44 | checked_len.is_some_and(|min_len| min_len <= len) | 648 | 44 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::check_image_fits <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::check_image_fits Line | Count | Source | 645 | 26 | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 646 | 26 | let checked_len = Self::image_buffer_len(width, height); | 647 | 26 | checked_len.is_some_and(|min_len| min_len <= len) | 648 | 26 | } |
<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::check_image_fits Line | Count | Source | 645 | 37 | fn check_image_fits(width: u32, height: u32, len: usize) -> bool { | 646 | 37 | let checked_len = Self::image_buffer_len(width, height); | 647 | 37 | checked_len.is_some_and(|min_len| min_len <= len) | 648 | 37 | } |
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>, &[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 |
649 | | |
650 | 9.32M | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { |
651 | 9.32M | Some(<P as Pixel>::CHANNEL_COUNT as usize) |
652 | 9.32M | .and_then(|size| size.checked_mul(width as usize)) <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::image_buffer_len::{closure#0}Line | Count | Source | 652 | 149 | .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 | 652 | 2.73k | .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 | 652 | 52 | .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 | 652 | 704 | .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 | 652 | 240 | .and_then(|size| size.checked_mul(width as usize)) |
<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::image_buffer_len::{closure#0}Line | Count | Source | 652 | 9 | .and_then(|size| size.checked_mul(width as usize)) |
<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::image_buffer_len::{closure#0}Line | Count | Source | 652 | 9.32M | .and_then(|size| size.checked_mul(width as usize)) |
<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#0}Line | Count | Source | 652 | 1.98k | .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 | 652 | 44 | .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 | 652 | 26 | .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 | 652 | 37 | .and_then(|size| size.checked_mul(width as usize)) |
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>, &[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} |
653 | 9.32M | .and_then(|size| size.checked_mul(height as usize)) <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::image_buffer_len::{closure#1}Line | Count | Source | 653 | 149 | .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 | 653 | 2.73k | .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 | 653 | 52 | .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 | 653 | 704 | .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 | 653 | 240 | .and_then(|size| size.checked_mul(height as usize)) |
<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::image_buffer_len::{closure#1}Line | Count | Source | 653 | 9 | .and_then(|size| size.checked_mul(height as usize)) |
<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::image_buffer_len::{closure#1}Line | Count | Source | 653 | 9.32M | .and_then(|size| size.checked_mul(height as usize)) |
<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len::{closure#1}Line | Count | Source | 653 | 1.98k | .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 | 653 | 44 | .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 | 653 | 26 | .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 | 653 | 37 | .and_then(|size| size.checked_mul(height as usize)) |
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>, &[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} |
654 | 9.32M | } <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::image_buffer_len Line | Count | Source | 650 | 149 | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 651 | 149 | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 652 | 149 | .and_then(|size| size.checked_mul(width as usize)) | 653 | 149 | .and_then(|size| size.checked_mul(height as usize)) | 654 | 149 | } |
<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::image_buffer_len Line | Count | Source | 650 | 2.73k | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 651 | 2.73k | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 652 | 2.73k | .and_then(|size| size.checked_mul(width as usize)) | 653 | 2.73k | .and_then(|size| size.checked_mul(height as usize)) | 654 | 2.73k | } |
<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::image_buffer_len Line | Count | Source | 650 | 52 | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 651 | 52 | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 652 | 52 | .and_then(|size| size.checked_mul(width as usize)) | 653 | 52 | .and_then(|size| size.checked_mul(height as usize)) | 654 | 52 | } |
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 | 650 | 704 | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 651 | 704 | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 652 | 704 | .and_then(|size| size.checked_mul(width as usize)) | 653 | 704 | .and_then(|size| size.checked_mul(height as usize)) | 654 | 704 | } |
<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::image_buffer_len Line | Count | Source | 650 | 240 | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 651 | 240 | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 652 | 240 | .and_then(|size| size.checked_mul(width as usize)) | 653 | 240 | .and_then(|size| size.checked_mul(height as usize)) | 654 | 240 | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::image_buffer_len Line | Count | Source | 650 | 9 | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 651 | 9 | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 652 | 9 | .and_then(|size| size.checked_mul(width as usize)) | 653 | 9 | .and_then(|size| size.checked_mul(height as usize)) | 654 | 9 | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::image_buffer_len Line | Count | Source | 650 | 9.32M | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 651 | 9.32M | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 652 | 9.32M | .and_then(|size| size.checked_mul(width as usize)) | 653 | 9.32M | .and_then(|size| size.checked_mul(height as usize)) | 654 | 9.32M | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::image_buffer_len Line | Count | Source | 650 | 1.98k | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 651 | 1.98k | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 652 | 1.98k | .and_then(|size| size.checked_mul(width as usize)) | 653 | 1.98k | .and_then(|size| size.checked_mul(height as usize)) | 654 | 1.98k | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::image_buffer_len Line | Count | Source | 650 | 44 | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 651 | 44 | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 652 | 44 | .and_then(|size| size.checked_mul(width as usize)) | 653 | 44 | .and_then(|size| size.checked_mul(height as usize)) | 654 | 44 | } |
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 | 650 | 26 | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 651 | 26 | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 652 | 26 | .and_then(|size| size.checked_mul(width as usize)) | 653 | 26 | .and_then(|size| size.checked_mul(height as usize)) | 654 | 26 | } |
<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::image_buffer_len Line | Count | Source | 650 | 37 | fn image_buffer_len(width: u32, height: u32) -> Option<usize> { | 651 | 37 | Some(<P as Pixel>::CHANNEL_COUNT as usize) | 652 | 37 | .and_then(|size| size.checked_mul(width as usize)) | 653 | 37 | .and_then(|size| size.checked_mul(height as usize)) | 654 | 37 | } |
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>, &[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 |
655 | | |
656 | | #[inline(always)] |
657 | 12.3M | fn pixel_indices(&self, x: u32, y: u32) -> Option<Range<usize>> { |
658 | 12.3M | if x >= self.width || y >= self.height { |
659 | 0 | return None; |
660 | 12.3M | } |
661 | | |
662 | 12.3M | Some(self.pixel_indices_unchecked(x, y)) |
663 | 12.3M | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::pixel_indices <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::pixel_indices Line | Count | Source | 657 | 4 | fn pixel_indices(&self, x: u32, y: u32) -> Option<Range<usize>> { | 658 | 4 | if x >= self.width || y >= self.height { | 659 | 0 | return None; | 660 | 4 | } | 661 | | | 662 | 4 | Some(self.pixel_indices_unchecked(x, y)) | 663 | 4 | } |
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<f32>, alloc::vec::Vec<f32>>>::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 | 657 | 12.3M | fn pixel_indices(&self, x: u32, y: u32) -> Option<Range<usize>> { | 658 | 12.3M | if x >= self.width || y >= self.height { | 659 | 0 | return None; | 660 | 12.3M | } | 661 | | | 662 | 12.3M | Some(self.pixel_indices_unchecked(x, y)) | 663 | 12.3M | } |
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<f32>, alloc::vec::Vec<f32>>>::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 |
664 | | |
665 | | #[inline(always)] |
666 | 12.3M | fn pixel_indices_unchecked(&self, x: u32, y: u32) -> Range<usize> { |
667 | 12.3M | let no_channels = <P as Pixel>::CHANNEL_COUNT as usize; |
668 | | // If in bounds, this can't overflow as we have tested that at construction! |
669 | 12.3M | let min_index = (y as usize * self.width as usize + x as usize) * no_channels; |
670 | 12.3M | min_index..min_index + no_channels |
671 | 12.3M | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::pixel_indices_unchecked <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::pixel_indices_unchecked Line | Count | Source | 666 | 4 | fn pixel_indices_unchecked(&self, x: u32, y: u32) -> Range<usize> { | 667 | 4 | let no_channels = <P as Pixel>::CHANNEL_COUNT as usize; | 668 | | // If in bounds, this can't overflow as we have tested that at construction! | 669 | 4 | let min_index = (y as usize * self.width as usize + x as usize) * no_channels; | 670 | 4 | min_index..min_index + no_channels | 671 | 4 | } |
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<f32>, alloc::vec::Vec<f32>>>::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 | 666 | 12.3M | fn pixel_indices_unchecked(&self, x: u32, y: u32) -> Range<usize> { | 667 | 12.3M | let no_channels = <P as Pixel>::CHANNEL_COUNT as usize; | 668 | | // If in bounds, this can't overflow as we have tested that at construction! | 669 | 12.3M | let min_index = (y as usize * self.width as usize + x as usize) * no_channels; | 670 | 12.3M | min_index..min_index + no_channels | 671 | 12.3M | } |
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<f32>, alloc::vec::Vec<f32>>>::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 |
672 | | |
673 | | /// Get the format of the buffer when viewed as a matrix of samples. |
674 | 0 | pub fn sample_layout(&self) -> SampleLayout { |
675 | | // None of these can overflow, as all our memory is addressable. |
676 | 0 | SampleLayout::row_major_packed(<P as Pixel>::CHANNEL_COUNT, self.width, self.height) |
677 | 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<f32>, alloc::vec::Vec<f32>>>::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<f32>, alloc::vec::Vec<f32>>>::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 |
678 | | |
679 | | /// Return the raw sample buffer with its stride an dimension information. |
680 | | /// |
681 | | /// The returned buffer is guaranteed to be well formed in all cases. It is laid out by |
682 | | /// colors, width then height, meaning `channel_stride <= width_stride <= height_stride`. All |
683 | | /// strides are in numbers of elements but those are mostly `u8` in which case the strides are |
684 | | /// also byte strides. |
685 | 0 | pub fn into_flat_samples(self) -> FlatSamples<Container> |
686 | 0 | where |
687 | 0 | Container: AsRef<[P::Subpixel]>, |
688 | | { |
689 | | // None of these can overflow, as all our memory is addressable. |
690 | 0 | let layout = self.sample_layout(); |
691 | 0 | FlatSamples { |
692 | 0 | samples: self.data, |
693 | 0 | layout, |
694 | 0 | color_hint: None, // TODO: the pixel type might contain P::COLOR_TYPE if it satisfies PixelWithColorType |
695 | 0 | } |
696 | 0 | } |
697 | | |
698 | | /// Return a view on the raw sample buffer. |
699 | | /// |
700 | | /// See [`into_flat_samples`](#method.into_flat_samples) for more details. |
701 | 0 | pub fn as_flat_samples(&self) -> FlatSamples<&[P::Subpixel]> { |
702 | 0 | let layout = self.sample_layout(); |
703 | 0 | FlatSamples { |
704 | 0 | samples: self.data.as_ref(), |
705 | 0 | layout, |
706 | 0 | color_hint: None, // TODO: the pixel type might contain P::COLOR_TYPE if it satisfies PixelWithColorType |
707 | 0 | } |
708 | 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<f32>, alloc::vec::Vec<f32>>>::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<f32>, alloc::vec::Vec<f32>>>::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 |
709 | | |
710 | | /// Return an image view on the raw sample buffer. |
711 | | /// |
712 | | /// This is related to [`Self::into_flat_samples`] and [`Self::as_flat_samples`] while |
713 | | /// encapsulating the conversion into an implementation of [`GenericImageView`]. In contrast to |
714 | | /// the generic [`GenericImageView::to_pixel_view`] this is not fallible. |
715 | | /// |
716 | | /// The result is similar to a [`crate::SubImage`] created from [`GenericImageView::try_view`] |
717 | | /// but unlike that generic type it is not strongly tied to the `Self` type and underlying |
718 | | /// buffer used. |
719 | | /// |
720 | | /// # Usage |
721 | | /// |
722 | | /// ``` |
723 | | /// use image::{RgbImage, GenericImageView, Rgb}; |
724 | | /// |
725 | | /// let mut img = RgbImage::from_pixel(16, 16, Rgb([0xff, 0xab, 0xcd])); |
726 | | /// let strided = img.as_pixel_view(); |
727 | | /// |
728 | | /// // This borrows `img` and is still a `GenericImageView`. |
729 | | /// assert_eq!(strided.get_pixel(8, 8), Rgb([0xff, 0xab, 0xcd])); |
730 | | /// ``` |
731 | 0 | pub fn as_pixel_view(&self) -> ViewOfPixel<'_, P> { |
732 | 0 | self.as_flat_samples() |
733 | 0 | .into_view() |
734 | 0 | .expect("buffer always uses a non-overlapping strided layout") |
735 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::as_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::as_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::as_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::as_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::as_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::as_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::as_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::as_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::as_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::as_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::as_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::as_pixel_view |
736 | | |
737 | | /// Return a mutable view on the raw sample buffer. |
738 | | /// |
739 | | /// See [`into_flat_samples`](#method.into_flat_samples) for more details. |
740 | 0 | pub fn as_flat_samples_mut(&mut self) -> FlatSamples<&mut [P::Subpixel]> |
741 | 0 | where |
742 | 0 | Container: DerefMut<Target = [P::Subpixel]>, |
743 | | { |
744 | 0 | let layout = self.sample_layout(); |
745 | 0 | FlatSamples { |
746 | 0 | samples: self.data.as_mut(), |
747 | 0 | layout, |
748 | 0 | color_hint: None, // TODO: the pixel type might contain P::COLOR_TYPE if it satisfies PixelWithColorType |
749 | 0 | } |
750 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::as_flat_samples_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::as_flat_samples_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::as_flat_samples_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::as_flat_samples_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::as_flat_samples_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::as_flat_samples_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::as_flat_samples_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::as_flat_samples_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::as_flat_samples_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::as_flat_samples_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::as_flat_samples_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::as_flat_samples_mut |
751 | | |
752 | | /// Return a mutable image view on the raw sample buffer. |
753 | | /// |
754 | | /// This is related to [`Self::into_flat_samples`] and [`Self::as_flat_samples_mut`] while still |
755 | | /// encapsulating the conversion into an implementation of [`GenericImage`]. In contrast to the |
756 | | /// generic [`GenericImage::to_pixel_view_mut`] this is not fallible. |
757 | | /// |
758 | | /// The result is similar to a [`crate::SubImage`] created from [`GenericImage::sub_image`] but |
759 | | /// unlike that generic type it is not strongly tied to the `Self` type and underlying buffer |
760 | | /// used. |
761 | | /// |
762 | | /// # Usage |
763 | | /// |
764 | | /// ``` |
765 | | /// use image::{RgbImage, GenericImage, Rgb}; |
766 | | /// |
767 | | /// let mut img = RgbImage::from_pixel(16, 16, Rgb([0xff, 0xab, 0xcd])); |
768 | | /// let mut strided = img.as_pixel_view_mut(); |
769 | | /// |
770 | | /// // This borrows `img` and is still a `GenericImage` (and a view). |
771 | | /// strided.put_pixel(8, 8, Rgb([0x00, 0x00, 0x00])); |
772 | | /// ``` |
773 | 0 | pub fn as_pixel_view_mut(&mut self) -> ViewMutOfPixel<'_, P> |
774 | 0 | where |
775 | 0 | Container: DerefMut<Target = [P::Subpixel]>, |
776 | | { |
777 | 0 | self.as_flat_samples_mut() |
778 | 0 | .into_view_mut() |
779 | 0 | .expect("buffer always uses a non-overlapping strided layout") |
780 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::as_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::as_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::as_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::as_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::as_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::as_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::as_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::as_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::as_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::as_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::as_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::as_pixel_view_mut |
781 | | |
782 | | /// Extract the alpha channel as a Luma image. |
783 | | /// |
784 | | /// If the pixel does not have an alpha channel, the value is filled with a fully opaque mask |
785 | | /// using the maximum value of the corresponding subpixel type. |
786 | 0 | pub fn to_alpha_mask(&self) -> ImageBuffer<Luma<P::Subpixel>, Vec<P::Subpixel>> { |
787 | 0 | let pixels = self.pixels().iter(); |
788 | | |
789 | 0 | let mask = if P::HAS_ALPHA { |
790 | 0 | assert!( |
791 | 0 | P::CHANNEL_COUNT > 0, |
792 | 0 | "Pixel with zero channels indicated an alpha channel" |
793 | | ); |
794 | | |
795 | 0 | pixels.map(|p| p.alpha()).collect() Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::to_alpha_mask::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::to_alpha_mask::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::to_alpha_mask::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::to_alpha_mask::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::to_alpha_mask::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::to_alpha_mask::{closure#0} |
796 | | } else { |
797 | 0 | vec![<P::Subpixel as Primitive>::DEFAULT_MAX_VALUE; pixels.len()] |
798 | | }; |
799 | | |
800 | 0 | ImageBuffer::from_vec(self.width, self.height, mask) |
801 | 0 | .expect("used the right pixel and channel count") |
802 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::to_alpha_mask Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::to_alpha_mask Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::to_alpha_mask Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::to_alpha_mask Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::to_alpha_mask Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::to_alpha_mask Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::to_alpha_mask Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::to_alpha_mask Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::to_alpha_mask Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::to_alpha_mask Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::to_alpha_mask Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::to_alpha_mask |
803 | | } |
804 | | |
805 | | impl<P, Container> ImageBuffer<P, Container> |
806 | | where |
807 | | P: Pixel, |
808 | | Container: Deref<Target = [P::Subpixel]> + DerefMut, |
809 | | { |
810 | | /// Returns a mutable slice of the subpixels of this image. |
811 | | /// |
812 | | /// This is guaranteed to contain exactly `width * height * channels` subpixels. |
813 | 9.30M | pub fn subpixels_mut(&mut self) -> &mut [P::Subpixel] { |
814 | 9.30M | let len = Self::image_buffer_len(self.width, self.height).unwrap(); |
815 | 9.30M | &mut self.data[..len] |
816 | 9.30M | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::subpixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::subpixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::subpixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::subpixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::subpixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::subpixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::subpixels_mut <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::subpixels_mut Line | Count | Source | 813 | 9.30M | pub fn subpixels_mut(&mut self) -> &mut [P::Subpixel] { | 814 | 9.30M | let len = Self::image_buffer_len(self.width, self.height).unwrap(); | 815 | 9.30M | &mut self.data[..len] | 816 | 9.30M | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::subpixels_mut Line | Count | Source | 813 | 993 | pub fn subpixels_mut(&mut self) -> &mut [P::Subpixel] { | 814 | 993 | let len = Self::image_buffer_len(self.width, self.height).unwrap(); | 815 | 993 | &mut self.data[..len] | 816 | 993 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::subpixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::subpixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::subpixels_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::subpixels_mut |
817 | | |
818 | | /// Returns a mutable slice of the pixels of this image. |
819 | | /// |
820 | | /// This is guaranteed to contain exactly `width * height` pixels. |
821 | 3.61k | pub fn pixels_mut(&mut self) -> &mut [P] { |
822 | 3.61k | let subpixels = self.subpixels_mut(); |
823 | 3.61k | <P as Pixel>::pixels_from_channels_mut(subpixels) |
824 | 3.61k | } 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 <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::pixels_mut Line | Count | Source | 821 | 2.62k | pub fn pixels_mut(&mut self) -> &mut [P] { | 822 | 2.62k | let subpixels = self.subpixels_mut(); | 823 | 2.62k | <P as Pixel>::pixels_from_channels_mut(subpixels) | 824 | 2.62k | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::pixels_mut Line | Count | Source | 821 | 993 | pub fn pixels_mut(&mut self) -> &mut [P] { | 822 | 993 | let subpixels = self.subpixels_mut(); | 823 | 993 | <P as Pixel>::pixels_from_channels_mut(subpixels) | 824 | 993 | } |
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 |
825 | | |
826 | | /// Returns an iterator over the mutable rows of this image. |
827 | | /// |
828 | | /// Only non-empty rows can be iterated in this manner. In particular the iterator will not |
829 | | /// yield any item when the width of the image is `0` or a pixel type without any channels is |
830 | | /// used. This ensures that its length can always be represented by `usize`. |
831 | 0 | pub fn rows_mut(&mut self) -> RowsMut<'_, P> { |
832 | 0 | let width = self.width; |
833 | 0 | let height = self.height; |
834 | 0 | RowsMut::with_image(self.pixels_mut(), width, height) |
835 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::rows_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::rows_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::rows_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::rows_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::rows_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::rows_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::rows_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::rows_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::rows_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::rows_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::rows_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::rows_mut |
836 | | |
837 | | /// Enumerates over the pixels of the image. |
838 | | /// The iterator yields the coordinates of each pixel |
839 | | /// along with a mutable reference to them. |
840 | 993 | pub fn enumerate_pixels_mut(&mut self) -> EnumeratePixelsMut<'_, P> { |
841 | 993 | let width = self.width; |
842 | 993 | EnumeratePixelsMut { |
843 | 993 | pixels: self.pixels_mut().iter_mut(), |
844 | 993 | x: 0, |
845 | 993 | y: 0, |
846 | 993 | width, |
847 | 993 | } |
848 | 993 | } 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<f32>, alloc::vec::Vec<f32>>>::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 <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, &mut [u8]>>::enumerate_pixels_mut Line | Count | Source | 840 | 993 | pub fn enumerate_pixels_mut(&mut self) -> EnumeratePixelsMut<'_, P> { | 841 | 993 | let width = self.width; | 842 | 993 | EnumeratePixelsMut { | 843 | 993 | pixels: self.pixels_mut().iter_mut(), | 844 | 993 | x: 0, | 845 | 993 | y: 0, | 846 | 993 | width, | 847 | 993 | } | 848 | 993 | } |
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<f32>, alloc::vec::Vec<f32>>>::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 |
849 | | |
850 | | /// Enumerates over the rows of the image. |
851 | | /// The iterator yields the y-coordinate of each row |
852 | | /// along with a mutable reference to them. |
853 | 0 | pub fn enumerate_rows_mut(&mut self) -> EnumerateRowsMut<'_, P> { |
854 | 0 | let width = self.width; |
855 | 0 | EnumerateRowsMut { |
856 | 0 | rows: self.rows_mut(), |
857 | 0 | y: 0, |
858 | 0 | width, |
859 | 0 | } |
860 | 0 | } |
861 | | |
862 | | /// Gets a reference to the mutable pixel at location `(x, y)` |
863 | | /// |
864 | | /// # Panics |
865 | | /// |
866 | | /// Panics if `(x, y)` is out of the bounds `(width, height)`. |
867 | | #[inline] |
868 | | #[track_caller] |
869 | 2 | pub fn get_pixel_mut(&mut self, x: u32, y: u32) -> &mut P { |
870 | 2 | match self.pixel_indices(x, y) { |
871 | 0 | None => panic!( |
872 | 0 | "Image index {:?} out of bounds {:?}", |
873 | 0 | (x, y), |
874 | 0 | (self.width, self.height) |
875 | | ), |
876 | 2 | Some(pixel_indices) => <P as Pixel>::from_slice_mut(&mut self.data[pixel_indices]), |
877 | | } |
878 | 2 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::get_pixel_mut <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::get_pixel_mut Line | Count | Source | 869 | 2 | pub fn get_pixel_mut(&mut self, x: u32, y: u32) -> &mut P { | 870 | 2 | match self.pixel_indices(x, y) { | 871 | 0 | None => panic!( | 872 | 0 | "Image index {:?} out of bounds {:?}", | 873 | 0 | (x, y), | 874 | 0 | (self.width, self.height) | 875 | | ), | 876 | 2 | Some(pixel_indices) => <P as Pixel>::from_slice_mut(&mut self.data[pixel_indices]), | 877 | | } | 878 | 2 | } |
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<f32>, alloc::vec::Vec<f32>>>::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<f32>, alloc::vec::Vec<f32>>>::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 |
879 | | |
880 | | /// Gets a reference to the mutable pixel at location `(x, y)` or returns |
881 | | /// `None` if the index is out of the bounds `(width, height)`. |
882 | 0 | pub fn get_pixel_mut_checked(&mut self, x: u32, y: u32) -> Option<&mut P> { |
883 | 0 | let range = self.pixel_indices(x, y)?; |
884 | 0 | self.data.get_mut(range).map(<P as Pixel>::from_slice_mut) |
885 | 0 | } |
886 | | |
887 | | /// Puts a pixel at location `(x, y)` |
888 | | /// |
889 | | /// # Panics |
890 | | /// |
891 | | /// Panics if `(x, y)` is out of the bounds `(width, height)`. |
892 | | #[inline] |
893 | | #[track_caller] |
894 | 0 | pub fn put_pixel(&mut self, x: u32, y: u32, pixel: P) { |
895 | 0 | *self.get_pixel_mut(x, y) = pixel; |
896 | 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<f32>, alloc::vec::Vec<f32>>>::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<f32>, alloc::vec::Vec<f32>>>::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 |
897 | | |
898 | | /// Crop this image in place, removing pixels outside of the bounding rectangle. |
899 | | /// |
900 | | /// This behaves similar to [`imageops::crop`](crate::imageops::crop) except no additional |
901 | | /// allocation takes place. The width and height of this buffer are adjusted as part of the |
902 | | /// operation. The selection is shrunk to the overlap with this image if it is out of bounds. |
903 | | /// |
904 | | /// The pixel buffer is *not* shrunk and will continue to occupy the same amount of memory as |
905 | | /// before. See [`ImageBuffer::shrink_to_fit`] if the container is a [`Vec`]. |
906 | | /// |
907 | | /// # Examples |
908 | | /// |
909 | | /// ``` |
910 | | /// use image::{RgbImage, math::Rect}; |
911 | | /// |
912 | | /// let mut img = RgbImage::new(128, 128); |
913 | | /// img.put_pixel(64, 64, image::Rgb([255, 0, 0])); |
914 | | /// |
915 | | /// let selection = Rect::from_xy_ranges(64..128, 64..128); |
916 | | /// img.crop_in_place(selection); |
917 | | /// |
918 | | /// assert_eq!(img.dimensions(), (64, 64)); |
919 | | /// assert_eq!(img.get_pixel(0, 0), &image::Rgb([255, 0, 0])); |
920 | | /// ``` |
921 | | /// |
922 | | /// Selections beyond the image bounds are clamped. |
923 | | /// |
924 | | /// ``` |
925 | | /// use image::{RgbImage, math::Rect}; |
926 | | /// |
927 | | /// let mut img = RgbImage::new(32, 32); |
928 | | /// let selection = Rect::from_xy_ranges(16..40, 16..24); |
929 | | /// # use image::GenericImageView as _; |
930 | | /// # assert_eq!(image::imageops::crop(&img, selection).dimensions(), (16, 8)); |
931 | | /// |
932 | | /// img.crop_in_place(selection); |
933 | | /// assert_eq!(img.dimensions(), (16, 8)); |
934 | | /// ``` |
935 | 0 | pub fn crop_in_place(&mut self, selection: Rect) { |
936 | 0 | let selection = selection.shrink_to_bounds_of(self); |
937 | 0 | assert!(selection.test_in_bounds_of(self).is_ok()); |
938 | | |
939 | 0 | fn copy_within<T: Copy>(data: &mut [T], src: usize, len: usize, dst: usize) { |
940 | 0 | if src == dst || len == 0 { |
941 | 0 | return; |
942 | 0 | } |
943 | 0 | data.copy_within(src..src + len, dst); |
944 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<_, _>>::crop_in_place::copy_within::<f32> Unexecuted instantiation: <image::images::buffer::ImageBuffer<_, _>>::crop_in_place::copy_within::<u8> Unexecuted instantiation: <image::images::buffer::ImageBuffer<_, _>>::crop_in_place::copy_within::<u16> |
945 | | |
946 | | // We're now running essentially `copy_within` with differing source and destination row |
947 | | // pitches. The above ensures that the target row pitch is smaller than our current one and |
948 | | // we copy to offset `0` so always all data backwards. |
949 | | // |
950 | | // Since `selection` describes a smaller layout than our own, all indices that are computed |
951 | | // from the pitches as type `usize` are within the bounds of the type and the underlying |
952 | | // storage and we assume them to be valid. (If the `DerefMut` is malicious you'll get |
953 | | // panics at runtime but that is not our problem, violating the contract of the container |
954 | | // type for channels). |
955 | 0 | let rowlen = (selection.width as usize) * usize::from(<P as Pixel>::CHANNEL_COUNT); |
956 | | |
957 | 0 | for y in 0..selection.height { |
958 | 0 | let sy = selection.y + y; |
959 | 0 | let source = self.pixel_indices_unchecked(selection.x, sy).start; |
960 | 0 | let dst = y as usize * rowlen; |
961 | 0 | copy_within(&mut self.data, source, rowlen, dst); |
962 | 0 | } |
963 | | |
964 | 0 | self.width = selection.width; |
965 | 0 | self.height = selection.height; |
966 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::crop_in_place Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::crop_in_place Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::crop_in_place Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::crop_in_place Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::crop_in_place Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::crop_in_place Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::crop_in_place Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::crop_in_place Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::crop_in_place Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::crop_in_place Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::crop_in_place Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::crop_in_place |
967 | | |
968 | | /// Fill the alpha channel of this image from a Luma mask. |
969 | | /// |
970 | | /// Returns an [`ImageError::Parameter`] if the mask dimensions do not match the image |
971 | | /// dimensions or if there is no alpha channel in the pixel's color type. |
972 | | /// |
973 | | /// NOTE: pending the generic constant argument MVP (#132980) this may gain a trait bound on |
974 | | /// available alpha channel instead of an error. Please do consider the design trade-off here. |
975 | | /// The standard library refrained from adding a non-zero bound to the length of |
976 | | /// `slice::as_chunks`. The bound would look like: |
977 | | /// |
978 | | /// ```text |
979 | | /// where |
980 | | /// P: Pixel<HAS_ALPHA = true> |
981 | | /// ``` |
982 | | /// |
983 | | /// Similar arguments apply as presented in [#99471], with post-monomorphization error and |
984 | | /// inability to type-check code on a const-dependent branch. We must consider if a slice length |
985 | | /// of `0` and non-alpha pixel types are similar usage patterns. |
986 | | /// |
987 | | /// [#99471]: https://github.com/rust-lang/rust/pull/99471 |
988 | | /// [#132980]: https://github.com/rust-lang/rust/issues/132980 |
989 | 0 | pub fn set_alpha_channel<RhsContainer>( |
990 | 0 | &mut self, |
991 | 0 | mask: &ImageBuffer<Luma<P::Subpixel>, RhsContainer>, |
992 | 0 | ) -> ImageResult<()> |
993 | 0 | where |
994 | 0 | RhsContainer: Deref<Target = [P::Subpixel]>, |
995 | | { |
996 | 0 | if (self.width, self.height) != (mask.width(), mask.height()) { |
997 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( |
998 | 0 | ParameterErrorKind::DimensionMismatch, |
999 | 0 | ))); |
1000 | 0 | } |
1001 | | |
1002 | 0 | if !P::HAS_ALPHA { |
1003 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( |
1004 | 0 | ParameterErrorKind::NoAlphaChannel, |
1005 | 0 | ))); |
1006 | 0 | } |
1007 | | |
1008 | 0 | assert!( |
1009 | 0 | P::CHANNEL_COUNT > 0, |
1010 | 0 | "Pixel with zero channels indicated an alpha channel" |
1011 | | ); |
1012 | | |
1013 | 0 | let pixels = self.pixels_mut().iter_mut(); |
1014 | 0 | let mask = mask.subpixels(); |
1015 | | |
1016 | 0 | for (p, alpha) in pixels.zip(mask.iter()) { |
1017 | | // If the pixel has an alpha channel, use it. |
1018 | 0 | p.apply_with_alpha(|c| c, |_| *alpha); |
1019 | | } |
1020 | | |
1021 | 0 | Ok(()) |
1022 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::set_alpha_channel::<alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::set_alpha_channel::<alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::set_alpha_channel::<alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::set_alpha_channel::<alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::set_alpha_channel::<alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::set_alpha_channel::<alloc::vec::Vec<u16>> |
1023 | | } |
1024 | | |
1025 | | impl<S: Primitive> ImageBuffer<Luma<S>, Vec<S>> { |
1026 | | /// Insert an alpha channel at every pixel. |
1027 | | /// |
1028 | | /// Before exposing this: |
1029 | | /// - should it be generic, if so, how? |
1030 | | /// - buffer reuse would works but only for `Vec` since we must resize. |
1031 | 0 | pub(crate) fn add_alpha_channel( |
1032 | 0 | &self, |
1033 | 0 | mask: &ImageBuffer<Luma<S>, Vec<S>>, |
1034 | 0 | ) -> ImageResult<ImageBuffer<LumaA<S>, Vec<S>>> { |
1035 | 0 | if (self.width, self.height) != (mask.width(), mask.height()) { |
1036 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( |
1037 | 0 | ParameterErrorKind::DimensionMismatch, |
1038 | 0 | ))); |
1039 | 0 | } |
1040 | | |
1041 | 0 | let data = self |
1042 | 0 | .pixels() |
1043 | 0 | .iter() |
1044 | 0 | .zip(mask.subpixels()) |
1045 | 0 | .map(|(&luma, &alpha)| [luma.0[0], alpha]) Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::add_alpha_channel::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::add_alpha_channel::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::add_alpha_channel::{closure#0} |
1046 | 0 | .collect::<Vec<_>>(); |
1047 | | |
1048 | 0 | Ok(ImageBuffer::from_vec(self.width, self.height, data.into_flattened()).unwrap()) |
1049 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::add_alpha_channel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::add_alpha_channel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::add_alpha_channel |
1050 | | } |
1051 | | |
1052 | | impl<S: Primitive> ImageBuffer<Rgb<S>, Vec<S>> { |
1053 | | /// See: `add_alpha_channel` for `ImageBuffer<Luma<S>>`. |
1054 | 0 | pub(crate) fn add_alpha_channel( |
1055 | 0 | &self, |
1056 | 0 | mask: &ImageBuffer<Luma<S>, Vec<S>>, |
1057 | 0 | ) -> ImageResult<ImageBuffer<Rgba<S>, Vec<S>>> { |
1058 | 0 | if (self.width, self.height) != (mask.width(), mask.height()) { |
1059 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( |
1060 | 0 | ParameterErrorKind::DimensionMismatch, |
1061 | 0 | ))); |
1062 | 0 | } |
1063 | | |
1064 | 0 | let data = self |
1065 | 0 | .pixels() |
1066 | 0 | .iter() |
1067 | 0 | .zip(mask.subpixels()) |
1068 | 0 | .map(|(&Rgb([r, g, b]), &alpha)| [r, g, b, alpha]) Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::add_alpha_channel::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::add_alpha_channel::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::add_alpha_channel::{closure#0} |
1069 | 0 | .collect::<Vec<_>>(); |
1070 | | |
1071 | 0 | Ok(ImageBuffer::from_vec(self.width, self.height, data.into_flattened()).unwrap()) |
1072 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::add_alpha_channel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::add_alpha_channel Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::add_alpha_channel |
1073 | | } |
1074 | | |
1075 | | impl<P: Pixel, Container> ImageBuffer<P, Container> { |
1076 | | /// Define the color space for the image. |
1077 | | /// |
1078 | | /// The color data is unchanged. Reinterprets the existing red, blue, green channels as points |
1079 | | /// in the new set of primary colors, changing the apparent shade of pixels. |
1080 | | /// |
1081 | | /// Note that the primaries also define a reference whitepoint When this buffer contains Luma |
1082 | | /// data, the luminance channel is interpreted as the `Y` channel of a related `YCbCr` color |
1083 | | /// space as if by a non-constant chromaticity derived matrix. That is, coefficients are *not* |
1084 | | /// applied in the linear RGB space but use encoded channel values. (In a color space with the |
1085 | | /// linear transfer function there is no difference). |
1086 | | /// |
1087 | | /// The default color space is [`Cicp::SRGB`]. |
1088 | 7.48k | pub fn set_rgb_primaries(&mut self, color: CicpColorPrimaries) { |
1089 | 7.48k | self.color.primaries = color; |
1090 | 7.48k | } <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::set_rgb_primaries Line | Count | Source | 1088 | 149 | pub fn set_rgb_primaries(&mut self, color: CicpColorPrimaries) { | 1089 | 149 | self.color.primaries = color; | 1090 | 149 | } |
<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::set_rgb_primaries Line | Count | Source | 1088 | 2.73k | pub fn set_rgb_primaries(&mut self, color: CicpColorPrimaries) { | 1089 | 2.73k | self.color.primaries = color; | 1090 | 2.73k | } |
<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::set_rgb_primaries Line | Count | Source | 1088 | 52 | pub fn set_rgb_primaries(&mut self, color: CicpColorPrimaries) { | 1089 | 52 | self.color.primaries = color; | 1090 | 52 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::set_rgb_primaries <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::set_rgb_primaries Line | Count | Source | 1088 | 704 | pub fn set_rgb_primaries(&mut self, color: CicpColorPrimaries) { | 1089 | 704 | self.color.primaries = color; | 1090 | 704 | } |
<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::set_rgb_primaries Line | Count | Source | 1088 | 240 | pub fn set_rgb_primaries(&mut self, color: CicpColorPrimaries) { | 1089 | 240 | self.color.primaries = color; | 1090 | 240 | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::set_rgb_primaries Line | Count | Source | 1088 | 9 | pub fn set_rgb_primaries(&mut self, color: CicpColorPrimaries) { | 1089 | 9 | self.color.primaries = color; | 1090 | 9 | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::set_rgb_primaries Line | Count | Source | 1088 | 3.48k | pub fn set_rgb_primaries(&mut self, color: CicpColorPrimaries) { | 1089 | 3.48k | self.color.primaries = color; | 1090 | 3.48k | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::set_rgb_primaries Line | Count | Source | 1088 | 44 | pub fn set_rgb_primaries(&mut self, color: CicpColorPrimaries) { | 1089 | 44 | self.color.primaries = color; | 1090 | 44 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::set_rgb_primaries <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::set_rgb_primaries Line | Count | Source | 1088 | 26 | pub fn set_rgb_primaries(&mut self, color: CicpColorPrimaries) { | 1089 | 26 | self.color.primaries = color; | 1090 | 26 | } |
<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::set_rgb_primaries Line | Count | Source | 1088 | 37 | pub fn set_rgb_primaries(&mut self, color: CicpColorPrimaries) { | 1089 | 37 | self.color.primaries = color; | 1090 | 37 | } |
|
1091 | | |
1092 | | /// Define the transfer function for the image. |
1093 | | /// |
1094 | | /// The color data is unchanged. Reinterprets all (non-alpha) components in the image, |
1095 | | /// potentially changing the apparent shade of pixels. Individual components are always |
1096 | | /// interpreted as encoded numbers. To denote numbers in a linear RGB space, use |
1097 | | /// [`CicpTransferCharacteristics::Linear`]. |
1098 | | /// |
1099 | | /// The default color space is [`Cicp::SRGB`]. |
1100 | 7.48k | pub fn set_transfer_function(&mut self, tf: CicpTransferCharacteristics) { |
1101 | 7.48k | self.color.transfer = tf; |
1102 | 7.48k | } <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::set_transfer_function Line | Count | Source | 1100 | 149 | pub fn set_transfer_function(&mut self, tf: CicpTransferCharacteristics) { | 1101 | 149 | self.color.transfer = tf; | 1102 | 149 | } |
<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::set_transfer_function Line | Count | Source | 1100 | 2.73k | pub fn set_transfer_function(&mut self, tf: CicpTransferCharacteristics) { | 1101 | 2.73k | self.color.transfer = tf; | 1102 | 2.73k | } |
<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::set_transfer_function Line | Count | Source | 1100 | 52 | pub fn set_transfer_function(&mut self, tf: CicpTransferCharacteristics) { | 1101 | 52 | self.color.transfer = tf; | 1102 | 52 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::set_transfer_function <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::set_transfer_function Line | Count | Source | 1100 | 704 | pub fn set_transfer_function(&mut self, tf: CicpTransferCharacteristics) { | 1101 | 704 | self.color.transfer = tf; | 1102 | 704 | } |
<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::set_transfer_function Line | Count | Source | 1100 | 240 | pub fn set_transfer_function(&mut self, tf: CicpTransferCharacteristics) { | 1101 | 240 | self.color.transfer = tf; | 1102 | 240 | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::set_transfer_function Line | Count | Source | 1100 | 9 | pub fn set_transfer_function(&mut self, tf: CicpTransferCharacteristics) { | 1101 | 9 | self.color.transfer = tf; | 1102 | 9 | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::set_transfer_function Line | Count | Source | 1100 | 3.48k | pub fn set_transfer_function(&mut self, tf: CicpTransferCharacteristics) { | 1101 | 3.48k | self.color.transfer = tf; | 1102 | 3.48k | } |
<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::set_transfer_function Line | Count | Source | 1100 | 44 | pub fn set_transfer_function(&mut self, tf: CicpTransferCharacteristics) { | 1101 | 44 | self.color.transfer = tf; | 1102 | 44 | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::set_transfer_function <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::set_transfer_function Line | Count | Source | 1100 | 26 | pub fn set_transfer_function(&mut self, tf: CicpTransferCharacteristics) { | 1101 | 26 | self.color.transfer = tf; | 1102 | 26 | } |
<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::set_transfer_function Line | Count | Source | 1100 | 37 | pub fn set_transfer_function(&mut self, tf: CicpTransferCharacteristics) { | 1101 | 37 | self.color.transfer = tf; | 1102 | 37 | } |
|
1103 | | |
1104 | | /// Get the Cicp encoding of this buffer's color data. |
1105 | 0 | pub fn color_space(&self) -> Cicp { |
1106 | 0 | self.color.into() |
1107 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::color_space |
1108 | | |
1109 | | /// Set primaries and transfer characteristics from a Cicp color space. |
1110 | | /// |
1111 | | /// Returns an error if `cicp` uses features that are not support with an RGB color space, e.g. |
1112 | | /// a matrix or narrow range (studio encoding) channels. |
1113 | 0 | pub fn set_color_space(&mut self, cicp: Cicp) -> ImageResult<()> { |
1114 | 0 | self.color = cicp.try_into_rgb()?; |
1115 | 0 | Ok(()) |
1116 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::set_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::set_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::set_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::set_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::set_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::set_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::set_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::set_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::set_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::set_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::set_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::set_color_space |
1117 | | |
1118 | 0 | pub(crate) fn set_rgb_color_space(&mut self, color: CicpRgb) { |
1119 | 0 | self.color = color; |
1120 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::set_rgb_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::set_rgb_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::set_rgb_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::set_rgb_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::set_rgb_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::set_rgb_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::set_rgb_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::set_rgb_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::set_rgb_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::set_rgb_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::set_rgb_color_space Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::set_rgb_color_space |
1121 | | } |
1122 | | |
1123 | | impl<P, Container> ImageBuffer<P, Container> |
1124 | | where |
1125 | | P: Pixel + PixelWithColorType, |
1126 | | [P::Subpixel]: EncodableLayout, |
1127 | | Container: Deref<Target = [P::Subpixel]>, |
1128 | | { |
1129 | | /// Saves the buffer to a file at the path specified. |
1130 | | /// |
1131 | | /// The image format is derived from the file extension. |
1132 | 0 | pub fn save<Q>(&self, path: Q) -> ImageResult<()> |
1133 | 0 | where |
1134 | 0 | Q: AsRef<Path>, |
1135 | | { |
1136 | 0 | save_buffer( |
1137 | 0 | path, |
1138 | 0 | self.subpixels().as_bytes(), |
1139 | 0 | self.width(), |
1140 | 0 | self.height(), |
1141 | | P::COLOR_TYPE, |
1142 | | ) |
1143 | 0 | } |
1144 | | |
1145 | | /// Saves the buffer to a file at the specified path in |
1146 | | /// the specified format. |
1147 | | /// |
1148 | | /// See [`save_buffer_with_format`](crate::save_buffer_with_format) for |
1149 | | /// supported types. |
1150 | 0 | pub fn save_with_format<Q>(&self, path: Q, format: ImageFormat) -> ImageResult<()> |
1151 | 0 | where |
1152 | 0 | Q: AsRef<Path>, |
1153 | | { |
1154 | 0 | save_buffer_with_format( |
1155 | 0 | path, |
1156 | 0 | self.subpixels().as_bytes(), |
1157 | 0 | self.width(), |
1158 | 0 | self.height(), |
1159 | | P::COLOR_TYPE, |
1160 | 0 | format, |
1161 | | ) |
1162 | 0 | } |
1163 | | |
1164 | | /// Writes the buffer to a writer in the specified format. |
1165 | | /// |
1166 | | /// Assumes the writer is buffered. In most cases, you should wrap your writer in a `BufWriter` |
1167 | | /// for best performance. |
1168 | 1.88k | pub fn write_to<W>(&self, writer: &mut W, format: ImageFormat) -> ImageResult<()> |
1169 | 1.88k | where |
1170 | 1.88k | W: std::io::Write + std::io::Seek, |
1171 | | { |
1172 | 1.88k | write_buffer_with_format( |
1173 | 1.88k | writer, |
1174 | 1.88k | self.subpixels().as_bytes(), |
1175 | 1.88k | self.width(), |
1176 | 1.88k | self.height(), |
1177 | | P::COLOR_TYPE, |
1178 | 1.88k | format, |
1179 | | ) |
1180 | 1.88k | } 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 | 1168 | 1.88k | pub fn write_to<W>(&self, writer: &mut W, format: ImageFormat) -> ImageResult<()> | 1169 | 1.88k | where | 1170 | 1.88k | W: std::io::Write + std::io::Seek, | 1171 | | { | 1172 | 1.88k | write_buffer_with_format( | 1173 | 1.88k | writer, | 1174 | 1.88k | self.subpixels().as_bytes(), | 1175 | 1.88k | self.width(), | 1176 | 1.88k | self.height(), | 1177 | | P::COLOR_TYPE, | 1178 | 1.88k | format, | 1179 | | ) | 1180 | 1.88k | } |
|
1181 | | |
1182 | | /// Writes the buffer with the given encoder. |
1183 | 0 | pub fn write_with_encoder<E>(&self, encoder: E) -> ImageResult<()> |
1184 | 0 | where |
1185 | 0 | E: ImageEncoder, |
1186 | | { |
1187 | 0 | encoder.write_image( |
1188 | 0 | self.subpixels().as_bytes(), |
1189 | 0 | self.width(), |
1190 | 0 | self.height(), |
1191 | | P::COLOR_TYPE, |
1192 | | ) |
1193 | 0 | } |
1194 | | } |
1195 | | |
1196 | | impl<P, Container> Default for ImageBuffer<P, Container> |
1197 | | where |
1198 | | P: Pixel, |
1199 | | Container: Default, |
1200 | | { |
1201 | 41.7k | fn default() -> Self { |
1202 | 41.7k | Self { |
1203 | 41.7k | width: 0, |
1204 | 41.7k | height: 0, |
1205 | 41.7k | _phantom: PhantomData, |
1206 | 41.7k | color: Cicp::SRGB.into_rgb(), |
1207 | 41.7k | data: Default::default(), |
1208 | 41.7k | } |
1209 | 41.7k | } |
1210 | | } |
1211 | | |
1212 | | impl<P, Container> Deref for ImageBuffer<P, Container> |
1213 | | where |
1214 | | P: Pixel, |
1215 | | Container: Deref<Target = [P::Subpixel]>, |
1216 | | { |
1217 | | type Target = [P::Subpixel]; |
1218 | | |
1219 | 0 | fn deref(&self) -> &<Self as Deref>::Target { |
1220 | 0 | &self.data |
1221 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>> as core::ops::deref::Deref>::deref Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>> as core::ops::deref::Deref>::deref |
1222 | | } |
1223 | | |
1224 | | impl<P, Container> DerefMut for ImageBuffer<P, Container> |
1225 | | where |
1226 | | P: Pixel, |
1227 | | Container: Deref<Target = [P::Subpixel]> + DerefMut, |
1228 | | { |
1229 | 0 | fn deref_mut(&mut self) -> &mut <Self as Deref>::Target { |
1230 | 0 | &mut self.data |
1231 | 0 | } |
1232 | | } |
1233 | | |
1234 | | impl<P, Container> Index<(u32, u32)> for ImageBuffer<P, Container> |
1235 | | where |
1236 | | P: Pixel, |
1237 | | Container: Deref<Target = [P::Subpixel]>, |
1238 | | { |
1239 | | type Output = P; |
1240 | | |
1241 | 0 | fn index(&self, (x, y): (u32, u32)) -> &P { |
1242 | 0 | self.get_pixel(x, y) |
1243 | 0 | } |
1244 | | } |
1245 | | |
1246 | | impl<P, Container> IndexMut<(u32, u32)> for ImageBuffer<P, Container> |
1247 | | where |
1248 | | P: Pixel, |
1249 | | Container: Deref<Target = [P::Subpixel]> + DerefMut, |
1250 | | { |
1251 | 0 | fn index_mut(&mut self, (x, y): (u32, u32)) -> &mut P { |
1252 | 0 | self.get_pixel_mut(x, y) |
1253 | 0 | } |
1254 | | } |
1255 | | |
1256 | | impl<P, Container> Clone for ImageBuffer<P, Container> |
1257 | | where |
1258 | | P: Pixel, |
1259 | | Container: Clone, |
1260 | | { |
1261 | 0 | fn clone(&self) -> ImageBuffer<P, Container> { |
1262 | 0 | ImageBuffer { |
1263 | 0 | data: self.data.clone(), |
1264 | 0 | width: self.width, |
1265 | 0 | height: self.height, |
1266 | 0 | color: self.color, |
1267 | 0 | _phantom: PhantomData, |
1268 | 0 | } |
1269 | 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<f32>, alloc::vec::Vec<f32>> 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<f32>, alloc::vec::Vec<f32>> 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 |
1270 | | |
1271 | 0 | fn clone_from(&mut self, source: &Self) { |
1272 | 0 | self.data.clone_from(&source.data); |
1273 | 0 | self.width = source.width; |
1274 | 0 | self.height = source.height; |
1275 | 0 | self.color = source.color; |
1276 | 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<f32>, alloc::vec::Vec<f32>> 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<f32>, alloc::vec::Vec<f32>> 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 |
1277 | | } |
1278 | | |
1279 | | impl<P, Container> fmt::Debug for ImageBuffer<P, Container> |
1280 | | where |
1281 | | P: Pixel + fmt::Debug, |
1282 | | Container: fmt::Debug, |
1283 | | { |
1284 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
1285 | 0 | let mut pixel = std::any::type_name::<P>(); |
1286 | 0 | pixel = pixel.strip_prefix("image::color::").unwrap_or(pixel); |
1287 | | |
1288 | 0 | let mut debug_struct = f.debug_struct(&format!("ImageBuffer::<{pixel}, _>")); |
1289 | 0 | debug_struct.field("width", &self.width); |
1290 | 0 | debug_struct.field("height", &self.height); |
1291 | | |
1292 | 0 | if let Some(color_name) = self.color.known_name() { |
1293 | 0 | debug_struct.field("color", &color_name); |
1294 | 0 | } else { |
1295 | 0 | debug_struct.field("color", &self.color); |
1296 | 0 | } |
1297 | | |
1298 | 0 | debug_struct.finish() |
1299 | 0 | } |
1300 | | } |
1301 | | |
1302 | | impl<P, Container> GenericImageView for ImageBuffer<P, Container> |
1303 | | where |
1304 | | P: Pixel, |
1305 | | Container: Deref<Target = [P::Subpixel]>, |
1306 | | { |
1307 | | type Pixel = P; |
1308 | | |
1309 | 1 | fn dimensions(&self) -> (u32, u32) { |
1310 | 1 | self.dimensions() |
1311 | 1 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImageView>::dimensions <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::dimensions Line | Count | Source | 1309 | 1 | fn dimensions(&self) -> (u32, u32) { | 1310 | 1 | self.dimensions() | 1311 | 1 | } |
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<f32>, alloc::vec::Vec<f32>> 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<f32>, alloc::vec::Vec<f32>> 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 |
1312 | | |
1313 | 2 | fn get_pixel(&self, x: u32, y: u32) -> P { |
1314 | 2 | *self.get_pixel(x, y) |
1315 | 2 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImageView>::get_pixel <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::get_pixel Line | Count | Source | 1313 | 2 | fn get_pixel(&self, x: u32, y: u32) -> P { | 1314 | 2 | *self.get_pixel(x, y) | 1315 | 2 | } |
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<f32>, alloc::vec::Vec<f32>> 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<f32>, alloc::vec::Vec<f32>> 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 |
1316 | | |
1317 | 0 | fn to_pixel_view(&self) -> Option<ViewOfPixel<'_, Self::Pixel>> { |
1318 | 0 | Some(self.as_pixel_view()) |
1319 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImageView>::to_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::to_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImageView>::to_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImageView>::to_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::to_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImageView>::to_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImageView>::to_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::to_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImageView>::to_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImageView>::to_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::to_pixel_view Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImageView>::to_pixel_view |
1320 | | |
1321 | | /// Returns the pixel located at (x, y), ignoring bounds checking. |
1322 | | #[inline(always)] |
1323 | 0 | unsafe fn unsafe_get_pixel(&self, x: u32, y: u32) -> P { |
1324 | 0 | let indices = self.pixel_indices_unchecked(x, y); |
1325 | 0 | *<P as Pixel>::from_slice(self.data.get_unchecked(indices)) |
1326 | 0 | } |
1327 | | |
1328 | 0 | fn buffer_with_dimensions(&self, width: u32, height: u32) -> ImageBuffer<P, Vec<P::Subpixel>> { |
1329 | 0 | let mut buffer = ImageBuffer::new(width, height); |
1330 | 0 | buffer.copy_color_space_from(self); |
1331 | 0 | buffer |
1332 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImageView>::buffer_with_dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::buffer_with_dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImageView>::buffer_with_dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImageView>::buffer_with_dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::buffer_with_dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImageView>::buffer_with_dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImageView>::buffer_with_dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::buffer_with_dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImageView>::buffer_with_dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImageView>::buffer_with_dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImageView>::buffer_with_dimensions Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImageView>::buffer_with_dimensions |
1333 | | } |
1334 | | |
1335 | | impl<P, Container> GenericImage for ImageBuffer<P, Container> |
1336 | | where |
1337 | | P: Pixel, |
1338 | | Container: Deref<Target = [P::Subpixel]> + DerefMut, |
1339 | | { |
1340 | 2 | fn put_pixel(&mut self, x: u32, y: u32, pixel: P) { |
1341 | 2 | *self.get_pixel_mut(x, y) = pixel; |
1342 | 2 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImage>::put_pixel <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::put_pixel Line | Count | Source | 1340 | 2 | fn put_pixel(&mut self, x: u32, y: u32, pixel: P) { | 1341 | 2 | *self.get_pixel_mut(x, y) = pixel; | 1342 | 2 | } |
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<f32>, alloc::vec::Vec<f32>> 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<f32>, alloc::vec::Vec<f32>> 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 |
1343 | | |
1344 | | /// Puts a pixel at location (x, y), ignoring bounds checking. |
1345 | | #[inline(always)] |
1346 | 0 | unsafe fn unsafe_put_pixel(&mut self, x: u32, y: u32, pixel: P) { |
1347 | 0 | let indices = self.pixel_indices_unchecked(x, y); |
1348 | 0 | let p = <P as Pixel>::from_slice_mut(self.data.get_unchecked_mut(indices)); |
1349 | 0 | *p = pixel; |
1350 | 0 | } |
1351 | | |
1352 | 0 | fn copy_from_samples( |
1353 | 0 | &mut self, |
1354 | 0 | view: ViewOfPixel<'_, Self::Pixel>, |
1355 | 0 | x: u32, |
1356 | 0 | y: u32, |
1357 | 0 | ) -> ImageResult<()> { |
1358 | 0 | let (width, height) = view.dimensions(); |
1359 | 0 | let pix_stride = usize::from(<Self::Pixel as Pixel>::CHANNEL_COUNT); |
1360 | 0 | Rect::from_image_at(&view, x, y).test_in_bounds_of(self)?; |
1361 | | |
1362 | 0 | if width == 0 || height == 0 || pix_stride == 0 { |
1363 | 0 | return Ok(()); |
1364 | 0 | } |
1365 | | |
1366 | | // Since this image is not empty, all its indices fit into `usize` as they address the |
1367 | | // memory resident buffer of `self`. |
1368 | 0 | let row_len = width as usize * pix_stride; |
1369 | 0 | let img_sh = self.width as usize; |
1370 | | |
1371 | 0 | let (sw, sh) = view.strides_wh(); |
1372 | 0 | let view_samples: &[_] = view.samples(); |
1373 | 0 | let inner = self.subpixels_mut(); |
1374 | | |
1375 | 0 | let img_pixel_indices_unchecked = |
1376 | 0 | |x: u32, y: u32| (y as usize * img_sh + x as usize) * pix_stride; Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImage>::copy_from_samples::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::copy_from_samples::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::copy_from_samples::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImage>::copy_from_samples::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::copy_from_samples::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::copy_from_samples::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImage>::copy_from_samples::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::copy_from_samples::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::copy_from_samples::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImage>::copy_from_samples::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::copy_from_samples::{closure#0}Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::copy_from_samples::{closure#0} |
1377 | | |
1378 | | // Can we use row-by-row byte copy? |
1379 | 0 | if sw == pix_stride { |
1380 | 0 | for j in 0..height { |
1381 | 0 | let start = img_pixel_indices_unchecked(x, j + y); |
1382 | 0 | let img_row = &mut inner[start..][..row_len]; |
1383 | 0 | let view_row = &view_samples[j as usize * sh..][..row_len]; |
1384 | 0 | img_row.copy_from_slice(view_row); |
1385 | 0 | } |
1386 | | |
1387 | 0 | return Ok(()); |
1388 | 0 | } |
1389 | | |
1390 | | // Fallback behavior. |
1391 | 0 | for j in 0..height { |
1392 | 0 | let img_start = img_pixel_indices_unchecked(x, j + y); |
1393 | 0 | let img_row = &mut inner[img_start..][..row_len]; |
1394 | 0 | let pixels = img_row.chunks_exact_mut(pix_stride); |
1395 | | |
1396 | 0 | let view_start = j as usize * sh; |
1397 | | |
1398 | 0 | for (i, sp) in pixels.enumerate() { |
1399 | 0 | let view_pixel = &view_samples[i * sw + view_start..][..pix_stride]; |
1400 | 0 | sp.copy_from_slice(view_pixel); |
1401 | 0 | } |
1402 | | } |
1403 | | |
1404 | 0 | Ok(()) |
1405 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImage>::copy_from_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::copy_from_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::copy_from_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImage>::copy_from_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::copy_from_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::copy_from_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImage>::copy_from_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::copy_from_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::copy_from_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImage>::copy_from_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::copy_from_samples Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::copy_from_samples |
1406 | | |
1407 | 0 | fn copy_within(&mut self, source: Rect, x: u32, y: u32) -> bool { |
1408 | | let Rect { |
1409 | 0 | x: sx, |
1410 | 0 | y: sy, |
1411 | 0 | width, |
1412 | 0 | height, |
1413 | 0 | } = source; |
1414 | 0 | let dx = x; |
1415 | 0 | let dy = y; |
1416 | 0 | assert!(sx < self.width() && dx < self.width()); |
1417 | 0 | assert!(sy < self.height() && dy < self.height()); |
1418 | 0 | if self.width() - dx.max(sx) < width || self.height() - dy.max(sy) < height { |
1419 | 0 | return false; |
1420 | 0 | } |
1421 | | |
1422 | 0 | if sy < dy { |
1423 | 0 | for y in (0..height).rev() { |
1424 | 0 | let sy = sy + y; |
1425 | 0 | let dy = dy + y; |
1426 | 0 | let Range { start, .. } = self.pixel_indices_unchecked(sx, sy); |
1427 | 0 | let Range { end, .. } = self.pixel_indices_unchecked(sx + width - 1, sy); |
1428 | 0 | let dst = self.pixel_indices_unchecked(dx, dy).start; |
1429 | 0 | self.data.copy_within(start..end, dst); |
1430 | 0 | } |
1431 | | } else { |
1432 | 0 | for y in 0..height { |
1433 | 0 | let sy = sy + y; |
1434 | 0 | let dy = dy + y; |
1435 | 0 | let Range { start, .. } = self.pixel_indices_unchecked(sx, sy); |
1436 | 0 | let Range { end, .. } = self.pixel_indices_unchecked(sx + width - 1, sy); |
1437 | 0 | let dst = self.pixel_indices_unchecked(dx, dy).start; |
1438 | 0 | self.data.copy_within(start..end, dst); |
1439 | 0 | } |
1440 | | } |
1441 | 0 | true |
1442 | 0 | } |
1443 | | |
1444 | 0 | fn to_pixel_view_mut(&mut self) -> Option<ViewMutOfPixel<'_, Self::Pixel>> { |
1445 | 0 | Some(self.as_pixel_view_mut()) |
1446 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImage>::to_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::to_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::to_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImage>::to_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::to_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::to_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImage>::to_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::to_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::to_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>> as image::images::generic_image::GenericImage>::to_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>> as image::images::generic_image::GenericImage>::to_pixel_view_mut Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>> as image::images::generic_image::GenericImage>::to_pixel_view_mut |
1447 | | } |
1448 | | |
1449 | | // concrete implementation for `Vec`-backed buffers |
1450 | | // TODO: I think that rustc does not "see" this impl any more: the impl with |
1451 | | // Container meets the same requirements. At least, I got compile errors that |
1452 | | // there is no such function as `into_vec`, whereas `into_raw` did work, and |
1453 | | // `into_vec` is redundant anyway, because `into_raw` will give you the vector, |
1454 | | // and it is more generic. |
1455 | | impl<P: Pixel> ImageBuffer<P, Vec<P::Subpixel>> { |
1456 | | /// Creates a new image buffer based on a `Vec<P::Subpixel>`. |
1457 | | /// |
1458 | | /// all the pixels of this image have a value of zero, regardless of the data type or number of channels. |
1459 | | /// |
1460 | | /// The color space is initially set to [`sRGB`][`Cicp::SRGB`]. |
1461 | | /// |
1462 | | /// # Panics |
1463 | | /// |
1464 | | /// Panics when the resulting image is larger than the maximum size of a vector. |
1465 | | #[must_use] |
1466 | 2.62k | pub fn new(width: u32, height: u32) -> ImageBuffer<P, Vec<P::Subpixel>> { |
1467 | 2.62k | let size = Self::image_buffer_len(width, height) |
1468 | 2.62k | .expect("Buffer length in `ImageBuffer::new` overflows usize"); |
1469 | 2.62k | ImageBuffer { |
1470 | 2.62k | data: vec![Zero::zero(); size], |
1471 | 2.62k | width, |
1472 | 2.62k | height, |
1473 | 2.62k | color: Cicp::SRGB.into_rgb(), |
1474 | 2.62k | _phantom: PhantomData, |
1475 | 2.62k | } |
1476 | 2.62k | } 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 <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::new Line | Count | Source | 1466 | 2.62k | pub fn new(width: u32, height: u32) -> ImageBuffer<P, Vec<P::Subpixel>> { | 1467 | 2.62k | let size = Self::image_buffer_len(width, height) | 1468 | 2.62k | .expect("Buffer length in `ImageBuffer::new` overflows usize"); | 1469 | 2.62k | ImageBuffer { | 1470 | 2.62k | data: vec![Zero::zero(); size], | 1471 | 2.62k | width, | 1472 | 2.62k | height, | 1473 | 2.62k | color: Cicp::SRGB.into_rgb(), | 1474 | 2.62k | _phantom: PhantomData, | 1475 | 2.62k | } | 1476 | 2.62k | } |
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 |
1477 | | |
1478 | | /// Constructs a new `ImageBuffer` by copying a pixel |
1479 | | /// |
1480 | | /// # Panics |
1481 | | /// |
1482 | | /// Panics when the resulting image is larger than the maximum size of a vector. |
1483 | 2.62k | pub fn from_pixel(width: u32, height: u32, pixel: P) -> ImageBuffer<P, Vec<P::Subpixel>> { |
1484 | 2.62k | let mut buf = ImageBuffer::new(width, height); |
1485 | 2.62k | buf.pixels_mut().fill(pixel); |
1486 | 2.62k | buf |
1487 | 2.62k | } |
1488 | | |
1489 | | /// Constructs a new `ImageBuffer` by repeated application of the supplied function. |
1490 | | /// |
1491 | | /// The arguments to the function are the pixel's x and y coordinates. |
1492 | | /// |
1493 | | /// # Panics |
1494 | | /// |
1495 | | /// Panics when the resulting image is larger than the maximum size of a vector. |
1496 | 0 | pub fn from_fn<F>(width: u32, height: u32, mut f: F) -> ImageBuffer<P, Vec<P::Subpixel>> |
1497 | 0 | where |
1498 | 0 | F: FnMut(u32, u32) -> P, |
1499 | | { |
1500 | 0 | let mut buf = ImageBuffer::new(width, height); |
1501 | 0 | for (x, y, p) in buf.enumerate_pixels_mut() { |
1502 | 0 | *p = f(x, y); |
1503 | 0 | } |
1504 | 0 | buf |
1505 | 0 | } |
1506 | | |
1507 | | /// Creates an image buffer out of an existing buffer. |
1508 | | /// Returns None if the buffer is not big enough. |
1509 | | #[must_use] |
1510 | 1.88k | pub fn from_vec( |
1511 | 1.88k | width: u32, |
1512 | 1.88k | height: u32, |
1513 | 1.88k | buf: Vec<P::Subpixel>, |
1514 | 1.88k | ) -> Option<ImageBuffer<P, Vec<P::Subpixel>>> { |
1515 | 1.88k | ImageBuffer::from_raw(width, height, buf) |
1516 | 1.88k | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::from_vec Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::from_vec Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::from_vec Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::from_vec Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::from_vec Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::from_vec Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::from_vec <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::from_vec Line | Count | Source | 1510 | 1.88k | pub fn from_vec( | 1511 | 1.88k | width: u32, | 1512 | 1.88k | height: u32, | 1513 | 1.88k | buf: Vec<P::Subpixel>, | 1514 | 1.88k | ) -> Option<ImageBuffer<P, Vec<P::Subpixel>>> { | 1515 | 1.88k | ImageBuffer::from_raw(width, height, buf) | 1516 | 1.88k | } |
Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::from_vec Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::from_vec Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::from_vec Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::from_vec |
1517 | | |
1518 | | /// Consumes the image buffer and returns the underlying data |
1519 | | /// as an owned buffer |
1520 | | #[must_use] |
1521 | 1.88k | pub fn into_vec(self) -> Vec<P::Subpixel> { |
1522 | 1.88k | self.into_raw() |
1523 | 1.88k | } 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 | 1521 | 1.88k | pub fn into_vec(self) -> Vec<P::Subpixel> { | 1522 | 1.88k | self.into_raw() | 1523 | 1.88k | } |
|
1524 | | |
1525 | | /// Shrink the length and capacity of the data buffer to fit the image size. |
1526 | | /// |
1527 | | /// This is useful after shrinking an image in-place, e.g. via cropping, to free unused memory |
1528 | | /// or in case the image was created from a buffer with excess capacity. |
1529 | | /// |
1530 | | /// ``` |
1531 | | /// use image::RgbImage; |
1532 | | /// |
1533 | | /// let data = vec![0u8; 10000]; |
1534 | | /// // `from_raw` allows excess data |
1535 | | /// let mut img = RgbImage::from_raw(16, 16, data).unwrap(); |
1536 | | /// img.shrink_to_fit(); |
1537 | | /// |
1538 | | /// assert_eq!(img.into_vec().len(), 16 * 16 * 3); |
1539 | | /// ``` |
1540 | 0 | pub fn shrink_to_fit(&mut self) { |
1541 | 0 | let need = self.subpixels().len(); |
1542 | 0 | self.data.truncate(need); |
1543 | 0 | self.data.shrink_to_fit(); |
1544 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::shrink_to_fit Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::shrink_to_fit Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::shrink_to_fit Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::shrink_to_fit Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::shrink_to_fit Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::shrink_to_fit Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::shrink_to_fit Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::shrink_to_fit Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::shrink_to_fit Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::shrink_to_fit Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::shrink_to_fit Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::shrink_to_fit |
1545 | | |
1546 | | /// Transfer the meta data, not the pixel values. |
1547 | | /// |
1548 | | /// This will reinterpret all the pixels. |
1549 | | /// |
1550 | | /// We may want to export this but under what name? |
1551 | 0 | pub(crate) fn copy_color_space_from<O: Pixel, C>(&mut self, other: &ImageBuffer<O, C>) { |
1552 | 0 | self.color = other.color; |
1553 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgb<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgb<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgb<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Luma<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Luma<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Luma<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgba<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgba<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgba<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::LumaA<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::LumaA<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::LumaA<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgb<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgb<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgb<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Luma<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Luma<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Luma<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgba<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgba<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgba<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::LumaA<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::LumaA<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::LumaA<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgb<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgb<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgb<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Luma<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Luma<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Luma<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgba<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgba<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgba<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::LumaA<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::LumaA<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::LumaA<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Luma<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Luma<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Luma<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgb<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgb<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgb<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgba<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgba<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgba<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::LumaA<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::LumaA<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::LumaA<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Luma<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Luma<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Luma<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgb<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgb<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgb<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgba<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgba<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgba<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::LumaA<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::LumaA<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::LumaA<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Luma<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Luma<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Luma<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgb<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgb<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgb<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgba<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgba<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgba<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::LumaA<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::LumaA<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::LumaA<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgba<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgba<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgba<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgb<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgb<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgb<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Luma<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Luma<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Luma<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::LumaA<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::LumaA<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::LumaA<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgba<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgba<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgba<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgb<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgb<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgb<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Luma<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Luma<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Luma<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::LumaA<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::LumaA<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::LumaA<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgba<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgba<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgba<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgb<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgb<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgb<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Luma<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Luma<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Luma<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::LumaA<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::LumaA<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::LumaA<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::LumaA<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::LumaA<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::LumaA<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgb<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgb<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgb<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Luma<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Luma<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Luma<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgba<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgba<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::copy_color_space_from::<image::color::Rgba<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::LumaA<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::LumaA<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::LumaA<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgb<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgb<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgb<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Luma<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Luma<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Luma<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgba<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgba<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgba<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::LumaA<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::LumaA<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::LumaA<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgb<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgb<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgb<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Luma<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Luma<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Luma<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgba<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgba<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::copy_color_space_from::<image::color::Rgba<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgba<u16>, &[u16]> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Rgb<u16>, &[u16]> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Luma<u8>, &[u8]> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::Luma<u16>, &[u16]> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::LumaA<u8>, &[u8]> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_color_space_from::<image::color::LumaA<u16>, &[u16]> |
1554 | | } |
1555 | | |
1556 | | impl<S, Container> ImageBuffer<Rgb<S>, Container> |
1557 | | where |
1558 | | Rgb<S>: PixelWithColorType<Subpixel = S>, |
1559 | | S: Primitive, |
1560 | | Container: DerefMut<Target = [S]>, |
1561 | | { |
1562 | | /// Construct an image by swapping `Bgr` channels into an `Rgb` order. |
1563 | 0 | pub fn from_raw_bgr(width: u32, height: u32, container: Container) -> Option<Self> { |
1564 | 0 | let mut img = Self::from_raw(width, height, container)?; |
1565 | 0 | S::swizzle_rgb_bgr(img.subpixels_mut()); |
1566 | 0 | Some(img) |
1567 | 0 | } |
1568 | | |
1569 | | /// Return the underlying raw buffer after converting it into `Bgr` channel order. |
1570 | 0 | pub fn into_raw_bgr(mut self) -> Container { |
1571 | 0 | S::swizzle_rgb_bgr(self.subpixels_mut()); |
1572 | 0 | self.into_raw() |
1573 | 0 | } |
1574 | | } |
1575 | | |
1576 | | impl<S, Container> ImageBuffer<Rgba<S>, Container> |
1577 | | where |
1578 | | Rgba<S>: PixelWithColorType<Subpixel = S>, |
1579 | | S: Primitive, |
1580 | | Container: DerefMut<Target = [S]>, |
1581 | | { |
1582 | | /// Construct an image by swapping `BgrA` channels into an `RgbA` order. |
1583 | 0 | pub fn from_raw_bgra(width: u32, height: u32, container: Container) -> Option<Self> { |
1584 | 0 | let mut img = Self::from_raw(width, height, container)?; |
1585 | 0 | S::swizzle_rgba_bgra(img.subpixels_mut()); |
1586 | 0 | Some(img) |
1587 | 0 | } |
1588 | | |
1589 | | /// Return the underlying raw buffer after converting it into `BgrA` channel order. |
1590 | 0 | pub fn into_raw_bgra(mut self) -> Container { |
1591 | 0 | S::swizzle_rgba_bgra(self.subpixels_mut()); |
1592 | 0 | self.into_raw() |
1593 | 0 | } |
1594 | | } |
1595 | | |
1596 | | impl GrayImage { |
1597 | | /// Expands a color palette into an RGBA image. Uses an optionally |
1598 | | /// transparent index to adjust its alpha value accordingly. |
1599 | | /// |
1600 | | /// Color indexes not in the palette are mapped to transparent black, |
1601 | | /// i.e. (0, 0, 0, 0). |
1602 | | #[must_use] |
1603 | 0 | pub fn expand_palette( |
1604 | 0 | &self, |
1605 | 0 | palette: &[(u8, u8, u8)], |
1606 | 0 | transparent_idx: Option<u8>, |
1607 | 0 | ) -> RgbaImage { |
1608 | 0 | let (width, height) = self.dimensions(); |
1609 | | |
1610 | 0 | let mut full_palette = vec![[0_u8; 4]; 256]; |
1611 | 0 | let full_palette: &mut [[u8; 4]; 256] = full_palette.as_mut_slice().try_into().unwrap(); |
1612 | 0 | for ((r, g, b), entry) in palette.iter().zip(full_palette.iter_mut()) { |
1613 | 0 | *entry = [*r, *g, *b, 255]; |
1614 | 0 | } |
1615 | 0 | if let Some(palette_index) = transparent_idx { |
1616 | 0 | full_palette[palette_index as usize][3] = 0; |
1617 | 0 | } |
1618 | | |
1619 | 0 | let rgba_data: Vec<[u8; 4]> = self |
1620 | 0 | .subpixels() |
1621 | 0 | .iter() |
1622 | 0 | .map(|&palette_index| full_palette[palette_index as usize]) |
1623 | 0 | .collect(); |
1624 | | |
1625 | 0 | ImageBuffer::from_vec(width, height, rgba_data.into_flattened()).unwrap() |
1626 | 0 | } |
1627 | | } |
1628 | | |
1629 | | impl<P: Pixel, Container> ImageBuffer<P, Container> |
1630 | | where |
1631 | | Container: Deref<Target = [P::Subpixel]>, |
1632 | | { |
1633 | | /// Convert this image buffer to another pixel type, copying the color space information. |
1634 | | /// |
1635 | | /// The conversion uses [`FromColor`] and ignores color space information. The resulting image |
1636 | | /// will have the same color space as the original, which may lead to incorrect colors if the |
1637 | | /// source and target pixel types have different color types, e.g. `Rgb` and `Luma`. |
1638 | | /// In that case, the conversion is a best effort and may be inaccurate. |
1639 | | /// Conversions between alpha and non-alpha variants of Pixels are correct regarding the color space. |
1640 | | /// |
1641 | | /// # Examples |
1642 | | /// |
1643 | | /// Convert RGB image to gray image. |
1644 | | /// |
1645 | | /// ```no_run |
1646 | | /// use image::GrayImage; |
1647 | | /// |
1648 | | /// let image_path = "examples/fractal.png"; |
1649 | | /// let image = image::open(&image_path) |
1650 | | /// .expect("Open file failed") |
1651 | | /// .to_rgba8(); |
1652 | | /// |
1653 | | /// let gray_image: GrayImage = image.convert(); |
1654 | | /// ``` |
1655 | 0 | pub fn convert<ToType>(&self) -> ImageBuffer<ToType, Vec<ToType::Subpixel>> |
1656 | 0 | where |
1657 | 0 | ToType: Pixel + FromColor<P>, |
1658 | | { |
1659 | 0 | let mut buffer: ImageBuffer<ToType, Vec<ToType::Subpixel>> = |
1660 | 0 | ImageBuffer::new(self.width, self.height); |
1661 | 0 | buffer.copy_color_space_from(self); |
1662 | 0 | for (to, from) in buffer.pixels_mut().iter_mut().zip(self.pixels().iter()) { |
1663 | 0 | to.from_color(from); |
1664 | 0 | } |
1665 | 0 | buffer |
1666 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<_, _>>::convert::<_> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, &[u16]>>::convert::<image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, &[u8]>>::convert::<image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, &[u16]>>::convert::<image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, &[u16]>>::convert::<image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, &[u8]>>::convert::<image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, &[u16]>>::convert::<image::color::Rgba<u8>> |
1667 | | } |
1668 | | |
1669 | | /// Inputs to [`ImageBuffer::copy_from_color_space`]. |
1670 | | #[non_exhaustive] |
1671 | | #[derive(Default)] |
1672 | | pub struct ConvertColorOptions { |
1673 | | /// A pre-calculated transform. This is only used when the actual colors of the input and |
1674 | | /// output image match the color spaces with which the was constructed. |
1675 | | /// |
1676 | | /// FIXME: Clarify that the transform is cheap to clone, i.e. internally an Arc of precomputed |
1677 | | /// tables and not expensive despite having `Clone`. |
1678 | | pub(crate) transform: Option<CicpTransform>, |
1679 | | /// Make sure we can later add options that are bound to the thread. That does not mean that |
1680 | | /// all attributes will be bound to the thread, only that we can add `!Sync` options later. You |
1681 | | /// should be constructing the options at the call site with each attribute being cheap to move |
1682 | | /// into here. |
1683 | | pub(crate) _auto_traits: PhantomData<std::rc::Rc<()>>, |
1684 | | } |
1685 | | |
1686 | | impl ConvertColorOptions { |
1687 | 0 | pub(crate) fn as_transform( |
1688 | 0 | &mut self, |
1689 | 0 | from_color: Cicp, |
1690 | 0 | into_color: Cicp, |
1691 | 0 | ) -> Result<&CicpTransform, ImageError> { |
1692 | 0 | if let Some(tr) = &self.transform { |
1693 | 0 | tr.check_applicable(from_color, into_color)?; |
1694 | 0 | } |
1695 | | |
1696 | 0 | if self.transform.is_none() { |
1697 | 0 | self.transform = CicpTransform::new(from_color, into_color); |
1698 | 0 | } |
1699 | | |
1700 | 0 | self.transform.as_ref().ok_or_else(|| { |
1701 | 0 | ImageError::Unsupported(UnsupportedError::from_format_and_kind( |
1702 | 0 | crate::error::ImageFormatHint::Unknown, |
1703 | | // One of them is responsible. |
1704 | 0 | UnsupportedErrorKind::ColorspaceCicp(if from_color.qualify_stability() { |
1705 | 0 | into_color |
1706 | | } else { |
1707 | 0 | from_color |
1708 | | }), |
1709 | | )) |
1710 | 0 | }) |
1711 | 0 | } |
1712 | | |
1713 | 0 | pub(crate) fn as_transform_fn<FromType, IntoType>( |
1714 | 0 | &mut self, |
1715 | 0 | from_color: Cicp, |
1716 | 0 | into_color: Cicp, |
1717 | 0 | ) -> Result<&'_ CicpApplicable<'_, FromType::Subpixel>, ImageError> |
1718 | 0 | where |
1719 | 0 | FromType: PixelWithColorType, |
1720 | 0 | IntoType: PixelWithColorType, |
1721 | | { |
1722 | 0 | Ok(self |
1723 | 0 | .as_transform(from_color, into_color)? |
1724 | 0 | .supported_transform_fn::<FromType, IntoType>()) |
1725 | 0 | } Unexecuted instantiation: <image::images::buffer::ConvertColorOptions>::as_transform_fn::<image::color::Rgb<f32>, image::color::Rgb<f32>> Unexecuted instantiation: <image::images::buffer::ConvertColorOptions>::as_transform_fn::<image::color::Rgb<f32>, image::color::Rgba<f32>> Unexecuted instantiation: <image::images::buffer::ConvertColorOptions>::as_transform_fn::<image::color::Rgb<u8>, image::color::Rgb<u8>> Unexecuted instantiation: <image::images::buffer::ConvertColorOptions>::as_transform_fn::<image::color::Rgb<u8>, image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ConvertColorOptions>::as_transform_fn::<image::color::Rgb<u16>, image::color::Rgb<u16>> Unexecuted instantiation: <image::images::buffer::ConvertColorOptions>::as_transform_fn::<image::color::Rgb<u16>, image::color::Rgba<u16>> Unexecuted instantiation: <image::images::buffer::ConvertColorOptions>::as_transform_fn::<image::color::Rgba<f32>, image::color::Rgba<f32>> Unexecuted instantiation: <image::images::buffer::ConvertColorOptions>::as_transform_fn::<image::color::Rgba<f32>, image::color::Rgb<f32>> Unexecuted instantiation: <image::images::buffer::ConvertColorOptions>::as_transform_fn::<image::color::Rgba<u8>, image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ConvertColorOptions>::as_transform_fn::<image::color::Rgba<u8>, image::color::Rgb<u8>> Unexecuted instantiation: <image::images::buffer::ConvertColorOptions>::as_transform_fn::<image::color::Rgba<u16>, image::color::Rgba<u16>> Unexecuted instantiation: <image::images::buffer::ConvertColorOptions>::as_transform_fn::<image::color::Rgba<u16>, image::color::Rgb<u16>> |
1726 | | } |
1727 | | |
1728 | | impl<C, SelfPixel: Pixel> ImageBuffer<SelfPixel, C> |
1729 | | where |
1730 | | SelfPixel: PixelWithColorType, |
1731 | | C: Deref<Target = [SelfPixel::Subpixel]> + DerefMut, |
1732 | | { |
1733 | | /// Convert the color data to another pixel type, the color space. |
1734 | | /// |
1735 | | /// This method is supposed to be called by exposed monomorphized methods, not directly by |
1736 | | /// users. In particular it serves to implement `DynamicImage`'s casts that go beyond those |
1737 | | /// offered by `PixelWithColorType` and include, e.g., `LumaAlpha<f32>`. |
1738 | | /// |
1739 | | /// Before exposing this method, decide if we want a design like [`DynamicImage::to`] (many |
1740 | | /// trait parameters) with color space aware `FromColor` or if we want a design that takes a |
1741 | | /// `ColorType` parameter / `PixelWithColorType`. The latter is not quite as flexible but |
1742 | | /// allows much greater internal changes that do not tie in with the _external_ stable API. |
1743 | 0 | pub(crate) fn cast_in_color_space<IntoPixel>( |
1744 | 0 | &self, |
1745 | 0 | ) -> ImageBuffer<IntoPixel, Vec<IntoPixel::Subpixel>> |
1746 | 0 | where |
1747 | 0 | SelfPixel: Pixel, |
1748 | 0 | IntoPixel: Pixel, |
1749 | 0 | IntoPixel: CicpPixelCast<SelfPixel>, |
1750 | 0 | SelfPixel::Subpixel: ColorComponentForCicp, |
1751 | 0 | IntoPixel::Subpixel: ColorComponentForCicp + FromPrimitive<SelfPixel::Subpixel>, |
1752 | | { |
1753 | 0 | let vec = self |
1754 | 0 | .color |
1755 | 0 | .cast_pixels::<SelfPixel, IntoPixel>(self.subpixels(), &|| [0.2126, 0.7152, 0.0722]); |
1756 | 0 | let mut buffer = ImageBuffer::from_vec(self.width, self.height, vec) |
1757 | 0 | .expect("cast_pixels returned the right number of pixels"); |
1758 | 0 | buffer.copy_color_space_from(self); |
1759 | 0 | buffer |
1760 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgb<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgb<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgb<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Luma<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Luma<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Luma<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgba<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgba<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::LumaA<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::LumaA<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::LumaA<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgb<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgb<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgb<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Luma<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Luma<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Luma<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgba<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgba<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::LumaA<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::LumaA<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::LumaA<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgb<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgb<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgb<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Luma<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Luma<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Luma<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgba<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgba<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::LumaA<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::LumaA<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::LumaA<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Luma<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Luma<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Luma<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgb<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgb<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgb<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgba<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgba<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::LumaA<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::LumaA<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::LumaA<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Luma<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Luma<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Luma<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgb<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgb<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgb<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgba<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgba<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::LumaA<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::LumaA<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::LumaA<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Luma<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Luma<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Luma<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgb<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgb<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgb<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgba<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgba<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::LumaA<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::LumaA<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::LumaA<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgba<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgba<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgb<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgb<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgb<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Luma<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Luma<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Luma<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::LumaA<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::LumaA<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::LumaA<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgba<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgba<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgb<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgb<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgb<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Luma<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Luma<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Luma<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::LumaA<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::LumaA<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::LumaA<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgba<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgba<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgb<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgb<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgb<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Luma<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Luma<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Luma<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::LumaA<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::LumaA<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::LumaA<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::LumaA<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::LumaA<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::LumaA<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgb<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgb<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgb<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Luma<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Luma<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Luma<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgba<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>>::cast_in_color_space::<image::color::Rgba<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::LumaA<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::LumaA<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::LumaA<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgb<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgb<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgb<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Luma<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Luma<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Luma<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgba<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>>::cast_in_color_space::<image::color::Rgba<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::LumaA<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::LumaA<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::LumaA<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgb<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgb<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgb<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Luma<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Luma<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Luma<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgba<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgba<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>>::cast_in_color_space::<image::color::Rgba<u16>> |
1761 | | |
1762 | | /// Copy pixel data from one buffer to another, calculating equivalent color representations |
1763 | | /// for the target's color space. |
1764 | | /// |
1765 | | /// Returns `Ok` if: |
1766 | | /// - Both images to have the same dimensions, otherwise returns a [`ImageError::Parameter`]. |
1767 | | /// - The primaries and transfer functions of both image's color spaces must be supported, |
1768 | | /// otherwise returns a [`ImageError::Unsupported`]. |
1769 | | /// - The pixel's channel layout must be supported for conversion, otherwise returns a |
1770 | | /// [`ImageError::Unsupported`]. You can rely on RGB and RGBA always being supported. If a |
1771 | | /// layout is supported for one color space it is supported for all of them. |
1772 | | /// |
1773 | | /// To copy color data of arbitrary channel layouts use `DynamicImage` with the overhead of |
1774 | | /// having data converted into and from RGB representation. |
1775 | 0 | pub fn copy_from_color_space<FromType, D>( |
1776 | 0 | &mut self, |
1777 | 0 | from: &ImageBuffer<FromType, D>, |
1778 | 0 | mut options: ConvertColorOptions, |
1779 | 0 | ) -> ImageResult<()> |
1780 | 0 | where |
1781 | 0 | FromType: Pixel<Subpixel = SelfPixel::Subpixel> + PixelWithColorType, |
1782 | 0 | D: Deref<Target = [SelfPixel::Subpixel]>, |
1783 | | { |
1784 | 0 | if self.dimensions() != from.dimensions() { |
1785 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( |
1786 | 0 | ParameterErrorKind::DimensionMismatch, |
1787 | 0 | ))); |
1788 | 0 | } |
1789 | | |
1790 | 0 | let transform = options |
1791 | 0 | .as_transform_fn::<FromType, SelfPixel>(from.color_space(), self.color_space())?; |
1792 | | |
1793 | 0 | let from = from.subpixels(); |
1794 | 0 | let into = self.subpixels_mut(); |
1795 | | |
1796 | 0 | debug_assert_eq!( |
1797 | 0 | from.len() / usize::from(FromType::CHANNEL_COUNT), |
1798 | 0 | into.len() / usize::from(SelfPixel::CHANNEL_COUNT), |
1799 | 0 | "Diverging pixel count despite same size", |
1800 | | ); |
1801 | | |
1802 | 0 | transform(from, into); |
1803 | | |
1804 | 0 | Ok(()) |
1805 | 0 | } Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::copy_from_color_space::<image::color::Rgb<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>>::copy_from_color_space::<image::color::Rgba<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::copy_from_color_space::<image::color::Rgb<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>>::copy_from_color_space::<image::color::Rgba<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::copy_from_color_space::<image::color::Rgb<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>>::copy_from_color_space::<image::color::Rgba<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::copy_from_color_space::<image::color::Rgba<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>::copy_from_color_space::<image::color::Rgb<f32>, alloc::vec::Vec<f32>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_from_color_space::<image::color::Rgba<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>>::copy_from_color_space::<image::color::Rgb<u8>, alloc::vec::Vec<u8>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::copy_from_color_space::<image::color::Rgba<u16>, alloc::vec::Vec<u16>> Unexecuted instantiation: <image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>>::copy_from_color_space::<image::color::Rgb<u16>, alloc::vec::Vec<u16>> |
1806 | | |
1807 | | /// Convert this buffer into a newly allocated buffer, changing the color representation. |
1808 | | /// |
1809 | | /// This will avoid an allocation if the target layout or the color conversion is not supported |
1810 | | /// (yet). |
1811 | | /// |
1812 | | /// See [`ImageBuffer::copy_from_color_space`] if you intend to assign to an existing buffer, |
1813 | | /// swapping the argument with `self`. |
1814 | 0 | pub fn to_color_space<IntoType>( |
1815 | 0 | &self, |
1816 | 0 | color: Cicp, |
1817 | 0 | mut options: ConvertColorOptions, |
1818 | 0 | ) -> Result<ImageBuffer<IntoType, Vec<SelfPixel::Subpixel>>, ImageError> |
1819 | 0 | where |
1820 | 0 | IntoType: Pixel<Subpixel = SelfPixel::Subpixel> + PixelWithColorType, |
1821 | | { |
1822 | 0 | let transform = |
1823 | 0 | options.as_transform_fn::<SelfPixel, IntoType>(self.color_space(), color)?; |
1824 | | |
1825 | 0 | let (width, height) = self.dimensions(); |
1826 | 0 | let mut target = ImageBuffer::new(width, height); |
1827 | | |
1828 | 0 | let from = self.subpixels(); |
1829 | 0 | let into = target.subpixels_mut(); |
1830 | | |
1831 | 0 | transform(from, into); |
1832 | | |
1833 | 0 | Ok(target) |
1834 | 0 | } |
1835 | | |
1836 | | /// Apply a color space to an image, transforming the pixel representation. |
1837 | 0 | pub fn apply_color_space( |
1838 | 0 | &mut self, |
1839 | 0 | color: Cicp, |
1840 | 0 | mut options: ConvertColorOptions, |
1841 | 0 | ) -> ImageResult<()> { |
1842 | 0 | if self.color_space() == color { |
1843 | 0 | return Ok(()); |
1844 | 0 | } |
1845 | | |
1846 | 0 | let transform = |
1847 | 0 | options.as_transform_fn::<SelfPixel, SelfPixel>(self.color_space(), color)?; |
1848 | | |
1849 | 0 | let mut scratch = [<SelfPixel::Subpixel as Primitive>::DEFAULT_MIN_VALUE; 1200]; |
1850 | 0 | let chunk_len = scratch.len() / usize::from(<SelfPixel as Pixel>::CHANNEL_COUNT) |
1851 | 0 | * usize::from(<SelfPixel as Pixel>::CHANNEL_COUNT); |
1852 | | |
1853 | 0 | for chunk in self.subpixels_mut().chunks_mut(chunk_len) { |
1854 | 0 | let scratch = &mut scratch[..chunk.len()]; |
1855 | 0 | scratch.copy_from_slice(chunk); |
1856 | 0 | transform(scratch, chunk); |
1857 | 0 | } |
1858 | | |
1859 | 0 | self.color = color.into_rgb(); |
1860 | | |
1861 | 0 | Ok(()) |
1862 | 0 | } |
1863 | | } |
1864 | | |
1865 | | /// Sendable Rgb image buffer |
1866 | | pub type RgbImage = ImageBuffer<Rgb<u8>, Vec<u8>>; |
1867 | | /// Sendable Rgb + alpha channel image buffer |
1868 | | pub type RgbaImage = ImageBuffer<Rgba<u8>, Vec<u8>>; |
1869 | | /// Sendable grayscale image buffer |
1870 | | pub type GrayImage = ImageBuffer<Luma<u8>, Vec<u8>>; |
1871 | | /// Sendable grayscale + alpha channel image buffer |
1872 | | pub type GrayAlphaImage = ImageBuffer<LumaA<u8>, Vec<u8>>; |
1873 | | /// Sendable 16-bit Rgb image buffer |
1874 | | pub(crate) type Rgb16Image = ImageBuffer<Rgb<u16>, Vec<u16>>; |
1875 | | /// Sendable 16-bit Rgb + alpha channel image buffer |
1876 | | pub(crate) type Rgba16Image = ImageBuffer<Rgba<u16>, Vec<u16>>; |
1877 | | /// Sendable 16-bit grayscale image buffer |
1878 | | pub(crate) type Gray16Image = ImageBuffer<Luma<u16>, Vec<u16>>; |
1879 | | /// Sendable 16-bit grayscale + alpha channel image buffer |
1880 | | pub(crate) type GrayAlpha16Image = ImageBuffer<LumaA<u16>, Vec<u16>>; |
1881 | | |
1882 | | /// An image buffer for 32-bit float grayscale pixels, |
1883 | | /// where the backing container is a flattened vector of floats. |
1884 | | pub(crate) type Gray32FImage = ImageBuffer<Luma<f32>, Vec<f32>>; |
1885 | | /// An image buffer for 32-bit float grayscale + alpha pixels, |
1886 | | /// where the backing container is a flattened vector of floats. |
1887 | | pub(crate) type GrayAlpha32FImage = ImageBuffer<LumaA<f32>, Vec<f32>>; |
1888 | | /// An image buffer for 32-bit float RGB pixels, |
1889 | | /// where the backing container is a flattened vector of floats. |
1890 | | pub type Rgb32FImage = ImageBuffer<Rgb<f32>, Vec<f32>>; |
1891 | | /// An image buffer for 32-bit float RGBA pixels, |
1892 | | /// where the backing container is a flattened vector of floats. |
1893 | | pub type Rgba32FImage = ImageBuffer<Rgba<f32>, Vec<f32>>; |
1894 | | |
1895 | | impl From<DynamicImage> for RgbImage { |
1896 | 0 | fn from(value: DynamicImage) -> Self { |
1897 | 0 | value.into_rgb8() |
1898 | 0 | } |
1899 | | } |
1900 | | |
1901 | | impl From<DynamicImage> for RgbaImage { |
1902 | 0 | fn from(value: DynamicImage) -> Self { |
1903 | 0 | value.into_rgba8() |
1904 | 0 | } |
1905 | | } |
1906 | | |
1907 | | impl From<DynamicImage> for GrayImage { |
1908 | 0 | fn from(value: DynamicImage) -> Self { |
1909 | 0 | value.into_luma8() |
1910 | 0 | } |
1911 | | } |
1912 | | |
1913 | | impl From<DynamicImage> for GrayAlphaImage { |
1914 | 0 | fn from(value: DynamicImage) -> Self { |
1915 | 0 | value.into_luma_alpha8() |
1916 | 0 | } |
1917 | | } |
1918 | | |
1919 | | impl From<DynamicImage> for Rgb16Image { |
1920 | 0 | fn from(value: DynamicImage) -> Self { |
1921 | 0 | value.into_rgb16() |
1922 | 0 | } |
1923 | | } |
1924 | | |
1925 | | impl From<DynamicImage> for Rgba16Image { |
1926 | 0 | fn from(value: DynamicImage) -> Self { |
1927 | 0 | value.into_rgba16() |
1928 | 0 | } |
1929 | | } |
1930 | | |
1931 | | impl From<DynamicImage> for Gray16Image { |
1932 | 0 | fn from(value: DynamicImage) -> Self { |
1933 | 0 | value.into_luma16() |
1934 | 0 | } |
1935 | | } |
1936 | | |
1937 | | impl From<DynamicImage> for GrayAlpha16Image { |
1938 | 0 | fn from(value: DynamicImage) -> Self { |
1939 | 0 | value.into_luma_alpha16() |
1940 | 0 | } |
1941 | | } |
1942 | | |
1943 | | impl From<DynamicImage> for Rgb32FImage { |
1944 | 0 | fn from(value: DynamicImage) -> Self { |
1945 | 0 | value.into_rgb32f() |
1946 | 0 | } |
1947 | | } |
1948 | | impl From<DynamicImage> for Rgba32FImage { |
1949 | 0 | fn from(value: DynamicImage) -> Self { |
1950 | 0 | value.into_rgba32f() |
1951 | 0 | } |
1952 | | } |
1953 | | impl From<DynamicImage> for Gray32FImage { |
1954 | 0 | fn from(value: DynamicImage) -> Self { |
1955 | 0 | value.into_luma32f() |
1956 | 0 | } |
1957 | | } |
1958 | | impl From<DynamicImage> for GrayAlpha32FImage { |
1959 | 0 | fn from(value: DynamicImage) -> Self { |
1960 | 0 | value.into_luma_alpha32f() |
1961 | 0 | } |
1962 | | } |
1963 | | |
1964 | | #[cfg(test)] |
1965 | | mod test { |
1966 | | use super::{GrayImage, ImageBuffer, RgbImage}; |
1967 | | use crate::math::Rect; |
1968 | | use crate::metadata::Cicp; |
1969 | | use crate::metadata::CicpMatrixCoefficients; |
1970 | | use crate::metadata::CicpTransform; |
1971 | | use crate::metadata::CicpVideoFullRangeFlag; |
1972 | | use crate::ImageFormat; |
1973 | | use crate::{GenericImage as _, GenericImageView as _}; |
1974 | | use crate::{Luma, LumaA, Pixel, Rgb, Rgba}; |
1975 | | use num_traits::Zero; |
1976 | | |
1977 | | #[test] |
1978 | | /// Tests if image buffers from slices work |
1979 | | fn slice_buffer() { |
1980 | | let data = [0; 9]; |
1981 | | let buf: ImageBuffer<Luma<u8>, _> = ImageBuffer::from_raw(3, 3, &data[..]).unwrap(); |
1982 | | assert_eq!(&*buf, &data[..]); |
1983 | | } |
1984 | | |
1985 | | macro_rules! new_buffer_zero_test { |
1986 | | ($test_name:ident, $pxt:ty) => { |
1987 | | #[test] |
1988 | | fn $test_name() { |
1989 | | let buffer = ImageBuffer::<$pxt, Vec<<$pxt as Pixel>::Subpixel>>::new(2, 2); |
1990 | | assert!(buffer |
1991 | | .iter() |
1992 | | .all(|p| *p == <$pxt as Pixel>::Subpixel::zero())); |
1993 | | } |
1994 | | }; |
1995 | | } |
1996 | | |
1997 | | new_buffer_zero_test!(luma_u8_zero_test, Luma<u8>); |
1998 | | new_buffer_zero_test!(luma_u16_zero_test, Luma<u16>); |
1999 | | new_buffer_zero_test!(luma_f32_zero_test, Luma<f32>); |
2000 | | new_buffer_zero_test!(luma_a_u8_zero_test, LumaA<u8>); |
2001 | | new_buffer_zero_test!(luma_a_u16_zero_test, LumaA<u16>); |
2002 | | new_buffer_zero_test!(luma_a_f32_zero_test, LumaA<f32>); |
2003 | | new_buffer_zero_test!(rgb_u8_zero_test, Rgb<u8>); |
2004 | | new_buffer_zero_test!(rgb_u16_zero_test, Rgb<u16>); |
2005 | | new_buffer_zero_test!(rgb_f32_zero_test, Rgb<f32>); |
2006 | | new_buffer_zero_test!(rgb_a_u8_zero_test, Rgba<u8>); |
2007 | | new_buffer_zero_test!(rgb_a_u16_zero_test, Rgba<u16>); |
2008 | | new_buffer_zero_test!(rgb_a_f32_zero_test, Rgba<f32>); |
2009 | | |
2010 | | #[test] |
2011 | | fn get_pixel() { |
2012 | | let mut a: RgbImage = ImageBuffer::new(10, 10); |
2013 | | { |
2014 | | let b = a.get_mut(3 * 10).unwrap(); |
2015 | | *b = 255; |
2016 | | } |
2017 | | assert_eq!(a.get_pixel(0, 1)[0], 255); |
2018 | | } |
2019 | | |
2020 | | #[test] |
2021 | | fn get_pixel_checked() { |
2022 | | let mut a: RgbImage = ImageBuffer::new(10, 10); |
2023 | | a.get_pixel_mut_checked(0, 1).unwrap()[0] = 255; |
2024 | | |
2025 | | assert_eq!(a.get_pixel_checked(0, 1), Some(&Rgb([255, 0, 0]))); |
2026 | | assert_eq!(a.get_pixel_checked(0, 1).unwrap(), a.get_pixel(0, 1)); |
2027 | | assert_eq!(a.get_pixel_checked(10, 0), None); |
2028 | | assert_eq!(a.get_pixel_checked(0, 10), None); |
2029 | | assert_eq!(a.get_pixel_mut_checked(10, 0), None); |
2030 | | assert_eq!(a.get_pixel_mut_checked(0, 10), None); |
2031 | | |
2032 | | // From image/issues/1672 |
2033 | | const WHITE: Rgb<u8> = Rgb([255_u8, 255, 255]); |
2034 | | let mut a = RgbImage::new(2, 1); |
2035 | | a.put_pixel(1, 0, WHITE); |
2036 | | |
2037 | | assert_eq!(a.get_pixel_checked(1, 0), Some(&WHITE)); |
2038 | | assert_eq!(a.get_pixel_checked(1, 0).unwrap(), a.get_pixel(1, 0)); |
2039 | | } |
2040 | | |
2041 | | #[test] |
2042 | | fn mut_iter() { |
2043 | | let mut a: RgbImage = ImageBuffer::new(10, 10); |
2044 | | { |
2045 | | let val = a.pixels_mut().first_mut().unwrap(); |
2046 | | *val = Rgb([42, 0, 0]); |
2047 | | } |
2048 | | assert_eq!(a.data[0], 42); |
2049 | | } |
2050 | | |
2051 | | #[test] |
2052 | | fn zero_width_zero_height() { |
2053 | | let mut image = RgbImage::new(0, 0); |
2054 | | |
2055 | | assert_eq!(image.rows_mut().count(), 0); |
2056 | | assert_eq!(image.pixels_mut().len(), 0); |
2057 | | assert_eq!(image.rows().count(), 0); |
2058 | | assert_eq!(image.pixels().len(), 0); |
2059 | | } |
2060 | | |
2061 | | #[test] |
2062 | | fn zero_width_nonzero_height() { |
2063 | | let mut image = RgbImage::new(0, 2); |
2064 | | |
2065 | | assert_eq!(image.rows_mut().count(), 0); |
2066 | | assert_eq!(image.pixels_mut().len(), 0); |
2067 | | assert_eq!(image.rows().count(), 0); |
2068 | | assert_eq!(image.pixels().len(), 0); |
2069 | | } |
2070 | | |
2071 | | #[test] |
2072 | | fn nonzero_width_zero_height() { |
2073 | | let mut image = RgbImage::new(2, 0); |
2074 | | |
2075 | | assert_eq!(image.rows_mut().count(), 0); |
2076 | | assert_eq!(image.pixels_mut().len(), 0); |
2077 | | assert_eq!(image.rows().count(), 0); |
2078 | | assert_eq!(image.pixels().len(), 0); |
2079 | | } |
2080 | | |
2081 | | #[test] |
2082 | | fn pixels_on_large_buffer() { |
2083 | | let mut image = RgbImage::from_raw(1, 1, vec![0; 6]).unwrap(); |
2084 | | |
2085 | | assert_eq!(image.pixels().len(), 1); |
2086 | | assert_eq!(image.enumerate_pixels().count(), 1); |
2087 | | assert_eq!(image.pixels_mut().len(), 1); |
2088 | | assert_eq!(image.enumerate_pixels_mut().count(), 1); |
2089 | | |
2090 | | assert_eq!(image.rows().count(), 1); |
2091 | | assert_eq!(image.rows_mut().count(), 1); |
2092 | | } |
2093 | | |
2094 | | #[test] |
2095 | | fn default() { |
2096 | | let image = ImageBuffer::<Rgb<u8>, Vec<u8>>::default(); |
2097 | | assert_eq!(image.dimensions(), (0, 0)); |
2098 | | } |
2099 | | |
2100 | | #[test] |
2101 | | #[rustfmt::skip] |
2102 | | fn test_image_buffer_copy_within_oob() { |
2103 | | let mut image: GrayImage = ImageBuffer::from_raw(4, 4, vec![0u8; 16]).unwrap(); |
2104 | | assert!(!image.copy_within(Rect { x: 0, y: 0, width: 5, height: 4 }, 0, 0)); |
2105 | | assert!(!image.copy_within(Rect { x: 0, y: 0, width: 4, height: 5 }, 0, 0)); |
2106 | | assert!(!image.copy_within(Rect { x: 1, y: 0, width: 4, height: 4 }, 0, 0)); |
2107 | | assert!(!image.copy_within(Rect { x: 0, y: 0, width: 4, height: 4 }, 1, 0)); |
2108 | | assert!(!image.copy_within(Rect { x: 0, y: 1, width: 4, height: 4 }, 0, 0)); |
2109 | | assert!(!image.copy_within(Rect { x: 0, y: 0, width: 4, height: 4 }, 0, 1)); |
2110 | | assert!(!image.copy_within(Rect { x: 1, y: 1, width: 4, height: 4 }, 0, 0)); |
2111 | | } |
2112 | | |
2113 | | #[test] |
2114 | | fn test_image_buffer_copy_within_tl() { |
2115 | | let data = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; |
2116 | | let expected = [0, 1, 2, 3, 4, 0, 1, 2, 8, 4, 5, 6, 12, 8, 9, 10]; |
2117 | | let mut image: GrayImage = ImageBuffer::from_raw(4, 4, Vec::from(&data[..])).unwrap(); |
2118 | | assert!(image.copy_within( |
2119 | | Rect { |
2120 | | x: 0, |
2121 | | y: 0, |
2122 | | width: 3, |
2123 | | height: 3 |
2124 | | }, |
2125 | | 1, |
2126 | | 1 |
2127 | | )); |
2128 | | assert_eq!(&image.into_raw(), &expected); |
2129 | | } |
2130 | | |
2131 | | #[test] |
2132 | | fn test_image_buffer_copy_within_tr() { |
2133 | | let data = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; |
2134 | | let expected = [0, 1, 2, 3, 1, 2, 3, 7, 5, 6, 7, 11, 9, 10, 11, 15]; |
2135 | | let mut image: GrayImage = ImageBuffer::from_raw(4, 4, Vec::from(&data[..])).unwrap(); |
2136 | | assert!(image.copy_within( |
2137 | | Rect { |
2138 | | x: 1, |
2139 | | y: 0, |
2140 | | width: 3, |
2141 | | height: 3 |
2142 | | }, |
2143 | | 0, |
2144 | | 1 |
2145 | | )); |
2146 | | assert_eq!(&image.into_raw(), &expected); |
2147 | | } |
2148 | | |
2149 | | #[test] |
2150 | | fn test_image_buffer_copy_within_bl() { |
2151 | | let data = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; |
2152 | | let expected = [0, 4, 5, 6, 4, 8, 9, 10, 8, 12, 13, 14, 12, 13, 14, 15]; |
2153 | | let mut image: GrayImage = ImageBuffer::from_raw(4, 4, Vec::from(&data[..])).unwrap(); |
2154 | | assert!(image.copy_within( |
2155 | | Rect { |
2156 | | x: 0, |
2157 | | y: 1, |
2158 | | width: 3, |
2159 | | height: 3 |
2160 | | }, |
2161 | | 1, |
2162 | | 0 |
2163 | | )); |
2164 | | assert_eq!(&image.into_raw(), &expected); |
2165 | | } |
2166 | | |
2167 | | #[test] |
2168 | | fn test_image_buffer_copy_within_br() { |
2169 | | let data = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; |
2170 | | let expected = [5, 6, 7, 3, 9, 10, 11, 7, 13, 14, 15, 11, 12, 13, 14, 15]; |
2171 | | let mut image: GrayImage = ImageBuffer::from_raw(4, 4, Vec::from(&data[..])).unwrap(); |
2172 | | assert!(image.copy_within( |
2173 | | Rect { |
2174 | | x: 1, |
2175 | | y: 1, |
2176 | | width: 3, |
2177 | | height: 3 |
2178 | | }, |
2179 | | 0, |
2180 | | 0 |
2181 | | )); |
2182 | | assert_eq!(&image.into_raw(), &expected); |
2183 | | } |
2184 | | |
2185 | | #[test] |
2186 | | #[cfg(feature = "png")] |
2187 | | fn write_to_with_large_buffer() { |
2188 | | // A buffer of 1 pixel, padded to 4 bytes as would be common in, e.g. BMP. |
2189 | | |
2190 | | let img: GrayImage = ImageBuffer::from_raw(1, 1, vec![0u8; 4]).unwrap(); |
2191 | | let mut buffer = std::io::Cursor::new(vec![]); |
2192 | | assert!(img.write_to(&mut buffer, ImageFormat::Png).is_ok()); |
2193 | | } |
2194 | | |
2195 | | #[test] |
2196 | | fn exact_size_iter_size_hint() { |
2197 | | // The docs for `std::iter::ExactSizeIterator` requires that the implementation of |
2198 | | // `size_hint` on the iterator returns the same value as the `len` implementation. |
2199 | | |
2200 | | // This test should work for any size image. |
2201 | | const N: u32 = 10; |
2202 | | |
2203 | | let mut image = RgbImage::from_raw(N, N, vec![0; (N * N * 3) as usize]).unwrap(); |
2204 | | |
2205 | | let iter = image.rows(); |
2206 | | let exact_len = ExactSizeIterator::len(&iter); |
2207 | | assert_eq!(iter.size_hint(), (exact_len, Some(exact_len))); |
2208 | | |
2209 | | let iter = image.rows_mut(); |
2210 | | let exact_len = ExactSizeIterator::len(&iter); |
2211 | | assert_eq!(iter.size_hint(), (exact_len, Some(exact_len))); |
2212 | | |
2213 | | let iter = image.enumerate_pixels(); |
2214 | | let exact_len = ExactSizeIterator::len(&iter); |
2215 | | assert_eq!(iter.size_hint(), (exact_len, Some(exact_len))); |
2216 | | |
2217 | | let iter = image.enumerate_rows(); |
2218 | | let exact_len = ExactSizeIterator::len(&iter); |
2219 | | assert_eq!(iter.size_hint(), (exact_len, Some(exact_len))); |
2220 | | |
2221 | | let iter = image.enumerate_pixels_mut(); |
2222 | | let exact_len = ExactSizeIterator::len(&iter); |
2223 | | assert_eq!(iter.size_hint(), (exact_len, Some(exact_len))); |
2224 | | |
2225 | | let iter = image.enumerate_rows_mut(); |
2226 | | let exact_len = ExactSizeIterator::len(&iter); |
2227 | | assert_eq!(iter.size_hint(), (exact_len, Some(exact_len))); |
2228 | | } |
2229 | | |
2230 | | #[test] |
2231 | | fn color_conversion() { |
2232 | | let mut source = ImageBuffer::from_fn(128, 128, |_, _| Rgb([255, 0, 0])); |
2233 | | let mut target = ImageBuffer::from_fn(128, 128, |_, _| Rgba(Default::default())); |
2234 | | |
2235 | | source.set_rgb_primaries(Cicp::SRGB.primaries); |
2236 | | source.set_transfer_function(Cicp::SRGB.transfer); |
2237 | | |
2238 | | target.set_rgb_primaries(Cicp::DISPLAY_P3.primaries); |
2239 | | target.set_transfer_function(Cicp::DISPLAY_P3.transfer); |
2240 | | |
2241 | | let result = target.copy_from_color_space(&source, Default::default()); |
2242 | | |
2243 | | assert!(result.is_ok(), "{result:?}"); |
2244 | | assert_eq!(target[(0, 0)], Rgba([234u8, 51, 35, 255])); |
2245 | | } |
2246 | | |
2247 | | #[test] |
2248 | | fn gray_conversions() { |
2249 | | let mut source = ImageBuffer::from_fn(128, 128, |_, _| Luma([255u8])); |
2250 | | let mut target = ImageBuffer::from_fn(128, 128, |_, _| Rgba(Default::default())); |
2251 | | |
2252 | | source.set_rgb_primaries(Cicp::SRGB.primaries); |
2253 | | source.set_transfer_function(Cicp::SRGB.transfer); |
2254 | | |
2255 | | target.set_rgb_primaries(Cicp::SRGB.primaries); |
2256 | | target.set_transfer_function(Cicp::SRGB.transfer); |
2257 | | |
2258 | | let result = target.copy_from_color_space(&source, Default::default()); |
2259 | | |
2260 | | assert!(result.is_ok(), "{result:?}"); |
2261 | | assert_eq!(target[(0, 0)], Rgba([u8::MAX; 4])); |
2262 | | } |
2263 | | |
2264 | | #[test] |
2265 | | fn rgb_to_gray_conversion() { |
2266 | | let mut source = ImageBuffer::from_fn(128, 128, |_, _| Rgb([128u8; 3])); |
2267 | | let mut target = ImageBuffer::from_fn(128, 128, |_, _| Luma(Default::default())); |
2268 | | |
2269 | | source.set_rgb_primaries(Cicp::SRGB.primaries); |
2270 | | source.set_transfer_function(Cicp::SRGB.transfer); |
2271 | | |
2272 | | target.set_rgb_primaries(Cicp::SRGB.primaries); |
2273 | | target.set_transfer_function(Cicp::SRGB.transfer); |
2274 | | |
2275 | | let result = target.copy_from_color_space(&source, Default::default()); |
2276 | | |
2277 | | assert!(result.is_ok(), "{result:?}"); |
2278 | | assert_eq!(target[(0, 0)], Luma([128u8])); |
2279 | | } |
2280 | | |
2281 | | #[test] |
2282 | | fn apply_color() { |
2283 | | let mut buffer = ImageBuffer::from_fn(128, 128, |_, _| Rgb([255u8, 0, 0])); |
2284 | | |
2285 | | buffer.set_rgb_primaries(Cicp::SRGB.primaries); |
2286 | | buffer.set_transfer_function(Cicp::SRGB.transfer); |
2287 | | |
2288 | | buffer |
2289 | | .apply_color_space(Cicp::DISPLAY_P3, Default::default()) |
2290 | | .expect("supported transform"); |
2291 | | |
2292 | | buffer.pixels().iter().for_each(|&p| { |
2293 | | assert_eq!(p, Rgb([234u8, 51, 35])); |
2294 | | }); |
2295 | | } |
2296 | | |
2297 | | #[test] |
2298 | | fn to_color() { |
2299 | | let mut source = ImageBuffer::from_fn(128, 128, |_, _| Rgba([255u8, 0, 0, 255])); |
2300 | | source.set_rgb_primaries(Cicp::SRGB.primaries); |
2301 | | source.set_transfer_function(Cicp::SRGB.transfer); |
2302 | | |
2303 | | let target = source |
2304 | | .to_color_space::<Rgb<u8>>(Cicp::DISPLAY_P3, Default::default()) |
2305 | | .expect("supported transform"); |
2306 | | |
2307 | | assert_eq!(target[(0, 0)], Rgb([234u8, 51, 35])); |
2308 | | } |
2309 | | |
2310 | | #[test] |
2311 | | fn transformation_mismatch() { |
2312 | | let mut source = ImageBuffer::from_fn(128, 128, |_, _| Luma([255u8])); |
2313 | | let mut target = ImageBuffer::from_fn(128, 128, |_, _| Rgba(Default::default())); |
2314 | | |
2315 | | source.set_color_space(Cicp::SRGB).unwrap(); |
2316 | | target.set_color_space(Cicp::DISPLAY_P3).unwrap(); |
2317 | | |
2318 | | let options = super::ConvertColorOptions { |
2319 | | transform: CicpTransform::new(Cicp::SRGB, Cicp::SRGB), |
2320 | | ..super::ConvertColorOptions::default() |
2321 | | }; |
2322 | | |
2323 | | let result = target.copy_from_color_space(&source, options); |
2324 | | assert!(matches!(result, Err(crate::ImageError::Parameter(_)))); |
2325 | | } |
2326 | | |
2327 | | #[test] |
2328 | | fn pleasant_debug() { |
2329 | | use super::*; |
2330 | | |
2331 | | assert_eq!( |
2332 | | format!("{:?}", GrayImage::new(100, 100)), |
2333 | | "ImageBuffer::<Luma<u8>, _> { width: 100, height: 100, color: \"sRGB\" }" |
2334 | | ); |
2335 | | assert_eq!( |
2336 | | format!("{:?}", GrayAlphaImage::new(100, 100)), |
2337 | | "ImageBuffer::<LumaA<u8>, _> { width: 100, height: 100, color: \"sRGB\" }" |
2338 | | ); |
2339 | | assert_eq!( |
2340 | | format!("{:?}", RgbImage::new(100, 100)), |
2341 | | "ImageBuffer::<Rgb<u8>, _> { width: 100, height: 100, color: \"sRGB\" }" |
2342 | | ); |
2343 | | assert_eq!( |
2344 | | format!("{:?}", RgbaImage::new(100, 100)), |
2345 | | "ImageBuffer::<Rgba<u8>, _> { width: 100, height: 100, color: \"sRGB\" }" |
2346 | | ); |
2347 | | assert_eq!( |
2348 | | format!("{:?}", Gray16Image::new(100, 100)), |
2349 | | "ImageBuffer::<Luma<u16>, _> { width: 100, height: 100, color: \"sRGB\" }" |
2350 | | ); |
2351 | | assert_eq!( |
2352 | | format!("{:?}", GrayAlpha16Image::new(100, 100)), |
2353 | | "ImageBuffer::<LumaA<u16>, _> { width: 100, height: 100, color: \"sRGB\" }" |
2354 | | ); |
2355 | | assert_eq!( |
2356 | | format!("{:?}", Rgb16Image::new(100, 100)), |
2357 | | "ImageBuffer::<Rgb<u16>, _> { width: 100, height: 100, color: \"sRGB\" }" |
2358 | | ); |
2359 | | assert_eq!( |
2360 | | format!("{:?}", Rgba16Image::new(100, 100)), |
2361 | | "ImageBuffer::<Rgba<u16>, _> { width: 100, height: 100, color: \"sRGB\" }" |
2362 | | ); |
2363 | | assert_eq!( |
2364 | | format!("{:?}", Rgb32FImage::new(100, 100)), |
2365 | | "ImageBuffer::<Rgb<f32>, _> { width: 100, height: 100, color: \"sRGB\" }" |
2366 | | ); |
2367 | | assert_eq!( |
2368 | | format!("{:?}", Rgba32FImage::new(100, 100)), |
2369 | | "ImageBuffer::<Rgba<f32>, _> { width: 100, height: 100, color: \"sRGB\" }" |
2370 | | ); |
2371 | | |
2372 | | let gray8 = ImageBuffer::from_pixel(16, 16, Luma([255u8])); |
2373 | | assert_eq!( |
2374 | | format!("{:?}", gray8), |
2375 | | "ImageBuffer::<Luma<u8>, _> { width: 16, height: 16, color: \"sRGB\" }" |
2376 | | ); |
2377 | | assert_eq!( |
2378 | | format!("{:#?}", gray8), |
2379 | | "ImageBuffer::<Luma<u8>, _> {\n width: 16,\n height: 16,\n color: \"sRGB\",\n}" |
2380 | | ); |
2381 | | |
2382 | | let mut rgba32f = ImageBuffer::from_pixel(16, 16, Rgba([0.0_f32; 4])); |
2383 | | rgba32f.set_color_space(Cicp::DISPLAY_P3).unwrap(); |
2384 | | assert_eq!( |
2385 | | format!("{:?}", rgba32f), |
2386 | | "ImageBuffer::<Rgba<f32>, _> { width: 16, height: 16, color: \"Display P3\" }" |
2387 | | ); |
2388 | | |
2389 | | let mut custom_color_space = ImageBuffer::from_pixel(16, 16, Rgba([0.0_f32; 4])); |
2390 | | custom_color_space |
2391 | | .set_color_space(Cicp { |
2392 | | primaries: CicpColorPrimaries::Rgb240m, |
2393 | | transfer: CicpTransferCharacteristics::LogSqrt, |
2394 | | matrix: CicpMatrixCoefficients::Identity, |
2395 | | full_range: CicpVideoFullRangeFlag::FullRange, |
2396 | | }) |
2397 | | .unwrap(); |
2398 | | assert_eq!( |
2399 | | format!("{:?}", custom_color_space), |
2400 | | "ImageBuffer::<Rgba<f32>, _> { width: 16, height: 16, color: CicpRgb { primaries: Rgb240m, transfer: LogSqrt, luminance: NonConstant } }" |
2401 | | ); |
2402 | | } |
2403 | | |
2404 | | /// We specialize copy_from on types that provide `as_samples` so test that. |
2405 | | #[test] |
2406 | | fn copy_from_subimage_to_middle() { |
2407 | | let mut source = RgbImage::new(16, 16); |
2408 | | let mut target = RgbImage::new(16, 16); |
2409 | | |
2410 | | source.put_pixel(8, 8, Rgb([255, 8, 8])); |
2411 | | source.put_pixel(9, 8, Rgb([255, 9, 8])); |
2412 | | source.put_pixel(9, 9, Rgb([255, 9, 9])); |
2413 | | |
2414 | | let view = source.view(Rect::from_xy_ranges(8..10, 8..10)); |
2415 | | assert!(target.copy_from(&*view, 4, 4).is_ok()); |
2416 | | |
2417 | | // Check the pixel was copied. |
2418 | | assert_eq!(*target.get_pixel(4, 4), Rgb([255, 8, 8])); |
2419 | | assert_eq!(*target.get_pixel(5, 4), Rgb([255, 9, 8])); |
2420 | | assert_eq!(*target.get_pixel(5, 5), Rgb([255, 9, 9])); |
2421 | | |
2422 | | // Check that were the only copied pixel. |
2423 | | assert_eq!( |
2424 | | target.iter().copied().map(usize::from).sum::<usize>(), |
2425 | | 3 * (255 + 8 + 9) |
2426 | | ); |
2427 | | } |
2428 | | |
2429 | | #[test] |
2430 | | fn copy_from_band() { |
2431 | | let source = RgbImage::from_fn(16, 8, |x, y| Rgb([x as u8, y as u8, 0])); |
2432 | | let mut target = RgbImage::new(16, 16); |
2433 | | |
2434 | | assert!(target.copy_from(&source, 0, 4).is_ok()); |
2435 | | |
2436 | | let lhs = source.chunks_exact(48); |
2437 | | let rhs = target.chunks_exact(48).skip(4).take(8); |
2438 | | |
2439 | | assert!(lhs.eq(rhs)); |
2440 | | } |
2441 | | |
2442 | | #[test] |
2443 | | fn copy_from_pixel() { |
2444 | | let bg = Rgb([255, 0, 128]); |
2445 | | let samples = crate::flat::FlatSamples::with_monocolor(&bg, 4, 4); |
2446 | | let source = samples.as_view().unwrap(); |
2447 | | |
2448 | | let mut target = RgbImage::new(16, 16); |
2449 | | assert!(target.copy_from(&source, 4, 4).is_ok()); |
2450 | | |
2451 | | for i in 4..8 { |
2452 | | for j in 4..8 { |
2453 | | assert_eq!(*target.get_pixel(i, j), bg); |
2454 | | } |
2455 | | } |
2456 | | |
2457 | | assert_eq!( |
2458 | | target.iter().copied().map(usize::from).sum::<usize>(), |
2459 | | 16 * (255 + 128) |
2460 | | ); |
2461 | | } |
2462 | | |
2463 | | #[test] |
2464 | | fn copy_from_strided() { |
2465 | | #[rustfmt::skip] |
2466 | | let sample_data = [ |
2467 | | 1, 0xff, 0, 0, 2, 0xff, |
2468 | | 3, 0xff, 0, 0, 4, 0xff |
2469 | | ]; |
2470 | | |
2471 | | let samples = crate::flat::FlatSamples { |
2472 | | samples: &sample_data, |
2473 | | layout: crate::flat::SampleLayout { |
2474 | | channels: 2, |
2475 | | channel_stride: 1, |
2476 | | width: 2, |
2477 | | width_stride: 4, |
2478 | | height: 2, |
2479 | | height_stride: 6, |
2480 | | }, |
2481 | | color_hint: None, |
2482 | | }; |
2483 | | |
2484 | | let source = samples.as_view::<LumaA<u8>>().unwrap(); |
2485 | | let mut target = crate::GrayAlphaImage::new(16, 16); |
2486 | | assert!(target.copy_from(&source, 4, 4).is_ok()); |
2487 | | |
2488 | | assert_eq!(*target.get_pixel(4, 4), LumaA([1, 0xff])); |
2489 | | assert_eq!(*target.get_pixel(5, 4), LumaA([2, 0xff])); |
2490 | | assert_eq!(*target.get_pixel(4, 5), LumaA([3, 0xff])); |
2491 | | assert_eq!(*target.get_pixel(5, 5), LumaA([4, 0xff])); |
2492 | | |
2493 | | assert_eq!( |
2494 | | target.iter().copied().map(usize::from).sum::<usize>(), |
2495 | | sample_data.iter().copied().map(usize::from).sum::<usize>(), |
2496 | | ); |
2497 | | } |
2498 | | |
2499 | | #[test] |
2500 | | fn copy_from_strided_subimage() { |
2501 | | #[rustfmt::skip] |
2502 | | let sample_data = [ |
2503 | | 1, 0xff, 0, 0, 2, 0xff, |
2504 | | 3, 0xff, 0, 0, 4, 0xff |
2505 | | ]; |
2506 | | |
2507 | | let samples = crate::flat::FlatSamples { |
2508 | | samples: &sample_data, |
2509 | | layout: crate::flat::SampleLayout { |
2510 | | channels: 2, |
2511 | | channel_stride: 1, |
2512 | | width: 2, |
2513 | | width_stride: 4, |
2514 | | height: 2, |
2515 | | height_stride: 6, |
2516 | | }, |
2517 | | color_hint: None, |
2518 | | }; |
2519 | | |
2520 | | let view = samples.as_view::<LumaA<u8>>().unwrap(); |
2521 | | let source = view.view(Rect::from_xy_ranges(1..2, 0..2)); |
2522 | | |
2523 | | let mut target = crate::GrayAlphaImage::new(16, 16); |
2524 | | assert!(target.copy_from(&*source, 4, 4).is_ok()); |
2525 | | |
2526 | | assert_eq!(*target.get_pixel(4, 4), LumaA([2, 0xff])); |
2527 | | assert_eq!(*target.get_pixel(4, 5), LumaA([4, 0xff])); |
2528 | | |
2529 | | assert_eq!( |
2530 | | target.iter().copied().map(usize::from).sum::<usize>(), |
2531 | | 2usize + 0xff + 4 + 0xff |
2532 | | ); |
2533 | | } |
2534 | | |
2535 | | #[test] |
2536 | | fn copy_from_subimage_subimage() { |
2537 | | let mut source = RgbImage::new(16, 16); |
2538 | | let mut target = RgbImage::new(16, 16); |
2539 | | |
2540 | | source.put_pixel(8, 8, Rgb([255, 8, 8])); |
2541 | | source.put_pixel(9, 8, Rgb([255, 9, 8])); |
2542 | | source.put_pixel(9, 9, Rgb([255, 9, 9])); |
2543 | | |
2544 | | let view = source.view(Rect::from_xy_ranges(8..10, 8..10)); |
2545 | | let view = view.view(Rect::from_xy_ranges(1..2, 0..1)); |
2546 | | assert!(target.copy_from(&*view, 4, 4).is_ok()); |
2547 | | |
2548 | | // Check the pixel was copied. |
2549 | | assert_eq!(*target.get_pixel(4, 4), Rgb([255, 9, 8])); |
2550 | | |
2551 | | // Check that was the only copied pixel. |
2552 | | assert_eq!( |
2553 | | target.iter().copied().map(usize::from).sum::<usize>(), |
2554 | | 255 + 9 + 8 |
2555 | | ); |
2556 | | } |
2557 | | |
2558 | | #[test] |
2559 | | fn expend_palette() { |
2560 | | let gray = GrayImage::from_fn(3, 1, |x, _| Luma([x as u8])); |
2561 | | let expanded = gray.expand_palette(&[(255, 0, 0), (1, 2, 3), (255, 255, 255)], None); |
2562 | | |
2563 | | assert_eq!(expanded.get_pixel(0, 0), &Rgba([255, 0, 0, 255])); |
2564 | | assert_eq!(expanded.get_pixel(1, 0), &Rgba([1, 2, 3, 255])); |
2565 | | assert_eq!(expanded.get_pixel(2, 0), &Rgba([255, 255, 255, 255])); |
2566 | | |
2567 | | // issue #2918 |
2568 | | let indexes = GrayImage::from_pixel(2, 2, Luma([0])); |
2569 | | let expanded = indexes.expand_palette(&[(255, 255, 255)], None); |
2570 | | |
2571 | | assert_eq!(expanded.get_pixel(1, 0), &Rgba([255, 255, 255, 255])); |
2572 | | assert_eq!(expanded.get_pixel(0, 1), &Rgba([255, 255, 255, 255])); |
2573 | | assert_eq!(expanded.get_pixel(1, 1), &Rgba([255, 255, 255, 255])); |
2574 | | assert_eq!(expanded.get_pixel(0, 0), &Rgba([255, 255, 255, 255])); |
2575 | | } |
2576 | | |
2577 | | #[test] |
2578 | | fn alpha_mask_of_gray() { |
2579 | | let image: GrayImage = ImageBuffer::new(4, 4); |
2580 | | let mask = image.to_alpha_mask(); |
2581 | | assert_eq!(mask.as_raw(), &[255; 16]); |
2582 | | } |
2583 | | |
2584 | | #[test] |
2585 | | #[rustfmt::skip] |
2586 | | fn alpha_mask_extraction() { |
2587 | | let image: ImageBuffer<LumaA<u8>, _> = ImageBuffer::from_raw(4, 4, vec![ |
2588 | | 0, 1, 0, 2, 0, 3, 0, 4, |
2589 | | 0, 5, 0, 6, 0, 7, 0, 8, |
2590 | | 0, 9, 0, 10, 0, 11, 0, 12, |
2591 | | 0, 13, 0, 14, 0, 15, 0, 16, |
2592 | | ]).unwrap(); |
2593 | | |
2594 | | let mask = image.to_alpha_mask(); |
2595 | | assert_eq!(mask.as_raw(), &(1u8..17).collect::<Vec<_>>()); |
2596 | | } |
2597 | | |
2598 | | #[test] |
2599 | | fn apply_alpha_mask() { |
2600 | | let mut image: ImageBuffer<LumaA<u8>, _> = ImageBuffer::new(4, 4); |
2601 | | |
2602 | | let alpha = ImageBuffer::from_pixel(4, 4, Luma([255])); |
2603 | | image.set_alpha_channel(&alpha).expect("can apply"); |
2604 | | |
2605 | | for pixel in image.pixels() { |
2606 | | assert_eq!(pixel.0, [0, 255]); |
2607 | | } |
2608 | | } |
2609 | | |
2610 | | #[test] |
2611 | | fn apply_alpha_mask_rgb() { |
2612 | | let mut image: ImageBuffer<Rgba<u8>, _> = ImageBuffer::new(4, 4); |
2613 | | |
2614 | | let alpha = ImageBuffer::from_pixel(4, 4, Luma([255])); |
2615 | | image.set_alpha_channel(&alpha).expect("can apply"); |
2616 | | |
2617 | | for pixel in image.pixels() { |
2618 | | assert_eq!(pixel.0, [0, 0, 0, 255]); |
2619 | | } |
2620 | | } |
2621 | | |
2622 | | #[test] |
2623 | | fn can_not_apply_alpha_mask() { |
2624 | | ImageBuffer::<LumaA<u8>, _>::new(4, 4) |
2625 | | .set_alpha_channel(&ImageBuffer::new(1, 1)) |
2626 | | .expect_err("can not apply with wrong dimensions"); |
2627 | | |
2628 | | ImageBuffer::<Luma<u8>, _>::new(4, 4) |
2629 | | .set_alpha_channel(&ImageBuffer::new(4, 4)) |
2630 | | .expect_err("can not apply without alpha channel"); |
2631 | | ImageBuffer::<Rgb<u8>, _>::new(4, 4) |
2632 | | .set_alpha_channel(&ImageBuffer::new(4, 4)) |
2633 | | .expect_err("can not apply without alpha channel"); |
2634 | | } |
2635 | | } |
2636 | | |
2637 | | #[cfg(test)] |
2638 | | #[cfg(feature = "benchmarks")] |
2639 | | mod benchmarks { |
2640 | | use super::{GrayImage, ImageBuffer, Pixel, RgbImage}; |
2641 | | |
2642 | | #[bench] |
2643 | | fn conversion(b: &mut test::Bencher) { |
2644 | | let mut a: RgbImage = ImageBuffer::new(1000, 1000); |
2645 | | for p in a.pixels_mut() { |
2646 | | let rgb = p.channels_mut(); |
2647 | | rgb[0] = 255; |
2648 | | rgb[1] = 23; |
2649 | | rgb[2] = 42; |
2650 | | } |
2651 | | |
2652 | | assert!(a.data[0] != 0); |
2653 | | b.iter(|| { |
2654 | | let b: GrayImage = a.convert(); |
2655 | | assert!(0 != b.data[0]); |
2656 | | assert!(a.data[0] != b.data[0]); |
2657 | | test::black_box(b); |
2658 | | }); |
2659 | | b.bytes = 1000 * 1000 * 3; |
2660 | | } |
2661 | | |
2662 | | #[bench] |
2663 | | fn image_access_row_by_row(b: &mut test::Bencher) { |
2664 | | let mut a: RgbImage = ImageBuffer::new(1000, 1000); |
2665 | | for p in a.pixels_mut() { |
2666 | | let rgb = p.channels_mut(); |
2667 | | rgb[0] = 255; |
2668 | | rgb[1] = 23; |
2669 | | rgb[2] = 42; |
2670 | | } |
2671 | | |
2672 | | b.iter(move || { |
2673 | | let image: &RgbImage = test::black_box(&a); |
2674 | | let mut sum: usize = 0; |
2675 | | for y in 0..1000 { |
2676 | | for x in 0..1000 { |
2677 | | let pixel = image.get_pixel(x, y); |
2678 | | sum = sum.wrapping_add(pixel[0] as usize); |
2679 | | sum = sum.wrapping_add(pixel[1] as usize); |
2680 | | sum = sum.wrapping_add(pixel[2] as usize); |
2681 | | } |
2682 | | } |
2683 | | test::black_box(sum) |
2684 | | }); |
2685 | | |
2686 | | b.bytes = 1000 * 1000 * 3; |
2687 | | } |
2688 | | |
2689 | | #[bench] |
2690 | | fn image_access_col_by_col(b: &mut test::Bencher) { |
2691 | | let mut a: RgbImage = ImageBuffer::new(1000, 1000); |
2692 | | for p in a.pixels_mut() { |
2693 | | let rgb = p.channels_mut(); |
2694 | | rgb[0] = 255; |
2695 | | rgb[1] = 23; |
2696 | | rgb[2] = 42; |
2697 | | } |
2698 | | |
2699 | | b.iter(move || { |
2700 | | let image: &RgbImage = test::black_box(&a); |
2701 | | let mut sum: usize = 0; |
2702 | | for x in 0..1000 { |
2703 | | for y in 0..1000 { |
2704 | | let pixel = image.get_pixel(x, y); |
2705 | | sum = sum.wrapping_add(pixel[0] as usize); |
2706 | | sum = sum.wrapping_add(pixel[1] as usize); |
2707 | | sum = sum.wrapping_add(pixel[2] as usize); |
2708 | | } |
2709 | | } |
2710 | | test::black_box(sum) |
2711 | | }); |
2712 | | |
2713 | | b.bytes = 1000 * 1000 * 3; |
2714 | | } |
2715 | | } |