X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2FUtil.js;h=2d652eda7ab43032a037f0a8835c3bea36517b59;hb=d66c74ef29a8ad222e7203911af1b46b37f5bde1;hp=2b308b36df08b6e0a017ec6ff64410488367f240;hpb=691cb47bb65c604efa9a1f1a6537192f618edb3e;p=dygraphs.git diff --git a/auto_tests/tests/Util.js b/auto_tests/tests/Util.js index 2b308b3..2d652ed 100644 --- a/auto_tests/tests/Util.js +++ b/auto_tests/tests/Util.js @@ -79,3 +79,19 @@ Util.makeNumbers = function(ary) { } return ret; }; + + +/** + * Sample a pixel from the canvas. + * Returns an [r, g, b, a] tuple where each values is in [0, 255]. + */ +Util.samplePixel = function(canvas, x, y) { + var ctx = canvas.getContext("2d"); // bypasses Proxy if applied. + + // TODO(danvk): Any performance issues with this? + var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height); + + var i = 4 * (x + imageData.width * y); + var d = imageData.data; + return [d[i], d[i+1], d[i+2], d[i+3]]; +};