Skip to content

Commit

Permalink
fix: miss applying image_smoothing_enabled and image_smoothing_quality
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Aug 4, 2022
1 parent 110606b commit 815bc91
Show file tree
Hide file tree
Showing 42 changed files with 63 additions and 6 deletions.
2 changes: 1 addition & 1 deletion __test__/image-snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function snapshotImage<C>(
} catch {
existed = false
}
if (!existed) {
if (!existed || process.env.UPDATE_SNAPSHOT) {
await fs.writeFile(p, image)
t.pass()
} else {
Expand Down
Binary file modified __test__/snapshots/arc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/arcTo-colorful.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/arcTo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/avif-output.avif
Binary file not shown.
Binary file modified __test__/snapshots/bezierCurveTo-colorful.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/bezierCurveTo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/clearRect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/createRadialGradient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/draw-image-svg-noto-emoji.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/drawImage-another-Canvas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/drawImage-svg-resize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/drawImage-svg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/drawImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/ellipse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/fillText-COLRv1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/fillText.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/filter-blur.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/filter-brightness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/filter-combine-contrast-brightness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/filter-contrast-ff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/filter-contrast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/filter-drop-shadow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/filter-grayscale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/filter-hue-rotate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/filter-invert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/filter-opacity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/filter-saturate.png
Binary file modified __test__/snapshots/filter-save-restore.png
Binary file modified __test__/snapshots/filter-sepia.png
Binary file modified __test__/snapshots/quadraticCurveTo.png
Binary file modified __test__/snapshots/should draw img.jpg
Binary file modified __test__/snapshots/stroke-and-filling-jpeg.jpg
Binary file modified __test__/snapshots/strokeText.png
Binary file modified __test__/snapshots/svg-transparent-background.png
Binary file modified __test__/snapshots/transform-with-radial-gradient-x.png
Binary file modified __test__/snapshots/transform-with-radial-gradient.png
Binary file modified __test__/snapshots/webp-output.webp
Binary file not shown.
18 changes: 16 additions & 2 deletions skia-c/skia_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,26 @@ extern "C"
CANVAS_CAST->drawColor(SkColor4f{r, g, b, a});
}

void skiac_canvas_draw_image(skiac_canvas *c_canvas, skiac_bitmap *c_bitmap, float sx, float sy, float s_width, float s_height, float dx, float dy, float d_width, float d_height, skiac_paint *c_paint)
void skiac_canvas_draw_image(
skiac_canvas *c_canvas,
skiac_bitmap *c_bitmap,
float sx,
float sy,
float s_width,
float s_height,
float dx,
float dy,
float d_width,
float d_height,
bool enable_smoothing,
int filter_quality,
skiac_paint *c_paint)
{
const auto src_rect = SkRect::MakeXYWH(sx, sy, s_width, s_height);
const auto dst_rect = SkRect::MakeXYWH(dx, dy, d_width, d_height);
auto sk_image = SkImage::MakeFromBitmap(*BITMAP_CAST);
const auto sampling = SkSamplingOptions(SkCubicResampler::Mitchell());
auto fq = enable_smoothing ? filter_quality : 0;
const auto sampling = SamplingOptionsFromFQ(fq);
auto paint = reinterpret_cast<const SkPaint *>(c_paint);
CANVAS_CAST->drawImageRect(sk_image, src_rect, dst_rect, sampling, paint, SkCanvas::kFast_SrcRectConstraint);
}
Expand Down
15 changes: 14 additions & 1 deletion skia-c/skia_c.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,20 @@ extern "C"
skiac_transform skiac_canvas_get_total_transform(skiac_canvas *c_canvas);
skiac_matrix *skiac_canvas_get_total_transform_matrix(skiac_canvas *c_canvas);
void skiac_canvas_draw_color(skiac_canvas *c_canvas, float r, float g, float b, float a);
void skiac_canvas_draw_image(skiac_canvas *c_canvas, skiac_bitmap *c_bitmap, float sx, float sy, float s_width, float s_height, float dx, float dy, float d_width, float d_height, skiac_paint *c_paint);
void skiac_canvas_draw_image(
skiac_canvas *c_canvas,
skiac_bitmap *c_bitmap,
float sx,
float sy,
float s_width,
float s_height,
float dx,
float dy,
float d_width,
float d_height,
bool enable_smoothing,
int filter_quality,
skiac_paint *c_paint);
void skiac_canvas_draw_path(skiac_canvas *c_canvas, skiac_path *c_path, skiac_paint *c_paint);
void skiac_canvas_draw_rect(
skiac_canvas *c_canvas,
Expand Down
15 changes: 14 additions & 1 deletion src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,24 @@ impl Context {
dy,
d_width,
d_height,
self.state.image_smoothing_enabled,
self.state.image_smoothing_quality,
&drop_shadow_paint,
);
}
self.surface.canvas.draw_image(
bitmap, sx, sy, s_width, s_height, dx, dy, d_width, d_height, &paint,
bitmap,
sx,
sy,
s_width,
s_height,
dx,
dy,
d_width,
d_height,
self.state.image_smoothing_enabled,
self.state.image_smoothing_quality,
&paint,
);

Ok(())
Expand Down
19 changes: 18 additions & 1 deletion src/sk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ mod ffi {
dy: f32,
d_width: f32,
d_height: f32,
enable_smoothing: bool,
filter_quality: i32,
paint: *mut skiac_paint,
);

Expand Down Expand Up @@ -1251,6 +1253,7 @@ impl From<i32> for BlendMode {
}
}

#[repr(i32)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub enum FilterQuality {
None = 0,
Expand Down Expand Up @@ -1993,11 +1996,25 @@ impl Canvas {
dy: f32,
d_width: f32,
d_height: f32,
enable_smoothing: bool,
quality: FilterQuality,
paint: &Paint,
) {
unsafe {
ffi::skiac_canvas_draw_image(
self.0, image, sx, sy, s_width, s_height, dx, dy, d_width, d_height, paint.0,
self.0,
image,
sx,
sy,
s_width,
s_height,
dx,
dy,
d_width,
d_height,
enable_smoothing,
quality as i32,
paint.0,
);
}
}
Expand Down

0 comments on commit 815bc91

Please sign in to comment.