Subversion Repositories Kolibri OS

Rev

Rev 109 | 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 A., add at ~07.06.2004
24
;0.11 many macros optimized by Halyavin A., 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
    words2reg ebx,x,xs ;x*65536+xs
373
    words2reg 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+36
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,6*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
499
    words2reg edx, x , y  ;arg1*65536+arg2
485 heavyiron 500
    mcall
31 halyavin 501
}
502
 
503
macro setframe x , y ,arg3
504
{
505
    mov  eax,7
506
    mov  ebx,arg3
507
    add  ebx,8
508
    words2reg edx, x , y  ;arg1*65536+arg2
509
    add  edx,dword [arg3]
510
    mov  ecx,dword [arg3+4]
485 heavyiron 511
    mcall
31 halyavin 512
}
513
 
514
 
515
macro getimg imgsrc,x,y,xs,ys,imgdest
516
{
517
local cyc
518
if xs eqtype 0
519
    mov dword [imgdest],xs
520
else
521
    mov eax,xs
522
    mov dword [imgdest],eax
523
end if
524
if ys eqtype 0
525
    mov dword [imgdest+4],ys
526
else
527
    mov eax,ys
528
    mov dword [imgdest+4],eax
529
end if
530
 
531
    mov eax,dword [imgsrc] ;getx size
532
;    lea ecx,[eax+2*eax]
533
    mov ecx,eax
534
    shl ecx,1
535
    add ecx,eax
536
 
537
    mov ebx,y
538
    mul ebx
539
    add eax,x
540
    mov edx,ecx
541
    lea eax,[eax+2*eax]  ;eax=offset on imsrc
542
;    mov ebp,eax
543
;    shl eax,1
544
;    add eax,ebp
545
 
546
    mov ecx,xs
547
    mov ebx,ys
548
 
549
    mov edi,8+imgdest
550
    lea esi,[eax+8+imgsrc]
551
;    mov esi,eax
552
;    add esi,8
553
;    add esi,imgsrc
554
 
555
    cld
556
cyc:
557
    movsw
558
    movsb
559
    dec ecx
560
    jne cyc
561
    add esi,edx
562
    mov ecx,xs
563
    sub esi,ecx
564
    sub esi,ecx
565
    sub esi,ecx
566
    dec ebx
567
    jne cyc
568
}
569
 
570
macro copyimg img2_off,img1_off
571
{
572
    mov  eax,dword [img1_off]
573
    mov  ebx,dword [img1_off+4]
574
    mul  ebx
575
    lea  ecx,[eax+2*eax]
576
    lea  esi,[img1_off+8]
577
    lea  edi,[img2_off+8]
578
    cld
579
    rep  movsb
580
}
581
 
582
macro fullimg img_off,xs,ys,color
583
{
584
local cop
585
    mov eax,xs
586
    mov ebx,ys
587
    mov  dword [img_off],eax
588
    mov  dword [img_off+4],ebx
589
    mul  ebx
590
    lea  ebp,[eax+2*eax]
591
    mov  esi,color
592
if color eqtype 0
593
6
594
else
595
    mov  ecx,esi
596
    shr  ecx,16
597
end if
598
    xor  edi,edi
599
cop:
600
    mov  word [img_off+8+edi],si
601
    add  edi,2
602
    mov  byte [img_off+8+edi],cl
603
    inc  edi
604
    cmp  edi,ebp
605
    jne  cop
606
}
607
 
608
 
609
 
610
  ; number of frame in ecx
611
  ; callculatin offset of raw data
612
 
613
macro getframeoff num_of_frame,offset_of_animation,offset_of_frame
614
{
615
local loo,setpic
616
  mov ebp,num_of_frame ;ecx
617
  mov esi,offset_of_animation;Image
618
loo:
619
  cmp ebp,0
620
  je  setpic
621
  movzx eax,word [esi+4]
622
  movzx ebx,word [esi+6]
623
  mul ebx ;dword [esi+4]
624
  mov ebx,3
625
  mul ebx
626
  add eax,8
627
  add esi,eax
628
  dec ebp
629
  jmp loo
630
setpic:
631
  mov dword offset_of_frame,esi
632
}
633
 
