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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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, const Palette& palette)
  58. {
  59. rdr::OutStream* os = conn->getOutStream();
  60. switch (pb->getPF().bpp) {
  61. case 8:
  62. if (improvedHextile) {
  63. hextileEncodeBetter8(os, pb);
  64. } else {
  65. hextileEncode8(os, pb);
  66. }
  67. break;
  68. case 16:
  69. if (improvedHextile) {
  70. hextileEncodeBetter16(os, pb);
  71. } else {
  72. hextileEncode16(os, pb);
  73. }
  74. break;
  75. case 32:
  76. if (improvedHextile) {
  77. hextileEncodeBetter32(os, pb);
  78. } else {
  79. hextileEncode32(os, pb);
  80. }
  81. break;
  82. }
  83. }
  84. void HextileEncoder::writeSolidRect(int width, int height,
  85. const PixelFormat& pf,
  86. const rdr::U8* colour)
  87. {
  88. rdr::OutStream* os;
  89. int tiles;
  90. os = conn->getOutStream();
  91. tiles = ((width + 15)/16) * ((height + 15)/16);
  92. os->writeU8(hextileBgSpecified);
  93. os->writeBytes(colour, pf.bpp/8);
  94. tiles--;
  95. while (tiles--)
  96. os->writeU8(0);
  97. }