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.

RREEncoder.cxx 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2014 Pierre Ossman for Cendio AB
  3. *
  4. * This is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This software is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this software; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  17. * USA.
  18. */
  19. #ifdef HAVE_CONFIG_H
  20. #include <config.h>
  21. #endif
  22. #include <rdr/OutStream.h>
  23. #include <rfb/encodings.h>
  24. #include <rfb/SConnection.h>
  25. #include <rfb/PixelFormat.h>
  26. #include <rfb/PixelBuffer.h>
  27. #include <rfb/Palette.h>
  28. #include <rfb/RREEncoder.h>
  29. using namespace rfb;
  30. #define BPP 8
  31. #include <rfb/rreEncode.h>
  32. #undef BPP
  33. #define BPP 16
  34. #include <rfb/rreEncode.h>
  35. #undef BPP
  36. #define BPP 32
  37. #include <rfb/rreEncode.h>
  38. #undef BPP
  39. RREEncoder::RREEncoder(SConnection* conn) :
  40. Encoder(conn, encodingRRE, EncoderPlain)
  41. {
  42. }
  43. RREEncoder::~RREEncoder()
  44. {
  45. }
  46. bool RREEncoder::isSupported()
  47. {
  48. return conn->client.supportsEncoding(encodingRRE);
  49. }
  50. void RREEncoder::writeRect(const PixelBuffer* pb, const Palette& palette)
  51. {
  52. rdr::U8* imageBuf;
  53. int stride;
  54. rdr::U32 bg;
  55. int w = pb->width();
  56. int h = pb->height();
  57. if (palette.size() == 1) {
  58. Encoder::writeSolidRect(pb, palette);
  59. return;
  60. }
  61. // We have to have our own copy of the data as we modify it as
  62. // we find subrects.
  63. bufferCopy.setPF(pb->getPF());
  64. bufferCopy.setSize(w, h);
  65. imageBuf = bufferCopy.getBufferRW(pb->getRect(), &stride);
  66. pb->getImage(imageBuf, pb->getRect());
  67. if (palette.size() > 0)
  68. bg = palette.getColour(0);
  69. else {
  70. // Some crazy person is using this encoder for high colour
  71. // data. Just pick the first pixel as the background colour.
  72. bg = 0;
  73. memcpy(&bg, imageBuf, pb->getPF().bpp/8);
  74. }
  75. int nSubrects = -1;
  76. switch (pb->getPF().bpp) {
  77. case 8:
  78. nSubrects = rreEncode8((rdr::U8*)imageBuf, w, h, &mos, bg);
  79. break;
  80. case 16:
  81. nSubrects = rreEncode16((rdr::U16*)imageBuf, w, h, &mos, bg);
  82. break;
  83. case 32:
  84. nSubrects = rreEncode32((rdr::U32*)imageBuf, w, h, &mos, bg);
  85. break;
  86. }
  87. bufferCopy.commitBufferRW(pb->getRect());
  88. rdr::OutStream* os = conn->getOutStream();
  89. os->writeU32(nSubrects);
  90. os->writeBytes(mos.data(), mos.length());
  91. mos.clear();
  92. }
  93. void RREEncoder::writeSolidRect(int /*width*/, int /*height*/,
  94. const PixelFormat& pf,
  95. const rdr::U8* colour)
  96. {
  97. rdr::OutStream* os;
  98. os = conn->getOutStream();
  99. os->writeU32(0);
  100. os->writeBytes(colour, pf.bpp/8);
  101. }