Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. COLOR_ORDER equ MENUETOS
  2. gif_hash_offset = gif_hash_area
  3.  
  4. macro gif2img gifsrc,imgsrc
  5. {
  6. local hasharea, ReadGIF, nextblock,_null
  7. local globalColor, img_count, cur_info, img_start
  8. local codesize, compsize, bit_count, CC, EOI, Palette
  9. local block_ofs, table_ptr, gifmacend
  10. local no_gc, block_skip, no_comm, noextblock, uselocal
  11. local setPal, filltable, reinit, cycle, zadd, noinc
  12. local notintable, er, zend, nxt, continue, ex, Gif_skipmap
  13. local Gif_get_sym, shift, nextbl, noblock, loop1, exx
  14. local Gif_output, next, loop2
  15.  
  16. _null fix 0x1000 ; 0x1000
  17.  
  18. if ~gifsrc eq esi
  19.     mov  esi,gifsrc
  20. end if
  21. if ~imgsrc eq edi
  22.     mov  edi,imgsrc
  23. end if
  24.  
  25.     if defined gif_hash_offset
  26.     mov  eax,gif_hash_offset
  27.     else
  28.     mov  eax,hasharea
  29.     end if
  30.  
  31.     call ReadGIF
  32.     jmp  gifmacend
  33.  
  34.     if defined gif_hash_offset
  35.     else
  36.     hasharea:
  37.     times 4096 dd 0 ;4096
  38.     end if
  39.  
  40. ReadGIF:
  41.     push esi edi
  42.     mov  [table_ptr],eax
  43.     mov  [cur_info],edi
  44.     xor  eax,eax
  45.     mov  [globalColor],eax
  46.     mov  [img_count],eax
  47.     inc  eax
  48.     cmp  dword[esi],'GIF8'
  49.     jne  er            ; signature
  50.     mov  ecx,[esi+0xa]
  51.     inc  eax
  52.     add  esi,0xd
  53.     mov  edi,esi
  54.     bt   ecx,7
  55.     jnc  nextblock
  56.     mov  [globalColor],esi
  57.     call Gif_skipmap
  58. nextblock:
  59.     cmp  byte[edi],0x21
  60.     jne  noextblock
  61.     inc  edi
  62.     cmp  byte[edi],0xf9 ; Graphic Control Ext
  63.     jne  no_gc
  64.     add  edi,7
  65.     jmp  nextblock
  66. no_gc:
  67.     cmp  byte[edi],0xfe ; Comment Ext
  68.     jne  no_comm
  69.     inc  edi
  70. block_skip:
  71.     movzx eax,byte[edi]
  72.     lea  edi,[edi+eax+1]
  73.     cmp  byte[edi],0
  74.     jnz  block_skip
  75.     inc  edi
  76.     jmp  nextblock
  77. no_comm:
  78.     cmp  byte[edi],0xff ; Application Ext
  79.     jne  nextblock
  80.     add  edi,13
  81.     jmp  block_skip
  82. noextblock:
  83.     cmp  byte[edi],0x2c    ; image beginning
  84.     jne  er
  85.     inc  [img_count]
  86.     inc  edi
  87.     mov  esi,[cur_info]
  88.     xchg esi,edi
  89. ;    movsd
  90. ;    movsd
  91.  
  92.     mov   bp,word[esi+4]
  93.     movzx ebx,bp
  94.     mov   [edi],ebx
  95.  
  96.     mov   bp,word[esi+6]
  97.     movzx ebx,bp
  98.     mov   [edi+4],ebx
  99.  
  100.     add edi,8
  101.     add esi,8
  102.  
  103.     push edi
  104.     movzx ecx,word[esi]
  105.     inc  esi
  106.     bt   ecx,7
  107.     jc   uselocal
  108.     push [globalColor]
  109.     mov  edi,esi
  110.     jmp  setPal
  111. uselocal:
  112.     call Gif_skipmap
  113.     push esi
  114. setPal:
  115.     movzx ecx,byte[edi]
  116.     inc  ecx
  117.     mov  [codesize],ecx
  118.     dec  ecx
  119.     pop  [Palette]
  120.     lea  esi,[edi+1]
  121.     mov  edi,[table_ptr]
  122.     xor  eax,eax
  123.     cld
  124.     lodsb               ; eax - block_count
  125.     add  eax,esi
  126.     mov  [block_ofs],eax
  127.     mov  [bit_count],8
  128.     mov  eax,1
  129.     shl  eax,cl
  130.     mov  [CC],eax
  131.     inc  eax
  132.     mov  [EOI],eax
  133.     lea  ecx,[eax-1]
  134.     mov  eax, _null shl 16
  135. filltable:
  136.     stosd
  137.     inc  eax
  138.     loop filltable
  139.     pop  edi
  140.     mov  [img_start],edi
  141. reinit:
  142.     mov  edx,[EOI]
  143.     inc  edx
  144.     push [codesize]
  145.     pop  [compsize]
  146.     call Gif_get_sym
  147.     cmp  eax,[CC]
  148.     je   reinit
  149.     call Gif_output
  150. cycle:
  151.     movzx ebx,ax
  152.     call Gif_get_sym
  153.     cmp  eax,edx
  154.     jae  notintable
  155.     cmp  eax,[CC]
  156.     je   reinit
  157.     cmp  eax,[EOI]
  158.     je   zend
  159.     call Gif_output
  160. zadd:
  161.     push eax
  162.     mov  eax,[table_ptr]
  163.     mov  [eax+edx*4],ebx
  164.     pop  eax
  165.     cmp  edx,0xFFF
  166.     jae  cycle
  167.     inc  edx
  168.     bsr  ebx,edx
  169.     cmp  ebx,[compsize]
  170.     jne  noinc
  171.     inc  [compsize]
  172. noinc:
  173.     jmp  cycle
  174. notintable:
  175.     push eax
  176.     mov  eax,ebx
  177.     call Gif_output
  178.     push ebx
  179.     movzx eax,bx
  180.     call Gif_output
  181.     pop  ebx eax
  182.     jmp  zadd
  183. er:
  184.     pop  edi
  185.     jmp  ex
  186. zend:
  187. ;    mov  eax,[.cur_info]    ; skip offset to next frame
  188. ;    mov  [eax],edi
  189.     mov  [cur_info],edi
  190.     add  esi,2
  191.     xchg esi,edi
  192. nxt:
  193.     cmp  byte[edi],0
  194.     jnz  continue
  195.     inc  edi
  196.     jmp  nxt
  197. continue:
  198. ;    cmp  byte[edi],0x3b    ;read next frame
  199. ;    jne  nextblock
  200.     xor  eax,eax
  201.     stosd
  202.     mov  ecx,[img_count]
  203. ex:
  204.     pop  edi esi
  205.     ret
  206.  
  207. Gif_skipmap:
  208. ; in: ecx - image descriptor, esi - pointer to colormap
  209. ; out: edi - pointer to area after colormap
  210.  
  211.     and  ecx,111b
  212.     inc  ecx            ; color map size
  213.     mov  ebx,1
  214.     shl  ebx,cl
  215.     lea  ebx,[ebx*2+ebx]
  216.     lea  edi,[esi+ebx]
  217.     ret
  218.  
  219. Gif_get_sym:
  220.     mov  ecx,[compsize]
  221.     push ecx
  222.     xor  eax,eax
  223. shift:
  224.     ror  byte[esi],1
  225.     rcr  eax,1
  226.     dec  [bit_count]
  227.     jnz  loop1
  228.     inc  esi
  229.     cmp  esi,[block_ofs]
  230.     jb   noblock
  231.     push eax
  232.     xor  eax,eax
  233.     lodsb
  234.     test eax,eax
  235.     jnz  nextbl
  236.     mov  eax,[EOI]
  237.     sub  esi,2
  238.     add  esp,8
  239.     jmp  exx
  240. nextbl:
  241.     add  eax,esi
  242.     mov  [block_ofs],eax
  243.     pop  eax
  244. noblock:
  245.     mov  [bit_count],8
  246. loop1:
  247.     loop shift
  248.     pop  ecx
  249.     rol  eax,cl
  250. exx:
  251.     xor  ecx,ecx
  252.     ret
  253.  
  254. Gif_output:
  255.     push esi eax edx
  256.     mov  edx,[table_ptr]
  257. next:
  258.     push word[edx+eax*4]
  259.     mov  ax,word[edx+eax*4+2]
  260.     inc  ecx
  261.     cmp  ax,_null
  262.     jnz  next
  263.     shl  ebx,16
  264.     mov  bx,[esp]
  265. loop2:
  266.     pop  ax
  267.  
  268.     lea  esi,[eax+eax*2]
  269.     add  esi,[Palette]
  270.  
  271.     if COLOR_ORDER eq MENUETOS
  272.         mov  esi,[esi]
  273.         bswap esi
  274.         shr  esi,8
  275.         mov  [edi],esi
  276.         add  edi,3
  277.     else
  278.         movsw
  279.         movsb
  280.     end if
  281.  
  282.     loop loop2
  283.     pop  edx eax esi
  284.     ret
  285.  
  286.     globalColor dd 1
  287.     img_count dd 1
  288.     cur_info dd 1        ; image table pointer
  289.     img_start dd 1
  290.     codesize dd 1
  291.     compsize dd 1
  292.     bit_count dd 1
  293.     CC dd 1
  294.     EOI dd 1
  295.     Palette dd 1
  296.     block_ofs dd 1
  297.     table_ptr dd 1
  298.  
  299. gifmacend:
  300. }
  301.  
  302.