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 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. #include <rdr/OutStream.h>
  20. #include <rfb/encodings.h>
  21. #include <rfb/SConnection.h>
  22. #include <rfb/PixelFormat.h>
  23. #include <rfb/PixelBuffer.h>
  24. #include <rfb/Palette.h>
  25. #include <rfb/RREEncoder.h>
  26. using namespace rfb;
  27. #define BPP 8
  28. #include <rfb/rreEncode.h>
  29. #undef BPP
  30. #define BPP 16
  31. #include <rfb/rreEncode.h>
  32. #undef BPP
  33. #define BPP 32
  34. #include <rfb/rreEncode.h>
  35. #undef BPP
  36. RREEncoder::RREEncoder(SConnection* conn) :
  37. Encoder(conn, encodingRRE, EncoderPlain)
  38. {
  39. }
  40. RREEncoder::~RREEncoder()
  41. {
  42. }
  43. bool RREEncoder::isSupported()
  44. {
  45. return conn->client.supportsEncoding(encodingRRE);
  46. }
  47. void RREEncoder::writeRect(const PixelBuffer* pb, const Palette& palette)
  48. {
  49. rdr::U8* imageBuf;
  50. int stride;
  51. rdr::U32 bg;
  52. int w = pb->width();
  53. int h = pb->height();
  54. if (palette.size() == 1) {
  55. Encoder::writeSolidRect(pb, palette);
  56. return;
  57. }
  58. // We have to have our own copy of the data as we modify it as
  59. // we find subrects.
  60. bufferCopy.setPF(pb->getPF());
  61. bufferCopy.setSize(w, h);
  62. imageBuf = bufferCopy.getBufferRW(pb->getRect(), &stride);
  63. pb->getImage(imageBuf, pb->getRect());
  64. if (palette.size() > 0)
  65. bg = palette.getColour(0);
  66. else {
  67. // Some crazy person is using this encoder for high colour
  68. // data. Just pick the first pixel as the background colour.
  69. bg = 0;
  70. memcpy(&bg, imageBuf, pb->getPF().bpp/8);
  71. }
  72. int nSubrects = -1;
  73. switch (pb->getPF().bpp) {
  74. case 8:
  75. nSubrects = rreEncode8((rdr::U8*)imageBuf, w, h, &mos, bg);
  76. break;
  77. case 16:
  78. nSubrects = rreEncode16((rdr::U16*)imageBuf, w, h, &mos, bg);
  79. break;
  80. case 32:
  81. nSubrects = rreEncode32((rdr::U32*)imageBuf, w, h, &mos, bg);
  82. break;
  83. }
  84. bufferCopy.commitBufferRW(pb->getRect());
  85. rdr::OutStream* os = conn->getOutStream();
  86. os->writeU32(nSubrects);
  87. os->writeBytes(mos.data(), mos.length());
  88. mos.clear();
  89. }
  90. void RREEncoder::writeSolidRect(int width, int height,
  91. const PixelFormat& pf,
  92. const rdr::U8* colour)
  93. {
  94. rdr::OutStream* os;
  95. os = conn->getOutStream();
  96. os->writeU32(0);
  97. os->writeBytes(colour, pf.bpp/8);
  98. }