summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2024-01-22 12:08:01 +0100
committerGitHub <noreply@github.com>2024-01-22 12:08:01 +0100
commit8f767627938ef10802864419061e58a8a75db567 (patch)
tree81f61ba0f8c14fb820a72500840eb0c619d54362 /cli
parentb4990d1aa233db662cf22d7f872d45b3a947e0f6 (diff)
feat(web): ImageBitmap (#21898)
Diffstat (limited to 'cli')
-rw-r--r--cli/build.rs1
-rw-r--r--cli/tests/integration/js_unit_tests.rs1
-rw-r--r--cli/tests/node_compat/test/common/index.js1
-rw-r--r--cli/tests/unit/image_bitmap_test.ts92
-rw-r--r--cli/tsc/dts/lib.deno.shared_globals.d.ts2
-rw-r--r--cli/tsc/dts/lib.deno.window.d.ts1
-rw-r--r--cli/tsc/mod.rs1
7 files changed, 98 insertions, 1 deletions
diff --git a/cli/build.rs b/cli/build.rs
index d3f428c50..5fd6ca4d5 100644
--- a/cli/build.rs
+++ b/cli/build.rs
@@ -152,6 +152,7 @@ mod ts {
op_crate_libs.insert("deno.webgpu", deno_webgpu_get_declaration());
op_crate_libs.insert("deno.websocket", deno_websocket::get_declaration());
op_crate_libs.insert("deno.webstorage", deno_webstorage::get_declaration());
+ op_crate_libs.insert("deno.canvas", deno_canvas::get_declaration());
op_crate_libs.insert("deno.crypto", deno_crypto::get_declaration());
op_crate_libs.insert(
"deno.broadcast_channel",
diff --git a/cli/tests/integration/js_unit_tests.rs b/cli/tests/integration/js_unit_tests.rs
index 8fbeb61e1..7680ee7a1 100644
--- a/cli/tests/integration/js_unit_tests.rs
+++ b/cli/tests/integration/js_unit_tests.rs
@@ -42,6 +42,7 @@ util::unit_test_factory!(
globals_test,
headers_test,
http_test,
+ image_bitmap_test,
image_data_test,
internals_test,
intl_test,
diff --git a/cli/tests/node_compat/test/common/index.js b/cli/tests/node_compat/test/common/index.js
index 986b8ea1a..9f5b4814c 100644
--- a/cli/tests/node_compat/test/common/index.js
+++ b/cli/tests/node_compat/test/common/index.js
@@ -34,6 +34,7 @@ let knownGlobals = [
closed,
confirm,
console,
+ createImageBitmap,
crypto,
Deno,
dispatchEvent,
diff --git a/cli/tests/unit/image_bitmap_test.ts b/cli/tests/unit/image_bitmap_test.ts
new file mode 100644
index 000000000..364f2a167
--- /dev/null
+++ b/cli/tests/unit/image_bitmap_test.ts
@@ -0,0 +1,92 @@
+// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+
+import { assertEquals } from "./test_util.ts";
+
+function generateNumberedData(n: number): Uint8ClampedArray {
+ return new Uint8ClampedArray(
+ Array.from({ length: n }, (_, i) => [i + 1, 0, 0, 1]).flat(),
+ );
+}
+
+Deno.test(async function imageBitmapDirect() {
+ const data = generateNumberedData(3);
+ const imageData = new ImageData(data, 3, 1);
+ const imageBitmap = await createImageBitmap(imageData);
+ assertEquals(
+ // @ts-ignore: Deno[Deno.internal].core allowed
+ Deno[Deno.internal].getBitmapData(imageBitmap),
+ new Uint8Array(data.buffer),
+ );
+});
+
+Deno.test(async function imageBitmapCrop() {
+ const data = generateNumberedData(3 * 3);
+ const imageData = new ImageData(data, 3, 3);
+ const imageBitmap = await createImageBitmap(imageData, 1, 1, 1, 1);
+ assertEquals(
+ // @ts-ignore: Deno[Deno.internal].core allowed
+ Deno[Deno.internal].getBitmapData(imageBitmap),
+ new Uint8Array([5, 0, 0, 1]),
+ );
+});
+
+Deno.test(async function imageBitmapCropPartialNegative() {
+ const data = generateNumberedData(3 * 3);
+ const imageData = new ImageData(data, 3, 3);
+ const imageBitmap = await createImageBitmap(imageData, -1, -1, 2, 2);
+ // @ts-ignore: Deno[Deno.internal].core allowed
+ // deno-fmt-ignore
+ assertEquals(Deno[Deno.internal].getBitmapData(imageBitmap), new Uint8Array([
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 1, 0, 0, 1
+ ]));
+});
+
+Deno.test(async function imageBitmapCropGreater() {
+ const data = generateNumberedData(3 * 3);
+ const imageData = new ImageData(data, 3, 3);
+ const imageBitmap = await createImageBitmap(imageData, -1, -1, 5, 5);
+ // @ts-ignore: Deno[Deno.internal].core allowed
+ // deno-fmt-ignore
+ assertEquals(Deno[Deno.internal].getBitmapData(imageBitmap), new Uint8Array([
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 1, 0, 0, 1, 2, 0, 0, 1, 3, 0, 0, 1, 0, 0, 0, 0,
+ 0, 0, 0, 0, 4, 0, 0, 1, 5, 0, 0, 1, 6, 0, 0, 1, 0, 0, 0, 0,
+ 0, 0, 0, 0, 7, 0, 0, 1, 8, 0, 0, 1, 9, 0, 0, 1, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ ]));
+});
+
+Deno.test(async function imageBitmapScale() {
+ const data = generateNumberedData(3);
+ const imageData = new ImageData(data, 3, 1);
+ const imageBitmap = await createImageBitmap(imageData, {
+ resizeHeight: 5,
+ resizeWidth: 5,
+ resizeQuality: "pixelated",
+ });
+ // @ts-ignore: Deno[Deno.internal].core allowed
+ // deno-fmt-ignore
+ assertEquals(Deno[Deno.internal].getBitmapData(imageBitmap), new Uint8Array([
+ 1, 0, 0, 1, 1, 0, 0, 1, 2, 0, 0, 1, 3, 0, 0, 1, 3, 0, 0, 1,
+ 1, 0, 0, 1, 1, 0, 0, 1, 2, 0, 0, 1, 3, 0, 0, 1, 3, 0, 0, 1,
+ 1, 0, 0, 1, 1, 0, 0, 1, 2, 0, 0, 1, 3, 0, 0, 1, 3, 0, 0, 1,
+ 1, 0, 0, 1, 1, 0, 0, 1, 2, 0, 0, 1, 3, 0, 0, 1, 3, 0, 0, 1,
+ 1, 0, 0, 1, 1, 0, 0, 1, 2, 0, 0, 1, 3, 0, 0, 1, 3, 0, 0, 1
+ ]));
+});
+
+Deno.test(async function imageBitmapFlipY() {
+ const data = generateNumberedData(9);
+ const imageData = new ImageData(data, 3, 3);
+ const imageBitmap = await createImageBitmap(imageData, {
+ imageOrientation: "flipY",
+ });
+ // @ts-ignore: Deno[Deno.internal].core allowed
+ // deno-fmt-ignore
+ assertEquals(Deno[Deno.internal].getBitmapData(imageBitmap), new Uint8Array([
+ 7, 0, 0, 1, 8, 0, 0, 1, 9, 0, 0, 1,
+ 4, 0, 0, 1, 5, 0, 0, 1, 6, 0, 0, 1,
+ 1, 0, 0, 1, 2, 0, 0, 1, 3, 0, 0, 1,
+ ]));
+});
diff --git a/cli/tsc/dts/lib.deno.shared_globals.d.ts b/cli/tsc/dts/lib.deno.shared_globals.d.ts
index f4d19c8e9..86bf8237e 100644
--- a/cli/tsc/dts/lib.deno.shared_globals.d.ts
+++ b/cli/tsc/dts/lib.deno.shared_globals.d.ts
@@ -8,6 +8,8 @@
/// <reference lib="deno.console" />
/// <reference lib="deno.url" />
/// <reference lib="deno.web" />
+/// <reference lib="deno.webgpu" />
+/// <reference lib="deno.canvas" />
/// <reference lib="deno.fetch" />
/// <reference lib="deno.websocket" />
/// <reference lib="deno.crypto" />
diff --git a/cli/tsc/dts/lib.deno.window.d.ts b/cli/tsc/dts/lib.deno.window.d.ts
index eaab7c3c2..83c385aa0 100644
--- a/cli/tsc/dts/lib.deno.window.d.ts
+++ b/cli/tsc/dts/lib.deno.window.d.ts
@@ -3,7 +3,6 @@
/// <reference no-default-lib="true" />
/// <reference lib="deno.ns" />
/// <reference lib="deno.shared_globals" />
-/// <reference lib="deno.webgpu" />
/// <reference lib="deno.webstorage" />
/// <reference lib="esnext" />
/// <reference lib="deno.cache" />
diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs
index 04450b8d0..4c7101d5c 100644
--- a/cli/tsc/mod.rs
+++ b/cli/tsc/mod.rs
@@ -94,6 +94,7 @@ pub fn get_types_declaration_file_text() -> String {
"deno.webgpu",
"deno.websocket",
"deno.webstorage",
+ "deno.canvas",
"deno.crypto",
"deno.broadcast_channel",
"deno.net",