blob: e135ec0e10dc3aec7fe45b203daf71b76144196b [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
DRCb4a83232011-08-19 04:57:18 +00002 * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
Pierre Ossman316a3242014-01-15 12:40:20 +01003 * Copyright 2014 Pierre Ossman for Cendio AB
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00004 *
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
Pierre Ossmanc0397262014-03-14 15:59:46 +010023#include <rdr/types.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000024#include <rfb/Rect.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000025
26namespace rfb {
Pierre Ossman668468b2014-01-31 12:37:32 +010027 class SConnection;
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020028 class PixelBuffer;
Pierre Ossmanc0397262014-03-14 15:59:46 +010029 class Palette;
30 class PixelFormat;
31
32 enum EncoderFlags {
33 // A constant for encoders that don't need anything special
34 EncoderPlain = 0,
35 // Give us the raw frame buffer, and not something converted to
36 // the what the client is asking for.
37 EncoderUseNativePF = 1 << 0,
Pierre Ossman6b2f1132016-11-30 08:03:35 +010038 // Encoder does not encode pixels perfectly accurate
39 EncoderLossy = 1 << 1,
Pierre Ossmanc0397262014-03-14 15:59:46 +010040 };
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000041
42 class Encoder {
43 public:
Pierre Ossmanc0397262014-03-14 15:59:46 +010044 Encoder(SConnection* conn, int encoding,
Pierre Ossman4694d882018-09-20 10:49:40 +020045 enum EncoderFlags flags, unsigned int maxPaletteSize=-1);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000046 virtual ~Encoder();
47
klemens0536d092017-01-28 20:56:56 +010048 // isSupported() should return a boolean indicating if this encoder
Pierre Ossmanc0397262014-03-14 15:59:46 +010049 // is okay to use with the current connection. This usually involves
50 // checking the list of encodings in the connection parameters.
51 virtual bool isSupported()=0;
52
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000053 virtual void setCompressLevel(int level) {};
54 virtual void setQualityLevel(int level) {};
Pierre Ossmanb948a912014-01-15 13:23:43 +010055 virtual void setFineQualityLevel(int quality, int subsampling) {};
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000056
Pierre Ossmanab9fd6b2018-09-20 10:51:00 +020057 virtual int getCompressLevel() { return -1; };
58 virtual int getQualityLevel() { return -1; };
59
Pierre Ossman717c07b2014-01-21 14:45:10 +010060 // writeRect() is the main interface that encodes the given rectangle
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020061 // with data from the PixelBuffer onto the SConnection given at
Pierre Ossmanc0397262014-03-14 15:59:46 +010062 // encoder creation.
63 //
64 // The PixelBuffer will be in the PixelFormat specified in ConnParams
65 // unless the flag UseNativePF is specified. In that case the
66 // PixelBuffer will remain in its native format and encoder will have
67 // to handle any conversion itself.
68 //
69 // The Palette will always be in the PixelFormat specified in
70 // ConnParams. An empty palette indicates a large number of colours,
71 // but could still be less than maxPaletteSize.
72 virtual void writeRect(const PixelBuffer* pb, const Palette& palette)=0;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000073
Pierre Ossmanc0397262014-03-14 15:59:46 +010074 // writeSolidRect() is a short cut in order to encode single colour
75 // rectangles efficiently without having to create a fake single
76 // colour PixelBuffer. The colour argument follows the same semantics
77 // as the PixelBuffer for writeRect().
78 //
79 // Note that there is a default implementation that can be called
80 // using Encoder::writeSolidRect() in the event that there is no
81 // efficient short cut.
82 virtual void writeSolidRect(int width, int height,
83 const PixelFormat& pf,
84 const rdr::U8* colour)=0;
85
86 protected:
87 // Helper method for redirecting a single colour palette to the
88 // short cut method.
89 void writeSolidRect(const PixelBuffer* pb, const Palette& palette);
90
91 public:
92 const int encoding;
93 const enum EncoderFlags flags;
94
95 // Maximum size of the palette per rect
96 const unsigned int maxPaletteSize;
Pierre Ossman4aba19e2014-01-29 16:42:48 +010097
98 protected:
Pierre Ossman668468b2014-01-31 12:37:32 +010099 SConnection* conn;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000100 };
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000101}
102
103#endif