634
 
635
; BMPTOIMG -Convert BMP format TO IMG format
636
; (SYNTAX)  BMPTOIMG BMP_source_offset,IMG_dest_ofset
637
; (SAMPLE)  View BMPLS.ASM sample.
638
; ( NOTE )  This is macros is not brake bmp structure! Tested in 32,8,4 bits
639
 
640
 
641
bmptoimg_data_area_count=0
642
macro bmptoimg bmp_load_area,img_dest_area
643
{
644
local fileinfo,string,end_bmp,nodix
645
local converttable,noaddelem,nextbit,convert1bpp,convert4bpp,convert2
646
local nextelem,convertno32,nomorestring,convert1,nextstring,yespicsize
647
;local qwe,bmpfn
648
 
649
;  convert:
650
    movzx eax,word [bmp_load_area+28]
651
    mul  dword [bmp_load_area+18]
652
    add  eax,31
653
    shr  eax,5
654
    mov  dword [bmptoimg_data_area_dwps],eax  ;dwps-doublewords per string
655
    shl  eax,2
656
    mov  dword [bmptoimg_data_area_bps],eax   ;bps-bytes per string
657
 
658
    cmp dword [bmp_load_area+34],0
659
    jne  yespicsize  ;if picture size is defined
660
    mul dword [bmp_load_area+22]
661
    mov dword [bmp_load_area+34],eax
662
 
663
  yespicsize:
664
    mov ebp,img_dest_area+8
665
 
666
    mov  eax,bmp_load_area
667
    mov  ebx,eax
668
    add  ebx, [bmp_load_area+2];file size
669
    inc  ebx
670
    mov  dword [bmptoimg_soi],ebx   ;soi-start of image area for drawing
671
 
672
    add  eax, [bmp_load_area+10]
673
    mov  dword [bmptoimg_data_area_sop],eax   ;sop-start of picture in file
674
    add  eax, [bmp_load_area+34]
675
    mov  dword [bmptoimg_data_area_eop],eax   ;eop-end of picture in file
676
    mov  eax, [bmp_load_area+18]
677
    lea  eax,[eax+2*eax]   ;3x pixels in eax
678
 
679
    mov  edi,dword [bmptoimg_soi]   ;initializing
680
    mov  esi,dword [bmptoimg_data_area_eop]
681
    sub  esi,dword [bmptoimg_data_area_bps]
682
 
683
 
684
  nextstring:
685
    push edi
686
    push ebp
687
    cmp  word [bmp_load_area+28],24
688
    jne  convertno32
689
 
690
    mov edi,ebp
691
    mov  ecx,[bmptoimg_data_area_dwps]
692
    cld
693
    rep movsd
694
 
695
  convert1:
696
    pop  ebp
697
    pop  edi
698
    sub  esi,dword [bmptoimg_data_area_bps]
699
    sub  esi,dword [bmptoimg_data_area_bps]
700
    cmp  esi,dword [bmptoimg_data_area_sop]
701
    jb   end_bmp
702
    add  edi,eax
703
    add  ebp,eax
704
    jmp  nextstring
705
 
706
  convertno32:
707
    mov  ebx,bmp_load_area
708
    add  ebx, [bmp_load_area+14]
709
    add  ebx,14          ;start of color table
710
    push esi
711
    add  esi,dword [bmptoimg_data_area_bps]
712
    mov  dword [bmptoimg_data_area_eos],esi
713
    pop  esi
714
  nextelem:
715
    push eax
716
    movzx eax,byte [esi]
717
    cmp  word [bmp_load_area+28],4
718
    je   convert4bpp
719
    cmp  word [bmp_load_area+28],1
720
    je   convert1bpp
721
    call converttable
722
 
723
  convert2:
724
    pop  eax
725
    inc  esi
726
    cmp  esi,dword [bmptoimg_data_area_eos]
727
    jae  convert1
728
    add  edi,3
729
 
730
    add  ebp,3
731
 
732
    jmp  nextelem
733
 
734
  convert4bpp:
735
    shl  ax,4
736
    shr  al,4
737
    push ax
738
    movzx eax,ah
739
    call converttable
740
    add  edi,3
741
 
742
    add ebp,3
743
 
744
    pop  ax
745
    movzx eax,al
746
    call converttable
747
    jmp  convert2
748
 
749
  convert1bpp:
750
    mov  ecx,eax
751
    mov  edx,7
752
  nextbit:
753
    xor  eax,eax
754
    bt   ecx,edx
755
    jnc  noaddelem
756
    inc  eax
757
  noaddelem:
758
    push edx
759
    call converttable
760
    pop  edx
761
    dec  edx
762
    js   convert2
763
    add  edi,3
764
 
765
    add  ebp,3
766
 
767
    jmp  nextbit
768
 
769
  converttable:
770
    shl  eax,2
771
    add  eax,ebx
772
    mov  edx, dword [eax]
773
;    mov  dword [edi],edx
774
    mov [ebp],edx
775
    ret
776
 
777
bmptoimg_data_area_count=bmptoimg_data_area_count+1
778
if bmptoimg_data_area_count = 1
779
; DATA AREA
780
bmptoimg_soi                dd 0
781
bmptoimg_data_area_bps      dd 0
782
bmptoimg_data_area_dwps     dd 0
783
bmptoimg_data_area_sop      dd 0
784
bmptoimg_data_area_eop      dd 0
785
bmptoimg_data_area_eos      dd 0
786
end if
787
 
788
end_bmp:
789
    mov  eax,dword [bmp_load_area+18]
790
    mov  ebx,dword [bmp_load_area+22]
791
    mov  dword [img_dest_area],eax
792
    mov  dword [img_dest_area+4],ebx
793
}
794
 
