Subversion Repositories Kolibri OS

Rev

Rev 5752 | 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]
5752 hidnplayr 20
        lea     edi, [ecx*BYTES_PER_CPIXEL]
5716 hidnplayr 21
 
5722 hidnplayr 22
  @@:
5752 hidnplayr 23
        lea     eax, [esi+edi]
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:
5756 hidnplayr 302
  @@:
303
        lea     eax, [esi+1]
304
        cmp     [datapointer], eax
305
        jae     @f
306
        call    read_data.more
307
        jmp     @b
308
  @@:
5716 hidnplayr 309
        lodsb
310
        rol     al, 1
311
        mov     ecx, eax
312
        and     eax, 0x1
313
        mov     eax, [palette+4*eax]
314
        stosw
315
        shr     eax, 16
316
        stosb
317
        dec     ebx
318
        jz      .palette_1bit_next_line
319
 
320
        rol     cl, 1
321
        mov     eax, ecx
322
        and     eax, 0x1
323
        mov     eax, [palette+4*eax]
324
        stosw
325
        shr     eax, 16
326
        stosb
327
        dec     ebx
328
        jz      .palette_1bit_next_line
329
 
330
        rol     cl, 1
331
        mov     eax, ecx
332
        and     eax, 0x1
333
        mov     eax, [palette+4*eax]
334
        stosw
335
        shr     eax, 16
336
        stosb
337
        dec     ebx
338
        jz      .palette_1bit_next_line
339
 
340
        rol     cl, 1
341
        mov     eax, ecx
342
        and     eax, 0x1
343
        mov     eax, [palette+4*eax]
344
        stosw
345
        shr     eax, 16
346
        stosb
347
        dec     ebx
348
        jz      .palette_1bit_next_line
349
 
350
        rol     cl, 1
351
        mov     eax, ecx
352
        and     eax, 0x1
353
        mov     eax, [palette+4*eax]
354
        stosw
355
        shr     eax, 16
356
        stosb
357
        dec     ebx
358
        jz      .palette_1bit_next_line
359
 
360
        rol     cl, 1
361
        mov     eax, ecx
362
        and     eax, 0x1
363
        mov     eax, [palette+4*eax]
364
        stosw
365
        shr     eax, 16
366
        stosb
367
        dec     ebx
368
        jz      .palette_1bit_next_line
369
 
370
        rol     cl, 1
371
        mov     eax, ecx
372
        and     eax, 0x1
373
        mov     eax, [palette+4*eax]
374
        stosw
375
        shr     eax, 16
376
        stosb
377
        dec     ebx
378
        jz      .palette_1bit_next_line
379
 
380
        rol     cl, 1
381
        and     ecx, 0x1
382
        mov     eax, [palette+4*ecx]
383
        stosw
384
        shr     eax, 16
385
        stosb
386
        dec     ebx
387
        jnz     .palette_1bit_byte
388
 
389
  .palette_1bit_next_line:
390
        add     edi, ebp
391
        dec     edx
392
        jnz     .palette_1bit_line
393
        jmp     .next_tile
394
 
395
 
396
 
397
  .palette_2bit:
398
        DEBUGF  1, "2-bit palette\n"
399
  .palette_2bit_line:
400
        mov     ebx, [subrectangle.width]
401
  .palette_2bit_byte:
5756 hidnplayr 402
  @@:
403
        lea     eax, [esi+1]
404
        cmp     [datapointer], eax
405
        jae     @f
406
        call    read_data.more
407
        jmp     @b
408
  @@:
5716 hidnplayr 409
        lodsb
410
        mov     ecx, eax
411
        and     eax, 0xc0
412
        shr     eax, 4
413
        mov     eax, [palette+eax]
414
        stosw
415
        shr     eax, 16
416
        stosb
417
        dec     ebx
418
        jz      .palette_2bit_next_line
419
 
420
        mov     eax, ecx
421
        and     eax, 0x30
422
        shr     eax, 2
423
        mov     eax, [palette+eax]
424
        stosw
425
        shr     eax, 16
426
        stosb
427
        dec     ebx
428
        jz      .palette_2bit_next_line
429
 
430
        mov     eax, ecx
431
        and     eax, 0x0c
432
        mov     eax, [palette+eax]
433
        stosw
434
        shr     eax, 16
435
        stosb
436
        dec     ebx
437
        jz      .palette_2bit_next_line
438
 
439
        and     ecx, 0x03
440
        mov     eax, [palette+4*ecx]
441
        stosw
442
        shr     eax, 16
443
        stosb
444
        dec     ebx
445
        jnz     .palette_2bit_byte
