blob: 1b86986fe061f8cfbfeccc2fa968fbb820ba71a7 [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>
19#include <rfb/ImageGetter.h>
20#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
36Encoder* RREEncoder::create(SMsgWriter* writer)
37{
38 return new RREEncoder(writer);
39}
40
41RREEncoder::RREEncoder(SMsgWriter* writer_) : writer(writer_)
42{
43}
44
45RREEncoder::~RREEncoder()
46{
47}
48
DRCffe09d62011-08-17 02:27:59 +000049bool RREEncoder::writeRect(const Rect& r, TransImageGetter* ig, Rect* actual)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000050{
51 int w = r.width();
52 int h = r.height();
53 rdr::U8* imageBuf = writer->getImageBuf(w*h);
54 ig->getImage(imageBuf, r);
55
56 mos.clear();
57
58 int nSubrects = -1;
59 switch (writer->bpp()) {
60 case 8: nSubrects = rreEncode8(imageBuf, w, h, &mos); break;
61 case 16: nSubrects = rreEncode16(imageBuf, w, h, &mos); break;
62 case 32: nSubrects = rreEncode32(imageBuf, w, h, &mos); break;
63 }
64
65 if (nSubrects < 0) {
66 return writer->writeRect(r, encodingRaw, ig, actual);
67 }
68
69 writer->startRect(r, encodingRRE);
70 rdr::OutStream* os = writer->getOutStream();
71 os->writeU32(nSubrects);
72 os->writeBytes(mos.data(), mos.length());
73 writer->endRect();
74 return true;
75}