Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ByLCY authored Sep 5, 2024
2 parents ac375d2 + 49574ed commit f1ab8cf
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 23 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [0.1.55](https://github.com/Brooooooklyn/canvas/compare/v0.1.54...v0.1.55) (2024-09-04)


### Bug Fixes

* image src is null after loaded ([#886](https://github.com/Brooooooklyn/canvas/issues/886)) ([1628756](https://github.com/Brooooooklyn/canvas/commit/16287561a804fd065aa900996cc696d16cf3dd07))


### Features

* upgrade skia to m129 ([#888](https://github.com/Brooooooklyn/canvas/issues/888)) ([b103fc2](https://github.com/Brooooooklyn/canvas/commit/b103fc2bc77a54c12bb054dda6d8ec98f90af04b))



## [0.1.54](https://github.com/Brooooooklyn/canvas/compare/v0.1.53...v0.1.54) (2024-08-17)


Expand Down
2 changes: 1 addition & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# `skr canvas`

![CI](https://github.com/Brooooooklyn/canvas/workflows/CI/badge.svg)
![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm128-hotpink)
![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm129-hotpink)
[![install size](https://packagephobia.com/badge?p=@napi-rs/canvas)](https://packagephobia.com/result?p=@napi-rs/canvas)
[![Downloads](https://img.shields.io/npm/dm/@napi-rs/canvas.svg?sanitize=true)](https://npmcharts.com/compare/@napi-rs/canvas?minimal=true)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# `skr canvas`

![CI](https://github.com/Brooooooklyn/canvas/workflows/CI/badge.svg)
![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm128-hotpink)
![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm129-hotpink)
[![install size](https://packagephobia.com/badge?p=@napi-rs/canvas)](https://packagephobia.com/result?p=@napi-rs/canvas)
[![Downloads](https://img.shields.io/npm/dm/@napi-rs/canvas.svg?sanitize=true)](https://npmcharts.com/compare/@napi-rs/canvas?minimal=true)

Expand Down
2 changes: 1 addition & 1 deletion npm/android-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@napi-rs/canvas-android-arm64",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"android"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@napi-rs/canvas-darwin-arm64",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@napi-rs/canvas-darwin-x64",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-arm-gnueabihf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@napi-rs/canvas-linux-arm-gnueabihf",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@napi-rs/canvas-linux-arm64-gnu",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-arm64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@napi-rs/canvas-linux-arm64-musl",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@napi-rs/canvas-linux-x64-gnu",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-x64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@napi-rs/canvas-linux-x64-musl",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@napi-rs/canvas-win32-x64-msvc",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@napi-rs/canvas",
"version": "0.1.54",
"version": "0.1.55",
"description": "Canvas for Node.js with skia backend",
"main": "index.js",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-06-05"
channel = "nightly-2024-09-04"
profile = "default"
2 changes: 1 addition & 1 deletion skia
Submodule skia updated 1040 files
27 changes: 18 additions & 9 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl Image {
width: self.width,
height: self.height,
color_space: self.color_space,
data,
data: Some(data),
this_ref: env.create_reference(&this)?,
};
let task_output = env.spawn(decoder)?;
Expand Down Expand Up @@ -299,7 +299,7 @@ struct BitmapDecoder {
width: f64,
height: f64,
color_space: ColorSpace,
data: Uint8Array,
data: Option<Uint8Array>,
this_ref: Ref<()>,
}

Expand Down Expand Up @@ -329,8 +329,17 @@ impl Task for BitmapDecoder {
type JsValue = ();

fn compute(&mut self) -> Result<Self::Output> {
let length = self.data.len();
let data_ref: &[u8] = &self.data;
let data_ref = match self.data.as_ref() {
Some(data) => data.as_ref(),
None => {
return Ok(DecodedBitmap {
bitmap: DecodeStatus::Empty,
width: self.width,
height: self.height,
})
}
};
let length = data_ref.len();
let mut width = self.width;
let mut height = self.height;
let bitmap = if str::from_utf8(&data_ref[0..10]) == Ok("data:image") {
Expand All @@ -355,18 +364,18 @@ impl Task for BitmapDecoder {
} else {
DecodeStatus::Empty
}
} else if let Some(kind) = infer::get(&self.data)
} else if let Some(kind) = infer::get(data_ref)
&& kind.matcher_type() == infer::MatcherType::Image
{
DecodeStatus::Ok(BitmapInfo {
data: Bitmap::from_buffer(self.data.as_ptr().cast_mut(), length),
data: Bitmap::from_buffer(data_ref.as_ptr().cast_mut(), length),
is_svg: false,
})
} else if is_svg_image(data_ref, length) {
let font = get_font().map_err(SkError::from)?;
if (self.width - -1.0).abs() > f64::EPSILON && (self.height - -1.0).abs() > f64::EPSILON {
if let Some(bitmap) = Bitmap::from_svg_data_with_custom_size(
self.data.as_ptr(),
data_ref.as_ptr(),
length,
self.width as f32,
self.height as f32,
Expand All @@ -381,7 +390,7 @@ impl Task for BitmapDecoder {
DecodeStatus::InvalidSvg
}
} else if let Some(bitmap) =
Bitmap::from_svg_data(self.data.as_ptr(), length, self.color_space, &font)
Bitmap::from_svg_data(data_ref.as_ptr(), length, self.color_space, &font)
{
if let Ok(bitmap) = bitmap {
DecodeStatus::Ok(BitmapInfo {
Expand Down Expand Up @@ -426,11 +435,11 @@ impl Task for BitmapDecoder {
self_mut.complete = true;
match output.bitmap {
DecodeStatus::Ok(bitmap) => {
self_mut.src = self.data.take();
let onload = this.get_named_property_unchecked::<Unknown>("onload")?;
if onload.get_type()? == ValueType::Function {
let onload_func: Function<(), ()> = Function::from_unknown(onload)?;
onload_func.apply(this, ())?;
self_mut.src = Some(self.data.clone());
}
self_mut.is_svg = bitmap.is_svg;
self_mut.bitmap = Some(bitmap.data);
Expand Down

0 comments on commit f1ab8cf

Please sign in to comment.