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.

HextileDecoder.cxx 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. #include <rdr/InStream.h>
  19. #include <rdr/MemInStream.h>
  20. #include <rdr/OutStream.h>
  21. #include <rfb/ServerParams.h>
  22. #include <rfb/PixelBuffer.h>
  23. #include <rfb/HextileDecoder.h>
  24. using namespace rfb;
  25. #define BPP 8
  26. #include <rfb/hextileDecode.h>
  27. #undef BPP
  28. #define BPP 16
  29. #include <rfb/hextileDecode.h>
  30. #undef BPP
  31. #define BPP 32
  32. #include <rfb/hextileDecode.h>
  33. #undef BPP
  34. HextileDecoder::HextileDecoder() : Decoder(DecoderPlain)
  35. {
  36. }
  37. HextileDecoder::~HextileDecoder()
  38. {
  39. }
  40. bool HextileDecoder::readRect(const Rect& r, rdr::InStream* is,
  41. const ServerParams& server, rdr::OutStream* os)
  42. {
  43. Rect t;
  44. size_t bytesPerPixel;
  45. is->setRestorePoint();
  46. bytesPerPixel = server.pf().bpp/8;
  47. for (t.tl.y = r.tl.y; t.tl.y < r.br.y; t.tl.y += 16) {
  48. t.br.y = __rfbmin(r.br.y, t.tl.y + 16);
  49. for (t.tl.x = r.tl.x; t.tl.x < r.br.x; t.tl.x += 16) {
  50. rdr::U8 tileType;
  51. t.br.x = __rfbmin(r.br.x, t.tl.x + 16);
  52. if (!is->hasDataOrRestore(1))
  53. return false;
  54. tileType = is->readU8();
  55. os->writeU8(tileType);
  56. if (tileType & hextileRaw) {
  57. if (!is->hasDataOrRestore(t.area() * bytesPerPixel))
  58. return false;
  59. os->copyBytes(is, t.area() * bytesPerPixel);
  60. continue;
  61. }
  62. if (tileType & hextileBgSpecified) {
  63. if (!is->hasDataOrRestore(bytesPerPixel))
  64. return false;
  65. os->copyBytes(is, bytesPerPixel);
  66. }
  67. if (tileType & hextileFgSpecified) {
  68. if (!is->hasDataOrRestore(bytesPerPixel))
  69. return false;
  70. os->copyBytes(is, bytesPerPixel);
  71. }
  72. if (tileType & hextileAnySubrects) {
  73. rdr::U8 nSubrects;
  74. if (!is->hasDataOrRestore(1))
  75. return false;
  76. nSubrects = is->readU8();
  77. os->writeU8(nSubrects);
  78. if (tileType & hextileSubrectsColoured) {
  79. if (!is->hasDataOrRestore(nSubrects * (bytesPerPixel + 2)))
  80. return false;
  81. os->copyBytes(is, nSubrects * (bytesPerPixel + 2));
  82. } else {
  83. if (!is->hasDataOrRestore(nSubrects * 2))
  84. return false;
  85. os->copyBytes(is, nSubrects * 2);
  86. }
  87. }
  88. }
  89. }
  90. is->clearRestorePoint();
  91. return true;
  92. }
  93. void HextileDecoder::decodeRect(const Rect& r, const void* buffer,
  94. size_t buflen, const ServerParams& server,
  95. ModifiablePixelBuffer* pb)
  96. {
  97. rdr::MemInStream is(buffer, buflen);
  98. const PixelFormat& pf = server.pf();
  99. switch (pf.bpp) {
  100. case 8: hextileDecode8 (r, &is, pf, pb); break;
  101. case 16: hextileDecode16(r, &is, pf, pb); break;
  102. case 32: hextileDecode32(r, &is, pf, pb); break;
  103. }
  104. }