| OLD | NEW |
| (Empty) |
| 1 function setF16Color(float32ImageData, i, f16Color) { | |
| 2 var s = i * 4; | |
| 3 float32ImageData[s] = f16Color[0]; | |
| 4 float32ImageData[s + 1] = f16Color[1]; | |
| 5 float32ImageData[s + 2] = f16Color[2]; | |
| 6 float32ImageData[s + 3] = f16Color[3]; | |
| 7 } | |
| 8 | |
| 9 function getF16Color(float32ImageData, i) { | |
| 10 var result = []; | |
| 11 var s = i * 4; | |
| 12 for (var j = 0; j < 4; j++) { | |
| 13 result[j] = float32ImageData[s + j]; | |
| 14 } | |
| 15 return result; | |
| 16 } | |
| 17 | |
| 18 function compareF16Colors(f16Color1, f16Color2) { | |
| 19 for (var j = 0; j < 4; j++) | |
| 20 if (f16Color1[j] != f16Color2[j]) | |
| 21 return false; | |
| 22 return true; | |
| 23 } | |
| 24 | |
| 25 test(function() { | |
| 26 | |
| 27 float32ImageData = new Float32ImageData(100, 50); | |
| 28 assert_equals(float32ImageData.width, 100, | |
| 29 "The width of the float32ImageData should be the width we passed to the co
nstructor."); | |
| 30 assert_equals(float32ImageData.height, 50, | |
| 31 "The height of the float32ImageData should be the height we passed to the
constructor."); | |
| 32 | |
| 33 var f16ColorData = getF16Color(float32ImageData.data, 4); | |
| 34 assert_equals(f16ColorData[0], 0, | |
| 35 "The default ImageData color is transparent black."); | |
| 36 assert_equals(f16ColorData[1], 0, | |
| 37 "The default ImageData color is transparent black."); | |
| 38 assert_equals(f16ColorData[2], 0, | |
| 39 "The default ImageData color is transparent black."); | |
| 40 assert_equals(f16ColorData[3], 0, | |
| 41 "The default ImageData color is transparent black."); | |
| 42 | |
| 43 var testColor = new Float32Array([0x00003c00, 0x00003c01, 0x00003c02, 0x00003c
03]); | |
| 44 setF16Color(float32ImageData.data, 4, testColor); | |
| 45 f16ColorData = getF16Color(float32ImageData.data, 4); | |
| 46 assert_equals(f16ColorData[0], 0x00003c00, | |
| 47 "The red component of f16 color is the value we set."); | |
| 48 assert_equals(f16ColorData[1], 0x00003c01, | |
| 49 "The green component of f16 color is the value we set."); | |
| 50 assert_equals(f16ColorData[2], 0x00003c02, | |
| 51 "The blue component of f16 color is the value we set."); | |
| 52 assert_equals(f16ColorData[3], 0x00003c03, | |
| 53 "The alpha component of f16 color is the value we set."); | |
| 54 | |
| 55 assert_throws(null, function() {new Float32ImageData(10);}, | |
| 56 "Float32ImageData constructor requires both width and height."); | |
| 57 assert_throws("IndexSizeError", function() {new Float32ImageData(0,10);}, | |
| 58 "Float32ImageData width must be greater than zero."); | |
| 59 assert_throws("IndexSizeError", function() {new Float32ImageData(10,0);}, | |
| 60 "Float32ImageData height must be greater than zero."); | |
| 61 assert_throws("IndexSizeError", function() {new Float32ImageData('width', 'hei
ght');}, | |
| 62 "Float32ImageData width and height must be numbers."); | |
| 63 assert_throws("IndexSizeError", function() {new Float32ImageData(1 << 31, 1 <<
31);}, | |
| 64 "Float32ImageData width multiplied by height must be less than 2^30 to avo
id buffer size overflow."); | |
| 65 | |
| 66 assert_throws(null, function() {new Float32ImageData(new Float32Array(0));}, | |
| 67 "The Float32Array passed to the constructor cannot have a length of zero."
); | |
| 68 assert_throws("IndexSizeError", function() {new Float32ImageData(new Float32Ar
ray(27), 2);}, | |
| 69 "The size of Float32Array passed to the constructor must be divisible by 4
* width."); | |
| 70 assert_throws("IndexSizeError", function() {new Float32ImageData(new Float32Ar
ray(28), 7, 0);}, | |
| 71 "The size of Float32Array passed to the constructor must be equal to 4 * w
idth * height."); | |
| 72 assert_throws(null, function() {new Float32ImageData(self, 4, 4);}, | |
| 73 "The object passed to the constructor as data array should be of type Floa
t32Array."); | |
| 74 assert_throws(null, function() {new Float32ImageData(null, 4, 4);}, | |
| 75 "The object passed to the constructor as data array should be of type Floa
t32Array."); | |
| 76 assert_throws("IndexSizeError", function() {new Float32ImageData(float32ImageD
ata.data, 0);}, | |
| 77 "The size of Float32Array passed to the constructor must be divisible by 4
* width."); | |
| 78 assert_throws("IndexSizeError", function() {new Float32ImageData(float32ImageD
ata.data, 13);}, | |
| 79 "The size of Float32Array passed to the constructor must be divisible by 4
* width."); | |
| 80 assert_throws("IndexSizeError", function() {new Float32ImageData(float32ImageD
ata.data, 1 << 31);}, | |
| 81 "The size of Float32Array passed to the constructor must be divisible by 4
* width."); | |
| 82 assert_throws("IndexSizeError", function() {new Float32ImageData(float32ImageD
ata.data, 'biggish');}, | |
| 83 "The width parameter must be a number."); | |
| 84 assert_throws("IndexSizeError", function() {new Float32ImageData(float32ImageD
ata.data, 1 << 24, 1 << 31);}, | |
| 85 "Float32ImageData width multiplied by height must be less than 2^30 to avo
id buffer size overflow."); | |
| 86 assert_throws("IndexSizeError", function() {new Float32ImageData(float32ImageD
ata.data, 1 << 31, 1 << 24);}, | |
| 87 "Float32ImageData width multiplied by height must be less than 2^30 to avo
id buffer size overflow."); | |
| 88 assert_equals((new Float32ImageData(new Float32Array(28), 7)).height, 1, | |
| 89 "The height must be equal to size of the data array divided by 4 * width."
); | |
| 90 | |
| 91 float32ImageDataFromData = new Float32ImageData(float32ImageData.data, 100); | |
| 92 assert_equals(float32ImageDataFromData.width, 100, | |
| 93 "The width of the float32ImageDataFromData should be the same as that of f
loat32ImageData."); | |
| 94 assert_equals(float32ImageDataFromData.height, 50, | |
| 95 "The height of the float32ImageDataFromData should be the same as that of
float32ImageData."); | |
| 96 assert_true(float32ImageDataFromData.data == float32ImageData.data, | |
| 97 "The pixel data buffer of float32ImageDataFromData should be the same as t
hat of float32ImageData."); | |
| 98 assert_true(compareF16Colors(getF16Color(float32ImageDataFromData.data, 10), | |
| 99 getF16Color(float32ImageData.data, 10)), | |
| 100 "The color of a pixel from float32ImageDataFromData should be the same as
that of float32ImageData."); | |
| 101 setF16Color(float32ImageData.data, 10, testColor); | |
| 102 assert_true(compareF16Colors(getF16Color(float32ImageDataFromData.data, 10), | |
| 103 getF16Color(float32ImageData.data, 10)), | |
| 104 "Setting the color of a pixel from float32ImageData must cascade to the sa
me pixel of float32ImageDataFromData."); | |
| 105 | |
| 106 var data = new Float32Array(400); | |
| 107 data[22] = 129; | |
| 108 float32ImageDataFromData = new Float32ImageData(data, 20, 5); | |
| 109 assert_equals(float32ImageDataFromData.width, 20, | |
| 110 "The width of the float32ImageData should be the width we passed to the co
nstructor."); | |
| 111 assert_equals(float32ImageDataFromData.height, 5, | |
| 112 "The height of the Float32ImageData must be equal to size of the Float32Ar
ray divided by 4 * width."); | |
| 113 assert_true(float32ImageDataFromData.data == data, | |
| 114 "The pixel data buffer of float32ImageDataFromData should be the same buff
er passed to the constructor."); | |
| 115 assert_true(compareF16Colors(getF16Color(float32ImageDataFromData.data, 2), ge
tF16Color(data, 2)), | |
| 116 "The pixel data of float32ImageDataFromData should be the same as that of
the buffer passed to the constructor."); | |
| 117 setF16Color(float32ImageDataFromData.data, 2, testColor); | |
| 118 assert_true(compareF16Colors(getF16Color(float32ImageDataFromData.data, 2), ge
tF16Color(data, 2)), | |
| 119 "Setting the color of a pixel from float32ImageDataFromData must cascade t
o the same pixel of the buffer passed to the constructor."); | |
| 120 | |
| 121 }, 'This test examines the correct behavior of Float32ImageData API.'); | |
| OLD | NEW |