blob: ba71d56d95b0efef990b41ff8b675285a45caa5c [file] [log] [blame]
Constantin Kaplinskyde179d42006-04-16 06:53:44 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Constantin Kaplinskyc7e67f82005-09-09 21:26:21 +00002 * Copyright (C) 2005 Constantin Kaplinsky. All Rights Reserved.
Constantin Kaplinskyde179d42006-04-16 06:53:44 +00003 *
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00004 * 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",
Constantin Kaplinsky5ca3e872005-09-27 18:26:16 +000031 true);
Constantin Kaplinskyc7e67f82005-09-09 21:26:21 +000032
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 Kaplinsky5ca3e872005-09-27 18:26:16 +000036#include <rfb/hextileEncode.h>
Constantin Kaplinskyc7e67f82005-09-09 21:26:21 +000037#include <rfb/hextileEncodeBetter.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000038#undef BPP
39#define BPP 16
40#include <rfb/hextileEncode.h>
Constantin Kaplinskyc7e67f82005-09-09 21:26:21 +000041#include <rfb/hextileEncodeBetter.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000042#undef BPP
43#define BPP 32
44#include <rfb/hextileEncode.h>
Constantin Kaplinskyc7e67f82005-09-09 21:26:21 +000045#include <rfb/hextileEncodeBetter.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000046#undef BPP
47
48Encoder* HextileEncoder::create(SMsgWriter* writer)
49{
50 return new HextileEncoder(writer);
51}
52
53HextileEncoder::HextileEncoder(SMsgWriter* writer_) : writer(writer_)
54{
55}
56
57HextileEncoder::~HextileEncoder()
58{
59}
60
61bool HextileEncoder::writeRect(const Rect& r, ImageGetter* ig, Rect* actual)
62{
63 writer->startRect(r, encodingHextile);
64 rdr::OutStream* os = writer->getOutStream();
65 switch (writer->bpp()) {
Constantin Kaplinskyc7e67f82005-09-09 21:26:21 +000066 case 8:
Constantin Kaplinsky5ca3e872005-09-27 18:26:16 +000067 if (improvedHextile) {
68 hextileEncodeBetter8(r, os, ig);
69 } else {
70 hextileEncode8(r, os, ig);
71 }
Constantin Kaplinskyc7e67f82005-09-09 21:26:21 +000072 break;
73 case 16:
74 if (improvedHextile) {
75 hextileEncodeBetter16(r, os, ig);
76 } else {
77 hextileEncode16(r, os, ig);
78 }
79 break;
80 case 32:
81 if (improvedHextile) {
82 hextileEncodeBetter32(r, os, ig);
83 } else {
84 hextileEncode32(r, os, ig);
85 }
86 break;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000087 }
88 writer->endRect();
89 return true;
90}