zrle.cpp
4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//
// Copyright (C) 2002 RealVNC Ltd. All Rights Reserved.
//
#include <rdr/ZlibInStream.h>
#include <rdr/FdInStream.h>
#include <rdr/Exception.h>
#include "stdhdrs.h"
#include "vncviewer.h"
// #include "ClientConnection.h"
// Instantiate the decoding function for 8, 16 and 32 BPP
//#define FAVOUR_FILL_RECT
#define zrleDecode ClientConnection::zrleDecode
#define ENDIAN_LITTLE 0
#define ENDIAN_BIG 1
#define ENDIAN_NO 2
#define BPP 8
#define ZYWRLE_ENDIAN ENDIAN_NO
#define IMAGE_RECT(x,y,w,h,data) \
SETUP_COLOR_SHORTCUTS; \
SETPIXELS(m_netbuf,8,x,y,w,h)
#define FILL_RECT(x,y,w,h,pix) \
SETUP_COLOR_SHORTCUTS; \
COLORREF color = COLOR_FROM_PIXEL8_ADDRESS(&pix); \
FillSolidRect(x,y,w,h,color)
#include <rfb/zrleDecode.h>
#undef BPP
#undef ZYWRLE_ENDIAN
#undef IMAGE_RECT
#undef FILL_RECT
#define BPP 16
#define ZYWRLE_ENDIAN ENDIAN_LITTLE
#define IMAGE_RECT(x,y,w,h,data) \
SETUP_COLOR_SHORTCUTS; \
SETPIXELS(m_netbuf,16,x,y,w,h)
#define FILL_RECT(x,y,w,h,pix) \
SETUP_COLOR_SHORTCUTS; \
COLORREF color = COLOR_FROM_PIXEL16_ADDRESS(&pix); \
FillSolidRect(x,y,w,h,color)
#include <rfb/zrleDecode.h>
#undef BPP
#undef ZYWRLE_ENDIAN
#define BPP 15
#define ZYWRLE_ENDIAN ENDIAN_LITTLE
#include <rfb/zrleDecode.h>
#undef BPP
#undef ZYWRLE_ENDIAN
#undef IMAGE_RECT
#undef FILL_RECT
#define IMAGE_RECT(x,y,w,h,data) \
SETUP_COLOR_SHORTCUTS; \
SETPIXELS(m_netbuf,32,x,y,w,h)
#define FILL_RECT(x,y,w,h,pix) \
SETUP_COLOR_SHORTCUTS; \
COLORREF color = COLOR_FROM_PIXEL32_ADDRESS(&pix); \
FillSolidRect(x,y,w,h,color)
#define BPP 32
#define ZYWRLE_ENDIAN ENDIAN_LITTLE
#include <rfb/zrleDecode.h>
#define CPIXEL 24A
#include <rfb/zrleDecode.h>
#undef CPIXEL
#define CPIXEL 24B
#include <rfb/zrleDecode.h>
#undef CPIXEL
#undef BPP
#undef ZYWRLE_ENDIAN
#undef IMAGE_RECT
#undef FILL_RECT
#undef zrleDecode
void ClientConnection::zrleDecode(int x, int y, int w, int h)
{
try {
CheckBufferSize(rfbZRLETileWidth * rfbZRLETileHeight * 4);
omni_mutex_lock l(m_bitmapdcMutex);
ObjectSelector b(m_hBitmapDC, m_hBitmap);
PaletteSelector p(m_hBitmapDC, m_hPalette);
if( zywrle ){
if( !m_opts.m_enableJpegCompression ){
zywrle_level = 1;
}else if( m_opts.m_jpegQualityLevel < 3 ){
zywrle_level = 3;
}else if( m_opts.m_jpegQualityLevel < 6 ){
zywrle_level = 2;
}else{
zywrle_level = 1;
}
}else{
zywrle_level = 0;
}
switch (m_myFormat.bitsPerPixel) {
case 8:
zrleDecode8NE(x,y,w,h,fis,zis,(rdr::U8*)m_netbuf);
break;
case 16:
if( m_myFormat.greenMax > 0x1F ){
zrleDecode16LE(x,y,w,h,fis,zis,(rdr::U16*)m_netbuf);
}else{
zrleDecode15LE(x,y,w,h,fis,zis,(rdr::U16*)m_netbuf);
}
break;
case 32:
bool fitsInLS3Bytes
= ((m_myFormat.redMax << m_myFormat.redShift) < (1<<24) &&
(m_myFormat.greenMax << m_myFormat.greenShift) < (1<<24) &&
(m_myFormat.blueMax << m_myFormat.blueShift) < (1<<24));
bool fitsInMS3Bytes = (m_myFormat.redShift > 7 &&
m_myFormat.greenShift > 7 &&
m_myFormat.blueShift > 7);
if ((fitsInLS3Bytes && !m_myFormat.bigEndian) ||
(fitsInMS3Bytes && m_myFormat.bigEndian))
{
zrleDecode24ALE(x,y,w,h,fis,zis,(rdr::U32*)m_netbuf);
}
else if ((fitsInLS3Bytes && m_myFormat.bigEndian) ||
(fitsInMS3Bytes && !m_myFormat.bigEndian))
{
zrleDecode24BLE(x,y,w,h,fis,zis,(rdr::U32*)m_netbuf);
}
else
{
zrleDecode32LE(x,y,w,h,fis,zis,(rdr::U32*)m_netbuf);
}
break;
}
} catch (rdr::Exception& e) {
fprintf(stderr,"ZRLE decoder exception: %s\n",e.str());
throw;
}
}