Subversion Repositories Kolibri OS

Rev

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

  1. ;405 412 586
  2. ;
  3. ;
  4. bufer_size=1024*16+2
  5. fichero=4
  6. mcu_ptr=8
  7. color_ptr=12
  8. estado=16
  9. color_c=17
  10. nbits=color_c
  11. idct=20
  12. tmp_bits=24
  13. actable=28
  14. matriz_limit=32
  15. sourcebits=36
  16. sourcebits_index=40
  17. sourcebits_limit=44
  18. qt_ptrs=48
  19. ht_dc_ptrs=64
  20. ht_ac_ptrs=80
  21. matrices=96
  22. tmp_bufer=100
  23. x_org=104
  24. y_org=108
  25. x_mcu=112
  26. y_mcu=116
  27. x_size=120
  28. y_size=124
  29. x_org2=128
  30. y_org2=132
  31. x_mcu2=136
  32. y_mcu2=140
  33. x_size2=144
  34. y_size2=148
  35. q_ptr=152
  36. dc=164
  37. position=204
  38. draw_ptr=208
  39. struct_size=212
  40.  
  41. jpeg_info:  ;fichero en eax
  42.             ;retorna ebp
  43.         xor ebp,ebp
  44.         pushad
  45.         mov ebp,esp
  46.         mov ecx,6
  47.         sub esp,ecx
  48.         mov edi,esp
  49.         call read
  50.         pop dx
  51.         cmp dx,0d8ffh
  52.         je .l1
  53.         mov esp,ebp
  54.         popad
  55.         ret
  56.    .l1: push eax
  57.         mov ecx,struct_size
  58.         call mallocz
  59.         mov [edi],ebp
  60.         mov ebp,edi
  61.         pop dword [ebp+fichero]
  62.         pop ax
  63.         pop cx
  64.         jmp .l3
  65.    .l2: mov ebx,[ebp+tmp_bufer]
  66.         add ebx,[ebx-4]
  67.         mov cx,[ebx-2]
  68.         mov ax,[ebx-4]
  69.    .l3: push .l2
  70.         xchg cl,ch
  71.         add cx,2
  72.         cmp ch,3
  73.         jnc .l4
  74.         cmp al,0ffh
  75.         jne eoi
  76.         cmp ah,0dbh
  77.         je dqt
  78.         cmp ah,0c4h
  79.         je dht
  80.         cmp ah,0c0h
  81.         je sof0
  82.         cmp ah,0dah
  83.         je sos
  84.         cmp ah,0c2h
  85.         je eoi
  86.         cmp ah,0c9h
  87.         je eoi
  88.         cmp ah,0d9h
  89.         je eoi
  90.    .l4: lea edx,[ecx-4]
  91.         xor ecx,ecx
  92.         mov eax,[ebp+fichero]
  93.         call skip
  94.         mov ecx,4
  95.         call READ
  96.         cmp ecx,[edi-4]
  97.         jne eoi
  98.         ret
  99.  
  100. eoi:
  101.       mov esp,[ebp]
  102.       call jpeg_close
  103.       popad
  104.       xor ebp,ebp
  105.       ret
  106.  
  107. jpeg_close:
  108.       test ebp,ebp
  109.       jz .l2
  110.       pushad
  111.       mov eax,[ebp+fichero]
  112.       call close
  113.       mov edi,[ebp+sourcebits]
  114.       call free
  115.       lea esi,[ebp+qt_ptrs]
  116.       mov ecx,14
  117.  .l1: mov edi,[esi]
  118.       add esi,4
  119.       call free
  120.       loop .l1
  121.       mov edi,ebp
  122.       call free
  123.       popad
  124.  .l2: ret
  125.  
  126. dqt:  call READ
  127.       mov esi,edi
  128.       lea eax,[edi+ecx]
  129.       push eax
  130.  .l1: xor eax,eax
  131.       lodsb
  132.       cmp al,4
  133.       jnc eoi
  134.       lea ebx,[ebp+qt_ptrs+eax*4]
  135.       test dword [ebx],-1
  136.       jnz eoi
  137.       mov ecx,64
  138.       xor eax,eax
  139.       sub esp,128
  140.       mov edi,esp
  141.  .l2: lodsb
  142.       stosw
  143.       loop .l2
  144.       mov ecx,256
  145.       call malloc
  146.       mov [ebx],edi
  147.       mov eax,esi
  148.       mov esi,esp
  149.       pushad
  150.       mov ebp,zigzag
  151.       fninit
  152.       mov cl,64
  153.       xor eax,eax
  154.   .l3: fild word[esi]
  155.       mov al,[ebp]
  156.       and al,-2
  157.       add ebp,2
  158.       add esi,2
  159.       mov ebx,eax
  160.       and ebx,28
  161.       fmul dword [ebx+k2]
  162.       mov ebx,eax
  163.       shr ebx,3
  164.       and ebx,4+8+16
  165.       fmul dword [ebx+k2]
  166.       fstp dword [edi+eax]
  167.       dec cl
  168.       jnz .l3
  169.       popad
  170.       mov esi,eax
  171.       add esp,128
  172.       mov eax,[esp]
  173.       sub eax,esi
  174.       jc eoi
  175.       cmp eax,4
  176.       ja .l1
  177.       jne eoi
  178.       pop eax
  179.       ret
  180.  
  181. sof0:  call READ
  182.        cmp byte [edi],8
  183.        jne eoi  ;precision
  184.        mov ax,[edi+1]
  185.        xchg al,ah
  186.        mov [ebp+y_size],ax
  187.        mov ax,[edi+3]
  188.        xchg al,ah
  189.        mov [ebp+x_size],ax
  190.        mov al,[edi+5] ;ncomponentes
  191.        mov cl,al
  192.        mov [ebp+color_c],al
  193.        mov edx,modes
  194.        dec al
  195.        jz .l1
  196.        dec al
  197.        dec al
  198.        jnz eoi
  199.        mov al,[edi+10]
  200.        mov ah,[edi+13]
  201.        cmp ax,1111h
  202.        jne eoi
  203.        mov al,[edi+7]
  204.        add edx,16
  205.        cmp al,11h
  206.        je .l1
  207.        add edx,16
  208.        cmp al,21h
  209.        je .l1
  210.        add edx,16
  211.        cmp al,22h
  212.        jne eoi
  213.   .l1: lea ebx,[ebp+q_ptr]
  214.        lea esi,[ebp+qt_ptrs]
  215.        mov [ebp+mcu_ptr],edx
  216.   .l2: movzx eax,byte [edi+8]
  217.        add edi,3
  218.        cmp al,4
  219.        jnc eoi
  220.        lea eax,[eax*4+esi]
  221.        mov [ebx],eax
  222.        add ebx,16
  223.        dec cl
  224.        jnz .l2
  225.        ret
  226.  
  227. READ:  mov eax,[ebp+fichero]
  228.        mov edi,[ebp+tmp_bufer]
  229.        movzx ecx,cx
  230.        call mresize
  231.        mov [ebp+tmp_bufer],edi
  232.        jmp read
  233.  
  234. dht:    call READ
  235.         mov esi,edi
  236.         lea eax,[edi+ecx]
  237.         push eax
  238.    .l1: lodsb
  239.         mov edi,esi
  240.         mov ebx,3+16
  241.         and bl,al
  242.         cmp bl,al
  243.         jne eoi
  244.         shr bl,2
  245.         and al,3
  246.         or bl,al
  247.         lea ebx,[ebp+ht_dc_ptrs+ebx*4]
  248.         test dword [ebx],-1
  249.         jnz eoi
  250.         mov cl,15
  251.         mov al,[edi]
  252.    .l2: inc edi  ;calcular numero de codigos
  253.         add al,[edi]
  254.         jc eoi
  255.         dec cl
  256.         jnz .l2
  257.         movzx ecx,al
  258.         lea ecx,[ecx*4+2]
  259.         call malloc
  260.         mov [ebx],edi
  261.         call arbol_hf
  262.         mov eax,[esp]
  263.         sub eax,ebx
  264.         jc eoi
  265.         mov esi,ebx
  266.         cmp eax,4
  267.         ja .l1
  268.         jne eoi
  269.         pop eax
  270.         ret
  271.  
  272. arbol_hf:   ;esi=ht edi=memoria para el arbol
  273.             ;retorna en ebx  el final de ht
  274.             ;codigos: bits 0-3=nbits del siguiente numero
  275.             ;         bits 4-7=numero de zeros
  276.             ;         bits 8-14=longitud de este codigo o error si =127
  277.             ;         bit 15=codigo/puntero
  278.         push ebp
  279.         lea ebx,[edi-2]
  280.         add ebx,[ebx-2]
  281.         mov word [ebx],-1 ;codigo de error si encontrado
  282.         push ebx
  283.         push esi
  284.         lea ebx,[esi+16]
  285.         mov ebp,esp
  286.         xor ecx,ecx
  287.         push edi
  288.         push ecx
  289.         add edi,2
  290.         mov dx,1
  291.         add dh,[esi]
  292.         jz .l3
  293.         jmp .l2
  294.   .l1:  push edi
  295.         push ecx
  296.         add edi,2
  297.   .l2:  inc cl
  298.         cmp cl,dl
  299.         jc .l1
  300.         mov al,[ebx]
  301.         inc ebx
  302.         mov ah,128 ;marca de codigo
  303.         or ah,dl
  304.         cmp edi,[ebp+4]
  305.         jnc .l5
  306.         stosw
  307.         cmp esp,ebp
  308.         jnc .l5
  309.         pop ecx
  310.         pop esi
  311.         lea eax,[edi-2]
  312.         sub eax,esi
  313.         mov [esi],ax
  314.         dec dh
  315.         jnz .l2 ;ncodigos
  316.         mov esi,[ebp]
  317.    .l3: inc esi
  318.         inc dl
  319.         cmp dl,17
  320.         jnc .l4
  321.         add dh,[esi]
  322.         jz .l3
  323.         mov [ebp],esi
  324.         jmp .l2
  325.    .l4: lea esp,[ebp+8]
  326.         pop ebp
  327.         ret
  328.    .l5: mov ebp,[ebp+8]
  329.         jmp eoi
  330.  
  331. sos:   sub ecx,4  ;a continuacion vienen los datos de la imagen
  332.        call READ
  333.        mov eax,[ebp+fichero]
  334.        call ftell
  335.        mov [ebp+position],edx
  336.        mov esi,edi
  337.        lea edi,[ebp+q_ptr]
  338.        lodsb ;numero de componentes
  339.        sub [ebp+color_c],al
  340.        jnz eoi
  341.        mov dh,al
  342.   .l1: mov ebx,[edi]
  343.        mov eax,[ebx]
  344.        stosd
  345.        lodsw
  346.        mov cl,ah
  347.        and eax,0f00h
  348.        and ecx,0f0h
  349.        shr eax,6
  350.        shr ecx,2
  351.        lea ebx,[ebp+ht_ac_ptrs+eax]
  352.        mov eax,[ebx]
  353.        lea ebx,[ebp+ht_dc_ptrs+ecx]
  354.        mov ecx,[ebx]
  355.        test eax,eax
  356.        jz eoi
  357.        test ecx,ecx
  358.        jz eoi
  359.        stosd
  360.        mov eax,ecx
  361.        stosd
  362.        add edi,4
  363.        dec dh
  364.        jnz .l1
  365.        mov edx,[ebp+mcu_ptr]
  366.        cmp edx,modes
  367.        jne .l2
  368.        lea esi,[ebp+q_ptr]
  369.        lea edi,[ebp+q_ptr+32]
  370.        movsd
  371.        movsd
  372.        movsd
  373.    .l2:
  374.        mov esi,edx
  375.        push dword [esi]
  376.        pop dword [ebp+mcu_ptr]
  377.        push dword [esi+4]
  378.        pop dword[ebp+color_ptr]
  379.        push dword [esi+12]
  380.        pop dword [ebp+y_mcu]
  381.        push dword [esi+8]
  382.        pop dword [ebp+x_mcu]
  383.        mov ecx,64*18
  384.        call malloc
  385.        mov [ebp+matrices],edi
  386.        mov ecx,bufer_size
  387.        call malloc
  388.        mov [ebp+sourcebits],edi
  389.        mov esp,[ebp]
  390.        mov [esp+8],ebp
  391.        popad
  392.        ret
  393.  
  394. jpeg_display:
  395.        test ebp,ebp
  396.        jnz .inicio
  397.        ret
  398.       .inicio:
  399.        pushad
  400.        mov [ebp],esp
  401.        mov eax,[ebp+fichero]
  402.        mov edx,[ebp+position]
  403.        call lseek
  404.        mov edi,[ebp+sourcebits]
  405.        add edi,bufer_size
  406.        mov [ebp+sourcebits_index],edi
  407.        sub edi,2
  408.        mov [ebp+sourcebits_limit],edi
  409.        mov edi,[ebp+matrices]
  410.        mov [ebp+matriz_limit],edi
  411.        xor eax,eax
  412.        mov [esp+8],eax
  413.        mov [ebp+estado],eax
  414.        mov [ebp+tmp_bits],eax
  415.        mov [ebp+dc],eax
  416.        mov [ebp+dc+16],eax
  417.        mov [ebp+dc+32],eax
  418.  
  419.        mov eax,[ebp+y_mcu]
  420.        mov ecx,[ebp+y_org]
  421.        sub ecx,eax
  422.        mov [ebp+y_org2],ecx
  423.        mov [ebp+y_mcu2],eax
  424.        push dword [ebp+y_size]
  425.        pop dword [ebp+y_size2]
  426.   .l3: push dword [ebp+x_org]
  427.        pop dword [ebp+x_org2]
  428.        push dword [ebp+x_mcu]
  429.        pop dword [ebp+x_mcu2]
  430.        push dword [ebp+x_size]
  431.        pop dword [ebp+x_size2]
  432.        mov eax,[ebp+y_mcu2]
  433.        add [ebp+y_org2],eax
  434.        sub [ebp+y_size2],eax
  435.        jnc .l4
  436.        add eax,[ebp+y_size2]
  437.        jnz .cont
  438.        mov [esp+8],ebp
  439.        popad
  440.        ret
  441.      .cont:
  442.        mov dword [ebp+y_size2],0
  443.        mov [ebp+y_mcu2],eax
  444.       .l4:
  445.         mov eax,[ebp+x_mcu2]
  446.         sub [ebp+x_size2],eax
  447.         jnc .l5
  448.         add eax,[ebp+x_size2]
  449.         jz .l3
  450.         mov dword [ebp+x_size2],0
  451.         mov [ebp+x_mcu2],eax
  452.         call dword [ebp+mcu_ptr]
  453.         mov eax,[ebp+x_mcu]
  454.         mov ecx,[ebp+x_mcu2]
  455.         mov edx,[ebp+y_mcu2]
  456.         call recortar
  457.         jmp .l6
  458.       .l5:
  459.         call dword [ebp+mcu_ptr]
  460.         mov ecx,[ebp+x_mcu2]
  461.         mov edx,[ebp+y_mcu2]
  462.       .l6:
  463.         mov eax,[ebp+x_org2]
  464.         mov ebx,[ebp+y_org2]
  465.         call dword [ebp+draw_ptr]
  466.         add [ebp+x_org2],ecx
  467.         mov ax,[ebp+estado]
  468.         test al,15
  469.         jz .l4
  470.         cmp ah,8
  471.         jnc .l4
  472.         xor edx,edx
  473.         mov [ebp+tmp_bits],edx
  474.         mov [ebp+dc],edx
  475.         mov [ebp+dc+16],edx
  476.         mov [ebp+dc+32],edx
  477.         add dword [ebp+sourcebits_index],2
  478.         and word [ebp+estado],0c0h
  479.         test al,32
  480.         jz .l4
  481.         jmp .l3
  482.  
  483. color100:
  484.         push edi
  485.     .l1: lodsw
  486.         mov dl,ah
  487.         mov ah,al
  488.         stosw
  489.         mov ah,dl
  490.         stosb
  491.         mov al,dl
  492.         stosb
  493.         stosw
  494.         dec cl
  495.         jnz .l1
  496.         pop edi
  497.         ret
  498.  
  499. color111:
  500.         push edi
  501.    .l1: lodsw
  502.         mov bx,[esi+62]
  503.         mov dx,[esi+126]
  504.         xchg ah,bh
  505.         xchg ah,dl
  506.         xchg ah,bl
  507.         stosw
  508.         mov ax,bx
  509.         stosw
  510.         mov ax,dx
  511.         stosw
  512.         dec cl
  513.         jnz .l1
  514.         pop edi
  515.         mov ecx,64*3
  516.         jmp ybr_bgr
  517.  
  518. color411:
  519.         push ebp
  520.         push edi
  521.         lea ebp,[esi+ecx*8]
  522.      .l1: push ecx
  523.         mov ax,[esi]
  524.         mov cx,[ebp]
  525.         mov dx,[ebp+64]
  526.         add ebp,2
  527.         xchg ch,dl
  528.         mov bx,ax
  529.         mov ah,cl
  530.         mov bl,ch
  531.         mov [edi],ax
  532.         mov [edi+2],bx
  533.         mov [edi+4],cx
  534.         mov ax,[esi+8]
  535.         mov bh,ah
  536.         mov ah,cl
  537.         mov [edi+48],ax
  538.         mov [edi+48+2],bx
  539.         mov [edi+48+4],cx
  540.         mov ax,[esi+2]
  541.         mov bx,ax
  542.         mov ah,dl
  543.         mov bl,dh
  544.         mov [edi+6],ax
  545.         mov [edi+2+6],bx
  546.         mov [edi+4+6],dx
  547.         mov ax,[esi+8+2]
  548.         mov bh,ah
  549.         mov ah,dl
  550.         mov [edi+48+6],ax
  551.         mov [edi+48+2+6],bx
  552.         mov [edi+48+4+6],dx
  553.         pop ecx
  554.         add edi,12
  555.         dec ecx
  556.         add esi,4
  557.         test cl,1
  558.         jnz .l1
  559.         add esi,64-8
  560.         test cl,2
  561.         jnz .l1
  562.         sub esi,128-16
  563.         add edi,48
  564.         test cl,15
  565.         jnz .l1
  566.         add esi,64
  567.         test cl,cl
  568.         jnz .l1
  569.         pop edi
  570.         pop ebp
  571.         mov ecx,64*4*3
  572.         jmp ybr_bgr
  573.  
  574. color211:
  575.         push ebp
  576.         push edi
  577.         lea ebp,[esi+ecx*4]
  578.     .l1: push ecx
  579.         mov ax,[esi]
  580.         mov cx,[ebp]
  581.         mov dx,[ebp+64]
  582.         add ebp,2
  583.         xchg ch,dl
  584.         mov bx,ax
  585.         mov ah,cl
  586.         mov bl,ch
  587.         mov [edi],ax
  588.         mov [edi+2],bx
  589.         mov [edi+4],cx
  590.         mov ax,[esi+2]
  591.         mov bx,ax
  592.         mov ah,dl
  593.         mov bl,dh
  594.         mov [edi+6],ax
  595.         mov [edi+2+6],bx
  596.         mov [edi+4+6],dx
  597.         pop ecx
  598.         add edi,12
  599.         dec cl
  600.         add esi,4
  601.         test cl,1
  602.         jnz .l1
  603.         add esi,64-8
  604.         test cl,2
  605.         jnz .l1
  606.         sub esi,128-8
  607.         test cl,cl
  608.         jnz .l1
  609.         pop edi
  610.         pop ebp
  611.         mov ecx,64*3*2
  612.         jmp ybr_bgr
  613.  
  614.  
  615. mcu411: lea ebx,[ebp+q_ptr]
  616.         call hufdecode
  617.         lea ebx,[ebp+q_ptr]
  618.         call hufdecode
  619. mcu211: lea ebx,[ebp+q_ptr]
  620.         call hufdecode
  621. mcu111: lea ebx,[ebp+q_ptr]
  622.         call hufdecode
  623.         lea ebx,[ebp+q_ptr+16]
  624.         call hufdecode
  625. mcu100: lea ebx,[ebp+q_ptr+32]
  626.         call hufdecode
  627.         mov esi,[ebp+matrices]
  628.         mov dword [ebp+matriz_limit],esi
  629.         mov ecx,32
  630.         lea edi,[esi+64*6]
  631.         jmp dword [ebp+color_ptr]
  632.  
  633. cargar_bits: ;edx=bits,cl=nbits,
  634.              ;bp=data struct
  635.              ;cr: cl,edx,eax,si
  636.              ;ncr bx,bp,di,ch
  637.  
  638.         mov esi,[ebp+sourcebits_index]
  639.         cmp esi,[ebp+sourcebits_limit]
  640.         jnc .l6
  641.         movzx eax,byte [esi]
  642.         inc esi
  643.         add cl,8
  644.         cmp al,-1
  645.         je .l2
  646.         mov ah,al
  647.         lodsb
  648.         add cl,8
  649.         cmp al,-1
  650.         je .l2
  651.    .l1: ror eax,cl
  652.         or edx,eax
  653.         mov [ebp+sourcebits_index],esi
  654.         ret
  655.    .l2: lodsb
  656.         test al,al
  657.         jnz .l3
  658.         mov al,-1
  659.         call .l1
  660.         cmp cl,16
  661.         jc cargar_bits
  662.         ret
  663.    .l3: sub esi,2
  664.         sub cl,8
  665.         sub al,0d0h
  666.         cmp al,8
  667.         jc .l4
  668.         sub al,9
  669.         mov al,63
  670.         jz .l4
  671.         mov al,127
  672.     .l4: inc al
  673.         or [ebp+estado],al
  674.         movzx eax,ah
  675.         jmp .l1
  676.     .l5: mov [ebp+sourcebits_limit],edi
  677.         mov word [edi],0d9ffh
  678.         popad
  679.         jmp cargar_bits
  680.    .l6: ;read file
  681.         pushad
  682.         mov ecx,bufer_size-2
  683.         mov edx,[ebp+sourcebits_limit]
  684.         mov edi,[ebp+sourcebits]
  685.         mov ax,[edx]
  686.         sub edx,edi
  687.         stosw
  688.         sub esi,edx
  689.         mov [ebp+sourcebits_index],esi
  690.         cmp edx,ecx
  691.         jne .l5
  692.         mov eax,[ebp+fichero]
  693.         call read
  694.         lea ecx,[edi+ecx-2]
  695.         mov [ebp+sourcebits_limit],ecx
  696.         popad
  697.         jmp cargar_bits
  698.  
  699.  
  700. hufdecode:  ;si->dctable [bp+20]->actable di->outbufer edx->bits cl->bits en edx
  701.  
  702.  
  703.             ;[bp+24]->sourcebits
  704.             ;[bp+22]=outbufer+128
  705.             ;[bx]       q ptr para aa&n
  706.             ;[bx+2]     a ptr
  707.             ;[bx+4]     d ptr
  708.             ;[bx+8]     dc componente
  709.         fninit
  710.         push dword [ebx]
  711.         mov cl,[ebp+nbits]
  712.         mov edx,[ebp+tmp_bits]
  713.         cmp cl,16
  714.         jnc .l1
  715.         call cargar_bits
  716.     .l1: mov eax,[ebx+4]
  717.         mov esi,[ebx+8]
  718.         mov [ebp+actable],eax
  719.         movzx eax,word [esi]
  720.         add esi,2
  721.    .l2: add edx,edx
  722.         jnc .l3
  723.         add esi,eax
  724.    .l3: lodsw
  725.         test ax,ax
  726.         jns .l2
  727.         ;codigo encontrado
  728.         and ax,7f0fh
  729.         mov edi,[ebp+matriz_limit] ;arrays
  730.         sub cl,ah
  731.         jns .l4
  732.         fldz
  733.    .error:
  734.         xor ecx,ecx
  735.         or byte [ebp+estado],32
  736.         jmp .l12
  737.    .l4: cmp cl,al
  738.         jnc .l5
  739.         push eax
  740.         call cargar_bits
  741.         pop eax
  742.    .l5: sub cl,al
  743.         mov ch,cl
  744.         mov cl,al
  745.         mov eax,edx
  746.         shl edx,cl
  747.         sar eax,17
  748.         xor ax,8000h
  749.         xor cl,15
  750.         sar ax,cl
  751.         mov cl,ch
  752.         mov ch,2
  753.         add ax,8000h ;incrementar si negativo
  754.         adc ax,8000h
  755.         add [ebx+12],ax
  756.         fild word [ebx+12]
  757.         push ecx
  758.         mov ecx,64
  759.         xor eax,eax
  760.         add [ebp+matriz_limit],ecx
  761.         rep stosd
  762.         pop ecx
  763.         sub edi,64*4
  764.         mov ebx,[esp]
  765.         fmul dword [ebx]
  766.     .l6: cmp cl,16
  767.         jnc .l7
  768.         call cargar_bits
  769.    .l7: mov esi,[ebp+actable]
  770.         movzx eax,word[esi]
  771.         add esi,2
  772.    .l8: add edx,edx
  773.         jnc .l9
  774.         add esi,eax
  775.    .l9: lodsw
  776.         test ax,ax
  777.         jns .l8
  778.         ;codigo encontrado
  779.         and ah,127
  780.         xor ebx,ebx
  781.         sub cl,ah
  782.         js .error
  783.         or bl,al
  784.         jz .l12
  785.         and al,0f0h
  786.         shr al,3
  787.         add ch,al
  788.         js .error
  789.         and bl,0fh
  790.         jz .l11
  791.         cmp cl,bl
  792.         jnc .l10
  793.         call cargar_bits
  794.     .l10: sub cl,bl
  795.         xchg bl,cl
  796.         mov eax,edx
  797.         shl edx,cl
  798.         sar eax,17
  799.         xor cl,15
  800.         xor ax,8000h
  801.         sar ax,cl
  802.         add ax,8000h ;incrementar si negativo
  803.         adc ax,8000h
  804.         mov cl,bl
  805.         mov bl,ch
  806.         mov [ebp+tmp_bits],ax
  807.         mov ax,[ebx+zigzag]
  808.         mov ebx,[esp]
  809.         fild word [ebp+tmp_bits]
  810.         or [ebp+idct],ax
  811.         and eax,11111100b
  812.         fmul dword [ebx+eax]
  813.         fstp dword [edi+eax]
  814.   .l11: add ch,2
  815.         jns .l6
  816.   .l12: mov [ebp+nbits],cl
  817.         mov [ebp+tmp_bits],edx
  818.         xor ebx,ebx
  819.         add esp,4
  820.         xchg ebx,[ebp+idct]
  821.         cmp ch,2
  822.         je idctf1
  823.         fstp dword [edi]
  824.         test bh,0feh
  825.         jnz idctf3
  826. idctf2a: test bh,1
  827.         mov esi,edi
  828.         jz .l1
  829.         test bl,1
  830.         jnz idctf3
  831.         push idctf2b
  832.         jmp idctf3b
  833.    .l1: call idctf3a
  834.         mov cl,4
  835.         call limit
  836.         mov eax,[edi-8]
  837.         mov edx,[edi-4]
  838.         mov cl,7
  839.    .l2: mov [edi],eax
  840.         mov [edi+4],edx
  841.         add edi,8
  842.         dec cl
  843.         jnz .l2
  844.         ret
  845.  
  846. idctf1: fistp word[edi+64]
  847.         mov ax,128
  848.         add ax,[edi+64]
  849.         jz .l2
  850.         test ah,ah
  851.         jz .l1
  852.         mov al,-1
  853.         js .l2
  854.    .l1: mov ah,al
  855.         stosw
  856.         stosw
  857.         mov eax,[edi-4]
  858.         mov ecx,15
  859.         rep stosd
  860.    .l2: ret
  861.  
  862. idctf3: mov bl,8
  863.         mov esi,edi
  864.     .l1: rcr bh,1
  865.         jc .l3
  866.         mov eax,[esi]
  867.         test eax,eax
  868.         jz .l4
  869.         mov cl,7
  870.     .l2: add esi,32
  871.         mov [esi],eax
  872.         dec cl
  873.         jnz .l2
  874.         sub esi,32*7-4
  875.         dec bl
  876.         jnz .l1
  877.         jmp .l5
  878.    .l3: call idctf3b
  879.    .l4: add esi,4
  880.         dec bl
  881.         jnz .l1
  882.    .l5: mov esi,edi
  883.         mov cl,8
  884.    .l6: call idctf3a
  885.         add esi,32
  886.         add edi,16
  887.         dec cl
  888.         jnz .l6
  889.         sub edi,128
  890.         mov esi,edi
  891.         mov cl,32
  892. limit:  mov dx,[esi]
  893.         mov bx,[esi+2]
  894.         add esi,4
  895.         add dx,128
  896.         add bx,128
  897.         test dh,dh
  898.         mov ax,dx
  899.         jz .l1
  900.         mov al,0
  901.         js .l1
  902.         mov al,-1
  903.    .l1: test bh,bh
  904.         mov ah,bl
  905.         jz .l2
  906.         mov ah,0
  907.         js .l2
  908.         mov ah,-1
  909.    .l2: stosw
  910.         dec cl
  911.         jnz limit
  912.         ret
  913.  
  914. idctf2b:
  915.         mov dl,8
  916.   .l1:  fld dword[esi]
  917.         add esi,32
  918.         mov ax,128
  919.         fistp word [edi]
  920.         add ax,[edi]
  921.         test ah,ah
  922.         jz .l2
  923.         mov al,0
  924.         js .l2
  925.         mov al,-1
  926.   .l2:  mov ah,al
  927.         stosw
  928.         stosw
  929.         stosw
  930.         stosw
  931.         dec dl
  932.         jnz .l1
  933.         ret
  934.  
  935. idctf3a: ;si(d float),di(w int) ncr
  936. fld dword[esi+1*4]      ;f1                ;t21=f1+f7
  937. fld st0
  938. fld dword[esi+7*4]          ;f7
  939. fadd st2,st0
  940. fsubp st1,st0          ;t22=f1-f7
  941. fld dword[esi+5*4]
  942. fld st0           ;f5       ;t23=f5+f3
  943. fld dword[esi+3*4]                   ;f3
  944. fadd st2,st0
  945. fsubp st1,st0          ;t20=f5-f3
  946. fld st0
  947. fadd st0,st3                ;t25=(t20+t22)*k2
  948. fmul dword[k+4]                 ;k2 ;t25,t20,t23,t22,t21
  949. fld st4                         ;t7=t21+t23
  950. fadd st0,st3                        ;t7,t25,t20,t23,t22,t21
  951. fld dword[k+12]                 ;k4     ;t6=k4*t20+t25-t7
  952. fmulp st3,st0
  953. fsub st2,st0
  954. fld st1
  955. faddp st3,st0                   ;t7,t25,t6,t23,t22,t21
  956. fld st5                         ;t5=(t21-t23)*k1-t6
  957. fsub st0,st4
  958. fmul dword[k]          ;k1
  959. fsub st0,st3
  960. fstp st6               ;t7,t25,t6,t23,t22,t5
  961. fstp st3                        ;t25,t6,t7,t22,t5
  962. fxch st3
  963. fmul dword[k+8]    ;k3      ;t4=k3*t22-t25+t5
  964. fadd st0,st4                        ;t22*k3+t5,t6,t7,t25,t5
  965. fsubrp st3,st0                  ;t6,t7,t4,t5
  966. fld dword[esi]                       ;f0           ;t10=f0+f4
  967. fst st5                         ;f0,t4,t5,t6,t7,f0
  968. fld dword[esi+4*4]                   ;f4
  969. fsub st6,st0                    ;t11=f0-f4
  970. faddp st1,st0
  971. fld st0               ;t10,t10,t6,t7,t4,t5,t11
  972. fld dword[esi+2*4]                   ;f2      ;t13=f2+f6
  973. fadd dword[esi+6*4]                  ;f6      ;t13,t10,t10,t6,t7,t4,t5,t11
  974. fadd st2,st0                    ;t13,t10,t0,t6,t7,t4,t5,t11 ;t0=t10+t13
  975. fsubp st1,st0                      ;t3,t0,t6,t7,t4,t5,t11 ;t3=t10-t13
  976. fld st0                         ;p3=t3-t4
  977. fsub st0,st5
  978. fistp word [edi+3*2]        ;p3
  979. fadd st0,st4                        ;p4=t3+t4
  980. fld dword[esi+2*4]                   ;f2
  981. fstp st5
  982. fistp word [edi+4*2]        ;p4 ;t0,t6,t7,f2,t5,t11
  983. fld st0                         ;p0=t0+t7
  984. fsub st0,st3
  985. fistp word [edi+7*2]        ;p7
  986. fadd st0,st2                        ;p7=t0-t7
  987. fistp word [edi]                     ;p0 ;t6,t7,f2,t5,t11
  988. fld st2                         ;f2  ;f2,t6,t7,f2,t5,t11  ;t12=(f2-f6)*k1-t13
  989. fld dword[esi+6*4]                   ;f6
  990. fadd st4,st0                    ;f6,f2,t6,t7,t13,t5,t11
  991. fsubp st1,st0
  992. fmul dword[k]         ;k1
  993. fsub st0,st3
  994. fst st3                ;t12,t6,t7,t12,t5,t11
  995. fadd st0,st5                        ;t1=t11+t12
  996. fst st2                         ;t1,t6,t1,t12,t5,t11
  997. fadd st0,st1                        ;p1=t1+t6
  998. fistp word [edi+2]                   ;p1    ;t6,t1,t12,t5,t11
  999. fsubp st1,st0                       ;p6=t1-t6
  1000. fistp word [edi+6*2]                 ;p6  ;t12,t5,t11
  1001. fsubp st2,st0                   ;t2=t11-t12  ;t5,t2
  1002. fld st0
  1003. fadd st0,st2                ;p2=t2+t5
  1004. fistp word [edi+2*2]                 ;p2
  1005. fsubp st1,st0                       ;p5=t2-t5   ;t5,t2
  1006. fistp word [edi+5*2]
  1007. ret             ;p5
  1008.  
  1009.  
  1010.  
  1011.  
  1012. idctf3b: ;si ncr
  1013. fld dword[esi+1*32]
  1014. fld st0          ;f1       ;t21=f1+f7
  1015. fld dword[esi+7*32]
  1016. fadd st2,st0     ;f7
  1017. fsubp st1,st0                       ;t22=f1-f7
  1018. fld dword[esi+5*32]
  1019. fld st0          ;f5       ;t23=f5+f3
  1020. fld dword[esi+3*32]                  ;f3
  1021. fadd st2,st0
  1022. fsubp st1,st0
  1023. fld st0  ;t20=f5-f3
  1024. fadd st0,st3                        ;t25=(t20+t22)*k2
  1025. fmul dword[k+4]                 ;k2 ;t25,t20,t23,t22,t21
  1026. fld st4                         ;t7=t21+t23
  1027. fadd st0,st3                        ;t7,t25,t20,t23,t22,t21
  1028. fld dword[k+12]                 ;k4     ;t6=k4*t20+t25-t7
  1029. fmulp st3,st0
  1030. fsub st2,st0
  1031. fld st1
  1032. faddp st3,st0                   ;t7,t25,t6,t23,t22,t21
  1033. fld st5                         ;t5=(t21-t23)*k1-t6
  1034. fsub st0,st4
  1035. fmul dword[k]          ;k1
  1036. fsub st0,st3
  1037. fstp st6               ;t7,t25,t6,t23,t22,t5
  1038. fstp st3
  1039. fxch st3               ;t25,t6,t7,t22,t5
  1040. fmul dword[k+8]                 ;k3      ;t4=k3*t22-t25+t5
  1041. fadd st0,st4                        ;t22*k3+t5,t6,t7,t25,t5
  1042. fsubrp st3,st0                  ;t6,t7,t4,t5
  1043. fld dword[esi]                       ;f0           ;t10=f0+f4
  1044. fst st5                         ;f0,t4,t5,t6,t7,f0
  1045. fld dword[esi+4*32]                  ;f4
  1046. fsub st6,st0                    ;t11=f0-f4
  1047. faddp st1,st0
  1048. fld st0               ;t10,t10,t6,t7,t4,t5,t11
  1049. fld dword[esi+2*32]                  ;f2      ;t13=f2+f6
  1050. fadd dword[esi+6*32]                 ;f6      ;t13,t10,t10,t6,t7,t4,t5,t11
  1051. fadd st2,st0                    ;t13,t10,t0,t6,t7,t4,t5,t11 ;t0=t10+t13
  1052. fsubp st1,st0                       ;t3,t0,t6,t7,t4,t5,t11 ;t3=t10-t13
  1053. fld st0                         ;p3=t3-t4
  1054. fsub st0,st5
  1055. fstp dword[esi+3*32]        ;p3
  1056. fadd st0,st4                        ;p4=t3+t4
  1057. fld dword[esi+2*32]                  ;f2
  1058. fstp st5
  1059. fstp dword[esi+4*32]        ;p4 ;t0,t6,t7,f2,t5,t11
  1060. fld st0
  1061. fsub st0,st3                ;p0=t0+t7
  1062. fstp dword[esi+7*32]                 ;p7
  1063. fadd st0,st2                        ;p7=t0-t7
  1064. fstp dword[esi]                      ;p0 ;t6,t7,f2,t5,t11
  1065. fld st2                         ;f2  ;f2,t6,t7,f2,t5,t11  ;t12=(f2-f6)*k1-t13
  1066. fld dword[esi+6*32]                  ;f6
  1067. fadd st4,st0                    ;f6,f2,t6,t7,t13,t5,t11
  1068. fsubp st1,st0
  1069. fmul dword[k]         ;k1
  1070. fsub st0,st3
  1071. fst st3                ;t12,t6,t7,t12,t5,t11
  1072. fadd st0,st5                        ;t1=t11+t12
  1073. fst st2                         ;t1,t6,t1,t12,t5,t11
  1074. fadd st0,st1                        ;p1=t1+t6
  1075. fstp dword[esi+1*32]                 ;p1    ;t6,t1,t12,t5,t11
  1076. fsubp st1,st0                       ;p6=t1-t6
  1077. fstp dword[esi+6*32]                 ;p6  ;t12,t5,t11
  1078. fsubp st2,st0
  1079. fld st0           ;t2=t11-t12  ;t5,t2
  1080. fadd st0,st2                        ;p2=t2+t5
  1081. fstp dword[esi+2*32]                 ;p2
  1082. fsubp st1,st0                       ;p5=t2-t5   ;t5,t2
  1083. fstp dword[esi+5*32]
  1084. ret             ;p5
  1085.  
  1086. ybr_bgr:  ;edi=bmp ecx=n_BYTES
  1087.           ;retorna edi+=ecx
  1088.         pushad
  1089.         mov esi,edi
  1090.         add edi,ecx
  1091.         push edi
  1092.         mov edi,[colortabla]
  1093.    .l1: lodsw
  1094.         movzx ebx,ah
  1095.         movzx ebp,al
  1096.         movzx eax,al
  1097.         movzx ecx,byte[esi]
  1098.         lea ebx,[ebx*4+edi+1024]
  1099.         lea ecx,[ecx*4+edi]
  1100.         add eax,[ebx] ;cb   ;solo se usan 16 bits
  1101.         mov edx,[ebx+2]     ;pero el codigo de 32 bits es mas rapido
  1102.         mov ebx,[ecx] ;cr
  1103.         add eax,[ecx+2]
  1104.         add ebx,ebp ;b
  1105.         add edx,ebp ;r
  1106.         test ah,ah
  1107.         jz .l2
  1108.         mov al,0
  1109.         js .l2
  1110.         mov al,-1
  1111.    .l2: test dh,dh
  1112.         jz .l3
  1113.         mov dl,0
  1114.         js .l3
  1115.         mov dl,-1
  1116.    .l3: test bh,bh
  1117.         mov dh,al
  1118.         jz .l4
  1119.         mov bl,0
  1120.         js .l4
  1121.         mov bl,-1
  1122.    .l4: mov [esi-2],dx
  1123.         mov [esi],bl
  1124.         inc esi
  1125.         cmp esi,[esp]
  1126.         jc .l1
  1127.         pop edi
  1128.         popad
  1129.         ret
  1130.  
  1131. recortar:  ;edi=bufer eax=ancho en pixels (ecx,edx)tama¤o deseado
  1132.         pushad
  1133.         dec edx
  1134.         jz .l2
  1135.         lea ebx,[ecx*3]
  1136.         lea eax,[eax*3]
  1137.         lea esi,[edi+eax]
  1138.         add edi,ebx
  1139.         sub eax,ebx
  1140.   .l1:  mov ecx,ebx
  1141.         call movedata
  1142.         add esi,eax
  1143.         dec edx
  1144.         jnz .l1
  1145.    .l2: popad
  1146.         ret
  1147.  
  1148. ;R = Y                    + 1.402  *(Cr-128)
  1149. ;G = Y - 0.34414*(Cb-128) - 0.71414*(Cr-128)
  1150. ;B = Y + 1.772  *(Cb-128)
  1151.  
  1152. colortabla: dd 0
  1153.  
  1154. colorprecalc: ;prepara la tabla para convertir ycb a rgb
  1155.          mov ecx,1024*2
  1156.          call malloc
  1157.          mov [colortabla],edi
  1158.          fninit
  1159.          fld dword [.k+4]
  1160.          fld dword [.k]
  1161.          mov dl,0
  1162.          call .l1
  1163.          fld dword [.k+12]
  1164.          fld dword[.k+8]
  1165.     .l1: mov cx,-128
  1166.     .l2: mov [edi],ecx
  1167.          inc ecx
  1168.          fild word[edi]
  1169.          fld st0
  1170.          fmul st0,st2
  1171.          fistp word[edi]
  1172.          fmul st0,st2
  1173.          fistp word[edi+2]
  1174.          add edi,4
  1175.          inc dl
  1176.          jnz .l2
  1177.          ret
  1178.  
  1179.      .k: dd 1.402,-0.71414,-0.34414,+1.772
  1180.