blob: 77befc7d965441b899d7b7fb5eb0d89f5c70f54b [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//
21// This file is #included after having set the following macros:
22// BPP - 8, 16 or 32
23// EXTRA_ARGS - optional extra arguments
24// FILL_RECT - fill a rectangle with a single colour
25// IMAGE_RECT - draw a rectangle of pixel data from a buffer
26
27#include <rdr/InStream.h>
28#include <rfb/hextileConstants.h>
29
30namespace rfb {
31
32// CONCAT2E concatenates its arguments, expanding them if they are macros
33
34#ifndef CONCAT2E
35#define CONCAT2(a,b) a##b
36#define CONCAT2E(a,b) CONCAT2(a,b)
37#endif
38
39#define PIXEL_T rdr::CONCAT2E(U,BPP)
40#define READ_PIXEL CONCAT2E(readOpaque,BPP)
41#define HEXTILE_DECODE CONCAT2E(hextileDecode,BPP)
42
43void HEXTILE_DECODE (const Rect& r, rdr::InStream* is, PIXEL_T* buf
44#ifdef EXTRA_ARGS
45 , EXTRA_ARGS
46#endif
47 )
48{
49 Rect t;
50 PIXEL_T bg = 0;
51 PIXEL_T fg = 0;
52
53 for (t.tl.y = r.tl.y; t.tl.y < r.br.y; t.tl.y += 16) {
54
55 t.br.y = __rfbmin(r.br.y, t.tl.y + 16);
56
57 for (t.tl.x = r.tl.x; t.tl.x < r.br.x; t.tl.x += 16) {
58
59 t.br.x = __rfbmin(r.br.x, t.tl.x + 16);
60
61 int tileType = is->readU8();
62
63 if (tileType & hextileRaw) {
64 is->readBytes(buf, t.area() * (BPP/8));
65 IMAGE_RECT(t, buf);
66 continue;
67 }
68
69 if (tileType & hextileBgSpecified)
70 bg = is->READ_PIXEL();
71
72#ifdef FAVOUR_FILL_RECT
73 FILL_RECT(t, bg);
74#else
75 int len = t.area();
76 PIXEL_T* ptr = (PIXEL_T*)buf;
77 while (len-- > 0) *ptr++ = bg;
78#endif
79
80 if (tileType & hextileFgSpecified)
81 fg = is->READ_PIXEL();
82
83 if (tileType & hextileAnySubrects) {
84 int nSubrects = is->readU8();
85
86 for (int i = 0; i < nSubrects; i++) {
87
88 if (tileType & hextileSubrectsColoured)
89 fg = is->READ_PIXEL();
90
91 int xy = is->readU8();
92 int wh = is->readU8();
93
94#ifdef FAVOUR_FILL_RECT
95 Rect s;
96 s.tl.x = t.tl.x + ((xy >> 4) & 15);
97 s.tl.y = t.tl.y + (xy & 15);
98 s.br.x = s.tl.x + ((wh >> 4) & 15) + 1;
99 s.br.y = s.tl.y + (wh & 15) + 1;
100 FILL_RECT(s, fg);
101#else
102 int x = ((xy >> 4) & 15);
103 int y = (xy & 15);
104 int w = ((wh >> 4) & 15) + 1;
105 int h = (wh & 15) + 1;
106 PIXEL_T* ptr = (PIXEL_T*)buf + y * t.width() + x;
107 int rowAdd = t.width() - w;
108 while (h-- > 0) {
109 int len = w;
110 while (len-- > 0) *ptr++ = fg;
111 ptr += rowAdd;
112 }
113#endif
114 }
115 }
116#ifndef FAVOUR_FILL_RECT
117 IMAGE_RECT(t, buf);
118#endif
119 }
120 }
121}
122
123#undef PIXEL_T
124#undef READ_PIXEL
125#undef HEXTILE_DECODE
126}