Skip to content

Commit e61a8eb

Browse files
authored
0.0.9 (#30)
* Support :blur :grayscale :brighten :invert in v-image (#29) * fix: v-image props into v-sk-image * chore: optimize doc and ci * feat: lock ci version of vue skia
1 parent 3c0d22b commit e61a8eb

File tree

13 files changed

+107
-21
lines changed

13 files changed

+107
-21
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,20 @@ jobs:
3333
- name: soft-skia-wasm
3434
run: |
3535
cargo install wasm-pack
36-
pnpm run build:wasm
36+
cd soft-skia-wasm
37+
wasm-pack build --release --target web
3738
3839
- name: vue-skia-framework
3940
run: |
4041
cd vue-skia-framework
4142
pnpm i
42-
cd ..
43-
pnpm run build:vue
43+
pnpm run build
4444
4545
- name: vue-playground
4646
run: |
4747
cd vue-playground
4848
pnpm i
49-
cd ..
50-
pnpm --filter vue-playground build
49+
pnpm run build
5150
5251
- name: Archive vue-skia-framework artifacts
5352
uses: actions/upload-artifact@v3

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,16 @@ $ wasm-pack build --release --target web
105105

106106
```shell
107107
$ cd vue-skia-framework
108-
$ npm i
109-
$ npm run build
108+
$ pnpm i
109+
$ pnpm run build
110+
```
111+
112+
#### Vue Playground Development
113+
114+
```shell
115+
$ cd vue-playground
116+
$ pnpm i
117+
$ pnpm run serve
110118
```
111119

112120
## License

package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
"name": "monorepo",
33
"version": "0.1.0",
44
"private": "true",
5-
"scripts": {
6-
"serve": "pnpm --filter vue-playground serve",
7-
"build": "pnpm build:wasm && pnpm build:vue",
8-
"build:vue": "pnpm --filter vue-skia build",
9-
"build:wasm": "cd soft-skia-wasm && wasm-pack build"
10-
},
5+
"scripts": {},
116
"packageManager": "[email protected]"
127
}

soft-skia-wasm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "soft-skia-wasm"
3-
version = "0.8.0"
3+
version = "0.9.0"
44
authors = ["meloalright <[email protected]>"]
55
edition = "2018"
66

soft-skia-wasm/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ pub struct WASMImageAttr {
9292
y: i32,
9393
width: u32,
9494
height: u32,
95+
blur: Option<f32>,
96+
grayscale: Option<bool>,
97+
brighten: Option<i32>,
98+
invert: Option<bool>,
9599
}
96100

97101
#[derive(Serialize, Deserialize, Debug)]
@@ -385,6 +389,10 @@ impl SoftSkiaWASM {
385389
image,
386390
width,
387391
height,
392+
blur,
393+
grayscale,
394+
brighten,
395+
invert,
388396
}) => self.0.set_shape_to_child(
389397
id,
390398
Shapes::I(Image {
@@ -393,6 +401,10 @@ impl SoftSkiaWASM {
393401
y,
394402
width,
395403
height,
404+
blur,
405+
grayscale,
406+
brighten,
407+
invert,
396408
}),
397409
),
398410
WASMShapesAttr::T(WASMTextAttr {

soft-skia/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "soft_skia"
3-
version = "0.8.0"
3+
version = "0.9.0"
44
edition = "2021"
55
description="software rasterization skia binding"
66
license = "MIT"
@@ -12,6 +12,7 @@ png = "0.17.5"
1212
tiny-skia = "0.10.0"
1313
base64 = "0.21.0"
1414
fontdue = "0.7.3"
15+
image = "0.25.1"
1516

1617
[dependencies.web-sys]
1718
version = "0.3"

soft-skia/src/shape.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use fontdue::{
77
use std::iter::zip;
88
pub use tiny_skia::{ColorU8, FillRule, Mask, Paint, PathBuilder, Pixmap, Stroke, Transform};
99
use tiny_skia::{LineCap, LineJoin, Path, PixmapPaint};
10+
use image::io::Reader as ImageReader;
11+
use std::io::Cursor;
1012

1113
#[derive(Debug)]
1214
pub enum Shapes {
@@ -112,6 +114,10 @@ pub struct Image {
112114
pub y: i32,
113115
pub width: u32,
114116
pub height: u32,
117+
pub blur: Option<f32>,
118+
pub grayscale: Option<bool>,
119+
pub brighten: Option<i32>,
120+
pub invert: Option<bool>,
115121
}
116122

117123
#[derive(Debug)]
@@ -509,7 +515,30 @@ impl Shape for Image {
509515

510516
fn draw(&self, pixmap: &mut Pixmap, context: &DrawContext) -> () {
511517
let u8_array = base64::decode(&self.image).expect("base64 decode failed");
512-
let p = Pixmap::decode_png(&u8_array).expect("decode png failed");
518+
let mut bytes: Vec<u8> = Vec::new();
519+
520+
let mut img = ImageReader::new(Cursor::new(&u8_array as &[u8])).with_guessed_format().unwrap().decode().unwrap();
521+
522+
if let Some(blur) = self.blur {
523+
img = img.blur(blur);
524+
}
525+
if let Some(grayscale) = self.grayscale {
526+
if grayscale {
527+
img = img.grayscale();
528+
}
529+
}
530+
if let Some(brighten) = self.brighten {
531+
img = img.brighten(brighten);
532+
}
533+
if let Some(invert) = self.invert {
534+
if invert {
535+
img.invert();
536+
}
537+
}
538+
539+
img.write_to(&mut Cursor::new(&mut bytes), image::ImageFormat::Png).unwrap();
540+
541+
let p = Pixmap::decode_png(&bytes).expect("decode png failed");
513542
let scale_x = self.width as f32 / p.width() as f32;
514543
let scale_y = self.height as f32 / p.height() as f32;
515544
pixmap.draw_pixmap(

vue-playground/package-ci.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-playground",
3-
"version": "0.8.0",
3+
"version": "0.9.0",
44
"private": true,
55
"scripts": {
66
"serve": "vue-cli-service serve",
@@ -14,7 +14,7 @@
1414
"prismjs": "^1.29.0",
1515
"vue": "^3.2.13",
1616
"vue-live": "^2.5.4",
17-
"vue-skia": "latest"
17+
"vue-skia": "0.0.9"
1818
},
1919
"devDependencies": {
2020
"@types/node": "^20.5.0",

vue-playground/src/App.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@
7373
:style="'fill'"
7474
>
7575
</v-rect>
76+
<v-image
77+
:x="30"
78+
:y="40"
79+
:image="'https://raw.githubusercontent.com/rustq/vue-skia/main/vue-playground/src/assets/logo.png'"
80+
:width="70"
81+
:height="70"
82+
v-bind:blur="10"
83+
:grayscale="false"
84+
:brighten="40"
85+
:invert="false"
86+
></v-image>
7687
<v-image
7788
:x="0"
7889
:y="0"

vue-playground/src/code.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ export default `<v-surface :width="360" :height="360">
1515
[98, 90],
1616
[138, 10],
1717
]" :style="'fill'" :strokeWidth="1" :color="'rgba(200, 255, 0, 0.7)'" />
18+
<v-image
19+
:x="30"
20+
:y="40"
21+
:image="'https://raw.githubusercontent.com/rustq/vue-skia/main/vue-playground/src/assets/logo.png'"
22+
:width="70"
23+
:height="70"
24+
v-bind:blur="10"
25+
:grayscale="false"
26+
:brighten="40"
27+
:invert="false"
28+
></v-image>
1829
<v-image
1930
:x="0"
2031
:y="0"

0 commit comments

Comments
 (0)