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.9KB

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