-
Notifications
You must be signed in to change notification settings - Fork 0
/
apendix.tex
243 lines (197 loc) · 7.79 KB
/
apendix.tex
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
\appendix
%\chapter{Diverse anexe}
%\chapter{Demonstrații matematice detaliate (dacă există)}
\chapter{Cod sursă (parțial)}
% \begin{verbatim}
% /** Maps are easy to use in Scala. */
% object Maps {
% val colors = Map("red" -> 0xFF0000,
% "turquoise" -> 0x00FFFF,
% "black" -> 0x000000,
% "orange" -> 0xFF8040,
% "brown" -> 0x804000)
% def main(args: Array[String]) {
% for (name <- args) println(
% colors.get(name) match {
% case Some(code) =>
% name + " has code: " + code
% case None =>
% "Unknown color: " + name
% }
% )
% }
% }
% \end{verbatim}
%\lstset{language=Python, showstringspaces=false, basicstyle=\tiny\ttfamily, linebreak}
\lstset{language=Python,frame=single, basicstyle=\ttfamily\small, showstringspaces=false, breaklines=true}
\begin{lstlisting}
/* Method used to create a VNC Viewer */
static PyObject *
module_CreateViewer(
PyObject* self,
PyObject* args
)
{
int retCode;
char *funcName;
char *serverName;
PLIST_T node;
Py_ssize_t pos;
PyObject *dict, *key, *value;
PyObject *key_str;
PyObject *viewer_self;
VNCViewer *viewer;
VNCViewerCallbacks vncCallbacks;
UNREFERENCED_PARAMETER(self);
pos = 0;
retCode = 0;
// Check arguments
if (!PyArg_ParseTuple(args, "O!sO", &PyDict_Type, &dict, &serverName, &viewer_self))
{
PyErr_Format(PyExc_TypeError, "You need to pass a dictionary with callback functions");
return NULL;
}
// Callback
memset(&vncCallbacks, 0, sizeof(vncCallbacks));
InitializeCallbacks(&vncCallbacks);
//Register Callbacks
while (PyDict_Next(dict, &pos, &key, &value))
{
if (!PyCallable_Check(value))
{
PyErr_SetString(PyExc_TypeError, "Parameter must be callable");
return NULL;
}
/* Prepare key and check value, then register the callback*/
key_str = PyObject_Str(key);
funcName = PyUnicode_AsUTF8(key_str);
if (!RegisterCallback(funcName, value))
{
PyErr_Format(PyExc_TypeError, "Function name not found: [%s]", funcName);
return NULL;
}
}
// Create Viewer
viewer = gVNCSdk.vncViewerCreate(&vncCallbacks, sizeof(vncCallbacks), FALSE);
if (NULL == viewer)
{
LOG_ERROR(0, "Viewer could not be created!");
retCode = 1;
goto end_this;
}
// You should keep this
if (!ListInsert(serverName, viewer_self, viewer, vncCallbacks))
{
LOG_ERROR(0, "Somehow the insert failed");
retCode = 1;
goto end_this;
}
// Set that Context ;)
node = ListGetNode(serverName);
if (NULL == node)
{
LOG_ERROR(0, "ListGetNode failed for [%s]. List probably corrupt.", serverName);
retCode = 1;
goto end_this;
}
gVNCSdk.vncViewerSetContext(node->context->pViewer, node->context);
end_this:
return Py_BuildValue("i", retCode);
}
\end{lstlisting}
\lstset{language=Python,frame=single, basicstyle=\ttfamily\small, showstringspaces=false, breaklines=true}
\begin{lstlisting}
import numpy as np
class PixelBuffer(object):
'''
Initialized at ServerInitCallback: width, height, desktopName, pServerNativePixelFormat
Copy desktop updates
'''
def __init__(self, width_height, desktop_name, rgb_max, rgb_shift, big_endian):
self.desktop_name = desktop_name
self.width, self.height = width_height
self.red_max, self.green_max, self.blue_max = rgb_max
self.red_shift, self.green_shift, self. blue_shift = rgb_shift
# ESENTIAL #
self.buffer = np.zeros((self.width,self.height))
if big_endian == 0:
self.big_endian = False
else:
self.big_endian = True
self.was_resized = False
# to be used
self.bits_per_pixel = None
self.depth = None
self.true_colour = None
def __str__(self):
pixel_info = '\nPixel Buffer [{}]'.format(self.desktop_name)
pixel_info += '\n * width [{}] x height [{}]'.format(self.width, self.height)
pixel_info += '\n * red max [{}] shift [{}]'.format(self.red_max, self.red_shift)
pixel_info += '\n * green max [{}] shift [{}]'.format(self.green_max, self.green_shift)
pixel_info += '\n * blue max [{}] shift [{}]'.format(self.blue_max, self.blue_shift)
pixel_info += '\n * big_endian [{}]'.format(self.big_endian)
pixel_info += '\n * ...'
return pixel_info
def update_rectangle(self,tx_ty, bx_by, pixel_data,
'''
Interpret pixel data and update Pixel Buffer submatrix with the new pixel info
tx_ty: (top left x, top left y)
bx_by: (bot left x, bot left y)
pixel_data: submatrix to be interpreted
data_len: !!! not used yet !!!
'''
top_left_x, top_left_y = tx_ty
bot_left_x, bot_left_y = bx_by
red = (np.right_shift(pixel_data, self.red_shift) & self.red_max) * 255 / self.red_max
red = red.astype(np.int32)
red = np.left_shift(red, 16)
green = (np.right_shift(pixel_data, self.green_shift) & self.green_max) * 255 / self.green_max
green = green.astype(np.int32)
green = np.left_shift(green, 8)
blue = (np.right_shift(pixel_data, self.blue_shift) & self.blue_max) * 255 / self.blue_max
blue = blue.astype(np.int32)
temp = red + green + blue
temp = np.fliplr(temp)
temp = np.rot90(temp)
self.buffer[top_left_x:bot_left_x , top_left_y:bot_left_y] = temp
def fill_rectangle(self,tx_ty, bx_by, pixel_data):
'''Fill rectangle at a given pos in Pixel Buffer with a single colour
tx_ty: (top left x, top left y)
bx_by: (bot left x, bot left y)
pixel_data: bytearray to be interpreted
'''
top_left_x, top_left_y = tx_ty
bot_left_x, bot_left_y = bx_by
if self.big_endian:
pixel_data = int.from_bytes(pixel_data, byteorder='big')
else:
pixel_data = int.from_bytes(pixel_data, byteorder='little')
red = ((pixel_data >> self.red_shift) & self.red_max) * 255 / self.red_max
red = int(red) << 16
green = ((pixel_data >> self.green_shift) & self.green_max) * 255 / self.green_max
green = int(green) << 8
blue = ((pixel_data >> self.blue_shift) & self.blue_max) * 255 / self.blue_max
blue = int(blue) << 0
self.buffer[top_left_x:bot_left_x , top_left_y:bot_left_y] = red + green + blue
return True
def copy_rectangle(destination, source):#NOT TESTED
'''Copy submatrix within the Pixel Buffer
destination: (dest->topLeft.x, dest->topLeft.y, dest->bottomRight.x, dest->bottomRight.y)
The rectangle on the VNC server desktop that is being
updated - that is, the destination of the copy.
source: (pSource.x, pSource.y)
The top-left corner of the source of the copy. The area to
be copied is the same as the area of *pDestination.
'''
dest_top_x, dest_top_y, dest_bot_x, dest_bot_y = destination
src_x, src_y = source
x = dest_bot_x - dest_top_x
y = dest_bot_y - dest_top_y
self.buffer[dest_top_x:dest_bot_x, dest_top_y:dest_bot_y] = self.buffer[src_x:src_x + x,src_y:src_y + y]
return True
def resize_screen(self, new_width_height):
self.width, self.height = new_width_height
self.buffer = np.zeros((self.width,self.height))
self.was_resized = True
\end{lstlisting}
%\chapter{Articole publicate}