Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. uglobal
  3. align 4
  4. ReadGIF.globalColor dd ?
  5. ReadGIF.cur_info    dd ?    ; image table pointer
  6. ReadGIF.codesize    dd ?
  7. ReadGIF.compsize    dd ?
  8. ReadGIF.bit_count   dd ?
  9. ReadGIF.CC          dd ?
  10. ReadGIF.EOI         dd ?
  11. ReadGIF.Palette     dd ?
  12. ReadGIF.block_ofs   dd ?
  13. ReadGIF.gif_workarea    rb 16*1024
  14. endg
  15.  
  16. ; unpacks GIF image
  17. ReadGIF:
  18. ;   in:
  19. ; esi - pointer to GIF file in memory
  20. ; edi - pointer to output image list
  21. ;   out:
  22. ; eax=0 -> ok, eax=1 -> invalid signature
  23. ; eax>=8 -> unsupported image attributes
  24.     push esi edi
  25.     mov  [.cur_info],edi
  26.     xor  eax,eax
  27.     mov  [.globalColor],eax
  28.     inc  eax
  29.     cmp  dword[esi],'GIF8'
  30.     jne  .ex            ; signature
  31.     mov  ecx,[esi+0xa]
  32.     add  esi,0xd
  33.     mov  edi,esi
  34.     test cl,cl
  35.     jns  .nextblock
  36.     mov  [.globalColor],esi
  37.     call .Gif_skipmap
  38.   .nextblock:
  39.     cmp  byte[edi],0x21
  40.     jne  .noextblock
  41.     inc  edi
  42.     inc  edi
  43.   .block_skip:
  44.     movzx eax,byte[edi]
  45.     lea  edi,[edi+eax+1]
  46.     test eax,eax
  47.     jnz  .block_skip
  48.     jmp  .nextblock
  49.   .noextblock:
  50.     mov  al,8
  51.     cmp  byte[edi],0x2c    ; image beginning
  52.     jne  .ex
  53.     inc  edi
  54.     mov  esi,[.cur_info]
  55.     xchg esi,edi
  56.     movzx eax,word[esi+4]
  57.     stosd
  58.     movzx eax,word[esi+6]
  59.     stosd
  60.     add   esi,8
  61.     push edi
  62.     mov  ecx,[esi]
  63.     inc  esi
  64.     test cl,cl
  65.     js   .uselocal
  66.     push [.globalColor]
  67.     mov  edi,esi
  68.     jmp  .setPal
  69.   .uselocal:
  70.     call .Gif_skipmap
  71.     push esi
  72.   .setPal:
  73.     movzx ecx,byte[edi]
  74.     inc  ecx
  75.     mov  [.codesize],ecx
  76.     dec  ecx
  77.     pop  [.Palette]
  78.     lea  esi,[edi+1]
  79.     mov  edi,.gif_workarea
  80.     xor  eax,eax
  81.     lodsb               ; eax - block_count
  82.     add  eax,esi
  83.     mov  [.block_ofs],eax
  84.     mov  [.bit_count],8
  85.     mov  eax,1
  86.     shl  eax,cl
  87.     mov  [.CC],eax
  88.     mov  ecx,eax
  89.     inc  eax
  90.     mov  [.EOI],eax
  91.     mov  eax, 1000h shl 16
  92.   .filltable:
  93.     stosd
  94.     inc  eax
  95.     loop .filltable
  96.     pop  edi
  97.   .reinit:
  98.     mov  edx,[.EOI]
  99.     inc  edx
  100.     push [.codesize]
  101.     pop  [.compsize]
  102.     call .Gif_get_sym
  103.     cmp  eax,[.CC]
  104.     je   .reinit
  105.     call .Gif_output
  106.   .cycle:
  107.     movzx ebx,ax
  108.     call .Gif_get_sym
  109.     cmp  eax,edx
  110.     jae  .notintable
  111.     cmp  eax,[.CC]
  112.     je   .reinit
  113.     cmp  eax,[.EOI]
  114.     je   .end
  115.     call .Gif_output
  116.   .add:
  117.     mov  dword [.gif_workarea+edx*4],ebx
  118.     cmp  edx,0xFFF
  119.     jae  .cycle
  120.     inc  edx
  121.     bsr  ebx,edx
  122.     cmp  ebx,[.compsize]
  123.     jne  .noinc
  124.     inc  [.compsize]
  125.   .noinc:
  126.     jmp  .cycle
  127.   .notintable:
  128.     push eax
  129.     mov  eax,ebx
  130.     call .Gif_output
  131.     push ebx
  132.     movzx eax,bx
  133.     call .Gif_output
  134.     pop  ebx eax
  135.     jmp  .add
  136.   .end:
  137.     xor  eax,eax
  138.   .ex:
  139.     pop  edi esi
  140.     ret
  141.  
  142. .Gif_skipmap:
  143. ; in: ecx - image descriptor, esi - pointer to colormap
  144. ; out: edi - pointer to area after colormap
  145.     and  ecx,111b
  146.     inc  ecx            ; color map size
  147.     mov  ebx,1
  148.     shl  ebx,cl
  149.     lea  ebx,[ebx*2+ebx]
  150.     lea  edi,[esi+ebx]
  151.     ret
  152.  
  153. .Gif_get_sym:
  154.     mov  ecx,[.compsize]
  155.     push ecx
  156.     xor  eax,eax
  157.   .shift:
  158.     ror  byte[esi],1
  159.     rcr  eax,1
  160.     dec  [.bit_count]
  161.     jnz  .loop1
  162.     inc  esi
  163.     cmp  esi,[.block_ofs]
  164.     jb   .noblock
  165.     push eax
  166.     xor  eax,eax
  167.     lodsb
  168.     test eax,eax
  169.     jnz  .nextbl
  170.     mov  eax,[.EOI]
  171.     sub  esi,2
  172.     add  esp,8
  173.     jmp  .exx
  174.   .nextbl:
  175.     add  eax,esi
  176.     mov  [.block_ofs],eax
  177.     pop  eax
  178.   .noblock:
  179.     mov  [.bit_count],8
  180.   .loop1:
  181.     loop .shift
  182.     pop  ecx
  183.     rol  eax,cl
  184.   .exx:
  185.     xor  ecx,ecx
  186.     ret
  187.  
  188. .Gif_output:
  189.     push esi eax edx
  190.     mov  edx,.gif_workarea
  191.   .next:
  192.     push word[edx+eax*4]
  193.     mov  ax,word[edx+eax*4+2]
  194.     inc  ecx
  195.     cmp  ax,1000h
  196.     jnz  .next
  197.     shl  ebx,16
  198.     mov  bx,[esp]
  199.   .loop2:
  200.     pop  ax
  201.     lea  esi,[eax+eax*2]
  202.     add  esi,[.Palette]
  203.     mov  esi,[esi]
  204.     bswap esi
  205.     shr  esi,8
  206.     mov  [edi],esi
  207.     add  edi,3
  208.     loop .loop2
  209.     pop  edx eax esi
  210.     ret
  211.