blob: 56ba11812a59c617dcc1a1064a32e632fdf7ec98 [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//
19// Hextile decoding function.
20//
Pierre Ossmanbcc295e2014-02-12 13:16:43 +010021// This file is #included after having set the following macro:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000022// BPP - 8, 16 or 32
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000023
24#include <rdr/InStream.h>
25#include <rfb/hextileConstants.h>
26
27namespace rfb {
28
29// CONCAT2E concatenates its arguments, expanding them if they are macros
30
31#ifndef CONCAT2E
32#define CONCAT2(a,b) a##b
33#define CONCAT2E(a,b) CONCAT2(a,b)
34#endif
35
36#define PIXEL_T rdr::CONCAT2E(U,BPP)
37#define READ_PIXEL CONCAT2E(readOpaque,BPP)
38#define HEXTILE_DECODE CONCAT2E(hextileDecode,BPP)
39
Pierre Ossmanbcc295e2014-02-12 13:16:43 +010040void HEXTILE_DECODE (const Rect& r, rdr::InStream* is, PIXEL_T* buf,
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020041 const PixelFormat& pf, ModifiablePixelBuffer* pb)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000042{
43 Rect t;
44 PIXEL_T bg = 0;
45 PIXEL_T fg = 0;
46
47 for (t.tl.y = r.tl.y; t.tl.y < r.br.y; t.tl.y += 16) {
48
49 t.br.y = __rfbmin(r.br.y, t.tl.y + 16);
50
51 for (t.tl.x = r.tl.x; t.tl.x < r.br.x; t.tl.x += 16) {
52
53 t.br.x = __rfbmin(r.br.x, t.tl.x + 16);
54
55 int tileType = is->readU8();
56
57 if (tileType & hextileRaw) {
58 is->readBytes(buf, t.area() * (BPP/8));
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020059 pb->imageRect(pf, t, buf);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000060 continue;
61 }
62
63 if (tileType & hextileBgSpecified)
64 bg = is->READ_PIXEL();
65
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000066 int len = t.area();
67 PIXEL_T* ptr = (PIXEL_T*)buf;
68 while (len-- > 0) *ptr++ = bg;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000069
70 if (tileType & hextileFgSpecified)
71 fg = is->READ_PIXEL();
72
73 if (tileType & hextileAnySubrects) {
74 int nSubrects = is->readU8();
75
76 for (int i = 0; i < nSubrects; i++) {
77
78 if (tileType & hextileSubrectsColoured)
79 fg = is->READ_PIXEL();
80
81 int xy = is->readU8();
82 int wh = is->readU8();
83
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000084 int x = ((xy >> 4) & 15);
85 int y = (xy & 15);
86 int w = ((wh >> 4) & 15) + 1;
87 int h = (wh & 15) + 1;
88 PIXEL_T* ptr = (PIXEL_T*)buf + y * t.width() + x;
89 int rowAdd = t.width() - w;
90 while (h-- > 0) {
91 int len = w;
92 while (len-- > 0) *ptr++ = fg;
93 ptr += rowAdd;
94 }
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000095 }
96 }
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020097 pb->imageRect(pf, t, buf);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000098 }
99 }
100}
101
102#undef PIXEL_T
103#undef READ_PIXEL
104#undef HEXTILE_DECODE
105}