imagebitmap_bug1239752.js (2593B)
1 var RGBAValues = [ 2 [42, 142, 23, 148], 3 [234, 165, 177, 91], 4 [74, 228, 75, 195], 5 [140, 108, 73, 65], 6 [25, 177, 3, 201], 7 [127, 104, 12, 199], 8 [196, 93, 240, 131], 9 [250, 121, 231, 189], 10 [175, 131, 215, 190], 11 [145, 122, 166, 70], 12 [18, 196, 210, 162], 13 [225, 1, 90, 188], 14 [223, 216, 182, 233], 15 [115, 48, 168, 56], 16 [50, 206, 198, 199], 17 [152, 28, 70, 130], 18 [176, 134, 133, 51], 19 [148, 46, 43, 144], 20 [78, 171, 141, 95], 21 [24, 177, 102, 110], 22 [0, 27, 127, 91], 23 [31, 221, 41, 170], 24 [85, 7, 218, 146], 25 [65, 30, 198, 238], 26 [121, 56, 123, 88], 27 [246, 39, 140, 146], 28 [174, 195, 254, 149], 29 [29, 153, 92, 116], 30 [17, 240, 5, 111], 31 [38, 162, 84, 143], 32 [237, 159, 201, 244], 33 [93, 68, 14, 246], 34 [143, 142, 82, 221], 35 [187, 215, 243, 154], 36 [24, 121, 220, 53], 37 [80, 153, 151, 219], 38 [202, 241, 250, 191], 39 ]; 40 41 function createOneTest(rgbaValue) { 42 return new Promise(function (resolve, reject) { 43 var tolerance = 5; 44 var r = rgbaValue[0]; 45 var g = rgbaValue[1]; 46 var b = rgbaValue[2]; 47 var a = rgbaValue[3]; 48 var imageData = new ImageData(new Uint8ClampedArray([r, g, b, a]), 1, 1); 49 50 var newImageData; 51 createImageBitmap(imageData).then( 52 function (imageBitmap) { 53 var context = document.createElement("canvas").getContext("2d"); 54 context.drawImage(imageBitmap, 0, 0); 55 newImageData = context.getImageData(0, 0, 1, 1); 56 var newR = newImageData.data[0]; 57 var newG = newImageData.data[1]; 58 var newB = newImageData.data[2]; 59 var newA = newImageData.data[3]; 60 var isTheSame = 61 Math.abs(r - newR) <= tolerance && 62 Math.abs(g - newG) <= tolerance && 63 Math.abs(b - newB) <= tolerance && 64 Math.abs(a - newA) <= tolerance; 65 ok( 66 isTheSame, 67 "newImageData(" + 68 newR + 69 "," + 70 newG + 71 "," + 72 newB + 73 "," + 74 newA + 75 ") should equal to imageData(" + 76 r + 77 "," + 78 g + 79 "," + 80 b + 81 "," + 82 a + 83 ")." + 84 "Premultiplied Alpha is handled while creating ImageBitmap from ImageData." 85 ); 86 if (isTheSame) { 87 resolve(); 88 } else { 89 reject(); 90 } 91 }, 92 function () { 93 reject(); 94 } 95 ); 96 }); 97 } 98 99 function testBug1239752() { 100 var tests = []; 101 for (var i = 0; i < RGBAValues.length; ++i) { 102 tests.push(createOneTest(RGBAValues[i])); 103 } 104 105 return Promise.all(tests); 106 }