LibWeb: Make new ImageData()
use unpremultiplied color data
This was already the case for `context.createImageData()`, but I forgot to do the same for `new ImageData()`. Add a regression test for both cases.
This commit is contained in:
parent
bd55e85027
commit
e926b4cbfb
Notes:
github-actions[bot]
2024-08-20 18:39:59 +00:00
Author: https://github.com/gmta Commit: https://github.com/LadybirdBrowser/ladybird/commit/e926b4cbfb6 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1134
3 changed files with 32 additions and 1 deletions
|
@ -0,0 +1,2 @@
|
|||
PASS
|
||||
PASS
|
|
@ -0,0 +1,29 @@
|
|||
<script src="../include.js"></script>
|
||||
<body><canvas id=c width=1 height=2></div>
|
||||
<script>
|
||||
test(() => {
|
||||
// Test createImageData + putImageData
|
||||
let ctx1 = c.getContext('2d');
|
||||
let img1 = ctx1.createImageData(1, 1);
|
||||
img1.data[0] = 50;
|
||||
img1.data[1] = 100;
|
||||
img1.data[2] = 200;
|
||||
img1.data[3] = 0;
|
||||
ctx1.putImageData(img1, 0, 0);
|
||||
let buf1 = ctx1.getImageData(0, 0, 1, 1);
|
||||
if (buf1.data[0] === 0 && buf1.data[1] === 0 && buf1.data[2] === 0 && buf1.data[3] === 0)
|
||||
println("PASS");
|
||||
else
|
||||
println("FAIL");
|
||||
|
||||
// Test new ImageData + putImageData
|
||||
let ctx2 = c.getContext('2d');
|
||||
let img2 = new ImageData(new Uint8ClampedArray([50, 100, 200, 0]), 1, 1);
|
||||
ctx2.putImageData(img2, 0, 0);
|
||||
let buf2 = ctx2.getImageData(0, 0, 1, 1);
|
||||
if (buf2.data[0] === 0 && buf2.data[1] === 0 && buf2.data[2] === 0 && buf2.data[3] === 0)
|
||||
println("PASS");
|
||||
else
|
||||
println("FAIL");
|
||||
});
|
||||
</script>
|
|
@ -74,7 +74,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ImageData>> ImageData::create(JS::Realm& re
|
|||
return WebIDL::IndexSizeError::create(realm, "Source height must be equal to the calculated height of the data."_fly_string);
|
||||
|
||||
// 7. Initialize this given sw, sh, settings set to settings, and source set to data.
|
||||
auto bitmap = TRY_OR_THROW_OOM(vm, Gfx::Bitmap::create_wrapper(Gfx::BitmapFormat::RGBA8888, Gfx::AlphaType::Premultiplied, Gfx::IntSize(sw, height), sw * sizeof(u32), uint8_clamped_array_data.data().data()));
|
||||
auto bitmap = TRY_OR_THROW_OOM(vm, Gfx::Bitmap::create_wrapper(Gfx::BitmapFormat::RGBA8888, Gfx::AlphaType::Unpremultiplied, Gfx::IntSize(sw, height), sw * sizeof(u32), uint8_clamped_array_data.data().data()));
|
||||
|
||||
return realm.heap().allocate<ImageData>(realm, realm, bitmap, uint8_clamped_array_data);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue