summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-09-30 16:39:43 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-09-30 16:51:42 +0700
commit2cc7e0a44901a46887b73d9e34d9b3dcc1de8580 (patch)
treeeaf443195fdce10e5c83389cd0e040876d8f705f /wgpu
parent60070eef274828ee4b65553c17d7bd14d2e39183 (diff)
downloadiced-2cc7e0a44901a46887b73d9e34d9b3dcc1de8580.tar.gz
iced-2cc7e0a44901a46887b73d9e34d9b3dcc1de8580.tar.bz2
iced-2cc7e0a44901a46887b73d9e34d9b3dcc1de8580.zip
Fix `Operation::perform` in `image::raster`
Flipping diagonally isn't the same as flipping each axis individually :sweat_smile:
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/image/raster.rs37
1 files changed, 31 insertions, 6 deletions
diff --git a/wgpu/src/image/raster.rs b/wgpu/src/image/raster.rs
index 318cefb6..e13987b4 100644
--- a/wgpu/src/image/raster.rs
+++ b/wgpu/src/image/raster.rs
@@ -175,16 +175,20 @@ impl Operation {
.unwrap_or_else(Self::empty))
}
- fn perform<I>(self, mut image: I) -> I
+ fn perform<P>(
+ self,
+ image: image_rs::ImageBuffer<P, Vec<P::Subpixel>>,
+ ) -> image_rs::ImageBuffer<P, Vec<P::Subpixel>>
where
- I: image_rs::GenericImage,
+ P: image_rs::Pixel + 'static,
{
use image_rs::imageops;
- if self.contains(Self::FLIP_DIAGONALLY) {
- imageops::flip_horizontal_in_place(&mut image);
- imageops::flip_vertical_in_place(&mut image);
- }
+ let mut image = if self.contains(Self::FLIP_DIAGONALLY) {
+ flip_diagonally(image)
+ } else {
+ image
+ };
if self.contains(Self::ROTATE_180) {
imageops::rotate180_in_place(&mut image);
@@ -197,3 +201,24 @@ impl Operation {
image
}
}
+
+fn flip_diagonally<I>(
+ image: I,
+) -> image_rs::ImageBuffer<I::Pixel, Vec<<I::Pixel as image_rs::Pixel>::Subpixel>>
+where
+ I: image_rs::GenericImage,
+ I::Pixel: 'static,
+{
+ let (width, height) = image.dimensions();
+ let mut out = image_rs::ImageBuffer::new(height, width);
+
+ for x in 0..width {
+ for y in 0..height {
+ let p = image.get_pixel(x, y);
+
+ out.put_pixel(y, x, p);
+ }
+ }
+
+ out
+}