forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibWeb: Add a test for
WindowOrWorkerGlobalScope.createImageBitmap
- Loading branch information
1 parent
7d1fb95
commit a7b88e1
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
RangeError: 0 is an invalid value for sw | ||
Bitmap is correctly loaded |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<script src="include.js"></script> | ||
<canvas id="test" width="2" height="2" hidden="hidden"></canvas> | ||
<script> | ||
test(() => { | ||
// The blob is a JXL image for a 2x2 checkerboard | ||
// Made with the following tree on https://jxl-art.lucaversari.it/: | ||
// Width 2 | ||
// Height 2 | ||
// Bitdepth 8 | ||
// if N > 0 | ||
// - Set 0 | ||
// - Set 255 | ||
|
||
let file = new Blob([new Uint8Array([255, 10, 8, 16, 0, 9, 8, 6, 1, 0, 40, 0, 75, 56, 73, 152, 108, 128, 253, 145, 96, 0])]); | ||
|
||
createImageBitmap(file, 0, 0, 0, 0).catch((err) => println(err)); | ||
|
||
createImageBitmap(file).then((bitmap) => { | ||
if (bitmap.width !== 2 || bitmap.height !== 2) | ||
println(`Unexpected size for image bitmap: '${bitmap.width}'x'${bitmap.height}'`); | ||
|
||
const canvas = document.getElementById("test"); | ||
const ctx = canvas.getContext("2d"); | ||
ctx.drawImage(bitmap, 0, 0) | ||
|
||
function is_pixel_wrong(coord, color) { | ||
let pixel = ctx.getImageData(coord[0], coord[1], 1, 1).data; | ||
|
||
if (pixel[3] !== 255) | ||
return true; | ||
|
||
if (color === 'white') | ||
return pixel[0] !== 255 || pixel[1] !== 255 || pixel[2] !== 255; | ||
|
||
return pixel[0] !== 0 || pixel[1] !== 0 || pixel[2] !== 0; | ||
} | ||
|
||
if (is_pixel_wrong([0, 0], 'white') || is_pixel_wrong([0, 1], 'black') || | ||
is_pixel_wrong([1, 0], 'black') || is_pixel_wrong([1, 1], 'white')) | ||
println(`Invalid value in the bitmap`); | ||
else | ||
println(`Bitmap is correctly loaded`); | ||
}) | ||
}); | ||
</script> |