merge in my changes from soc-krdc branch
[kdenetwork.git] / krdc / vnc / hextile.c
blob1c3e7efd410fa7016fb9a2826fbffc0648705d12
1 /*
2 * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this software; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17 * USA.
21 * hextile.c - handle hextile encoding.
23 * This file shouldn't be compiled directly. It is included multiple times by
24 * rfbproto.c, each time with a different definition of the macro BPP. For
25 * each value of BPP, this file defines a function which handles a hextile
26 * encoded rectangle with BPP bits per pixel.
29 #define HandleHextileBPP CONCAT2E(HandleHextile,BPP)
30 #define CARDBPP CONCAT2E(CARD,BPP)
31 #define GET_PIXEL CONCAT2E(GET_PIXEL,BPP)
32 #define FillRectangleBPP CONCAT2E(FillRectangle,BPP)
34 static Bool
35 HandleHextileBPP (int rx, int ry, int rw, int rh)
37 CARDBPP bg, fg;
38 int i;
39 CARD8 *ptr;
40 int x, y, w, h;
41 int sx, sy, sw, sh;
42 CARD8 subencoding;
43 CARD8 nSubrects;
45 for (y = ry; y < ry+rh; y += 16) {
46 for (x = rx; x < rx+rw; x += 16) {
47 w = h = 16;
48 if (rx+rw - x < 16)
49 w = rx+rw - x;
50 if (ry+rh - y < 16)
51 h = ry+rh - y;
53 if (!ReadFromRFBServer((char *)&subencoding, 1))
54 return False;
56 if (subencoding & rfbHextileRaw) {
57 if (!ReadFromRFBServer(buffer, w * h * (BPP / 8)))
58 return False;
60 CopyDataToScreen(buffer, x, y, w, h);
61 continue;
64 if (subencoding & rfbHextileBackgroundSpecified)
65 if (!ReadFromRFBServer((char *)&bg, sizeof(bg)))
66 return False;
68 LockFramebuffer();
69 if (subencoding & rfbHextileBackgroundSpecified)
70 FillRectangleBPP(bg, x, y, w, h);
72 if (subencoding & rfbHextileForegroundSpecified)
73 if (!ReadFromRFBServer((char *)&fg, sizeof(fg))) {
74 UnlockFramebuffer();
75 return False;
78 if (!(subencoding & rfbHextileAnySubrects)) {
79 UnlockFramebuffer();
80 SyncScreenRegion(x, y, w, h);
81 continue;
84 if (!ReadFromRFBServer((char *)&nSubrects, 1)) {
85 UnlockFramebuffer();
86 return False;
89 ptr = (CARD8 *)buffer;
91 if (subencoding & rfbHextileSubrectsColoured) {
92 if (!ReadFromRFBServer(buffer, nSubrects * (2 + (BPP / 8)))) {
93 UnlockFramebuffer();
94 return False;
97 for (i = 0; i < nSubrects; i++) {
98 GET_PIXEL(fg, ptr);
99 sx = rfbHextileExtractX(*ptr);
100 sy = rfbHextileExtractY(*ptr);
101 ptr++;
102 sw = rfbHextileExtractW(*ptr);
103 sh = rfbHextileExtractH(*ptr);
104 ptr++;
105 FillRectangleBPP(fg, x+sx, y+sy, sw, sh);
108 } else {
109 if (!ReadFromRFBServer(buffer, nSubrects * 2)) {
110 UnlockFramebuffer();
111 return False;
114 for (i = 0; i < nSubrects; i++) {
115 sx = rfbHextileExtractX(*ptr);
116 sy = rfbHextileExtractY(*ptr);
117 ptr++;
118 sw = rfbHextileExtractW(*ptr);
119 sh = rfbHextileExtractH(*ptr);
120 ptr++;
121 FillRectangleBPP(fg, x+sx, y+sy, sw, sh);
124 UnlockFramebuffer();
125 SyncScreenRegion(x, y, w, h);
129 return True;