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.

TightEncoder.h 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* Copyright (C) 2000-2003 Constantin Kaplinsky. All Rights Reserved.
  2. * Copyright (C) 2011 D. R. Commander
  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. #ifndef __RFB_TIGHTENCODER_H__
  20. #define __RFB_TIGHTENCODER_H__
  21. #include <rdr/MemOutStream.h>
  22. #include <rdr/ZlibOutStream.h>
  23. #include <rfb/Encoder.h>
  24. #include <rfb/JpegCompressor.h>
  25. #include <rfb/Palette.h>
  26. // FIXME: Check if specifying extern "C" is really necessary.
  27. #include <stdio.h>
  28. extern "C" {
  29. #include <jpeglib.h>
  30. }
  31. namespace rfb {
  32. class PixelBuffer;
  33. struct TIGHT_CONF {
  34. unsigned int maxRectSize, maxRectWidth;
  35. unsigned int monoMinRectSize;
  36. int idxZlibLevel, monoZlibLevel, rawZlibLevel;
  37. int idxMaxColorsDivisor;
  38. int palMaxColorsWithJPEG;
  39. int jpegQuality;
  40. int jpegSubsampling;
  41. };
  42. //
  43. // Compression level stuff. The following array contains various
  44. // encoder parameters for each of 10 compression levels (0..9).
  45. // Last three parameters correspond to JPEG quality levels (0..9).
  46. //
  47. // NOTE: s_conf[9].maxRectSize should be >= s_conf[i].maxRectSize,
  48. // where i in [0..8]. RequiredBuffSize() method depends on this.
  49. // FIXME: Is this comment obsolete?
  50. //
  51. class TightEncoder : public Encoder {
  52. public:
  53. TightEncoder(SConnection* conn);
  54. virtual ~TightEncoder();
  55. virtual void setCompressLevel(int level);
  56. virtual void setQualityLevel(int level);
  57. virtual void setFineQualityLevel(int quality, int subsampling);
  58. virtual int getNumRects(const Rect &r);
  59. virtual void writeRect(const Rect& r, PixelBuffer* pb);
  60. private:
  61. bool checkSolidTile(Rect& r, rdr::U32* colorPtr, bool needSameColor);
  62. void extendSolidArea(const Rect& r, rdr::U32 colorValue, Rect& er);
  63. void findBestSolidArea(Rect& r, rdr::U32 colorValue, Rect& bestr);
  64. void sendRectSimple(const Rect& r);
  65. void writeSubrect(const Rect& r, bool forceSolid = false);
  66. void writeCompact(rdr::OutStream* os, rdr::U32 value);
  67. void compressData(const void *buf, unsigned int length,
  68. rdr::ZlibOutStream *zos, int zlibLevel,
  69. rdr::OutStream *os);
  70. void fastFillPalette8(const rdr::U8 *data, int stride, const Rect &r);
  71. void fastFillPalette16(const rdr::U16 *data, int stride, const Rect &r);
  72. void fastFillPalette32(const rdr::U32 *data, int stride, const Rect &r);
  73. void fillPalette8(rdr::U8 *data, int count);
  74. void fillPalette16(rdr::U16 *data, int count);
  75. void fillPalette32(rdr::U32 *data, int count);
  76. unsigned int packPixels8(rdr::U8 *buf, unsigned int count);
  77. unsigned int packPixels16(rdr::U16 *buf, unsigned int count);
  78. unsigned int packPixels32(rdr::U32 *buf, unsigned int count);
  79. void tightEncode8(const Rect& r, rdr::OutStream *os, bool forceSolid);
  80. void tightEncode16(const Rect& r, rdr::OutStream *os, bool forceSolid);
  81. void tightEncode32(const Rect& r, rdr::OutStream *os, bool forceSolid);
  82. bool checkSolidTile8(Rect& r, rdr::U32 *colorPtr, bool needSameColor);
  83. bool checkSolidTile16(Rect& r, rdr::U32 *colorPtr, bool needSameColor);
  84. bool checkSolidTile32(Rect& r, rdr::U32 *colorPtr, bool needSameColor);
  85. void encodeSolidRect8(rdr::U8 *buf, rdr::OutStream *os);
  86. void encodeSolidRect16(rdr::U16 *buf, rdr::OutStream *os);
  87. void encodeSolidRect32(rdr::U32 *buf, rdr::OutStream *os);
  88. void encodeFullColorRect8(rdr::U8 *buf, const Rect& r, rdr::OutStream *os);
  89. void encodeFullColorRect16(rdr::U16 *buf, const Rect& r, rdr::OutStream *os);
  90. void encodeFullColorRect32(rdr::U32 *buf, const Rect& r, rdr::OutStream *os);
  91. void encodeMonoRect8(rdr::U8 *buf, const Rect& r, rdr::OutStream *os);
  92. void encodeMonoRect16(rdr::U16 *buf, const Rect& r, rdr::OutStream *os);
  93. void encodeMonoRect32(rdr::U32 *buf, const Rect& r, rdr::OutStream *os);
  94. void encodeIndexedRect16(rdr::U16 *buf, const Rect& r, rdr::OutStream *os);
  95. void encodeIndexedRect32(rdr::U32 *buf, const Rect& r, rdr::OutStream *os);
  96. void encodeJpegRect16(rdr::U16 *buf, int stride, const Rect& r,
  97. rdr::OutStream *os);
  98. void encodeJpegRect32(rdr::U32 *buf, int stride, const Rect& r,
  99. rdr::OutStream *os);
  100. rdr::MemOutStream mos;
  101. rdr::ZlibOutStream zos[4];
  102. JpegCompressor jc;
  103. PixelBuffer *pb;
  104. PixelFormat serverpf, clientpf;
  105. bool pack24;
  106. int palMaxColors;
  107. Palette palette;
  108. static const int defaultCompressLevel;
  109. static const TIGHT_CONF conf[];
  110. const TIGHT_CONF* pconf;
  111. int jpegQuality;
  112. int jpegSubsampling;
  113. };
  114. }
  115. #endif