Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 2 | * Copyright (C) 2005 Constantin Kaplinsky. All Rights Reserved. |
| 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 | */ |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 19 | #include <rfb/encodings.h> |
| 20 | #include <rfb/SMsgWriter.h> |
Pierre Ossman | 668468b | 2014-01-31 12:37:32 +0100 | [diff] [blame] | 21 | #include <rfb/SConnection.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 22 | #include <rfb/HextileEncoder.h> |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame^] | 23 | #include <rfb/PixelFormat.h> |
| 24 | #include <rfb/PixelBuffer.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 25 | #include <rfb/Configuration.h> |
| 26 | |
| 27 | using namespace rfb; |
| 28 | |
| 29 | BoolParameter improvedHextile("ImprovedHextile", |
| 30 | "Use improved compression algorithm for Hextile " |
| 31 | "encoding which achieves better compression " |
| 32 | "ratios by the cost of using more CPU time", |
| 33 | true); |
| 34 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 35 | #define BPP 8 |
| 36 | #include <rfb/hextileEncode.h> |
| 37 | #include <rfb/hextileEncodeBetter.h> |
| 38 | #undef BPP |
| 39 | #define BPP 16 |
| 40 | #include <rfb/hextileEncode.h> |
| 41 | #include <rfb/hextileEncodeBetter.h> |
| 42 | #undef BPP |
| 43 | #define BPP 32 |
| 44 | #include <rfb/hextileEncode.h> |
| 45 | #include <rfb/hextileEncodeBetter.h> |
| 46 | #undef BPP |
| 47 | |
Pierre Ossman | 668468b | 2014-01-31 12:37:32 +0100 | [diff] [blame] | 48 | HextileEncoder::HextileEncoder(SConnection* conn) : Encoder(conn) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 49 | { |
| 50 | } |
| 51 | |
| 52 | HextileEncoder::~HextileEncoder() |
| 53 | { |
| 54 | } |
| 55 | |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame^] | 56 | void HextileEncoder::writeRect(const Rect& r, PixelBuffer* pb) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 57 | { |
Pierre Ossman | 668468b | 2014-01-31 12:37:32 +0100 | [diff] [blame] | 58 | conn->writer()->startRect(r, encodingHextile); |
| 59 | rdr::OutStream* os = conn->getOutStream(); |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame^] | 60 | const PixelFormat& pf = conn->cp.pf(); |
| 61 | switch (pf.bpp) { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 62 | case 8: |
| 63 | if (improvedHextile) { |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame^] | 64 | hextileEncodeBetter8(r, os, pf, pb); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 65 | } else { |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame^] | 66 | hextileEncode8(r, os, pf, pb); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 67 | } |
| 68 | break; |
| 69 | case 16: |
| 70 | if (improvedHextile) { |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame^] | 71 | hextileEncodeBetter16(r, os, pf, pb); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 72 | } else { |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame^] | 73 | hextileEncode16(r, os, pf, pb); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 74 | } |
| 75 | break; |
| 76 | case 32: |
| 77 | if (improvedHextile) { |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame^] | 78 | hextileEncodeBetter32(r, os, pf, pb); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 79 | } else { |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame^] | 80 | hextileEncode32(r, os, pf, pb); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 81 | } |
| 82 | break; |
| 83 | } |
Pierre Ossman | 668468b | 2014-01-31 12:37:32 +0100 | [diff] [blame] | 84 | conn->writer()->endRect(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 85 | } |