Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2000-2003 Constantin Kaplinsky. All Rights Reserved. |
Peter Åstrand | d69bcc4 | 2011-09-28 12:52:53 +0000 | [diff] [blame] | 2 | * Copyright 2004-2005 Cendio AB. |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 3 | * Copyright (C) 2011 D. R. Commander. All Rights Reserved. |
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 | */ |
| 20 | #include <rfb/CMsgReader.h> |
Pierre Ossman | 668468b | 2014-01-31 12:37:32 +0100 | [diff] [blame] | 21 | #include <rfb/CConnection.h> |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame^] | 22 | #include <rfb/PixelBuffer.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 23 | #include <rfb/TightDecoder.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 24 | |
| 25 | using namespace rfb; |
| 26 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 27 | #define TIGHT_MAX_WIDTH 2048 |
| 28 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 29 | #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 Ossman | 668468b | 2014-01-31 12:37:32 +0100 | [diff] [blame] | 39 | TightDecoder::TightDecoder(CConnection* conn) : Decoder(conn) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 40 | { |
| 41 | } |
| 42 | |
| 43 | TightDecoder::~TightDecoder() |
| 44 | { |
| 45 | } |
| 46 | |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame^] | 47 | void TightDecoder::readRect(const Rect& r, ModifiablePixelBuffer* pb) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 48 | { |
Pierre Ossman | 668468b | 2014-01-31 12:37:32 +0100 | [diff] [blame] | 49 | is = conn->getInStream(); |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame^] | 50 | this->pb = pb; |
| 51 | clientpf = pb->getPF(); |
| 52 | serverpf = conn->cp.pf(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 53 | |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 54 | if (clientpf.equal(serverpf)) { |
| 55 | /* Decode directly into the framebuffer (fast path) */ |
| 56 | directDecode = true; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 57 | } else { |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 58 | /* Decode into an intermediate buffer and use pixel translation */ |
| 59 | directDecode = false; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 60 | } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 61 | |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 62 | switch (serverpf.bpp) { |
| 63 | case 8: |
| 64 | tightDecode8 (r); break; |
| 65 | case 16: |
| 66 | tightDecode16(r); break; |
| 67 | case 32: |
| 68 | tightDecode32(r); break; |
| 69 | } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 70 | } |
Pierre Ossman | 7b5c069 | 2014-03-17 14:35:51 +0100 | [diff] [blame] | 71 | |
| 72 | rdr::U32 TightDecoder::readCompact(rdr::InStream* is) |
| 73 | { |
| 74 | rdr::U8 b; |
| 75 | rdr::U32 result; |
| 76 | |
| 77 | b = is->readU8(); |
| 78 | result = (int)b & 0x7F; |
| 79 | if (b & 0x80) { |
| 80 | b = is->readU8(); |
| 81 | result |= ((int)b & 0x7F) << 7; |
| 82 | if (b & 0x80) { |
| 83 | b = is->readU8(); |
| 84 | result |= ((int)b & 0xFF) << 14; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return result; |
| 89 | } |