blob: 58cf7414e9e5cec2f613355f29f0bfadb20fa3d8 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 * Copyright (C) 2005 Constantin Kaplinsky. All Rights Reserved.
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 */
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000019#include <rfb/encodings.h>
20#include <rfb/SMsgWriter.h>
Pierre Ossman668468b2014-01-31 12:37:32 +010021#include <rfb/SConnection.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000022#include <rfb/HextileEncoder.h>
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020023#include <rfb/PixelFormat.h>
24#include <rfb/PixelBuffer.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000025#include <rfb/Configuration.h>
26
27using namespace rfb;
28
29BoolParameter improvedHextile("ImprovedHextile",
30 "Use improved compression algorithm for Hextile "
31 "encoding which achieves better compression "
32 "ratios by the cost of using more CPU time",
33 true);
34
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000035#define BPP 8
36#include <rfb/hextileEncode.h>
37#include <rfb/hextileEncodeBetter.h>
38#undef BPP
39#define BPP 16
40#include <rfb/hextileEncode.h>
41#include <rfb/hextileEncodeBetter.h>
42#undef BPP
43#define BPP 32
44#include <rfb/hextileEncode.h>
45#include <rfb/hextileEncodeBetter.h>
46#undef BPP
47
Pierre Ossman668468b2014-01-31 12:37:32 +010048HextileEncoder::HextileEncoder(SConnection* conn) : Encoder(conn)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000049{
50}
51
52HextileEncoder::~HextileEncoder()
53{
54}
55
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020056void HextileEncoder::writeRect(const Rect& r, PixelBuffer* pb)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000057{
Pierre Ossman668468b2014-01-31 12:37:32 +010058 conn->writer()->startRect(r, encodingHextile);
59 rdr::OutStream* os = conn->getOutStream();
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020060 const PixelFormat& pf = conn->cp.pf();
61 switch (pf.bpp) {
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000062 case 8:
63 if (improvedHextile) {
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020064 hextileEncodeBetter8(r, os, pf, pb);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000065 } else {
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020066 hextileEncode8(r, os, pf, pb);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000067 }
68 break;
69 case 16:
70 if (improvedHextile) {
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020071 hextileEncodeBetter16(r, os, pf, pb);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000072 } else {
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020073 hextileEncode16(r, os, pf, pb);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000074 }
75 break;
76 case 32:
77 if (improvedHextile) {
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020078 hextileEncodeBetter32(r, os, pf, pb);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000079 } else {
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020080 hextileEncode32(r, os, pf, pb);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000081 }
82 break;
83 }
Pierre Ossman668468b2014-01-31 12:37:32 +010084 conn->writer()->endRect();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000085}