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.

Encoder.cxx 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 <rfb/Encoder.h>
  20. #include <rfb/PixelBuffer.h>
  21. #include <rfb/Palette.h>
  22. using namespace rfb;
  23. Encoder::Encoder(SConnection *conn_, int encoding_,
  24. enum EncoderFlags flags_, unsigned int maxPaletteSize_) :
  25. encoding(encoding_), flags(flags_),
  26. maxPaletteSize(maxPaletteSize_), conn(conn_)
  27. {
  28. }
  29. Encoder::~Encoder()
  30. {
  31. }
  32. void Encoder::writeSolidRect(int width, int height,
  33. const PixelFormat& pf, const rdr::U8* colour)
  34. {
  35. ManagedPixelBuffer buffer(pf, width, height);
  36. Palette palette;
  37. rdr::U32 palcol;
  38. buffer.fillRect(buffer.getRect(), colour);
  39. palcol = 0;
  40. memcpy(&palcol, colour, pf.bpp/8);
  41. palette.insert(palcol, 1);
  42. writeRect(&buffer, palette);
  43. }
  44. void Encoder::writeSolidRect(const PixelBuffer* pb, const Palette& palette)
  45. {
  46. rdr::U32 col32;
  47. rdr::U16 col16;
  48. rdr::U8 col8;
  49. rdr::U8* buffer;
  50. assert(palette.size() == 1);
  51. // The Palette relies on implicit up and down conversion
  52. switch (pb->getPF().bpp) {
  53. case 32:
  54. col32 = (rdr::U32)palette.getColour(0);
  55. buffer = (rdr::U8*)&col32;
  56. break;
  57. case 16:
  58. col16 = (rdr::U16)palette.getColour(0);
  59. buffer = (rdr::U8*)&col16;
  60. break;
  61. default:
  62. col8 = (rdr::U8)palette.getColour(0);
  63. buffer = (rdr::U8*)&col8;
  64. break;
  65. }
  66. writeSolidRect(pb->width(), pb->height(), pb->getPF(), buffer);
  67. }