Skip to content

fix(🐛): ImageBitmap alpha and options - #434

Merged
wcandillon merged 6 commits into
mainfrom
test/image-bitmap-suite
Jul 25, 2026
Merged

fix(🐛): ImageBitmap alpha and options#434
wcandillon merged 6 commits into
mainfrom
test/image-bitmap-suite

Conversation

@wcandillon

@wcandillon wcandillon commented Jul 24, 2026

Copy link
Copy Markdown
Owner

fixes #432

Two snapshot-based suites covering createImageBitmap and copyExternalImageToTexture, with baselines validated against Chrome (yarn test:ref) and the dawn.node client (yarn test:node):

setup.ts: the node client polyfills now implement premultiplyAlpha, crop, bilinear resize, flipY orientation, close(), and alpha-aware copyExternalImageToTexture with the same integer math as the native ImageBitmap, so reference results can be generated and cross-checked locally.

wcandillon and others added 4 commits July 24, 2026 14:00
Two snapshot-based suites covering createImageBitmap and
copyExternalImageToTexture, with baselines validated against Chrome
(yarn test:ref) and the dawn.node client (yarn test:node):

- ImageBitmapAlpha.spec.ts: full matrix of premultiplyAlpha x
  destination premultipliedAlpha x flipY, over both the blob and the
  ArrayBuffer overload, plus exact-value checks where losslessness is
  guaranteed. The alpha baselines encode the reference integer
  conversion math; native platforms pass once straight-alpha support
  lands (issue #432 / PR #433).
- ImageBitmapOptions.spec.ts: crop-rect overload, resizeWidth/Height,
  imageOrientation, and colorSpaceConversion (Display-P3 fixture
  generated by Chrome). Native currently ignores these options, so on
  iOS/Android each case asserts today's identity behavior and flips to
  the reference snapshot once the option is implemented.

setup.ts: the node client polyfills now implement premultiplyAlpha,
crop, bilinear resize, flipY orientation, close(), and alpha-aware
copyExternalImageToTexture with the same integer math as the native
ImageBitmap, so reference results can be generated and cross-checked
locally.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…remultipliedAlpha

createImageBitmap ignored the premultiplyAlpha option and
copyExternalImageToTexture ignored the destination's premultipliedAlpha,
so an ImageBitmap always came through premultiplied regardless of what
was requested. This diverged from the web API and failed the new
ImageBitmapAlpha suite on device.

- Track the alpha representation on ImageData (premultiplied flag) and
  expose it on ImageBitmap.
- Add a shared convertAlpha helper that matches the reference client's
  integer rounding, so native results stay bit-exact with dawn.node.
- Parse premultiplyAlpha (from both the (source, options) and crop-rect
  overloads) and convert the decoded pixels to the requested
  representation before wrapping them in an ImageBitmap.
- Convert to the destination's premultipliedAlpha (default false) in
  copyExternalImageToTexture, composing with the existing flipY.
- Decode straight (non-premultiplied) RGBA on Apple via vImage so
  premultiplyAlpha "none" preserves the decoded bytes exactly;
  CGBitmapContext cannot target a non-premultiplied layout. Link
  Accelerate for vImage.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@wcandillon wcandillon changed the title test(🧪): add ImageBitmap alpha and options test suites fix(🐛): ImageBitmap alpha and options Jul 25, 2026
@wcandillon
wcandillon merged commit bc83857 into main Jul 25, 2026
2 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.6.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

createImageBitmap and copyExternalImageToTexture do not preserve alpha semantics on Apple platforms

1 participant