Subversion Repositories Kolibri OS

Rev

Rev 485 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
lang equ ru
2
 
3
;
4
;   Assembler
5
;     SMALL
6
;       CODE
7
;         Graphics
8
;           Libary
9
;
10
;   Ver 0.18 By Pavlushin Evgeni (RUSSIA)
11
;   www.waptap@mail.ru
12
 
13
;InfoList
14
;0.01 LoadImage
15
;0.02 SetBmp
16
;0.03 Bmptoimg, Setimg ~01.03.2004
17
;0.04 Bug deleted, copyimg ~03.05.2004
18
;0.05 fullimg, collimg ~05.05.2004
19
;0.06 getimg ~09.05.2004
20
;0.07 convbmp ~13.05.2004
21
;0.08 fps ~14.05.2004
22
;0.09 drawfbox ~03.06.2004
23
;0.10 all macros optimized by halyavin, add at ~07.06.2004
24
;0.11 many macros optimized by halyavin, add at ~30.08.2004
25
;0.12 bmptoimg ~07.09.2004
26
;0.13 imgtoimg ~08.09.2004
27
;0.14 imgtoimg modify not brake bmp pict! ~09.09.2004
28
;0.15 giftoimg, giftoani ~10.09.2004
29
;0.16 setframe, rgbtobgr, setbmp deleted ~20.09.2004
30
;0.17 modification giftoimg, giftoani, getframeoff ~01.10.2004
31
;0.18 aframetoimg,aimgtoimg,frametoimg ~03.10.2004
32
 
33
aframetoimg_use_count=0
34
macro aframetoimg img, x, y, canvas,acol
35
{
36
local loo,loo2,acolor
37
aframetoimg_use_count=aframetoimg_use_count+1
38
if aframetoimg_use_count = 1
39
 
40
     jmp end_aframetoimg_proc
41
 
42
acolor dd 0
43
aframetoimg_proc:
44
;getout coord
45
    mov [acolor],ebp
46
 
47
    mov edx,ebx ;img   ;xsize
48
    movzx eax,word [edx]
49
    add eax,esi ;y cor
50
 
51
;    mov eax,esi ;y cor
52
    mul dword [ecx] ;canvas xsize
53
    add eax,edi ;x cor
54
 
55
    mov ebp,ebx ;img   ;xsize
56
    movzx edx,word [ebp]
57
    add eax,edx
58
 
59
    mov ebp,eax
60
    shl eax,1
61
    add ebp,eax
62
    add ebp,ecx ;canvas+8;start
63
    add ebp,8
64
;get img size
65
    add ebx,4
66
    mov eax,ebx ;img   ;xsize
67
    movzx esi,word [eax]
68
    movzx edi,word [eax+2]
69
    add ebx,4
70
    mov edx,ebx ;img+8
71
loo2:
72
push esi
73
loo:
74
;test on alpha color
75
    mov eax,[edx]
76
    shl eax,8
77
    shr eax,8
78
    cmp eax,[acolor]
79
    jne  yx
80
    add edx,3
81
    add ebp,3
82
    jmp nx
83
yx:
84
 
85
    mov al,byte [edx]
86
    mov byte [ebp],al
87
    inc ebp
88
    inc edx
89
    mov al,byte [edx]
90
    mov byte [ebp],al
91
    inc ebp
92
    inc edx
93
    mov al,byte [edx]
94
    mov byte [ebp],al
95
    inc ebp
96
    inc edx
97
nx:
98
    dec esi
99
    jnz loo
100
pop esi
101
    sub ebp,3
102
    mov eax,[ecx]  ;offset = offset+((canxsize-imgxsize)*3)
103
    sub eax,esi
104
    add ebp,eax
105
    shl eax,1
106
    add ebp,eax
107
 
108
    add ebp,3
109
 
110
    dec edi
111
    jnz loo2
112
    ret
113
end_aframetoimg_proc:
114
end if
115
    push img
116
    push canvas
117
    push x
118
    push y
119
    push acol
120
    pop  ebp
121
    pop  esi
122
    pop  edi
123
    pop ecx
124
    pop ebx
125
    call aframetoimg_proc
126
}
127
 
