Rev 5722 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5717 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2010-2015. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;; VNC client for KolibriOS ;; |
||
7 | ;; ;; |
||
8 | ;; Written by hidnplayr@kolibrios.org ;; |
||
9 | ;; ;; |
||
10 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
11 | ;; Version 2, June 1991 ;; |
||
12 | ;; ;; |
||
13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
14 | |||
5722 | hidnplayr | 15 | |
5717 | hidnplayr | 16 | deflate_callback: |
17 | mov eax, [deflate_length] |
||
18 | mov ecx, [esp+8] |
||
19 | mov [ecx], eax |
||
20 | mov eax, [deflate_buffer] |
||
21 | ret 8 |
||
22 | |||
5722 | hidnplayr | 23 | |
5717 | hidnplayr | 24 | encoding_ZRLE: |
25 | |||
26 | DEBUGF 2, "ZRLE\n" |
||
27 | @@: |
||
28 | lea eax, [esi+4] |
||
29 | cmp [datapointer], eax |
||
30 | jae @f |
||
31 | call read_data.more |
||
32 | jmp @b |
||
33 | @@: |
||
34 | |||
35 | lodsd |
||
36 | bswap eax ; number of packed bytes |
||
37 | DEBUGF 2, "packed length=%u bytes\n", eax |
||
38 | |||
39 | @@: |
||
40 | push eax |
||
41 | add eax, esi |
||
42 | cmp [datapointer], eax |
||
43 | jae @f |
||
44 | call read_data.more |
||
45 | pop eax |
||
46 | jmp @b |
||
47 | @@: |
||
48 | pop ecx |
||
49 | lea eax, [esi+ecx] |
||
50 | push eax ; end of data ptr |
||
51 | |||
52 | cmp [deflate_buffer], 0 ; first chunk of the stream? |
||
53 | jne @f |
||
54 | lodsw ; load zlib header |
||
55 | cmp ax, 0x9c78 ; default compression? |
||
56 | jne .deflate_fail |
||
57 | sub ecx, 2 ; subtract 2 byte header |
||
58 | |||
59 | ; invoke deflate_init |
||
60 | ; mov [deflate_str], eax |
||
61 | @@: |
||
62 | |||
63 | sub ecx, 4 ; subtract 4 byte check value trailer |
||
64 | mov [deflate_buffer], esi |
||
65 | mov [deflate_length], ecx |
||
66 | |||
67 | ; mov eax, [deflate_str] |
||
68 | push eax ; allocate place on stack |
||
69 | invoke deflate_unpack2, deflate_callback, 0, esp ; unpack the data |
||
70 | pop ecx ; get size in ecx |
||
71 | test eax, eax |
||
72 | jz .deflate_fail |
||
73 | push eax |
||
74 | DEBUGF 2, "%u bytes unpacked succesfully\n", ecx |
||
75 | test ecx, ecx |
||
76 | jz .fail |
||
77 | |||
78 | mov esi, eax |
||
79 | mov [subrectangle.x], 0 |
||
80 | mov [subrectangle.y], 0 |
||
81 | .tile: |
||
82 | mov eax, [rectangle.width] |
||
83 | sub eax, [subrectangle.x] |
||
84 | cmp eax, 64 |
||
85 | jb @f |
||
86 | mov eax, 64 |
||
87 | @@: |
||
88 | mov [subrectangle.width], eax |
||
89 | |||
90 | mov edx, [rectangle.height] |
||
91 | sub edx, [subrectangle.y] |
||
92 | cmp edx, 64 |
||
93 | jb @f |
||
94 | mov edx, 64 |
||
95 | @@: |
||
96 | mov [subrectangle.height], edx |
||
97 | DEBUGF 1, "Subrectangle: x=%u y=%u width=%u height=%u ", \ |
||
98 | [subrectangle.x], [subrectangle.y], [subrectangle.width], [subrectangle.height] |
||
99 | |||
100 | ; Calculate first pixel pos |
||
101 | mov eax, [rectangle.y] |
||
102 | add eax, [subrectangle.y] |
||
103 | movzx ebx, [screen.width] |
||
104 | mul ebx |
||
105 | add eax, [rectangle.x] |
||
106 | add eax, [subrectangle.x] |
||
5722 | hidnplayr | 107 | lea edi, [framebuffer+eax*3] |
5717 | hidnplayr | 108 | |
109 | ; Calculate offset between two rows of pixels |
||
110 | movzx eax, [screen.width] |
||
111 | sub eax, [subrectangle.width] |
||
112 | lea ebp, [eax*3] |
||
113 | |||
114 | mov edx, [subrectangle.height] |
||
115 | |||
116 | ;;;; |
||
117 | lodsb ; subencoding type |
||
118 | DEBUGF 1, "encoding=%u\n", al |
||
119 | test al, al |
||
120 | jz .raw |
||
121 | cmp al, 1 |
||
122 | je .solid |
||
123 | cmp al, 16 |
||
124 | jbe .palette_packed |
||
125 | cmp al, 127 |
||
126 | je .reuse_palette |
||
127 | jb .invalid |
||
128 | and al, 0x7f |
||
129 | jz .plain_rle |
||
130 | cmp al, 1 |
||
131 | je .prle_reuse_palette |
||
132 | |||
133 | ; Palette Run Length Encoded tile |
||
134 | mov [palettesize], al |
||
135 | call create_palette |
||
136 | .prle_reuse_palette: |
||
137 | DEBUGF 1, "Pallete RLE tile\n" |
||
138 | |||
139 | mov eax, 1 |
||
140 | .prle_line: |
||
141 | mov ebx, [subrectangle.width] |
||
142 | .prle_pixel: |
||
143 | dec eax |
||
144 | jz .prle_reload |
||
145 | |||
146 | mov word[edi], cx |
||
147 | rol ecx, 16 |
||
148 | add edi, 2 |
||
149 | mov byte[edi], cl |
||
150 | rol ecx, 16 |
||
151 | inc edi |
||
152 | dec ebx |
||
153 | jnz .prle_pixel |
||
154 | |||
155 | add edi, ebp |
||
156 | dec edx |
||
157 | jnz .prle_line |
||
158 | jmp .next_tile |
||
159 | |||
160 | .prle_reload: |
||
161 | ;;; |
||
162 | ; load palette index and get color from palette |
||
163 | xor eax, eax |
||
164 | lodsb |
||
165 | push ebx |
||
166 | mov bl, al |
||
167 | and al, 0x7f |
||
168 | mov ecx, [palette+eax*4] |
||
169 | |||
170 | ; run length follows? |
||
171 | xor eax, eax |
||
172 | test bl, 0x80 |
||
173 | pop ebx |
||
174 | jz .plength_ok |
||
175 | |||
176 | ;;; |
||
177 | |||
178 | ; load runlength |
||
179 | push ebx |
||
180 | xor eax, eax |
||
181 | xor ebx, ebx |
||
182 | @@: |
||
183 | lodsb |
||
184 | cmp al, 255 |
||
185 | jne @f |
||
186 | add ebx, eax |
||
187 | jmp @b |
||
188 | @@: |
||
189 | add eax, ebx |
||
190 | pop ebx |
||
191 | .plength_ok: |
||
192 | add eax, 2 |
||
193 | jmp .prle_pixel |
||
194 | |||
195 | |||
196 | |||
197 | |||
198 | ; Run Length Encoded tile |
||
199 | .plain_rle: |
||
200 | |||
201 | DEBUGF 1, "Plain RLE tile\n" |
||
202 | |||
203 | mov eax, 1 |
||
204 | .rle_line: |
||
205 | mov ebx, [subrectangle.width] |
||
206 | .rle_pixel: |
||
207 | dec eax |
||
208 | jz .rle_reload |
||
209 | |||
210 | mov word[edi], cx |
||
211 | rol ecx, 16 |
||
212 | add edi, 2 |
||
213 | mov byte[edi], cl |
||
214 | rol ecx, 16 |
||
215 | inc edi |
||
216 | dec ebx |
||
217 | jnz .rle_pixel |
||
218 | add edi, ebp |
||
219 | dec edx |
||
220 | jnz .rle_line |
||
221 | jmp .next_tile |
||
222 | |||
223 | .rle_reload: |
||
5750 | hidnplayr | 224 | ; TODO: check for buffer underrun |
5717 | hidnplayr | 225 | |
5750 | hidnplayr | 226 | ; load pixel value |
227 | call load_cpixel |
||
228 | mov ecx, eax |
||
5717 | hidnplayr | 229 | |
230 | ; load length |
||
231 | xor eax, eax |
||
232 | push ebx |
||
233 | xor ebx, ebx |
||
234 | @@: |
||
235 | lodsb |
||
236 | cmp al, 255 |
||
237 | jne @f |
||
238 | add ebx, eax |
||
239 | jmp @b |
||
240 | @@: |
||
241 | add eax, ebx |
||
242 | add eax, 2 |
||
243 | pop ebx |
||
244 | jmp .rle_pixel |
||
245 | |||
246 | |||
247 | |||
248 | .reuse_palette: |
||
249 | cmp [palettesize], 1 |
||
250 | jne .reuse_palette_ |
||
251 | mov ecx, [palette] |
||
252 | mov eax, ecx |
||
253 | shr eax, 16 |
||
254 | jmp .solid_line |
||
255 | |||
256 | ; Palette packed tile |
||
257 | .palette_packed: |
||
258 | DEBUGF 1, "Palette packed tile\n" |
||
259 | |||
260 | mov [palettesize], al |
||
261 | call create_palette |
||
262 | |||
263 | .reuse_palette_: |
||
264 | cmp [palettesize], 2 |
||
265 | je .palette_1bit |
||
266 | cmp [palettesize], 4 |
||
267 | jbe .palette_2bit |
||
268 | jmp .palette_4bit |
||
269 | |||
270 | .palette_1bit: |
||
271 | DEBUGF 1, "1-bit palette\n" |
||
272 | .palette_1bit_line: |
||
273 | mov ebx, [subrectangle.width] |
||
274 | .palette_1bit_byte: |
||
275 | lodsb |
||
276 | rol al, 1 |
||
277 | mov ecx, eax |
||
278 | and eax, 0x1 |
||
279 | mov eax, [palette+4*eax] |
||
280 | stosw |
||
281 | shr eax, 16 |
||
282 | stosb |
||
283 | dec ebx |
||
284 | jz .palette_1bit_next_line |
||
285 | |||
286 | rol cl, 1 |
||
287 | mov eax, ecx |
||
288 | and eax, 0x1 |
||
289 | mov eax, [palette+4*eax] |
||
290 | stosw |
||
291 | shr eax, 16 |
||
292 | stosb |
||
293 | dec ebx |
||
294 | jz .palette_1bit_next_line |
||
295 | |||
296 | rol cl, 1 |
||
297 | mov eax, ecx |
||
298 | and eax, 0x1 |
||
299 | mov eax, [palette+4*eax] |
||
300 | stosw |
||
301 | shr eax, 16 |
||
302 | stosb |
||
303 | dec ebx |
||
304 | jz .palette_1bit_next_line |
||
305 | |||
306 | rol cl, 1 |
||
307 | mov eax, ecx |
||
308 | and eax, 0x1 |
||
309 | mov eax, [palette+4*eax] |
||
310 | stosw |
||
311 | shr eax, 16 |
||
312 | stosb |
||
313 | dec ebx |
||
314 | jz .palette_1bit_next_line |
||
315 | |||
316 | rol cl, 1 |
||
317 | mov eax, ecx |
||
318 | and eax, 0x1 |
||
319 | mov eax, [palette+4*eax] |
||
320 | stosw |
||
321 | shr eax, 16 |
||
322 | stosb |
||
323 | dec ebx |
||
324 | jz .palette_1bit_next_line |
||
325 | |||
326 | rol cl, 1 |
||
327 | mov eax, ecx |
||
328 | and eax, 0x1 |
||
329 | mov eax, [palette+4*eax] |
||
330 | stosw |
||
331 | shr eax, 16 |
||
332 | stosb |
||
333 | dec ebx |
||
334 | jz .palette_1bit_next_line |
||
335 | |||
336 | rol cl, 1 |
||
337 | mov eax, ecx |
||
338 | and eax, 0x1 |
||
339 | mov eax, [palette+4*eax] |
||
340 | stosw |
||
341 | shr eax, 16 |
||
342 | stosb |
||
343 | dec ebx |
||
344 | jz .palette_1bit_next_line |
||
345 | |||
346 | rol cl, 1 |
||
347 | and ecx, 0x1 |
||
348 | mov eax, [palette+4*ecx] |
||
349 | stosw |
||
350 | shr eax, 16 |
||
351 | stosb |
||
352 | dec ebx |
||
353 | jnz .palette_1bit_byte |
||
354 | |||
355 | .palette_1bit_next_line: |
||
356 | add edi, ebp |
||
357 | dec edx |
||
358 | jnz .palette_1bit_line |
||
359 | jmp .next_tile |
||
360 | |||
361 | |||
362 | |||
363 | .palette_2bit: |
||
364 | DEBUGF 1, "2-bit palette\n" |
||
365 | .palette_2bit_line: |
||
366 | mov ebx, [subrectangle.width] |
||
367 | .palette_2bit_byte: |
||
368 | lodsb |
||
369 | mov ecx, eax |
||
370 | and eax, 0xc0 |
||
371 | shr eax, 4 |
||
372 | mov eax, [palette+eax] |
||
373 | stosw |
||
374 | shr eax, 16 |
||
375 | stosb |
||
376 | dec ebx |
||
377 | jz .palette_2bit_next_line |
||
378 | |||
379 | mov eax, ecx |
||
380 | and eax, 0x30 |
||
381 | shr eax, 2 |
||
382 | mov eax, [palette+eax] |
||
383 | stosw |
||
384 | shr eax, 16 |
||
385 | stosb |
||
386 | dec ebx |
||
387 | jz .palette_2bit_next_line |
||
388 | |||
389 | mov eax, ecx |
||
390 | and eax, 0x0c |
||
391 | mov eax, [palette+eax] |
||
392 | stosw |
||
393 | shr eax, 16 |
||
394 | stosb |
||
395 | dec ebx |
||
396 | jz .palette_2bit_next_line |
||
397 | |||
398 | and ecx, 0x03 |
||
399 | mov eax, [palette+4*ecx] |
||
400 | stosw |
||
401 | shr eax, 16 |
||
402 | stosb |
||
403 | dec ebx |
||
404 | jnz .palette_2bit_byte |
||
405 | |||
406 | .palette_2bit_next_line: |
||
407 | add edi, ebp |
||
408 | dec edx |
||
409 | jnz .palette_2bit_line |
||
410 | jmp .next_tile |
||
411 | |||
412 | |||
413 | |||
414 | |||
415 | .palette_4bit: |
||
416 | DEBUGF 1, "4-bit palette\n" |
||
417 | .palette_4bit_line: |
||
418 | mov ebx, [subrectangle.width] |
||
419 | .palette_4bit_byte: |
||
420 | lodsb |
||
421 | mov cl, al |
||
422 | and eax, 0xf0 |
||
423 | shr eax, 2 |
||
424 | mov eax, [palette+eax] |
||
425 | stosw |
||
426 | shr eax, 16 |
||
427 | stosb |
||
428 | dec ebx |
||
429 | jz .palette_4bit_next_line |
||
430 | |||
431 | and ecx, 0x0f |
||
432 | shl ecx, 2 |
||
433 | mov eax, [palette+ecx] |
||
434 | stosw |
||
435 | shr eax, 16 |
||
436 | stosb |
||
437 | dec ebx |
||
438 | jnz .palette_4bit_byte |
||
439 | .palette_4bit_next_line: |
||
440 | add edi, ebp |
||
441 | dec edx |
||
442 | jnz .palette_4bit_line |
||
443 | jmp .next_tile |
||
444 | |||
445 | |||
446 | ; RAW tile |
||
447 | .raw: |
||
448 | push edx |
||
449 | mov eax, [subrectangle.width] |
||
450 | mul [subrectangle.height] |
||
451 | lea eax, [eax*3] |
||
452 | pop edx |
||
453 | |||
5750 | hidnplayr | 454 | ; TODO: check for buffer underrun |
5717 | hidnplayr | 455 | |
456 | DEBUGF 1, "RAW tile\n" |
||
457 | .raw_line: |
||
458 | mov ebx, [subrectangle.width] |
||
459 | .raw_pixel: |
||
5750 | hidnplayr | 460 | call load_cpixel |
461 | stosw |
||
462 | shr eax, 16 |
||
463 | stosb |
||
5717 | hidnplayr | 464 | dec ebx |
465 | jnz .raw_pixel |
||
466 | add edi, ebp |
||
467 | dec edx |
||
468 | jnz .raw_line |
||
469 | jmp .next_tile |
||
470 | |||
471 | |||
472 | |||
473 | ; Single color tile |
||
474 | .solid: |
||
475 | DEBUGF 1, "Solid tile\n" |
||
476 | |||
5750 | hidnplayr | 477 | ; TODO: check for buffer underrun |
478 | |||
479 | call load_cpixel |
||
480 | mov ecx, eax |
||
481 | shr ecx, 16 |
||
482 | |||
5717 | hidnplayr | 483 | mov [palettesize], 1 |
5750 | hidnplayr | 484 | mov [palette], eax |
5717 | hidnplayr | 485 | |
486 | .solid_line: |
||
487 | mov ebx, [subrectangle.width] |
||
488 | .solid_pixel: |
||
5750 | hidnplayr | 489 | stosw |
490 | mov [edi], cl |
||
5717 | hidnplayr | 491 | inc edi |
492 | dec ebx |
||
493 | jnz .solid_pixel |
||
494 | add edi, ebp |
||
495 | dec edx |
||
496 | jnz .solid_line |
||
497 | ; jmp .next_tile |
||
498 | |||
499 | |||
500 | ; Go to the next tile |
||
501 | .next_tile: |
||
502 | mov eax, [subrectangle.x] |
||
503 | add eax, 64 |
||
504 | cmp eax, [rectangle.width] |
||
505 | jae .next_row |
||
506 | mov [subrectangle.x], eax |
||
507 | jmp .tile |
||
508 | .next_row: |
||
509 | mov [subrectangle.x], 0 |
||
510 | mov eax, [subrectangle.y] |
||
511 | add eax, 64 |
||
512 | cmp eax, [rectangle.height] |
||
513 | jae .done |
||
514 | mov [subrectangle.y], eax |
||
515 | jmp .tile |
||
516 | |||
517 | .done: |
||
518 | DEBUGF 1, "ZRLE complete!\n" |
||
519 | pop ecx |
||
520 | mcall 68, 13 ; free the unpacked data |
||
521 | pop esi |
||
522 | jmp next_rectangle |
||
523 | |||
524 | .invalid: |
||
525 | DEBUGF 2, "Invalid subencoding type!\n" |
||
526 | .fail: |
||
527 | DEBUGF 2, "ZRLE failed!\n" |
||
528 | pop ecx |
||
529 | mcall 68, 13 ; free unpacked data |
||
530 | pop esi |
||
531 | jmp next_rectangle |
||
532 | |||
533 | |||
534 | .deflate_fail: |
||
535 | DEBUGF 2,"Unpacking failed!\n" |
||
536 | pop esi |
||
537 | jmp next_rectangle |