You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TightDecoder.cxx 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Copyright (C) 2000-2003 Constantin Kaplinsky. All Rights Reserved.
  2. * Copyright 2004-2005 Cendio AB.
  3. * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
  4. *
  5. * This is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This software is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this software; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  18. * USA.
  19. */
  20. #include <rfb/CMsgReader.h>
  21. #include <rfb/CConnection.h>
  22. #include <rfb/PixelBuffer.h>
  23. #include <rfb/TightDecoder.h>
  24. using namespace rfb;
  25. #define TIGHT_MAX_WIDTH 2048
  26. #define BPP 8
  27. #include <rfb/tightDecode.h>
  28. #undef BPP
  29. #define BPP 16
  30. #include <rfb/tightDecode.h>
  31. #undef BPP
  32. #define BPP 32
  33. #include <rfb/tightDecode.h>
  34. #undef BPP
  35. TightDecoder::TightDecoder(CConnection* conn) : Decoder(conn)
  36. {
  37. }
  38. TightDecoder::~TightDecoder()
  39. {
  40. }
  41. void TightDecoder::readRect(const Rect& r, ModifiablePixelBuffer* pb)
  42. {
  43. is = conn->getInStream();
  44. this->pb = pb;
  45. clientpf = pb->getPF();
  46. serverpf = conn->cp.pf();
  47. if (clientpf.equal(serverpf)) {
  48. /* Decode directly into the framebuffer (fast path) */
  49. directDecode = true;
  50. } else {
  51. /* Decode into an intermediate buffer and use pixel translation */
  52. directDecode = false;
  53. }
  54. switch (serverpf.bpp) {
  55. case 8:
  56. tightDecode8 (r); break;
  57. case 16:
  58. tightDecode16(r); break;
  59. case 32:
  60. tightDecode32(r); break;
  61. }
  62. }
  63. rdr::U32 TightDecoder::readCompact(rdr::InStream* is)
  64. {
  65. rdr::U8 b;
  66. rdr::U32 result;
  67. b = is->readU8();
  68. result = (int)b & 0x7F;
  69. if (b & 0x80) {
  70. b = is->readU8();
  71. result |= ((int)b & 0x7F) << 7;
  72. if (b & 0x80) {
  73. b = is->readU8();
  74. result |= ((int)b & 0xFF) << 14;
  75. }
  76. }
  77. return result;
  78. }