blob: a317d25071e8a67318ff221d8f844d3d0d0b054b [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2000-2003 Constantin Kaplinsky. All Rights Reserved.
Peter Åstrandd69bcc42011-09-28 12:52:53 +00002 * Copyright 2004-2005 Cendio AB.
DRC33c15e32011-11-03 18:49:21 +00003 * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
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 */
20#include <rfb/CMsgReader.h>
21#include <rfb/CMsgHandler.h>
22#include <rfb/TightDecoder.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000023
24using namespace rfb;
25
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000026#define TIGHT_MAX_WIDTH 2048
27
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000028#define BPP 8
29#include <rfb/tightDecode.h>
30#undef BPP
31#define BPP 16
32#include <rfb/tightDecode.h>
33#undef BPP
34#define BPP 32
35#include <rfb/tightDecode.h>
36#undef BPP
37
Pierre Ossman4aba19e2014-01-29 16:42:48 +010038TightDecoder::TightDecoder(CMsgReader* reader) : Decoder(reader)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000039{
40}
41
42TightDecoder::~TightDecoder()
43{
44}
45
46void TightDecoder::readRect(const Rect& r, CMsgHandler* handler)
47{
DRC33c15e32011-11-03 18:49:21 +000048 is = reader->getInStream();
49 this->handler = handler;
50 clientpf = handler->getPreferredPF();
51 serverpf = handler->cp.pf();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000052
DRC33c15e32011-11-03 18:49:21 +000053 if (clientpf.equal(serverpf)) {
54 /* Decode directly into the framebuffer (fast path) */
55 directDecode = true;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000056 } else {
DRC33c15e32011-11-03 18:49:21 +000057 /* Decode into an intermediate buffer and use pixel translation */
58 directDecode = false;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000059 }
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000060
DRC33c15e32011-11-03 18:49:21 +000061 switch (serverpf.bpp) {
62 case 8:
63 tightDecode8 (r); break;
64 case 16:
65 tightDecode16(r); break;
66 case 32:
67 tightDecode32(r); break;
68 }
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000069}
Pierre Ossman7b5c0692014-03-17 14:35:51 +010070
71rdr::U32 TightDecoder::readCompact(rdr::InStream* is)
72{
73 rdr::U8 b;
74 rdr::U32 result;
75
76 b = is->readU8();
77 result = (int)b & 0x7F;
78 if (b & 0x80) {
79 b = is->readU8();
80 result |= ((int)b & 0x7F) << 7;
81 if (b & 0x80) {
82 b = is->readU8();
83 result |= ((int)b & 0xFF) << 14;
84 }
85 }
86
87 return result;
88}