imagebitmap: Crop bitmap data with formatting (#37397)

Follow the ImageBitmap specification and make cropping of the bitmap
data to the source rectangle with formatting:
https://html.spec.whatwg.org/multipage/#cropped-to-the-source-rectangle-with-formatting

For now the next functionality not implemented:
- image orientation support (such as EXIF metadata)
- color space conversion (image, blob)

The convertion from ResizeQuality to "image" FilterType:
 - pixelated/low/medium/high -> Nearest/Triangle/CatmullRom/Lanczos3

Other browsers use the following sample filtering:
 - chromium (skia): Nearest/Linear/Linear/CatmullRom
 - firefox (skia): Lanczos3

Testing: Improvements in the following WPT tests
 - html/canvas/element/manual/imagebitmap/*

Fixes (partially): #34112

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
This commit is contained in:
Andrei Volykhin 2025-06-16 15:09:04 +03:00 committed by GitHub
parent 0f61361e27
commit bcade589e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 441 additions and 164 deletions

View file

@ -1,16 +1,4 @@
[canvas-createImageBitmap-resize.html]
[createImageBitmap from an ImageData with resize option.]
expected: FAIL
[createImageBitmap from a HTMLImageElement with resize option.]
expected: FAIL
[createImageBitmap from a HTMLCanvasElement with resize option.]
expected: FAIL
[createImageBitmap from an ImageBitmap with resize option.]
expected: FAIL
[createImageBitmap from a Blob with resize option.]
expected: FAIL

View file

@ -1,12 +0,0 @@
[createImageBitmap-bounds.html]
[simple clip inside]
expected: FAIL
[clip outside negative]
expected: FAIL
[clip outside positive]
expected: FAIL
[clip inside using negative width and height]
expected: FAIL

View file

@ -1,40 +1,22 @@
[createImageBitmap-drawImage.html]
[createImageBitmap from an OffscreenCanvas resized, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a vector HTMLImageElement resized, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a bitmap HTMLImageElement resized, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an HTMLVideoElement, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an HTMLVideoElement from a data URL scaled down, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an ImageData scaled down, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an OffscreenCanvas scaled down, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a bitmap SVGImageElement, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a bitmap SVGImageElement resized, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an HTMLCanvasElement scaled down, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a vector SVGImageElement, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an ImageData scaled up, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an HTMLVideoElement with negative sw/sh, and drawImage on the created ImageBitmap]
expected: FAIL
@ -44,18 +26,12 @@
[createImageBitmap from a vector SVGImageElement resized, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a bitmap HTMLImageElement scaled up, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a vector SVGImageElement scaled down, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a vector SVGImageElement with negative sw/sh, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a bitmap HTMLImageElement scaled down, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an HTMLVideoElement scaled down, and drawImage on the created ImageBitmap]
expected: FAIL
@ -65,9 +41,6 @@
[createImageBitmap from a Blob scaled down, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an ImageData resized, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a vector HTMLImageElement scaled down, and drawImage on the created ImageBitmap]
expected: FAIL
@ -86,9 +59,6 @@
[createImageBitmap from an HTMLVideoElement scaled up, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an HTMLCanvasElement resized, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a Blob, and drawImage on the created ImageBitmap]
expected: FAIL
@ -98,27 +68,12 @@
[createImageBitmap from an HTMLVideoElement from a data URL scaled up, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an ImageBitmap scaled down, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a Blob with negative sw/sh, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a bitmap SVGImageElement with negative sw/sh, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an ImageBitmap scaled up, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an ImageBitmap resized, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an OffscreenCanvas scaled up, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an HTMLCanvasElement scaled up, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a Blob resized, and drawImage on the created ImageBitmap]
expected: FAIL
@ -133,9 +88,3 @@
[createImageBitmap from a vector HTMLImageElement scaled up, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an ImageData, and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an ImageData with negative sw/sh, and drawImage on the created ImageBitmap]
expected: FAIL

View file

@ -1,16 +1,7 @@
[createImageBitmap-flipY.html]
[createImageBitmap from a vector SVGImageElement imageOrientation: "none", and drawImage on the created ImageBitmap]
expected: NOTRUN
[createImageBitmap from a vector SVGImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an HTMLCanvasElement imageOrientation: "none", and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an ImageData imageOrientation: "none", and drawImage on the created ImageBitmap]
expected: NOTRUN
[createImageBitmap from an HTMLVideoElement from a data URL imageOrientation: "flipY", and drawImage on the created ImageBitmap]
expected: FAIL
@ -23,33 +14,9 @@
[createImageBitmap from a Blob imageOrientation: "flipY", and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an HTMLVideoElement imageOrientation: "none", and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an OffscreenCanvas imageOrientation: "none", and drawImage on the created ImageBitmap]
expected: NOTRUN
[createImageBitmap from a vector HTMLImageElement imageOrientation: "none", and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a Blob imageOrientation: "none", and drawImage on the created ImageBitmap]
expected: NOTRUN
[createImageBitmap from an HTMLVideoElement from a data URL imageOrientation: "none", and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an ImageBitmap imageOrientation: "none", and drawImage on the created ImageBitmap]
expected: NOTRUN
[createImageBitmap from a bitmap HTMLImageElement imageOrientation: "none", and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a bitmap SVGImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a bitmap SVGImageElement imageOrientation: "none", and drawImage on the created ImageBitmap]
expected: TIMEOUT
[createImageBitmap from an HTMLVideoElement imageOrientation: "from-image", and drawImage on the created ImageBitmap]
expected: FAIL
@ -67,21 +34,3 @@
[createImageBitmap from a Blob imageOrientation: "from-image", and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an HTMLCanvasElement imageOrientation: "flipY", and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from a bitmap HTMLImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an OffscreenCanvas imageOrientation: "flipY", and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an ImageData imageOrientation: "from-image", and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an ImageData imageOrientation: "flipY", and drawImage on the created ImageBitmap]
expected: FAIL
[createImageBitmap from an ImageBitmap imageOrientation: "flipY", and drawImage on the created ImageBitmap]
expected: FAIL

View file

@ -47,20 +47,5 @@
[createImageBitmap with a vector SVGImageElement source and a value between 0 and 1 in resizeWidth]
expected: FAIL
[createImageBitmap with an HTMLCanvasElement source and oversized (unallocatable) crop region]
expected: FAIL
[createImageBitmap with a bitmap HTMLImageElement source and oversized (unallocatable) crop region]
expected: FAIL
[createImageBitmap with an OffscreenCanvas source and oversized (unallocatable) crop region]
expected: FAIL
[createImageBitmap with an ImageData source and oversized (unallocatable) crop region]
expected: FAIL
[createImageBitmap with an ImageBitmap source and oversized (unallocatable) crop region]
expected: FAIL
[createImageBitmap with a bitmap SVGImageElement source and a value between 0 and 1 in resizeWidth]
expected: FAIL

View file

@ -1,9 +1,9 @@
[createImageBitmap-premultiplyAlpha.html]
[createImageBitmap: from ImageData, unpremultiplied, drawn to canvas]
[createImageBitmap: from Canvas2D, unpremultiplied, drawn to canvas]
expected: FAIL
[createImageBitmap: from ImageData, premultiplied, drawn to canvas]
[createImageBitmap: from Canvas2D willReadFrequently:true, unpremultiplied, drawn to canvas]
expected: FAIL
[createImageBitmap: from ImageData, default, drawn to canvas]
[createImageBitmap: from Canvas2D willReadFrequently:false, unpremultiplied, drawn to canvas]
expected: FAIL

View file

@ -1,6 +0,0 @@
[createImageBitmap-sizeOverflow.html]
[createImageBitmap throws an InvalidStateError error with big imageBitmap scaled up in big height]
expected: FAIL
[createImageBitmap throws an InvalidStateError error with big imageBitmap scaled up in big width]
expected: FAIL