795
; For convert RGB to BGR
796
COLOR_ORDER equ MENUETOS
797
 
798
macro giftoani gifsrc,imgsrc,num_of_frames
799
{
800
local hasharea, ReadGIF, nextblock,_null
801
local globalColor, img_count, cur_info, img_start
802
local codesize, compsize, bit_count, CC, EOI, Palette
803
local block_ofs, table_ptr, gifmacend
804
local no_gc, block_skip, no_comm, noextblock, uselocal
805
local setPal, filltable, reinit, cycle, zadd, noinc
806
local notintable, er, zend, nxt, continue, ex, Gif_skipmap
807
local Gif_get_sym, shift, nextbl, noblock, loop1, exx
808
local Gif_output, next, loop2
809
 
810
_null fix 0x1000 ; 0x1000
811
 
812
;    jmp sss
813
;    if defined gif_hash_offset
814
;    else
815
;    hasharea:
816
;    times 4096 dd 0 ;4096
817
;    end if
818
;sss:
819
 
820
    mov  esi,gifsrc           ;Указатель на ГИФ фаил в памяти
821
    mov  edi,imgsrc           ;Указатель на список картинок
822
 
823
    if defined gif_hash_offset
824
    mov  eax,gif_hash_offset    ;Рабочая область минимум 4096*4 байт
825
    else
826
    mov  eax,hasharea         ;Рабочая область минимум 4096*4 байт
827
    end if
828
 
829
    call ReadGIF
830
    push ecx
831
    pop  dword num_of_frames
832
    jmp  gifmacend
833
 
834
    if defined gif_hash_offset
835
    else
836
    hasharea:
837
    times 4096 dd 0 ;4096
838
    end if
839
 
840
ReadGIF:
841
    push esi edi
842
    mov  [table_ptr],eax
843
    mov  [cur_info],edi
844
    xor  eax,eax
845
    mov  [globalColor],eax
846
    mov  [img_count],eax
847
    inc  eax
848
    cmp  dword[esi],'GIF8'
849
    jne  er            ; signature
850
    mov  ecx,[esi+0xa]
851
    inc  eax
852
    add  esi,0xd
853
    mov  edi,esi
854
    bt   ecx,7
855
    jnc  nextblock
856
    mov  [globalColor],esi
857
    call Gif_skipmap
858
nextblock:
859
    cmp  byte[edi],0x21
860
    jne  noextblock
861
    inc  edi
862
    cmp  byte[edi],0xf9 ; Graphic Control Ext
863
    jne  no_gc
864
    add  edi,7
865
    jmp  nextblock
866
no_gc:
867
    cmp  byte[edi],0xfe ; Comment Ext
868
    jne  no_comm
869
    inc  edi
870
block_skip:
871
    movzx eax,byte[edi]
872
    lea  edi,[edi+eax+1]
873
    cmp  byte[edi],0
874
    jnz  block_skip
875
    inc  edi
876
    jmp  nextblock
877
no_comm:
878
    cmp  byte[edi],0xff ; Application Ext
879
    jne  nextblock
880
    add  edi,13
881
    jmp  block_skip
882
noextblock:
883
    cmp  byte[edi],0x2c    ; image beginning
884
    jne  er
885
    inc  [img_count]
886
    inc  edi
887
    mov  esi,[cur_info]
888
    xchg esi,edi
889
    movsd
890
    movsd
891
 
892
    push edi
893
    movzx ecx,word[esi]
894
    inc  esi
895
    bt   ecx,7
896
    jc   uselocal
897
    push [globalColor]
898
    mov  edi,esi
899
    jmp  setPal
900
uselocal:
901
    call Gif_skipmap
902
    push esi
903
setPal:
904
    movzx ecx,byte[edi]
905
    inc  ecx
906
    mov  [codesize],ecx
907
    dec  ecx
908
    pop  [Palette]
909
    lea  esi,[edi+1]
910
    mov  edi,[table_ptr]
911
    xor  eax,eax
912
    cld
913
    lodsb               ; eax - block_count
914
    add  eax,esi
915
    mov  [block_ofs],eax
916
    mov  [bit_count],8
917
    mov  eax,1
918
    shl  eax,cl
919
    mov  [CC],eax
920
    inc  eax
921
    mov  [EOI],eax
922
    lea  ecx,[eax-1]
923
    mov  eax, _null shl 16
924
filltable:
925
    stosd
926
    inc  eax
927
    loop filltable
928
    pop  edi
929
    mov  [img_start],edi
930
reinit:
931
    mov  edx,[EOI]
932
    inc  edx
933
    push [codesize]
934
    pop  [compsize]
935
    call Gif_get_sym
936
    cmp  eax,[CC]
937
    je   reinit
938
    call Gif_output
939
cycle:
940
    movzx ebx,ax
941
    call Gif_get_sym
942
    cmp  eax,edx
943
    jae  notintable
944
    cmp  eax,[CC]
945
    je   reinit
946
    cmp  eax,[EOI]
947
    je   zend
948
    call Gif_output
949
zadd:
950
    push eax
951
    mov  eax,[table_ptr]
952
    mov  [eax+edx*4],ebx
953
    pop  eax
954
    cmp  edx,0xFFF
955
    jae  cycle
956
    inc  edx
957
    bsr  ebx,edx
958
    cmp  ebx,[compsize]
959
    jne  noinc
960
    inc  [compsize]
961
noinc:
962
    jmp  cycle
963
notintable:
964
    push eax
965
    mov  eax,ebx
966
    call Gif_output
967
    push ebx
968
    movzx eax,bx
969
    call Gif_output
970
    pop  ebx eax
971
    jmp  zadd
972
er:
973
    pop  edi
974
    jmp  ex
975
zend:
976
;    mov  eax,[.cur_info]    ; skip offset to next frame
977
;    mov  [eax],edi
978
    mov  [cur_info],edi
979
    add  esi,2
980
    xchg esi,edi
981
nxt:
982
    cmp  byte[edi],0
983
    jnz  continue
984
    inc  edi
985
    jmp  nxt
986
continue:
987
    cmp  byte[edi],0x3b    ;read next frame
988
    jne  nextblock
989
    xor  eax,eax
990
    stosd
991
    mov  ecx,[img_count]
992
ex:
993
    pop  edi esi
994
    ret
995
 
996
Gif_skipmap:
997
; in: ecx - image descriptor, esi - pointer to colormap
998
; out: edi - pointer to area after colormap
999
 
1000
    and  ecx,111b
1001
    inc  ecx            ; color map size
1002
    mov  ebx,1
1003
    shl  ebx,cl
1004
    lea  ebx,[ebx*2+ebx]
1005
    lea  edi,[esi+ebx]
1006
    ret
1007
 
1008
Gif_get_sym:
1009
    mov  ecx,[compsize]
1010
    push ecx
1011
    xor  eax,eax
1012
shift:
1013
    ror  byte[esi],1
1014
    rcr  eax,1
1015
    dec  [bit_count]
1016
    jnz  loop1
1017
    inc  esi
1018
    cmp  esi,[block_ofs]
1019
    jb   noblock
1020
    push eax
1021
    xor  eax,eax
1022
    lodsb
1023
    test eax,eax
1024
    jnz  nextbl
1025
    mov  eax,[EOI]
1026
    sub  esi,2
1027
    add  esp,8
1028
    jmp  exx
1029
nextbl:
1030
    add  eax,esi
1031
    mov  [block_ofs],eax
1032
    pop  eax
1033
noblock:
1034
    mov  [bit_count],8
1035
loop1:
1036
    loop shift
1037
    pop  ecx
1038
    rol  eax,cl
1039
exx:
1040
    xor  ecx,ecx
1041
    ret
1042
 
1043
Gif_output:
1044
    push esi eax edx
1045
    mov  edx,[table_ptr]
1046
next:
1047
    push word[edx+eax*4]
1048
    mov  ax,word[edx+eax*4+2]
1049
    inc  ecx
1050
    cmp  ax,_null
1051
    jnz  next
1052
    shl  ebx,16
1053
    mov  bx,[esp]
1054
loop2:
1055
    pop  ax
1056
 
1057
    lea  esi,[eax+eax*2]
1058
    add  esi,[Palette]
1059
 
1060
    if COLOR_ORDER eq MENUETOS
1061
        mov  esi,[esi]
1062
        bswap esi
1063
        shr  esi,8
1064
        mov  [edi],esi
1065
        add  edi,3
1066
    else
1067
        movsw
1068
        movsb
1069
    end if
1070
 
1071
    loop loop2
1072
    pop  edx eax esi
1073
    ret
1074
 
1075
    globalColor dd 1
1076
    img_count dd 1
1077
    cur_info dd 1        ; image table pointer
1078
    img_start dd 1
1079
    codesize dd 1
1080
    compsize dd 1
1081
    bit_count dd 1
1082
    CC dd 1
1083
    EOI dd 1
1084
    Palette dd 1
1085
    block_ofs dd 1
1086
    table_ptr dd 1
1087
 
1088
gifmacend:
1089
}
1090
 
