Subversion Repositories Kolibri OS

Rev

Rev 552 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 552 Rev 9241
Line 5... Line 5...
5
;     SMALL
5
;     SMALL
6
;       CODE
6
;       CODE
7
;         Graphics
7
;         Graphics
8
;           Libary
8
;           Libary
9
;
9
;
-
 
10
;   Ver 0.18
-
 
11
;
-
 
12
 
10
;   Ver 0.18 By Pavlushin Evgeni (RUSSIA)
13
; draw image into image with alpha color mask
-
 
14
; image_draw_acimage dest, source, x, y, alpha_color
-
 
15
;
-
 
16
macro image_draw_acimage dest, source, x, y, alpha_color
-
 
17
{
-
 
18
local next_pix,next_line,skip_pix,no_skip
-
 
19
   push dest
-
 
20
   push source
-
 
21
   push x
-
 
22
   push y
11
;   www.waptap@mail.ru
23
   push alpha_color
-
 
24
   pop ebp  ; alpha color
-
 
25
   pop eax  ; y
-
 
26
   pop ebx  ; x
-
 
27
   pop esi  ; src
-
 
28
   pop edi  ; dest
-
 
29
   call image_draw_acimage_proc
-
 
30
 
-
 
31
if ~ defined image_draw_acimage_used
-
 
32
image_draw_acimage_used equ 1
-
 
33
 
-
 
34
   jmp end_image_draw_acimage_proc
-
 
35
image_draw_acimage_proc:
-
 
36
   mov ecx,dword [edi]   ; ecx = canvas width
-
 
37
   mul ecx       ; edx:eax = ypos * canvas width
-
 
38
   add eax,ebx   ; eax =  (ypos * canvas width) + xpos
-
 
39
   lea eax,[eax+eax*2+8] ; eax=(y*xsize+x)*3+8 (8=skip xy size dwords)
-
 
40
 
-
 
41
   mov edx,[esi]   ; edx = img width
-
 
42
   sub ecx,edx     ; ecx = canvas width - img width
-
 
43
   lea ebx,[ecx*2+ecx] ; ebx = how many pixels skip for new line
-
 
44
   mov ecx,[esi+4] ; ecx = img height
-
 
45
   add esi,8       ; esi + 8 for skip xy size dwords
-
 
46
   add edi,eax     ; edi = dest position
-
 
47
   shl ebp,8       ; for fast compare with alpha color
-
 
48
   cld             ; set movs direction flag
-
 
49
next_line:
-
 
50
   push edx
-
 
51
next_pix:
-
 
52
   mov eax,[esi]
-
 
53
   shl eax,8
-
 
54
   cmp eax,ebp
-
 
55
   je  skip_pix
-
 
56
   movsw
-
 
57
   movsb
-
 
58
   jmp no_skip
-
 
59
skip_pix:
-
 
60
   add esi,3
-
 
61
   add edi,3
-
 
62
no_skip:
-
 
63
   dec edx
-
 
64
   jnz next_pix
-
 
65
   pop edx
-
 
66
   add edi,ebx
-
 
67
   dec ecx
-
 
68
   jnz next_line
-
 
69
   ret
-
 
70
end_image_draw_acimage_proc :
-
 
71
end if
-
 
72
 
-
 
73
}
-
 
74
 
-
 
75
macro image_set_size image,width,height
-
 
76
{
-
 
77
   mov dword [image],width
-
 
78
   mov dword [image+4],height
-
 
79
}
-
 
80
 
-
 
81
; label - draw label on window
-
 
82
; example:
-
 
83
; label 10,12,'Hello World!',cl_Green+font_size_x4+utf16
Line -... Line 84...
-
 
84
 
-
 
85
macro image_draw_label image,x,y,text,color
-
 
86
{
-
 
87
local label_text
12
 
88
   draw_to_buffer   equ 00001000b shl 24
-
 
89
   jmp @f
-
 
90
label_text db text
-
 
91
@@:
-
 
92
   words2reg ebx,x,y       ; ebx - position
13
;InfoList
93
   dword2reg ecx,color+draw_to_buffer ; ecx - color
-
 
94
   mov edi,image
-
 
95
   mov edx,label_text      ; edx - address of label text
14
;0.01 LoadImage
96
   mov esi,@b-label_text   ; esi - size of libel in bytes
-
 
97
   mov eax,4
-
 
98
   mcall
-
 
99
}
-
 
