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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. #ifdef HAVE_CONFIG_H
  19. #include <config.h>
  20. #endif
  21. #include <rdr/InStream.h>
  22. #include <rdr/MemInStream.h>
  23. #include <rdr/OutStream.h>
  24. #include <rfb/ServerParams.h>
  25. #include <rfb/PixelBuffer.h>
  26. #include <rfb/HextileDecoder.h>
  27. using namespace rfb;
  28. #define BPP 8
  29. #include <rfb/hextileDecode.h>
  30. #undef BPP
  31. #define BPP 16
  32. #include <rfb/hextileDecode.h>
  33. #undef BPP
  34. #define BPP 32
  35. #include <rfb/hextileDecode.h>
  36. #undef BPP
  37. HextileDecoder::HextileDecoder() : Decoder(DecoderPlain)
  38. {
  39. }
  40. HextileDecoder::~HextileDecoder()
  41. {
  42. }
  43. bool HextileDecoder::readRect(const Rect& r, rdr::InStream* is,
  44. const ServerParams& server, rdr::OutStream* os)
  45. {
  46. Rect t;
  47. size_t bytesPerPixel;
  48. is->setRestorePoint();
  49. bytesPerPixel = server.pf().bpp/8;
  50. for (t.tl.y = r.tl.y; t.tl.y < r.br.y; t.tl.y += 16) {
  51. t.br.y = __rfbmin(r.br.y, t.tl.y + 16);
  52. for (t.tl.x = r.tl.x; t.tl.x < r.br.x; t.tl.x += 16) {
  53. rdr::U8 tileType;
  54. t.br.x = __rfbmin(r.br.x, t.tl.x + 16);
  55. if (!is->hasDataOrRestore(1))
  56. return false;
  57. tileType = is->readU8();
  58. os->writeU8(tileType);
  59. if (tileType & hextileRaw) {
  60. if (!is->hasDataOrRestore(t.area() * bytesPerPixel))
  61. return false;
  62. os->copyBytes(is, t.area() * bytesPerPixel);
  63. continue;
  64. }
  65. if (tileType & hextileBgSpecified) {
  66. if (!is->hasDataOrRestore(bytesPerPixel))
  67. return false;
  68. os->copyBytes(is, bytesPerPixel);
  69. }
  70. if (tileType & hextileFgSpecified) {
  71. if (!is->hasDataOrRestore(bytesPerPixel))
  72. return false;
  73. os->copyBytes(is, bytesPerPixel);
  74. }
  75. if (tileType & hextileAnySubrects) {
  76. rdr::U8 nSubrects;
  77. if (!is->hasDataOrRestore(1))
  78. return false;
  79. nSubrects = is->readU8();
  80. os->writeU8(nSubrects);
  81. if (tileType & hextileSubrectsColoured) {
  82. if (!is->hasDataOrRestore(nSubrects * (bytesPerPixel + 2)))
  83. return false;
  84. os->copyBytes(is, nSubrects * (bytesPerPixel + 2));
  85. } else {
  86. if (!is->hasDataOrRestore(nSubrects * 2))
  87. return false;
  88. os->copyBytes(is, nSubrects * 2);
  89. }
  90. }
  91. }
  92. }
  93. is->clearRestorePoint();
  94. return true;
  95. }
  96. void HextileDecoder::decodeRect(const Rect& r, const void* buffer,
  97. size_t buflen, const ServerParams& server,
  98. ModifiablePixelBuffer* pb)
  99. {
  100. rdr::MemInStream is(buffer, buflen);
  101. const PixelFormat& pf = server.pf();
  102. switch (pf.bpp) {
  103. case 8: hextileDecode8 (r, &is, pf, pb); break;
  104. case 16: hextileDecode16(r, &is, pf, pb); break;
  105. case 32: hextileDecode32(r, &is, pf, pb); break;
  106. }
  107. }