blob: 515104e5f7bbe07c01148003c558df4916dc16c3 [file] [log] [blame]
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00001/* Copyright (C) 2002-2004 RealVNC Ltd. All Rights Reserved.
Constantin Kaplinskyc7e67f82005-09-09 21:26:21 +00002 * Copyright (C) 2005 Constantin Kaplinsky. All Rights Reserved.
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +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#include <rfb/ImageGetter.h>
20#include <rfb/encodings.h>
21#include <rfb/SMsgWriter.h>
22#include <rfb/HextileEncoder.h>
Constantin Kaplinskyc7e67f82005-09-09 21:26:21 +000023#include <rfb/Configuration.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000024
25using namespace rfb;
26
Constantin Kaplinskyc7e67f82005-09-09 21:26:21 +000027BoolParameter improvedHextile("ImprovedHextile",
28 "Use improved compression algorithm for Hextile "
29 "encoding which achieves better compression "
30 "ratios by the cost of using more CPU time",
31 false);
32
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000033#define EXTRA_ARGS ImageGetter* ig
34#define GET_IMAGE_INTO_BUF(r,buf) ig->getImage(buf, r);
35#define BPP 8
Constantin Kaplinskyc7e67f82005-09-09 21:26:21 +000036#include <rfb/hextileEncodeBetter.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000037#undef BPP
38#define BPP 16
39#include <rfb/hextileEncode.h>
Constantin Kaplinskyc7e67f82005-09-09 21:26:21 +000040#include <rfb/hextileEncodeBetter.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000041#undef BPP
42#define BPP 32
43#include <rfb/hextileEncode.h>
Constantin Kaplinskyc7e67f82005-09-09 21:26:21 +000044#include <rfb/hextileEncodeBetter.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000045#undef BPP
46
47Encoder* HextileEncoder::create(SMsgWriter* writer)
48{
49 return new HextileEncoder(writer);
50}
51
52HextileEncoder::HextileEncoder(SMsgWriter* writer_) : writer(writer_)
53{
54}
55
56HextileEncoder::~HextileEncoder()
57{
58}
59
60bool HextileEncoder::writeRect(const Rect& r, ImageGetter* ig, Rect* actual)
61{
62 writer->startRect(r, encodingHextile);
63 rdr::OutStream* os = writer->getOutStream();
64 switch (writer->bpp()) {
Constantin Kaplinskyc7e67f82005-09-09 21:26:21 +000065 case 8:
66 // NOTE: We always use improved Hextile for 8-bit data.
67 hextileEncodeBetter8(r, os, ig);
68 break;
69 case 16:
70 if (improvedHextile) {
71 hextileEncodeBetter16(r, os, ig);
72 } else {
73 hextileEncode16(r, os, ig);
74 }
75 break;
76 case 32:
77 if (improvedHextile) {
78 hextileEncodeBetter32(r, os, ig);
79 } else {
80 hextileEncode32(r, os, ig);
81 }
82 break;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000083 }
84 writer->endRect();
85 return true;
86}