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.

HextileEncoder.cxx 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright (C) 2005 Constantin Kaplinsky. All Rights Reserved.
  3. * Copyright 2014 Pierre Ossman for Cendio AB
  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/encodings.h>
  21. #include <rfb/SConnection.h>
  22. #include <rfb/HextileEncoder.h>
  23. #include <rfb/PixelBuffer.h>
  24. #include <rfb/Configuration.h>
  25. using namespace rfb;
  26. BoolParameter improvedHextile("ImprovedHextile",
  27. "Use improved compression algorithm for Hextile "
  28. "encoding which achieves better compression "
  29. "ratios by the cost of using more CPU time",
  30. true);
  31. #define BPP 8
  32. #include <rfb/hextileEncode.h>
  33. #include <rfb/hextileEncodeBetter.h>
  34. #undef BPP
  35. #define BPP 16
  36. #include <rfb/hextileEncode.h>
  37. #include <rfb/hextileEncodeBetter.h>
  38. #undef BPP
  39. #define BPP 32
  40. #include <rfb/hextileEncode.h>
  41. #include <rfb/hextileEncodeBetter.h>
  42. #undef BPP
  43. HextileEncoder::HextileEncoder(SConnection* conn) :
  44. Encoder(conn, encodingHextile, EncoderPlain)
  45. {
  46. }
  47. HextileEncoder::~HextileEncoder()
  48. {
  49. }
  50. bool HextileEncoder::isSupported()
  51. {
  52. return conn->client.supportsEncoding(encodingHextile);
  53. }
  54. void HextileEncoder::writeRect(const PixelBuffer* pb, const Palette& palette)
  55. {
  56. rdr::OutStream* os = conn->getOutStream();
  57. switch (pb->getPF().bpp) {
  58. case 8:
  59. if (improvedHextile) {
  60. hextileEncodeBetter8(os, pb);
  61. } else {
  62. hextileEncode8(os, pb);
  63. }
  64. break;
  65. case 16:
  66. if (improvedHextile) {
  67. hextileEncodeBetter16(os, pb);
  68. } else {
  69. hextileEncode16(os, pb);
  70. }
  71. break;
  72. case 32:
  73. if (improvedHextile) {
  74. hextileEncodeBetter32(os, pb);
  75. } else {
  76. hextileEncode32(os, pb);
  77. }
  78. break;
  79. }
  80. }
  81. void HextileEncoder::writeSolidRect(int width, int height,
  82. const PixelFormat& pf,
  83. const rdr::U8* colour)
  84. {
  85. rdr::OutStream* os;
  86. int tiles;
  87. os = conn->getOutStream();
  88. tiles = ((width + 15)/16) * ((height + 15)/16);
  89. os->writeU8(hextileBgSpecified);
  90. os->writeBytes(colour, pf.bpp/8);
  91. tiles--;
  92. while (tiles--)
  93. os->writeU8(0);
  94. }