blob: 064a8343e1078ee8ce6ef37bfdb6eabb94f7f37a [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2000-2003 Constantin Kaplinsky. All Rights Reserved.
DRCcd2c5d42011-08-11 11:18:34 +00002 * Copyright (C) 2011 D. R. Commander
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00003 *
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>
DRCcd2c5d42011-08-11 11:18:34 +000024#include <rfb/JpegCompressor.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000025#include <rfb/Encoder.h>
26
27// FIXME: Check if specifying extern "C" is really necessary.
28#include <stdio.h>
29extern "C" {
Constantin Kaplinskye19ac6d2006-05-30 06:15:20 +000030#include <jpeglib.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000031}
32
33namespace rfb {
34
35 struct TIGHT_CONF {
36 unsigned int maxRectSize, maxRectWidth;
37 unsigned int monoMinRectSize;
38 int idxZlibLevel, monoZlibLevel, rawZlibLevel;
39 int idxMaxColorsDivisor;
DRCcd2c5d42011-08-11 11:18:34 +000040 int palMaxColorsWithJPEG;
DRC773cf3c2009-03-12 19:26:44 +000041 int jpegQuality;
DRCcd2c5d42011-08-11 11:18:34 +000042 JPEG_SUBSAMP jpegSubSample;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000043 };
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);
DRCcd2c5d42011-08-11 11:18:34 +000067 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 Kaplinskya2adc8d2006-05-25 05:01:55 +000075
76 SMsgWriter* writer;
77 rdr::MemOutStream mos;
78 rdr::ZlibOutStream zos[4];
DRCcd2c5d42011-08-11 11:18:34 +000079 JpegCompressor jc;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000080
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