File: createImageBitmap-flipY.html

package info (click to toggle)
firefox 145.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,528 kB
  • sloc: cpp: 7,594,999; javascript: 6,459,658; ansic: 3,752,909; python: 1,403,455; xml: 629,809; asm: 438,679; java: 186,421; sh: 67,287; makefile: 19,169; objc: 13,086; perl: 12,982; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (73 lines) | stat: -rw-r--r-- 2,899 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html>
<title>createImageBitmap + drawImage test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>
<script src="/common/media.js"></script>
<script src="common.sub.js"></script>
<link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css">
<body>
<script>
function testCanvasDisplayingPattern(canvas, width, height, sourceIsVideo, flipped)
{
    var tolerance = 3;
    let topLeft = [255, 0, 0, 255];
    let topRight = [0, 255, 0, 255];
    let bottomLeft = [0, 0, 255, 255];
    let bottomRight = [0, 0, 0, 255];
    if (sourceIsVideo) {
        // The source video uses colors in the Rec.601 color space whose
        // values are close to full red, full green, full blue, and black,
        // but when converted to sRGB, are somewhat different.
        topLeft = [247, 37, 0, 255];
        topRight = [63, 251, 0, 255];
        bottomLeft = [28, 35, 255, 255];
        bottomRight = [5, 0, 2, 255];
    }
    if (flipped) {
        [topLeft, bottomLeft] = [bottomLeft, topLeft];
        [topRight, bottomRight] = [bottomRight, topRight];
    }
    const check = (x, y, [r, g, b, a]) =>
        _assertPixelApprox(canvas, x,y, r,g,b,a, tolerance);
    check(1 * width / 4, 1 * height / 4, topLeft);
    check(3 * width / 4, 1 * height / 4, topRight);
    check(1 * width / 4, 3 * height / 4, bottomLeft);
    check(3 * width / 4, 3 * height / 4, bottomRight);
}

function testDrawImageBitmap(source, args = [], flipped, { resizeWidth = 20, resizeHeight = 20 } = {})
{
    let sourceIsVideo = source instanceof HTMLVideoElement;
    var canvas = document.createElement("canvas");
    canvas.width = resizeWidth;
    canvas.height = resizeHeight;
    var ctx = canvas.getContext("2d");
    return createImageBitmap(source, ...args).then(imageBitmap => {
        assert_equals(imageBitmap.width, resizeWidth);
        assert_equals(imageBitmap.height, resizeHeight);
        ctx.drawImage(imageBitmap, 0, 0);
        testCanvasDisplayingPattern(canvas, resizeWidth, resizeHeight, sourceIsVideo, flipped);
    });
}

for (let { name, factory } of imageSourceTypes) {
    promise_test(function() {
        return factory().then(function(img) {
            const options = { imageOrientation: 'from-image' };
            return testDrawImageBitmap(img, [options], false);
        });
    }, `createImageBitmap from ${name} imageOrientation: "from-image", and drawImage on the created ImageBitmap`);

    promise_test(function() {
        return factory().then(function(img) {
            const options = { imageOrientation: 'flipY' };
            return testDrawImageBitmap(img, [options], true);
        });
    }, `createImageBitmap from ${name} imageOrientation: "flipY", and drawImage on the created ImageBitmap`);

}
</script>
</body>
</html>