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_Palette.asm < prev    next >
Encoding:
Assembly Source File  |  2001-11-17  |  18.3 KB  |  1,013 lines

  1. ;ASM_Palette.asm  by Robert Rayment  7/11/01
  2.  
  3. ;VB
  4.  
  5. ; Assumes MCode Structure set
  6. ; MCode Structure
  7. ; Public Type MCodeStruc
  8. ;   PICW As Long
  9. ;   PICH As Long
  10. ;   PtrPalBGR As Long
  11. ;   PtrPalLineCopy As Long
  12. ;   Increment As Long
  13. ;   QBLongColor As Long
  14. ;   OpCode As Long
  15. ; End Type
  16. ; Public MCODE As MCodeStruc
  17. ;
  18. ; ptrStruc = VarPtr(MCODE.PICW)
  19. ; ptMC = VarPtr mcode byte array
  20.  
  21. ; Palette Effects
  22. ; OpCode& = 0    'Redder
  23. ; OpCode& = 1    'LessRed
  24. ; OpCode& = 2    'Greener
  25. ; OpCode& = 3    'LessGreen
  26. ; OpCode& = 4    'Bluer
  27. ; OpCode& = 5    'LessBlue
  28. ; OpCode& = 6    'Brighter
  29. ; OpCode& = 7    'Darker
  30. ; OpCode& = 8    'RotateColorsPlus
  31. ; OpCode& = 9    'RotateColorsMinus
  32. ; OpCode& = 10   'AddNoise
  33. ; OpCode& = 11   'Invert
  34. ; OpCode& = 12   'Grey
  35. ; OpCode& = 13   'Blacken < 24
  36. ; OpCode& = 14   'Whiten  > 248
  37. ; OpCode& = 15   'Black2White
  38. ; OpCode& = 16   'White2Black
  39. ; OpCode& = 17   'NonWhite2Black
  40. ; OpCode& = 18   'NonBlack2White
  41. ; OpCode& = 19   'BlackAndWhite
  42. ;
  43. ; Rand = 255 * Rnd
  44. ;   
  45. ; res = CallWindowProc(ptMC, ptrStruc, Rand, 3&, 4&)
  46. ;                      [ebp +  8        12   16  20 ]
  47. ; End Sub
  48.  
  49.  
  50. %macro movab 2        ; name & num of parameters
  51.   push dword %2        ; 2nd param
  52.   pop dword %1        ; 1st param
  53. %endmacro            ; use  movab %1,%2
  54. ; Allows eg    movab bmW,[ebx+4]
  55.  
  56. %define PICW            [ebp-4]        ; PICW Mod 4
  57. %define PICH            [ebp-8]        ; PICH
  58. %define PtrPalBGR       [ebp-12]    ; PTR to PalBGR(1,1,1,N)
  59. %define PtrPalLineCopy  [ebp-16]    ; PTR to PalLineCopy(4,1)
  60. %define Increment       [ebp-20]     ; 1,2,4,8
  61. %define QBLongColor     [ebp-24]    ; RGB(QBRed, QBGreen, QBBlue)    
  62. %define OpCode          [ebp-28]    ; 0,1,2,, etc
  63.  
  64. %define PalSize    [ebp-32]
  65. %define LineBytes  [ebp-36]
  66. %define Seed       [ebp-40] ; from Rand
  67. ; For MMX
  68. %define lo32 [ebp-44]
  69. %define hi32 [ebp-48]
  70.  
  71.  
  72. [bits 32]
  73.  
  74.     push ebp
  75.     mov ebp,esp
  76.     sub esp,76
  77.     push edi
  78.     push esi
  79.     push ebx
  80.  
  81.     ; Copy structure
  82.     mov ebx,[ebp+8]
  83.     
  84.     movab PICW,          [ebx]
  85.     movab PICH,          [ebx+4]
  86.     movab PtrPalBGR,     [ebx+8]
  87.     movab PtrPalLineCopy,[ebx+12]
  88.     movab Increment,     [ebx+16]
  89.     movab QBLongColor,   [ebx+20]
  90.     movab OpCode,        [ebx+24]
  91.     
  92.     mov eax,[ebp+12]
  93.     mov Seed,eax
  94.     
  95.     mov eax,PICH
  96.     mov ebx,PICW
  97.     mul ebx
  98.     mov PalSize,eax        ; In 4 byte chunks
  99.     
  100.     mov eax,PICW
  101.     shl eax,2            ; x4
  102.     mov LineBytes,eax
  103.     
  104.     
  105.     mov eax,OpCode
  106.     cmp eax,0
  107.     jne Test1
  108.     Call near Redder
  109.     jmp near GETOUT
  110. Test1:
  111.     cmp eax,1
  112.     jne Test2
  113.     Call near LessRed
  114.     jmp near GETOUT
  115. Test2:
  116.     cmp eax,2
  117.     jne Test3
  118.     Call near Greener
  119.     jmp near GETOUT
  120. Test3:
  121.     cmp eax,3
  122.     jne Test4
  123.     Call near LessGreen
  124.     jmp near GETOUT
  125. Test4:
  126.     cmp eax,4
  127.     jne Test5
  128.     Call near Bluer
  129.     jmp near GETOUT
  130. Test5:
  131.     cmp eax,5
  132.     jne Test6
  133.     Call near LessBlue
  134.     jmp near GETOUT
  135. Test6:
  136.     cmp eax,6
  137.     jne Test7
  138.     Call near Brighter
  139. Test7:
  140.     cmp eax,7
  141.     jne Test8
  142.     Call Darker
  143. Test8:
  144.     cmp eax,8
  145.     jne Test9
  146.     Call near RotateColorsPlus
  147.     jmp GETOUT
  148. Test9:
  149.     cmp eax,9
  150.     jne Test10
  151.     Call near RotateColorsMinus
  152.     jmp GETOUT
  153. Test10:    
  154.     cmp eax,10
  155.     jne Test11
  156.     Call near AddNoise
  157.     jmp GETOUT
  158. Test11:
  159.     cmp eax,11
  160.     jne Test12
  161.     Call near Invert
  162.     jmp GETOUT
  163. Test12:
  164.     cmp eax,12
  165.     jne Test13
  166.     Call near Grey
  167.     jmp GETOUT
  168. Test13:
  169.     cmp eax,13
  170.     jne Test14
  171.     Call near Blacken
  172.     jmp GETOUT
  173. Test14:
  174.     cmp eax,14
  175.     jne Test15
  176.     Call near Whiten
  177.     jmp GETOUT
  178. Test15:
  179.     cmp eax,15
  180.     jne Test16
  181.     Call near Black2White
  182.     jmp GETOUT
  183. Test16:
  184.     cmp eax,16
  185.     jne Test17
  186.     Call near White2Black
  187.     jmp GETOUT
  188. Test17:
  189.     cmp eax,17
  190.     jne Test18
  191.     Call near NonWhite2Black
  192.     jmp GETOUT
  193. Test18:
  194.     cmp eax,18
  195.     jne Test19
  196.     Call near NonBlack2White
  197.     jmp GETOUT
  198. Test19:
  199.     cmp eax,19
  200.     jne Test20
  201.     Call near BlackAndWhite
  202.     jmp GETOUT
  203. Test20:
  204.  
  205.  
  206.  
  207. GETOUT:
  208.     pop ebx
  209.     pop esi
  210.     pop edi
  211.     mov esp,ebp
  212.     pop ebp
  213.     ret 16
  214.  
  215. ;############################################################
  216. ;============================================================
  217.  
  218. Redder:        ; 0
  219.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  220.     mov eax,PalSize
  221.     shl eax,2            ; x4
  222.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  223.  
  224.     xor eax,eax
  225.     mov eax,Increment
  226.     shl eax,16            ;00 In 00 00
  227.                         ;A  R  G  B
  228.     mov lo32,eax
  229.     mov hi32,eax
  230.     movq mm0,hi32
  231.     
  232.     mov ecx,PalSize
  233.     shr ecx,1            ; Num 8 byte chunks
  234.     mov ebx,8
  235. L0:
  236.     movq mm1,[esi]
  237.     paddusb mm1,mm0
  238.     movq [esi],mm1
  239.     add esi,ebx
  240.     dec ecx
  241.     jnz L0
  242.     emms
  243. RET
  244. ;============================================================
  245. LessRed:        ; 1
  246.  
  247.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  248.     mov eax,PalSize
  249.     shl eax,2            ; x4
  250.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  251.  
  252.     xor eax,eax
  253.     mov eax,Increment
  254.     shl eax,16            ;00 In 00 00
  255.                         ;A  R  G  B
  256.     mov lo32,eax
  257.     mov hi32,eax
  258.     movq mm0,hi32
  259.     
  260.     mov ecx,PalSize
  261.     shr ecx,1            ; Num 8 byte chunks
  262.     mov ebx,8
  263. L1:
  264.     movq mm1,[esi]
  265.     psubusb mm1,mm0
  266.     movq [esi],mm1
  267.     add esi,ebx
  268.     dec ecx
  269.     jnz L1
  270.     emms
  271.     
  272. RET
  273. ;============================================================
  274. Greener:        ; 2
  275.  
  276.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  277.     mov eax,PalSize
  278.     shl eax,2            ; x4
  279.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  280.  
  281.     xor eax,eax
  282.     mov eax,Increment
  283.     shl eax,8            ;00 00 In 00
  284.                         ;A  R  G  B
  285.     mov lo32,eax
  286.     mov hi32,eax
  287.     movq mm0,hi32
  288.     
  289.     mov ecx,PalSize
  290.     shr ecx,1            ; Num 8 byte chunks
  291.     mov ebx,8
  292. L2:
  293.     movq mm1,[esi]
  294.     paddusb mm1,mm0
  295.     movq [esi],mm1
  296.     add esi,ebx
  297.     dec ecx
  298.     jnz L2
  299.     emms
  300.     
  301. RET
  302. ;============================================================
  303. LessGreen:        ; 3
  304.  
  305.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  306.     mov eax,PalSize
  307.     shl eax,2            ; x4
  308.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  309.  
  310.     xor eax,eax
  311.     mov eax,Increment
  312.     shl eax,8            ;00 00 In 00
  313.                         ;A  R  G  B
  314.     mov lo32,eax
  315.     mov hi32,eax
  316.     movq mm0,hi32
  317.     
  318.     mov ecx,PalSize
  319.     shr ecx,1            ; Num 8 byte chunks
  320.     mov ebx,8
  321. L3:
  322.     movq mm1,[esi]
  323.     psubusb mm1,mm0
  324.     movq [esi],mm1
  325.     add esi,ebx
  326.     dec ecx
  327.     jnz L3
  328.     emms
  329.  
  330. RET
  331. ;============================================================
  332. Bluer:        ; 4
  333.  
  334.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  335.     mov eax,PalSize
  336.     shl eax,2            ; x4
  337.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  338.  
  339.     xor eax,eax
  340.     mov eax,Increment
  341.                           ;00 00 0 In
  342.                         ;A  R  G  B
  343.     mov lo32,eax
  344.     mov hi32,eax
  345.     movq mm0,hi32
  346.     
  347.     mov ecx,PalSize
  348.     shr ecx,1            ; Num 8 byte chunks
  349.     mov ebx,8
  350. L4:
  351.     movq mm1,[esi]
  352.     paddusb mm1,mm0
  353.     movq [esi],mm1
  354.     add esi,ebx
  355.     dec ecx
  356.     jnz L4
  357.     emms
  358.  
  359. RET
  360. ;============================================================
  361. LessBlue:        ; 5
  362.  
  363.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  364.     mov eax,PalSize
  365.     shl eax,2            ; x4
  366.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  367.  
  368.     xor eax,eax
  369.     mov eax,Increment
  370.                           ;00 00 00 In
  371.                         ;A  R  G  B
  372.     mov lo32,eax
  373.     mov hi32,eax
  374.     movq mm0,hi32
  375.     
  376.     mov ecx,PalSize
  377.     shr ecx,1            ; Num 8 byte chunks
  378.     mov ebx,8
  379. L5:
  380.     movq mm1,[esi]
  381.     psubusb mm1,mm0
  382.     movq [esi],mm1
  383.     add esi,ebx
  384.     dec ecx
  385.     jnz L5
  386.     emms
  387.  
  388. RET
  389. ;============================================================
  390. Brighter:    ; 6
  391.  
  392.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  393.     mov eax,PalSize
  394.     shl eax,2            ; x4
  395.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  396.  
  397.     xor eax,eax
  398.     mov eax,Increment
  399.     shl eax,8            ;00 00 In 00
  400.                         ;A  R  G  B
  401.     mov aL,Increment
  402.     shl eax,8            ;00 In In 00
  403.                         ;A  R  G  B
  404.     mov aL,Increment    ;00 In In In
  405.                         ;A  R  G  B
  406.     
  407.     mov lo32,eax
  408.     mov hi32,eax
  409.     movq mm0,hi32
  410.     
  411.     mov ecx,PalSize
  412.     shr ecx,1            ; Num 8 byte chunks
  413.     mov ebx,8
  414. L6:
  415.     movq mm1,[esi]
  416.     paddusb mm1,mm0
  417.     movq [esi],mm1
  418.     add esi,ebx
  419.     dec ecx
  420.     jnz L6
  421.     emms
  422. RET
  423.  
  424. ;============================================================
  425. Darker:    ; 7
  426.  
  427.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  428.     mov eax,PalSize
  429.     shl eax,2            ; x4
  430.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  431.  
  432.     xor eax,eax
  433.     mov eax,Increment
  434.     shl eax,8            ;00 00 In 00
  435.                         ;A  R  G  B
  436.     mov aL,Increment
  437.     shl eax,8            ;00 In In 00
  438.                         ;A  R  G  B
  439.     mov aL,Increment    ;00 In In In
  440.                         ;A  R  G  B
  441.     
  442.     mov lo32,eax
  443.     mov hi32,eax
  444.     movq mm0,hi32
  445.     
  446.     mov ecx,PalSize
  447.     shr ecx,1            ; Num 8 byte chunks
  448.     mov ebx,8
  449. L7:
  450.     movq mm1,[esi]
  451.     psubusb mm1,mm0
  452.     movq [esi],mm1
  453.     add esi,ebx
  454.     dec ecx
  455.     jnz L7
  456.     emms
  457. RET
  458. ;============================================================
  459.  
  460. RotateColorsPlus:    ; 8
  461.  
  462.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  463.     mov eax,PalSize
  464.     shl eax,2            ; x4
  465.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  466.  
  467.     xor eax,eax
  468.     mov eax,Increment
  469.     shl eax,8            ;00 00 In 00
  470.                         ;A  R  G  B
  471.     mov aL,Increment
  472.     shl eax,8            ;00 In In 00
  473.                         ;A  R  G  B
  474.     mov aL,Increment    ;00 In In In
  475.                         ;A  R  G  B
  476.     
  477.     mov lo32,eax
  478.     mov hi32,eax
  479.     movq mm0,hi32
  480.     
  481.     mov ecx,PalSize
  482.     shr ecx,1            ; Num 8 byte chunks
  483.     mov ebx,8
  484. L8:
  485.     movq mm1,[esi]
  486.     paddb mm1,mm0
  487.     movq [esi],mm1
  488.     add esi,ebx
  489.     dec ecx
  490.     jnz L8
  491.     emms
  492. RET
  493. ;============================================================
  494. RotateColorsMinus:    ; 9
  495.  
  496.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  497.     mov eax,PalSize
  498.     shl eax,2            ; x4
  499.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  500.  
  501.     xor eax,eax
  502.     mov eax,Increment
  503.     shl eax,8            ;00 00 In 00
  504.                         ;A  R  G  B
  505.     mov aL,Increment
  506.     shl eax,8            ;00 In In 00
  507.                         ;A  R  G  B
  508.     mov aL,Increment    ;00 In In In
  509.                         ;A  R  G  B
  510.     
  511.     mov lo32,eax
  512.     mov hi32,eax
  513.     movq mm0,hi32
  514.     
  515.     mov ecx,PalSize
  516.     shr ecx,1            ; Num 8 byte chunks
  517.     mov ebx,8
  518. L9:
  519.     movq mm1,[esi]
  520.     psubb mm1,mm0
  521.     movq [esi],mm1
  522.     add esi,ebx
  523.     dec ecx
  524.     jnz L9
  525.     emms
  526. RET
  527. ;============================================================
  528.  
  529. %define zFac2      [ebp-52]    ; = (zFac * 2 + 1)
  530. %define a255       [ebp-56]    
  531. %define culB       [ebp-60]    
  532. %define culG       [ebp-64]    
  533. %define culR       [ebp-68]    
  534. %define aran       [ebp-72] ; aran 0-255
  535. %define zFac       [ebp-76]    ; = 20 * Increment
  536.  
  537. AddNoise:    ; 10
  538.  
  539.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  540.     mov eax,PalSize
  541.     shl eax,2            ; x4
  542.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  543.  
  544.     mov eax,Increment
  545.     mov ebx,20
  546.     mul ebx
  547.     mov zFac,eax        ; zFac=20*Increment
  548.     shl eax,1            ; zFac*2
  549.     add eax,1            ; zFac*2+1
  550.     mov zFac2,eax
  551.     
  552.     mov eax,255
  553.     mov a255,eax
  554.     
  555.     mov ecx,PalSize
  556. iy10:
  557.     ;---------------------
  558.     Call RANDNOISE        ; Out: aL & Seed & aran = rand(0-255)
  559.     fild dword aran        
  560.     fild dword a255        ; 255,aran
  561.     fdivp st1            ; aran/255   0-1
  562.     fild dword zFac2
  563.     fmulp st1            ; (zFac*2+1)*Rnd
  564.     fild dword zFac        ; zFac,(zFac*2+1)*Rnd
  565.     fsubp st1            ; (zFac*2+1)*Rnd - zFac
  566.     
  567.     movzx eax,byte [esi]   ; B
  568.     mov culB,eax
  569.     
  570.     fild dword culB
  571.     faddp st1
  572.     fistp dword culB
  573.     ;---------------------
  574.     inc esi                ; G    
  575.     ;---------------------
  576.     Call RANDNOISE        ; Out: aL & Seed = rand(0-255)
  577.     fild dword aran        
  578.     fild dword a255        ; 255,aran
  579.     fdivp st1            ; aran/255   0-1
  580.     fild dword zFac2
  581.     fmulp st1            ; (zFac*2+1)*Rnd
  582.     fild dword zFac        ; zFac,(zFac*2+1)*Rnd
  583.     fsubp st1            ; (zFac*2+1)*Rnd - zFac
  584.     
  585.     movzx eax,byte [esi]   ; G
  586.     mov culG,eax
  587.     
  588.     fild dword culG
  589.     faddp st1
  590.     fistp dword culG
  591.     ;---------------------
  592.     inc esi                ; R
  593.     ;---------------------
  594.     Call RANDNOISE        ; Out: aL & Seed = rand(0-255)
  595.     fild dword aran        
  596.     fild dword a255        ; 255,aran
  597.     fdivp st1            ; aran/255   0-1
  598.     fild dword zFac2
  599.     fmulp st1            ; (zFac*2+1)*Rnd
  600.     fild dword zFac        ; zFac,(zFac*2+1)*Rnd
  601.     fsubp st1            ; (zFac*2+1)*Rnd - zFac
  602.     
  603.     movzx eax,byte [esi]   ; R
  604.     mov culR,eax
  605.     
  606.     fild dword culR
  607.     faddp st1
  608.     fistp dword culR
  609.     ;---------------------
  610.  
  611.     ;---------------------
  612.     mov eax,culB
  613.     cmp eax,255
  614.     jl t10
  615.     mov eax,255
  616.     jmp s10
  617. t10:
  618.     cmp eax,0
  619.     jg s10
  620.     mov eax,0
  621. s10:
  622.     mov culB,eax
  623.     ;---------------------
  624.     mov eax,culG
  625.     cmp eax,255
  626.     jl t100
  627.     mov eax,255
  628.     jmp s100
  629. t100:
  630.     cmp eax,0
  631.     jg s100
  632.     mov eax,0
  633. s100:
  634.     mov culG,eax
  635.     ;---------------------
  636.     mov eax,culR
  637.     cmp eax,255
  638.     jl t1000
  639.     mov eax,255
  640.     jmp s1000
  641. t1000:
  642.     cmp eax,0
  643.     jg s1000
  644.     mov eax,0
  645. s1000:
  646.     mov culR,eax
  647.     ;---------------------
  648.     ; esi->R
  649.     mov eax,culR
  650.     mov byte[esi],aL
  651.     dec esi            ; ->G
  652.     mov eax,culG
  653.     mov byte[esi],aL
  654.     dec esi            ; ->B
  655.     mov eax,culB
  656.     mov byte[esi],aL
  657.     
  658.     mov edx,4
  659.     add esi,edx        ; -> next B
  660.     
  661.     dec ecx
  662.     jnz near iy10
  663.  
  664. RET
  665.  
  666. ;============================================================
  667. RANDNOISE:        ; Out: aL & Seed = rand(0-255)
  668.     mov eax,011813h         ; 71699 prime 
  669.     imul DWORD Seed
  670.     add eax, 0AB209h     ; 700937 prime
  671.     rcr eax,1            ; leaving out gives vertical lines plus
  672.                         ; faint horizontal ones, tartan
  673.  
  674.     ;----------------------------------------
  675.     ;jc ok                ; these 2 have little effect
  676.     ;rol eax,1            ;
  677. ok:                        ;
  678.     ;----------------------------------------
  679.     
  680.     ;----------------------------------------
  681.     ;dec eax            ; these produce vert lines
  682.     ;inc eax            ; & with fsin marble arches
  683.     ;----------------------------------------
  684.  
  685.     mov Seed,eax    ; save seed
  686.     and eax,255
  687.     mov aran,eax    ; aran = rnd(0-255)
  688. RET
  689.  
  690. ;============================================================
  691. Invert:    ; 11
  692.  
  693.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  694.     mov eax,PalSize
  695.     shl eax,2            ; x4
  696.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  697.  
  698.     xor eax,eax
  699.     mov eax,0FFFFFFFFh
  700.     
  701.     mov lo32,eax
  702.     mov hi32,eax
  703.     
  704.     mov ecx,PalSize
  705.     shr ecx,1            ; Num 8 byte chunks
  706.     mov ebx,8
  707. L11:
  708.     movq mm0,hi32
  709.     movq mm1,[esi]
  710.     psubb mm0,mm1
  711.     movq [esi],mm0
  712.     add esi,ebx
  713.     dec ecx
  714.     jnz L11
  715.     emms
  716. RET
  717. ;============================================================
  718. Grey:    ; 12
  719.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  720.     mov eax,PalSize
  721.     shl eax,2            ; x4
  722.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  723.  
  724.     mov ecx,PalSize
  725. iy12:
  726.     movzx ax,byte[esi]
  727.     mov bx,ax
  728.     movzx ax,byte[esi+1]
  729.     mov dx,ax
  730.     movzx ax,byte[esi+2]
  731.     add ax,dx
  732.     add ax,bx
  733.     mov bx,3
  734.     div bL                ; to get result in aL !
  735.     mov byte[esi],aL    ; B
  736.     inc esi
  737.     mov byte[esi],aL    ; G
  738.     inc esi    
  739.     mov byte[esi],aL    ; R
  740.     inc esi            ; -> A
  741.     inc esi            ; -> next B
  742.     
  743.     dec ecx
  744.     jnz iy12
  745.  
  746. RET
  747. ;============================================================
  748. Blacken:    ; 13    Blacken if R,G & B <24
  749.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  750.     mov eax,PalSize
  751.     shl eax,2            ; x4
  752.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  753.  
  754.     mov ecx,PalSize
  755. iy13:
  756.     mov aL,byte[esi]
  757.     cmp aL,24
  758.     ja ny13                ; ja not jg 
  759.     mov aL,byte[esi+1]
  760.     cmp aL,24
  761.     ja ny13
  762.     mov aL,byte[esi+2]
  763.     cmp aL,24
  764.     ja ny13
  765.     mov aL,0
  766.     mov byte[esi],aL    ; B
  767.     inc esi
  768.     mov byte[esi],aL    ; G
  769.     inc esi    
  770.     mov byte[esi],aL    ; R
  771.     inc esi            ; -> A
  772.     inc esi            ; -> next B
  773.     jmp ny130
  774. ny13:
  775.     mov edx,4
  776.     add esi,edx
  777. ny130:
  778.     dec ecx
  779.     jnz iy13
  780.  
  781. RET
  782.  
  783. ;============================================================
  784. Whiten:    ; 14 Whiten if R,G & B >248
  785.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  786.     mov eax,PalSize
  787.     shl eax,2            ; x4
  788.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  789.  
  790.     mov ecx,PalSize
  791. iy14:
  792.     mov aL,byte[esi]
  793.     cmp aL,248            ; aL-248
  794.     jbe ny14     
  795.     mov aL,byte[esi+1]
  796.     cmp aL,248
  797.     jbe ny14
  798.     mov aL,byte[esi+2]
  799.     cmp aL,248
  800.     jbe ny14
  801.     
  802.     mov aL,255
  803.     mov byte[esi],aL    ; B
  804.     inc esi
  805.     mov byte[esi],aL    ; G
  806.     inc esi    
  807.     mov byte[esi],aL    ; R
  808.     inc esi            ; -> A
  809.     inc esi            ; -> next B
  810.     jmp ny140
  811. ny14:
  812.     mov edx,4
  813.     add esi,edx
  814. ny140:
  815.     dec ecx
  816.     jnz iy14
  817.  
  818. RET
  819.  
  820. ;============================================================
  821. Black2White:    ; 15 B to W if R,G & B = 0
  822.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  823.     mov eax,PalSize
  824.     shl eax,2            ; x4
  825.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  826.  
  827.     mov ecx,PalSize
  828. iy15:
  829.     mov aL,byte[esi]
  830.     cmp aL,0            ; aL-0
  831.     jne ny15     
  832.     mov aL,byte[esi+1]
  833.     cmp aL,0
  834.     jne ny15
  835.     mov aL,byte[esi+2]
  836.     cmp aL,0
  837.     jne ny15
  838.     
  839.     mov aL,255
  840.     mov byte[esi],aL    ; B
  841.     inc esi
  842.     mov byte[esi],aL    ; G
  843.     inc esi    
  844.     mov byte[esi],aL    ; R
  845.     inc esi            ; -> A
  846.     inc esi            ; -> next B
  847.     jmp ny150
  848. ny15:
  849.     mov edx,4
  850.     add esi,edx
  851. ny150:
  852.     dec ecx
  853.     jnz iy15
  854.  
  855. RET
  856.  
  857. ;============================================================
  858. White2Black:    ; 16 W to B if R,G & B = 255
  859.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  860.     mov eax,PalSize
  861.     shl eax,2            ; x4
  862.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  863.  
  864.     mov ecx,PalSize
  865. iy16:
  866.     mov aL,byte[esi]
  867.     cmp aL,255        
  868.     jne ny16     
  869.     mov aL,byte[esi+1]
  870.     cmp aL,255
  871.     jne ny16
  872.     mov aL,byte[esi+2]
  873.     cmp aL,255
  874.     jne ny16
  875.     
  876.     mov aL,0
  877.     mov byte[esi],aL    ; B
  878.     inc esi
  879.     mov byte[esi],aL    ; G
  880.     inc esi    
  881.     mov byte[esi],aL    ; R
  882.     inc esi            ; -> A
  883.     inc esi            ; -> next B
  884.     jmp ny160
  885. ny16:
  886.     mov edx,4
  887.     add esi,edx
  888. ny160:
  889.     dec ecx
  890.     jnz iy16
  891.  
  892. RET
  893.  
  894. ;============================================================
  895. NonWhite2Black:    ; 17 NW to B if R,G & B <> 255
  896.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  897.     mov eax,PalSize
  898.     shl eax,2            ; x4
  899.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  900.  
  901.     mov ecx,PalSize
  902. iy17:
  903.     mov aL,byte[esi]
  904.     cmp aL,255        
  905.     jne ny17     
  906.     mov aL,byte[esi+1]
  907.     cmp aL,255
  908.     jne ny17
  909.     mov aL,byte[esi+2]
  910.     cmp aL,255
  911.     je ny170
  912. ny17:
  913.     mov aL,0
  914.     mov byte[esi],aL    ; B
  915.     inc esi
  916.     mov byte[esi],aL    ; G
  917.     inc esi    
  918.     mov byte[esi],aL    ; R
  919.     inc esi            ; -> A
  920.     inc esi            ; -> next B
  921.     jmp ny1700
  922. ny170:
  923.     mov edx,4
  924.     add esi,edx
  925. ny1700:
  926.     dec ecx
  927.     jnz iy17
  928.  
  929. RET
  930. ;============================================================
  931. NonBlack2White:    ; 18 NB to W if R,G & B <> 0
  932.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  933.     mov eax,PalSize
  934.     shl eax,2            ; x4
  935.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  936.  
  937.     mov ecx,PalSize
  938. iy18:
  939.     mov aL,byte[esi]
  940.     cmp aL,0        
  941.     jnz ny18     
  942.     mov aL,byte[esi+1]
  943.     cmp aL,0
  944.     jnz ny18
  945.     mov aL,byte[esi+2]
  946.     cmp aL,0
  947.     jz ny180
  948. ny18:    
  949.     mov aL,255
  950.     mov byte[esi],aL    ; B
  951.     inc esi
  952.     mov byte[esi],aL    ; G
  953.     inc esi    
  954.     mov byte[esi],aL    ; R
  955.     inc esi            ; -> A
  956.     inc esi            ; -> next B
  957.     jmp ny1800
  958. ny180:
  959.     mov edx,4
  960.     add esi,edx
  961. ny1800:
  962.     dec ecx
  963.     jnz iy18
  964.  
  965. RET
  966.  
  967. ;============================================================
  968. BlackAndWhite:    ; 19 Whiten if R,G & B >=180 else Black
  969.     mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
  970.     mov eax,PalSize
  971.     shl eax,2            ; x4
  972.     add esi,eax            ; pts to PalBGR(1,1,1,2) Blue
  973.  
  974.     mov ecx,PalSize
  975. iy19:
  976.     mov aL,byte[esi]    ; B
  977.     cmp aL,180            ; aL-180
  978.     jb ny19     
  979.     mov aL,byte[esi+1]    ; G
  980.     cmp aL,180
  981.     jb ny191
  982.     mov aL,byte[esi+2]    ; R
  983.     cmp aL,180
  984.     jb ny192
  985. GE180:
  986.     mov aL,255
  987. BW19:
  988.     mov byte[esi],aL    ; B
  989.     inc esi
  990.     mov byte[esi],aL    ; G
  991.     inc esi    
  992.     mov byte[esi],aL    ; R
  993.     inc esi            ; -> A
  994.     inc esi            ; -> next B
  995.     jmp ny1900
  996. ny19:
  997.     mov aL,byte[esi+1]    ; G
  998.     cmp aL,180
  999.     jae GE180 
  1000. ny191:
  1001.     mov aL,byte[esi+2]    ; R
  1002.     cmp aL,180
  1003.     jae GE180 
  1004. ny192:
  1005.     mov aL,0
  1006.     jmp BW19            ; All < 180
  1007.  
  1008. ny1900:
  1009.     dec ecx
  1010.     jnz iy19
  1011.  
  1012. RET
  1013.