mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-08 18:11:52 +00:00
LibWeb: Use bitmap's alpha type instead of assuming unpremultiplied
When converting a `Gfx::Bitmap` to a Skia bitmap, we cannot assume the color data is unpremultiplied. For example, everything canvas-related uses premultiplied color data: https://html.spec.whatwg.org/multipage/canvas.html#premultiplied-alpha-and-the-2d-rendering-context We were probably assuming unpremultiplied since that is what the PNG decoder gives us. Since we now make `Gfx::Bitmap` identify what alpha type is being used, we can instruct Skia a bit better :^) Update our `EdgeFlagPathRasterizer` to use premultiplied alpha instead of unpremultiplied so we can apply alpha correctly for path masks. This fixes the dark borders sometimes visible when SVGs are blended with a colored background. This also exposed an issue with our `CanvasRenderingContext2D`, which is supposed to hold a bitmap with premultiplied alpha internally but expose a bitmap with unpremultiplied alpha in `CanvasImageData`. Expand our C2D test to include the alpha channel as well. Finally, this also exposed an off-by-one issue in `EdgeFlagPathRasterizer` which caused the last scanlines for edges to render incorrectly. We had some reference images which included these corruptions (they were almost unnoticeable), so update them as well.
This commit is contained in:
parent
a430ae6dcf
commit
5865cf5864
Notes:
github-actions[bot]
2024-08-07 18:16:57 +00:00
Author: https://github.com/gmta
Commit: 5865cf5864
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/999
12 changed files with 29 additions and 13 deletions
|
@ -30,7 +30,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ImageData>> ImageData::create(JS::Realm& re
|
|||
// 2. Initialize this given sw, sh, and settings set to settings.
|
||||
// 3. Initialize the image data of this to transparent black.
|
||||
auto data = TRY(JS::Uint8ClampedArray::create(realm, sw * sh * 4));
|
||||
auto bitmap = TRY_OR_THROW_OOM(vm, Gfx::Bitmap::create_wrapper(Gfx::BitmapFormat::RGBA8888, Gfx::AlphaType::Premultiplied, Gfx::IntSize(sw, sh), sw * sizeof(u32), data->data().data()));
|
||||
auto bitmap = TRY_OR_THROW_OOM(vm, Gfx::Bitmap::create_wrapper(Gfx::BitmapFormat::RGBA8888, Gfx::AlphaType::Unpremultiplied, Gfx::IntSize(sw, sh), sw * sizeof(u32), data->data().data()));
|
||||
|
||||
return realm.heap().allocate<ImageData>(realm, realm, bitmap, data);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue