您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Encoder.cxx 2.3KB

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