diff options
| author | 2024-05-03 07:31:34 +0200 | |
|---|---|---|
| committer | 2024-05-03 07:31:34 +0200 | |
| commit | 1cefe6be210cdae8c6769673e8d23c6781a988f1 (patch) | |
| tree | 7d4a383412e6bd69d0cc1b32f996ba7cf6ef892e /tiny_skia/src | |
| parent | fe240a93aacd15bd3fa75876054753a53bda9054 (diff) | |
| parent | 4010e3983d40e24a5d7b590d8fec9801651199ce (diff) | |
| download | iced-1cefe6be210cdae8c6769673e8d23c6781a988f1.tar.gz iced-1cefe6be210cdae8c6769673e8d23c6781a988f1.tar.bz2 iced-1cefe6be210cdae8c6769673e8d23c6781a988f1.zip | |
Merge pull request #2334 from DKolter/image-rotation
Adding feature: Image rotation
Diffstat (limited to 'tiny_skia/src')
| -rw-r--r-- | tiny_skia/src/engine.rs | 51 | ||||
| -rw-r--r-- | tiny_skia/src/layer.rs | 12 | ||||
| -rw-r--r-- | tiny_skia/src/lib.rs | 14 | ||||
| -rw-r--r-- | tiny_skia/src/vector.rs | 4 | 
4 files changed, 58 insertions, 23 deletions
| diff --git a/tiny_skia/src/engine.rs b/tiny_skia/src/engine.rs index fbca1274..e9935bdb 100644 --- a/tiny_skia/src/engine.rs +++ b/tiny_skia/src/engine.rs @@ -539,10 +539,10 @@ impl Engine {      pub fn draw_image(          &mut self,          image: &Image, -        _transformation: Transformation, -        _pixels: &mut tiny_skia::PixmapMut<'_>, -        _clip_mask: &mut tiny_skia::Mask, -        _clip_bounds: Rectangle, +        transformation: Transformation, +        pixels: &mut tiny_skia::PixmapMut<'_>, +        clip_mask: &mut tiny_skia::Mask, +        clip_bounds: Rectangle,      ) {          match image {              #[cfg(feature = "image")] @@ -550,22 +550,32 @@ impl Engine {                  handle,                  filter_method,                  bounds, +                rotation,              } => { -                let physical_bounds = *bounds * _transformation; +                let physical_bounds = *bounds * transformation; -                if !_clip_bounds.intersects(&physical_bounds) { +                if !clip_bounds.intersects(&physical_bounds) {                      return;                  } -                let clip_mask = (!physical_bounds.is_within(&_clip_bounds)) -                    .then_some(_clip_mask as &_); +                let clip_mask = (!physical_bounds.is_within(&clip_bounds)) +                    .then_some(clip_mask as &_); + +                let center = physical_bounds.center(); +                let radians = f32::from(*rotation); + +                let transform = into_transform(transformation).post_rotate_at( +                    radians.to_degrees(), +                    center.x, +                    center.y, +                );                  self.raster_pipeline.draw(                      handle,                      *filter_method,                      *bounds, -                    _pixels, -                    into_transform(_transformation), +                    pixels, +                    transform,                      clip_mask,                  );              } @@ -574,21 +584,32 @@ impl Engine {                  handle,                  color,                  bounds, +                rotation,              } => { -                let physical_bounds = *bounds * _transformation; +                let physical_bounds = *bounds * transformation; -                if !_clip_bounds.intersects(&physical_bounds) { +                if !clip_bounds.intersects(&physical_bounds) {                      return;                  } -                let clip_mask = (!physical_bounds.is_within(&_clip_bounds)) -                    .then_some(_clip_mask as &_); +                let clip_mask = (!physical_bounds.is_within(&clip_bounds)) +                    .then_some(clip_mask as &_); + +                let center = physical_bounds.center(); +                let radians = f32::from(*rotation); + +                let transform = into_transform(transformation).post_rotate_at( +                    radians.to_degrees(), +                    center.x, +                    center.y, +                );                  self.vector_pipeline.draw(                      handle,                      *color,                      physical_bounds, -                    _pixels, +                    pixels, +                    transform,                      clip_mask,                  );              } diff --git a/tiny_skia/src/layer.rs b/tiny_skia/src/layer.rs index 3e42e4aa..c907c93c 100644 --- a/tiny_skia/src/layer.rs +++ b/tiny_skia/src/layer.rs @@ -1,7 +1,7 @@ -use crate::core::image; -use crate::core::renderer::Quad; -use crate::core::svg; -use crate::core::{Background, Color, Point, Rectangle, Transformation}; +use crate::core::{ +    image, renderer::Quad, svg, Background, Color, Point, Radians, Rectangle, +    Transformation, +};  use crate::graphics::damage;  use crate::graphics::layer;  use crate::graphics::text::{Editor, Paragraph, Text}; @@ -121,11 +121,13 @@ impl Layer {          filter_method: image::FilterMethod,          bounds: Rectangle,          transformation: Transformation, +        rotation: Radians,      ) {          let image = Image::Raster {              handle,              filter_method,              bounds: bounds * transformation, +            rotation,          };          self.images.push(image); @@ -137,11 +139,13 @@ impl Layer {          color: Option<Color>,          bounds: Rectangle,          transformation: Transformation, +        rotation: Radians,      ) {          let svg = Image::Vector {              handle,              color,              bounds: bounds * transformation, +            rotation,          };          self.images.push(svg); diff --git a/tiny_skia/src/lib.rs b/tiny_skia/src/lib.rs index 4c2c9430..75aaaf92 100644 --- a/tiny_skia/src/lib.rs +++ b/tiny_skia/src/lib.rs @@ -29,7 +29,7 @@ pub use geometry::Geometry;  use crate::core::renderer;  use crate::core::{ -    Background, Color, Font, Pixels, Point, Rectangle, Transformation, +    Background, Color, Font, Pixels, Point, Radians, Rectangle, Transformation,  };  use crate::engine::Engine;  use crate::graphics::compositor; @@ -377,9 +377,16 @@ impl core::image::Renderer for Renderer {          handle: Self::Handle,          filter_method: core::image::FilterMethod,          bounds: Rectangle, +        rotation: Radians,      ) {          let (layer, transformation) = self.layers.current_mut(); -        layer.draw_image(handle, filter_method, bounds, transformation); +        layer.draw_image( +            handle, +            filter_method, +            bounds, +            transformation, +            rotation, +        );      }  } @@ -397,9 +404,10 @@ impl core::svg::Renderer for Renderer {          handle: core::svg::Handle,          color: Option<Color>,          bounds: Rectangle, +        rotation: Radians,      ) {          let (layer, transformation) = self.layers.current_mut(); -        layer.draw_svg(handle, color, bounds, transformation); +        layer.draw_svg(handle, color, bounds, transformation, rotation);      }  } diff --git a/tiny_skia/src/vector.rs b/tiny_skia/src/vector.rs index 5150cffe..8e3463f2 100644 --- a/tiny_skia/src/vector.rs +++ b/tiny_skia/src/vector.rs @@ -4,6 +4,7 @@ use crate::graphics::text;  use resvg::usvg::{self, TreeTextToPath};  use rustc_hash::{FxHashMap, FxHashSet}; +use tiny_skia::Transform;  use std::cell::RefCell;  use std::collections::hash_map; @@ -34,6 +35,7 @@ impl Pipeline {          color: Option<Color>,          bounds: Rectangle,          pixels: &mut tiny_skia::PixmapMut<'_>, +        transform: Transform,          clip_mask: Option<&tiny_skia::Mask>,      ) {          if let Some(image) = self.cache.borrow_mut().draw( @@ -46,7 +48,7 @@ impl Pipeline {                  bounds.y as i32,                  image,                  &tiny_skia::PixmapPaint::default(), -                tiny_skia::Transform::identity(), +                transform,                  clip_mask,              );          } | 
