OLD | NEW |
| (Empty) |
1 description("Test ImageData constructor"); | |
2 | |
3 function setRGBA(imageData, i, rgba) { | |
4 var s = i * 4; | |
5 imageData[s] = rgba[0]; | |
6 imageData[s + 1] = rgba[1]; | |
7 imageData[s + 2] = rgba[2]; | |
8 imageData[s + 3] = rgba[3]; | |
9 } | |
10 | |
11 function getRGBA(imageData, i) { | |
12 var result = []; | |
13 var s = i * 4; | |
14 for (var j = 0; j < 4; j++) { | |
15 result[j] = imageData[s + j]; | |
16 } | |
17 return result; | |
18 } | |
19 | |
20 shouldBeDefined("ImageData"); | |
21 shouldBe("ImageData.length", "2"); | |
22 | |
23 imageData = new ImageData(100, 50); | |
24 | |
25 shouldBeNonNull("imageData"); | |
26 shouldBeNonNull("imageData.data"); | |
27 shouldBe("imageData.width", "100"); | |
28 shouldBe("imageData.height", "50"); | |
29 shouldBe("getRGBA(imageData.data, 4)", "[0, 0, 0, 0]"); | |
30 | |
31 var testColor = [0, 255, 255, 128]; | |
32 setRGBA(imageData.data, 4, testColor); | |
33 shouldBe("getRGBA(imageData.data, 4)", "testColor"); | |
34 | |
35 shouldThrow("new ImageData(10)"); | |
36 shouldThrow("new ImageData(0, 10)"); | |
37 shouldThrow("new ImageData(10, 0)"); | |
38 shouldThrow("new ImageData('width', 'height')"); | |
39 shouldThrow("new ImageData(1 << 31, 1 << 31)"); | |
40 | |
41 shouldThrow("new ImageData(new Uint8ClampedArray(0))"); | |
42 shouldThrow("new ImageData(new Uint8Array(100), 25)"); | |
43 shouldThrow("new ImageData(new Uint8ClampedArray(27), 2)"); | |
44 shouldThrow("new ImageData(new Uint8ClampedArray(104), 14)"); | |
45 shouldThrow("new ImageData(imageData.data, 0)"); | |
46 shouldThrow("new ImageData(imageData.data, 13)"); | |
47 shouldThrow("new ImageData(imageData.data, 1 << 31)"); | |
48 shouldThrow("new ImageData(imageData.data, 'biggish')"); | |
49 shouldThrow("new ImageData(imageData.data, 1 << 24, 1 << 31)"); | |
50 | |
51 imageDataFromData = new ImageData(imageData.data, 100); | |
52 shouldBe("imageDataFromData.width", "100"); | |
53 shouldBe("imageDataFromData.height", "50"); | |
54 shouldBe("imageDataFromData.data", "imageData.data"); | |
55 shouldBe("getRGBA(imageDataFromData.data, 10)", "getRGBA(imageData.data, 10)"); | |
56 setRGBA(imageData.data, 10, testColor); | |
57 shouldBe("getRGBA(imageDataFromData.data, 10)", "getRGBA(imageData.data, 10)"); | |
58 | |
59 var data = new Uint8ClampedArray(400); | |
60 data[22] = 129; | |
61 imageDataFromData = new ImageData(data, 20, 5); | |
62 shouldBe("imageDataFromData.width", "20"); | |
63 shouldBe("imageDataFromData.height", "5"); | |
64 shouldBe("imageDataFromData.data", "data"); | |
65 shouldBe("getRGBA(imageDataFromData.data, 2)", "getRGBA(data, 2)"); | |
66 setRGBA(imageDataFromData.data, 2, testColor); | |
67 shouldBe("getRGBA(imageDataFromData.data, 2)", "getRGBA(data, 2)"); | |
OLD | NEW |