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 | */ |
Pierre Ossman | 80b4209 | 2015-11-10 17:17:34 +0100 | [diff] [blame] | 18 | |
Pierre Ossman | 8635062 | 2015-11-10 13:02:12 +0100 | [diff] [blame] | 19 | #include <rdr/InStream.h> |
Pierre Ossman | 80b4209 | 2015-11-10 17:17:34 +0100 | [diff] [blame] | 20 | #include <rdr/MemInStream.h> |
| 21 | #include <rdr/OutStream.h> |
| 22 | |
Pierre Ossman | 8635062 | 2015-11-10 13:02:12 +0100 | [diff] [blame] | 23 | #include <rfb/ConnParams.h> |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame] | 24 | #include <rfb/PixelBuffer.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 25 | #include <rfb/HextileDecoder.h> |
| 26 | |
| 27 | using namespace rfb; |
| 28 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 29 | #define BPP 8 |
| 30 | #include <rfb/hextileDecode.h> |
| 31 | #undef BPP |
| 32 | #define BPP 16 |
| 33 | #include <rfb/hextileDecode.h> |
| 34 | #undef BPP |
| 35 | #define BPP 32 |
| 36 | #include <rfb/hextileDecode.h> |
| 37 | #undef BPP |
| 38 | |
Pierre Ossman | 570cd5c | 2015-11-12 13:07:42 +0100 | [diff] [blame] | 39 | HextileDecoder::HextileDecoder() : Decoder(DecoderPlain) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 40 | { |
| 41 | } |
| 42 | |
| 43 | HextileDecoder::~HextileDecoder() |
| 44 | { |
| 45 | } |
| 46 | |
Pierre Ossman | 8635062 | 2015-11-10 13:02:12 +0100 | [diff] [blame] | 47 | void HextileDecoder::readRect(const Rect& r, rdr::InStream* is, |
Pierre Ossman | 80b4209 | 2015-11-10 17:17:34 +0100 | [diff] [blame] | 48 | const ConnParams& cp, rdr::OutStream* os) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 49 | { |
Pierre Ossman | 80b4209 | 2015-11-10 17:17:34 +0100 | [diff] [blame] | 50 | Rect t; |
| 51 | size_t bytesPerPixel; |
| 52 | |
| 53 | bytesPerPixel = cp.pf().bpp/8; |
| 54 | |
| 55 | for (t.tl.y = r.tl.y; t.tl.y < r.br.y; t.tl.y += 16) { |
| 56 | |
| 57 | t.br.y = __rfbmin(r.br.y, t.tl.y + 16); |
| 58 | |
| 59 | for (t.tl.x = r.tl.x; t.tl.x < r.br.x; t.tl.x += 16) { |
| 60 | rdr::U8 tileType; |
| 61 | |
| 62 | t.br.x = __rfbmin(r.br.x, t.tl.x + 16); |
| 63 | |
| 64 | tileType = is->readU8(); |
| 65 | os->writeU8(tileType); |
| 66 | |
| 67 | if (tileType & hextileRaw) { |
| 68 | os->copyBytes(is, t.area() * bytesPerPixel); |
| 69 | continue; |
| 70 | } |
| 71 | |
| 72 | if (tileType & hextileBgSpecified) |
| 73 | os->copyBytes(is, bytesPerPixel); |
| 74 | |
| 75 | if (tileType & hextileFgSpecified) |
| 76 | os->copyBytes(is, bytesPerPixel); |
| 77 | |
| 78 | if (tileType & hextileAnySubrects) { |
| 79 | rdr::U8 nSubrects; |
| 80 | |
| 81 | nSubrects = is->readU8(); |
| 82 | os->writeU8(nSubrects); |
| 83 | |
| 84 | if (tileType & hextileSubrectsColoured) |
| 85 | os->copyBytes(is, nSubrects * (bytesPerPixel + 2)); |
| 86 | else |
| 87 | os->copyBytes(is, nSubrects * 2); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | void HextileDecoder::decodeRect(const Rect& r, const void* buffer, |
| 94 | size_t buflen, const ConnParams& cp, |
| 95 | ModifiablePixelBuffer* pb) |
| 96 | { |
| 97 | rdr::MemInStream is(buffer, buflen); |
Pierre Ossman | 8635062 | 2015-11-10 13:02:12 +0100 | [diff] [blame] | 98 | const PixelFormat& pf = cp.pf(); |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame] | 99 | switch (pf.bpp) { |
Pierre Ossman | 80b4209 | 2015-11-10 17:17:34 +0100 | [diff] [blame] | 100 | case 8: hextileDecode8 (r, &is, pf, pb); break; |
| 101 | case 16: hextileDecode16(r, &is, pf, pb); break; |
| 102 | case 32: hextileDecode32(r, &is, pf, pb); break; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 103 | } |
| 104 | } |