128
frametoimg_use_count=0
129
macro frametoimg img, x, y, canvas
130
{
131
local loo,loo2
132
frametoimg_use_count=frametoimg_use_count+1
133
if frametoimg_use_count = 1
134
 
135
    jmp end_frametoimg_proc
136
 
137
frametoimg_proc:
138
;getout coord
139
    mov edx,ebx ;img   ;xsize
140
    movzx eax,word [edx]
141
    add eax,esi ;y cor
142
 
143
;    mov eax,esi ;y cor
144
    mul dword [ecx] ;canvas xsize
145
    add eax,edi ;x cor
146
 
147
    mov ebp,ebx ;img   ;xsize
148
    movzx edx,word [ebp]
149
    add eax,edx
150
 
151
    mov ebp,eax
152
    shl eax,1
153
    add ebp,eax
154
    add ebp,ecx ;canvas+8;start
155
    add ebp,8
156
;get img size
157
    add ebx,4
158
    mov eax,ebx ;img   ;xsize
159
    movzx esi,word [eax]
160
    movzx edi,word [eax+2]
161
    add ebx,4
162
    mov edx,ebx ;img+8
163
loo2:
164
push esi
165
loo:
166
    mov al,byte [edx]
167
    mov byte [ebp],al
168
    inc ebp
169
    inc edx
170
    mov al,byte [edx]
171
    mov byte [ebp],al
172
    inc ebp
173
    inc edx
174
    mov al,byte [edx]
175
    mov byte [ebp],al
176
    inc ebp
177
    inc edx
178
 
179
    dec esi
180
    jnz loo
181
pop esi
182
    sub ebp,3
183
    mov eax,[ecx]  ;offset = offset+((canxsize-imgxsize)*3)
184
    sub eax,esi
185
    add ebp,eax
186
    shl eax,1
187
    add ebp,eax
188
 
189
    add ebp,3
190
 
191
    dec edi
192
    jnz loo2
193
    ret
194
end_frametoimg_proc:
195
end if
196
    push img
197
    push canvas
198
    push x
199
    push y
200
    pop  esi
201
    pop  edi
202
    pop ecx
203
    pop ebx
204
    call frametoimg_proc
205
}
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
 
298
 
299
imgtoimg_use_count=0
300
macro imgtoimg img, x, y, canvas
301
{
302
local loo,loo2
303
imgtoimg_use_count=imgtoimg_use_count+1
304
if imgtoimg_use_count = 1
305
 
306
     jmp end_imgtoimg_proc
307
imgtoimg_proc:
308
;getout coord
309
    mov eax,esi ;y cor
310
    mul dword [ecx] ;canvas xsize
311
    add eax,edi ;x cor
312
    mov ebp,eax
313
    shl eax,1
314
    add ebp,eax
315
    add ebp,ecx ;canvas+8;start
316
    add ebp,8
317
;get img size
318
    mov eax,ebx ;img   ;xsize
319
    mov esi,[eax]
320
    add ebx,4
321
    mov eax,ebx ; img+4 ;ysize
322
    mov edi,[eax]
323
    add ebx,4
324
    mov edx,ebx ;img+8
325
loo2:
326
push esi
327
loo:
328
    mov al,byte [edx]
329
    mov byte [ebp],al
330
    inc ebp
331
    inc edx
332
    mov al,byte [edx]
333
    mov byte [ebp],al
334
    inc ebp
335
    inc edx
336
    mov al,byte [edx]
337
    mov byte [ebp],al
338
    inc ebp
339
    inc edx
340
    dec esi
341
    jnz loo
342
pop esi
343
    sub ebp,3
344
    mov eax,[ecx]  ;offset = offset+((canxsize-imgxsize)*3)
345
    sub eax,esi
346
    add ebp,eax
347
    shl eax,1
348
    add ebp,eax
349
 
350
    add ebp,3
351
 
352
    dec edi
353
    jnz loo2
354
    ret
355
end_imgtoimg_proc:
356
end if
357
    push img
358
    push canvas
359
    push x
360
    push y
361
    pop  esi
362
    pop  edi
363
    pop  ecx
364
    pop  ebx
365
    call imgtoimg_proc
366
}
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
485 heavyiron 376
    mcall
