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

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