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 | #include <rdr/OutStream.h> |
| 19 | #include <rfb/ImageGetter.h> |
| 20 | #include <rfb/encodings.h> |
| 21 | #include <rfb/SMsgWriter.h> |
| 22 | #include <rfb/RREEncoder.h> |
| 23 | |
| 24 | using namespace rfb; |
| 25 | |
| 26 | #define BPP 8 |
| 27 | #include <rfb/rreEncode.h> |
| 28 | #undef BPP |
| 29 | #define BPP 16 |
| 30 | #include <rfb/rreEncode.h> |
| 31 | #undef BPP |
| 32 | #define BPP 32 |
| 33 | #include <rfb/rreEncode.h> |
| 34 | #undef BPP |
| 35 | |
| 36 | Encoder* RREEncoder::create(SMsgWriter* writer) |
| 37 | { |
| 38 | return new RREEncoder(writer); |
| 39 | } |
| 40 | |
| 41 | RREEncoder::RREEncoder(SMsgWriter* writer_) : writer(writer_) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | RREEncoder::~RREEncoder() |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | bool RREEncoder::writeRect(const Rect& r, ImageGetter* ig, Rect* actual) |
| 50 | { |
| 51 | int w = r.width(); |
| 52 | int h = r.height(); |
| 53 | rdr::U8* imageBuf = writer->getImageBuf(w*h); |
| 54 | ig->getImage(imageBuf, r); |
| 55 | |
| 56 | mos.clear(); |
| 57 | |
| 58 | int nSubrects = -1; |
| 59 | switch (writer->bpp()) { |
| 60 | case 8: nSubrects = rreEncode8(imageBuf, w, h, &mos); break; |
| 61 | case 16: nSubrects = rreEncode16(imageBuf, w, h, &mos); break; |
| 62 | case 32: nSubrects = rreEncode32(imageBuf, w, h, &mos); break; |
| 63 | } |
| 64 | |
| 65 | if (nSubrects < 0) { |
| 66 | return writer->writeRect(r, encodingRaw, ig, actual); |
| 67 | } |
| 68 | |
| 69 | writer->startRect(r, encodingRRE); |
| 70 | rdr::OutStream* os = writer->getOutStream(); |
| 71 | os->writeU32(nSubrects); |
| 72 | os->writeBytes(mos.data(), mos.length()); |
| 73 | writer->endRect(); |
| 74 | return true; |
| 75 | } |