Skip to content

Commit

Permalink
fix: default value of FilterQuality in SamplingOptions should be high
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Aug 13, 2021
1 parent bf8388d commit 389aa26
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions __test__/draw.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ test('createConicGradient', async (t) => {

test('drawImage', async (t) => {
const { ctx } = t.context
const filePath = './snapshots/drawImage.png'
const filePath = './javascript.png'
const file = await promises.readFile(join(__dirname, filePath))
const image = new Image()
image.src = file
Expand Down Expand Up @@ -339,7 +339,7 @@ test('drawImage-svg-resize', async (t) => {
image.width = 100
image.height = 100
ctx.drawImage(image, 0, 0)
await snapshotImage(t, { canvas, ctx }, 'png', 0.1)
await snapshotImage(t, { canvas, ctx }, 'png', 0.2)
})

test.skip('drawImage-svg-with-css', async (t) => {
Expand Down
Binary file added __test__/javascript.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/fillText-AA.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-maxWidth.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 example/resize-svg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 7 additions & 6 deletions skia-c/skia_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ extern "C"
SkPaint paint;
paint.setAlpha(SK_AlphaOPAQUE);

const auto sampling = SkSamplingOptions();
const auto sampling = SkSamplingOptions(SkCubicResampler{1 / 3.0f, 1 / 3.0f});
// The original surface draws itself to the copy's canvas.
SURFACE_CAST->draw(copy->getCanvas(), -(SkScalar)x, -(SkScalar)y, sampling, &paint);

Expand Down Expand Up @@ -251,7 +251,7 @@ extern "C"
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();
const auto sampling = SkSamplingOptions(SkCubicResampler{1 / 3.0f, 1 / 3.0f});
auto paint = reinterpret_cast<const SkPaint *>(c_paint);
CANVAS_CAST->drawImageRect(sk_image, src_rect, dst_rect, sampling, paint, SkCanvas::kFast_SrcRectConstraint);
}
Expand Down Expand Up @@ -282,7 +282,8 @@ extern "C"
SkPaint paint;
paint.setAlpha(alpha);
paint.setBlendMode((SkBlendMode)blend_mode);
const auto sampling = SkSamplingOptions();
// Equal to SkSamplingOptions(SkFilterQuality::kHigh_SkFilterQuality)
const auto sampling = SkSamplingOptions(SkCubicResampler{1 / 3.0f, 1 / 3.0f});
CANVAS_CAST->drawImage(image, left, top, sampling, &paint);
}

Expand All @@ -296,7 +297,7 @@ extern "C"
SkPaint paint;
auto src = SkRect::MakeXYWH(0, 0, image->width(), image->height());
auto dst = SkRect::MakeXYWH(x, y, w, h);
const auto sampling = SkSamplingOptions();
const auto sampling = SkSamplingOptions(SkCubicResampler{1 / 3.0f, 1 / 3.0f});
CANVAS_CAST->drawImageRect(image, src, dst, sampling, &paint, SkCanvas::kFast_SrcRectConstraint);
}

Expand Down Expand Up @@ -475,7 +476,7 @@ extern "C"
auto image = SkImage::MakeRasterData(info, data, row_bytes);
auto src_rect = SkRect::MakeXYWH(dirty_x, dirty_y, dirty_width, dirty_height);
auto dst_rect = SkRect::MakeXYWH(x + dirty_x, y + dirty_y, dirty_width, dirty_height);
const auto sampling = SkSamplingOptions();
const auto sampling = SkSamplingOptions(SkCubicResampler{1 / 3.0f, 1 / 3.0f});
CANVAS_CAST->drawImageRect(image, src_rect, dst_rect, sampling, nullptr, SkCanvas::kFast_SrcRectConstraint);
}

Expand Down Expand Up @@ -986,7 +987,7 @@ extern "C"
{
auto skia_tile_mode = SkTileMode::kRepeat;
const auto ts = conv_from_transform(c_ts);
const auto sampling_options = new SkSamplingOptions();
const auto sampling_options = new SkSamplingOptions(SkCubicResampler{1 / 3.0f, 1 / 3.0f});
sk_sp<SkImage> image = SURFACE_CAST->makeImageSnapshot();
auto shader = image->makeShader(
skia_tile_mode,
Expand Down

1 comment on commit 389aa26

@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: 389aa26 Previous: ead9d75 Ratio
Draw house#skia-canvas 27 ops/sec (±0.49%) 20.1 ops/sec (±0.66%) 0.74
Draw house#node-canvas 23 ops/sec (±0.42%) 20.5 ops/sec (±1.29%) 0.89
Draw house#@napi-rs/skia 25 ops/sec (±0.68%) 21.5 ops/sec (±0.94%) 0.86
Draw gradient#skia-canvas 26 ops/sec (±0.26%) 19.1 ops/sec (±1.47%) 0.73
Draw gradient#node-canvas 22 ops/sec (±0.27%) 19.7 ops/sec (±1.28%) 0.90
Draw gradient#@napi-rs/skia 24 ops/sec (±0.09%) 20.4 ops/sec (±0.62%) 0.85

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

Please sign in to comment.