blob: 2dd4a1292ef4dc4bccd0d41583171c1ae3b72513 [file] [log] [blame]
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00001/* Copyright (C) 2002-2003 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18#include <rfb/CMsgReader.h>
19#include <rfb/CMsgHandler.h>
20#include <rfb/ZRLEDecoder.h>
21
22using namespace rfb;
23
24#define EXTRA_ARGS CMsgHandler* handler
25#define FILL_RECT(r, p) handler->fillRect(r, p)
26#define IMAGE_RECT(r, p) handler->imageRect(r, p)
27#define BPP 8
28#include <rfb/zrleDecode.h>
29#undef BPP
30#define BPP 16
31#include <rfb/zrleDecode.h>
32#undef BPP
33#define BPP 32
34#include <rfb/zrleDecode.h>
35#define CPIXEL 24A
36#include <rfb/zrleDecode.h>
37#undef CPIXEL
38#define CPIXEL 24B
39#include <rfb/zrleDecode.h>
40#undef CPIXEL
41#undef BPP
42
43Decoder* ZRLEDecoder::create(CMsgReader* reader)
44{
45 return new ZRLEDecoder(reader);
46}
47
48ZRLEDecoder::ZRLEDecoder(CMsgReader* reader_) : reader(reader_)
49{
50}
51
52ZRLEDecoder::~ZRLEDecoder()
53{
54}
55
56void ZRLEDecoder::readRect(const Rect& r, CMsgHandler* handler)
57{
58 rdr::InStream* is = reader->getInStream();
59 rdr::U8* buf = reader->getImageBuf(64 * 64 * 4);
60 switch (reader->bpp()) {
61 case 8: zrleDecode8 (r, is, &zis, (rdr::U8*) buf, handler); break;
62 case 16: zrleDecode16(r, is, &zis, (rdr::U16*)buf, handler); break;
63 case 32:
64 {
65 const rfb::PixelFormat& pf = handler->cp.pf();
66 bool fitsInLS3Bytes = ((pf.redMax << pf.redShift) < (1<<24) &&
67 (pf.greenMax << pf.greenShift) < (1<<24) &&
68 (pf.blueMax << pf.blueShift) < (1<<24));
69
70 bool fitsInMS3Bytes = (pf.redShift > 7 &&
71 pf.greenShift > 7 &&
72 pf.blueShift > 7);
73
74 if ((fitsInLS3Bytes && !pf.bigEndian) ||
75 (fitsInMS3Bytes && pf.bigEndian))
76 {
77 zrleDecode24A(r, is, &zis, (rdr::U32*)buf, handler);
78 }
79 else if ((fitsInLS3Bytes && pf.bigEndian) ||
80 (fitsInMS3Bytes && !pf.bigEndian))
81 {
82 zrleDecode24B(r, is, &zis, (rdr::U32*)buf, handler);
83 }
84 else
85 {
86 zrleDecode32(r, is, &zis, (rdr::U32*)buf, handler);
87 }
88 break;
89 }
90 }
91}