summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/canvas/canvas-blending-image-over-image.html
blob: e31f39692f0ad30f5cb873be57ba9438f83fcb00 (plain)
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
<!DOCTYPE HTML>
<html>
<head>
    <script type="text/javascript">
        if (window.testRunner)
            testRunner.waitUntilDone();
        window.jsTestIsAsync = true
    </script>
</head>
<body>
    <script src="../../resources/js-test.js"></script>
    <script type="text/javascript" src="canvas-blending-helpers.js"></script>
    <script type="text/javascript">

        description("Series of tests to ensure correct results on applying different blend modes when drawing an image on top of another.");

        var context;
        function actualColor(x, y) {
            return context.getImageData(x, y, 1, 1).data;
        }

        function checkBlendModeResult(i, context, sigma) {
            var expectedColor = blendColors([129 / 255, 1, 129 / 255, 1], [1, 129 / 255, 129 / 255, 1], i);
            var ac = "actualColor(0, 0)";
            shouldBeCloseTo(ac + "[0]", expectedColor[0], sigma);
            shouldBeCloseTo(ac + "[1]", expectedColor[1], sigma);
            shouldBeCloseTo(ac + "[2]", expectedColor[2], sigma);
            shouldBeCloseTo(ac + "[3]", expectedColor[3], sigma);
        }

        function drawElement(context, i) {
            if (i >= blendModes.length) {
                finishJSTest();
                return;
            }
            debug("Testing blend mode " + blendModes[i]);

            context.clearRect(0, 0, 10, 10);
            context.save();
            drawBackdropColorImageInContext(context, function() {
                context.globalCompositeOperation = blendModes[i];

                drawSourceColorImageInContext(context, function() {
                    checkBlendModeResult(i, context, 5);
                    context.restore();
                    debug('');
                    drawElement(context, ++i);
                });
            });
        }

        function runTest() {
            var canvas = document.createElement("canvas");
            var sigma = 5;
            canvas.width = 10;
            canvas.height = 10;
            context = canvas.getContext("2d");
            drawElement(context, 0);
        }

        runTest();
    </script>
</body>
</html>