diff options
Diffstat (limited to 'components/canvas/canvas_data.rs')
-rw-r--r-- | components/canvas/canvas_data.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs index 778851524ba..38d84f2d00c 100644 --- a/components/canvas/canvas_data.rs +++ b/components/canvas/canvas_data.rs @@ -446,11 +446,12 @@ impl<'a> CanvasData<'a> { pub fn draw_image( &mut self, - image_data: Vec<u8>, + image_data: &[u8], image_size: Size2D<f64>, dest_rect: Rect<f64>, source_rect: Rect<f64>, smoothing_enabled: bool, + premultiply: bool, ) { // We round up the floating pixel values to draw the pixels let source_rect = source_rect.ceil(); @@ -469,6 +470,7 @@ impl<'a> CanvasData<'a> { source_rect.size, dest_rect, smoothing_enabled, + premultiply, &draw_options, ); }; @@ -1306,17 +1308,24 @@ pub struct CanvasPaintState<'a> { /// image_size: The size of the image to be written /// dest_rect: Area of the destination target where the pixels will be copied /// smoothing_enabled: It determines if smoothing is applied to the image result +/// premultiply: Determines whenever the image data should be premultiplied or not fn write_image( draw_target: &mut dyn GenericDrawTarget, - image_data: Vec<u8>, + mut image_data: Vec<u8>, image_size: Size2D<f64>, dest_rect: Rect<f64>, smoothing_enabled: bool, + premultiply: bool, draw_options: &DrawOptions, ) { if image_data.is_empty() { return; } + + if premultiply { + pixels::rgba8_premultiply_inplace(&mut image_data); + } + let image_rect = Rect::new(Point2D::zero(), image_size); // From spec https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage |