Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2000-2003 Constantin Kaplinsky. All Rights Reserved. |
DRC | cd2c5d4 | 2011-08-11 11:18:34 +0000 | [diff] [blame] | 2 | * Copyright (C) 2011 D. R. Commander |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 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 | |
| 22 | #include <rdr/MemOutStream.h> |
| 23 | #include <rdr/ZlibOutStream.h> |
DRC | cd2c5d4 | 2011-08-11 11:18:34 +0000 | [diff] [blame] | 24 | #include <rfb/JpegCompressor.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 25 | #include <rfb/Encoder.h> |
| 26 | |
| 27 | // FIXME: Check if specifying extern "C" is really necessary. |
| 28 | #include <stdio.h> |
| 29 | extern "C" { |
Constantin Kaplinsky | e19ac6d | 2006-05-30 06:15:20 +0000 | [diff] [blame] | 30 | #include <jpeglib.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | namespace rfb { |
| 34 | |
| 35 | struct TIGHT_CONF { |
| 36 | unsigned int maxRectSize, maxRectWidth; |
| 37 | unsigned int monoMinRectSize; |
| 38 | int idxZlibLevel, monoZlibLevel, rawZlibLevel; |
| 39 | int idxMaxColorsDivisor; |
DRC | cd2c5d4 | 2011-08-11 11:18:34 +0000 | [diff] [blame] | 40 | int palMaxColorsWithJPEG; |
DRC | 773cf3c | 2009-03-12 19:26:44 +0000 | [diff] [blame] | 41 | int jpegQuality; |
DRC | cd2c5d4 | 2011-08-11 11:18:34 +0000 | [diff] [blame] | 42 | JPEG_SUBSAMP jpegSubSample; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | // |
| 46 | // Compression level stuff. The following array contains various |
| 47 | // encoder parameters for each of 10 compression levels (0..9). |
| 48 | // Last three parameters correspond to JPEG quality levels (0..9). |
| 49 | // |
| 50 | // NOTE: s_conf[9].maxRectSize should be >= s_conf[i].maxRectSize, |
| 51 | // where i in [0..8]. RequiredBuffSize() method depends on this. |
| 52 | // FIXME: Is this comment obsolete? |
| 53 | // |
| 54 | |
| 55 | |
| 56 | class TightEncoder : public Encoder { |
| 57 | public: |
| 58 | static Encoder* create(SMsgWriter* writer); |
| 59 | virtual void setCompressLevel(int level); |
| 60 | virtual void setQualityLevel(int level); |
| 61 | virtual int getNumRects(const Rect &r); |
| 62 | virtual bool writeRect(const Rect& r, ImageGetter* ig, Rect* actual); |
| 63 | virtual ~TightEncoder(); |
| 64 | |
| 65 | private: |
| 66 | TightEncoder(SMsgWriter* writer); |
DRC | cd2c5d4 | 2011-08-11 11:18:34 +0000 | [diff] [blame] | 67 | bool checkSolidTile(Rect& r, ImageGetter *ig, rdr::U32* colorPtr, |
| 68 | bool needSameColor); |
| 69 | void extendSolidArea(const Rect& r, ImageGetter *ig, |
| 70 | rdr::U32 colorValue, Rect& er); |
| 71 | void findBestSolidArea(Rect& r, ImageGetter* ig, rdr::U32 colorValue, |
| 72 | Rect& bestr); |
| 73 | void sendRectSimple(const Rect& r, ImageGetter* ig); |
| 74 | void writeSubrect(const Rect& r, ImageGetter* ig, bool forceSolid = false); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 75 | |
| 76 | SMsgWriter* writer; |
| 77 | rdr::MemOutStream mos; |
| 78 | rdr::ZlibOutStream zos[4]; |
DRC | cd2c5d4 | 2011-08-11 11:18:34 +0000 | [diff] [blame] | 79 | JpegCompressor jc; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 80 | |
| 81 | static const int defaultCompressLevel; |
| 82 | static const TIGHT_CONF conf[]; |
| 83 | |
| 84 | const TIGHT_CONF* pconf; |
| 85 | const TIGHT_CONF* pjconf; |
| 86 | }; |
| 87 | |
| 88 | } |
| 89 | |
| 90 | #endif |