1091
 
1092
 
1093
macro giftoimg gifsrc,imgsrc
1094
{
1095
local hasharea, ReadGIF, nextblock,_null
1096
local globalColor, img_count, cur_info, img_start
1097
local codesize, compsize, bit_count, CC, EOI, Palette
1098
local block_ofs, table_ptr, gifmacend
1099
local no_gc, block_skip, no_comm, noextblock, uselocal
1100
local setPal, filltable, reinit, cycle, zadd, noinc
1101
local notintable, er, zend, nxt, continue, ex, Gif_skipmap
1102
local Gif_get_sym, shift, nextbl, noblock, loop1, exx
1103
local Gif_output, next, loop2
1104
 
1105
_null fix 0x1000 ; 0x1000
1106
 
1107
    mov  esi,gifsrc           ;Указатель на ГИФ фаил в памяти
1108
    mov  edi,imgsrc           ;Указатель на список картинок
1109
 
1110
    if defined gif_hash_offset
1111
    mov  eax,gif_hash_offset    ;Рабочая область минимум 4096*4 байт
1112
    else
1113
    mov  eax,hasharea         ;Рабочая область минимум 4096*4 байт
1114
    end if
1115
 
1116
    call ReadGIF
1117
    jmp  gifmacend
1118
 
1119
    if defined gif_hash_offset
1120
    else
1121
    hasharea:
1122
    times 4096 dd 0 ;4096
1123
    end if
1124
 
1125
ReadGIF:
1126
    push esi edi
1127
    mov  [table_ptr],eax
1128
    mov  [cur_info],edi
1129
    xor  eax,eax
1130
    mov  [globalColor],eax
1131
    mov  [img_count],eax
1132
    inc  eax
1133
    cmp  dword[esi],'GIF8'
1134
    jne  er            ; signature
1135
    mov  ecx,[esi+0xa]
1136
    inc  eax
1137
    add  esi,0xd
1138
    mov  edi,esi
1139
    bt   ecx,7
1140
    jnc  nextblock
1141
    mov  [globalColor],esi
1142
    call Gif_skipmap
1143
nextblock:
1144
    cmp  byte[edi],0x21
1145
    jne  noextblock
1146
    inc  edi
1147
    cmp  byte[edi],0xf9 ; Graphic Control Ext
1148
    jne  no_gc
1149
    add  edi,7
1150
    jmp  nextblock
1151
no_gc:
1152
    cmp  byte[edi],0xfe ; Comment Ext
1153
    jne  no_comm
1154
    inc  edi
1155
block_skip:
1156
    movzx eax,byte[edi]
1157
    lea  edi,[edi+eax+1]
1158
    cmp  byte[edi],0
1159
    jnz  block_skip
1160
    inc  edi
1161
    jmp  nextblock
1162
no_comm:
1163
    cmp  byte[edi],0xff ; Application Ext
1164
    jne  nextblock
1165
    add  edi,13
1166
    jmp  block_skip
1167
noextblock:
1168
    cmp  byte[edi],0x2c    ; image beginning
1169
    jne  er
1170
    inc  [img_count]
1171
    inc  edi
1172
    mov  esi,[cur_info]
1173
    xchg esi,edi
1174
;    movsd
1175
;    movsd
1176
 
1177
    mov   bp,word[esi+4]
1178
    movzx ebx,bp
1179
    mov   [edi],ebx
1180
 
1181
    mov   bp,word[esi+6]
1182
    movzx ebx,bp
1183
    mov   [edi+4],ebx
1184
 
1185
    add edi,8
1186
    add esi,8
1187
 
1188
    push edi
1189
    movzx ecx,word[esi]
1190
    inc  esi
1191
    bt   ecx,7
1192
    jc   uselocal
1193
    push [globalColor]
1194
    mov  edi,esi
1195
    jmp  setPal
1196
uselocal:
1197
    call Gif_skipmap
1198
    push esi
1199
setPal:
1200
    movzx ecx,byte[edi]
1201
    inc  ecx
1202
    mov  [codesize],ecx
1203
    dec  ecx
1204
    pop  [Palette]
1205
    lea  esi,[edi+1]
1206
    mov  edi,[table_ptr]
1207
    xor  eax,eax
1208
    cld
1209
    lodsb               ; eax - block_count
1210
    add  eax,esi
1211
    mov  [block_ofs],eax
1212
    mov  [bit_count],8
1213
    mov  eax,1
1214
    shl  eax,cl
1215
    mov  [CC],eax
1216
    inc  eax
1217
    mov  [EOI],eax
1218
    lea  ecx,[eax-1]
1219
    mov  eax, _null shl 16
1220
filltable:
1221
    stosd
1222
    inc  eax
1223
    loop filltable
1224
    pop  edi
1225
    mov  [img_start],edi
1226
reinit:
1227
    mov  edx,[EOI]
1228
    inc  edx
1229
    push [codesize]
1230
    pop  [compsize]
1231
    call Gif_get_sym
1232
    cmp  eax,[CC]
1233
    je   reinit
1234
    call Gif_output
1235
cycle:
1236
    movzx ebx,ax
1237
    call Gif_get_sym
1238
    cmp  eax,edx
1239
    jae  notintable
1240
    cmp  eax,[CC]
1241
    je   reinit
1242
    cmp  eax,[EOI]
1243
    je   zend
1244
    call Gif_output
1245
zadd:
1246
    push eax
1247
    mov  eax,[table_ptr]
1248
    mov  [eax+edx*4],ebx
1249
    pop  eax
1250
    cmp  edx,0xFFF
1251
    jae  cycle
1252
    inc  edx
1253
    bsr  ebx,edx
1254
    cmp  ebx,[compsize]
1255
    jne  noinc
1256
    inc  [compsize]
1257
noinc:
1258
    jmp  cycle
1259
notintable:
1260
    push eax
1261
    mov  eax,ebx
1262
    call Gif_output
1263
    push ebx
1264
    movzx eax,bx
1265
    call Gif_output
1266
    pop  ebx eax
1267
    jmp  zadd
1268
er:
1269
    pop  edi
1270
    jmp  ex
1271
zend:
1272
;    mov  eax,[.cur_info]    ; skip offset to next frame
1273
;    mov  [eax],edi
1274
    mov  [cur_info],edi
1275
    add  esi,2
1276
    xchg esi,edi
1277
nxt:
1278
    cmp  byte[edi],0
1279
    jnz  continue
1280
    inc  edi
1281
    jmp  nxt
1282
continue:
1283
;    cmp  byte[edi],0x3b    ;read next frame
1284
;    jne  nextblock
1285
    xor  eax,eax
1286
    stosd
1287
    mov  ecx,[img_count]
1288
ex:
1289
    pop  edi esi
1290
    ret
1291
 
1292
Gif_skipmap:
1293
; in: ecx - image descriptor, esi - pointer to colormap
1294
; out: edi - pointer to area after colormap
1295
 
1296
    and  ecx,111b
1297
    inc  ecx            ; color map size
1298
    mov  ebx,1
1299
    shl  ebx,cl
1300
    lea  ebx,[ebx*2+ebx]
1301
    lea  edi,[esi+ebx]
1302
    ret
1303
 
1304
Gif_get_sym:
1305
    mov  ecx,[compsize]
1306
    push ecx
1307
    xor  eax,eax
1308
shift:
1309
    ror  byte[esi],1
1310
    rcr  eax,1
1311
    dec  [bit_count]
1312
    jnz  loop1
1313
    inc  esi
1314
    cmp  esi,[block_ofs]
1315
    jb   noblock
1316
    push eax
1317
    xor  eax,eax
1318
    lodsb
1319
    test eax,eax
1320
    jnz  nextbl
1321
    mov  eax,[EOI]
1322
    sub  esi,2
1323
    add  esp,8
1324
    jmp  exx
1325
nextbl:
1326
    add  eax,esi
1327
    mov  [block_ofs],eax
1328
    pop  eax
1329
noblock:
1330
    mov  [bit_count],8
1331
loop1:
1332
    loop shift
1333
    pop  ecx
1334
    rol  eax,cl
1335
exx:
1336
    xor  ecx,ecx
1337
    ret
1338
 
1339
Gif_output:
1340
    push esi eax edx
1341
    mov  edx,[table_ptr]
1342
next:
1343
    push word[edx+eax*4]
1344
    mov  ax,word[edx+eax*4+2]
1345
    inc  ecx
1346
    cmp  ax,_null
1347
    jnz  next
1348
    shl  ebx,16
1349
    mov  bx,[esp]
1350
loop2:
1351
    pop  ax
1352
 
1353
    lea  esi,[eax+eax*2]
1354
    add  esi,[Palette]
1355
 
1356
    if COLOR_ORDER eq MENUETOS
1357
        mov  esi,[esi]
1358
        bswap esi
1359
        shr  esi,8
1360
        mov  [edi],esi
1361
        add  edi,3
1362
    else
1363
        movsw
1364
        movsb
1365
    end if
1366
 
1367
    loop loop2
1368
    pop  edx eax esi
1369
    ret
1370
 
1371
    globalColor dd 1
1372
    img_count dd 1
1373
    cur_info dd 1        ; image table pointer
1374
    img_start dd 1
1375
    codesize dd 1
1376
    compsize dd 1
1377
    bit_count dd 1
1378
    CC dd 1
1379
    EOI dd 1
1380
    Palette dd 1
1381
    block_ofs dd 1
1382
    table_ptr dd 1
1383
 
1384
gifmacend:
1385
}
1386