Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2004 RealVNC Ltd. All Rights Reserved. |
Constantin Kaplinsky | c7e67f8 | 2005-09-09 21:26:21 +0000 | [diff] [blame] | 2 | * Copyright (C) 2005 Constantin Kaplinsky. All Rights Reserved. |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 3 | * |
| 4 | * This is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This software is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this software; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 17 | * USA. |
| 18 | */ |
| 19 | #include <rfb/ImageGetter.h> |
| 20 | #include <rfb/encodings.h> |
| 21 | #include <rfb/SMsgWriter.h> |
| 22 | #include <rfb/HextileEncoder.h> |
Constantin Kaplinsky | c7e67f8 | 2005-09-09 21:26:21 +0000 | [diff] [blame] | 23 | #include <rfb/Configuration.h> |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 24 | |
| 25 | using namespace rfb; |
| 26 | |
Constantin Kaplinsky | c7e67f8 | 2005-09-09 21:26:21 +0000 | [diff] [blame] | 27 | BoolParameter improvedHextile("ImprovedHextile", |
| 28 | "Use improved compression algorithm for Hextile " |
| 29 | "encoding which achieves better compression " |
| 30 | "ratios by the cost of using more CPU time", |
| 31 | false); |
| 32 | |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 33 | #define EXTRA_ARGS ImageGetter* ig |
| 34 | #define GET_IMAGE_INTO_BUF(r,buf) ig->getImage(buf, r); |
| 35 | #define BPP 8 |
Constantin Kaplinsky | c7e67f8 | 2005-09-09 21:26:21 +0000 | [diff] [blame] | 36 | #include <rfb/hextileEncodeBetter.h> |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 37 | #undef BPP |
| 38 | #define BPP 16 |
| 39 | #include <rfb/hextileEncode.h> |
Constantin Kaplinsky | c7e67f8 | 2005-09-09 21:26:21 +0000 | [diff] [blame] | 40 | #include <rfb/hextileEncodeBetter.h> |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 41 | #undef BPP |
| 42 | #define BPP 32 |
| 43 | #include <rfb/hextileEncode.h> |
Constantin Kaplinsky | c7e67f8 | 2005-09-09 21:26:21 +0000 | [diff] [blame] | 44 | #include <rfb/hextileEncodeBetter.h> |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 45 | #undef BPP |
| 46 | |
| 47 | Encoder* HextileEncoder::create(SMsgWriter* writer) |
| 48 | { |
| 49 | return new HextileEncoder(writer); |
| 50 | } |
| 51 | |
| 52 | HextileEncoder::HextileEncoder(SMsgWriter* writer_) : writer(writer_) |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | HextileEncoder::~HextileEncoder() |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | bool HextileEncoder::writeRect(const Rect& r, ImageGetter* ig, Rect* actual) |
| 61 | { |
| 62 | writer->startRect(r, encodingHextile); |
| 63 | rdr::OutStream* os = writer->getOutStream(); |
| 64 | switch (writer->bpp()) { |
Constantin Kaplinsky | c7e67f8 | 2005-09-09 21:26:21 +0000 | [diff] [blame] | 65 | case 8: |
| 66 | // NOTE: We always use improved Hextile for 8-bit data. |
| 67 | hextileEncodeBetter8(r, os, ig); |
| 68 | break; |
| 69 | case 16: |
| 70 | if (improvedHextile) { |
| 71 | hextileEncodeBetter16(r, os, ig); |
| 72 | } else { |
| 73 | hextileEncode16(r, os, ig); |
| 74 | } |
| 75 | break; |
| 76 | case 32: |
| 77 | if (improvedHextile) { |
| 78 | hextileEncodeBetter32(r, os, ig); |
| 79 | } else { |
| 80 | hextileEncode32(r, os, ig); |
| 81 | } |
| 82 | break; |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 83 | } |
| 84 | writer->endRect(); |
| 85 | return true; |
| 86 | } |