31 halyavin 377
}
378
 
379
; FPS - Set Frame Per Second Display
380
fps_show_frequency=40
381
macro fps x,y,color,delcolor
382
{
383
local spdat,savetime,new_time,fps,fps_cntr,out_fps,new_time,ttt
384
local no_out_fps
385
    jmp spdat
386
savetime dd 0
387
fps_cntr dd 0
388
fps      dd 0
389
ttt      dd 0
390
spdat:
391
get_time:
392
    mov eax,3
485 heavyiron 393
    mcall
31 halyavin 394
    cmp eax,[savetime]
395
    jne new_time
396
    inc [fps_cntr]
397
    cmp dword [ttt],0
398
    je  out_fps
399
    dec dword [ttt]
400
    jmp no_out_fps
401
new_time:
402
    mov [savetime],eax
403
    mov ebx,[fps_cntr]
404
    mov [fps],ebx
405
    mov [fps_cntr],0
406
out_fps:
407
if ~(delcolor eq )
408
    mov ebx,x*65536+30
409
    mov ecx,y*65536+7
410
    mov edx,delcolor
411
    mov eax,13
485 heavyiron 412
    mcall
31 halyavin 413
end if
414
    mov dword [ttt],fps_show_frequency
415
    mov eax,47
416
    mov ebx,5*65536
417
;   mov bl,0
418
    mov edx,x*65536+y
419
    mov esi,color
420
    mov ecx,[fps]
485 heavyiron 421
    mcall
31 halyavin 422
no_out_fps:
423
}
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
 
470
macro rgbtobgr image
471
{
472
local loo
473
    mov eax,[image]
474
    mul dword [image+4]
475
    mov ecx,eax
476
    mov esi,image+8
477
;   add esi,8
478
loo:
479
   mov al,[esi]
480
   mov bl,[esi+2]
481
   mov [esi],bl
482
   mov [esi+2],al
483
   add esi,3
484
   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
485 heavyiron 499
    mcall
31 halyavin 500
}
501
 
502
macro setframe x , y ,arg3
503
{
504
    mov  eax,7
505
    mov  ebx,arg3
506
    add  ebx,8
507
    wordstoreg edx, x , y  ;arg1*65536+arg2
508
    add  edx,dword [arg3]
509
    mov  ecx,dword [arg3+4]
485 heavyiron 510
    mcall
31 halyavin 511
}
512
 
513
 
514
macro getimg imgsrc,x,y,xs,ys,imgdest
515
{
516
local cyc
517
if xs eqtype 0
518
    mov dword [imgdest],xs
519
else
520
    mov eax,xs
521
    mov dword [imgdest],eax
522
end if
523
if ys eqtype 0
524
    mov dword [imgdest+4],ys
525
else
526
    mov eax,ys
527
    mov dword [imgdest+4],eax
528
end if
529
 
530
    mov eax,dword [imgsrc] ;getx size
531
;    lea ecx,[eax+2*eax]
532
    mov ecx,eax
533
    shl ecx,1
534
    add ecx,eax
535
 
536
    mov ebx,y
537
    mul ebx
538
    add eax,x
539
    mov edx,ecx
540
    lea eax,[eax+2*eax]  ;eax=offset on imsrc
541
;    mov ebp,eax
542
;    shl eax,1
543
;    add eax,ebp
544
 
545
    mov ecx,xs
546
    mov ebx,ys
547
 
548
    mov edi,8+imgdest
549
    lea esi,[eax+8+imgsrc]
550
;    mov esi,eax
551
;    add esi,8
552
;    add esi,imgsrc
553
 
554
    cld
555
cyc:
556
    movsw
557
    movsb
558
    dec ecx
559
    jne cyc
560
    add esi,edx
561
    mov ecx,xs
562
    sub esi,ecx
563
    sub esi,ecx
564
    sub esi,ecx
565
    dec ebx
566
    jne cyc
567
}
568
 
