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

@ -195,6 +195,10 @@ impl Snapshot<Data> {
&self.data
}
pub fn data_mut(&mut self) -> &mut [u8] {
&mut self.data
}
/// Convert inner data of snapshot to target format and alpha mode.
/// If data is already in target format and alpha mode no work will be done.
pub fn transform(&mut self, target_alpha_mode: AlphaMode, target_format: PixelFormat) {