/src/image/src/imageops/affine.rs
Line | Count | Source |
1 | | //! Functions for performing affine transformations. |
2 | | |
3 | | use crate::error::{ImageError, ParameterError, ParameterErrorKind}; |
4 | | use crate::traits::Pixel; |
5 | | use crate::{GenericImage, GenericImageView, ImageBuffer}; |
6 | | |
7 | | /// Rotate an image 90 degrees clockwise. |
8 | 168 | pub fn rotate90<I: GenericImageView>( |
9 | 168 | image: &I, |
10 | 168 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { |
11 | 168 | let (width, height) = image.dimensions(); |
12 | 168 | let mut out = image.buffer_with_dimensions(height, width); |
13 | 168 | let _ = rotate90_in(image, &mut out); |
14 | 168 | out |
15 | 168 | } image::imageops::affine::rotate90::<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>> Line | Count | Source | 8 | 11 | pub fn rotate90<I: GenericImageView>( | 9 | 11 | image: &I, | 10 | 11 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { | 11 | 11 | let (width, height) = image.dimensions(); | 12 | 11 | let mut out = image.buffer_with_dimensions(height, width); | 13 | 11 | let _ = rotate90_in(image, &mut out); | 14 | 11 | out | 15 | 11 | } |
image::imageops::affine::rotate90::<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>> Line | Count | Source | 8 | 37 | pub fn rotate90<I: GenericImageView>( | 9 | 37 | image: &I, | 10 | 37 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { | 11 | 37 | let (width, height) = image.dimensions(); | 12 | 37 | let mut out = image.buffer_with_dimensions(height, width); | 13 | 37 | let _ = rotate90_in(image, &mut out); | 14 | 37 | out | 15 | 37 | } |
image::imageops::affine::rotate90::<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>> Line | Count | Source | 8 | 14 | pub fn rotate90<I: GenericImageView>( | 9 | 14 | image: &I, | 10 | 14 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { | 11 | 14 | let (width, height) = image.dimensions(); | 12 | 14 | let mut out = image.buffer_with_dimensions(height, width); | 13 | 14 | let _ = rotate90_in(image, &mut out); | 14 | 14 | out | 15 | 14 | } |
Unexecuted instantiation: image::imageops::affine::rotate90::<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>> image::imageops::affine::rotate90::<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>> Line | Count | Source | 8 | 38 | pub fn rotate90<I: GenericImageView>( | 9 | 38 | image: &I, | 10 | 38 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { | 11 | 38 | let (width, height) = image.dimensions(); | 12 | 38 | let mut out = image.buffer_with_dimensions(height, width); | 13 | 38 | let _ = rotate90_in(image, &mut out); | 14 | 38 | out | 15 | 38 | } |
image::imageops::affine::rotate90::<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>> Line | Count | Source | 8 | 24 | pub fn rotate90<I: GenericImageView>( | 9 | 24 | image: &I, | 10 | 24 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { | 11 | 24 | let (width, height) = image.dimensions(); | 12 | 24 | let mut out = image.buffer_with_dimensions(height, width); | 13 | 24 | let _ = rotate90_in(image, &mut out); | 14 | 24 | out | 15 | 24 | } |
image::imageops::affine::rotate90::<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>> Line | Count | Source | 8 | 14 | pub fn rotate90<I: GenericImageView>( | 9 | 14 | image: &I, | 10 | 14 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { | 11 | 14 | let (width, height) = image.dimensions(); | 12 | 14 | let mut out = image.buffer_with_dimensions(height, width); | 13 | 14 | let _ = rotate90_in(image, &mut out); | 14 | 14 | out | 15 | 14 | } |
image::imageops::affine::rotate90::<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>> Line | Count | Source | 8 | 15 | pub fn rotate90<I: GenericImageView>( | 9 | 15 | image: &I, | 10 | 15 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { | 11 | 15 | let (width, height) = image.dimensions(); | 12 | 15 | let mut out = image.buffer_with_dimensions(height, width); | 13 | 15 | let _ = rotate90_in(image, &mut out); | 14 | 15 | out | 15 | 15 | } |
image::imageops::affine::rotate90::<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>> Line | Count | Source | 8 | 15 | pub fn rotate90<I: GenericImageView>( | 9 | 15 | image: &I, | 10 | 15 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { | 11 | 15 | let (width, height) = image.dimensions(); | 12 | 15 | let mut out = image.buffer_with_dimensions(height, width); | 13 | 15 | let _ = rotate90_in(image, &mut out); | 14 | 15 | out | 15 | 15 | } |
Unexecuted instantiation: image::imageops::affine::rotate90::<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>> Unexecuted instantiation: image::imageops::affine::rotate90::<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>> Unexecuted instantiation: image::imageops::affine::rotate90::<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>> |
16 | | |
17 | | /// Rotate an image 180 degrees clockwise. |
18 | 0 | pub fn rotate180<I: GenericImageView>( |
19 | 0 | image: &I, |
20 | 0 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { |
21 | 0 | let (width, height) = image.dimensions(); |
22 | 0 | let mut out = image.buffer_with_dimensions(width, height); |
23 | 0 | let _ = rotate180_in(image, &mut out); |
24 | 0 | out |
25 | 0 | } Unexecuted instantiation: image::imageops::affine::rotate180::<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>> Unexecuted instantiation: image::imageops::affine::rotate180::<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>> Unexecuted instantiation: image::imageops::affine::rotate180::<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>> Unexecuted instantiation: image::imageops::affine::rotate180::<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>> Unexecuted instantiation: image::imageops::affine::rotate180::<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>> Unexecuted instantiation: image::imageops::affine::rotate180::<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>> Unexecuted instantiation: image::imageops::affine::rotate180::<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>> Unexecuted instantiation: image::imageops::affine::rotate180::<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>> Unexecuted instantiation: image::imageops::affine::rotate180::<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>> Unexecuted instantiation: image::imageops::affine::rotate180::<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>> Unexecuted instantiation: image::imageops::affine::rotate180::<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>> Unexecuted instantiation: image::imageops::affine::rotate180::<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>> |
26 | | |
27 | | /// Rotate an image 270 degrees clockwise. |
28 | 165 | pub fn rotate270<I: GenericImageView>( |
29 | 165 | image: &I, |
30 | 165 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { |
31 | 165 | let (width, height) = image.dimensions(); |
32 | 165 | let mut out = image.buffer_with_dimensions(height, width); |
33 | 165 | let _ = rotate270_in(image, &mut out); |
34 | 165 | out |
35 | 165 | } image::imageops::affine::rotate270::<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>> Line | Count | Source | 28 | 8 | pub fn rotate270<I: GenericImageView>( | 29 | 8 | image: &I, | 30 | 8 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { | 31 | 8 | let (width, height) = image.dimensions(); | 32 | 8 | let mut out = image.buffer_with_dimensions(height, width); | 33 | 8 | let _ = rotate270_in(image, &mut out); | 34 | 8 | out | 35 | 8 | } |
image::imageops::affine::rotate270::<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>> Line | Count | Source | 28 | 39 | pub fn rotate270<I: GenericImageView>( | 29 | 39 | image: &I, | 30 | 39 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { | 31 | 39 | let (width, height) = image.dimensions(); | 32 | 39 | let mut out = image.buffer_with_dimensions(height, width); | 33 | 39 | let _ = rotate270_in(image, &mut out); | 34 | 39 | out | 35 | 39 | } |
image::imageops::affine::rotate270::<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>> Line | Count | Source | 28 | 8 | pub fn rotate270<I: GenericImageView>( | 29 | 8 | image: &I, | 30 | 8 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { | 31 | 8 | let (width, height) = image.dimensions(); | 32 | 8 | let mut out = image.buffer_with_dimensions(height, width); | 33 | 8 | let _ = rotate270_in(image, &mut out); | 34 | 8 | out | 35 | 8 | } |
Unexecuted instantiation: image::imageops::affine::rotate270::<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>> image::imageops::affine::rotate270::<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>> Line | Count | Source | 28 | 59 | pub fn rotate270<I: GenericImageView>( | 29 | 59 | image: &I, | 30 | 59 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { | 31 | 59 | let (width, height) = image.dimensions(); | 32 | 59 | let mut out = image.buffer_with_dimensions(height, width); | 33 | 59 | let _ = rotate270_in(image, &mut out); | 34 | 59 | out | 35 | 59 | } |
image::imageops::affine::rotate270::<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>> Line | Count | Source | 28 | 15 | pub fn rotate270<I: GenericImageView>( | 29 | 15 | image: &I, | 30 | 15 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { | 31 | 15 | let (width, height) = image.dimensions(); | 32 | 15 | let mut out = image.buffer_with_dimensions(height, width); | 33 | 15 | let _ = rotate270_in(image, &mut out); | 34 | 15 | out | 35 | 15 | } |
image::imageops::affine::rotate270::<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>> Line | Count | Source | 28 | 17 | pub fn rotate270<I: GenericImageView>( | 29 | 17 | image: &I, | 30 | 17 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { | 31 | 17 | let (width, height) = image.dimensions(); | 32 | 17 | let mut out = image.buffer_with_dimensions(height, width); | 33 | 17 | let _ = rotate270_in(image, &mut out); | 34 | 17 | out | 35 | 17 | } |
image::imageops::affine::rotate270::<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>> Line | Count | Source | 28 | 16 | pub fn rotate270<I: GenericImageView>( | 29 | 16 | image: &I, | 30 | 16 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { | 31 | 16 | let (width, height) = image.dimensions(); | 32 | 16 | let mut out = image.buffer_with_dimensions(height, width); | 33 | 16 | let _ = rotate270_in(image, &mut out); | 34 | 16 | out | 35 | 16 | } |
image::imageops::affine::rotate270::<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>> Line | Count | Source | 28 | 3 | pub fn rotate270<I: GenericImageView>( | 29 | 3 | image: &I, | 30 | 3 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { | 31 | 3 | let (width, height) = image.dimensions(); | 32 | 3 | let mut out = image.buffer_with_dimensions(height, width); | 33 | 3 | let _ = rotate270_in(image, &mut out); | 34 | 3 | out | 35 | 3 | } |
Unexecuted instantiation: image::imageops::affine::rotate270::<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>> Unexecuted instantiation: image::imageops::affine::rotate270::<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>> Unexecuted instantiation: image::imageops::affine::rotate270::<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>> |
36 | | |
37 | | /// Rotate an image 90 degrees clockwise and put the result into the destination [`ImageBuffer`]. |
38 | 168 | pub fn rotate90_in<I, Container>( |
39 | 168 | image: &I, |
40 | 168 | destination: &mut ImageBuffer<I::Pixel, Container>, |
41 | 168 | ) -> crate::ImageResult<()> |
42 | 168 | where |
43 | 168 | I: GenericImageView, |
44 | 168 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, |
45 | | { |
46 | 168 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); |
47 | 168 | if w0 != h1 || h0 != w1 { |
48 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( |
49 | 0 | ParameterErrorKind::DimensionMismatch, |
50 | 0 | ))); |
51 | 168 | } |
52 | | |
53 | 187k | for y in 0..h0 { |
54 | 345M | for x in 0..w0 { |
55 | 345M | let p = image.get_pixel(x, y); |
56 | 345M | destination.put_pixel(h0 - y - 1, x, p); |
57 | 345M | } |
58 | | } |
59 | 168 | Ok(()) |
60 | 168 | } image::imageops::affine::rotate90_in::<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Line | Count | Source | 38 | 11 | pub fn rotate90_in<I, Container>( | 39 | 11 | image: &I, | 40 | 11 | destination: &mut ImageBuffer<I::Pixel, Container>, | 41 | 11 | ) -> crate::ImageResult<()> | 42 | 11 | where | 43 | 11 | I: GenericImageView, | 44 | 11 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, | 45 | | { | 46 | 11 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); | 47 | 11 | if w0 != h1 || h0 != w1 { | 48 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( | 49 | 0 | ParameterErrorKind::DimensionMismatch, | 50 | 0 | ))); | 51 | 11 | } | 52 | | | 53 | 310 | for y in 0..h0 { | 54 | 415 | for x in 0..w0 { | 55 | 415 | let p = image.get_pixel(x, y); | 56 | 415 | destination.put_pixel(h0 - y - 1, x, p); | 57 | 415 | } | 58 | | } | 59 | 11 | Ok(()) | 60 | 11 | } |
image::imageops::affine::rotate90_in::<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Line | Count | Source | 38 | 37 | pub fn rotate90_in<I, Container>( | 39 | 37 | image: &I, | 40 | 37 | destination: &mut ImageBuffer<I::Pixel, Container>, | 41 | 37 | ) -> crate::ImageResult<()> | 42 | 37 | where | 43 | 37 | I: GenericImageView, | 44 | 37 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, | 45 | | { | 46 | 37 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); | 47 | 37 | if w0 != h1 || h0 != w1 { | 48 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( | 49 | 0 | ParameterErrorKind::DimensionMismatch, | 50 | 0 | ))); | 51 | 37 | } | 52 | | | 53 | 112k | for y in 0..h0 { | 54 | 226M | for x in 0..w0 { | 55 | 226M | let p = image.get_pixel(x, y); | 56 | 226M | destination.put_pixel(h0 - y - 1, x, p); | 57 | 226M | } | 58 | | } | 59 | 37 | Ok(()) | 60 | 37 | } |
image::imageops::affine::rotate90_in::<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> Line | Count | Source | 38 | 14 | pub fn rotate90_in<I, Container>( | 39 | 14 | image: &I, | 40 | 14 | destination: &mut ImageBuffer<I::Pixel, Container>, | 41 | 14 | ) -> crate::ImageResult<()> | 42 | 14 | where | 43 | 14 | I: GenericImageView, | 44 | 14 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, | 45 | | { | 46 | 14 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); | 47 | 14 | if w0 != h1 || h0 != w1 { | 48 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( | 49 | 0 | ParameterErrorKind::DimensionMismatch, | 50 | 0 | ))); | 51 | 14 | } | 52 | | | 53 | 309 | for y in 0..h0 { | 54 | 28.9k | for x in 0..w0 { | 55 | 28.9k | let p = image.get_pixel(x, y); | 56 | 28.9k | destination.put_pixel(h0 - y - 1, x, p); | 57 | 28.9k | } | 58 | | } | 59 | 14 | Ok(()) | 60 | 14 | } |
Unexecuted instantiation: image::imageops::affine::rotate90_in::<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> image::imageops::affine::rotate90_in::<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Line | Count | Source | 38 | 38 | pub fn rotate90_in<I, Container>( | 39 | 38 | image: &I, | 40 | 38 | destination: &mut ImageBuffer<I::Pixel, Container>, | 41 | 38 | ) -> crate::ImageResult<()> | 42 | 38 | where | 43 | 38 | I: GenericImageView, | 44 | 38 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, | 45 | | { | 46 | 38 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); | 47 | 38 | if w0 != h1 || h0 != w1 { | 48 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( | 49 | 0 | ParameterErrorKind::DimensionMismatch, | 50 | 0 | ))); | 51 | 38 | } | 52 | | | 53 | 73.0k | for y in 0..h0 { | 54 | 118M | for x in 0..w0 { | 55 | 118M | let p = image.get_pixel(x, y); | 56 | 118M | destination.put_pixel(h0 - y - 1, x, p); | 57 | 118M | } | 58 | | } | 59 | 38 | Ok(()) | 60 | 38 | } |
image::imageops::affine::rotate90_in::<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> Line | Count | Source | 38 | 24 | pub fn rotate90_in<I, Container>( | 39 | 24 | image: &I, | 40 | 24 | destination: &mut ImageBuffer<I::Pixel, Container>, | 41 | 24 | ) -> crate::ImageResult<()> | 42 | 24 | where | 43 | 24 | I: GenericImageView, | 44 | 24 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, | 45 | | { | 46 | 24 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); | 47 | 24 | if w0 != h1 || h0 != w1 { | 48 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( | 49 | 0 | ParameterErrorKind::DimensionMismatch, | 50 | 0 | ))); | 51 | 24 | } | 52 | | | 53 | 952 | for y in 0..h0 { | 54 | 96.9k | for x in 0..w0 { | 55 | 96.9k | let p = image.get_pixel(x, y); | 56 | 96.9k | destination.put_pixel(h0 - y - 1, x, p); | 57 | 96.9k | } | 58 | | } | 59 | 24 | Ok(()) | 60 | 24 | } |
image::imageops::affine::rotate90_in::<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Line | Count | Source | 38 | 14 | pub fn rotate90_in<I, Container>( | 39 | 14 | image: &I, | 40 | 14 | destination: &mut ImageBuffer<I::Pixel, Container>, | 41 | 14 | ) -> crate::ImageResult<()> | 42 | 14 | where | 43 | 14 | I: GenericImageView, | 44 | 14 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, | 45 | | { | 46 | 14 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); | 47 | 14 | if w0 != h1 || h0 != w1 { | 48 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( | 49 | 0 | ParameterErrorKind::DimensionMismatch, | 50 | 0 | ))); | 51 | 14 | } | 52 | | | 53 | 56 | for y in 0..h0 { | 54 | 1.95k | for x in 0..w0 { | 55 | 1.95k | let p = image.get_pixel(x, y); | 56 | 1.95k | destination.put_pixel(h0 - y - 1, x, p); | 57 | 1.95k | } | 58 | | } | 59 | 14 | Ok(()) | 60 | 14 | } |
image::imageops::affine::rotate90_in::<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Line | Count | Source | 38 | 15 | pub fn rotate90_in<I, Container>( | 39 | 15 | image: &I, | 40 | 15 | destination: &mut ImageBuffer<I::Pixel, Container>, | 41 | 15 | ) -> crate::ImageResult<()> | 42 | 15 | where | 43 | 15 | I: GenericImageView, | 44 | 15 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, | 45 | | { | 46 | 15 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); | 47 | 15 | if w0 != h1 || h0 != w1 { | 48 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( | 49 | 0 | ParameterErrorKind::DimensionMismatch, | 50 | 0 | ))); | 51 | 15 | } | 52 | | | 53 | 530 | for y in 0..h0 { | 54 | 6.97k | for x in 0..w0 { | 55 | 6.97k | let p = image.get_pixel(x, y); | 56 | 6.97k | destination.put_pixel(h0 - y - 1, x, p); | 57 | 6.97k | } | 58 | | } | 59 | 15 | Ok(()) | 60 | 15 | } |
image::imageops::affine::rotate90_in::<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> Line | Count | Source | 38 | 15 | pub fn rotate90_in<I, Container>( | 39 | 15 | image: &I, | 40 | 15 | destination: &mut ImageBuffer<I::Pixel, Container>, | 41 | 15 | ) -> crate::ImageResult<()> | 42 | 15 | where | 43 | 15 | I: GenericImageView, | 44 | 15 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, | 45 | | { | 46 | 15 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); | 47 | 15 | if w0 != h1 || h0 != w1 { | 48 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( | 49 | 0 | ParameterErrorKind::DimensionMismatch, | 50 | 0 | ))); | 51 | 15 | } | 52 | | | 53 | 101 | for y in 0..h0 { | 54 | 1.87k | for x in 0..w0 { | 55 | 1.87k | let p = image.get_pixel(x, y); | 56 | 1.87k | destination.put_pixel(h0 - y - 1, x, p); | 57 | 1.87k | } | 58 | | } | 59 | 15 | Ok(()) | 60 | 15 | } |
Unexecuted instantiation: image::imageops::affine::rotate90_in::<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Unexecuted instantiation: image::imageops::affine::rotate90_in::<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Unexecuted instantiation: image::imageops::affine::rotate90_in::<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> |
61 | | |
62 | | /// Rotate an image 180 degrees clockwise and put the result into the destination [`ImageBuffer`]. |
63 | 0 | pub fn rotate180_in<I, Container>( |
64 | 0 | image: &I, |
65 | 0 | destination: &mut ImageBuffer<I::Pixel, Container>, |
66 | 0 | ) -> crate::ImageResult<()> |
67 | 0 | where |
68 | 0 | I: GenericImageView, |
69 | 0 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, |
70 | | { |
71 | 0 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); |
72 | 0 | if w0 != w1 || h0 != h1 { |
73 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( |
74 | 0 | ParameterErrorKind::DimensionMismatch, |
75 | 0 | ))); |
76 | 0 | } |
77 | | |
78 | 0 | for y in 0..h0 { |
79 | 0 | for x in 0..w0 { |
80 | 0 | let p = image.get_pixel(x, y); |
81 | 0 | destination.put_pixel(w0 - x - 1, h0 - y - 1, p); |
82 | 0 | } |
83 | | } |
84 | 0 | Ok(()) |
85 | 0 | } Unexecuted instantiation: image::imageops::affine::rotate180_in::<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Unexecuted instantiation: image::imageops::affine::rotate180_in::<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Unexecuted instantiation: image::imageops::affine::rotate180_in::<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> Unexecuted instantiation: image::imageops::affine::rotate180_in::<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Unexecuted instantiation: image::imageops::affine::rotate180_in::<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Unexecuted instantiation: image::imageops::affine::rotate180_in::<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> Unexecuted instantiation: image::imageops::affine::rotate180_in::<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Unexecuted instantiation: image::imageops::affine::rotate180_in::<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Unexecuted instantiation: image::imageops::affine::rotate180_in::<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> Unexecuted instantiation: image::imageops::affine::rotate180_in::<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Unexecuted instantiation: image::imageops::affine::rotate180_in::<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Unexecuted instantiation: image::imageops::affine::rotate180_in::<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> |
86 | | |
87 | | /// Rotate an image 270 degrees clockwise and put the result into the destination [`ImageBuffer`]. |
88 | 165 | pub fn rotate270_in<I, Container>( |
89 | 165 | image: &I, |
90 | 165 | destination: &mut ImageBuffer<I::Pixel, Container>, |
91 | 165 | ) -> crate::ImageResult<()> |
92 | 165 | where |
93 | 165 | I: GenericImageView, |
94 | 165 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, |
95 | | { |
96 | 165 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); |
97 | 165 | if w0 != h1 || h0 != w1 { |
98 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( |
99 | 0 | ParameterErrorKind::DimensionMismatch, |
100 | 0 | ))); |
101 | 165 | } |
102 | | |
103 | 760k | for y in 0..h0 { |
104 | 305M | for x in 0..w0 { |
105 | 305M | let p = image.get_pixel(x, y); |
106 | 305M | destination.put_pixel(y, w0 - x - 1, p); |
107 | 305M | } |
108 | | } |
109 | 165 | Ok(()) |
110 | 165 | } image::imageops::affine::rotate270_in::<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Line | Count | Source | 88 | 8 | pub fn rotate270_in<I, Container>( | 89 | 8 | image: &I, | 90 | 8 | destination: &mut ImageBuffer<I::Pixel, Container>, | 91 | 8 | ) -> crate::ImageResult<()> | 92 | 8 | where | 93 | 8 | I: GenericImageView, | 94 | 8 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, | 95 | | { | 96 | 8 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); | 97 | 8 | if w0 != h1 || h0 != w1 { | 98 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( | 99 | 0 | ParameterErrorKind::DimensionMismatch, | 100 | 0 | ))); | 101 | 8 | } | 102 | | | 103 | 21 | for y in 0..h0 { | 104 | 2.12k | for x in 0..w0 { | 105 | 2.12k | let p = image.get_pixel(x, y); | 106 | 2.12k | destination.put_pixel(y, w0 - x - 1, p); | 107 | 2.12k | } | 108 | | } | 109 | 8 | Ok(()) | 110 | 8 | } |
image::imageops::affine::rotate270_in::<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Line | Count | Source | 88 | 39 | pub fn rotate270_in<I, Container>( | 89 | 39 | image: &I, | 90 | 39 | destination: &mut ImageBuffer<I::Pixel, Container>, | 91 | 39 | ) -> crate::ImageResult<()> | 92 | 39 | where | 93 | 39 | I: GenericImageView, | 94 | 39 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, | 95 | | { | 96 | 39 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); | 97 | 39 | if w0 != h1 || h0 != w1 { | 98 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( | 99 | 0 | ParameterErrorKind::DimensionMismatch, | 100 | 0 | ))); | 101 | 39 | } | 102 | | | 103 | 184k | for y in 0..h0 { | 104 | 91.3M | for x in 0..w0 { | 105 | 91.3M | let p = image.get_pixel(x, y); | 106 | 91.3M | destination.put_pixel(y, w0 - x - 1, p); | 107 | 91.3M | } | 108 | | } | 109 | 39 | Ok(()) | 110 | 39 | } |
image::imageops::affine::rotate270_in::<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> Line | Count | Source | 88 | 8 | pub fn rotate270_in<I, Container>( | 89 | 8 | image: &I, | 90 | 8 | destination: &mut ImageBuffer<I::Pixel, Container>, | 91 | 8 | ) -> crate::ImageResult<()> | 92 | 8 | where | 93 | 8 | I: GenericImageView, | 94 | 8 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, | 95 | | { | 96 | 8 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); | 97 | 8 | if w0 != h1 || h0 != w1 { | 98 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( | 99 | 0 | ParameterErrorKind::DimensionMismatch, | 100 | 0 | ))); | 101 | 8 | } | 102 | | | 103 | 34 | for y in 0..h0 { | 104 | 132 | for x in 0..w0 { | 105 | 132 | let p = image.get_pixel(x, y); | 106 | 132 | destination.put_pixel(y, w0 - x - 1, p); | 107 | 132 | } | 108 | | } | 109 | 8 | Ok(()) | 110 | 8 | } |
Unexecuted instantiation: image::imageops::affine::rotate270_in::<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> image::imageops::affine::rotate270_in::<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Line | Count | Source | 88 | 59 | pub fn rotate270_in<I, Container>( | 89 | 59 | image: &I, | 90 | 59 | destination: &mut ImageBuffer<I::Pixel, Container>, | 91 | 59 | ) -> crate::ImageResult<()> | 92 | 59 | where | 93 | 59 | I: GenericImageView, | 94 | 59 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, | 95 | | { | 96 | 59 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); | 97 | 59 | if w0 != h1 || h0 != w1 { | 98 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( | 99 | 0 | ParameterErrorKind::DimensionMismatch, | 100 | 0 | ))); | 101 | 59 | } | 102 | | | 103 | 575k | for y in 0..h0 { | 104 | 213M | for x in 0..w0 { | 105 | 213M | let p = image.get_pixel(x, y); | 106 | 213M | destination.put_pixel(y, w0 - x - 1, p); | 107 | 213M | } | 108 | | } | 109 | 59 | Ok(()) | 110 | 59 | } |
image::imageops::affine::rotate270_in::<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> Line | Count | Source | 88 | 15 | pub fn rotate270_in<I, Container>( | 89 | 15 | image: &I, | 90 | 15 | destination: &mut ImageBuffer<I::Pixel, Container>, | 91 | 15 | ) -> crate::ImageResult<()> | 92 | 15 | where | 93 | 15 | I: GenericImageView, | 94 | 15 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, | 95 | | { | 96 | 15 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); | 97 | 15 | if w0 != h1 || h0 != w1 { | 98 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( | 99 | 0 | ParameterErrorKind::DimensionMismatch, | 100 | 0 | ))); | 101 | 15 | } | 102 | | | 103 | 553 | for y in 0..h0 { | 104 | 69.0k | for x in 0..w0 { | 105 | 69.0k | let p = image.get_pixel(x, y); | 106 | 69.0k | destination.put_pixel(y, w0 - x - 1, p); | 107 | 69.0k | } | 108 | | } | 109 | 15 | Ok(()) | 110 | 15 | } |
image::imageops::affine::rotate270_in::<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Line | Count | Source | 88 | 17 | pub fn rotate270_in<I, Container>( | 89 | 17 | image: &I, | 90 | 17 | destination: &mut ImageBuffer<I::Pixel, Container>, | 91 | 17 | ) -> crate::ImageResult<()> | 92 | 17 | where | 93 | 17 | I: GenericImageView, | 94 | 17 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, | 95 | | { | 96 | 17 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); | 97 | 17 | if w0 != h1 || h0 != w1 { | 98 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( | 99 | 0 | ParameterErrorKind::DimensionMismatch, | 100 | 0 | ))); | 101 | 17 | } | 102 | | | 103 | 88 | for y in 0..h0 { | 104 | 2.27k | for x in 0..w0 { | 105 | 2.27k | let p = image.get_pixel(x, y); | 106 | 2.27k | destination.put_pixel(y, w0 - x - 1, p); | 107 | 2.27k | } | 108 | | } | 109 | 17 | Ok(()) | 110 | 17 | } |
image::imageops::affine::rotate270_in::<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Line | Count | Source | 88 | 16 | pub fn rotate270_in<I, Container>( | 89 | 16 | image: &I, | 90 | 16 | destination: &mut ImageBuffer<I::Pixel, Container>, | 91 | 16 | ) -> crate::ImageResult<()> | 92 | 16 | where | 93 | 16 | I: GenericImageView, | 94 | 16 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, | 95 | | { | 96 | 16 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); | 97 | 16 | if w0 != h1 || h0 != w1 { | 98 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( | 99 | 0 | ParameterErrorKind::DimensionMismatch, | 100 | 0 | ))); | 101 | 16 | } | 102 | | | 103 | 920 | for y in 0..h0 { | 104 | 8.82k | for x in 0..w0 { | 105 | 8.82k | let p = image.get_pixel(x, y); | 106 | 8.82k | destination.put_pixel(y, w0 - x - 1, p); | 107 | 8.82k | } | 108 | | } | 109 | 16 | Ok(()) | 110 | 16 | } |
image::imageops::affine::rotate270_in::<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> Line | Count | Source | 88 | 3 | pub fn rotate270_in<I, Container>( | 89 | 3 | image: &I, | 90 | 3 | destination: &mut ImageBuffer<I::Pixel, Container>, | 91 | 3 | ) -> crate::ImageResult<()> | 92 | 3 | where | 93 | 3 | I: GenericImageView, | 94 | 3 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, | 95 | | { | 96 | 3 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); | 97 | 3 | if w0 != h1 || h0 != w1 { | 98 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( | 99 | 0 | ParameterErrorKind::DimensionMismatch, | 100 | 0 | ))); | 101 | 3 | } | 102 | | | 103 | 41 | for y in 0..h0 { | 104 | 825 | for x in 0..w0 { | 105 | 825 | let p = image.get_pixel(x, y); | 106 | 825 | destination.put_pixel(y, w0 - x - 1, p); | 107 | 825 | } | 108 | | } | 109 | 3 | Ok(()) | 110 | 3 | } |
Unexecuted instantiation: image::imageops::affine::rotate270_in::<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Unexecuted instantiation: image::imageops::affine::rotate270_in::<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Unexecuted instantiation: image::imageops::affine::rotate270_in::<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> |
111 | | |
112 | | /// Flip an image horizontally |
113 | 0 | pub fn flip_horizontal<I: GenericImageView>( |
114 | 0 | image: &I, |
115 | 0 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { |
116 | 0 | let mut out = image.buffer_like(); |
117 | 0 | let _ = flip_horizontal_in(image, &mut out); |
118 | 0 | out |
119 | 0 | } Unexecuted instantiation: image::imageops::affine::flip_horizontal::<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>> Unexecuted instantiation: image::imageops::affine::flip_horizontal::<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>> Unexecuted instantiation: image::imageops::affine::flip_horizontal::<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>> Unexecuted instantiation: image::imageops::affine::flip_horizontal::<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>> Unexecuted instantiation: image::imageops::affine::flip_horizontal::<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>> Unexecuted instantiation: image::imageops::affine::flip_horizontal::<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>> Unexecuted instantiation: image::imageops::affine::flip_horizontal::<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>> Unexecuted instantiation: image::imageops::affine::flip_horizontal::<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>> Unexecuted instantiation: image::imageops::affine::flip_horizontal::<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>> Unexecuted instantiation: image::imageops::affine::flip_horizontal::<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>> Unexecuted instantiation: image::imageops::affine::flip_horizontal::<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>> Unexecuted instantiation: image::imageops::affine::flip_horizontal::<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>> |
120 | | |
121 | | /// Flip an image vertically |
122 | 0 | pub fn flip_vertical<I: GenericImageView>( |
123 | 0 | image: &I, |
124 | 0 | ) -> ImageBuffer<I::Pixel, Vec<<I::Pixel as Pixel>::Subpixel>> { |
125 | 0 | let mut out = image.buffer_like(); |
126 | 0 | let _ = flip_vertical_in(image, &mut out); |
127 | 0 | out |
128 | 0 | } Unexecuted instantiation: image::imageops::affine::flip_vertical::<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>> Unexecuted instantiation: image::imageops::affine::flip_vertical::<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>> Unexecuted instantiation: image::imageops::affine::flip_vertical::<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>> Unexecuted instantiation: image::imageops::affine::flip_vertical::<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>> Unexecuted instantiation: image::imageops::affine::flip_vertical::<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>> Unexecuted instantiation: image::imageops::affine::flip_vertical::<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>> Unexecuted instantiation: image::imageops::affine::flip_vertical::<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>> Unexecuted instantiation: image::imageops::affine::flip_vertical::<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>> Unexecuted instantiation: image::imageops::affine::flip_vertical::<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>> Unexecuted instantiation: image::imageops::affine::flip_vertical::<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>> Unexecuted instantiation: image::imageops::affine::flip_vertical::<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>> Unexecuted instantiation: image::imageops::affine::flip_vertical::<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>> |
129 | | |
130 | | /// Flip an image horizontally and put the result into the destination [`ImageBuffer`]. |
131 | 0 | pub fn flip_horizontal_in<I, Container>( |
132 | 0 | image: &I, |
133 | 0 | destination: &mut ImageBuffer<I::Pixel, Container>, |
134 | 0 | ) -> crate::ImageResult<()> |
135 | 0 | where |
136 | 0 | I: GenericImageView, |
137 | 0 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, |
138 | | { |
139 | 0 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); |
140 | 0 | if w0 != w1 || h0 != h1 { |
141 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( |
142 | 0 | ParameterErrorKind::DimensionMismatch, |
143 | 0 | ))); |
144 | 0 | } |
145 | | |
146 | 0 | for y in 0..h0 { |
147 | 0 | for x in 0..w0 { |
148 | 0 | let p = image.get_pixel(x, y); |
149 | 0 | destination.put_pixel(w0 - x - 1, y, p); |
150 | 0 | } |
151 | | } |
152 | 0 | Ok(()) |
153 | 0 | } Unexecuted instantiation: image::imageops::affine::flip_horizontal_in::<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Unexecuted instantiation: image::imageops::affine::flip_horizontal_in::<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Unexecuted instantiation: image::imageops::affine::flip_horizontal_in::<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> Unexecuted instantiation: image::imageops::affine::flip_horizontal_in::<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Unexecuted instantiation: image::imageops::affine::flip_horizontal_in::<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Unexecuted instantiation: image::imageops::affine::flip_horizontal_in::<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> Unexecuted instantiation: image::imageops::affine::flip_horizontal_in::<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Unexecuted instantiation: image::imageops::affine::flip_horizontal_in::<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Unexecuted instantiation: image::imageops::affine::flip_horizontal_in::<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> Unexecuted instantiation: image::imageops::affine::flip_horizontal_in::<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Unexecuted instantiation: image::imageops::affine::flip_horizontal_in::<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Unexecuted instantiation: image::imageops::affine::flip_horizontal_in::<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> |
154 | | |
155 | | /// Flip an image vertically and put the result into the destination [`ImageBuffer`]. |
156 | 0 | pub fn flip_vertical_in<I, Container>( |
157 | 0 | image: &I, |
158 | 0 | destination: &mut ImageBuffer<I::Pixel, Container>, |
159 | 0 | ) -> crate::ImageResult<()> |
160 | 0 | where |
161 | 0 | I: GenericImageView, |
162 | 0 | Container: std::ops::DerefMut<Target = [<I::Pixel as Pixel>::Subpixel]>, |
163 | | { |
164 | 0 | let ((w0, h0), (w1, h1)) = (image.dimensions(), destination.dimensions()); |
165 | 0 | if w0 != w1 || h0 != h1 { |
166 | 0 | return Err(ImageError::Parameter(ParameterError::from_kind( |
167 | 0 | ParameterErrorKind::DimensionMismatch, |
168 | 0 | ))); |
169 | 0 | } |
170 | | |
171 | 0 | for y in 0..h0 { |
172 | 0 | for x in 0..w0 { |
173 | 0 | let p = image.get_pixel(x, y); |
174 | 0 | destination.put_pixel(x, h0 - 1 - y, p); |
175 | 0 | } |
176 | | } |
177 | 0 | Ok(()) |
178 | 0 | } Unexecuted instantiation: image::imageops::affine::flip_vertical_in::<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Unexecuted instantiation: image::imageops::affine::flip_vertical_in::<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Unexecuted instantiation: image::imageops::affine::flip_vertical_in::<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> Unexecuted instantiation: image::imageops::affine::flip_vertical_in::<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Unexecuted instantiation: image::imageops::affine::flip_vertical_in::<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Unexecuted instantiation: image::imageops::affine::flip_vertical_in::<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> Unexecuted instantiation: image::imageops::affine::flip_vertical_in::<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Unexecuted instantiation: image::imageops::affine::flip_vertical_in::<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Unexecuted instantiation: image::imageops::affine::flip_vertical_in::<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> Unexecuted instantiation: image::imageops::affine::flip_vertical_in::<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>, alloc::vec::Vec<f32>> Unexecuted instantiation: image::imageops::affine::flip_vertical_in::<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>, alloc::vec::Vec<u8>> Unexecuted instantiation: image::imageops::affine::flip_vertical_in::<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>, alloc::vec::Vec<u16>> |
179 | | |
180 | | /// Rotate an image 180 degrees clockwise in place. |
181 | 189 | pub fn rotate180_in_place<I: GenericImage>(image: &mut I) { |
182 | 189 | let (width, height) = image.dimensions(); |
183 | | |
184 | 202k | for y in 0..height / 2 { |
185 | 236M | for x in 0..width { |
186 | 236M | let p = image.get_pixel(x, y); |
187 | 236M | |
188 | 236M | let x2 = width - x - 1; |
189 | 236M | let y2 = height - y - 1; |
190 | 236M | |
191 | 236M | let p2 = image.get_pixel(x2, y2); |
192 | 236M | image.put_pixel(x, y, p2); |
193 | 236M | image.put_pixel(x2, y2, p); |
194 | 236M | } |
195 | | } |
196 | | |
197 | 189 | if height % 2 != 0 { |
198 | 143 | let middle = height / 2; |
199 | | |
200 | 121k | for x in 0..width / 2 { |
201 | 121k | let p = image.get_pixel(x, middle); |
202 | 121k | let x2 = width - x - 1; |
203 | 121k | |
204 | 121k | let p2 = image.get_pixel(x2, middle); |
205 | 121k | image.put_pixel(x, middle, p2); |
206 | 121k | image.put_pixel(x2, middle, p); |
207 | 121k | } |
208 | 46 | } |
209 | 189 | } image::imageops::affine::rotate180_in_place::<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>> Line | Count | Source | 181 | 11 | pub fn rotate180_in_place<I: GenericImage>(image: &mut I) { | 182 | 11 | let (width, height) = image.dimensions(); | 183 | | | 184 | 11 | for y in 0..height / 2 { | 185 | 25 | for x in 0..width { | 186 | 25 | let p = image.get_pixel(x, y); | 187 | 25 | | 188 | 25 | let x2 = width - x - 1; | 189 | 25 | let y2 = height - y - 1; | 190 | 25 | | 191 | 25 | let p2 = image.get_pixel(x2, y2); | 192 | 25 | image.put_pixel(x, y, p2); | 193 | 25 | image.put_pixel(x2, y2, p); | 194 | 25 | } | 195 | | } | 196 | | | 197 | 11 | if height % 2 != 0 { | 198 | 10 | let middle = height / 2; | 199 | | | 200 | 49 | for x in 0..width / 2 { | 201 | 49 | let p = image.get_pixel(x, middle); | 202 | 49 | let x2 = width - x - 1; | 203 | 49 | | 204 | 49 | let p2 = image.get_pixel(x2, middle); | 205 | 49 | image.put_pixel(x, middle, p2); | 206 | 49 | image.put_pixel(x2, middle, p); | 207 | 49 | } | 208 | 1 | } | 209 | 11 | } |
image::imageops::affine::rotate180_in_place::<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>> Line | Count | Source | 181 | 58 | pub fn rotate180_in_place<I: GenericImage>(image: &mut I) { | 182 | 58 | let (width, height) = image.dimensions(); | 183 | | | 184 | 64.5k | for y in 0..height / 2 { | 185 | 140M | for x in 0..width { | 186 | 140M | let p = image.get_pixel(x, y); | 187 | 140M | | 188 | 140M | let x2 = width - x - 1; | 189 | 140M | let y2 = height - y - 1; | 190 | 140M | | 191 | 140M | let p2 = image.get_pixel(x2, y2); | 192 | 140M | image.put_pixel(x, y, p2); | 193 | 140M | image.put_pixel(x2, y2, p); | 194 | 140M | } | 195 | | } | 196 | | | 197 | 58 | if height % 2 != 0 { | 198 | 45 | let middle = height / 2; | 199 | | | 200 | 15.2k | for x in 0..width / 2 { | 201 | 15.2k | let p = image.get_pixel(x, middle); | 202 | 15.2k | let x2 = width - x - 1; | 203 | 15.2k | | 204 | 15.2k | let p2 = image.get_pixel(x2, middle); | 205 | 15.2k | image.put_pixel(x, middle, p2); | 206 | 15.2k | image.put_pixel(x2, middle, p); | 207 | 15.2k | } | 208 | 13 | } | 209 | 58 | } |
image::imageops::affine::rotate180_in_place::<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>> Line | Count | Source | 181 | 17 | pub fn rotate180_in_place<I: GenericImage>(image: &mut I) { | 182 | 17 | let (width, height) = image.dimensions(); | 183 | | | 184 | 146 | for y in 0..height / 2 { | 185 | 2.87k | for x in 0..width { | 186 | 2.87k | let p = image.get_pixel(x, y); | 187 | 2.87k | | 188 | 2.87k | let x2 = width - x - 1; | 189 | 2.87k | let y2 = height - y - 1; | 190 | 2.87k | | 191 | 2.87k | let p2 = image.get_pixel(x2, y2); | 192 | 2.87k | image.put_pixel(x, y, p2); | 193 | 2.87k | image.put_pixel(x2, y2, p); | 194 | 2.87k | } | 195 | | } | 196 | | | 197 | 17 | if height % 2 != 0 { | 198 | 15 | let middle = height / 2; | 199 | | | 200 | 2.49k | for x in 0..width / 2 { | 201 | 2.49k | let p = image.get_pixel(x, middle); | 202 | 2.49k | let x2 = width - x - 1; | 203 | 2.49k | | 204 | 2.49k | let p2 = image.get_pixel(x2, middle); | 205 | 2.49k | image.put_pixel(x, middle, p2); | 206 | 2.49k | image.put_pixel(x2, middle, p); | 207 | 2.49k | } | 208 | 2 | } | 209 | 17 | } |
Unexecuted instantiation: image::imageops::affine::rotate180_in_place::<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>> image::imageops::affine::rotate180_in_place::<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>> Line | Count | Source | 181 | 56 | pub fn rotate180_in_place<I: GenericImage>(image: &mut I) { | 182 | 56 | let (width, height) = image.dimensions(); | 183 | | | 184 | 136k | for y in 0..height / 2 { | 185 | 95.7M | for x in 0..width { | 186 | 95.7M | let p = image.get_pixel(x, y); | 187 | 95.7M | | 188 | 95.7M | let x2 = width - x - 1; | 189 | 95.7M | let y2 = height - y - 1; | 190 | 95.7M | | 191 | 95.7M | let p2 = image.get_pixel(x2, y2); | 192 | 95.7M | image.put_pixel(x, y, p2); | 193 | 95.7M | image.put_pixel(x2, y2, p); | 194 | 95.7M | } | 195 | | } | 196 | | | 197 | 56 | if height % 2 != 0 { | 198 | 38 | let middle = height / 2; | 199 | | | 200 | 101k | for x in 0..width / 2 { | 201 | 101k | let p = image.get_pixel(x, middle); | 202 | 101k | let x2 = width - x - 1; | 203 | 101k | | 204 | 101k | let p2 = image.get_pixel(x2, middle); | 205 | 101k | image.put_pixel(x, middle, p2); | 206 | 101k | image.put_pixel(x2, middle, p); | 207 | 101k | } | 208 | 18 | } | 209 | 56 | } |
image::imageops::affine::rotate180_in_place::<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>> Line | Count | Source | 181 | 2 | pub fn rotate180_in_place<I: GenericImage>(image: &mut I) { | 182 | 2 | let (width, height) = image.dimensions(); | 183 | | | 184 | 4 | for y in 0..height / 2 { | 185 | 44 | for x in 0..width { | 186 | 44 | let p = image.get_pixel(x, y); | 187 | 44 | | 188 | 44 | let x2 = width - x - 1; | 189 | 44 | let y2 = height - y - 1; | 190 | 44 | | 191 | 44 | let p2 = image.get_pixel(x2, y2); | 192 | 44 | image.put_pixel(x, y, p2); | 193 | 44 | image.put_pixel(x2, y2, p); | 194 | 44 | } | 195 | | } | 196 | | | 197 | 2 | if height % 2 != 0 { | 198 | 2 | let middle = height / 2; | 199 | | | 200 | 517 | for x in 0..width / 2 { | 201 | 517 | let p = image.get_pixel(x, middle); | 202 | 517 | let x2 = width - x - 1; | 203 | 517 | | 204 | 517 | let p2 = image.get_pixel(x2, middle); | 205 | 517 | image.put_pixel(x, middle, p2); | 206 | 517 | image.put_pixel(x2, middle, p); | 207 | 517 | } | 208 | 0 | } | 209 | 2 | } |
image::imageops::affine::rotate180_in_place::<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>> Line | Count | Source | 181 | 15 | pub fn rotate180_in_place<I: GenericImage>(image: &mut I) { | 182 | 15 | let (width, height) = image.dimensions(); | 183 | | | 184 | 67 | for y in 0..height / 2 { | 185 | 217 | for x in 0..width { | 186 | 217 | let p = image.get_pixel(x, y); | 187 | 217 | | 188 | 217 | let x2 = width - x - 1; | 189 | 217 | let y2 = height - y - 1; | 190 | 217 | | 191 | 217 | let p2 = image.get_pixel(x2, y2); | 192 | 217 | image.put_pixel(x, y, p2); | 193 | 217 | image.put_pixel(x2, y2, p); | 194 | 217 | } | 195 | | } | 196 | | | 197 | 15 | if height % 2 != 0 { | 198 | 12 | let middle = height / 2; | 199 | | | 200 | 73 | for x in 0..width / 2 { | 201 | 73 | let p = image.get_pixel(x, middle); | 202 | 73 | let x2 = width - x - 1; | 203 | 73 | | 204 | 73 | let p2 = image.get_pixel(x2, middle); | 205 | 73 | image.put_pixel(x, middle, p2); | 206 | 73 | image.put_pixel(x2, middle, p); | 207 | 73 | } | 208 | 3 | } | 209 | 15 | } |
image::imageops::affine::rotate180_in_place::<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>> Line | Count | Source | 181 | 27 | pub fn rotate180_in_place<I: GenericImage>(image: &mut I) { | 182 | 27 | let (width, height) = image.dimensions(); | 183 | | | 184 | 1.10k | for y in 0..height / 2 { | 185 | 28.3k | for x in 0..width { | 186 | 28.3k | let p = image.get_pixel(x, y); | 187 | 28.3k | | 188 | 28.3k | let x2 = width - x - 1; | 189 | 28.3k | let y2 = height - y - 1; | 190 | 28.3k | | 191 | 28.3k | let p2 = image.get_pixel(x2, y2); | 192 | 28.3k | image.put_pixel(x, y, p2); | 193 | 28.3k | image.put_pixel(x2, y2, p); | 194 | 28.3k | } | 195 | | } | 196 | | | 197 | 27 | if height % 2 != 0 { | 198 | 18 | let middle = height / 2; | 199 | | | 200 | 548 | for x in 0..width / 2 { | 201 | 548 | let p = image.get_pixel(x, middle); | 202 | 548 | let x2 = width - x - 1; | 203 | 548 | | 204 | 548 | let p2 = image.get_pixel(x2, middle); | 205 | 548 | image.put_pixel(x, middle, p2); | 206 | 548 | image.put_pixel(x2, middle, p); | 207 | 548 | } | 208 | 9 | } | 209 | 27 | } |
image::imageops::affine::rotate180_in_place::<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>> Line | Count | Source | 181 | 3 | pub fn rotate180_in_place<I: GenericImage>(image: &mut I) { | 182 | 3 | let (width, height) = image.dimensions(); | 183 | | | 184 | 3 | for y in 0..height / 2 { | 185 | 6 | for x in 0..width { | 186 | 6 | let p = image.get_pixel(x, y); | 187 | 6 | | 188 | 6 | let x2 = width - x - 1; | 189 | 6 | let y2 = height - y - 1; | 190 | 6 | | 191 | 6 | let p2 = image.get_pixel(x2, y2); | 192 | 6 | image.put_pixel(x, y, p2); | 193 | 6 | image.put_pixel(x2, y2, p); | 194 | 6 | } | 195 | | } | 196 | | | 197 | 3 | if height % 2 != 0 { | 198 | 3 | let middle = height / 2; | 199 | | | 200 | 513 | for x in 0..width / 2 { | 201 | 513 | let p = image.get_pixel(x, middle); | 202 | 513 | let x2 = width - x - 1; | 203 | 513 | | 204 | 513 | let p2 = image.get_pixel(x2, middle); | 205 | 513 | image.put_pixel(x, middle, p2); | 206 | 513 | image.put_pixel(x2, middle, p); | 207 | 513 | } | 208 | 0 | } | 209 | 3 | } |
Unexecuted instantiation: image::imageops::affine::rotate180_in_place::<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>> Unexecuted instantiation: image::imageops::affine::rotate180_in_place::<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>> Unexecuted instantiation: image::imageops::affine::rotate180_in_place::<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>> |
210 | | |
211 | | /// Flip an image horizontally in place. |
212 | 276 | pub fn flip_horizontal_in_place<I: GenericImage>(image: &mut I) { |
213 | 276 | let (width, height) = image.dimensions(); |
214 | | |
215 | 771k | for y in 0..height { |
216 | 409M | for x in 0..width / 2 { |
217 | 409M | let x2 = width - x - 1; |
218 | 409M | let p2 = image.get_pixel(x2, y); |
219 | 409M | let p = image.get_pixel(x, y); |
220 | 409M | image.put_pixel(x2, y, p); |
221 | 409M | image.put_pixel(x, y, p2); |
222 | 409M | } |
223 | | } |
224 | 276 | } image::imageops::affine::flip_horizontal_in_place::<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>> Line | Count | Source | 212 | 21 | pub fn flip_horizontal_in_place<I: GenericImage>(image: &mut I) { | 213 | 21 | let (width, height) = image.dimensions(); | 214 | | | 215 | 87 | for y in 0..height { | 216 | 236 | for x in 0..width / 2 { | 217 | 236 | let x2 = width - x - 1; | 218 | 236 | let p2 = image.get_pixel(x2, y); | 219 | 236 | let p = image.get_pixel(x, y); | 220 | 236 | image.put_pixel(x2, y, p); | 221 | 236 | image.put_pixel(x, y, p2); | 222 | 236 | } | 223 | | } | 224 | 21 | } |
image::imageops::affine::flip_horizontal_in_place::<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>> Line | Count | Source | 212 | 61 | pub fn flip_horizontal_in_place<I: GenericImage>(image: &mut I) { | 213 | 61 | let (width, height) = image.dimensions(); | 214 | | | 215 | 63.7k | for y in 0..height { | 216 | 78.1M | for x in 0..width / 2 { | 217 | 78.1M | let x2 = width - x - 1; | 218 | 78.1M | let p2 = image.get_pixel(x2, y); | 219 | 78.1M | let p = image.get_pixel(x, y); | 220 | 78.1M | image.put_pixel(x2, y, p); | 221 | 78.1M | image.put_pixel(x, y, p2); | 222 | 78.1M | } | 223 | | } | 224 | 61 | } |
image::imageops::affine::flip_horizontal_in_place::<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>> Line | Count | Source | 212 | 24 | pub fn flip_horizontal_in_place<I: GenericImage>(image: &mut I) { | 213 | 24 | let (width, height) = image.dimensions(); | 214 | | | 215 | 930 | for y in 0..height { | 216 | 50.1k | for x in 0..width / 2 { | 217 | 50.1k | let x2 = width - x - 1; | 218 | 50.1k | let p2 = image.get_pixel(x2, y); | 219 | 50.1k | let p = image.get_pixel(x, y); | 220 | 50.1k | image.put_pixel(x2, y, p); | 221 | 50.1k | image.put_pixel(x, y, p2); | 222 | 50.1k | } | 223 | | } | 224 | 24 | } |
Unexecuted instantiation: image::imageops::affine::flip_horizontal_in_place::<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>> image::imageops::affine::flip_horizontal_in_place::<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>> Line | Count | Source | 212 | 83 | pub fn flip_horizontal_in_place<I: GenericImage>(image: &mut I) { | 213 | 83 | let (width, height) = image.dimensions(); | 214 | | | 215 | 703k | for y in 0..height { | 216 | 331M | for x in 0..width / 2 { | 217 | 331M | let x2 = width - x - 1; | 218 | 331M | let p2 = image.get_pixel(x2, y); | 219 | 331M | let p = image.get_pixel(x, y); | 220 | 331M | image.put_pixel(x2, y, p); | 221 | 331M | image.put_pixel(x, y, p2); | 222 | 331M | } | 223 | | } | 224 | 83 | } |
image::imageops::affine::flip_horizontal_in_place::<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>> Line | Count | Source | 212 | 25 | pub fn flip_horizontal_in_place<I: GenericImage>(image: &mut I) { | 213 | 25 | let (width, height) = image.dimensions(); | 214 | | | 215 | 1.85k | for y in 0..height { | 216 | 47.7k | for x in 0..width / 2 { | 217 | 47.7k | let x2 = width - x - 1; | 218 | 47.7k | let p2 = image.get_pixel(x2, y); | 219 | 47.7k | let p = image.get_pixel(x, y); | 220 | 47.7k | image.put_pixel(x2, y, p); | 221 | 47.7k | image.put_pixel(x, y, p2); | 222 | 47.7k | } | 223 | | } | 224 | 25 | } |
image::imageops::affine::flip_horizontal_in_place::<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>> Line | Count | Source | 212 | 34 | pub fn flip_horizontal_in_place<I: GenericImage>(image: &mut I) { | 213 | 34 | let (width, height) = image.dimensions(); | 214 | | | 215 | 713 | for y in 0..height { | 216 | 2.30k | for x in 0..width / 2 { | 217 | 2.30k | let x2 = width - x - 1; | 218 | 2.30k | let p2 = image.get_pixel(x2, y); | 219 | 2.30k | let p = image.get_pixel(x, y); | 220 | 2.30k | image.put_pixel(x2, y, p); | 221 | 2.30k | image.put_pixel(x, y, p2); | 222 | 2.30k | } | 223 | | } | 224 | 34 | } |
image::imageops::affine::flip_horizontal_in_place::<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>> Line | Count | Source | 212 | 19 | pub fn flip_horizontal_in_place<I: GenericImage>(image: &mut I) { | 213 | 19 | let (width, height) = image.dimensions(); | 214 | | | 215 | 473 | for y in 0..height { | 216 | 725 | for x in 0..width / 2 { | 217 | 725 | let x2 = width - x - 1; | 218 | 725 | let p2 = image.get_pixel(x2, y); | 219 | 725 | let p = image.get_pixel(x, y); | 220 | 725 | image.put_pixel(x2, y, p); | 221 | 725 | image.put_pixel(x, y, p2); | 222 | 725 | } | 223 | | } | 224 | 19 | } |
image::imageops::affine::flip_horizontal_in_place::<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>> Line | Count | Source | 212 | 9 | pub fn flip_horizontal_in_place<I: GenericImage>(image: &mut I) { | 213 | 9 | let (width, height) = image.dimensions(); | 214 | | | 215 | 267 | for y in 0..height { | 216 | 903 | for x in 0..width / 2 { | 217 | 903 | let x2 = width - x - 1; | 218 | 903 | let p2 = image.get_pixel(x2, y); | 219 | 903 | let p = image.get_pixel(x, y); | 220 | 903 | image.put_pixel(x2, y, p); | 221 | 903 | image.put_pixel(x, y, p2); | 222 | 903 | } | 223 | | } | 224 | 9 | } |
Unexecuted instantiation: image::imageops::affine::flip_horizontal_in_place::<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>> Unexecuted instantiation: image::imageops::affine::flip_horizontal_in_place::<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>> Unexecuted instantiation: image::imageops::affine::flip_horizontal_in_place::<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>> |
225 | | |
226 | | /// Flip an image vertically in place. |
227 | 99 | pub fn flip_vertical_in_place<I: GenericImage>(image: &mut I) { |
228 | 99 | let (width, height) = image.dimensions(); |
229 | | |
230 | 82.1k | for y in 0..height / 2 { |
231 | 59.0M | for x in 0..width { |
232 | 59.0M | let y2 = height - y - 1; |
233 | 59.0M | let p2 = image.get_pixel(x, y2); |
234 | 59.0M | let p = image.get_pixel(x, y); |
235 | 59.0M | image.put_pixel(x, y2, p); |
236 | 59.0M | image.put_pixel(x, y, p2); |
237 | 59.0M | } |
238 | | } |
239 | 99 | } image::imageops::affine::flip_vertical_in_place::<image::images::buffer::ImageBuffer<image::color::Rgb<f32>, alloc::vec::Vec<f32>>> Line | Count | Source | 227 | 4 | pub fn flip_vertical_in_place<I: GenericImage>(image: &mut I) { | 228 | 4 | let (width, height) = image.dimensions(); | 229 | | | 230 | 5 | for y in 0..height / 2 { | 231 | 16 | for x in 0..width { | 232 | 16 | let y2 = height - y - 1; | 233 | 16 | let p2 = image.get_pixel(x, y2); | 234 | 16 | let p = image.get_pixel(x, y); | 235 | 16 | image.put_pixel(x, y2, p); | 236 | 16 | image.put_pixel(x, y, p2); | 237 | 16 | } | 238 | | } | 239 | 4 | } |
image::imageops::affine::flip_vertical_in_place::<image::images::buffer::ImageBuffer<image::color::Rgb<u8>, alloc::vec::Vec<u8>>> Line | Count | Source | 227 | 26 | pub fn flip_vertical_in_place<I: GenericImage>(image: &mut I) { | 228 | 26 | let (width, height) = image.dimensions(); | 229 | | | 230 | 32.3k | for y in 0..height / 2 { | 231 | 40.7M | for x in 0..width { | 232 | 40.7M | let y2 = height - y - 1; | 233 | 40.7M | let p2 = image.get_pixel(x, y2); | 234 | 40.7M | let p = image.get_pixel(x, y); | 235 | 40.7M | image.put_pixel(x, y2, p); | 236 | 40.7M | image.put_pixel(x, y, p2); | 237 | 40.7M | } | 238 | | } | 239 | 26 | } |
image::imageops::affine::flip_vertical_in_place::<image::images::buffer::ImageBuffer<image::color::Rgb<u16>, alloc::vec::Vec<u16>>> Line | Count | Source | 227 | 4 | pub fn flip_vertical_in_place<I: GenericImage>(image: &mut I) { | 228 | 4 | let (width, height) = image.dimensions(); | 229 | | | 230 | 39 | for y in 0..height / 2 { | 231 | 3.72k | for x in 0..width { | 232 | 3.72k | let y2 = height - y - 1; | 233 | 3.72k | let p2 = image.get_pixel(x, y2); | 234 | 3.72k | let p = image.get_pixel(x, y); | 235 | 3.72k | image.put_pixel(x, y2, p); | 236 | 3.72k | image.put_pixel(x, y, p2); | 237 | 3.72k | } | 238 | | } | 239 | 4 | } |
Unexecuted instantiation: image::imageops::affine::flip_vertical_in_place::<image::images::buffer::ImageBuffer<image::color::Luma<f32>, alloc::vec::Vec<f32>>> image::imageops::affine::flip_vertical_in_place::<image::images::buffer::ImageBuffer<image::color::Luma<u8>, alloc::vec::Vec<u8>>> Line | Count | Source | 227 | 31 | pub fn flip_vertical_in_place<I: GenericImage>(image: &mut I) { | 228 | 31 | let (width, height) = image.dimensions(); | 229 | | | 230 | 45.9k | for y in 0..height / 2 { | 231 | 18.3M | for x in 0..width { | 232 | 18.3M | let y2 = height - y - 1; | 233 | 18.3M | let p2 = image.get_pixel(x, y2); | 234 | 18.3M | let p = image.get_pixel(x, y); | 235 | 18.3M | image.put_pixel(x, y2, p); | 236 | 18.3M | image.put_pixel(x, y, p2); | 237 | 18.3M | } | 238 | | } | 239 | 31 | } |
image::imageops::affine::flip_vertical_in_place::<image::images::buffer::ImageBuffer<image::color::Luma<u16>, alloc::vec::Vec<u16>>> Line | Count | Source | 227 | 9 | pub fn flip_vertical_in_place<I: GenericImage>(image: &mut I) { | 228 | 9 | let (width, height) = image.dimensions(); | 229 | | | 230 | 132 | for y in 0..height / 2 { | 231 | 3.51k | for x in 0..width { | 232 | 3.51k | let y2 = height - y - 1; | 233 | 3.51k | let p2 = image.get_pixel(x, y2); | 234 | 3.51k | let p = image.get_pixel(x, y); | 235 | 3.51k | image.put_pixel(x, y2, p); | 236 | 3.51k | image.put_pixel(x, y, p2); | 237 | 3.51k | } | 238 | | } | 239 | 9 | } |
image::imageops::affine::flip_vertical_in_place::<image::images::buffer::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>> Line | Count | Source | 227 | 6 | pub fn flip_vertical_in_place<I: GenericImage>(image: &mut I) { | 228 | 6 | let (width, height) = image.dimensions(); | 229 | | | 230 | 10 | for y in 0..height / 2 { | 231 | 121 | for x in 0..width { | 232 | 121 | let y2 = height - y - 1; | 233 | 121 | let p2 = image.get_pixel(x, y2); | 234 | 121 | let p = image.get_pixel(x, y); | 235 | 121 | image.put_pixel(x, y2, p); | 236 | 121 | image.put_pixel(x, y, p2); | 237 | 121 | } | 238 | | } | 239 | 6 | } |
image::imageops::affine::flip_vertical_in_place::<image::images::buffer::ImageBuffer<image::color::Rgba<u8>, alloc::vec::Vec<u8>>> Line | Count | Source | 227 | 19 | pub fn flip_vertical_in_place<I: GenericImage>(image: &mut I) { | 228 | 19 | let (width, height) = image.dimensions(); | 229 | | | 230 | 3.63k | for y in 0..height / 2 { | 231 | 3.75k | for x in 0..width { | 232 | 3.75k | let y2 = height - y - 1; | 233 | 3.75k | let p2 = image.get_pixel(x, y2); | 234 | 3.75k | let p = image.get_pixel(x, y); | 235 | 3.75k | image.put_pixel(x, y2, p); | 236 | 3.75k | image.put_pixel(x, y, p2); | 237 | 3.75k | } | 238 | | } | 239 | 19 | } |
Unexecuted instantiation: image::imageops::affine::flip_vertical_in_place::<image::images::buffer::ImageBuffer<image::color::Rgba<u16>, alloc::vec::Vec<u16>>> Unexecuted instantiation: image::imageops::affine::flip_vertical_in_place::<image::images::buffer::ImageBuffer<image::color::LumaA<f32>, alloc::vec::Vec<f32>>> Unexecuted instantiation: image::imageops::affine::flip_vertical_in_place::<image::images::buffer::ImageBuffer<image::color::LumaA<u8>, alloc::vec::Vec<u8>>> Unexecuted instantiation: image::imageops::affine::flip_vertical_in_place::<image::images::buffer::ImageBuffer<image::color::LumaA<u16>, alloc::vec::Vec<u16>>> |
240 | | |
241 | | #[cfg(test)] |
242 | | mod test { |
243 | | use super::{ |
244 | | flip_horizontal, flip_horizontal_in_place, flip_vertical, flip_vertical_in_place, |
245 | | rotate180, rotate180_in_place, rotate270, rotate90, |
246 | | }; |
247 | | |
248 | | use crate::traits::Pixel; |
249 | | use crate::{GenericImage, GrayImage, ImageBuffer}; |
250 | | |
251 | | macro_rules! assert_pixels_eq { |
252 | | ($actual:expr, $expected:expr) => {{ |
253 | | let actual_dim = $actual.dimensions(); |
254 | | let expected_dim = $expected.dimensions(); |
255 | | |
256 | | if actual_dim != expected_dim { |
257 | | panic!( |
258 | | "dimensions do not match. \ |
259 | | actual: {:?}, expected: {:?}", |
260 | | actual_dim, expected_dim |
261 | | ) |
262 | | } |
263 | | |
264 | | let diffs = pixel_diffs($actual, $expected); |
265 | | |
266 | | if !diffs.is_empty() { |
267 | | let mut err = "".to_string(); |
268 | | |
269 | | let diff_messages = diffs |
270 | | .iter() |
271 | | .take(5) |
272 | | .map(|d| format!("\nactual: {:?}, expected {:?} ", d.0, d.1)) |
273 | | .collect::<Vec<_>>() |
274 | | .join(""); |
275 | | |
276 | | err.push_str(&diff_messages); |
277 | | panic!("pixels do not match. {:?}", err) |
278 | | } |
279 | | }}; |
280 | | } |
281 | | |
282 | | #[test] |
283 | | fn test_rotate90() { |
284 | | let image: GrayImage = |
285 | | ImageBuffer::from_raw(3, 2, vec![0u8, 1u8, 2u8, 10u8, 11u8, 12u8]).unwrap(); |
286 | | |
287 | | let expected: GrayImage = |
288 | | ImageBuffer::from_raw(2, 3, vec![10u8, 0u8, 11u8, 1u8, 12u8, 2u8]).unwrap(); |
289 | | |
290 | | assert_pixels_eq!(&rotate90(&image), &expected); |
291 | | } |
292 | | |
293 | | #[test] |
294 | | fn test_rotate180() { |
295 | | let image: GrayImage = |
296 | | ImageBuffer::from_raw(3, 2, vec![0u8, 1u8, 2u8, 10u8, 11u8, 12u8]).unwrap(); |
297 | | |
298 | | let expected: GrayImage = |
299 | | ImageBuffer::from_raw(3, 2, vec![12u8, 11u8, 10u8, 2u8, 1u8, 0u8]).unwrap(); |
300 | | |
301 | | assert_pixels_eq!(&rotate180(&image), &expected); |
302 | | } |
303 | | |
304 | | #[test] |
305 | | fn test_rotate270() { |
306 | | let image: GrayImage = |
307 | | ImageBuffer::from_raw(3, 2, vec![0u8, 1u8, 2u8, 10u8, 11u8, 12u8]).unwrap(); |
308 | | |
309 | | let expected: GrayImage = |
310 | | ImageBuffer::from_raw(2, 3, vec![2u8, 12u8, 1u8, 11u8, 0u8, 10u8]).unwrap(); |
311 | | |
312 | | assert_pixels_eq!(&rotate270(&image), &expected); |
313 | | } |
314 | | |
315 | | #[test] |
316 | | fn test_rotate180_in_place() { |
317 | | let mut image: GrayImage = |
318 | | ImageBuffer::from_raw(3, 2, vec![0u8, 1u8, 2u8, 10u8, 11u8, 12u8]).unwrap(); |
319 | | |
320 | | let expected: GrayImage = |
321 | | ImageBuffer::from_raw(3, 2, vec![12u8, 11u8, 10u8, 2u8, 1u8, 0u8]).unwrap(); |
322 | | |
323 | | rotate180_in_place(&mut image); |
324 | | |
325 | | assert_pixels_eq!(&image, &expected); |
326 | | } |
327 | | |
328 | | #[test] |
329 | | fn test_flip_horizontal() { |
330 | | let image: GrayImage = |
331 | | ImageBuffer::from_raw(3, 2, vec![0u8, 1u8, 2u8, 10u8, 11u8, 12u8]).unwrap(); |
332 | | |
333 | | let expected: GrayImage = |
334 | | ImageBuffer::from_raw(3, 2, vec![2u8, 1u8, 0u8, 12u8, 11u8, 10u8]).unwrap(); |
335 | | |
336 | | assert_pixels_eq!(&flip_horizontal(&image), &expected); |
337 | | } |
338 | | |
339 | | #[test] |
340 | | fn test_flip_vertical() { |
341 | | let image: GrayImage = |
342 | | ImageBuffer::from_raw(3, 2, vec![0u8, 1u8, 2u8, 10u8, 11u8, 12u8]).unwrap(); |
343 | | |
344 | | let expected: GrayImage = |
345 | | ImageBuffer::from_raw(3, 2, vec![10u8, 11u8, 12u8, 0u8, 1u8, 2u8]).unwrap(); |
346 | | |
347 | | assert_pixels_eq!(&flip_vertical(&image), &expected); |
348 | | } |
349 | | |
350 | | #[test] |
351 | | fn test_flip_horizontal_in_place() { |
352 | | let mut image: GrayImage = |
353 | | ImageBuffer::from_raw(3, 2, vec![0u8, 1u8, 2u8, 10u8, 11u8, 12u8]).unwrap(); |
354 | | |
355 | | let expected: GrayImage = |
356 | | ImageBuffer::from_raw(3, 2, vec![2u8, 1u8, 0u8, 12u8, 11u8, 10u8]).unwrap(); |
357 | | |
358 | | flip_horizontal_in_place(&mut image); |
359 | | |
360 | | assert_pixels_eq!(&image, &expected); |
361 | | } |
362 | | |
363 | | #[test] |
364 | | fn test_flip_vertical_in_place() { |
365 | | let mut image: GrayImage = |
366 | | ImageBuffer::from_raw(3, 2, vec![0u8, 1u8, 2u8, 10u8, 11u8, 12u8]).unwrap(); |
367 | | |
368 | | let expected: GrayImage = |
369 | | ImageBuffer::from_raw(3, 2, vec![10u8, 11u8, 12u8, 0u8, 1u8, 2u8]).unwrap(); |
370 | | |
371 | | flip_vertical_in_place(&mut image); |
372 | | |
373 | | assert_pixels_eq!(&image, &expected); |
374 | | } |
375 | | |
376 | | #[allow(clippy::type_complexity)] |
377 | | fn pixel_diffs<I, J, P>(left: &I, right: &J) -> Vec<((u32, u32, P), (u32, u32, P))> |
378 | | where |
379 | | I: GenericImage<Pixel = P>, |
380 | | J: GenericImage<Pixel = P>, |
381 | | P: Pixel + Eq, |
382 | | { |
383 | | left.pixels() |
384 | | .zip(right.pixels()) |
385 | | .filter(|&(p, q)| p != q) |
386 | | .collect::<Vec<_>>() |
387 | | } |
388 | | } |