blob: 418a44048672922b6f375f5dbe3d76812ae14a75 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 * Copyright (C) 2005 Constantin Kaplinsky. All Rights Reserved.
Pierre Ossmanc0397262014-03-14 15:59:46 +01003 * Copyright 2014 Pierre Ossman for Cendio AB
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00004 *
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 Kaplinskya2adc8d2006-05-25 05:01:55 +000020#include <rfb/encodings.h>
Pierre Ossman668468b2014-01-31 12:37:32 +010021#include <rfb/SConnection.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000022#include <rfb/HextileEncoder.h>
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020023#include <rfb/PixelBuffer.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000024#include <rfb/Configuration.h>
25
26using namespace rfb;
27
28BoolParameter 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 Kaplinskya2adc8d2006-05-25 05:01:55 +000034#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 Ossmanc0397262014-03-14 15:59:46 +010047HextileEncoder::HextileEncoder(SConnection* conn) :
48 Encoder(conn, encodingHextile, EncoderPlain, -1)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000049{
50}
51
52HextileEncoder::~HextileEncoder()
53{
54}
55
Pierre Ossmanc0397262014-03-14 15:59:46 +010056bool HextileEncoder::isSupported()
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000057{
Pierre Ossmanc0397262014-03-14 15:59:46 +010058 return conn->cp.supportsEncoding(encodingHextile);
59}
60
61void HextileEncoder::writeRect(const PixelBuffer* pb, const Palette& palette)
62{
Pierre Ossman668468b2014-01-31 12:37:32 +010063 rdr::OutStream* os = conn->getOutStream();
Pierre Ossmanc0397262014-03-14 15:59:46 +010064 switch (pb->getPF().bpp) {
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000065 case 8:
66 if (improvedHextile) {
Pierre Ossmanc0397262014-03-14 15:59:46 +010067 hextileEncodeBetter8(os, pb);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000068 } else {
Pierre Ossmanc0397262014-03-14 15:59:46 +010069 hextileEncode8(os, pb);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000070 }
71 break;
72 case 16:
73 if (improvedHextile) {
Pierre Ossmanc0397262014-03-14 15:59:46 +010074 hextileEncodeBetter16(os, pb);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000075 } else {
Pierre Ossmanc0397262014-03-14 15:59:46 +010076 hextileEncode16(os, pb);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000077 }
78 break;
79 case 32:
80 if (improvedHextile) {
Pierre Ossmanc0397262014-03-14 15:59:46 +010081 hextileEncodeBetter32(os, pb);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000082 } else {
Pierre Ossmanc0397262014-03-14 15:59:46 +010083 hextileEncode32(os, pb);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000084 }
85 break;
86 }
Pierre Ossmanc0397262014-03-14 15:59:46 +010087}
88
89void 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 Kaplinskya2adc8d2006-05-25 05:01:55 +0000106}