Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

hextileDecode.h 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. //
  19. // Hextile decoding function.
  20. //
  21. // This file is #included after having set the following macro:
  22. // BPP - 8, 16 or 32
  23. #include <rdr/InStream.h>
  24. #include <rfb/hextileConstants.h>
  25. namespace rfb {
  26. // CONCAT2E concatenates its arguments, expanding them if they are macros
  27. #ifndef CONCAT2E
  28. #define CONCAT2(a,b) a##b
  29. #define CONCAT2E(a,b) CONCAT2(a,b)
  30. #endif
  31. #define PIXEL_T rdr::CONCAT2E(U,BPP)
  32. #define READ_PIXEL CONCAT2E(readOpaque,BPP)
  33. #define HEXTILE_DECODE CONCAT2E(hextileDecode,BPP)
  34. void HEXTILE_DECODE (const Rect& r, rdr::InStream* is, PIXEL_T* buf,
  35. const PixelFormat& pf, ModifiablePixelBuffer* pb)
  36. {
  37. Rect t;
  38. PIXEL_T bg = 0;
  39. PIXEL_T fg = 0;
  40. for (t.tl.y = r.tl.y; t.tl.y < r.br.y; t.tl.y += 16) {
  41. t.br.y = __rfbmin(r.br.y, t.tl.y + 16);
  42. for (t.tl.x = r.tl.x; t.tl.x < r.br.x; t.tl.x += 16) {
  43. t.br.x = __rfbmin(r.br.x, t.tl.x + 16);
  44. int tileType = is->readU8();
  45. if (tileType & hextileRaw) {
  46. is->readBytes(buf, t.area() * (BPP/8));
  47. pb->imageRect(pf, t, buf);
  48. continue;
  49. }
  50. if (tileType & hextileBgSpecified)
  51. bg = is->READ_PIXEL();
  52. int len = t.area();
  53. PIXEL_T* ptr = (PIXEL_T*)buf;
  54. while (len-- > 0) *ptr++ = bg;
  55. if (tileType & hextileFgSpecified)
  56. fg = is->READ_PIXEL();
  57. if (tileType & hextileAnySubrects) {
  58. int nSubrects = is->readU8();
  59. for (int i = 0; i < nSubrects; i++) {
  60. if (tileType & hextileSubrectsColoured)
  61. fg = is->READ_PIXEL();
  62. int xy = is->readU8();
  63. int wh = is->readU8();
  64. int x = ((xy >> 4) & 15);
  65. int y = (xy & 15);
  66. int w = ((wh >> 4) & 15) + 1;
  67. int h = (wh & 15) + 1;
  68. PIXEL_T* ptr = (PIXEL_T*)buf + y * t.width() + x;
  69. int rowAdd = t.width() - w;
  70. while (h-- > 0) {
  71. int len = w;
  72. while (len-- > 0) *ptr++ = fg;
  73. ptr += rowAdd;
  74. }
  75. }
  76. }
  77. pb->imageRect(pf, t, buf);
  78. }
  79. }
  80. }
  81. #undef PIXEL_T
  82. #undef READ_PIXEL
  83. #undef HEXTILE_DECODE
  84. }