blob: d1412d4a12908e2376b927ec659790beef9c1f26 [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 */
Pierre Ossman80b42092015-11-10 17:17:34 +010018
Pierre Ossman86350622015-11-10 13:02:12 +010019#include <rdr/InStream.h>
Pierre Ossman80b42092015-11-10 17:17:34 +010020#include <rdr/MemInStream.h>
21#include <rdr/OutStream.h>
22
Pierre Ossman86350622015-11-10 13:02:12 +010023#include <rfb/ConnParams.h>
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020024#include <rfb/PixelBuffer.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000025#include <rfb/HextileDecoder.h>
26
27using namespace rfb;
28
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000029#define BPP 8
30#include <rfb/hextileDecode.h>
31#undef BPP
32#define BPP 16
33#include <rfb/hextileDecode.h>
34#undef BPP
35#define BPP 32
36#include <rfb/hextileDecode.h>
37#undef BPP
38
Pierre Ossman86350622015-11-10 13:02:12 +010039HextileDecoder::HextileDecoder()
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000040{
41}
42
43HextileDecoder::~HextileDecoder()
44{
45}
46
Pierre Ossman86350622015-11-10 13:02:12 +010047void HextileDecoder::readRect(const Rect& r, rdr::InStream* is,
Pierre Ossman80b42092015-11-10 17:17:34 +010048 const ConnParams& cp, rdr::OutStream* os)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000049{
Pierre Ossman80b42092015-11-10 17:17:34 +010050 Rect t;
51 size_t bytesPerPixel;
52
53 bytesPerPixel = cp.pf().bpp/8;
54
55 for (t.tl.y = r.tl.y; t.tl.y < r.br.y; t.tl.y += 16) {
56
57 t.br.y = __rfbmin(r.br.y, t.tl.y + 16);
58
59 for (t.tl.x = r.tl.x; t.tl.x < r.br.x; t.tl.x += 16) {
60 rdr::U8 tileType;
61
62 t.br.x = __rfbmin(r.br.x, t.tl.x + 16);
63
64 tileType = is->readU8();
65 os->writeU8(tileType);
66
67 if (tileType & hextileRaw) {
68 os->copyBytes(is, t.area() * bytesPerPixel);
69 continue;
70 }
71
72 if (tileType & hextileBgSpecified)
73 os->copyBytes(is, bytesPerPixel);
74
75 if (tileType & hextileFgSpecified)
76 os->copyBytes(is, bytesPerPixel);
77
78 if (tileType & hextileAnySubrects) {
79 rdr::U8 nSubrects;
80
81 nSubrects = is->readU8();
82 os->writeU8(nSubrects);
83
84 if (tileType & hextileSubrectsColoured)
85 os->copyBytes(is, nSubrects * (bytesPerPixel + 2));
86 else
87 os->copyBytes(is, nSubrects * 2);
88 }
89 }
90 }
91}
92
93void HextileDecoder::decodeRect(const Rect& r, const void* buffer,
94 size_t buflen, const ConnParams& cp,
95 ModifiablePixelBuffer* pb)
96{
97 rdr::MemInStream is(buffer, buflen);
Pierre Ossman86350622015-11-10 13:02:12 +010098 const PixelFormat& pf = cp.pf();
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020099 switch (pf.bpp) {
Pierre Ossman80b42092015-11-10 17:17:34 +0100100 case 8: hextileDecode8 (r, &is, pf, pb); break;
101 case 16: hextileDecode16(r, &is, pf, pb); break;
102 case 32: hextileDecode32(r, &is, pf, pb); break;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000103 }
104}