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