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.h 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
  3. * Copyright 2014 Pierre Ossman for Cendio AB
  4. *
  5. * This is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This software is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this software; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  18. * USA.
  19. */
  20. #ifndef __RFB_ENCODER_H__
  21. #define __RFB_ENCODER_H__
  22. #include <rdr/types.h>
  23. #include <rfb/Rect.h>
  24. namespace rfb {
  25. class SConnection;
  26. class PixelBuffer;
  27. class Palette;
  28. class PixelFormat;
  29. enum EncoderFlags {
  30. // A constant for encoders that don't need anything special
  31. EncoderPlain = 0,
  32. // Give us the raw frame buffer, and not something converted to
  33. // the what the client is asking for.
  34. EncoderUseNativePF = 1 << 0,
  35. // Encoder does not encode pixels perfectly accurate
  36. EncoderLossy = 1 << 1,
  37. };
  38. class Encoder {
  39. public:
  40. Encoder(SConnection* conn, int encoding,
  41. enum EncoderFlags flags, unsigned int maxPaletteSize=-1,
  42. int losslessQuality=-1);
  43. virtual ~Encoder();
  44. // isSupported() should return a boolean indicating if this encoder
  45. // is okay to use with the current connection. This usually involves
  46. // checking the list of encodings in the connection parameters.
  47. virtual bool isSupported()=0;
  48. virtual void setCompressLevel(int /*level*/) {};
  49. virtual void setQualityLevel(int /*level*/) {};
  50. virtual void setFineQualityLevel(int /*quality*/,
  51. int /*subsampling*/) {};
  52. virtual int getCompressLevel() { return -1; };
  53. virtual int getQualityLevel() { return -1; };
  54. // writeRect() is the main interface that encodes the given rectangle
  55. // with data from the PixelBuffer onto the SConnection given at
  56. // encoder creation.
  57. //
  58. // The PixelBuffer will be in the PixelFormat specified in ConnParams
  59. // unless the flag UseNativePF is specified. In that case the
  60. // PixelBuffer will remain in its native format and encoder will have
  61. // to handle any conversion itself.
  62. //
  63. // The Palette will always be in the PixelFormat specified in
  64. // ConnParams. An empty palette indicates a large number of colours,
  65. // but could still be less than maxPaletteSize.
  66. virtual void writeRect(const PixelBuffer* pb, const Palette& palette)=0;
  67. // writeSolidRect() is a short cut in order to encode single colour
  68. // rectangles efficiently without having to create a fake single
  69. // colour PixelBuffer. The colour argument follows the same semantics
  70. // as the PixelBuffer for writeRect().
  71. //
  72. // Note that there is a default implementation that can be called
  73. // using Encoder::writeSolidRect() in the event that there is no
  74. // efficient short cut.
  75. virtual void writeSolidRect(int width, int height,
  76. const PixelFormat& pf,
  77. const rdr::U8* colour)=0;
  78. protected:
  79. // Helper method for redirecting a single colour palette to the
  80. // short cut method.
  81. void writeSolidRect(const PixelBuffer* pb, const Palette& palette);
  82. public:
  83. const int encoding;
  84. const enum EncoderFlags flags;
  85. // Maximum size of the palette per rect
  86. const unsigned int maxPaletteSize;
  87. // Minimum level where the quality loss will not be noticed by
  88. // most users (only relevant with EncoderLossy flag)
  89. const int losslessQuality;
  90. protected:
  91. SConnection* conn;
  92. };
  93. }
  94. #endif