100
 
-
 
101
; draw_frect - draw filled rect
-
 
102
macro draw_frect x,y,xs,ys,color
15
;0.02 SetBmp
103
{
16
;0.03 Bmptoimg, Setimg ~01.03.2004
104
   wordstoreg ebx,x,xs ;x*65536+xs
-
 
105
   wordstoreg ecx,y,ys ;y*65536+ys
-
 
106
   mov  edx,color
-
 
107
   mov  eax,13
-
 
108
   mcall
-
 
109
}
17
;0.04 Bug deleted, copyimg ~03.05.2004
110
 
-
 
111
; draw_label - Draw label in window
-
 
112
; example:
-
 
113
; draw_label 10,12,'Hello World!',cl_Green+font_size_x4+utf16
-
 
114
 
-
 
115
macro draw_label x,y,text,color
-
 
116
{
-
 
117
local label_text
-
 
118
   words2reg ebx,x,y   ; ebx - position
-
 
119
if text eqtype 123 | text eqtype eax
-
 
120
   movt edx,text
-
 
121
   mov ecx,color+(1 shl 31)  ; ecx - color
-
 
122
else
-
 
123
   mov edx,label_text  ; edx - address of label text
18
;0.05 fullimg, collimg ~05.05.2004
124
   jmp @f
-
 
125
label_text db text
-
 
126
@@:
-
 
127
   mov esi,@b-label_text     ; esi - size of libel in bytes
-
 
128
   movt ecx,color            ; ecx - color
-
 
129
end if
-
 
130
   mov eax,4
-
 
131
   mcall
-
 
132
}
19
;0.06 getimg ~09.05.2004
133
 
20
;0.07 convbmp ~13.05.2004
134
hide_zeros equ (1 shl 31)
21
;0.08 fps ~14.05.2004
135
use_bg_color equ (1 shl 30)
-
 
136
use_big_font equ (1 shl 28)
22
;0.09 drawfbox ~03.06.2004
137
 
-
 
138
macro draw_number data, x, y, color, numtype, bg_color
-
 
139
{
-
 
140
   movt ecx,data
23
;0.10 all macros optimized by halyavin, add at ~07.06.2004
141
   movt ebx,numtype
-
 
142
   mov bl,0     ; if bl = 0, ecx is contain number
-
 
143
   words2reg edx,x,y
-
 
144
if bg_color eq
-
 
145
   movt esi,color
24
;0.11 many macros optimized by halyavin, add at ~30.08.2004
146
else
25
;0.12 bmptoimg ~07.09.2004
147
   movt esi,color+use_bg_color
-
 
148
   movt edi,bg_color
-
 
149
end if
-
 
150
   mov eax,47
-
 
151
   mcall
-
 
152
}
26
;0.13 imgtoimg ~08.09.2004
153
 
27
;0.14 imgtoimg modify not brake bmp pict! ~09.09.2004
154
; draw_image - macro for draw image on window area
-
 
155
macro draw_image x, y, image
28
;0.15 giftoimg, giftoani ~10.09.2004
156
{
29
;0.16 setframe, rgbtobgr, setbmp deleted ~20.09.2004
157
   mov ecx,[image-2]    ; -2 for except shl ecx,16
-
 
158
   mov cx,[image+4]     ; ecx = xsize*65536+ysize
30
;0.17 modification giftoimg, giftoani, getframeoff ~01.10.2004
159
   wordstoreg edx, x, y ; edx = x*65536+y
-
 
160
   lea ebx,[image+8]    ; ebx = image data address
-
 
161
   mov eax,7            ; eax = 7 is draw image function
-
 
162
   mcall
Line 31... Line 163...
31
;0.18 aframetoimg,aimgtoimg,frametoimg ~03.10.2004
163
}
32
 
164
 
33
aframetoimg_use_count=0
165
aframetoimg_use_count=0
34
macro aframetoimg img, x, y, canvas,acol
166
macro aframetoimg img, x, y, canvas,acol
Line 79... Line 211...
79
    jne  yx
211
   jne  yx
80
    add edx,3
212
   add edx,3
81
    add ebp,3
213
   add ebp,3
82
    jmp nx
214
   jmp nx
83
yx:
215
yx:
84
 
-
 
85
    mov al,byte [edx]
216
   mov al,byte [edx]
86
    mov byte [ebp],al
217
   mov byte [ebp],al
87
    inc ebp
218
   inc ebp
88
    inc edx
219
   inc edx
89
    mov al,byte [edx]
220
   mov al,byte [edx]
Line 203... Line 334...
203
    pop ebx
334
   pop ebx
204
    call frametoimg_proc
335
   call frametoimg_proc
205
}
336
}
Line 206... Line -...
206
 
-
 
207
 
-
 
208
aimgtoimg_use_count=0
-
 
209
macro aimgtoimg img, x, y, canvas,acol
-
 
210
{
-
 
211
local loo,loo2,acolor
-
 
212
aimgtoimg_use_count=aimgtoimg_use_count+1
-
 
213
if aimgtoimg_use_count = 1
-
 
214
 
-
 
215
     jmp end_aimgtoimg_proc
-
 
216
 
-
 
217
acolor dd 0
-
 
218
aimgtoimg_proc:
-
 
219
;getout coord
-
 
220
    mov [acolor],ebp
-
 
221
 
-
 
222
    mov eax,esi ;y cor
-
 
223
    mul dword [ecx] ;canvas xsize
-
 
224
    add eax,edi ;x cor
-
 
225
    mov ebp,eax
-
 
226
    shl eax,1
-
 
227
    add ebp,eax
-
 
228
    add ebp,ecx ;canvas+8;start
-
 
229
    add ebp,8
-
 
230
;get img size
-
 
231
    mov eax,ebx ;img   ;xsize
-
 
232
    mov esi,[eax]
-
 
233
    add ebx,4
-
 
234
    mov eax,ebx ; img+4 ;ysize
-
 
235
    mov edi,[eax]
-
 
236
    add ebx,4
-
 
237
    mov edx,ebx ;img+8
-
 
238
loo2:
-
 
239
push esi
-
 
240
loo:
-
 
241
 
-
 
242
;test on alpha color
-
 
243
    mov eax,[edx]
-
 
244
    shl eax,8
-
 
245
    shr eax,8
-
 
246
    cmp eax,[acolor]
-
 
247
    jne  yx
-
 
248
    add edx,3
-
 
249
    add ebp,3
-
 
250
    jmp nx
-
 
251
yx:
-
 
252
 
-
 
253
    mov al,byte [edx]
-
 
254
    mov byte [ebp],al
-
 
255
    inc ebp
-
 
256
    inc edx
-
 
257
    mov al,byte [edx]
-
 
258
    mov byte [ebp],al
-
 
259
    inc ebp
-
 
260
    inc edx
-
 
261
    mov al,byte [edx]
-
 
262
    mov byte [ebp],al
-
 
263
    inc ebp
-
 
264
    inc edx
-
 
265
nx:
-
 
266
    dec esi
-
 
267
    jnz loo
-
 
268
pop esi
-
 
269
    sub ebp,3
-
 
270
    mov eax,[ecx]  ;offset = offset+((canxsize-imgxsize)*3)
-
 
271
    sub eax,esi
-
 
272
    add ebp,eax
-
 
273
    shl eax,1
-
 
274
    add ebp,eax
-
 
275
 
-
 
276
    add ebp,3
-
 
277
 
-
 
278
    dec edi
-
 
279
    jnz loo2
-
 
280
    ret
-
 
281
end_aimgtoimg_proc:
-
 
282
end if
-
 
283
    push img
-
 
284
    push canvas
-
 
285
    push x
-
 
286
    push y
-
 
287
    push acol
-
 
288
    pop  ebp
-
 
289
    pop  esi
-
 
290
    pop  edi
-
 
291
    pop ecx
-
 
292
    pop ebx
-
 
293
    call aimgtoimg_proc
-
 
294
}
-
 
295
 
-
 
296
 
-
 
297
 
337
 
298
 
338
 
