Skip to content

Commit

Permalink
fix: parameters for drawImage(canvas)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Jun 29, 2022
1 parent f13c1a3 commit 2392263
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ impl Context {

pub(crate) fn draw_image(
&mut self,
image: &Image,
bitmap: &Bitmap,
sx: f32,
sy: f32,
s_width: f32,
Expand All @@ -697,7 +697,7 @@ impl Context {
d_width: f32,
d_height: f32,
) -> Result<()> {
let bitmap = image.bitmap.as_ref().unwrap().0.bitmap;
let bitmap = bitmap.0.bitmap;
let paint = self.fill_paint()?;
if let Some(drop_shadow_paint) = self.drop_shadow_paint(&paint) {
let surface = &mut self.surface;
Expand Down Expand Up @@ -1099,22 +1099,23 @@ fn draw_image(ctx: CallContext) -> Result<JsUndefined> {
return ctx.env.get_undefined();
}

let image_w = image.bitmap.as_ref().unwrap().0.width as f32;
let image_h = image.bitmap.as_ref().unwrap().0.height as f32;
let bitmap = image.bitmap.as_ref().unwrap();
let image_w = bitmap.0.width as f32;
let image_h = bitmap.0.height as f32;

if ctx.length == 3 {
let dx: f64 = ctx.get::<JsNumber>(1)?.get_double()?;
let dy: f64 = ctx.get::<JsNumber>(2)?.get_double()?;
context_2d.draw_image(
image, 0f32, 0f32, image_w, image_h, dx as f32, dy as f32, image_w, image_h,
bitmap, 0f32, 0f32, image_w, image_h, dx as f32, dy as f32, image_w, image_h,
)?;
} else if ctx.length == 5 {
let dx: f64 = ctx.get::<JsNumber>(1)?.get_double()?;
let dy: f64 = ctx.get::<JsNumber>(2)?.get_double()?;
let d_width: f64 = ctx.get::<JsNumber>(3)?.get_double()?;
let d_height: f64 = ctx.get::<JsNumber>(4)?.get_double()?;
context_2d.draw_image(
image,
bitmap,
0f32,
0f32,
image_w,
Expand All @@ -1134,7 +1135,7 @@ fn draw_image(ctx: CallContext) -> Result<JsUndefined> {
let d_width: f64 = ctx.get::<JsNumber>(7)?.get_double()?;
let d_height: f64 = ctx.get::<JsNumber>(8)?.get_double()?;
context_2d.draw_image(
image,
bitmap,
sx as f32,
sy as f32,
s_width as f32,
Expand All @@ -1158,11 +1159,11 @@ fn draw_image(ctx: CallContext) -> Result<JsUndefined> {
let dy = ctx.get::<JsNumber>(2)?.get_double()? as f32;
(0.0f32, 0.0f32, width, height, dx, dy, width, height)
} else if ctx.length == 5 {
let sx = ctx.get::<JsNumber>(1)?.get_double()? as f32;
let sy = ctx.get::<JsNumber>(2)?.get_double()? as f32;
let sw = ctx.get::<JsNumber>(3)?.get_double()? as f32;
let sh = ctx.get::<JsNumber>(4)?.get_double()? as f32;
(sx, sy, sw, sh, 0.0f32, 0.0f32, sw, sh)
let dx = ctx.get::<JsNumber>(1)?.get_double()? as f32;
let dy = ctx.get::<JsNumber>(2)?.get_double()? as f32;
let d_width = ctx.get::<JsNumber>(3)?.get_double()? as f32;
let d_height = ctx.get::<JsNumber>(4)?.get_double()? as f32;
(0.0, 0.0, width, height, dx, dy, d_width, d_height)
} else if ctx.length == 9 {
(
ctx.get::<JsNumber>(1)?.get_double()? as f32,
Expand All @@ -1181,8 +1182,8 @@ fn draw_image(ctx: CallContext) -> Result<JsUndefined> {
));
};

context_2d.surface.canvas.draw_surface_rect(
&another_ctx.surface,
context_2d.draw_image(
&another_ctx.surface.get_bitmap(),
sx,
sy,
sw,
Expand All @@ -1191,8 +1192,7 @@ fn draw_image(ctx: CallContext) -> Result<JsUndefined> {
dy,
dw,
dh,
FilterQuality::High,
);
)?;
}
};

Expand Down

1 comment on commit 2392263

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 2392263 Previous: 671c4b1 Ratio
Draw house#skia-canvas 22 ops/sec (±0.08%) 22 ops/sec (±0.12%) 1
Draw house#node-canvas 26 ops/sec (±0.73%) 26 ops/sec (±0.24%) 1
Draw house#@napi-rs/skia 23 ops/sec (±0.11%) 24 ops/sec (±0.13%) 1.04
Draw gradient#skia-canvas 21.5 ops/sec (±0.04%) 21 ops/sec (±0.05%) 0.98
Draw gradient#node-canvas 25 ops/sec (±0.37%) 25 ops/sec (±0.27%) 1
Draw gradient#@napi-rs/skia 22.2 ops/sec (±0.96%) 23 ops/sec (±0.5%) 1.04

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.