blob: 96749a9eb64f0c2bb6aa474a9a2fe1746714b0f2 [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 */
Pierre Ossman86350622015-11-10 13:02:12 +010020#include <rdr/InStream.h>
21#include <rfb/ConnParams.h>
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020022#include <rfb/PixelBuffer.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000023#include <rfb/TightDecoder.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000024
25using namespace rfb;
26
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000027#define TIGHT_MAX_WIDTH 2048
28
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000029#define BPP 8
30#include <rfb/tightDecode.h>
31#undef BPP
32#define BPP 16
33#include <rfb/tightDecode.h>
34#undef BPP
35#define BPP 32
36#include <rfb/tightDecode.h>
37#undef BPP
38
Pierre Ossman86350622015-11-10 13:02:12 +010039TightDecoder::TightDecoder()
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000040{
41}
42
43TightDecoder::~TightDecoder()
44{
45}
46
Pierre Ossman86350622015-11-10 13:02:12 +010047void TightDecoder::readRect(const Rect& r, rdr::InStream* is,
48 const ConnParams& cp, ModifiablePixelBuffer* pb)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000049{
Pierre Ossman86350622015-11-10 13:02:12 +010050 this->is = is;
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020051 this->pb = pb;
52 clientpf = pb->getPF();
Pierre Ossman86350622015-11-10 13:02:12 +010053 serverpf = cp.pf();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000054
DRC33c15e32011-11-03 18:49:21 +000055 if (clientpf.equal(serverpf)) {
56 /* Decode directly into the framebuffer (fast path) */
57 directDecode = true;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000058 } else {
DRC33c15e32011-11-03 18:49:21 +000059 /* Decode into an intermediate buffer and use pixel translation */
60 directDecode = false;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000061 }
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000062
DRC33c15e32011-11-03 18:49:21 +000063 switch (serverpf.bpp) {
64 case 8:
65 tightDecode8 (r); break;
66 case 16:
67 tightDecode16(r); break;
68 case 32:
69 tightDecode32(r); break;
70 }
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000071}
Pierre Ossman7b5c0692014-03-17 14:35:51 +010072
73rdr::U32 TightDecoder::readCompact(rdr::InStream* is)
74{
75 rdr::U8 b;
76 rdr::U32 result;
77
78 b = is->readU8();
79 result = (int)b & 0x7F;
80 if (b & 0x80) {
81 b = is->readU8();
82 result |= ((int)b & 0x7F) << 7;
83 if (b & 0x80) {
84 b = is->readU8();
85 result |= ((int)b & 0xFF) << 14;
86 }
87 }
88
89 return result;
90}