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 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. void HextileDecoder::readRect(const Rect& r, rdr::InStream* is,
  41. const ServerParams& server, rdr::OutStream* os)
  42. {
  43. Rect t;
  44. size_t bytesPerPixel;
  45. bytesPerPixel = server.pf().bpp/8;
  46. for (t.tl.y = r.tl.y; t.tl.y < r.br.y; t.tl.y += 16) {
  47. t.br.y = __rfbmin(r.br.y, t.tl.y + 16);
  48. for (t.tl.x = r.tl.x; t.tl.x < r.br.x; t.tl.x += 16) {
  49. rdr::U8 tileType;
  50. t.br.x = __rfbmin(r.br.x, t.tl.x + 16);
  51. tileType = is->readU8();
  52. os->writeU8(tileType);
  53. if (tileType & hextileRaw) {
  54. os->copyBytes(is, t.area() * bytesPerPixel);
  55. continue;
  56. }
  57. if (tileType & hextileBgSpecified)
  58. os->copyBytes(is, bytesPerPixel);
  59. if (tileType & hextileFgSpecified)
  60. os->copyBytes(is, bytesPerPixel);
  61. if (tileType & hextileAnySubrects) {
  62. rdr::U8 nSubrects;
  63. nSubrects = is->readU8();
  64. os->writeU8(nSubrects);
  65. if (tileType & hextileSubrectsColoured)
  66. os->copyBytes(is, nSubrects * (bytesPerPixel + 2));
  67. else
  68. os->copyBytes(is, nSubrects * 2);
  69. }
  70. }
  71. }
  72. }
  73. void HextileDecoder::decodeRect(const Rect& r, const void* buffer,
  74. size_t buflen, const ServerParams& server,
  75. ModifiablePixelBuffer* pb)
  76. {
  77. rdr::MemInStream is(buffer, buflen);
  78. const PixelFormat& pf = server.pf();
  79. switch (pf.bpp) {
  80. case 8: hextileDecode8 (r, &is, pf, pb); break;
  81. case 16: hextileDecode16(r, &is, pf, pb); break;
  82. case 32: hextileDecode32(r, &is, pf, pb); break;
  83. }
  84. }