OLD | NEW |
1 description("This test ensures that putImageData works correctly, the end result
should be a 100x100px green square."); | 1 description("This test ensures that putImageData works correctly, the end result
should be a 100x100px green square."); |
2 | 2 |
3 function fillRect(imageData, x, y, width, height, r, g, b, a) | 3 function fillRect(imageData, x, y, width, height, r, g, b, a) |
4 { | 4 { |
5 var bytesPerRow = imageData.width * 4; | 5 var bytesPerRow = imageData.width * 4; |
6 var data =imageData.data; | 6 var data =imageData.data; |
7 for (var i = 0; i < height; i++) { | 7 for (var i = 0; i < height; i++) { |
8 var rowOrigin = (y+i) * bytesPerRow; | 8 var rowOrigin = (y+i) * bytesPerRow; |
9 rowOrigin += x * 4; | 9 rowOrigin += x * 4; |
10 for (var j = 0; j < width; j++) { | 10 for (var j = 0; j < width; j++) { |
(...skipping 21 matching lines...) Expand all Loading... |
32 } | 32 } |
33 | 33 |
34 function pixelShouldBe(x, y, colour) { | 34 function pixelShouldBe(x, y, colour) { |
35 shouldBe("getPixel(" + [x, y] +")", "["+colour+"]"); | 35 shouldBe("getPixel(" + [x, y] +")", "["+colour+"]"); |
36 } | 36 } |
37 | 37 |
38 var canvas = document.getElementById("canvas"); | 38 var canvas = document.getElementById("canvas"); |
39 var context = canvas.getContext("2d"); | 39 var context = canvas.getContext("2d"); |
40 | 40 |
41 if (!context.createImageData) | 41 if (!context.createImageData) |
42 context.createImageData = function(w,h) { | 42 context.createImageData = function(w,h) { |
43 var data = this.getImageData(0, 0, w, h); | 43 var data = this.getImageData(0, 0, w, h); |
44 for (var i = 0; i < data.data.length; i++) | 44 for (var i = 0; i < data.data.length; i++) |
45 data.data[i] = 0; | 45 data.data[i] = 0; |
46 } | 46 } |
47 var buffer = context.createImageData(100,100); | 47 var buffer = context.createImageData(100,100); |
48 // Fill top left corner | 48 // Fill top left corner |
49 fillRect(buffer, 0, 0, 50, 50, 0, 128,0,255); | 49 fillRect(buffer, 0, 0, 50, 50, 0, 128,0,255); |
50 context.putImageData(buffer, 0, 0); | 50 context.putImageData(buffer, 0, 0); |
51 pixelShouldBe( 0, 0, [0, 128,0,255]); | 51 pixelShouldBe( 0, 0, [0, 128,0,255]); |
52 pixelShouldBe(25, 25, [0, 128,0,255]); | 52 pixelShouldBe(25, 25, [0, 128,0,255]); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 context.putImageData(smallbuffer, 1, 1, 0.0, 0.0, 8.25, 8.25); | 195 context.putImageData(smallbuffer, 1, 1, 0.0, 0.0, 8.25, 8.25); |
196 pixelShouldBe(1, 1, [0, 128,0,255]); | 196 pixelShouldBe(1, 1, [0, 128,0,255]); |
197 pixelShouldBe(9, 9, [0, 128,0,255]); | 197 pixelShouldBe(9, 9, [0, 128,0,255]); |
198 context.fillRect(1, 1, 7, 7); | 198 context.fillRect(1, 1, 7, 7); |
199 context.putImageData(smallbuffer, 1, 1, 0.5, 0.5, 7.9, 7.9); | 199 context.putImageData(smallbuffer, 1, 1, 0.5, 0.5, 7.9, 7.9); |
200 pixelShouldBe(1, 1, [0, 128,0,255]); | 200 pixelShouldBe(1, 1, [0, 128,0,255]); |
201 pixelShouldBe(9, 9, [0, 128,0,255]); | 201 pixelShouldBe(9, 9, [0, 128,0,255]); |
202 | 202 |
203 | 203 |
204 shouldThrow("context.putImageData({}, 0, 0)", "'TypeError: Type error'"); | 204 shouldThrow("context.putImageData({}, 0, 0)", "'TypeError: Type error'"); |
205 shouldThrow("context.putImageData(buffer, NaN, 0, 0, 0, 0, 0)", "'Error: NotSupp
ortedError: DOM Exception 9'"); | 205 shouldThrow("context.putImageData(buffer, NaN, 0, 0, 0, 0, 0)", "'NotSupportedEr
ror: The implementation did not support the requested type of object or operatio
n.'"); |
206 shouldThrow("context.putImageData(buffer, 0, NaN, 0, 0, 0, 0)", "'Error: NotSupp
ortedError: DOM Exception 9'"); | 206 shouldThrow("context.putImageData(buffer, 0, NaN, 0, 0, 0, 0)", "'NotSupportedEr
ror: The implementation did not support the requested type of object or operatio
n.'"); |
207 shouldThrow("context.putImageData(buffer, 0, 0, NaN, 0, 0, 0)", "'Error: NotSupp
ortedError: DOM Exception 9'"); | 207 shouldThrow("context.putImageData(buffer, 0, 0, NaN, 0, 0, 0)", "'NotSupportedEr
ror: The implementation did not support the requested type of object or operatio
n.'"); |
208 shouldThrow("context.putImageData(buffer, 0, 0, 0, NaN, 0, 0)", "'Error: NotSupp
ortedError: DOM Exception 9'"); | 208 shouldThrow("context.putImageData(buffer, 0, 0, 0, NaN, 0, 0)", "'NotSupportedEr
ror: The implementation did not support the requested type of object or operatio
n.'"); |
209 shouldThrow("context.putImageData(buffer, 0, 0, 0, 0, NaN, 0)", "'Error: NotSupp
ortedError: DOM Exception 9'"); | 209 shouldThrow("context.putImageData(buffer, 0, 0, 0, 0, NaN, 0)", "'NotSupportedEr
ror: The implementation did not support the requested type of object or operatio
n.'"); |
210 shouldThrow("context.putImageData(buffer, 0, 0, 0, 0, 0, NaN)", "'Error: NotSupp
ortedError: DOM Exception 9'"); | 210 shouldThrow("context.putImageData(buffer, 0, 0, 0, 0, 0, NaN)", "'NotSupportedEr
ror: The implementation did not support the requested type of object or operatio
n.'"); |
211 shouldThrow("context.putImageData(buffer, Infinity, 0, 0, 0, 0, 0)", "'Error: No
tSupportedError: DOM Exception 9'"); | 211 shouldThrow("context.putImageData(buffer, Infinity, 0, 0, 0, 0, 0)", "'NotSuppor
tedError: The implementation did not support the requested type of object or ope
ration.'"); |
212 shouldThrow("context.putImageData(buffer, 0, Infinity, 0, 0, 0, 0)", "'Error: No
tSupportedError: DOM Exception 9'"); | 212 shouldThrow("context.putImageData(buffer, 0, Infinity, 0, 0, 0, 0)", "'NotSuppor
tedError: The implementation did not support the requested type of object or ope
ration.'"); |
213 shouldThrow("context.putImageData(buffer, 0, 0, Infinity, 0, 0, 0)", "'Error: No
tSupportedError: DOM Exception 9'"); | 213 shouldThrow("context.putImageData(buffer, 0, 0, Infinity, 0, 0, 0)", "'NotSuppor
tedError: The implementation did not support the requested type of object or ope
ration.'"); |
214 shouldThrow("context.putImageData(buffer, 0, 0, 0, Infinity, 0, 0)", "'Error: No
tSupportedError: DOM Exception 9'"); | 214 shouldThrow("context.putImageData(buffer, 0, 0, 0, Infinity, 0, 0)", "'NotSuppor
tedError: The implementation did not support the requested type of object or ope
ration.'"); |
215 shouldThrow("context.putImageData(buffer, 0, 0, 0, 0, Infinity, 0)", "'Error: No
tSupportedError: DOM Exception 9'"); | 215 shouldThrow("context.putImageData(buffer, 0, 0, 0, 0, Infinity, 0)", "'NotSuppor
tedError: The implementation did not support the requested type of object or ope
ration.'"); |
216 shouldThrow("context.putImageData(buffer, 0, 0, 0, 0, 0, Infinity)", "'Error: No
tSupportedError: DOM Exception 9'"); | 216 shouldThrow("context.putImageData(buffer, 0, 0, 0, 0, 0, Infinity)", "'NotSuppor
tedError: The implementation did not support the requested type of object or ope
ration.'"); |
217 shouldThrow("context.putImageData(buffer, undefined, 0, 0, 0, 0, 0)", "'Error: N
otSupportedError: DOM Exception 9'"); | 217 shouldThrow("context.putImageData(buffer, undefined, 0, 0, 0, 0, 0)", "'NotSuppo
rtedError: The implementation did not support the requested type of object or op
eration.'"); |
218 shouldThrow("context.putImageData(buffer, 0, undefined, 0, 0, 0, 0)", "'Error: N
otSupportedError: DOM Exception 9'"); | 218 shouldThrow("context.putImageData(buffer, 0, undefined, 0, 0, 0, 0)", "'NotSuppo
rtedError: The implementation did not support the requested type of object or op
eration.'"); |
219 shouldThrow("context.putImageData(buffer, 0, 0, undefined, 0, 0, 0)", "'Error: N
otSupportedError: DOM Exception 9'"); | 219 shouldThrow("context.putImageData(buffer, 0, 0, undefined, 0, 0, 0)", "'NotSuppo
rtedError: The implementation did not support the requested type of object or op
eration.'"); |
220 shouldThrow("context.putImageData(buffer, 0, 0, 0, undefined, 0, 0)", "'Error: N
otSupportedError: DOM Exception 9'"); | 220 shouldThrow("context.putImageData(buffer, 0, 0, 0, undefined, 0, 0)", "'NotSuppo
rtedError: The implementation did not support the requested type of object or op
eration.'"); |
221 shouldThrow("context.putImageData(buffer, 0, 0, 0, 0, undefined, 0)", "'Error: N
otSupportedError: DOM Exception 9'"); | 221 shouldThrow("context.putImageData(buffer, 0, 0, 0, 0, undefined, 0)", "'NotSuppo
rtedError: The implementation did not support the requested type of object or op
eration.'"); |
222 shouldThrow("context.putImageData(buffer, 0, 0, 0, 0, 0, undefined)", "'Error: N
otSupportedError: DOM Exception 9'"); | 222 shouldThrow("context.putImageData(buffer, 0, 0, 0, 0, 0, undefined)", "'NotSuppo
rtedError: The implementation did not support the requested type of object or op
eration.'"); |
223 | 223 |
224 // Ensure we don't mess up bounds clipping checks | 224 // Ensure we don't mess up bounds clipping checks |
225 var rectcanvas = document.createElement("canvas"); | 225 var rectcanvas = document.createElement("canvas"); |
226 rectcanvas.width = 20; | 226 rectcanvas.width = 20; |
227 rectcanvas.height = 10; | 227 rectcanvas.height = 10; |
228 var rectbuffer = rectcanvas.getContext("2d"); | 228 var rectbuffer = rectcanvas.getContext("2d"); |
229 rectbuffer.putImageData(smallbuffer, 10, 0); | 229 rectbuffer.putImageData(smallbuffer, 10, 0); |
230 | 230 |
231 var rectcanvas = document.createElement("canvas"); | 231 var rectcanvas = document.createElement("canvas"); |
232 rectcanvas.width = 10; | 232 rectcanvas.width = 10; |
233 rectcanvas.height = 20; | 233 rectcanvas.height = 20; |
234 var rectbuffer = rectcanvas.getContext("2d"); | 234 var rectbuffer = rectcanvas.getContext("2d"); |
235 rectbuffer.putImageData(smallbuffer, 0, 10); | 235 rectbuffer.putImageData(smallbuffer, 0, 10); |
OLD | NEW |