home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Machine_Co3621711202001.psc / ASM_Magnify.asm next >
Encoding:
Assembly Source File  |  2001-11-18  |  12.0 KB  |  644 lines

  1. ; ASM_Magnify.asm  by Robert Rayment  7/11/01
  2.  
  3. ; VB
  4.  
  5. ;zParam1 = iXp
  6. ;zParam2 = iYp
  7. ;MAG = 10*zMag
  8. ;
  9. ;MAG = 10 * zMag
  10.  
  11. ;Select Case chkMagIndex
  12. ;
  13. ;Case 0      ' SIMPLE MAG
  14. ;   MCODE.OpCode = chkMagIndex
  15. ;   res = CallWindowProc(ptMC, ptrStruc, zParam1, zParam2, MAG)
  16. ;Case 1      ' ANTI-ALIAS MAG
  17. ;   MCODE.OpCode = chkMagIndex
  18. ;   res = CallWindowProc(ptMC, ptrStruc, zParam1, zParam2, MAG)
  19. ;
  20. ;End Select
  21.  
  22. ; Assumes MCode Structure set
  23. ; MCode Structure
  24. ; Public Type MCodeStruc
  25. ;   PICW As Long
  26. ;   PICH As Long
  27. ;   PtrPalBGR As Long
  28. ;   PtrPalLineCopy As Long
  29. ;   Increment As Long
  30. ;   QBLongColor As Long
  31. ;   OpCode As Long
  32. ; End Type
  33. ; Public MCODE As MCodeStruc
  34. ;
  35. ; ptrStruc = VarPtr(MCODE.PICW)
  36. ; ptMC = Ptr to mcode byte array
  37.  
  38. ; Magnify
  39. ; OpCode& = 0    'Magnify
  40. ; OpCode& = 1    'AAMagnify
  41. ;   
  42. ; res = CallWindowProc(ptMC, ptrStruc, zParam1, zParam2, MAG)
  43. ;                      [ebp +  8        12       16       20 ]
  44.  
  45.  
  46. %macro movab 2        ; name & num of parameters
  47.   push dword %2        ; 2nd param
  48.   pop dword %1        ; 1st param
  49. %endmacro            ; use  movab %1,%2
  50. ; Allows eg    movab bmW,[ebx+4]
  51.  
  52. %define PICW            [ebp-4]        ; PICW Mod 4
  53. %define PICH            [ebp-8]        ; PICH
  54. %define PtrPalBGR       [ebp-12]    ; PTR to PalBGR(1,1,1,N)
  55. %define PtrPalLineCopy  [ebp-16]    ; PTR to PalLineCopy(4,1)
  56. %define Increment       [ebp-20]     ; 1,2,4,8
  57. %define QBLongColor     [ebp-24]    ; RGB(QBRed, QBGreen, QBBlue)    
  58. %define OpCode          [ebp-28]    ; 0,1,2,, etc
  59.  
  60. %define PalSize    [ebp-32]
  61. %define LineBytes  [ebp-36]
  62.  
  63. %define Xp           [ebp-40] ; from VB
  64. %define Yp         [ebp-44] ; from VB
  65. %define ix           [ebp-48]    
  66. %define iy         [ebp-52]
  67. %define culB       [ebp-56]    
  68. %define culG       [ebp-60]    
  69. %define culR       [ebp-64]    
  70. %define zMul       [ebp-68]
  71. %define zCos       [ebp-72]
  72. %define zSin       [ebp-76]
  73. %define Half       [ebp-80]
  74. %define numbr      [ebp-84]
  75. %define ixs           [ebp-88]
  76. %define iys           [ebp-92]
  77. %define xs            [ebp-96]    
  78. %define ys            [ebp-100]    
  79. %define xsf            [ebp-104]    ; scale factors    
  80. %define ysf            [ebp-108]    
  81.  
  82. %define culBT        [ebp-112]    ; Temps
  83. %define culGT        [ebp-116]    
  84. %define culRT        [ebp-120]    
  85.  
  86. [bits 32]
  87.  
  88.     push ebp
  89.     mov ebp,esp
  90.     sub esp,120
  91.     push edi
  92.     push esi
  93.     push ebx
  94.  
  95.     ; Copy structure
  96.     mov ebx,[ebp+8]
  97.     
  98.     movab PICW,          [ebx]
  99.     movab PICH,          [ebx+4]
  100.     movab PtrPalBGR,     [ebx+8]
  101.     movab PtrPalLineCopy,[ebx+12]
  102.     movab Increment,     [ebx+16]
  103.     movab QBLongColor,   [ebx+20]
  104.     movab OpCode,        [ebx+24]
  105.     
  106.     mov eax,[ebp+12]
  107.     mov Xp,eax            ; rotation point from VB
  108.     mov eax,[ebp+16]
  109.     mov Yp,eax
  110.     mov eax,[ebp+20]
  111.     mov zMul,eax
  112.  
  113.     ; Make MAG = zMul = 1/zMag (ie 1/ (MAG/10))
  114.     mov eax,10
  115.     mov numbr,eax
  116.     fld1
  117.     fild dword zMul
  118.     fild dword numbr
  119.     fdivp st1            ; zMag, 1
  120.     fdivp st1            ; zMul= 1/zMag
  121.     fstp dword zMul    
  122.     
  123.     mov eax,PICH
  124.     mov ebx,PICW
  125.     mul ebx
  126.     mov PalSize,eax        ; In 4 byte chunks
  127.     
  128.     mov eax,PICW
  129.     shl eax,4            ; x4
  130.     mov LineBytes,eax
  131.     
  132.  
  133.     ; Get RGB    
  134.     mov eax,QBLongColor
  135.     and eax,0FFh
  136.     mov culR,eax
  137.     mov eax,QBLongColor
  138.     and eax,0FF00h
  139.     shr eax,8
  140.     mov culG,eax
  141.     mov eax,QBLongColor
  142.     and eax,0FF0000h
  143.     shr eax,16
  144.     mov culB,eax
  145.     
  146.     
  147.     ; Make Yp PICH-Yp
  148.     fild dword PICH
  149.     fld dword Yp
  150.     fsubp st1            ; PICH-Yp
  151.     fstp dword Yp
  152.     
  153.     ; Get 0.5 for int round down
  154.     mov eax,2
  155.     mov Half,eax
  156.     fld1        
  157.     fild dword Half        ; 2, 1
  158.     fdivp st1            ; 1/2
  159.     fstp dword Half
  160.  
  161. ; OpCode& = 0    'Magnify
  162. ; OpCode& = 1    'AAMagnify
  163.  
  164.     mov eax,OpCode
  165.     cmp eax,0
  166.     jne Test1
  167.     Call near Magnify
  168.     jmp near GETOUT
  169. Test1:
  170.     cmp eax,1
  171.     jne Test2
  172.     Call near AAMagnify
  173.     jmp near GETOUT
  174. Test2:
  175.  
  176. GETOUT:
  177.     pop ebx
  178.     pop esi
  179.     pop edi
  180.     mov esp,ebp
  181.     pop ebp
  182.     ret 16
  183.  
  184. ;############################################################
  185. ;============================================================
  186.  
  187. Magnify:        ;0        Magnify(display) 3 into 2
  188.     
  189.     mov edi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  190.     mov eax,PalSize
  191.     shl eax,2            ; x4
  192.     add edi,eax            ; pts to DEST PalBGR(1,1,1,2) Blue
  193.     
  194.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  195.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  196.     add esi,eax            ; pts to SOURCE PalBGR(1,1,1,3) Blue
  197.     
  198.     Call SimpleMagnify
  199.  
  200. RET
  201. ;============================================================
  202.  
  203. AAMagnify:    ; 1            Anti-alias Magnify(display) 3 into 2
  204.  
  205.     mov edi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  206.     mov eax,PalSize
  207.     shl eax,2            ; x4
  208.     add edi,eax            ; pts to DEST PalBGR(1,1,1,2) Blue
  209.     
  210.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  211.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  212.     add esi,eax            ; pts to SOURCE PalBGR(1,1,1,3) Blue
  213.  
  214.     Call near AAMagnifier
  215.  
  216. RET
  217. ;============================================================
  218. ;============================================================
  219. ;============================================================
  220. SimpleMagnify:        ; 0 & 2
  221.  
  222.     mov eax,PICH
  223.     mov ecx,eax
  224. IY0:
  225.     mov iy,ecx
  226.     push ecx
  227.     
  228.     mov eax,PICW
  229.     mov ecx,eax
  230. IX0:
  231.     mov ix,ecx
  232.     ;-----------------------
  233.     ; Get ixs
  234.     fild dword ix
  235.     fld dword Xp
  236.     fsubp st1            ; (ix-Xp)
  237.     fld dword zMul
  238.     fmulp st1            ; zMul*(ix-Xp)
  239.     fld dword Xp
  240.     faddp st1            ; Xp + zMul*(ix-Xp)
  241.     fistp dword ixs
  242.  
  243.     ; Test if ixs in-range
  244.     mov eax,ixs
  245.     cmp eax,1
  246.     jl QB0
  247.     cmp eax,PICW
  248.     jle Getiys0
  249. QB0:
  250.     ;edi->blue in 2
  251.     push edi
  252.     
  253.     Call GetAddrEDIixiy
  254.     
  255.     mov eax,culB
  256.     mov byte[edi],aL
  257.     mov eax,culG
  258.     mov byte[edi+1],aL
  259.     mov eax,culR
  260.     mov byte[edi+2],aL
  261.     
  262.     pop edi
  263.     jmp nexix0
  264.  
  265. Getiys0:
  266.     fild dword iy
  267.     fld dword Yp
  268.     fsubp st1            ; (iy-Yp)
  269.  
  270.     fld dword zMul
  271.     fmulp st1            ; zMul*(iy-Yp)
  272.     fld dword Yp
  273.     faddp st1            ; Yp + zMul*(iy-Yp)
  274.     fistp dword iys
  275.     
  276.     ; Test if iys in-range
  277.     mov eax,iys
  278.     cmp eax,1
  279.     jl QB00
  280.     cmp eax,PICH
  281.     jle FillBGR0
  282. QB00:
  283.     ;edi->blue in 2
  284.     push edi
  285.     
  286.     Call GetAddrEDIixiy    
  287.     
  288.     mov eax,culB
  289.     mov byte[edi],aL
  290.     mov eax,culG
  291.     mov byte[edi+1],aL
  292.     mov eax,culR
  293.     mov byte[edi+2],aL
  294.     
  295.     pop edi
  296.     jmp nexix0
  297.  
  298. FillBGR0:
  299.     ; BGR @ ixs,iys in 3 -> ix,iy in 2
  300.     ; esi->3  edi->2
  301.     
  302.     push edi
  303.     push esi
  304.     
  305.     Call GetAddrESIixsiys        ; 3 @ ixs,iys
  306.     Call GetAddrEDIixiy            ; 2 @ ix,iy
  307.     
  308.     mov aL,byte [esi]
  309.     mov byte [edi],aL
  310.     mov aL,byte [esi+1]
  311.     mov byte [edi+1],aL
  312.     mov aL,byte [esi+2]
  313.     mov byte [edi+2],aL
  314.  
  315.     pop esi
  316.     pop edi
  317.     
  318.     ;-----------------------
  319. nexix0:
  320.     dec ecx
  321.     jnz near IX0
  322.     
  323.     pop ecx
  324.     dec ecx
  325.     jnz near IY0
  326. RET
  327. ;============================================================
  328.  
  329. AAMagnifier:
  330.  
  331.     mov eax,PICH
  332.     mov ecx,eax
  333. IY1:
  334.     mov iy,ecx
  335.     push ecx
  336.     
  337.     mov eax,PICW
  338.     mov ecx,eax
  339. IX1:
  340.     mov ix,ecx
  341.     ;-----------------------
  342.     ; Get xs
  343.     fild dword ix
  344.     fld dword Xp
  345.     fsubp st1            ; (ix-Xp)
  346.  
  347.     fld dword zMul
  348.     fmulp st1            ; zMul*(ix-Xp)
  349.     fld dword Xp
  350.     faddp st1            ; Xp + zMul*(ix-Xp)
  351.     fstp dword xs
  352.  
  353.     ; Get ys
  354.     fild dword iy
  355.     fld dword Yp
  356.     fsubp st1            ; (iy-Yp)
  357.  
  358.     fld dword zMul
  359.     fmulp st1            ; zMul*(iy-Yp)
  360.     fld dword Yp
  361.     faddp st1            ; Yp + zMul*(iy-Yp)
  362.     fstp dword ys
  363.  
  364.     ;-----------------------
  365.     ; Get ixs,iys  INTEGERS
  366.     fld dword xs
  367.     fld dword Half        ; 0.5, xs
  368.     fsubp st1            ; xs-0.5
  369.     fistp dword ixs        ; truncated xs
  370.  
  371.     fld dword ys
  372.     fld dword Half        ; 0.5, ys
  373.     fsubp st1            ; ys-0.5
  374.     fistp dword iys        ; truncated ys
  375.     
  376.     ; Check in-range
  377.     mov eax,ixs
  378.     cmp eax,1
  379.     jl QB1
  380.     cmp eax,PICW
  381.     jge QB1
  382.     mov eax,iys
  383.     cmp eax,1
  384.     jl QB1
  385.     cmp eax,PICH
  386.     jge QB1
  387.     jmp InRange
  388. QB1:
  389.     ;edi->blue in 2
  390.     push edi
  391.     
  392.     Call GetAddrEDIixiy
  393.     
  394.     mov eax,culB
  395.     mov byte[edi],aL
  396.     mov eax,culG
  397.     mov byte[edi+1],aL
  398.     mov eax,culR
  399.     mov byte[edi+2],aL
  400.     
  401.     pop edi
  402.     jmp near nexix1
  403.     ;-----------------------
  404. InRange:
  405.     ; Get scale factors xsf=xs-ixs, ysf=ys-iys
  406.     fld dword xs
  407.     fild dword ixs
  408.     fsubp st1        ; xs-ixs
  409.     fstp dword xsf
  410.     
  411.     fld dword ys
  412.     fild dword iys
  413.     fsubp st1        ; ys-iys
  414.     fstp dword ysf
  415.     
  416.     ; Pick up from 3 esi
  417.     
  418.     push esi
  419.     
  420.     Call near GetAddrESIixsiys
  421.  
  422.     mov ebx,PICW
  423.     shl ebx,2                ; 4*PICW
  424.     ;===================================
  425.     ; Get weighted Blue over 4 points
  426.     ; y, x->x+1
  427.     movzx eax,byte[esi]        ; B
  428.     mov culBT,eax
  429.     fild dword culBT
  430.     movzx eax,byte[esi+4]    ; B+1
  431.     mov culBT,eax
  432.     fild dword culBT        ; P2, P1
  433.     fsub st1                ; (P2-P1), P1
  434.     fld dword xsf
  435.     fmulp st1                ; xsf*(P2-P1), P1
  436.     faddp st1                ; PA = P1 + xsf*(P2-P1)
  437.     ; y+1, x->x+1
  438.     movzx eax,byte[esi+ebx]    ; B
  439.     mov culBT,eax
  440.     fild dword culBT
  441.     movzx eax,byte[esi+ebx+4]    ; B+1
  442.     mov culBT,eax
  443.     fild dword culBT        ; P4, P3
  444.     fsub st1                ; (P4-P3), P3
  445.     fld dword xsf
  446.     fmulp st1                ; xsf*(P4-P3), P3
  447.     faddp st1                ; PB= P3 + xsf*(P4-P3), PA
  448.     ; y->y+1
  449.     fsub st1                ; (PB-PA), PA
  450.     fld dword ysf
  451.     fmulp st1                ; ysf*(PB-PA), PA
  452.     faddp st1                ; PA + ysf*(PB-PA)
  453.     
  454.     fistp dword culBT
  455.     ;===================================
  456.     
  457.     ; Get weighted Green over 4 points
  458.     
  459.     inc esi    ; GREEN
  460.     
  461.     movzx eax,byte[esi]        ; G
  462.     mov culGT,eax
  463.     fild dword culGT
  464.     movzx eax,byte[esi+4]    ; G+1
  465.     mov culGT,eax
  466.     fild dword culGT        ; P2, P1
  467.     fsub st1                ; (P2-P1), P1
  468.     fld dword xsf
  469.     fmulp st1                ; xsf*(P2-P1), P1
  470.     faddp st1                ; PA = P1 + xsf*(P2-P1)
  471.     
  472.     movzx eax,byte[esi+ebx]    ; G
  473.     mov culGT,eax
  474.     fild dword culGT
  475.     movzx eax,byte[esi+ebx+4]    ; B+1
  476.     mov culGT,eax
  477.     fild dword culGT        ; P4, P3
  478.     fsub st1                ; (P4-P3), P3
  479.     fld dword xsf
  480.     fmulp st1                ; xsf*(P4-P3), P3
  481.     faddp st1                ; PB= P3 + xsf*(P4-P3), PA
  482.     
  483.     fsub st1                ; (PB-PA), PA
  484.     fld dword ysf
  485.     fmulp st1                ; ysf*(PB-PA), PA
  486.     faddp st1                ; PA + ysf*(PB-PA)
  487.     
  488.     fistp dword culGT
  489.     ;===================================
  490.  
  491.     ; Get weighted Red over 4 points
  492.     
  493.     inc esi    ; RED  
  494.     
  495.     movzx eax,byte[esi]        ; R
  496.     mov culRT,eax
  497.     fild dword culRT
  498.     movzx eax,byte[esi+4]    ; R+1
  499.     mov culRT,eax
  500.     fild dword culRT        ; P2, P1
  501.     fsub st1                ; (P2-P1), P1
  502.     fld dword xsf
  503.     fmulp st1                ; xsf*(P2-P1), P1
  504.     faddp st1                ; PA = P1 + xsf*(P2-P1)
  505.     
  506.     movzx eax,byte[esi+ebx]    ; R
  507.     mov culRT,eax
  508.     fild dword culRT
  509.     movzx eax,byte[esi+ebx+4]    ; R+1
  510.     mov culRT,eax
  511.     fild dword culRT        ; P4, P3
  512.     fsub st1                ; (P4-P3), P3
  513.     fld dword xsf
  514.     fmulp st1                ; xsf*(P4-P3), P3
  515.     faddp st1                ; PB= P3 + xsf*(P4-P3), PA
  516.     
  517.     fsub st1                ; (PB-PA), PA
  518.     fld dword ysf
  519.     fmulp st1                ; ysf*(PB-PA), PA
  520.     faddp st1                ; PA + ysf*(PB-PA)
  521.     
  522.     fistp dword culRT
  523.     ;===================================
  524.  
  525.     pop esi
  526.     
  527.     ; Ensure colors in range
  528.     Call near CheckculBGRT
  529.     
  530.     push edi
  531.     
  532.     Call GetAddrEDIixiy
  533.     
  534.     mov eax,culBT
  535.     mov byte[edi],aL
  536.     mov eax,culGT
  537.     mov byte[edi+1],aL
  538.     mov eax,culRT
  539.     mov byte[edi+2],aL
  540.     
  541.     pop edi
  542.  
  543.     ;-----------------------
  544. nexix1:
  545.     dec ecx
  546.     jnz near IX1
  547.     
  548.     pop ecx
  549.     dec ecx
  550.     jnz near IY1
  551.  
  552. RET
  553. ;============================================================
  554. ;============================================================
  555.  
  556. CheckculBGRT:
  557.     
  558.     ; Ensure colors in range
  559.     mov eax,255
  560.     cmp culBT,eax    ; culBT-255
  561.     jle THG
  562.     mov culBT,eax
  563. THG:
  564.     cmp culGT,eax
  565.     jle THR
  566.     mov culGT,eax
  567. THR:
  568.     cmp culRT,eax
  569.     jle LoLim
  570.     mov culRT,eax
  571. LoLim:
  572.     mov eax,0
  573.     cmp culBT,eax    ; culBT-0
  574.     jge TLG
  575.     mov culBT,eax
  576. TLG:
  577.     cmp culGT,eax
  578.     jge TLR
  579.     mov culGT,eax
  580. TLR:
  581.     cmp culRT,eax
  582.     jge CulsDone
  583.     mov culRT,eax
  584.  
  585. CulsDone:
  586.  
  587. RET
  588. ;============================================================
  589.  
  590. GetAddrESIixsiys:    ; In esi-> PalBGR(1,1,1,2),ix,iy  Out: new esi->B
  591.     ;B = esi + (4 * (iy-1) * PICW + 4 * (ix-1))
  592.     ;B = esi + 4 * [(iy-1) * PICW + (ix-1))]
  593.     mov eax,iys
  594.     dec eax
  595.     mov ebx,PICW
  596.     mul ebx
  597.     mov ebx,ixs
  598.     dec ebx
  599.     add eax,ebx
  600.     shl eax,2        ; x4
  601.     add esi,eax
  602. RET
  603.  
  604. ;============================================================
  605.  
  606. GetAddrEDIixiy:
  607.     ;B = edi + (4 * (iy-1) * PICW + 4 * (ix-1))
  608.     ;B = edi + 4 * [(iy-1) * PICW + (ix-1))]
  609.     mov eax,iy
  610.     dec eax
  611.     mov ebx,PICW
  612.     mul ebx
  613.     mov ebx,ix
  614.     dec ebx
  615.     add eax,ebx
  616.     shl eax,2        ; x4
  617.     add edi,eax
  618. RET
  619. ;============================================================
  620. GetAddrEDIixsiys:    ; In edi-> PalBGR(1,1,1,2),ixs,iys  Out: new edi->B
  621.     ;B = edi + (4 * (iy-1) * PICW + 4 * (ix-1))
  622.     ;B = edi + 4 * [(iy-1) * PICW + (ix-1))]
  623.     mov eax,iys
  624.     dec eax
  625.     mov ebx,PICW
  626.     mul ebx
  627.     mov ebx,ixs
  628.     dec ebx
  629.     add eax,ebx
  630.     shl eax,2        ; x4
  631.     add edi,eax
  632. RET
  633. ;============================================================
  634. ;============================================================
  635.     ;mov ebx,[ebp+20]
  636.     ;mov [ebx],eax
  637.     ;ret
  638.     ;jmp GETOUT
  639.  
  640. ;mov eax,ecx
  641. ;mov ebx,[ebp+20]
  642. ;mov [ebx],eax
  643.  
  644.