gecko-dev/content/canvas/test/test_2d.imageData.get.clamp...

35 строки
1.2 KiB
HTML

<!DOCTYPE HTML>
<title>Canvas test: 2d.imageData.get.clamp</title>
<!-- Testing: getImageData() clamps colours to the range [0, 255] -->
<script src="/MochiKit/MochiKit.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<body>
<canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
<script>
SimpleTest.waitForExplicitFinish();
MochiKit.DOM.addLoadEvent(function () {
var canvas = document.getElementById('c');
var ctx = canvas.getContext('2d');
ctx.fillStyle = 'rgb(-100, -200, -300)';
ctx.fillRect(0, 0, 100, 50);
ctx.fillStyle = 'rgb(256, 300, 400)';
ctx.fillRect(20, 10, 60, 10);
var imgdata1 = ctx.getImageData(10, 5, 1, 1);
ok(imgdata1.data[0] === 0, "imgdata1.data[\""+(0)+"\"] === 0");
ok(imgdata1.data[1] === 0, "imgdata1.data[\""+(1)+"\"] === 0");
ok(imgdata1.data[2] === 0, "imgdata1.data[\""+(2)+"\"] === 0");
var imgdata2 = ctx.getImageData(30, 15, 1, 1);
ok(imgdata2.data[0] === 255, "imgdata2.data[\""+(0)+"\"] === 255");
ok(imgdata2.data[1] === 255, "imgdata2.data[\""+(1)+"\"] === 255");
ok(imgdata2.data[2] === 255, "imgdata2.data[\""+(2)+"\"] === 255");
SimpleTest.finish();
});
</script>