@@ -23,7 +23,7 @@ use pathfinder_content::dash::OutlineDash;
23
23
use pathfinder_content:: effects:: { BlendMode , BlurDirection , PatternFilter } ;
24
24
use pathfinder_content:: gradient:: Gradient ;
25
25
use pathfinder_content:: outline:: { Contour , Outline } ;
26
- use pathfinder_content:: pattern:: Pattern ;
26
+ use pathfinder_content:: pattern:: { Image , Pattern } ;
27
27
use pathfinder_content:: render_target:: RenderTargetId ;
28
28
use pathfinder_content:: stroke:: { LineJoin as StrokeLineJoin } ;
29
29
use pathfinder_content:: stroke:: { OutlineStrokeToFill , StrokeStyle } ;
@@ -562,6 +562,18 @@ impl CanvasRenderingContext2D {
562
562
self . current_state . fill_paint = old_fill_paint;
563
563
}
564
564
565
+ // Pixel manipulation
566
+
567
+ pub fn put_image_data < L > ( & mut self , image_data : ImageData , dest_location : L )
568
+ where L : CanvasImageDestLocation {
569
+ let origin = dest_location. origin ( ) ;
570
+ let size = dest_location. size ( ) . unwrap_or ( image_data. size . to_f32 ( ) ) ;
571
+ let pattern = Pattern :: from_image ( image_data. into_image ( ) ) ;
572
+ let paint_id = self . canvas . scene . push_paint ( & Paint :: from_pattern ( pattern) ) ;
573
+ let draw_path = DrawPath :: new ( Outline :: from_rect ( RectF :: new ( origin, size) ) , paint_id) ;
574
+ self . canvas . scene . push_draw_path ( draw_path) ;
575
+ }
576
+
565
577
// Image smoothing
566
578
567
579
#[ inline]
@@ -985,6 +997,23 @@ impl CanvasImageDestLocation for Vector2F {
985
997
}
986
998
}
987
999
1000
+ pub struct ImageData {
1001
+ pub data : Vec < ColorU > ,
1002
+ pub size : Vector2I ,
1003
+ }
1004
+
1005
+ impl ImageData {
1006
+ #[ inline]
1007
+ pub fn new ( size : Vector2I ) -> ImageData {
1008
+ ImageData { data : vec ! [ ColorU :: transparent_black( ) ; size. area( ) as usize ] , size }
1009
+ }
1010
+
1011
+ #[ inline]
1012
+ pub fn into_image ( self ) -> Image {
1013
+ Image :: new ( self . size , Arc :: new ( self . data ) )
1014
+ }
1015
+ }
1016
+
988
1017
impl Debug for Path2D {
989
1018
fn fmt ( & self , formatter : & mut Formatter ) -> Result < ( ) , FmtError > {
990
1019
self . clone ( ) . into_outline ( ) . fmt ( formatter)
0 commit comments