(left, right, text, callback, delta)
| 68 | |
| 69 | |
| 70 | function imageEqual(left, right, text, callback, delta){ |
| 71 | loadImage(left, function (left){ |
| 72 | left.setAttribute('style', 'border: 2px solid red; padding: 2px;'); |
| 73 | document.body.appendChild(left.cloneNode()); |
| 74 | |
| 75 | loadImage(right, function (right){ |
| 76 | right.setAttribute('style', 'border: 2px solid blue; padding: 2px;'); |
| 77 | document.body.appendChild(right); |
| 78 | |
| 79 | left = toCanvas(left); |
| 80 | right = toCanvas(right); |
| 81 | |
| 82 | if( left.width != right.width ){ |
| 83 | ok(false, text + ' (width: '+left.width+' != '+right.width+')'); |
| 84 | } |
| 85 | else if( left.height != right.height ){ |
| 86 | ok(false, text + ' (height: '+left.height+' != '+right.height+')'); |
| 87 | } |
| 88 | else { |
| 89 | var state = true, pixels = 0, failPixels = 0; |
| 90 | var leftData = left.getContext('2d').getImageData(0, 0, left.width, left.height); |
| 91 | var rightData = right.getContext('2d').getImageData(0, 0, left.width, left.height); |
| 92 | |
| 93 | check: for( var y = 0; y < leftData.height; y++ ){ |
| 94 | for( var x = 0; x < leftData.width; x++ ){ |
| 95 | var idx = (x + y * leftData.width) * 4; |
| 96 | pixels++; |
| 97 | if( !pixelEqual(leftData.data, rightData.data, idx) ){ |
| 98 | failPixels++; |
| 99 | // break check; |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | ok(failPixels/pixels < (delta || .01), text + ' (fail pixels: '+ (failPixels/pixels) +')'); |
| 105 | } |
| 106 | |
| 107 | callback(); |
| 108 | }); |
| 109 | }); |
| 110 | } |
| 111 | |
| 112 | |
| 113 | function pixelEqual(left, right, idx){ |
no test coverage detected