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 | // RRE 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> |
Pierre Ossman | 466de9c | 2017-01-18 13:33:48 +0100 | [diff] [blame] | 25 | #include <rfb/Exception.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 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 RRE_DECODE CONCAT2E(rreDecode,BPP) |
| 39 | |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame] | 40 | void RRE_DECODE (const Rect& r, rdr::InStream* is, |
| 41 | const PixelFormat& pf, ModifiablePixelBuffer* pb) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 42 | { |
| 43 | int nSubrects = is->readU32(); |
| 44 | PIXEL_T bg = is->READ_PIXEL(); |
Pierre Ossman | 56f99d6 | 2015-06-05 12:57:02 +0200 | [diff] [blame] | 45 | pb->fillRect(pf, r, &bg); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 46 | |
| 47 | for (int i = 0; i < nSubrects; i++) { |
| 48 | PIXEL_T pix = is->READ_PIXEL(); |
| 49 | int x = is->readU16(); |
| 50 | int y = is->readU16(); |
| 51 | int w = is->readU16(); |
| 52 | int h = is->readU16(); |
Pierre Ossman | 466de9c | 2017-01-18 13:33:48 +0100 | [diff] [blame] | 53 | |
| 54 | if (((x+w) > r.width()) || ((y+h) > r.height())) |
| 55 | throw Exception ("RRE decode error"); |
| 56 | |
Pierre Ossman | 56f99d6 | 2015-06-05 12:57:02 +0200 | [diff] [blame] | 57 | pb->fillRect(pf, Rect(r.tl.x+x, r.tl.y+y, r.tl.x+x+w, r.tl.y+y+h), &pix); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | |
| 61 | #undef PIXEL_T |
| 62 | #undef READ_PIXEL |
| 63 | #undef RRE_DECODE |
| 64 | } |