raw.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * noVNC: HTML5 VNC client
  3. * Copyright (C) 2019 The noVNC Authors
  4. * Licensed under MPL 2.0 (see LICENSE.txt)
  5. *
  6. * See README.md for usage and integration instructions.
  7. *
  8. */
  9. export default class RawDecoder {
  10. constructor() {
  11. this._lines = 0;
  12. }
  13. decodeRect(x, y, width, height, sock, display, depth) {
  14. if ((width === 0) || (height === 0)) {
  15. return true;
  16. }
  17. if (this._lines === 0) {
  18. this._lines = height;
  19. }
  20. const pixelSize = depth == 8 ? 1 : 4;
  21. const bytesPerLine = width * pixelSize;
  22. while (this._lines > 0) {
  23. if (sock.rQwait("RAW", bytesPerLine)) {
  24. return false;
  25. }
  26. const curY = y + (height - this._lines);
  27. let data = sock.rQshiftBytes(bytesPerLine, false);
  28. // Convert data if needed
  29. if (depth == 8) {
  30. const newdata = new Uint8Array(width * 4);
  31. for (let i = 0; i < width; i++) {
  32. newdata[i * 4 + 0] = ((data[i] >> 0) & 0x3) * 255 / 3;
  33. newdata[i * 4 + 1] = ((data[i] >> 2) & 0x3) * 255 / 3;
  34. newdata[i * 4 + 2] = ((data[i] >> 4) & 0x3) * 255 / 3;
  35. newdata[i * 4 + 3] = 255;
  36. }
  37. data = newdata;
  38. }
  39. // Max sure the image is fully opaque
  40. for (let i = 0; i < width; i++) {
  41. data[i * 4 + 3] = 255;
  42. }
  43. display.blitImage(x, curY, width, 1, data, 0);
  44. this._lines--;
  45. }
  46. return true;
  47. }
  48. }