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(ext/canvas): enhance createImageBitmap specification compliance #25517

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

Hajime-san
Copy link
Contributor

@Hajime-san Hajime-san commented Sep 8, 2024

Feature

basic support for decoding image format

  • jpeg, png, gif, bmp, ico, webp
    • animated image
    • 16-bit image
    • Grayscale image

support colorSpace for ImageData

There can convert color space from srgb to display-p3 with createImageBitmap.

This was a misunderstanding on my part, so I reverted it.
The conversion using the ImageData colorSpace option was probably the responsibility of CanvasRenderingContext2D.
I've left the implementation commented out as it may be useful as a reference for implementing CanvasRenderingContext2D or OffscreenCanvasRenderingContext2D.

support colorSpaceConversion option

The specifications are not particularly clear about the implementation details, and I had a hard time understanding its behavior, but I eventually do reverse engineering the results of wpt and implemented it to be consistent with those results.

port to Rust

To simplify code, almost logic moved to Rust side.

added a simple architecture document for README

It is basically based on the image implementation, and I wrote roughly how you can handle data effectively.

performance impact

I was curious to see if the increased amount of Rust code, especially static dispatch, was affecting the bootstrap time of the runtime.
I'm not very confident about the suitability of this benchmark, but it may not have had a big impact.

Deno.bench("bootstrap time", () => {
  null
})
Deno.bench("createImageBitmap", async () => {
  const imageData = new ImageData(new Uint8ClampedArray([255, 0, 0, 255]), 1, 1);
  await createImageBitmap(imageData);
})
% target/release/deno bench bench.ts
Check file:///path/to/deno/bench.ts
    CPU | Apple M1
Runtime | Deno 2.0.0-rc.1 (aarch64-apple-darwin)

file:///path/to/deno/bench.ts

benchmark           time/iter (avg)        iter/s      (min … max)           p75      p99     p995
------------------- ----------------------------- --------------------- --------------------------
bootstrap time               4.3 ns   232,900,000 (  3.9 ns …   1.0 µs)   4.1 ns   7.3 ns  10.2 ns
createImageBitmap            6.8 µs       146,300 (  5.0 µs …  26.4 ms)   5.6 µs  19.8 µs  26.4 µs
% target/release/deno bench bench.ts  
Check file:///path/to/deno/bench.ts
    CPU | Apple M1
Runtime | Deno 1.46.1 (aarch64-apple-darwin)

file:///path/to/deno/bench.ts

benchmark           time/iter (avg)        iter/s      (min … max)           p75      p99     p995
------------------- ----------------------------- --------------------- --------------------------
bootstrap time               4.9 ns   205,300,000 (  4.2 ns … 101.1 ns)   4.3 ns  11.0 ns  13.5 ns
createImageBitmap            4.6 µs       218,000 (  4.4 µs …   5.0 µs)   4.6 µs   5.0 µs   5.0 µs

plans for enhancement in another PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant