Subversion Repositories Kolibri OS

Rev

Rev 950 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;
  2. ;   Assembler
  3. ;     SMALL
  4. ;       CODE
  5. ;         Graphics
  6. ;           Libary
  7. ;
  8. ;   Ver 0.18 By Pavlushin Evgeni (RUSSIA)
  9. ;   www.waptap@mail.ru
  10.  
  11. ;InfoList
  12. ;0.01 LoadImage
  13. ;0.02 SetBmp
  14. ;0.03 Bmptoimg, Setimg ~01.03.2004
  15. ;0.04 Bug deleted, copyimg ~03.05.2004
  16. ;0.05 fullimg, collimg ~05.05.2004
  17. ;0.06 getimg ~09.05.2004
  18. ;0.07 convbmp ~13.05.2004
  19. ;0.08 fps ~14.05.2004
  20. ;0.09 drawfbox ~03.06.2004
  21. ;0.10 all macros optimized by halyavin, add at ~07.06.2004
  22. ;0.11 many macros optimized by halyavin, add at ~30.08.2004
  23. ;0.12 bmptoimg ~07.09.2004
  24. ;0.13 imgtoimg ~08.09.2004
  25. ;0.14 imgtoimg modify not brake bmp pict! ~09.09.2004
  26. ;0.15 giftoimg, giftoani ~10.09.2004
  27. ;0.16 setframe, rgbtobgr, setbmp deleted ~20.09.2004
  28. ;0.17 modification giftoimg, giftoani, getframeoff ~01.10.2004
  29. ;0.18 aframetoimg,aimgtoimg,frametoimg ~03.10.2004
  30.  
  31. aframetoimg_use_count=0
  32. macro aframetoimg img, x, y, canvas,acol
  33. {
  34. local loo,loo2,acolor
  35. aframetoimg_use_count=aframetoimg_use_count+1
  36. if aframetoimg_use_count = 1
  37.  
  38.      jmp end_aframetoimg_proc
  39.  
  40. acolor dd 0
  41. aframetoimg_proc:
  42. ;getout coord
  43.     mov [acolor],ebp
  44.  
  45.     mov edx,ebx ;img   ;xsize
  46.     movzx eax,word [edx]
  47.     add eax,esi ;y cor
  48.  
  49. ;    mov eax,esi ;y cor
  50.     mul dword [ecx] ;canvas xsize
  51.     add eax,edi ;x cor
  52.  
  53.     mov ebp,ebx ;img   ;xsize
  54.     movzx edx,word [ebp]
  55.     add eax,edx
  56.  
  57.     mov ebp,eax
  58.     shl eax,1
  59.     add ebp,eax
  60.     add ebp,ecx ;canvas+8;start
  61.     add ebp,8
  62. ;get img size
  63.     add ebx,4
  64.     mov eax,ebx ;img   ;xsize
  65.     movzx esi,word [eax]
  66.     movzx edi,word [eax+2]
  67.     add ebx,4
  68.     mov edx,ebx ;img+8
  69. loo2:
  70. push esi
  71. loo:
  72. ;test on alpha color
  73.     mov eax,[edx]
  74.     shl eax,8
  75.     shr eax,8
  76.     cmp eax,[acolor]
  77.     jne  yx
  78.     add edx,3
  79.     add ebp,3
  80.     jmp nx
  81. yx:
  82.  
  83.     mov al,byte [edx]
  84.     mov byte [ebp],al
  85.     inc ebp
  86.     inc edx
  87.     mov al,byte [edx]
  88.     mov byte [ebp],al
  89.     inc ebp
  90.     inc edx
  91.     mov al,byte [edx]
  92.     mov byte [ebp],al
  93.     inc ebp
  94.     inc edx
  95. nx:
  96.     dec esi
  97.     jnz loo
  98. pop esi
  99.     sub ebp,3
  100.     mov eax,[ecx]  ;offset = offset+((canxsize-imgxsize)*3)
  101.     sub eax,esi
  102.     add ebp,eax
  103.     shl eax,1
  104.     add ebp,eax
  105.  
  106.     add ebp,3
  107.  
  108.     dec edi
  109.     jnz loo2
  110.     ret
  111. end_aframetoimg_proc:
  112. end if
  113.     push img
  114.     push canvas
  115.     push x
  116.     push y
  117.     push acol
  118.     pop  ebp
  119.     pop  esi
  120.     pop  edi
  121.     pop ecx
  122.     pop ebx
  123.     call aframetoimg_proc
  124. }
  125.  
  126. frametoimg_use_count=0
  127. macro frametoimg img, x, y, canvas
  128. {
  129. local loo,loo2
  130. frametoimg_use_count=frametoimg_use_count+1
  131. if frametoimg_use_count = 1
  132.  
  133.     jmp end_frametoimg_proc
  134.  
  135. frametoimg_proc:
  136. ;getout coord
  137.     mov edx,ebx ;img   ;xsize
  138.     movzx eax,word [edx]
  139.     add eax,esi ;y cor
  140.  
  141. ;    mov eax,esi ;y cor
  142.     mul dword [ecx] ;canvas xsize
  143.     add eax,edi ;x cor
  144.  
  145.     mov ebp,ebx ;img   ;xsize
  146.     movzx edx,word [ebp]
  147.     add eax,edx
  148.  
  149.     mov ebp,eax
  150.     shl eax,1
  151.     add ebp,eax
  152.     add ebp,ecx ;canvas+8;start
  153.     add ebp,8
  154. ;get img size
  155.     add ebx,4
  156.     mov eax,ebx ;img   ;xsize
  157.     movzx esi,word [eax]
  158.     movzx edi,word [eax+2]
  159.     add ebx,4
  160.     mov edx,ebx ;img+8
  161. loo2:
  162. push esi
  163. loo:
  164.     mov al,byte [edx]
  165.     mov byte [ebp],al
  166.     inc ebp
  167.     inc edx
  168.     mov al,byte [edx]
  169.     mov byte [ebp],al
  170.     inc ebp
  171.     inc edx
  172.     mov al,byte [edx]
  173.     mov byte [ebp],al
  174.     inc ebp
  175.     inc edx
  176.  
  177.     dec esi
  178.     jnz loo
  179. pop esi
  180.     sub ebp,3
  181.     mov eax,[ecx]  ;offset = offset+((canxsize-imgxsize)*3)
  182.     sub eax,esi
  183.     add ebp,eax
  184.     shl eax,1
  185.     add ebp,eax
  186.  
  187.     add ebp,3
  188.  
  189.     dec edi
  190.     jnz loo2
  191.     ret
  192. end_frametoimg_proc:
  193. end if
  194.     push img
  195.     push canvas
  196.     push x
  197.     push y
  198.     pop  esi
  199.     pop  edi
  200.     pop ecx
  201.     pop ebx
  202.     call frametoimg_proc
  203. }
  204.  
  205.  
  206. aimgtoimg_use_count=0
  207. macro aimgtoimg img, x, y, canvas,acol,offset
  208. {
  209. local loo,loo2,acolor
  210. aimgtoimg_use_count=aimgtoimg_use_count+1
  211. if aimgtoimg_use_count = 1
  212.  
  213.      jmp end_aimgtoimg_proc
  214.  
  215. acolor dd 0
  216. aimgtoimg_proc:
  217. ;getout coord
  218.     mov [acolor],ebp
  219.     push eax                      ;;;;;;;;;;;;;;;;;;;
  220.     mov eax,esi ;y cor
  221.     mul dword [ecx] ;canvas xsize
  222.     add eax,edi ;x cor
  223.     mov ebp,eax
  224.     shl eax,1
  225.     add ebp,eax
  226.     add ebp,ecx ;canvas+8;start
  227.     add ebp,8
  228. ;get img size
  229.     mov eax,ebx ;img   ;xsize
  230.     mov esi,[eax]
  231.     add ebx,4
  232.     mov eax,ebx ; img+4 ;ysize
  233.     mov edi,[eax]
  234.     add ebx,4
  235.     mov edx,ebx ;img+8
  236.     pop eax
  237.     add edx,eax
  238.  
  239. loo2:
  240. push esi
  241. loo:
  242.  
  243. ;test on alpha color
  244.     mov eax,[edx]
  245.     shl eax,8
  246.     shr eax,8
  247.     cmp eax,[acolor]
  248.     jne  yx
  249.     add edx,3
  250.     add ebp,3
  251.     jmp nx
  252. yx:
  253.  
  254.     mov al,byte [edx]
  255.     mov byte [ebp],al
  256.     inc ebp
  257.     inc edx
  258.     mov al,byte [edx]
  259.     mov byte [ebp],al
  260.     inc ebp
  261.     inc edx
  262.     mov al,byte [edx]
  263.     mov byte [ebp],al
  264.     inc ebp
  265.     inc edx
  266. nx:
  267.     dec esi
  268.     jnz loo
  269. pop esi
  270.     sub ebp,3
  271.     mov eax,[ecx]  ;offset = offset+((canxsize-imgxsize)*3)
  272.     sub eax,esi
  273.     add ebp,eax
  274.     shl eax,1
  275.     add ebp,eax
  276.  
  277.     add ebp,3
  278.  
  279.     dec edi
  280.     jnz loo2
  281.     ret
  282. end_aimgtoimg_proc:
  283. end if
  284.     push img
  285.     push canvas
  286.     push x
  287.     push y
  288.     push acol
  289.     push offset
  290.     pop  eax
  291.     pop  ebp
  292.     pop  esi
  293.     pop  edi
  294.     pop ecx
  295.     pop ebx
  296.     call aimgtoimg_proc
  297. }
  298.  
  299.  
  300.  
  301.  
  302. imgtoimg_use_count=0
  303. macro imgtoimg img, x, y, canvas
  304. {
  305. local loo,loo2
  306. imgtoimg_use_count=imgtoimg_use_count+1
  307. if imgtoimg_use_count = 1
  308.  
  309.      jmp end_imgtoimg_proc
  310. imgtoimg_proc:
  311. ;getout coord
  312.     mov eax,esi ;y cor
  313.     mul dword [ecx] ;canvas xsize
  314.     add eax,edi ;x cor
  315.     mov ebp,eax
  316.     shl eax,1
  317.     add ebp,eax
  318.     add ebp,ecx ;canvas+8;start
  319.     add ebp,8
  320. ;get img size
  321.     mov eax,ebx ;img   ;xsize
  322.     mov esi,[eax]
  323.     add ebx,4
  324.     mov eax,ebx ; img+4 ;ysize
  325.     mov edi,[eax]
  326.     add ebx,4
  327.     mov edx,ebx ;img+8
  328. loo2:
  329. push esi
  330. loo:
  331.     mov al,byte [edx]
  332.     mov byte [ebp],al
  333.     inc ebp
  334.     inc edx
  335.     mov al,byte [edx]
  336.     mov byte [ebp],al
  337.     inc ebp
  338.     inc edx
  339.     mov al,byte [edx]
  340.     mov byte [ebp],al
  341.     inc ebp
  342.     inc edx
  343.     dec esi
  344.     jnz loo
  345. pop esi
  346.     sub ebp,3
  347.     mov eax,[ecx]  ;offset = offset+((canxsize-imgxsize)*3)
  348.     sub eax,esi
  349.     add ebp,eax
  350.     shl eax,1
  351.     add ebp,eax
  352.  
  353.     add ebp,3
  354.  
  355.     dec edi
  356.     jnz loo2
  357.     ret
  358. end_imgtoimg_proc:
  359. end if
  360.     push img
  361.     push canvas
  362.     push x
  363.     push y
  364.     pop  esi
  365.     pop  edi
  366.     pop  ecx
  367.     pop  ebx
  368.     call imgtoimg_proc
  369. }
  370.  
  371.  
  372. ;DrawBox
  373. macro drawfbox x,y,xs,ys,color
  374. {
  375.     words2reg ebx,x,xs ;x*65536+xs
  376.     words2reg ecx,y,ys ;y*65536+ys
  377.     mov  edx,color
  378.     mov  eax,13
  379.     int  0x40
  380. }
  381.  
  382. ; FPS - Set Frame Per Second Display
  383. fps_show_frequency=40
  384. macro fps x,y,color,delcolor
  385. {
  386. local spdat,savetime,new_time,fps,fps_cntr,out_fps,new_time,ttt
  387. local no_out_fps
  388.     jmp spdat
  389. savetime dd 0
  390. fps_cntr dd 0
  391. fps      dd 0
  392. ttt      dd 0
  393. spdat:
  394. get_time:
  395.     mov eax,3
  396.     int 0x40
  397.     cmp eax,[savetime]
  398.     jne new_time
  399.     inc [fps_cntr]
  400.     cmp dword [ttt],0
  401.     je  out_fps
  402.     dec dword [ttt]
  403.     jmp no_out_fps
  404. new_time:
  405.     mov [savetime],eax
  406.     mov ebx,[fps_cntr]
  407.     mov [fps],ebx
  408.     mov [fps_cntr],0
  409. out_fps:
  410. if ~(delcolor eq )
  411.     mov ebx,x*65536+30
  412.     mov ecx,y*65536+7
  413.     mov edx,delcolor
  414.     mov eax,13
  415.     int 0x40
  416. end if
  417.     mov dword [ttt],fps_show_frequency
  418.     mov eax,47
  419.     mov ebx,5*65536
  420. ;   mov bl,0
  421.     mov edx,x*65536+y
  422.     mov esi,color
  423.     mov ecx,[fps]
  424.     int 0x40
  425. no_out_fps:
  426. }
  427.  
  428. ; COLLIMG - Collusion image's
  429. _1dbounce_count=0;
  430. macro collimg img1_off,x1,y1,img2_off,x2,y2,otv
  431. {
  432. local bounce,exit,anot,bc,nbc
  433.         mov esi,[img1_off] ;xs1
  434.         mov edi,[img2_off] ;ys2
  435.         mov eax,x1 ;
  436.         mov ebx,x2 ;
  437.         call _1dbounce
  438.         mov edx,ecx
  439.         mov esi,[img1_off+4] ;ys1
  440.         mov edi,[img2_off+4] ;ys2
  441.         mov eax,y1 ;
  442.         mov ebx,y2 ;
  443.         call _1dbounce
  444.         add edx,ecx
  445.         cmp edx,2
  446.         je bounce
  447.         mov otv,0
  448.         jmp exit
  449. _1dbounce_count=_1dbounce_count+1
  450. if _1dbounce_count = 1
  451. _1dbounce:
  452.         cmp ebx,eax
  453.         jb  anot
  454.         add eax,esi
  455.         cmp eax,ebx
  456.         jbe nbc
  457. bc:
  458.         mov ecx,1
  459.         ret
  460. anot:
  461.     add ebx,edi
  462.         cmp ebx,eax
  463.         ja  bc
  464. nbc:
  465.         xor ecx,ecx
  466.         ret
  467. end if
  468. bounce:
  469.         mov otv,1
  470. exit:
  471. }
  472.  
  473. macro rgbtobgr image
  474. {
  475. local loo
  476.     mov eax,[image]
  477.     mul dword [image+4]
  478.     mov ecx,eax
  479.     mov esi,image+8
  480. ;   add esi,8
  481. loo:
  482.    mov al,[esi]
  483.    mov bl,[esi+2]
  484.    mov [esi],bl
  485.    mov [esi+2],al
  486.    add esi,3
  487.    dec ecx
  488.    jnz loo
  489. }
  490.  
  491.  
  492. macro setimg x , y ,arg3
  493. {
  494.     mov  eax,7
  495.     mov  ebx,arg3
  496.     add  ebx,8
  497.     mov  cx,[arg3]
  498.     shl  ecx,16
  499.     add  cx,[arg3+4]
  500. ;    wordstoreg ecx,[arg3],[arg3+4]
  501.     words2reg edx, x , y  ;arg1*65536+arg2
  502.     int  0x40
  503. }
  504.  
  505. macro setframe x , y ,arg3
  506. {
  507.     mov  eax,7
  508.     mov  ebx,arg3
  509.     add  ebx,8
  510.     words2reg edx, x , y  ;arg1*65536+arg2
  511.     add  edx,dword [arg3]
  512.     mov  ecx,dword [arg3+4]
  513.     int  0x40
  514. }
  515.  
  516.  
  517. macro getimg imgsrc,x,y,xs,ys,imgdest
  518. {
  519. local cyc
  520. if xs eqtype 0
  521.     mov dword [imgdest],xs
  522. else
  523.     mov eax,xs
  524.     mov dword [imgdest],eax
  525. end if
  526. if ys eqtype 0
  527.     mov dword [imgdest+4],ys
  528. else
  529.     mov eax,ys
  530.     mov dword [imgdest+4],eax
  531. end if
  532.  
  533.     mov eax,dword [imgsrc] ;getx size
  534. ;    lea ecx,[eax+2*eax]
  535.     mov ecx,eax
  536.     shl ecx,1
  537.     add ecx,eax
  538.  
  539.     mov ebx,y
  540.     mul ebx
  541.     add eax,x
  542.     mov edx,ecx
  543.     lea eax,[eax+2*eax]  ;eax=offset on imsrc
  544. ;    mov ebp,eax
  545. ;    shl eax,1
  546. ;    add eax,ebp
  547.  
  548.     mov ecx,xs
  549.     mov ebx,ys
  550.  
  551.     mov edi,8+imgdest
  552.     lea esi,[eax+8+imgsrc]
  553. ;    mov esi,eax
  554. ;    add esi,8
  555. ;    add esi,imgsrc
  556.  
  557.     cld
  558. cyc:
  559.     movsw
  560.     movsb
  561.     dec ecx
  562.     jne cyc
  563.     add esi,edx
  564.     mov ecx,xs
  565.     sub esi,ecx
  566.     sub esi,ecx
  567.     sub esi,ecx
  568.     dec ebx
  569.     jne cyc
  570. }
  571.  
  572. macro copyimg img2_off,img1_off
  573. {
  574.     mov  eax,dword [img1_off]
  575.     mov  ebx,dword [img1_off+4]
  576.     mul  ebx
  577.     lea  ecx,[eax+2*eax]
  578.     lea  esi,[img1_off+8]
  579.     lea  edi,[img2_off+8]
  580.     cld
  581.     rep  movsb
  582. }
  583.  
  584. macro fullimg img_off,xs,ys,color
  585. {
  586. local cop
  587.     mov eax,xs
  588.     mov ebx,ys
  589.     mov  dword [img_off],eax
  590.     mov  dword [img_off+4],ebx
  591.     mul  ebx
  592.     lea  ebp,[eax+2*eax]
  593.     mov  esi,color
  594. if color eqtype 0
  595.     mov  ecx,color/65536
  596. else
  597.     mov  ecx,esi
  598.     shr  ecx,16
  599. end if
  600.     xor  edi,edi
  601. cop:
  602.     mov  word [img_off+8+edi],si
  603.     add  edi,2
  604.     mov  byte [img_off+8+edi],cl
  605.     inc  edi
  606.     cmp  edi,ebp
  607.     jne  cop
  608. }
  609.  
  610.  
  611.  
  612.   ; number of frame in ecx
  613.   ; callculatin offset of raw data
  614.  
  615. macro getframeoff num_of_frame,offset_of_animation,offset_of_frame
  616. {
  617. local loo,setpic
  618.   mov ebp,num_of_frame ;ecx
  619.   mov esi,offset_of_animation;Image
  620. loo:
  621.   cmp ebp,0
  622.   je  setpic
  623.   movzx eax,word [esi+4]
  624.   movzx ebx,word [esi+6]
  625.   mul ebx ;dword [esi+4]
  626.   mov ebx,3
  627.   mul ebx
  628.   add eax,8
  629.   add esi,eax
  630.   dec ebp
  631.   jmp loo
  632. setpic:
  633.   mov dword offset_of_frame,esi
  634. }
  635.  
  636.  
  637. ; BMPTOIMG -Convert BMP format TO IMG format
  638. ; (SYNTAX)  BMPTOIMG BMP_source_offset,IMG_dest_ofset
  639. ; (SAMPLE)  View BMPLS.ASM sample.
  640. ; ( NOTE )  This is macros is not brake bmp structure! Tested in 32,8,4 bits
  641.  
  642.  
  643. bmptoimg_data_area_count=0
  644. macro bmptoimg bmp_load_area,img_dest_area
  645. {
  646. local fileinfo,string,end_bmp,nodix
  647. local converttable,noaddelem,nextbit,convert1bpp,convert4bpp,convert2
  648. local nextelem,convertno32,nomorestring,convert1,nextstring,yespicsize
  649. ;local qwe,bmpfn
  650.  
  651. ;  convert:
  652.     movzx eax,word [bmp_load_area+28]
  653.     mul  dword [bmp_load_area+18]
  654.     add  eax,31
  655.     shr  eax,5
  656.     mov  dword [bmptoimg_data_area_dwps],eax  ;dwps-doublewords per string
  657.     shl  eax,2
  658.     mov  dword [bmptoimg_data_area_bps],eax   ;bps-bytes per string
  659.  
  660.     cmp dword [bmp_load_area+34],0
  661.     jne  yespicsize  ;if picture size is defined
  662.     mul dword [bmp_load_area+22]
  663.     mov dword [bmp_load_area+34],eax
  664.  
  665.   yespicsize:
  666.     mov ebp,img_dest_area+8
  667.  
  668.     mov  eax,bmp_load_area
  669.     mov  ebx,eax
  670.     add  ebx, [bmp_load_area+2];file size
  671.     inc  ebx
  672.     mov  dword [bmptoimg_soi],ebx   ;soi-start of image area for drawing
  673.  
  674.     add  eax, [bmp_load_area+10]
  675.     mov  dword [bmptoimg_data_area_sop],eax   ;sop-start of picture in file
  676.     add  eax, [bmp_load_area+34]
  677.     mov  dword [bmptoimg_data_area_eop],eax   ;eop-end of picture in file
  678.     mov  eax, [bmp_load_area+18]
  679.     lea  eax,[eax+2*eax]   ;3x pixels in eax
  680.  
  681.     mov  edi,dword [bmptoimg_soi]   ;initializing
  682.     mov  esi,dword [bmptoimg_data_area_eop]
  683.     sub  esi,dword [bmptoimg_data_area_bps]
  684.  
  685.  
  686.   nextstring:
  687.     push edi
  688.     push ebp
  689.     cmp  word [bmp_load_area+28],24
  690.     jne  convertno32
  691.  
  692.     mov edi,ebp
  693.     mov  ecx,[bmptoimg_data_area_dwps]
  694.     cld
  695.     rep movsd
  696.  
  697.   convert1:
  698.     pop  ebp
  699.     pop  edi
  700.     sub  esi,dword [bmptoimg_data_area_bps]
  701.     sub  esi,dword [bmptoimg_data_area_bps]
  702.     cmp  esi,dword [bmptoimg_data_area_sop]
  703.     jb   end_bmp
  704.     add  edi,eax
  705.     add  ebp,eax
  706.     jmp  nextstring
  707.  
  708.   convertno32:
  709.     mov  ebx,bmp_load_area
  710.     add  ebx, [bmp_load_area+14]
  711.     add  ebx,14          ;start of color table
  712.     push esi
  713.     add  esi,dword [bmptoimg_data_area_bps]
  714.     mov  dword [bmptoimg_data_area_eos],esi
  715.     pop  esi
  716.   nextelem:
  717.     push eax
  718.     movzx eax,byte [esi]
  719.     cmp  word [bmp_load_area+28],4
  720.     je   convert4bpp
  721.     cmp  word [bmp_load_area+28],1
  722.     je   convert1bpp
  723.     call converttable
  724.  
  725.   convert2:
  726.     pop  eax
  727.     inc  esi
  728.     cmp  esi,dword [bmptoimg_data_area_eos]
  729.     jae  convert1
  730.     add  edi,3
  731.  
  732.     add  ebp,3
  733.  
  734.     jmp  nextelem
  735.  
  736.   convert4bpp:
  737.     shl  ax,4
  738.     shr  al,4
  739.     push ax
  740.     movzx eax,ah
  741.     call converttable
  742.     add  edi,3
  743.  
  744.     add ebp,3
  745.  
  746.     pop  ax
  747.     movzx eax,al
  748.     call converttable
  749.     jmp  convert2
  750.  
  751.   convert1bpp:
  752.     mov  ecx,eax
  753.     mov  edx,7
  754.   nextbit:
  755.     xor  eax,eax
  756.     bt   ecx,edx
  757.     jnc  noaddelem
  758.     inc  eax
  759.   noaddelem:
  760.     push edx
  761.     call converttable
  762.     pop  edx
  763.     dec  edx
  764.     js   convert2
  765.     add  edi,3
  766.  
  767.     add  ebp,3
  768.  
  769.     jmp  nextbit
  770.  
  771.   converttable:
  772.     shl  eax,2
  773.     add  eax,ebx
  774.     mov  edx, dword [eax]
  775. ;    mov  dword [edi],edx
  776.     mov [ebp],edx
  777.     ret
  778.  
  779. bmptoimg_data_area_count=bmptoimg_data_area_count+1
  780. if bmptoimg_data_area_count = 1
  781. ; DATA AREA
  782. bmptoimg_soi                dd 0
  783. bmptoimg_data_area_bps      dd 0
  784. bmptoimg_data_area_dwps     dd 0
  785. bmptoimg_data_area_sop      dd 0
  786. bmptoimg_data_area_eop      dd 0
  787. bmptoimg_data_area_eos      dd 0
  788. end if
  789.  
  790. end_bmp:
  791.     mov  eax,dword [bmp_load_area+18]
  792.     mov  ebx,dword [bmp_load_area+22]
  793.     mov  dword [img_dest_area],eax
  794.     mov  dword [img_dest_area+4],ebx
  795. }
  796.  
  797. ; For convert RGB to BGR
  798. COLOR_ORDER equ MENUETOS
  799.  
  800. macro giftoani gifsrc,imgsrc,num_of_frames
  801. {
  802. local hasharea, ReadGIF, nextblock,_null
  803. local globalColor, img_count, cur_info, img_start
  804. local codesize, compsize, bit_count, CC, EOI, Palette
  805. local block_ofs, table_ptr, gifmacend
  806. local no_gc, block_skip, no_comm, noextblock, uselocal
  807. local setPal, filltable, reinit, cycle, zadd, noinc
  808. local notintable, er, zend, nxt, continue, ex, Gif_skipmap
  809. local Gif_get_sym, shift, nextbl, noblock, loop1, exx
  810. local Gif_output, next, loop2
  811.  
  812. _null fix 1000h ; 0x1000
  813.  
  814. ;    jmp sss
  815. ;    if defined gif_hash_offset
  816. ;    else
  817. ;    hasharea:
  818. ;    times 4096 dd 0 ;4096
  819. ;    end if
  820. ;sss:
  821.  
  822.     mov  esi,gifsrc           ;“ª § â¥«ì ­  ƒˆ” ä ¨« ¢ ¯ ¬ïâ¨
  823.     mov  edi,imgsrc           ;“ª § â¥«ì ­  ᯨ᮪ ª à⨭®ª
  824.  
  825.     if defined gif_hash_offset
  826.     mov  eax,gif_hash_offset    ; ¡®ç ï ®¡« áâì ¬¨­¨¬ã¬ 4096*4 ¡ ©â
  827.     else
  828.     mov  eax,hasharea         ; ¡®ç ï ®¡« áâì ¬¨­¨¬ã¬ 4096*4 ¡ ©â
  829.     end if
  830.  
  831.     call ReadGIF
  832.     push ecx
  833.     pop  dword num_of_frames
  834.     jmp  gifmacend
  835.  
  836.     if defined gif_hash_offset
  837.     else
  838.     hasharea:
  839.     times 4096 dd 0 ;4096
  840.     end if
  841.  
  842. ReadGIF:
  843.     push esi edi
  844.     mov  [table_ptr],eax
  845.     mov  [cur_info],edi
  846.     xor  eax,eax
  847.     mov  [globalColor],eax
  848.     mov  [img_count],eax
  849.     inc  eax
  850.     cmp  dword[esi],'GIF8'
  851.     jne  er            ; signature
  852.     mov  ecx,[esi+0xa]
  853.     inc  eax
  854.     add  esi,0xd
  855.     mov  edi,esi
  856.     bt   ecx,7
  857.     jnc  nextblock
  858.     mov  [globalColor],esi
  859.     call Gif_skipmap
  860. nextblock:
  861.     cmp  byte[edi],0x21
  862.     jne  noextblock
  863.     inc  edi
  864.     cmp  byte[edi],0xf9 ; Graphic Control Ext
  865.     jne  no_gc
  866.     add  edi,7
  867.     jmp  nextblock
  868. no_gc:
  869.     cmp  byte[edi],0xfe ; Comment Ext
  870.     jne  no_comm
  871.     inc  edi
  872. block_skip:
  873.     movzx eax,byte[edi]
  874.     lea  edi,[edi+eax+1]
  875.     cmp  byte[edi],0
  876.     jnz  block_skip
  877.     inc  edi
  878.     jmp  nextblock
  879. no_comm:
  880.     cmp  byte[edi],0xff ; Application Ext
  881.     jne  nextblock
  882.     add  edi,13
  883.     jmp  block_skip
  884. noextblock:
  885.     cmp  byte[edi],0x2c    ; image beginning
  886.     jne  er
  887.     inc  [img_count]
  888.     inc  edi
  889.     mov  esi,[cur_info]
  890.     xchg esi,edi
  891.     movsd
  892.     movsd
  893.  
  894.     push edi
  895.     movzx ecx,word[esi]
  896.     inc  esi
  897.     bt   ecx,7
  898.     jc   uselocal
  899.     push [globalColor]
  900.     mov  edi,esi
  901.     jmp  setPal
  902. uselocal:
  903.     call Gif_skipmap
  904.     push esi
  905. setPal:
  906.     movzx ecx,byte[edi]
  907.     inc  ecx
  908.     mov  [codesize],ecx
  909.     dec  ecx
  910.     pop  [Palette]
  911.     lea  esi,[edi+1]
  912.     mov  edi,[table_ptr]
  913.     xor  eax,eax
  914.     cld
  915.     lodsb               ; eax - block_count
  916.     add  eax,esi
  917.     mov  [block_ofs],eax
  918.     mov  [bit_count],8
  919.     mov  eax,1
  920.     shl  eax,cl
  921.     mov  [CC],eax
  922.     inc  eax
  923.     mov  [EOI],eax
  924.     lea  ecx,[eax-1]
  925.     mov  eax, _null shl 16
  926. filltable:
  927.     stosd
  928.     inc  eax
  929.     loop filltable
  930.     pop  edi
  931.     mov  [img_start],edi
  932. reinit:
  933.     mov  edx,[EOI]
  934.     inc  edx
  935.     push [codesize]
  936.     pop  [compsize]
  937.     call Gif_get_sym
  938.     cmp  eax,[CC]
  939.     je   reinit
  940.     call Gif_output
  941. cycle:
  942.     movzx ebx,ax
  943.     call Gif_get_sym
  944.     cmp  eax,edx
  945.     jae  notintable
  946.     cmp  eax,[CC]
  947.     je   reinit
  948.     cmp  eax,[EOI]
  949.     je   zend
  950.     call Gif_output
  951. zadd:
  952.     push eax
  953.     mov  eax,[table_ptr]
  954.     mov  [eax+edx*4],ebx
  955.     pop  eax
  956.     cmp  edx,0xFFF
  957.     jae  cycle
  958.     inc  edx
  959.     bsr  ebx,edx
  960.     cmp  ebx,[compsize]
  961.     jne  noinc
  962.     inc  [compsize]
  963. noinc:
  964.     jmp  cycle
  965. notintable:
  966.     push eax
  967.     mov  eax,ebx
  968.     call Gif_output
  969.     push ebx
  970.     movzx eax,bx
  971.     call Gif_output
  972.     pop  ebx eax
  973.     jmp  zadd
  974. er:
  975.     pop  edi
  976.     jmp  ex
  977. zend:
  978. ;    mov  eax,[.cur_info]    ; skip offset to next frame
  979. ;    mov  [eax],edi
  980.     mov  [cur_info],edi
  981.     add  esi,2
  982.     xchg esi,edi
  983. nxt:
  984.     cmp  byte[edi],0
  985.     jnz  continue
  986.     inc  edi
  987.     jmp  nxt
  988. continue:
  989.     cmp  byte[edi],0x3b    ;read next frame
  990.     jne  nextblock
  991.     xor  eax,eax
  992.     stosd
  993.     mov  ecx,[img_count]
  994. ex:
  995.     pop  edi esi
  996.     ret
  997.  
  998. Gif_skipmap:
  999. ; in: ecx - image descriptor, esi - pointer to colormap
  1000. ; out: edi - pointer to area after colormap
  1001.  
  1002.     and  ecx,111b
  1003.     inc  ecx            ; color map size
  1004.     mov  ebx,1
  1005.     shl  ebx,cl
  1006.     lea  ebx,[ebx*2+ebx]
  1007.     lea  edi,[esi+ebx]
  1008.     ret
  1009.  
  1010. Gif_get_sym:
  1011.     mov  ecx,[compsize]
  1012.     push ecx
  1013.     xor  eax,eax
  1014. shift:
  1015.     ror  byte[esi],1
  1016.     rcr  eax,1
  1017.     dec  [bit_count]
  1018.     jnz  loop1
  1019.     inc  esi
  1020.     cmp  esi,[block_ofs]
  1021.     jb   noblock
  1022.     push eax
  1023.     xor  eax,eax
  1024.     lodsb
  1025.     test eax,eax
  1026.     jnz  nextbl
  1027.     mov  eax,[EOI]
  1028.     sub  esi,2
  1029.     add  esp,8
  1030.     jmp  exx
  1031. nextbl:
  1032.     add  eax,esi
  1033.     mov  [block_ofs],eax
  1034.     pop  eax
  1035. noblock:
  1036.     mov  [bit_count],8
  1037. loop1:
  1038.     loop shift
  1039.     pop  ecx
  1040.     rol  eax,cl
  1041. exx:
  1042.     xor  ecx,ecx
  1043.     ret
  1044.  
  1045. Gif_output:
  1046.     push esi eax edx
  1047.     mov  edx,[table_ptr]
  1048. next:
  1049.     push word[edx+eax*4]
  1050.     mov  ax,word[edx+eax*4+2]
  1051.     inc  ecx
  1052.     cmp  ax,_null
  1053.     jnz  next
  1054.     shl  ebx,16
  1055.     mov  bx,[esp]
  1056. loop2:
  1057.     pop  ax
  1058.  
  1059.     lea  esi,[eax+eax*2]
  1060.     add  esi,[Palette]
  1061.  
  1062.     if COLOR_ORDER eq MENUETOS
  1063.         mov  esi,[esi]
  1064.         bswap esi
  1065.         shr  esi,8
  1066.         mov  [edi],esi
  1067.         add  edi,3
  1068.     else
  1069.         movsw
  1070.         movsb
  1071.     end if
  1072.  
  1073.     loop loop2
  1074.     pop  edx eax esi
  1075.     ret
  1076.  
  1077.     globalColor dd 1
  1078.     img_count dd 1
  1079.     cur_info dd 1        ; image table pointer
  1080.     img_start dd 1
  1081.     codesize dd 1
  1082.     compsize dd 1
  1083.     bit_count dd 1
  1084.     CC dd 1
  1085.     EOI dd 1
  1086.     Palette dd 1
  1087.     block_ofs dd 1
  1088.     table_ptr dd 1
  1089.  
  1090. gifmacend:
  1091. }
  1092.  
  1093.  
  1094.  
  1095. macro giftoimg gifsrc,imgsrc
  1096. {
  1097. local hasharea, ReadGIF, nextblock,_null
  1098. local globalColor, img_count, cur_info, img_start
  1099. local codesize, compsize, bit_count, CC, EOI, Palette
  1100. local block_ofs, table_ptr, gifmacend
  1101. local no_gc, block_skip, no_comm, noextblock, uselocal
  1102. local setPal, filltable, reinit, cycle, zadd, noinc
  1103. local notintable, er, zend, nxt, continue, ex, Gif_skipmap
  1104. local Gif_get_sym, shift, nextbl, noblock, loop1, exx
  1105. local Gif_output, next, loop2
  1106.  
  1107. _null fix 0x1000 ; 0x1000
  1108.  
  1109.     mov  esi,gifsrc           ;“ª § â¥«ì ­  ƒˆ” ä ¨« ¢ ¯ ¬ïâ¨
  1110.     mov  edi,imgsrc           ;“ª § â¥«ì ­  ᯨ᮪ ª à⨭®ª
  1111.  
  1112.     if defined gif_hash_offset
  1113.     mov  eax,gif_hash_offset    ; ¡®ç ï ®¡« áâì ¬¨­¨¬ã¬ 4096*4 ¡ ©â
  1114.     else
  1115.     mov  eax,hasharea         ; ¡®ç ï ®¡« áâì ¬¨­¨¬ã¬ 4096*4 ¡ ©â
  1116.     end if
  1117.  
  1118.     call ReadGIF
  1119.     jmp  gifmacend
  1120.  
  1121.     if defined gif_hash_offset
  1122.     else
  1123.     hasharea:
  1124.     times 4096 dd 0 ;4096
  1125.     end if
  1126.  
  1127. ReadGIF:
  1128.     push esi edi
  1129.     mov  [table_ptr],eax
  1130.     mov  [cur_info],edi
  1131.     xor  eax,eax
  1132.     mov  [globalColor],eax
  1133.     mov  [img_count],eax
  1134.     inc  eax
  1135.     cmp  dword[esi],'GIF8'
  1136.     jne  er            ; signature
  1137.     mov  ecx,[esi+0xa]
  1138.     inc  eax
  1139.     add  esi,0xd
  1140.     mov  edi,esi
  1141.     bt   ecx,7
  1142.     jnc  nextblock
  1143.     mov  [globalColor],esi
  1144.     call Gif_skipmap
  1145. nextblock:
  1146.     cmp  byte[edi],0x21
  1147.     jne  noextblock
  1148.     inc  edi
  1149.     cmp  byte[edi],0xf9 ; Graphic Control Ext
  1150.     jne  no_gc
  1151.     add  edi,7
  1152.     jmp  nextblock
  1153. no_gc:
  1154.     cmp  byte[edi],0xfe ; Comment Ext
  1155.     jne  no_comm
  1156.     inc  edi
  1157. block_skip:
  1158.     movzx eax,byte[edi]
  1159.     lea  edi,[edi+eax+1]
  1160.     cmp  byte[edi],0
  1161.     jnz  block_skip
  1162.     inc  edi
  1163.     jmp  nextblock
  1164. no_comm:
  1165.     cmp  byte[edi],0xff ; Application Ext
  1166.     jne  nextblock
  1167.     add  edi,13
  1168.     jmp  block_skip
  1169. noextblock:
  1170.     cmp  byte[edi],0x2c    ; image beginning
  1171.     jne  er
  1172.     inc  [img_count]
  1173.     inc  edi
  1174.     mov  esi,[cur_info]
  1175.     xchg esi,edi
  1176. ;    movsd
  1177. ;    movsd
  1178.  
  1179.     mov   bp,word[esi+4]
  1180.     movzx ebx,bp
  1181.     mov   [edi],ebx
  1182.  
  1183.     mov   bp,word[esi+6]
  1184.     movzx ebx,bp
  1185.     mov   [edi+4],ebx
  1186.  
  1187.     add edi,8
  1188.     add esi,8
  1189.  
  1190.     push edi
  1191.     movzx ecx,word[esi]
  1192.     inc  esi
  1193.     bt   ecx,7
  1194.     jc   uselocal
  1195.     push [globalColor]
  1196.     mov  edi,esi
  1197.     jmp  setPal
  1198. uselocal:
  1199.     call Gif_skipmap
  1200.     push esi
  1201. setPal:
  1202.     movzx ecx,byte[edi]
  1203.     inc  ecx
  1204.     mov  [codesize],ecx
  1205.     dec  ecx
  1206.     pop  [Palette]
  1207.     lea  esi,[edi+1]
  1208.     mov  edi,[table_ptr]
  1209.     xor  eax,eax
  1210.     cld
  1211.     lodsb               ; eax - block_count
  1212.     add  eax,esi
  1213.     mov  [block_ofs],eax
  1214.     mov  [bit_count],8
  1215.     mov  eax,1
  1216.     shl  eax,cl
  1217.     mov  [CC],eax
  1218.     inc  eax
  1219.     mov  [EOI],eax
  1220.     lea  ecx,[eax-1]
  1221.     mov  eax, _null shl 16
  1222. filltable:
  1223.     stosd
  1224.     inc  eax
  1225.     loop filltable
  1226.     pop  edi
  1227.     mov  [img_start],edi
  1228. reinit:
  1229.     mov  edx,[EOI]
  1230.     inc  edx
  1231.     push [codesize]
  1232.     pop  [compsize]
  1233.     call Gif_get_sym
  1234.     cmp  eax,[CC]
  1235.     je   reinit
  1236.     call Gif_output
  1237. cycle:
  1238.     movzx ebx,ax
  1239.     call Gif_get_sym
  1240.     cmp  eax,edx
  1241.     jae  notintable
  1242.     cmp  eax,[CC]
  1243.     je   reinit
  1244.     cmp  eax,[EOI]
  1245.     je   zend
  1246.     call Gif_output
  1247. zadd:
  1248.     push eax
  1249.     mov  eax,[table_ptr]
  1250.     mov  [eax+edx*4],ebx
  1251.     pop  eax
  1252.     cmp  edx,0xFFF
  1253.     jae  cycle
  1254.     inc  edx
  1255.     bsr  ebx,edx
  1256.     cmp  ebx,[compsize]
  1257.     jne  noinc
  1258.     inc  [compsize]
  1259. noinc:
  1260.     jmp  cycle
  1261. notintable:
  1262.     push eax
  1263.     mov  eax,ebx
  1264.     call Gif_output
  1265.     push ebx
  1266.     movzx eax,bx
  1267.     call Gif_output
  1268.     pop  ebx eax
  1269.     jmp  zadd
  1270. er:
  1271.     pop  edi
  1272.     jmp  ex
  1273. zend:
  1274. ;    mov  eax,[.cur_info]    ; skip offset to next frame
  1275. ;    mov  [eax],edi
  1276.     mov  [cur_info],edi
  1277.     add  esi,2
  1278.     xchg esi,edi
  1279. nxt:
  1280.     cmp  byte[edi],0
  1281.     jnz  continue
  1282.     inc  edi
  1283.     jmp  nxt
  1284. continue:
  1285. ;    cmp  byte[edi],0x3b    ;read next frame
  1286. ;    jne  nextblock
  1287.     xor  eax,eax
  1288.     stosd
  1289.     mov  ecx,[img_count]
  1290. ex:
  1291.     pop  edi esi
  1292.     ret
  1293.  
  1294. Gif_skipmap:
  1295. ; in: ecx - image descriptor, esi - pointer to colormap
  1296. ; out: edi - pointer to area after colormap
  1297.  
  1298.     and  ecx,111b
  1299.     inc  ecx            ; color map size
  1300.     mov  ebx,1
  1301.     shl  ebx,cl
  1302.     lea  ebx,[ebx*2+ebx]
  1303.     lea  edi,[esi+ebx]
  1304.     ret
  1305.  
  1306. Gif_get_sym:
  1307.     mov  ecx,[compsize]
  1308.     push ecx
  1309.     xor  eax,eax
  1310. shift:
  1311.     ror  byte[esi],1
  1312.     rcr  eax,1
  1313.     dec  [bit_count]
  1314.     jnz  loop1
  1315.     inc  esi
  1316.     cmp  esi,[block_ofs]
  1317.     jb   noblock
  1318.     push eax
  1319.     xor  eax,eax
  1320.     lodsb
  1321.     test eax,eax
  1322.     jnz  nextbl
  1323.     mov  eax,[EOI]
  1324.     sub  esi,2
  1325.     add  esp,8
  1326.     jmp  exx
  1327. nextbl:
  1328.     add  eax,esi
  1329.     mov  [block_ofs],eax
  1330.     pop  eax
  1331. noblock:
  1332.     mov  [bit_count],8
  1333. loop1:
  1334.     loop shift
  1335.     pop  ecx
  1336.     rol  eax,cl
  1337. exx:
  1338.     xor  ecx,ecx
  1339.     ret
  1340.  
  1341. Gif_output:
  1342.     push esi eax edx
  1343.     mov  edx,[table_ptr]
  1344. next:
  1345.     push word[edx+eax*4]
  1346.     mov  ax,word[edx+eax*4+2]
  1347.     inc  ecx
  1348.     cmp  ax,_null
  1349.     jnz  next
  1350.     shl  ebx,16
  1351.     mov  bx,[esp]
  1352. loop2:
  1353.     pop  ax
  1354.  
  1355.     lea  esi,[eax+eax*2]
  1356.     add  esi,[Palette]
  1357.  
  1358.     if COLOR_ORDER eq MENUETOS
  1359.         mov  esi,[esi]
  1360.         bswap esi
  1361.         shr  esi,8
  1362.         mov  [edi],esi
  1363.         add  edi,3
  1364.     else
  1365.         movsw
  1366.         movsb
  1367.     end if
  1368.  
  1369.     loop loop2
  1370.     pop  edx eax esi
  1371.     ret
  1372.  
  1373.     globalColor dd 1
  1374.     img_count dd 1
  1375.     cur_info dd 1        ; image table pointer
  1376.     img_start dd 1
  1377.     codesize dd 1
  1378.     compsize dd 1
  1379.     bit_count dd 1
  1380.     CC dd 1
  1381.     EOI dd 1
  1382.     Palette dd 1
  1383.     block_ofs dd 1
  1384.     table_ptr dd 1
  1385.  
  1386. gifmacend:
  1387. }
  1388.  
  1389.