446
 
447
  .palette_2bit_next_line:
448
        add     edi, ebp
449
        dec     edx
450
        jnz     .palette_2bit_line
451
        jmp     .next_tile
452
 
453
 
454
 
455
 
456
  .palette_4bit:
457
        DEBUGF  1, "4-bit palette\n"
458
  .palette_4bit_line:
459
        mov     ebx, [subrectangle.width]
460
  .palette_4bit_byte:
5756 hidnplayr 461
  @@:
462
        lea     eax, [esi+1]
463
        cmp     [datapointer], eax
464
        jae     @f
465
        call    read_data.more
466
        jmp     @b
467
  @@:
5716 hidnplayr 468
        lodsb
469
        mov     cl, al
470
        and     eax, 0xf0
471
        shr     eax, 2
472
        mov     eax, [palette+eax]
473
        stosw
474
        shr     eax, 16
475
        stosb
476
        dec     ebx
477
        jz      .palette_4bit_next_line
478
 
479
        and     ecx, 0x0f
480
        shl     ecx, 2
481
        mov     eax, [palette+ecx]
482
        stosw
483
        shr     eax, 16
484
        stosb
485
        dec     ebx
486
        jnz     .palette_4bit_byte
487
  .palette_4bit_next_line:
488
        add     edi, ebp
489
        dec     edx
490
        jnz     .palette_4bit_line
491
        jmp     .next_tile
492
 
493
 
494
; RAW tile
495
  .raw:
496
        push    edx
497
        mov     eax, [subrectangle.width]
498
        mul     [subrectangle.height]
499
 
5750 hidnplayr 500
        push    eax
501
        lea     ecx, [eax*BYTES_PER_CPIXEL]
5716 hidnplayr 502
  @@:
5750 hidnplayr 503
        lea     eax, [esi+ecx]
5716 hidnplayr 504
        cmp     [datapointer], eax
505
        jae     @f
506
        call    read_data.more
507
        jmp     @b
508
  @@:
509
        pop     eax
5750 hidnplayr 510
        lea     eax, [eax*3]
511
        pop     edx
5716 hidnplayr 512
 
513
        DEBUGF  1, "RAW tile\n"
514
  .raw_line:
515
        mov     ebx, [subrectangle.width]
516
  .raw_pixel:
5750 hidnplayr 517
        call    load_cpixel
518
        stosw
519
        shr     eax, 16
520
        stosb
5716 hidnplayr 521
        dec     ebx
522
        jnz     .raw_pixel
523
        add     edi, ebp
524
        dec     edx
525
        jnz     .raw_line
526
        jmp     .next_tile
527
 
528
 
529
 
530
; Single color tile
531
  .solid:
532
        DEBUGF  1, "Solid tile\n"
5750 hidnplayr 533
  @@:
534
        lea     eax, [esi+BYTES_PER_CPIXEL]
535
        cmp     [datapointer], eax
536
        jae     @f
537
        call    read_data.more
538
        jmp     @b
539
  @@:
540
        call    load_cpixel
541
        mov     ecx, eax
542
        shr     ecx, 16
5716 hidnplayr 543
 
544
        mov     [palettesize], 1
5750 hidnplayr 545
        mov     [palette], eax
5716 hidnplayr 546
 
547
  .solid_line:
548
        mov     ebx, [subrectangle.width]
549
  .solid_pixel:
5750 hidnplayr 550
        stosw
551
        mov     [edi], cl
5716 hidnplayr 552
        inc     edi
553
        dec     ebx
554
        jnz     .solid_pixel
555
        add     edi, ebp
556
        dec     edx
557
        jnz     .solid_line
558
;        jmp     .next_tile
559
 
560
 
561
 
562
; Go to the next tile
563
  .next_tile:
564
        mov     eax, [subrectangle.x]
565
        add     eax, 16
566
        cmp     eax, [rectangle.width]
567
        jae     .next_row
568
        mov     [subrectangle.x], eax
569
        jmp     .tile
570
  .next_row:
571
        mov     [subrectangle.x], 0
572
        mov     eax, [subrectangle.y]
573
        add     eax, 16
574
        cmp     eax, [rectangle.height]
575
        jae     .done
576
        mov     [subrectangle.y], eax
577
        jmp     .tile
578
 
579
  .invalid:
580
        DEBUGF  2, "Invalid subencoding type!\n"
581
  .fail:
582
        DEBUGF  2, "TRLE failed!\n"
583
        jmp     next_rectangle
584
 
585
  .done:
586
        DEBUGF  1, "TRLE complete!\n"
587
        jmp     next_rectangle