blob: 36d4695514003ad8cf1a92d89b06bede51d79720 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18#include <rdr/OutStream.h>
Pierre Ossman456b2c22014-01-15 13:22:03 +010019#include <rfb/TransImageGetter.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000020#include <rfb/encodings.h>
21#include <rfb/SMsgWriter.h>
22#include <rfb/RREEncoder.h>
23
24using namespace rfb;
25
26#define BPP 8
27#include <rfb/rreEncode.h>
28#undef BPP
29#define BPP 16
30#include <rfb/rreEncode.h>
31#undef BPP
32#define BPP 32
33#include <rfb/rreEncode.h>
34#undef BPP
35
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000036RREEncoder::RREEncoder(SMsgWriter* writer_) : writer(writer_)
37{
38}
39
40RREEncoder::~RREEncoder()
41{
42}
43
DRCffe09d62011-08-17 02:27:59 +000044bool RREEncoder::writeRect(const Rect& r, TransImageGetter* ig, Rect* actual)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000045{
46 int w = r.width();
47 int h = r.height();
48 rdr::U8* imageBuf = writer->getImageBuf(w*h);
49 ig->getImage(imageBuf, r);
50
51 mos.clear();
52
53 int nSubrects = -1;
54 switch (writer->bpp()) {
55 case 8: nSubrects = rreEncode8(imageBuf, w, h, &mos); break;
56 case 16: nSubrects = rreEncode16(imageBuf, w, h, &mos); break;
57 case 32: nSubrects = rreEncode32(imageBuf, w, h, &mos); break;
58 }
59
60 if (nSubrects < 0) {
61 return writer->writeRect(r, encodingRaw, ig, actual);
62 }
63
64 writer->startRect(r, encodingRRE);
65 rdr::OutStream* os = writer->getOutStream();
66 os->writeU32(nSubrects);
67 os->writeBytes(mos.data(), mos.length());
68 writer->endRect();
69 return true;
70}