Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
DRC | b4a8323 | 2011-08-19 04:57:18 +0000 | [diff] [blame] | 2 | * Copyright (C) 2011 D. R. Commander. All Rights Reserved. |
Pierre Ossman | 316a324 | 2014-01-15 12:40:20 +0100 | [diff] [blame] | 3 | * Copyright 2014 Pierre Ossman for Cendio AB |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 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 | |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 23 | #include <rdr/types.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 24 | #include <rfb/Rect.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 25 | |
| 26 | namespace rfb { |
Pierre Ossman | 668468b | 2014-01-31 12:37:32 +0100 | [diff] [blame] | 27 | class SConnection; |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame] | 28 | class PixelBuffer; |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 29 | 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 Ossman | 6b2f113 | 2016-11-30 08:03:35 +0100 | [diff] [blame] | 38 | // Encoder does not encode pixels perfectly accurate |
| 39 | EncoderLossy = 1 << 1, |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 40 | }; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 41 | |
| 42 | class Encoder { |
| 43 | public: |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 44 | Encoder(SConnection* conn, int encoding, |
Pierre Ossman | beab2b6 | 2018-09-20 10:52:15 +0200 | [diff] [blame] | 45 | enum EncoderFlags flags, unsigned int maxPaletteSize=-1, |
| 46 | int losslessQuality=-1); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 47 | virtual ~Encoder(); |
| 48 | |
klemens | 0536d09 | 2017-01-28 20:56:56 +0100 | [diff] [blame] | 49 | // isSupported() should return a boolean indicating if this encoder |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 50 | // is okay to use with the current connection. This usually involves |
| 51 | // checking the list of encodings in the connection parameters. |
| 52 | virtual bool isSupported()=0; |
| 53 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 54 | virtual void setCompressLevel(int level) {}; |
| 55 | virtual void setQualityLevel(int level) {}; |
Pierre Ossman | b948a91 | 2014-01-15 13:23:43 +0100 | [diff] [blame] | 56 | virtual void setFineQualityLevel(int quality, int subsampling) {}; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 57 | |
Pierre Ossman | ab9fd6b | 2018-09-20 10:51:00 +0200 | [diff] [blame] | 58 | virtual int getCompressLevel() { return -1; }; |
| 59 | virtual int getQualityLevel() { return -1; }; |
| 60 | |
Pierre Ossman | 717c07b | 2014-01-21 14:45:10 +0100 | [diff] [blame] | 61 | // writeRect() is the main interface that encodes the given rectangle |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame] | 62 | // with data from the PixelBuffer onto the SConnection given at |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 63 | // encoder creation. |
| 64 | // |
| 65 | // The PixelBuffer will be in the PixelFormat specified in ConnParams |
| 66 | // unless the flag UseNativePF is specified. In that case the |
| 67 | // PixelBuffer will remain in its native format and encoder will have |
| 68 | // to handle any conversion itself. |
| 69 | // |
| 70 | // The Palette will always be in the PixelFormat specified in |
| 71 | // ConnParams. An empty palette indicates a large number of colours, |
| 72 | // but could still be less than maxPaletteSize. |
| 73 | virtual void writeRect(const PixelBuffer* pb, const Palette& palette)=0; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 74 | |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 75 | // writeSolidRect() is a short cut in order to encode single colour |
| 76 | // rectangles efficiently without having to create a fake single |
| 77 | // colour PixelBuffer. The colour argument follows the same semantics |
| 78 | // as the PixelBuffer for writeRect(). |
| 79 | // |
| 80 | // Note that there is a default implementation that can be called |
| 81 | // using Encoder::writeSolidRect() in the event that there is no |
| 82 | // efficient short cut. |
| 83 | virtual void writeSolidRect(int width, int height, |
| 84 | const PixelFormat& pf, |
| 85 | const rdr::U8* colour)=0; |
| 86 | |
| 87 | protected: |
| 88 | // Helper method for redirecting a single colour palette to the |
| 89 | // short cut method. |
| 90 | void writeSolidRect(const PixelBuffer* pb, const Palette& palette); |
| 91 | |
| 92 | public: |
| 93 | const int encoding; |
| 94 | const enum EncoderFlags flags; |
| 95 | |
| 96 | // Maximum size of the palette per rect |
| 97 | const unsigned int maxPaletteSize; |
Pierre Ossman | 4aba19e | 2014-01-29 16:42:48 +0100 | [diff] [blame] | 98 | |
Pierre Ossman | beab2b6 | 2018-09-20 10:52:15 +0200 | [diff] [blame] | 99 | // Minimum level where the quality loss will not be noticed by |
| 100 | // most users (only relevant with EncoderLossy flag) |
| 101 | const int losslessQuality; |
| 102 | |
Pierre Ossman | 4aba19e | 2014-01-29 16:42:48 +0100 | [diff] [blame] | 103 | protected: |
Pierre Ossman | 668468b | 2014-01-31 12:37:32 +0100 | [diff] [blame] | 104 | SConnection* conn; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 105 | }; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | #endif |