Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 8, 2025

WhatWG spec now defines ImageDataArray as Uint8ClampedArray | Uint16Array | Float32Array. This adds the missing types.

Changes

TypeScript definitions (index.d.ts)

  • Added Uint16Array | Float16Array | Float32Array to ImageData constructor signature
  • Float16Array included for forward compatibility (runtime support pending napi-rs)

Rust implementation (src/image.rs)

  • Changed constructor parameter from Either<u32, Uint8ClampedArray> to Either4<u32, Uint8ClampedArray, Uint16Array, Float32Array>
  • Uint16Array: Scale 16-bit (0-65535) → 8-bit (0-255) using (val * 255 + 32767) / 65535
  • Float32Array: Clamp [0.0, 1.0] and scale to 8-bit using val.clamp(0.0, 1.0) * 255
  • Both convert to Uint8ClampedArray internally, preserving existing behavior

Tests (__test__/image-data.spec.ts)

  • Coverage for both array types with/without explicit height parameter
  • Edge case validation (clamping, boundary values, scaling accuracy)

Usage

// Now supported alongside Uint8ClampedArray
const u16Data = new Uint16Array(width * height * 4);
const imageData = new ImageData(u16Data, width, height);

const f32Data = new Float32Array(width * height * 4).fill(0.5);
const imageData2 = new ImageData(f32Data, width, height);

Refs: WhatWG ImageDataArray spec

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • chromium.googlesource.com
    • Triggering command: /home/REDACTED/.rustup/toolchains/1.90.0-x86_64-REDACTED-linux-gnu/bin/cargo metadata --format-version 1 --all-features --manifest-path /home/REDACTED/work/canvas/canvas/skia/bazel/external/icu4x/Cargo.toml --filter-platform x86_64-REDACTED-linux-gnu --lockfile-path /tmp/rust-analyzer3e3a-0/Cargo.lock -Zunstable-options (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Add Float16Array to ImageData constructor</issue_title>
<issue_description>The ImageData constructor now accepts a Float16Array as a data type for the data, this should be added here as well.

References

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add Float16Array support to ImageData constructor Add Uint16Array and Float32Array support to ImageData constructor Nov 8, 2025
Copilot AI requested a review from Brooooooklyn November 8, 2025 13:43
@Brooooooklyn Brooooooklyn marked this pull request as ready for review November 8, 2025 16:21
@Brooooooklyn Brooooooklyn changed the title Add Uint16Array and Float32Array support to ImageData constructor feat: add Uint16Array and Float32Array support to ImageData constructor Nov 8, 2025
@Brooooooklyn Brooooooklyn merged commit b6fc7d8 into main Nov 8, 2025
38 of 58 checks passed
@Brooooooklyn Brooooooklyn deleted the copilot/add-float16array-to-imagedata branch November 8, 2025 16:21
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.

Add Float16Array to ImageData constructor

2 participants