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. |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 3 | * Copyright 2014 Pierre Ossman for Cendio AB |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 4 | * |
| 5 | * This is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This software is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this software; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 18 | * USA. |
| 19 | */ |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 20 | #include <rfb/encodings.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/PixelBuffer.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 24 | #include <rfb/Configuration.h> |
| 25 | |
| 26 | using namespace rfb; |
| 27 | |
| 28 | BoolParameter improvedHextile("ImprovedHextile", |
| 29 | "Use improved compression algorithm for Hextile " |
| 30 | "encoding which achieves better compression " |
| 31 | "ratios by the cost of using more CPU time", |
| 32 | true); |
| 33 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 34 | #define BPP 8 |
| 35 | #include <rfb/hextileEncode.h> |
| 36 | #include <rfb/hextileEncodeBetter.h> |
| 37 | #undef BPP |
| 38 | #define BPP 16 |
| 39 | #include <rfb/hextileEncode.h> |
| 40 | #include <rfb/hextileEncodeBetter.h> |
| 41 | #undef BPP |
| 42 | #define BPP 32 |
| 43 | #include <rfb/hextileEncode.h> |
| 44 | #include <rfb/hextileEncodeBetter.h> |
| 45 | #undef BPP |
| 46 | |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 47 | HextileEncoder::HextileEncoder(SConnection* conn) : |
Pierre Ossman | 4694d88 | 2018-09-20 10:49:40 +0200 | [diff] [blame] | 48 | Encoder(conn, encodingHextile, EncoderPlain) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 49 | { |
| 50 | } |
| 51 | |
| 52 | HextileEncoder::~HextileEncoder() |
| 53 | { |
| 54 | } |
| 55 | |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 56 | bool HextileEncoder::isSupported() |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 57 | { |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 58 | return conn->client.supportsEncoding(encodingHextile); |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void HextileEncoder::writeRect(const PixelBuffer* pb, const Palette& palette) |
| 62 | { |
Pierre Ossman | 668468b | 2014-01-31 12:37:32 +0100 | [diff] [blame] | 63 | rdr::OutStream* os = conn->getOutStream(); |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 64 | switch (pb->getPF().bpp) { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 65 | case 8: |
| 66 | if (improvedHextile) { |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 67 | hextileEncodeBetter8(os, pb); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 68 | } else { |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 69 | hextileEncode8(os, pb); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 70 | } |
| 71 | break; |
| 72 | case 16: |
| 73 | if (improvedHextile) { |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 74 | hextileEncodeBetter16(os, pb); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 75 | } else { |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 76 | hextileEncode16(os, pb); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 77 | } |
| 78 | break; |
| 79 | case 32: |
| 80 | if (improvedHextile) { |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 81 | hextileEncodeBetter32(os, pb); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 82 | } else { |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 83 | hextileEncode32(os, pb); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 84 | } |
| 85 | break; |
| 86 | } |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void HextileEncoder::writeSolidRect(int width, int height, |
| 90 | const PixelFormat& pf, |
| 91 | const rdr::U8* colour) |
| 92 | { |
| 93 | rdr::OutStream* os; |
| 94 | int tiles; |
| 95 | |
| 96 | os = conn->getOutStream(); |
| 97 | |
| 98 | tiles = ((width + 15)/16) * ((height + 15)/16); |
| 99 | |
| 100 | os->writeU8(hextileBgSpecified); |
| 101 | os->writeBytes(colour, pf.bpp/8); |
| 102 | tiles--; |
| 103 | |
| 104 | while (tiles--) |
| 105 | os->writeU8(0); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 106 | } |