Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): Add blur filter #1070

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/reason-skia/examples/skia-cli/SkiaCli.re
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ let draw = canvas => {

let fill3 = Paint.make();
Paint.setColor(fill3, Color.makeArgb(0xFFl, 0xFFl, 0xFFl, 0xFFl));
Paint.setTextSize(fill3, 30.);
Paint.setTextSize(fill3, 20.);

let nonExistentTypeface = Typeface.makeFromFile("non-existent-font.ttf", 0);
assert(nonExistentTypeface == None);
Expand All @@ -97,7 +97,18 @@ let draw = canvas => {
print_endline(__LOC__ ++ ": we will set.");
Paint.setTypeface(fill3, typeFace);
print_endline(__LOC__ ++ ": setTypeface is OK.");
Canvas.drawText(canvas, "Hello, world!", 30., 30., fill3);
Paint.setImageFilter(
fill3,
Some(ImageFilter.Blur.make(3., 3., None, None)),
);
let spreadX = 3.0;
let spreadY = 3.0;
Canvas.drawText(canvas, "Hello, world!", 150. -. spreadX, 50., fill3);
Canvas.drawText(canvas, "Hello, world!", 150. +. spreadX, 50., fill3);
Canvas.drawText(canvas, "Hello, world!", 150., 50. -. spreadY, fill3);
Canvas.drawText(canvas, "Hello, world!", 150., 50. +. spreadY, fill3);
Paint.setImageFilter(fill3, None);
Canvas.drawText(canvas, "Hello, world!", 150., 50., fill3);
let metrics = FontMetrics.make();
let _ret: float = Paint.getFontMetrics(fill3, metrics, 1.0);

Expand Down
14 changes: 14 additions & 0 deletions packages/reason-skia/src/Skia.re
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ module ImageFilter = {
};
};

module Blur = {
let make = (~sigmaX, ~sigmaY, inputOption, cropRectOption) => {
let blurFilter =
SkiaWrapped.ImageFilter.Blur.allocate(
sigmaX,
sigmaY,
inputOption,
cropRectOption,
);
Gc.finalise(SkiaWrapped.ImageFilter.delete, blurFilter);
blurFilter;
};
};

let makeDropShadow = DropShadow.make;
};

Expand Down
5 changes: 5 additions & 0 deletions packages/reason-skia/src/Skia.rei
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ module ImageFilter: {
t;
};

module Blur: {
let make:
(~sigmaX: float, ~sigmaY: float, option(t), option(CropRect.t)) => t;
};

let makeDropShadow:
(
float,
Expand Down
12 changes: 12 additions & 0 deletions packages/reason-skia/src/wrapped/bindings/SkiaWrappedBindings.re
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ module M = (F: FOREIGN) => {
@-> returning(t),
);
};

module Blur = {
let allocate =
foreign(
"sk_imagefilter_new_blur",
float
@-> float
@-> ptr_opt(SkiaTypes.ImageFilter.t)
@-> ptr_opt(SkiaTypes.ImageFilter.CropRect.t)
@-> returning(t),
);
};
};

module Point = {
Expand Down