зеркало из https://github.com/mozilla/pjs.git
66 строки
2.1 KiB
HTML
66 строки
2.1 KiB
HTML
<!DOCTYPE HTML>
|
|
<title>Canvas test: toDataURL.complexcolours</title>
|
|
<script src="/MochiKit/MochiKit.js"></script>
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
|
|
<body>
|
|
<canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
|
|
<script>
|
|
var _deferred = false;
|
|
function isPixel(ctx, x,y, r,g,b,a, pos, colour, d, f) {
|
|
var pixel = ctx.getImageData(x, y, 1, 1);
|
|
var pr = pixel.data[0],
|
|
pg = pixel.data[1],
|
|
pb = pixel.data[2],
|
|
pa = pixel.data[3];
|
|
(f || ok)(r-d <= pr && pr <= r+d &&
|
|
g-d <= pg && pg <= g+d &&
|
|
b-d <= pb && pb <= b+d &&
|
|
a-d <= pa && pa <= a+d,
|
|
"pixel "+pos+" is "+pr+","+pg+","+pb+","+pa+"; expected "+colour+" +/- "+d);
|
|
}
|
|
function deferTest() {
|
|
_deferred = true;
|
|
}
|
|
function wrapFunction(f) {
|
|
return function () {
|
|
f.apply(null, arguments);
|
|
SimpleTest.finish();
|
|
}
|
|
}
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
MochiKit.DOM.addLoadEvent(function () {
|
|
|
|
var canvas = document.getElementById('c');
|
|
var ctx = canvas.getContext('2d');
|
|
|
|
// (These values are chosen to survive relatively alright through being premultiplied)
|
|
ctx.fillStyle = 'rgba(1, 3, 254, 1)';
|
|
ctx.fillRect(0, 0, 25, 25);
|
|
ctx.fillStyle = 'rgba(8, 252, 248, 0.75)';
|
|
ctx.fillRect(25, 0, 25, 25);
|
|
ctx.fillStyle = 'rgba(6, 10, 250, 0.502)';
|
|
ctx.fillRect(50, 0, 25, 25);
|
|
ctx.fillStyle = 'rgba(12, 16, 244, 0.25)';
|
|
ctx.fillRect(75, 0, 25, 25);
|
|
var img = new Image();
|
|
deferTest();
|
|
img.onload = wrapFunction(function ()
|
|
{
|
|
ctx.drawImage(img, 0, 25);
|
|
// (The alpha values do not really survive float->int conversion, so just
|
|
// do approximate comparisons)
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
|
|
isPixel(ctx, 12,40, 1,3,254,255, "12,40", "1,3,254,255", 0);
|
|
isPixel(ctx, 37,40, 8,252,248,191, "37,40", "8,252,248,191", 2);
|
|
isPixel(ctx, 62,40, 6,10,250,127, "62,40", "6,10,250,127", 4);
|
|
isPixel(ctx, 87,40, 12,16,244,63, "87,40", "12,16,244,63", 8);
|
|
});
|
|
img.src = canvas.toDataURL();
|
|
|
|
if (!_deferred) SimpleTest.finish();
|
|
});
|
|
</script>
|
|
|