569
macro copyimg img2_off,img1_off
570
{
571
    mov  eax,dword [img1_off]
572
    mov  ebx,dword [img1_off+4]
573
    mul  ebx
574
    lea  ecx,[eax+2*eax]
575
    lea  esi,[img1_off+8]
576
    lea  edi,[img2_off+8]
577
    cld
578
    rep  movsb
579
}
580
 
581
macro fullimg img_off,xs,ys,color
582
{
583
local cop
584
    mov eax,xs
585
    mov ebx,ys
586
    mov  dword [img_off],eax
587
    mov  dword [img_off+4],ebx
588
    mul  ebx
589
    lea  ebp,[eax+2*eax]
590
    mov  esi,color
591
if color eqtype 0
592
    mov  ecx,color/65536
593
else
594
    mov  ecx,esi
595
    shr  ecx,16
596
end if
597
    xor  edi,edi
598
cop:
599
    mov  word [img_off+8+edi],si
600
    add  edi,2
601
    mov  byte [img_off+8+edi],cl
602
    inc  edi
603
    cmp  edi,ebp
604
    jne  cop
605
}
606
 
607
 
608
 
609
  ; number of frame in ecx
610
  ; callculatin offset of raw data
611
 
612
macro getframeoff num_of_frame,offset_of_animation,offset_of_frame
613
{
614
local loo,setpic
615
  mov ebp,num_of_frame ;ecx
616
  mov esi,offset_of_animation;Image
617
loo:
618
  cmp ebp,0
619
  je  setpic
620
  movzx eax,word [esi+4]
621
  movzx ebx,word [esi+6]
622
  mul ebx ;dword [esi+4]
623
  mov ebx,3
624
  mul ebx
625
  add eax,8
626
  add esi,eax
627
  dec ebp
628
  jmp loo
629
setpic:
630
  mov dword offset_of_frame,esi
631
}
632
 
633
 
634
; BMPTOIMG -Convert BMP format TO IMG format
635
; (SYNTAX)  BMPTOIMG BMP_source_offset,IMG_dest_ofset
636
; (SAMPLE)  View BMPLS.ASM sample.
637
; ( NOTE )  This is macros is not brake bmp structure! Tested in 32,8,4 bits
638
 
639
 
