blob: 47006a042828469a3581fd7ed74b42439446c032 [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 Ossman80b42092015-11-10 17:17:34 +010040static void HEXTILE_DECODE (const Rect& r, rdr::InStream* is,
41 const PixelFormat& pf,
42 ModifiablePixelBuffer* pb)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000043{
44 Rect t;
45 PIXEL_T bg = 0;
46 PIXEL_T fg = 0;
Pierre Ossman1349e422016-10-05 11:00:37 +020047 PIXEL_T buf[16 * 16];
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000048
49 for (t.tl.y = r.tl.y; t.tl.y < r.br.y; t.tl.y += 16) {
50
51 t.br.y = __rfbmin(r.br.y, t.tl.y + 16);
52
53 for (t.tl.x = r.tl.x; t.tl.x < r.br.x; t.tl.x += 16) {
54
55 t.br.x = __rfbmin(r.br.x, t.tl.x + 16);
56
57 int tileType = is->readU8();
58
59 if (tileType & hextileRaw) {
Pierre Ossman80b42092015-11-10 17:17:34 +010060 is->readBytes(buf, t.area() * (BPP/8));
61 pb->imageRect(pf, t, buf);
62 continue;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000063 }
64
65 if (tileType & hextileBgSpecified)
Pierre Ossman80b42092015-11-10 17:17:34 +010066 bg = is->READ_PIXEL();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000067
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000068 int len = t.area();
Pierre Ossman80b42092015-11-10 17:17:34 +010069 PIXEL_T* ptr = buf;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000070 while (len-- > 0) *ptr++ = bg;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000071
72 if (tileType & hextileFgSpecified)
Pierre Ossman80b42092015-11-10 17:17:34 +010073 fg = is->READ_PIXEL();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000074
75 if (tileType & hextileAnySubrects) {
76 int nSubrects = is->readU8();
77
78 for (int i = 0; i < nSubrects; i++) {
79
80 if (tileType & hextileSubrectsColoured)
81 fg = is->READ_PIXEL();
82
83 int xy = is->readU8();
84 int wh = is->readU8();
85
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000086 int x = ((xy >> 4) & 15);
87 int y = (xy & 15);
88 int w = ((wh >> 4) & 15) + 1;
89 int h = (wh & 15) + 1;
Pierre Ossman80b42092015-11-10 17:17:34 +010090 PIXEL_T* ptr = buf + y * t.width() + x;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000091 int rowAdd = t.width() - w;
92 while (h-- > 0) {
93 int len = w;
94 while (len-- > 0) *ptr++ = fg;
95 ptr += rowAdd;
96 }
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000097 }
98 }
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020099 pb->imageRect(pf, t, buf);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000100 }
101 }
102}
103
104#undef PIXEL_T
105#undef READ_PIXEL
106#undef HEXTILE_DECODE
107}