test.tight.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. const expect = chai.expect;
  2. import Websock from '../core/websock.js';
  3. import Display from '../core/display.js';
  4. import TightDecoder from '../core/decoders/tight.js';
  5. import FakeWebSocket from './fake.websocket.js';
  6. function testDecodeRect(decoder, x, y, width, height, data, display, depth) {
  7. let sock;
  8. sock = new Websock;
  9. sock.open("ws://example.com");
  10. sock.on('message', () => {
  11. decoder.decodeRect(x, y, width, height, sock, display, depth);
  12. });
  13. // Empty messages are filtered at multiple layers, so we need to
  14. // do a direct call
  15. if (data.length === 0) {
  16. decoder.decodeRect(x, y, width, height, sock, display, depth);
  17. } else {
  18. sock._websocket._receiveData(new Uint8Array(data));
  19. }
  20. display.flip();
  21. }
  22. describe('Tight Decoder', function () {
  23. let decoder;
  24. let display;
  25. before(FakeWebSocket.replace);
  26. after(FakeWebSocket.restore);
  27. beforeEach(function () {
  28. decoder = new TightDecoder();
  29. display = new Display(document.createElement('canvas'));
  30. display.resize(4, 4);
  31. });
  32. it('should handle fill rects', function () {
  33. testDecodeRect(decoder, 0, 0, 4, 4,
  34. [0x80, 0xff, 0x88, 0x44],
  35. display, 24);
  36. let targetData = new Uint8Array([
  37. 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255,
  38. 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255,
  39. 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255,
  40. 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255, 0xff, 0x88, 0x44, 255,
  41. ]);
  42. expect(display).to.have.displayed(targetData);
  43. });
  44. it('should handle uncompressed copy rects', function () {
  45. let blueData = [ 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff ];
  46. let greenData = [ 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00 ];
  47. testDecodeRect(decoder, 0, 0, 2, 1, blueData, display, 24);
  48. testDecodeRect(decoder, 0, 1, 2, 1, blueData, display, 24);
  49. testDecodeRect(decoder, 2, 0, 2, 1, greenData, display, 24);
  50. testDecodeRect(decoder, 2, 1, 2, 1, greenData, display, 24);
  51. testDecodeRect(decoder, 0, 2, 2, 1, greenData, display, 24);
  52. testDecodeRect(decoder, 0, 3, 2, 1, greenData, display, 24);
  53. testDecodeRect(decoder, 2, 2, 2, 1, blueData, display, 24);
  54. testDecodeRect(decoder, 2, 3, 2, 1, blueData, display, 24);
  55. let targetData = new Uint8Array([
  56. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  57. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  58. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
  59. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
  60. ]);
  61. expect(display).to.have.displayed(targetData);
  62. });
  63. it('should handle compressed copy rects', function () {
  64. let data = [
  65. // Control byte
  66. 0x00,
  67. // Pixels (compressed)
  68. 0x15,
  69. 0x78, 0x9c, 0x63, 0x60, 0xf8, 0xcf, 0x00, 0x44,
  70. 0x60, 0x82, 0x01, 0x99, 0x8d, 0x29, 0x02, 0xa6,
  71. 0x00, 0x7e, 0xbf, 0x0f, 0xf1 ];
  72. testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24);
  73. let targetData = new Uint8Array([
  74. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  75. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  76. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
  77. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
  78. ]);
  79. expect(display).to.have.displayed(targetData);
  80. });
  81. it('should handle uncompressed mono rects', function () {
  82. let data = [
  83. // Control bytes
  84. 0x40, 0x01,
  85. // Palette
  86. 0x01, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00,
  87. // Pixels
  88. 0x30, 0x30, 0xc0, 0xc0 ];
  89. testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24);
  90. let targetData = new Uint8Array([
  91. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  92. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  93. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
  94. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
  95. ]);
  96. expect(display).to.have.displayed(targetData);
  97. });
  98. it('should handle compressed mono rects', function () {
  99. display.resize(4, 12);
  100. let data = [
  101. // Control bytes
  102. 0x40, 0x01,
  103. // Palette
  104. 0x01, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00,
  105. // Pixels (compressed)
  106. 0x0e,
  107. 0x78, 0x9c, 0x33, 0x30, 0x38, 0x70, 0xc0, 0x00,
  108. 0x8a, 0x01, 0x21, 0x3c, 0x05, 0xa1 ];
  109. testDecodeRect(decoder, 0, 0, 4, 12, data, display, 24);
  110. let targetData = new Uint8Array([
  111. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  112. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  113. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
  114. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
  115. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  116. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  117. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
  118. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
  119. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  120. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  121. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
  122. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
  123. ]);
  124. expect(display).to.have.displayed(targetData);
  125. });
  126. it('should handle uncompressed palette rects', function () {
  127. let data1 = [
  128. // Control bytes
  129. 0x40, 0x01,
  130. // Palette
  131. 0x02, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
  132. // Pixels
  133. 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01 ];
  134. let data2 = [
  135. // Control bytes
  136. 0x40, 0x01,
  137. // Palette
  138. 0x02, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
  139. // Pixels
  140. 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00 ];
  141. testDecodeRect(decoder, 0, 0, 4, 2, data1, display, 24);
  142. testDecodeRect(decoder, 0, 2, 4, 2, data2, display, 24);
  143. let targetData = new Uint8Array([
  144. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  145. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  146. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
  147. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
  148. ]);
  149. expect(display).to.have.displayed(targetData);
  150. });
  151. it('should handle compressed palette rects', function () {
  152. let data = [
  153. // Control bytes
  154. 0x40, 0x01,
  155. // Palette
  156. 0x02, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
  157. // Pixels (compressed)
  158. 0x12,
  159. 0x78, 0x9c, 0x63, 0x60, 0x60, 0x64, 0x64, 0x00,
  160. 0x62, 0x08, 0xc9, 0xc0, 0x00, 0x00, 0x00, 0x54,
  161. 0x00, 0x09 ];
  162. testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24);
  163. let targetData = new Uint8Array([
  164. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  165. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  166. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
  167. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
  168. ]);
  169. expect(display).to.have.displayed(targetData);
  170. });
  171. it.skip('should handle uncompressed gradient rects', function () {
  172. // Not implemented yet
  173. });
  174. it.skip('should handle compressed gradient rects', function () {
  175. // Not implemented yet
  176. });
  177. it('should handle empty copy rects', function () {
  178. display.fillRect(0, 0, 4, 4, [ 0x00, 0x00, 0xff ]);
  179. display.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]);
  180. display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]);
  181. testDecodeRect(decoder, 1, 2, 0, 0, [ 0x00 ], display, 24);
  182. let targetData = new Uint8Array([
  183. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  184. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  185. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
  186. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
  187. ]);
  188. expect(display).to.have.displayed(targetData);
  189. });
  190. it('should handle empty palette rects', function () {
  191. display.fillRect(0, 0, 4, 4, [ 0x00, 0x00, 0xff ]);
  192. display.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]);
  193. display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]);
  194. testDecodeRect(decoder, 1, 2, 0, 0,
  195. [ 0x40, 0x01, 0x01,
  196. 0xff, 0xff, 0xff,
  197. 0xff, 0xff, 0xff ], display, 24);
  198. let targetData = new Uint8Array([
  199. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  200. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  201. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
  202. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
  203. ]);
  204. expect(display).to.have.displayed(targetData);
  205. });
  206. it('should handle empty fill rects', function () {
  207. display.fillRect(0, 0, 4, 4, [ 0x00, 0x00, 0xff ]);
  208. display.fillRect(2, 0, 2, 2, [ 0x00, 0xff, 0x00 ]);
  209. display.fillRect(0, 2, 2, 2, [ 0x00, 0xff, 0x00 ]);
  210. testDecodeRect(decoder, 1, 2, 0, 0,
  211. [ 0x80, 0xff, 0xff, 0xff ], display, 24);
  212. let targetData = new Uint8Array([
  213. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  214. 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  215. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
  216. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
  217. ]);
  218. expect(display).to.have.displayed(targetData);
  219. });
  220. it('should handle JPEG rects', function (done) {
  221. let data = [
  222. // Control bytes
  223. 0x90, 0xd6, 0x05,
  224. // JPEG data
  225. 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46,
  226. 0x49, 0x46, 0x00, 0x01, 0x01, 0x01, 0x00, 0x48,
  227. 0x00, 0x48, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x13,
  228. 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20,
  229. 0x77, 0x69, 0x74, 0x68, 0x20, 0x47, 0x49, 0x4d,
  230. 0x50, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x01, 0x01,
  231. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  232. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  233. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  234. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  235. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  236. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  237. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  238. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xff, 0xdb,
  239. 0x00, 0x43, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  240. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  241. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  242. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  243. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  244. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  245. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  246. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  247. 0x01, 0x01, 0x01, 0xff, 0xc2, 0x00, 0x11, 0x08,
  248. 0x00, 0x04, 0x00, 0x04, 0x03, 0x01, 0x11, 0x00,
  249. 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff, 0xc4,
  250. 0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
  251. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  252. 0x00, 0x00, 0x00, 0x07, 0xff, 0xc4, 0x00, 0x14,
  253. 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  254. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  255. 0x00, 0x08, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01,
  256. 0x00, 0x02, 0x10, 0x03, 0x10, 0x00, 0x00, 0x01,
  257. 0x1e, 0x0a, 0xa7, 0x7f, 0xff, 0xc4, 0x00, 0x14,
  258. 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  259. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  260. 0x00, 0x05, 0xff, 0xda, 0x00, 0x08, 0x01, 0x01,
  261. 0x00, 0x01, 0x05, 0x02, 0x5d, 0x74, 0x41, 0x47,
  262. 0xff, 0xc4, 0x00, 0x1f, 0x11, 0x00, 0x01, 0x04,
  263. 0x02, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
  264. 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x04, 0x05,
  265. 0x07, 0x08, 0x14, 0x16, 0x03, 0x15, 0x17, 0x25,
  266. 0x26, 0xff, 0xda, 0x00, 0x08, 0x01, 0x03, 0x01,
  267. 0x01, 0x3f, 0x01, 0xad, 0x35, 0xa6, 0x13, 0xb8,
  268. 0x10, 0x98, 0x5d, 0x8a, 0xb1, 0x41, 0x7e, 0x43,
  269. 0x99, 0x24, 0x3d, 0x8f, 0x70, 0x30, 0xd8, 0xcb,
  270. 0x44, 0xbb, 0x7d, 0x48, 0xb5, 0xf8, 0x18, 0x7f,
  271. 0xe7, 0xc1, 0x9f, 0x86, 0x45, 0x9b, 0xfa, 0xf1,
  272. 0x61, 0x96, 0x46, 0xbf, 0x56, 0xc8, 0x8b, 0x2b,
  273. 0x0b, 0x35, 0x6e, 0x4b, 0x8a, 0x95, 0x6a, 0xf9,
  274. 0xff, 0x00, 0xff, 0xc4, 0x00, 0x1f, 0x11, 0x00,
  275. 0x01, 0x04, 0x02, 0x02, 0x03, 0x00, 0x00, 0x00,
  276. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
  277. 0x02, 0x04, 0x05, 0x12, 0x13, 0x14, 0x01, 0x06,
  278. 0x11, 0x22, 0x23, 0xff, 0xda, 0x00, 0x08, 0x01,
  279. 0x02, 0x01, 0x01, 0x3f, 0x01, 0x85, 0x85, 0x8c,
  280. 0xec, 0x31, 0x8d, 0xa6, 0x26, 0x1b, 0x6e, 0x48,
  281. 0xbc, 0xcd, 0xb0, 0xe3, 0x33, 0x86, 0xf9, 0x35,
  282. 0xdc, 0x15, 0xa8, 0xbe, 0x4d, 0x4a, 0x10, 0x22,
  283. 0x80, 0x00, 0x91, 0xe8, 0x24, 0xda, 0xb6, 0x57,
  284. 0x95, 0xf2, 0xa5, 0x73, 0xff, 0xc4, 0x00, 0x1e,
  285. 0x10, 0x00, 0x01, 0x04, 0x03, 0x00, 0x03, 0x00,
  286. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  287. 0x00, 0x03, 0x01, 0x02, 0x04, 0x12, 0x05, 0x11,
  288. 0x13, 0x14, 0x22, 0x23, 0xff, 0xda, 0x00, 0x08,
  289. 0x01, 0x01, 0x00, 0x06, 0x3f, 0x02, 0x91, 0x89,
  290. 0xc4, 0xc8, 0xf1, 0x60, 0x45, 0xe5, 0xc0, 0x1c,
  291. 0x80, 0x7a, 0x77, 0x00, 0xe4, 0x97, 0xeb, 0x24,
  292. 0x66, 0x33, 0xac, 0x63, 0x11, 0xfe, 0xe4, 0x76,
  293. 0xad, 0x56, 0xe9, 0xa8, 0x88, 0x9f, 0xff, 0xc4,
  294. 0x00, 0x14, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00,
  295. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  296. 0x00, 0x00, 0x00, 0x00, 0xff, 0xda, 0x00, 0x08,
  297. 0x01, 0x01, 0x00, 0x01, 0x3f, 0x21, 0x68, 0x3f,
  298. 0x92, 0x17, 0x81, 0x1f, 0x7f, 0xff, 0xda, 0x00,
  299. 0x0c, 0x03, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00,
  300. 0x00, 0x00, 0x10, 0x5f, 0xff, 0xc4, 0x00, 0x14,
  301. 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  302. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  303. 0x00, 0x00, 0xff, 0xda, 0x00, 0x08, 0x01, 0x03,
  304. 0x01, 0x01, 0x3f, 0x10, 0x03, 0xeb, 0x11, 0xe4,
  305. 0xa7, 0xe3, 0xff, 0x00, 0xff, 0xc4, 0x00, 0x14,
  306. 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  307. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  308. 0x00, 0x00, 0xff, 0xda, 0x00, 0x08, 0x01, 0x02,
  309. 0x01, 0x01, 0x3f, 0x10, 0x6b, 0xd3, 0x02, 0xdc,
  310. 0x9a, 0xf4, 0xff, 0x00, 0xff, 0xc4, 0x00, 0x14,
  311. 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  312. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  313. 0x00, 0x00, 0xff, 0xda, 0x00, 0x08, 0x01, 0x01,
  314. 0x00, 0x01, 0x3f, 0x10, 0x62, 0x7b, 0x3a, 0xd0,
  315. 0x3f, 0xeb, 0xff, 0x00, 0xff, 0xd9,
  316. ];
  317. testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24);
  318. let targetData = new Uint8Array([
  319. 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  320. 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
  321. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255,
  322. 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0xff, 0x00, 0x00, 255, 0xff, 0x00, 0x00, 255
  323. ]);
  324. // Browsers have rounding errors, so we need an approximate
  325. // comparing function
  326. function almost(a, b) {
  327. let diff = Math.abs(a - b);
  328. return diff < 5;
  329. }
  330. display.onflush = () => {
  331. expect(display).to.have.displayed(targetData, almost);
  332. done();
  333. };
  334. display.flush();
  335. });
  336. });