Skip to content

Commit

Permalink
Merge pull request #513 from Brooooooklyn/fix-image-smooth
Browse files Browse the repository at this point in the history
fix: miss applying image_smoothing_enabled and image_smoothing_quality
  • Loading branch information
Brooooooklyn authored Aug 5, 2022
2 parents 110606b + 20b1b02 commit 0e73a98
Show file tree
Hide file tree
Showing 44 changed files with 68 additions and 20 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@ jobs:
export CFLAGS="-isysroot $SYSROOT -isystem $SYSROOT";
yarn build --target aarch64-apple-darwin
strip -x skia.darwin-arm64.node
- host: ubuntu-18.04
- host: ubuntu-latest
downloadTarget: 'aarch64-unknown-linux-gnu'
target: 'aarch64-unknown-linux-gnu'
setup: |
sudo apt-get update
sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu -y
docker: |
docker pull ghcr.io/brooooooklyn/canvas/ubuntu-builder:focal-aarch64
docker tag ghcr.io/brooooooklyn/canvas/ubuntu-builder:focal-aarch64 builder
build: |
yarn build --target aarch64-unknown-linux-gnu
aarch64-linux-gnu-strip skia.linux-arm64-gnu.node
docker run --rm -v ~/.cargo/git:/usr/local/cargo/git -v ~/.cargo/registry:/usr/local/cargo/registry -v $(pwd):/canvas -w /canvas builder sh -c "rustup toolchain install $(cat ./rust-toolchain) && rustup target add aarch64-unknown-linux-gnu && yarn build --target aarch64-unknown-linux-gnu && llvm-strip-14 skia.linux-arm64-gnu.node"
- host: ubuntu-latest
target: 'aarch64-unknown-linux-musl'
downloadTarget: 'aarch64-unknown-linux-musl'
Expand Down
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.
8 changes: 0 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ fn main() {
build.cpp(true).file("skia-c/skia_c.cpp");

match compile_target.as_str() {
"aarch64-unknown-linux-gnu" => {
build
.flag("--sysroot=/usr/aarch64-linux-gnu")
.flag("--gcc-toolchain=aarch64-linux-gnu-gcc")
.include("/usr/aarch64-linux-gnu/include/c++/7")
.include("/usr/aarch64-linux-gnu/include/c++/7/aarch64-linux-gnu");
}
"aarch64-unknown-linux-musl" => {
let gcc_version = String::from_utf8(
process::Command::new("ls")
Expand Down Expand Up @@ -189,7 +182,6 @@ fn main() {
println!("cargo:rustc-link-search=/usr/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot/lib");
println!("cargo:rustc-link-search=/usr/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/4.8.5");
} else {
println!("cargo:rustc-link-lib=static=c++abi");
println!("cargo:rustc-link-search=/usr/lib/llvm-14/lib");
}
}
Expand Down
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 0e73a98

Please sign in to comment.