299
imgtoimg_use_count=0
339
imgtoimg_use_count=0
300
macro imgtoimg img, x, y, canvas
340
macro imgtoimg img, x, y, canvas
301
{
341
{
Line 344... Line 384...
344
    mov eax,[ecx]  ;offset = offset+((canxsize-imgxsize)*3)
384
   mov eax,[ecx]  ;offset = offset+((canxsize-imgxsize)*3)
345
    sub eax,esi
385
   sub eax,esi
346
    add ebp,eax
386
   add ebp,eax
347
    shl eax,1
387
   shl eax,1
348
    add ebp,eax
388
   add ebp,eax
349
 
-
 
350
    add ebp,3
389
   add ebp,3
351
 
-
 
352
    dec edi
390
   dec edi
353
    jnz loo2
391
   jnz loo2
354
    ret
392
   ret
355
end_imgtoimg_proc:
393
end_imgtoimg_proc:
356
end if
394
end if
Line 363... Line 401...
363
    pop  ecx
401
   pop  ecx
364
    pop  ebx
402
   pop  ebx
365
    call imgtoimg_proc
403
   call imgtoimg_proc
366
}
404
}
Line 367... Line -...
367
 
-
 
368
 
-
 
369
;DrawBox
-
 
370
macro drawfbox x,y,xs,ys,color
-
 
371
{
-
 
372
    wordstoreg ebx,x,xs ;x*65536+xs
-
 
373
    wordstoreg ecx,y,ys ;y*65536+ys
-
 
374
    mov  edx,color
-
 
375
    mov  eax,13
-
 
376
    mcall
-
 
377
}
-
 
378
 
405
 
379
; FPS - Set Frame Per Second Display
406
; FPS - Set Frame Per Second Display
380
fps_show_frequency=40
407
fps_show_frequency=40
381
macro fps x,y,color,delcolor
408
macro fps x,y,color,delcolor
382
{
409
{
Line 420... Line 447...
420
    mov ecx,[fps]
447
   mov ecx,[fps]
421
    mcall
448
   mcall
422
no_out_fps:
449
no_out_fps:
423
}
450
}
Line 424... Line -...
424
 
-
 
425
; COLLIMG - Collusion image's
-
 
426
_1dbounce_count=0;
-
 
427
macro collimg img1_off,x1,y1,img2_off,x2,y2,otv
-
 
428
{
-
 
429
local bounce,exit,anot,bc,nbc
-
 
430
	mov esi,[img1_off] ;xs1
-
 
431
	mov edi,[img2_off] ;ys2
-
 
432
	mov eax,x1 ;
-
 
433
	mov ebx,x2 ;
-
 
434
	call _1dbounce
-
 
435
	mov edx,ecx
-
 
436
	mov esi,[img1_off+4] ;ys1
-
 
437
	mov edi,[img2_off+4] ;ys2
-
 
438
	mov eax,y1 ;
-
 
439
	mov ebx,y2 ;
-
 
440
	call _1dbounce
-
 
441
	add edx,ecx
-
 
442
	cmp edx,2
-
 
443
	je bounce
-
 
444
	mov otv,0
-
 
445
	jmp exit
-
 
446
_1dbounce_count=_1dbounce_count+1
-
 
447
if _1dbounce_count = 1
-
 
448
_1dbounce:
-
 
449
	cmp ebx,eax
-
 
450
	jb  anot
-
 
451
	add eax,esi
-
 
452
	cmp eax,ebx
-
 
453
	jbe nbc
-
 
454
bc:
-
 
455
	mov ecx,1
-
 
456
	ret
-
 
457
anot:
-
 
458
    add ebx,edi
-
 
459
	cmp ebx,eax
-
 
460
	ja  bc
-
 
461
nbc:
-
 
462
	xor ecx,ecx
-
 
463
	ret
-
 
464
end if
-
 
465
bounce:	
-
 
466
	mov otv,1
-
 
467
exit:	
-
 
468
}
-
 
469
 
451
 
