[4] | 1 | /************************************************************************ |
---|
| 2 | * |
---|
| 3 | * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. |
---|
| 4 | * |
---|
| 5 | * This is free software; you can redistribute it and/or modify |
---|
| 6 | * it under the terms of the GNU General Public License as published by |
---|
| 7 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 8 | * (at your option) any later version. |
---|
| 9 | * |
---|
| 10 | * This software is distributed in the hope that it will be useful, |
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | * GNU General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU General Public License |
---|
| 16 | * along with this software; if not, write to the Free Software |
---|
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
---|
| 18 | * USA. |
---|
| 19 | ************************************************************************/ |
---|
| 20 | |
---|
| 21 | /* |
---|
| 22 | * hextile.c - handle hextile encoding. |
---|
| 23 | * |
---|
| 24 | * This file shouldn't be compiled directly. It is included multiple times by |
---|
| 25 | * rfbproto.c, each time with a different definition of the macro BPP. For |
---|
| 26 | * each value of BPP, this file defines a function which handles a hextile |
---|
| 27 | * encoded rectangle with BPP bits per pixel. |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | #ifdef HandleRREBPP |
---|
| 31 | #undef HandleRREBPP |
---|
| 32 | #endif |
---|
| 33 | #ifdef ReceiveRREBPP |
---|
| 34 | #undef ReceiveRREBPP |
---|
| 35 | #endif |
---|
| 36 | #ifdef flushRREBPP |
---|
| 37 | #undef flushRREBPP |
---|
| 38 | #endif |
---|
| 39 | #ifdef CARDBPP |
---|
| 40 | #undef CARDBPP |
---|
| 41 | #endif |
---|
| 42 | #ifdef HandleHextileBPP |
---|
| 43 | #undef HandleHextileBPP |
---|
| 44 | #endif |
---|
| 45 | #ifdef GET_PIXEL |
---|
| 46 | #undef GET_PIXEL |
---|
| 47 | #endif |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | #define HandleHextileBPP CONCAT2E(HandleHextile,BPP) |
---|
| 51 | #define ReceiveHextileBPP CONCAT2E(ReceiveHextile,BPP) |
---|
| 52 | #define flushHextileBPP CONCAT2E(flushHextile,BPP) |
---|
| 53 | #define CARDBPP CONCAT2E(CARD,BPP) |
---|
| 54 | #define GET_PIXEL CONCAT2E(GET_PIXEL,BPP) |
---|
| 55 | |
---|
| 56 | Bool |
---|
| 57 | VNCViewer::HandleHextileBPP (sgVNCViewer *ct, int rx, int ry, int rw, int rh) |
---|
| 58 | { |
---|
| 59 | CARDBPP bg, fg; |
---|
| 60 | int i; |
---|
| 61 | CARD8 *ptr; |
---|
| 62 | int x, y, w, h; |
---|
| 63 | int sx, sy, sw, sh; |
---|
| 64 | CARD8 subencoding; |
---|
| 65 | CARD8 nSubrects; |
---|
| 66 | |
---|
| 67 | for (y = ry; y < ry+rh; y += 16) { |
---|
| 68 | for (x = rx; x < rx+rw; x += 16) { |
---|
| 69 | w = h = 16; |
---|
| 70 | if (rx+rw - x < 16) |
---|
| 71 | w = rx+rw - x; |
---|
| 72 | if (ry+rh - y < 16) |
---|
| 73 | h = ry+rh - y; |
---|
| 74 | |
---|
| 75 | if (!ReadFromRFBServer((char *)&subencoding, 1)) |
---|
| 76 | return False; |
---|
| 77 | |
---|
| 78 | if (subencoding & rfbHextileRaw) { |
---|
| 79 | if (!ReadFromRFBServer(buffer, w * h * (BPP / 8))) |
---|
| 80 | return False; |
---|
| 81 | |
---|
| 82 | ct->CopyDataToScreen(buffer, x, y, w, h); |
---|
| 83 | continue; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | if (subencoding & rfbHextileBackgroundSpecified) |
---|
| 87 | if (!ReadFromRFBServer((char *)&bg, sizeof(bg))) |
---|
| 88 | return False; |
---|
| 89 | |
---|
| 90 | ct->FillToScreen(bg, x, y, w, h); |
---|
| 91 | |
---|
| 92 | if (subencoding & rfbHextileForegroundSpecified) |
---|
| 93 | if (!ReadFromRFBServer((char *)&fg, sizeof(fg))) |
---|
| 94 | return False; |
---|
| 95 | |
---|
| 96 | if (!(subencoding & rfbHextileAnySubrects)) { |
---|
| 97 | continue; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | if (!ReadFromRFBServer((char *)&nSubrects, 1)) |
---|
| 101 | return False; |
---|
| 102 | |
---|
| 103 | ptr = (CARD8 *)buffer; |
---|
| 104 | |
---|
| 105 | if (subencoding & rfbHextileSubrectsColoured) { |
---|
| 106 | if (!ReadFromRFBServer(buffer, nSubrects * (2 + (BPP / 8)))) |
---|
| 107 | return False; |
---|
| 108 | |
---|
| 109 | for (i = 0; i < nSubrects; i++) { |
---|
| 110 | GET_PIXEL(fg, ptr); |
---|
| 111 | sx = rfbHextileExtractX(*ptr); |
---|
| 112 | sy = rfbHextileExtractY(*ptr); |
---|
| 113 | ptr++; |
---|
| 114 | sw = rfbHextileExtractW(*ptr); |
---|
| 115 | sh = rfbHextileExtractH(*ptr); |
---|
| 116 | ptr++; |
---|
| 117 | |
---|
| 118 | ct->FillToScreen(fg, x+sx, y+sy, sw, sh); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | } else { |
---|
| 122 | if (!ReadFromRFBServer(buffer, nSubrects * 2)) |
---|
| 123 | return False; |
---|
| 124 | |
---|
| 125 | for (i = 0; i < nSubrects; i++) { |
---|
| 126 | sx = rfbHextileExtractX(*ptr); |
---|
| 127 | sy = rfbHextileExtractY(*ptr); |
---|
| 128 | ptr++; |
---|
| 129 | sw = rfbHextileExtractW(*ptr); |
---|
| 130 | sh = rfbHextileExtractH(*ptr); |
---|
| 131 | ptr++; |
---|
| 132 | |
---|
| 133 | ct->FillToScreen(fg, x+sx, y+sy, sw, sh); |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | return True; |
---|
| 140 | } |
---|
| 141 | |
---|