Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* 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 Ossman | bcc295e | 2014-02-12 13:16:43 +0100 | [diff] [blame] | 21 | // This file is #included after having set the following macro: |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 22 | // BPP - 8, 16 or 32 |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 23 | |
| 24 | #include <rdr/InStream.h> |
| 25 | #include <rfb/hextileConstants.h> |
| 26 | |
| 27 | namespace 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 Ossman | 80b4209 | 2015-11-10 17:17:34 +0100 | [diff] [blame] | 40 | static void HEXTILE_DECODE (const Rect& r, rdr::InStream* is, |
| 41 | const PixelFormat& pf, |
| 42 | ModifiablePixelBuffer* pb) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 43 | { |
| 44 | Rect t; |
| 45 | PIXEL_T bg = 0; |
| 46 | PIXEL_T fg = 0; |
Pierre Ossman | 1349e42 | 2016-10-05 11:00:37 +0200 | [diff] [blame^] | 47 | PIXEL_T buf[16 * 16]; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 48 | |
| 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 Ossman | 80b4209 | 2015-11-10 17:17:34 +0100 | [diff] [blame] | 60 | is->readBytes(buf, t.area() * (BPP/8)); |
| 61 | pb->imageRect(pf, t, buf); |
| 62 | continue; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | if (tileType & hextileBgSpecified) |
Pierre Ossman | 80b4209 | 2015-11-10 17:17:34 +0100 | [diff] [blame] | 66 | bg = is->READ_PIXEL(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 67 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 68 | int len = t.area(); |
Pierre Ossman | 80b4209 | 2015-11-10 17:17:34 +0100 | [diff] [blame] | 69 | PIXEL_T* ptr = buf; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 70 | while (len-- > 0) *ptr++ = bg; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 71 | |
| 72 | if (tileType & hextileFgSpecified) |
Pierre Ossman | 80b4209 | 2015-11-10 17:17:34 +0100 | [diff] [blame] | 73 | fg = is->READ_PIXEL(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 74 | |
| 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 Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 86 | int x = ((xy >> 4) & 15); |
| 87 | int y = (xy & 15); |
| 88 | int w = ((wh >> 4) & 15) + 1; |
| 89 | int h = (wh & 15) + 1; |
Pierre Ossman | 80b4209 | 2015-11-10 17:17:34 +0100 | [diff] [blame] | 90 | PIXEL_T* ptr = buf + y * t.width() + x; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 91 | int rowAdd = t.width() - w; |
| 92 | while (h-- > 0) { |
| 93 | int len = w; |
| 94 | while (len-- > 0) *ptr++ = fg; |
| 95 | ptr += rowAdd; |
| 96 | } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 97 | } |
| 98 | } |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame] | 99 | pb->imageRect(pf, t, buf); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | #undef PIXEL_T |
| 105 | #undef READ_PIXEL |
| 106 | #undef HEXTILE_DECODE |
| 107 | } |