translate.cpp
5.19 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
* translate.c - translate between different pixel formats
*/
/*
* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
#include "stdhdrs.h"
#include "translate.h"
#include <stdio.h>
#include "rfb.h"
#include "vncOSVersion.h"
#define CONCAT2(a,b) a##b
#define CONCAT2E(a,b) CONCAT2(a,b)
#define CONCAT4(a,b,c,d) a##b##c##d
#define CONCAT4E(a,b,c,d) CONCAT4(a,b,c,d)
#define OUTVNC 8
#include "tableinittctemplate.cpp"
#include "tableinitcmtemplate.cpp"
#define INVNC 8
#include "tabletranstemplate.cpp"
#undef INVNC
#define INVNC 16
#include "tabletranstemplate.cpp"
#undef INVNC
#define INVNC 32
#include "tabletranstemplate.cpp"
#undef INVNC
#undef OUTVNC
#define OUTVNC 16
#include "tableinittctemplate.cpp"
#include "tableinitcmtemplate.cpp"
#define INVNC 8
#include "tabletranstemplate.cpp"
#undef INVNC
#define INVNC 16
#include "tabletranstemplate.cpp"
#undef INVNC
#define INVNC 32
#include "tabletranstemplate.cpp"
#undef INVNC
#undef OUTVNC
#define OUTVNC 32
#include "tableinittctemplate.cpp"
#include "tableinitcmtemplate.cpp"
#define INVNC 8
#include "tabletranstemplate.cpp"
#undef INVNC
#define INVNC 16
#include "tabletranstemplate.cpp"
#undef INVNC
#define INVNC 32
#include "tabletranstemplate.cpp"
#undef INVNC
#undef OUTVNC
rfbInitTableFnType rfbInitTrueColourSingleTableFns[3] = {
rfbInitTrueColourSingleTable8,
rfbInitTrueColourSingleTable16,
rfbInitTrueColourSingleTable32
};
rfbInitTableFnType rfbInitColourMapSingleTableFns[3] = {
rfbInitColourMapSingleTable8,
rfbInitColourMapSingleTable16,
rfbInitColourMapSingleTable32
};
rfbInitTableFnType rfbInitTrueColourRGBTablesFns[3] = {
rfbInitTrueColourRGBTables8,
rfbInitTrueColourRGBTables16,
rfbInitTrueColourRGBTables32
};
rfbTranslateFnType rfbTranslateWithSingleTableFns[3][3] = {
{ rfbTranslateWithSingleTable8to8,
rfbTranslateWithSingleTable8to16,
rfbTranslateWithSingleTable8to32 },
{ rfbTranslateWithSingleTable16to8,
rfbTranslateWithSingleTable16to16,
rfbTranslateWithSingleTable16to32 },
{ rfbTranslateWithSingleTable32to8,
rfbTranslateWithSingleTable32to16,
rfbTranslateWithSingleTable32to32 }
};
rfbTranslateFnType rfbTranslateWithRGBTablesFns[3][3] = {
{ rfbTranslateWithRGBTables8to8,
rfbTranslateWithRGBTables8to16,
rfbTranslateWithRGBTables8to32 },
{ rfbTranslateWithRGBTables16to8,
rfbTranslateWithRGBTables16to16,
rfbTranslateWithRGBTables16to32 },
{ rfbTranslateWithRGBTables32to8,
rfbTranslateWithRGBTables32to16,
rfbTranslateWithRGBTables32to32 }
};
// rfbTranslateNone is used when no translation is required.
void
rfbTranslateNone(char *table, rfbPixelFormat *in, rfbPixelFormat *out,
char *iptr, char *optr, int bytesBetweenInputLines,
int width, int height)
{
int bytesPerOutputLine = width * (out->bitsPerPixel / 8);
while (height > 0) {
if(IsBadReadPtr(iptr,bytesPerOutputLine)) return;
if(IsBadWritePtr(optr,bytesPerOutputLine)) return;
memcpy(optr, iptr, bytesPerOutputLine);
iptr += bytesBetweenInputLines;
optr += bytesPerOutputLine;
height--;
}
}
HDC GetDcMirror()
{
if(OSVersion()==1)
{
typedef BOOL (WINAPI* pEnumDisplayDevices)(PVOID,DWORD,PVOID,DWORD);
HDC m_hrootdc;
pEnumDisplayDevices pd;
LPSTR driverName = "Winvnc video hook driver";
BOOL DriverFound;
DEVMODE devmode;
FillMemory(&devmode, sizeof(DEVMODE), 0);
devmode.dmSize = sizeof(DEVMODE);
devmode.dmDriverExtra = 0;
BOOL change = EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&devmode);
devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
HMODULE hUser32=LoadLibrary("USER32");
pd = (pEnumDisplayDevices)GetProcAddress( hUser32, "EnumDisplayDevicesA");
if (pd)
{
LPSTR deviceName=NULL;
DISPLAY_DEVICE dd;
ZeroMemory(&dd, sizeof(dd));
dd.cb = sizeof(dd);
devmode.dmDeviceName[0] = '\0';
INT devNum = 0;
BOOL result;
DriverFound=false;
while (result = (*pd)(NULL,devNum, &dd,0))
{
if (strcmp((const char *)&dd.DeviceString[0], driverName) == 0)
{
DriverFound=true;
break;
}
devNum++;
}
if (DriverFound)
{
deviceName = (LPSTR)&dd.DeviceName[0];
m_hrootdc = CreateDC("DISPLAY",deviceName,NULL,NULL);
}
}
if (hUser32) FreeLibrary(hUser32);
return m_hrootdc;
}
else return NULL;
}