470
macro rgbtobgr image
452
macro rgbtobgr image
471
{
-
 
472
local loo
453
{
473
    mov eax,[image]
454
   mov eax,[image]
474
    mul dword [image+4]
455
   mul dword [image+4]
475
    mov ecx,eax
456
   mov ecx,eax
476
    mov esi,image+8
-
 
477
;   add esi,8
457
   mov esi,image+8
478
loo:
458
@@:
479
   mov al,[esi]
459
   mov al,[esi]
480
   mov bl,[esi+2]
460
   mov bl,[esi+2]
481
   mov [esi],bl
461
   mov [esi],bl
482
   mov [esi+2],al
462
   mov [esi+2],al
483
   add esi,3
463
   add esi,3
484
   dec ecx
464
   dec ecx
485
   jnz loo
-
 
486
}
-
 
487
 
-
 
488
 
-
 
489
macro setimg x , y ,arg3
-
 
490
{
-
 
491
    mov  eax,7
-
 
492
    mov  ebx,arg3
-
 
493
    add  ebx,8
-
 
494
    mov  cx,[arg3]
-
 
495
    shl  ecx,16
-
 
496
    add  cx,[arg3+4]
-
 
497
;    wordstoreg ecx,[arg3],[arg3+4]
-
 
498
    wordstoreg edx, x , y  ;arg1*65536+arg2
-
 
499
    mcall
465
   jnz @b
Line 500... Line 466...
500
}
466
}
501
 
467
 
502
macro setframe x , y ,arg3
468
macro setframe x , y ,arg3
Line 511... Line 477...
511
}
477
}
Line 512... Line 478...
512
 
478
 
513
 
479
 
-
 
480
macro getimg imgsrc,x,y,xs,ys,imgdest
514
macro getimg imgsrc,x,y,xs,ys,imgdest
481
{
515
{
482
local next_pixel,next_line
516
local cyc
483
; store image size
517
if xs eqtype 0
484
if xs eqtype 0 | xs eqtype eax
518
    mov dword [imgdest],xs
485
   mov dword [imgdest],xs
519
else
486
else
520
    mov eax,xs
487
   mov eax,xs
521
    mov dword [imgdest],eax
488
   mov dword [imgdest],eax
522
end if
489
end if
523
if ys eqtype 0
490
if ys eqtype 0 | ys eqtype eax
-
 
491
   mov dword [imgdest+4],ys
-
 
492
else
524
    mov dword [imgdest+4],ys
493
   ;push ys
525
else
494
   ;pop dword [imgdest+4]
526
    mov eax,ys
495
   mov eax,ys
Line 527... Line 496...
527
    mov dword [imgdest+4],eax
496
   mov dword [imgdest+4],eax
528
end if
497
end if
529
 
-
 
530
    mov eax,dword [imgsrc] ;getx size
-
 
531
;    lea ecx,[eax+2*eax]
498
 
532
    mov ecx,eax
-
 
533
    shl ecx,1
499
   lea edi,[8+imgdest]    ; edi = destinaton address
534
    add ecx,eax
500
   mov eax,dword [imgsrc] ; eax = xsize of source image in pixels
535
 
501
   push eax               ; store eax before mul operation
536
    mov ebx,y
-
 
537
    mul ebx
502
   mov edx,y
538
    add eax,x
503
   mul edx                ; edx:eax = eax*edx
539
    mov edx,ecx
504
   add eax,x
540
    lea eax,[eax+2*eax]  ;eax=offset on imsrc
505
   lea esi,[imgsrc+8+eax+2*eax]    ; esi = start offset on img src
541
;    mov ebp,eax
-
 
542
;    shl eax,1
-
 
543
;    add eax,ebp
-
 
544
 
506
   pop eax                ; restore eax
545
    mov ecx,xs
507
   sub eax,xs             ; eax = src image xsize - crop fragment xsize
546
    mov ebx,ys
508
   lea eax,[eax+eax*2]    ; eax = eax * 3 (bytes per pixel)
547
 
509
 
548
    mov edi,8+imgdest
510
   ; this loop used esi,edi,ecx,edx,eax registers
549
    lea esi,[eax+8+imgsrc]
511
   mov edx,ys     ; edx = ysize in pixels
550
;    mov esi,eax
-
 
551
;    add esi,8
512
   cld            ; set direction
552
;    add esi,imgsrc
-
 
553
 
513
next_line:
554
    cld
514
   mov ecx,xs     ; ecx = xsize in pixels
555
cyc:
515
next_pixel:
556
    movsw
516
   movsw
557
    movsb
517
   movsb          ; write 3 bytes pixel
558
    dec ecx
-
 
559
    jne cyc
-
 
560
    add esi,edx
-
 
561
    mov ecx,xs
-
 
562
    sub esi,ecx
518
   dec ecx
563
    sub esi,ecx
519
   jnz next_pixel
564
    sub esi,ecx
520
   add esi,eax
Line 565... Line 521...
565
    dec ebx
521
   dec edx
566
    jne cyc
522
   jnz next_line
567
}
523
}
Line 602... Line 558...
602
    inc  edi
