Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 2 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /jpegxl/canvas-decode-paths.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<title>JPEG XL integration: canvas decode paths</title>
<link rel="help" href="https://github.com/web-platform-tests/interop-jpegxl">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(async () => {
const image = new Image();
const loaded = new Promise((resolve, reject) => {
image.onload = resolve;
image.onerror = () => reject(new Error('image decode failed'));
});
image.src = 'resources/3x3_srgb_lossless.jxl';
await loaded;
const canvas = document.createElement('canvas');
canvas.width = 3;
canvas.height = 3;
const ctx = canvas.getContext('2d');
ctx.drawImage(image, 0, 0);
const p = ctx.getImageData(1, 1, 1, 1).data;
const nonZero = p[0] !== 0 || p[1] !== 0 || p[2] !== 0 || p[3] !== 0;
assert_true(nonZero, '2D canvas contains decoded JPEG XL pixels');
}, 'Canvas 2D drawImage path with JPEG XL image.');
promise_test(async () => {
const response = await fetch('resources/3x3_srgb_lossless.jxl');
const blob = await response.blob();
const bitmap = await createImageBitmap(blob);
assert_equals(bitmap.width, 3);
assert_equals(bitmap.height, 3);
bitmap.close();
}, 'createImageBitmap() decodes JPEG XL blob.');
</script>