640
bmptoimg_data_area_count=0
641
macro bmptoimg bmp_load_area,img_dest_area
642
{
643
local fileinfo,string,end_bmp,nodix
644
local converttable,noaddelem,nextbit,convert1bpp,convert4bpp,convert2
645
local nextelem,convertno32,nomorestring,convert1,nextstring,yespicsize
646
;local qwe,bmpfn
647
 
648
;  convert:
649
    movzx eax,word [bmp_load_area+28]
650
    mul  dword [bmp_load_area+18]
651
    add  eax,31
652
    shr  eax,5
653
    mov  dword [bmptoimg_data_area_dwps],eax  ;dwps-doublewords per string
654
    shl  eax,2
655
    mov  dword [bmptoimg_data_area_bps],eax   ;bps-bytes per string
656
 
657
    cmp dword [bmp_load_area+34],0
658
    jne  yespicsize  ;if picture size is defined
659
    mul dword [bmp_load_area+22]
660
    mov dword [bmp_load_area+34],eax
661
 
662
  yespicsize:
663
    mov ebp,img_dest_area+8
664
 
665
    mov  eax,bmp_load_area
666
    mov  ebx,eax
667
    add  ebx, [bmp_load_area+2];file size
668
    inc  ebx
669
    mov  dword [bmptoimg_soi],ebx   ;soi-start of image area for drawing
670
 
671
    add  eax, [bmp_load_area+10]
672
    mov  dword [bmptoimg_data_area_sop],eax   ;sop-start of picture in file
673
    add  eax, [bmp_load_area+34]
674
    mov  dword [bmptoimg_data_area_eop],eax   ;eop-end of picture in file
675
    mov  eax, [bmp_load_area+18]
676
    lea  eax,[eax+2*eax]   ;3x pixels in eax
677
 
678
    mov  edi,dword [bmptoimg_soi]   ;initializing
679
    mov  esi,dword [bmptoimg_data_area_eop]
680
    sub  esi,dword [bmptoimg_data_area_bps]
681
 
682
 
683
  nextstring:
684
    push edi
685
    push ebp
686
    cmp  word [bmp_load_area+28],24
687
    jne  convertno32
688
 
689
    mov edi,ebp
690
    mov  ecx,[bmptoimg_data_area_dwps]
691
    cld
692
    rep movsd
693
 
694
  convert1:
695
    pop  ebp
696
    pop  edi
697
    sub  esi,dword [bmptoimg_data_area_bps]
698
    sub  esi,dword [bmptoimg_data_area_bps]
699
    cmp  esi,dword [bmptoimg_data_area_sop]
700
    jb   end_bmp
701
    add  edi,eax
702
    add  ebp,eax
703
    jmp  nextstring
704
 
705
  convertno32:
706
    mov  ebx,bmp_load_area
707
    add  ebx, [bmp_load_area+14]
708
    add  ebx,14          ;start of color table
709
    push esi
710
    add  esi,dword [bmptoimg_data_area_bps]
711
    mov  dword [bmptoimg_data_area_eos],esi
712
    pop  esi
713
  nextelem:
714
    push eax
715
    movzx eax,byte [esi]
716
    cmp  word [bmp_load_area+28],4
717
    je   convert4bpp
718
    cmp  word [bmp_load_area+28],1
719
    je   convert1bpp
720
    call converttable
721
 
722
  convert2:
723
    pop  eax
724
    inc  esi
725
    cmp  esi,dword [bmptoimg_data_area_eos]
726
    jae  convert1
727
    add  edi,3
728
 
729
    add  ebp,3
730
 
731
    jmp  nextelem
732
 
733
  convert4bpp:
734
    shl  ax,4
735
    shr  al,4
736
    push ax
737
    movzx eax,ah
738
    call converttable
739
    add  edi,3
740
 
741
    add ebp,3
742
 
743
    pop  ax
744
    movzx eax,al
745
    call converttable
746
    jmp  convert2
747
 
748
  convert1bpp:
749
    mov  ecx,eax
750
    mov  edx,7
751
  nextbit:
752
    xor  eax,eax
753
    bt   ecx,edx
754
    jnc  noaddelem
755
    inc  eax
756
  noaddelem:
757
    push edx
758
    call converttable
759
    pop  edx
760
    dec  edx
761
    js   convert2
762
    add  edi,3
763
 
764
    add  ebp,3
765
 
766
    jmp  nextbit
767
 
768
  converttable:
769
    shl  eax,2
770
    add  eax,ebx
771
    mov  edx, dword [eax]
772
;    mov  dword [edi],edx
773
    mov [ebp],edx
774
    ret
775
 
776
bmptoimg_data_area_count=bmptoimg_data_area_count+1
777
if bmptoimg_data_area_count = 1
778
; DATA AREA
779
bmptoimg_soi                dd 0
780
bmptoimg_data_area_bps      dd 0
781
bmptoimg_data_area_dwps     dd 0
782
bmptoimg_data_area_sop      dd 0
783
bmptoimg_data_area_eop      dd 0
784
bmptoimg_data_area_eos      dd 0
785
end if
786
 
787
end_bmp:
788
    mov  eax,dword [bmp_load_area+18]
789
    mov  ebx,dword [bmp_load_area+22]
790
    mov  dword [img_dest_area],eax
791
    mov  dword [img_dest_area+4],ebx
792
}
793
 
552 diamond 794
if used ReadGIF
31 halyavin 795
; For convert RGB to BGR
796
COLOR_ORDER equ MENUETOS
552 diamond 797
include 'gif_lite.inc'
798
end if
31 halyavin 799
 
800
macro giftoani gifsrc,imgsrc,num_of_frames
801
{
552 diamond 802
gif_img_count = num_of_frames
803
        mov     esi, gifsrc
804
        mov     edi, imgsrc
805
        call    ReadGIF
31 halyavin 806
}
807
 
808
macro giftoimg gifsrc,imgsrc
809
{
552 diamond 810
if defined gif_img_count
811
error 'giftoimg cannot be used in GIF multiple images mode. Use giftoani instead.'
812
end if
813
        mov     esi, gifsrc
814
        mov     edi, imgsrc
815
        call    ReadGIF
31 halyavin 816
}