558
   inc  edi
603
    cmp  edi,ebp
559
   cmp  edi,ebp
604
    jne  cop
560
   jne  cop
605
}
561
}
Line 606... Line -...
606
 
-
 
607
 
-
 
608
 
562
 
609
  ; number of frame in ecx
563
; number of frame in ecx
Line 610... Line 564...
610
  ; callculatin offset of raw data
564
; callculatin offset of raw data
611
 
565
 
Line 628... Line 582...
628
  jmp loo
582
  jmp loo
629
setpic:
583
setpic:
630
  mov dword offset_of_frame,esi
584
  mov dword offset_of_frame,esi
631
}
585
}
Line 632... Line -...
632
 
-
 
633
 
586
 
634
; BMPTOIMG -Convert BMP format TO IMG format
587
; BMPTOIMG -Convert BMP format TO IMG format
635
; (SYNTAX)  BMPTOIMG BMP_source_offset,IMG_dest_ofset
588
; (SYNTAX)  BMPTOIMG BMP_source_offset,IMG_dest_ofset
636
; (SAMPLE)  View BMPLS.ASM sample.
589
; (SAMPLE)  View BMPLS.ASM sample.
637
; ( NOTE )  This is macros is not brake bmp structure! Tested in 32,8,4 bits
-
 
Line 638... Line 590...
638
 
590
; ( NOTE )  This is macro is not brake bmp structure! Tested in 32,8,4 bits
639
 
591
 
640
bmptoimg_data_area_count=0
592
bmptoimg_data_area_count=0
641
macro bmptoimg bmp_load_area,img_dest_area
593
macro bmptoimg bmp_load_area,img_dest_area
Line 723... Line 675...
723
    pop  eax
675
   pop  eax
724
    inc  esi
676
   inc  esi
725
    cmp  esi,dword [bmptoimg_data_area_eos]
677
   cmp  esi,dword [bmptoimg_data_area_eos]
726
    jae  convert1
678
   jae  convert1
727
    add  edi,3
679
   add  edi,3
728
 
-
 
729
    add  ebp,3
680
   add  ebp,3
730
 
-
 
731
    jmp  nextelem
681
   jmp  nextelem
Line 732... Line 682...
732
 
682
 
733
  convert4bpp:
683
convert4bpp:
734
    shl  ax,4
684
   shl  ax,4
735
    shr  al,4
685
   shr  al,4
736
    push ax
686
   push ax
737
    movzx eax,ah
687
   movzx eax,ah
738
    call converttable
688
   call converttable
739
    add  edi,3
-
 
740
 
689
   add  edi,3
741
    add ebp,3
-
 
742
 
690
   add ebp,3
743
    pop  ax
691
   pop  ax
744
    movzx eax,al
692
   movzx eax,al
745
    call converttable
693
   call converttable
Line 758... Line 706...
758
    call converttable
706
   call converttable
759
    pop  edx
707
   pop  edx
760
    dec  edx
708
   dec  edx
761
    js   convert2
709
   js   convert2
762
    add  edi,3
710
   add  edi,3
763
 
-
 
764
    add  ebp,3
711
   add  ebp,3
765
 
-
 
766
    jmp  nextbit
712
   jmp  nextbit
767
 
-
 
768
  converttable:
713
converttable:
769
    shl  eax,2
714
   shl  eax,2
770
    add  eax,ebx
715
   add  eax,ebx
771
    mov  edx, dword [eax]
716
   mov  edx, dword [eax]
772
;    mov  dword [edi],edx
717
   ;    mov  dword [edi],edx