rre.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * noVNC: HTML5 VNC client
  3. * Copyright (C) 2012 Joel Martin
  4. * Copyright (C) 2018 Samuel Mannehed for Cendio AB
  5. * Copyright (C) 2018 Pierre Ossman for Cendio AB
  6. * Licensed under MPL 2.0 (see LICENSE.txt)
  7. *
  8. * See README.md for usage and integration instructions.
  9. *
  10. */
  11. export default class RREDecoder {
  12. constructor() {
  13. this._subrects = 0;
  14. }
  15. decodeRect(x, y, width, height, sock, display, depth) {
  16. if (this._subrects === 0) {
  17. if (sock.rQwait("RRE", 4 + 4)) {
  18. return false;
  19. }
  20. this._subrects = sock.rQshift32();
  21. let color = sock.rQshiftBytes(4); // Background
  22. display.fillRect(x, y, width, height, color);
  23. }
  24. while (this._subrects > 0) {
  25. if (sock.rQwait("RRE", 4 + 8)) {
  26. return false;
  27. }
  28. let color = sock.rQshiftBytes(4);
  29. let sx = sock.rQshift16();
  30. let sy = sock.rQshift16();
  31. let swidth = sock.rQshift16();
  32. let sheight = sock.rQshift16();
  33. display.fillRect(x + sx, y + sy, swidth, sheight, color);
  34. this._subrects--;
  35. }
  36. return true;
  37. }
  38. }