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