Subversion Repositories Kolibri OS

Rev

Rev 2733 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;================================================================================================;;
  2. ;;//// blend_sse.asm //// (c) dunkaist, 2011-2012 ////////////////////////////////////////////////;;
  3. ;;================================================================================================;;
  4. ;;                                                                                                ;;
  5. ;; This file is part of Common development libraries (Libs-Dev).                                  ;;
  6. ;;                                                                                                ;;
  7. ;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
  8. ;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
  9. ;; of the License, or (at your option) any later version.                                         ;;
  10. ;;                                                                                                ;;
  11. ;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
  12. ;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
  13. ;; Lesser General Public License for more details.                                                ;;
  14. ;;                                                                                                ;;
  15. ;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
  16. ;; If not, see <http://www.gnu.org/licenses/>.                                                    ;;
  17. ;;                                                                                                ;;
  18. ;;================================================================================================;;
  19.  
  20. proc    xcf._.blend_rgb
  21.  
  22.         push            eax ebx
  23.  
  24.         xchg            al, bh
  25.         mov             ah, bh
  26.         neg             ax
  27.         add             ax, 0xffff
  28.         mul             ah
  29.         neg             ah
  30.         add             ah, 0xff
  31.         xchg            ah, bh
  32.  
  33.         mov             al, 0xff
  34.         cmp             ah, bh
  35.         je              @f
  36.         not             al
  37.         div             bh
  38.     @@:
  39.         mov             ah, al
  40.         movd            xmm1, eax
  41.  
  42.         pop             ebx eax
  43.         push            ebx
  44.  
  45.         shr             eax, 8
  46.         shr             ebx, 8
  47.  
  48.         xchg            al, bh
  49.         mov             ah, bh
  50.         neg             ax
  51.         add             ax, 0xffff
  52.         mul             ah
  53.         neg             ah
  54.         add             ah, 0xff
  55.         xchg            ah, bh
  56.  
  57.         mov             al, 0xff
  58.         cmp             ah, bh
  59.         je              @f
  60.         not             al
  61.         div             bh
  62.     @@:
  63.         mov             ah, al
  64.         movd            ebx, xmm1
  65.         ror             ebx, 16
  66.         mov             bx, ax
  67.         rol             ebx, 16
  68.         movd            xmm1, ebx
  69.  
  70.         pop             ebx
  71.  
  72. ;       movdqu          xmm1, xword[xcf._.xmm_000000ff]
  73. ;       movdqa          xmm4, xmm1
  74. ;       movdqa          xmm5, xmm1
  75. ;       movdqa          xmm6, xmm2
  76. ;       psrldq          xmm6, 3
  77. ;       pand            xmm6, xmm1
  78. ;       psubw           xmm4, xmm6
  79. ;       movdqa          xmm6, xmm3
  80. ;       psrldq          xmm6, 3
  81. ;       pand            xmm6, xmm1
  82. ;       psubw           xmm5, xmm6
  83. ;       pmullw          xmm4, xmm5
  84. ;       psrlw           xmm4, 8
  85. ;       psubw           xmm1, xmm4
  86. ;       movdqa          xmm4, xmm1
  87. ;       movdqa          xmm1, xmm6
  88. ;       divps           xmm1, xmm4
  89. ;       packuswb        xmm1, xmm0
  90. ;       packuswb        xmm1, xmm0
  91. ;       punpcklbw       xmm1, xmm1
  92.  
  93.         punpcklbw       xmm1, xmm1
  94.         punpcklbw       xmm1, xmm0
  95.  
  96.         movdqa          xmm7, xmm1
  97.         psrlw           xmm7, 7
  98.         paddw           xmm1, xmm7
  99.  
  100.         psubw           xmm3, xmm2
  101.         pmullw          xmm3, xmm1
  102.         psllw           xmm2, 8
  103.         paddw           xmm3, xmm2
  104.         pinsrw          xmm3, ebx, 3
  105.         shr             ebx, 8
  106.         pinsrw          xmm3, ebx, 7
  107.         psrlw           xmm3, 8
  108.         packuswb        xmm3, xmm0
  109.  
  110.         ret
  111. endp
  112.  
  113.  
  114. proc    xcf._.blend_gray
  115.  
  116.         xchg            al, bh
  117.         mov             ah, bh
  118.         neg             ax
  119.         add             ax, 0xffff
  120.         mul             ah
  121.         neg             ah
  122.         add             ah, 0xff
  123.         xchg            ah, bh
  124.  
  125.         mov             al, 0xff
  126.         cmp             ah, bh
  127.         je              @f
  128.         not             al
  129.         div             bh
  130.     @@:
  131.  
  132.         mov             ah, al
  133.  
  134.         movd            xmm1, eax
  135.         punpcklbw       xmm1, xmm1
  136.         punpcklbw       xmm1, xmm0
  137.  
  138.         movq            xmm7, xmm1
  139.         psrlw           xmm7, 7
  140.         paddw           xmm1, xmm7
  141.  
  142.         psubw           xmm3, xmm2
  143.         pmullw          xmm3, xmm1
  144.         psllw           xmm2, 8
  145.         paddw           xmm3, xmm2
  146.         pinsrw          xmm3, ebx, 1
  147.         psrlw           xmm3, 8
  148.         packuswb        xmm3, xmm0
  149.  
  150.         ret
  151. endp
  152.  
  153.  
  154. proc    xcf._.merge_32 _copy_width, _copy_height, _img_total_bpl, _bottom_total_bpl
  155.  
  156.         pxor            xmm0, xmm0
  157.  
  158.   .line:
  159.         mov             ecx, [_copy_width]
  160.         bt              ecx, 0
  161.         jnc             .even
  162.   .odd:
  163.         movd            xmm2, [edi]
  164.         movd            xmm3, [esi]
  165.         add             esi, 4
  166.  
  167.         movdqa          xmm4, xmm2
  168.         pminub          xmm4, xmm3
  169.         pextrw          eax, xmm4, 3
  170.         pextrw          ebx, xmm4, 1
  171.         mov             al, bh
  172.  
  173.         push            eax
  174.         pextrw          eax, xmm2, 3
  175.         pextrw          ebx, xmm2, 1
  176.         mov             bl, ah
  177.         shl             ebx, 8
  178.         pop             eax
  179.  
  180.         call            edx
  181.         call            xcf._.blend_rgb
  182.         movd            [edi], xmm3
  183.         add             edi, 4
  184.  
  185.         cmp             ecx, 1
  186.         je              .done
  187.  
  188.   .even:
  189.         sub             ecx, 2
  190.   .pixel:
  191.         movq            xmm2, [edi]
  192.         movq            xmm3, [esi]
  193.         add             esi, 8
  194.  
  195.         movdqa          xmm4, xmm2
  196.         pminub          xmm4, xmm3
  197.         pextrw          eax, xmm4, 3
  198.         pextrw          ebx, xmm4, 1
  199.         mov             al, bh
  200.  
  201.         push            eax
  202.         pextrw          eax, xmm2, 3
  203.         pextrw          ebx, xmm2, 1
  204.         mov             bl, ah
  205.         shl             ebx, 8
  206.         pop             eax
  207.  
  208.         call            edx
  209.         call            xcf._.blend_rgb
  210.         movq            [edi], xmm3
  211.         add             edi, 8
  212.         sub             ecx, 2
  213.         jns             .pixel
  214.         add             esi, [_img_total_bpl]
  215.         add             edi, [_bottom_total_bpl]
  216.         dec             [_copy_height]
  217.         jnz             .line
  218.   .done:
  219.         ret
  220. endp
  221.  
  222.  
  223. proc    xcf._.merge_8a _copy_width, _copy_height, _img_total_bpl, _bottom_total_bpl
  224.   .gray_line:
  225.         mov             ecx, [_copy_width]
  226.   .gray_pixel:
  227.         mov             bx,  word[edi]
  228.         lodsw
  229.         movd            xmm2, ebx
  230.         movd            xmm3, eax
  231.         shr             eax, 8
  232.         cmp             al, bh
  233.         jna             @f
  234.         mov             al, bh
  235.     @@:
  236.         pxor            xmm0, xmm0
  237.         call            edx
  238.         call            xcf._.blend_gray
  239.         movd            eax, xmm3
  240.         stosw
  241.         dec             ecx
  242.         jnz             .gray_pixel
  243.         add             esi, [_img_total_bpl]
  244.         add             edi, [_bottom_total_bpl]
  245.         dec             [_copy_height]
  246.         jnz             .gray_line
  247.         ret
  248. endp
  249.  
  250.  
  251. proc    xcf._.composite_rgb_00 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
  252.  
  253.         pxor            xmm0, xmm0
  254.  
  255.   .line:
  256.         mov             ecx, [_copy_width]
  257.         bt              ecx, 0
  258.         jnc             .even
  259.   .odd:
  260.         movlpd          xmm2, [edi]
  261.         movlpd          xmm3, [esi]
  262.         add             esi, 4
  263.  
  264.         pextrw          eax, xmm3, 3
  265.         pextrw          ebx, xmm3, 1
  266.         mov             al, bh
  267.  
  268.         push            eax
  269.         pextrw          eax, xmm2, 3
  270.         pextrw          ebx, xmm2, 1
  271.         mov             bl, ah
  272.         shl             ebx, 8
  273.         pop             eax
  274.  
  275.         xchg            al, bh
  276.         mov             ah, bh
  277.         neg             al
  278.         neg             ah
  279.         dec             al
  280.         dec             ah
  281.         mul             ah
  282.         neg             ah
  283.         dec             ah
  284.         xchg            ah, bh
  285.  
  286.         mov             al, 0xff
  287.         cmp             ah, bh
  288.         je              @f
  289.         inc             al
  290.         div             bh
  291.     @@:
  292.         mov             ah, al
  293.         movd            xmm1, eax
  294.  
  295.         punpcklbw       xmm1, xmm1
  296.         punpcklbw       xmm1, xmm0
  297.         punpcklbw       xmm2, xmm0
  298.         punpcklbw       xmm3, xmm0
  299.  
  300.         psubsw          xmm3, xmm2
  301.         pmullw          xmm3, xmm1
  302.         psllw           xmm2, 8
  303.         paddw           xmm3, xmm2
  304.         pinsrw          xmm3, ebx, 3
  305.         shr             ebx, 8
  306.         pinsrw          xmm3, ebx, 7
  307.         psrlw           xmm3, 8
  308.         packuswb        xmm3, xmm0
  309.  
  310.         movd            [edi], xmm3
  311.         add             edi, 4
  312.  
  313.         cmp             ecx, 1
  314.         je              .done
  315.  
  316.   .even:
  317.         sub             ecx, 2
  318.   .pixel:
  319.         movlpd          xmm2, [edi]
  320.         movlpd          xmm3, [esi]
  321.         add             esi, 8
  322.  
  323.         pextrw          eax, xmm3, 3
  324.         pextrw          ebx, xmm3, 1
  325.         mov             al, bh
  326.  
  327.         push            eax
  328.         pextrw          eax, xmm2, 3
  329.         pextrw          ebx, xmm2, 1
  330.         mov             bl, ah
  331.         shl             ebx, 8
  332.         pop             eax
  333.  
  334.  
  335.         push            eax ebx
  336.  
  337.         xchg            al, bh
  338.         mov             ah, bh
  339.         neg             al
  340.         neg             ah
  341.         dec             al
  342.         dec             ah
  343.         mul             ah
  344.         neg             ah
  345.         dec             ah
  346.         xchg            ah, bh
  347.  
  348.         mov             al, 0xff
  349.         cmp             ah, bh
  350.         je              @f
  351.         inc             al
  352.         div             bh
  353.     @@:
  354.         mov             ah, al
  355.         movd            xmm1, eax
  356.  
  357.         pop             ebx eax
  358.         push            ebx
  359.  
  360.         shr             eax, 8
  361.         shr             ebx, 8
  362.  
  363.         xchg            al, bh
  364.         mov             ah, bh
  365.         neg             ax
  366.         add             ax, 0xffff
  367.         mul             ah
  368.         neg             ah
  369.         add             ah, 0xff
  370.         xchg            ah, bh
  371.  
  372.         mov             al, 0xff
  373.         cmp             ah, bh
  374.         je              @f
  375.         not             al
  376.         div             bh
  377.     @@:
  378.         mov             ah, al
  379.         movd            ebx, xmm1
  380.         ror             ebx, 16
  381.         mov             bx, ax
  382.         rol             ebx, 16
  383.         movd            xmm1, ebx
  384.  
  385.         pop             ebx
  386.  
  387.         punpcklbw       xmm1, xmm1
  388.         punpcklbw       xmm1, xmm0
  389.         punpcklbw       xmm2, xmm0
  390.         punpcklbw       xmm3, xmm0
  391.  
  392.         psubsw          xmm3, xmm2
  393.         pmullw          xmm3, xmm1
  394.         psllw           xmm2, 8
  395.         paddw           xmm3, xmm2
  396.         pinsrw          xmm3, ebx, 3
  397.         shr             ebx, 8
  398.         pinsrw          xmm3, ebx, 7
  399.         psrlw           xmm3, 8
  400.         packuswb        xmm3, xmm0
  401.  
  402.         movq            [edi], xmm3
  403.         add             edi, 8
  404.         sub             ecx, 2
  405.         jns             .pixel
  406.         add             esi, [_img_total_bpl]
  407.         add             edi, [_bottom_total_bpl]
  408.         dec             [_copy_height]
  409.         jnz             .line
  410.   .done:
  411.         ret
  412. endp
  413.  
  414.  
  415. proc    xcf._.composite_gray_00 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
  416.  
  417.   .line:
  418.         mov             ecx, [_copy_width]
  419.   .pixel:
  420.         mov             bx, [edi]
  421.         lodsw
  422.         movd            xmm2, ebx
  423.         movd            xmm3, eax
  424.  
  425.         shr             eax, 8
  426.  
  427.         xchg            al, bh
  428.         mov             ah, bh
  429.         neg             ax
  430.         add             ax, 0xffff
  431.         mul             ah
  432.         neg             ah
  433.         add             ah, 0xff
  434.         xchg            ah, bh
  435.  
  436.         mov             al, 0xff
  437.         cmp             ah, bh
  438.         je              @f
  439.         not             al
  440.         div             bh
  441.     @@:
  442.  
  443.         mov             ah, al
  444.  
  445.         movd            xmm1, eax
  446.         pxor            xmm0, xmm0
  447.         punpcklbw       xmm1, xmm1
  448.         punpcklbw       xmm1, xmm0
  449.         punpcklbw       xmm2, xmm0
  450.         punpcklbw       xmm3, xmm0
  451.  
  452.         psubw           xmm3, xmm2
  453.         pmullw          xmm3, xmm1
  454.         psllw           xmm2, 8
  455.         paddw           xmm3, xmm2
  456.         pinsrw          xmm3, ebx, 1
  457.         psrlw           xmm3, 8
  458.         packuswb        xmm3, xmm0
  459.         movd            eax, xmm3
  460.         stosw
  461.  
  462.         dec             ecx
  463.         jnz             .pixel
  464.         add             esi, [_img_total_bpl]
  465.         add             edi, [_bottom_total_bpl]
  466.         dec             [_copy_height]
  467.         jnz             .line
  468.  
  469.         ret
  470. endp
  471.  
  472.  
  473. proc    xcf._.composite_indexed_00 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
  474.  
  475.   .line:
  476.         mov             ecx, [_copy_width]
  477.   .pixel:
  478.         mov             bx, [edi]
  479.         lodsw
  480.  
  481.         or              ah, 0x7f
  482.         test            ah, 0x80
  483.         jnz             @f
  484.         mov             ax, bx
  485.     @@:
  486.         stosw
  487.  
  488.         dec             ecx
  489.         jnz             .pixel
  490.         add             esi, [_img_total_bpl]
  491.         add             edi, [_bottom_total_bpl]
  492.         dec             [_copy_height]
  493.         jnz             .line
  494.         ret
  495. endp
  496.  
  497.  
  498. proc    xcf._.composite_rgb_01 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
  499.         pushad
  500.  
  501.         pxor            xmm4, xmm4
  502.         movd            xmm4, [xcf._.random_b]
  503.         movd            xmm1, [xcf._.random_a]
  504.         movd            xmm2, [xcf._.random_c]
  505.  
  506.   .line:
  507.         mov             ecx, [_copy_width]
  508.   .pixel:
  509.         mov             ebx, [edi]
  510.         lodsd
  511.  
  512.         movq            xmm0, xmm4
  513.         pmuludq         xmm0, xmm1
  514.         paddq           xmm0, xmm2
  515.         movd            edx, xmm0
  516.         movd            xmm4, edx
  517.         pxor            xmm0, xmm0
  518.  
  519.         rol             eax, 8
  520.         test            al, al
  521.         jz              @f
  522.         shr             edx, 17
  523.         cmp             dl, al
  524.         ja              @f
  525.         ror             eax, 8
  526.         or              eax, 0xff000000
  527.         jmp             .done
  528.     @@:
  529.         mov             eax, ebx
  530.   .done:
  531.         stosd
  532.         dec             ecx
  533.         jnz             .pixel
  534.         add             esi, [_img_total_bpl]
  535.         add             edi, [_bottom_total_bpl]
  536.         dec             [_copy_height]
  537.         jnz             .line
  538.  
  539.   .quit:
  540.         popad
  541.         ret
  542. endp
  543.  
  544.  
  545. proc    xcf._.composite_gray_01 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
  546.         pushad
  547.  
  548.         pxor            xmm4, xmm4
  549.         movd            xmm4, [xcf._.random_b]
  550.         movd            xmm1, [xcf._.random_a]
  551.         movd            xmm2, [xcf._.random_c]
  552.  
  553.   .line:
  554.         mov             ecx, [_copy_width]
  555.   .pixel:
  556.         mov             ebx, [edi]
  557.         lodsw
  558.  
  559.         movq            xmm0, xmm4
  560.         pmuludq         xmm0, xmm1
  561.         paddq           xmm0, xmm2
  562.         movd            edx, xmm0
  563.         movd            xmm4, edx
  564.         pxor            xmm0, xmm0
  565.  
  566.         test            ah, ah
  567.         jz              @f
  568.         shr             edx, 17
  569.         cmp             dl, ah
  570.         ja              @f
  571.         or              ax, 0xff00
  572.         jmp             .done
  573.     @@:
  574.         mov             eax, ebx
  575.   .done:
  576.         stosw
  577.         dec             ecx
  578.         jnz             .pixel
  579.         add             esi, [_img_total_bpl]
  580.         add             edi, [_bottom_total_bpl]
  581.         dec             [_copy_height]
  582.         jnz             .line
  583.  
  584.   .quit:
  585.         popad
  586.         ret
  587. endp
  588.  
  589.  
  590. proc    xcf._.composite_rgb_03                  ; Multiply
  591.  
  592.         punpcklbw       xmm2, xmm0
  593.         punpcklbw       xmm3, xmm0
  594.         pmullw          xmm3, xmm2
  595.         psrlw           xmm3, 8
  596.  
  597.         ret
  598. endp
  599.  
  600.  
  601. proc    xcf._.composite_rgb_04                  ; Screen
  602.  
  603.         punpcklbw       xmm2, xmm0
  604.         punpcklbw       xmm3, xmm0
  605.         movdqu          xmm4, xword[xcf._.xmm_00ff]
  606.         movdqa          xmm5, xmm4
  607.         psubw           xmm5, xmm3
  608.         movdqa          xmm3, xmm4
  609.         psubw           xmm4, xmm2
  610.         pmullw          xmm4, xmm5
  611.         psrlw           xmm4, 8
  612.         psubw           xmm3, xmm4
  613.         ret
  614. endp
  615.  
  616.  
  617. proc    xcf._.composite_rgb_05                  ; Overlay
  618.  
  619.         punpcklbw       xmm2, xmm0
  620.         punpcklbw       xmm3, xmm0
  621.         movdqu          xmm4, xword[xcf._.xmm_00ff]
  622.         psubw           xmm4, xmm2
  623.         pmullw          xmm3, xmm4
  624.         psrlw           xmm3, 7
  625.         paddw           xmm3, xmm2
  626.         pmullw          xmm3, xmm2
  627.         psrlw           xmm3, 8
  628.  
  629.         ret
  630. endp
  631.  
  632.  
  633. proc    xcf._.composite_rgb_06                  ; Difference
  634.  
  635.         movdqa          xmm4, xmm3
  636.         pminub          xmm4, xmm2
  637.         pmaxub          xmm3, xmm2
  638.         psubusb         xmm3, xmm4
  639.         punpcklbw       xmm2, xmm0
  640.         punpcklbw       xmm3, xmm0
  641.  
  642.         ret
  643. endp
  644.  
  645.  
  646. proc    xcf._.composite_rgb_07                  ; Addition
  647.  
  648.         paddusb         xmm3, xmm2
  649.         punpcklbw       xmm2, xmm0
  650.         punpcklbw       xmm3, xmm0
  651.  
  652.         ret
  653. endp
  654.  
  655.  
  656. proc    xcf._.composite_rgb_08                  ; Subtract
  657.  
  658.         movdqa          xmm4, xmm2
  659.         psubusb         xmm4, xmm3
  660.         movq            xmm3, xmm4
  661.         punpcklbw       xmm2, xmm0
  662.         punpcklbw       xmm3, xmm0
  663.  
  664.         ret
  665. endp
  666.  
  667.  
  668. proc    xcf._.composite_rgb_09                  ; Darken Only
  669.  
  670.         pminub          xmm3, xmm2
  671.         punpcklbw       xmm2, xmm0
  672.         punpcklbw       xmm3, xmm0
  673.  
  674.         ret
  675. endp
  676.  
  677.  
  678. proc    xcf._.composite_rgb_10                  ; Lighten Only
  679.  
  680.         pmaxub          xmm3, xmm2
  681.         punpcklbw       xmm2, xmm0
  682.         punpcklbw       xmm3, xmm0
  683.  
  684.         ret
  685. endp
  686.  
  687.  
  688. proc    xcf._.composite_rgb_11                  ; Hue (H of HSV)
  689.         push            eax ebx ecx edx
  690.  
  691.         movd            eax, xmm3
  692.         movd            ebx, xmm2
  693.  
  694.         call            xcf._.rgb2hsv
  695.         xchg            eax, ebx
  696.         call            xcf._.rgb2hsv
  697.         xchg            eax, ebx
  698.  
  699.         test            ah, ah
  700.         jnz             @f
  701.         ror             eax, 8
  702.         ror             ebx, 8
  703.         mov             ah, bh
  704.         rol             eax, 8
  705.         rol             ebx, 8
  706.     @@:
  707.         mov             ax, bx
  708.  
  709.         call            xcf._.hsv2rgb
  710.  
  711.         push            eax
  712.  
  713.         movq            xmm1, xmm3
  714.         psrldq          xmm1, 4
  715.         movd            eax, xmm1
  716.         movq            xmm1, xmm2
  717.         psrldq          xmm1, 4
  718.         movd            ebx, xmm1
  719.  
  720.         call            xcf._.rgb2hsv
  721.         xchg            eax, ebx
  722.         call            xcf._.rgb2hsv
  723.         xchg            eax, ebx
  724.  
  725.         test            ah, ah
  726.         jnz             @f
  727.         ror             eax, 8
  728.         ror             ebx, 8
  729.         mov             ah, bh
  730.         rol             eax, 8
  731.         rol             ebx, 8
  732.     @@:
  733.         mov             ax, bx
  734.  
  735.         call            xcf._.hsv2rgb
  736.  
  737.         movd            xmm3, eax
  738.         pslldq          xmm3, 4
  739.         pop             eax
  740.         movd            xmm1, eax
  741.         paddq           xmm3, xmm1
  742.  
  743.         punpcklbw       xmm2, xmm0
  744.         punpcklbw       xmm3, xmm0
  745.  
  746.   .quit:
  747.         pop             edx ecx ebx eax
  748.         ret
  749. endp
  750.  
  751.  
  752. proc    xcf._.composite_rgb_12                  ; Saturation (S of HSV)
  753.         push            eax ebx ecx edx
  754.  
  755.         movd            eax, xmm3
  756.         movd            ebx, xmm2
  757.  
  758.         call            xcf._.rgb2hsv
  759.         xchg            eax, ebx
  760.         call            xcf._.rgb2hsv
  761.         xchg            eax, ebx
  762.  
  763.         ror             eax, 8
  764.         ror             ebx, 8
  765.         mov             ah, bh
  766.         rol             eax, 8
  767.         rol             ebx, 8
  768.         mov             al, bl
  769.  
  770.         call            xcf._.hsv2rgb
  771.  
  772.         push            eax
  773.         movq            xmm1, xmm3
  774.         psrldq          xmm1, 4
  775.         movd            eax, xmm1
  776.         movq            xmm1, xmm2
  777.         psrldq          xmm1, 4
  778.         movd            ebx, xmm1
  779.  
  780.         call            xcf._.rgb2hsv
  781.         xchg            eax, ebx
  782.         call            xcf._.rgb2hsv
  783.         xchg            eax, ebx
  784.  
  785.         ror             eax, 8
  786.         ror             ebx, 8
  787.         mov             ah, bh
  788.         rol             eax, 8
  789.         rol             ebx, 8
  790.         mov             al, bl
  791.  
  792.         call            xcf._.hsv2rgb
  793.  
  794.  
  795.         movd            xmm3, eax
  796.         pslldq          xmm3, 4
  797.         pop             eax
  798.         movd            xmm1, eax
  799.         paddq           xmm3, xmm1
  800.  
  801.         punpcklbw       xmm2, xmm0
  802.         punpcklbw       xmm3, xmm0
  803.  
  804.   .quit:
  805.         pop             edx ecx ebx eax
  806.         ret
  807. endp
  808.  
  809.  
  810. proc    xcf._.composite_rgb_13                  ; Color (H and S of HSL)
  811.         push            eax ebx ecx edx
  812.  
  813.         movd            eax, xmm3
  814.         movd            ebx, xmm2
  815.  
  816.         call            xcf._.rgb2hsl
  817.         xchg            eax,    ebx
  818.         call            xcf._.rgb2hsl
  819.         xchg            eax,    ebx
  820.  
  821.         mov             al, bl
  822.  
  823.         call            xcf._.hsl2rgb
  824.  
  825.         push            eax
  826.         movq            xmm1, xmm3
  827.         psrldq          xmm1, 4
  828.         movd            eax, xmm1
  829.         movq            xmm1, xmm2
  830.         psrldq          xmm1, 4
  831.         movd            ebx, xmm1
  832.  
  833.         call            xcf._.rgb2hsl
  834.         xchg            eax,    ebx
  835.         call            xcf._.rgb2hsl
  836.         xchg            eax,    ebx
  837.  
  838.         mov             al, bl
  839.  
  840.         call            xcf._.hsl2rgb
  841.  
  842.         movd            xmm3, eax
  843.         pslldq          xmm3, 4
  844.         pop             eax
  845.         movd            xmm1, eax
  846.         paddq           xmm3, xmm1
  847.  
  848.         punpcklbw       xmm2, xmm0
  849.         punpcklbw       xmm3, xmm0
  850.  
  851.   .quit:
  852.         pop             edx ecx ebx eax
  853.         ret
  854. endp
  855.  
  856.  
  857. proc    xcf._.composite_rgb_14                  ; Value (V of HSV)
  858.         push            eax ebx ecx edx
  859.  
  860.         movd            eax, xmm3
  861.         movd            ebx, xmm2
  862.  
  863.         call            xcf._.rgb2hsv
  864.         xchg            eax, ebx
  865.         call            xcf._.rgb2hsv
  866.         xchg            eax, ebx
  867.  
  868.         ror             eax, 8
  869.         ror             ebx, 8
  870.         mov             ax, bx
  871.         rol             eax, 8
  872.         rol             ebx, 8
  873.  
  874.         call            xcf._.hsv2rgb
  875.  
  876.         push            eax
  877.         movq            xmm1, xmm3
  878.         psrldq          xmm1, 4
  879.         movd            eax, xmm1
  880.         movq            xmm1, xmm2
  881.         psrldq          xmm1, 4
  882.         movd            ebx, xmm1
  883.  
  884.         call            xcf._.rgb2hsv
  885.         xchg            eax, ebx
  886.         call            xcf._.rgb2hsv
  887.         xchg            eax, ebx
  888.  
  889.         ror             eax, 8
  890.         ror             ebx, 8
  891.         mov             ax, bx
  892.         rol             eax, 8
  893.         rol             ebx, 8
  894.  
  895.         call            xcf._.hsv2rgb
  896.  
  897.         movd            xmm3, eax
  898.         pslldq          xmm3, 4
  899.         pop             eax
  900.         movd            xmm1, eax
  901.         paddq           xmm3, xmm1
  902.  
  903.         punpcklbw       xmm2, xmm0
  904.         punpcklbw       xmm3, xmm0
  905.  
  906.   .quit:
  907.         pop             edx ecx ebx eax
  908.         ret
  909. endp
  910.  
  911.  
  912. proc    xcf._.composite_rgb_15                  ; Divide
  913.         push            eax ebx ecx
  914.  
  915.         movd            eax, xmm3
  916.         movd            ebx, xmm2
  917.  
  918.         rol             eax, 8
  919.         rol             ebx, 8
  920.  
  921.         xchg            eax, ebx
  922.  
  923.         mov             ecx, 3
  924.  
  925.   .color:
  926.         rol             eax, 8
  927.         rol             ebx, 8
  928.         shl             ax, 8
  929.         test            bl, bl
  930.         jz              .clamp1
  931.         cmp             ah, bl
  932.         jae             .clamp2
  933.         div             bl
  934.         jmp             .done
  935.   .clamp1:
  936.         mov             al, 0xff
  937.         test            ah, ah
  938.         jnz             @f
  939.         not             al
  940.     @@:
  941.         jmp             .done
  942.   .clamp2:
  943.         mov             al, 0xff
  944.         jmp             .done
  945.   .done:
  946.         mov             ah, al
  947.         loop            .color
  948.  
  949.         ror             eax, 8
  950.  
  951.  
  952.         push            eax
  953.         movq            xmm1, xmm3
  954.         psrldq          xmm1, 4
  955.         movd            eax, xmm1
  956.         movq            xmm1, xmm2
  957.         psrldq          xmm1, 4
  958.         movd            ebx, xmm1
  959.  
  960.  
  961.         rol             eax, 8
  962.         rol             ebx, 8
  963.  
  964.         xchg            eax, ebx
  965.  
  966.         mov             ecx, 3
  967.  
  968.   .color2:
  969.         rol             eax, 8
  970.         rol             ebx, 8
  971.         shl             ax, 8
  972.         test            bl, bl
  973.         jz              .clamp12
  974.         cmp             ah, bl
  975.         jae             .clamp22
  976.         div             bl
  977.         jmp             .done2
  978.   .clamp12:
  979.         mov             al, 0xff
  980.         test            ah, ah
  981.         jnz             @f
  982.         not             al
  983.     @@:
  984.         jmp             .done2
  985.   .clamp22:
  986.         mov             al, 0xff
  987.         jmp             .done2
  988.   .done2:
  989.         mov             ah, al
  990.         loop            .color2
  991.  
  992.         ror             eax, 8
  993.  
  994.  
  995.         movd            xmm3, eax
  996.         pslldq          xmm3, 4
  997.         pop             eax
  998.         movd            xmm1, eax
  999.         paddq           xmm3, xmm1
  1000.  
  1001.         punpcklbw       xmm2, xmm0
  1002.         punpcklbw       xmm3, xmm0
  1003.  
  1004.         pop             ecx ebx eax
  1005.         ret
  1006. endp
  1007.  
  1008.  
  1009. proc    xcf._.composite_rgb_16                  ; Dodge
  1010.         push            eax ebx ecx
  1011.  
  1012.         movd            eax, xmm3
  1013.         movd            ebx, xmm2
  1014.  
  1015.         rol             eax, 8
  1016.         rol             ebx, 8
  1017.  
  1018.         xchg            eax, ebx
  1019.  
  1020.         mov             ecx, 3
  1021.  
  1022.   .color:
  1023.         rol             eax, 8
  1024.         rol             ebx, 8
  1025.         shl             ax, 8
  1026.         neg             bl
  1027.         add             bl, 0xff
  1028.         test            bl, bl
  1029.         jz              .clamp1
  1030.         cmp             ah,  bl
  1031.         jae             .clamp2
  1032.         div             bl
  1033.         jmp             .done
  1034.   .clamp1:
  1035.         mov             al, 0xff
  1036.         test            ah, ah
  1037.         jnz             @f
  1038.         not             al
  1039.     @@:
  1040.         jmp             .done
  1041.   .clamp2:
  1042.         mov             al, 0xff
  1043.         jmp             .done
  1044.   .done:
  1045.         mov             ah, al
  1046.         loop            .color
  1047.  
  1048.         ror             eax, 8
  1049.  
  1050.  
  1051.         push            eax
  1052.         movq            xmm1, xmm3
  1053.         psrldq          xmm1, 4
  1054.         movd            eax, xmm1
  1055.         movq            xmm1, xmm2
  1056.         psrldq          xmm1, 4
  1057.         movd            ebx, xmm1
  1058.  
  1059.  
  1060.         rol             eax, 8
  1061.         rol             ebx, 8
  1062.  
  1063.         xchg            eax, ebx
  1064.  
  1065.         mov             ecx, 3
  1066.  
  1067.   .color2:
  1068.         rol             eax, 8
  1069.         rol             ebx, 8
  1070.         shl             ax, 8
  1071.         neg             bl
  1072.         add             bl, 0xff
  1073.         test            bl, bl
  1074.         jz              .clamp12
  1075.         cmp             ah,  bl
  1076.         jae             .clamp22
  1077.         div             bl
  1078.         jmp             .done2
  1079.   .clamp12:
  1080.         mov             al, 0xff
  1081.         test            ah, ah
  1082.         jnz             @f
  1083.         not             al
  1084.     @@:
  1085.         jmp             .done2
  1086.   .clamp22:
  1087.         mov             al, 0xff
  1088.         jmp             .done2
  1089.   .done2:
  1090.         mov             ah, al
  1091.         loop            .color2
  1092.  
  1093.         ror             eax, 8
  1094.  
  1095.  
  1096.         movd            xmm3, eax
  1097.         pslldq          xmm3, 4
  1098.         pop             eax
  1099.         movd            xmm1, eax
  1100.         paddq           xmm3, xmm1
  1101.  
  1102.         punpcklbw       xmm2, xmm0
  1103.         punpcklbw       xmm3, xmm0
  1104.  
  1105.         pop             ecx ebx eax
  1106.         ret
  1107. endp
  1108.  
  1109.  
  1110. proc    xcf._.composite_rgb_17                  ; Burn
  1111.         push            eax ebx ecx
  1112.  
  1113.         movd            eax, xmm3
  1114.         movd            ebx, xmm2
  1115.  
  1116.         rol             eax, 8
  1117.         rol             ebx, 8
  1118.  
  1119.         xchg            eax, ebx
  1120.  
  1121.         mov             ecx, 3
  1122.  
  1123.   .color:
  1124.         rol             eax, 8
  1125.         rol             ebx, 8
  1126.         shl             ax, 8
  1127.         neg             ah
  1128.         add             ah, 0xff
  1129.         test            bl, bl
  1130.         jz              .clamp1
  1131.         cmp             ah, bl
  1132.         jae             .clamp2
  1133.         div             bl
  1134.         jmp             .done
  1135.   .clamp1:
  1136.         mov             al, 0xff
  1137.         test            ah, ah
  1138.         jnz             @f
  1139.         not             al
  1140.     @@:
  1141.         jmp             .done
  1142.   .clamp2:
  1143.         mov             al, 0xff
  1144.         jmp             .done
  1145.   .done:
  1146.         mov             ah, al
  1147.         neg             ah
  1148.         add             ah, 0xff
  1149.         loop            .color
  1150.  
  1151.         ror             eax, 8
  1152.  
  1153.  
  1154.         push            eax
  1155.         movq            xmm1, xmm3
  1156.         psrldq          xmm1, 4
  1157.         movd            eax, xmm1
  1158.         movq            xmm1, xmm2
  1159.         psrldq          xmm1, 4
  1160.         movd            ebx, xmm1
  1161.  
  1162.  
  1163.         rol             eax, 8
  1164.         rol             ebx, 8
  1165.  
  1166.         xchg            eax, ebx
  1167.  
  1168.         mov             ecx, 3
  1169.  
  1170.   .color2:
  1171.         rol             eax, 8
  1172.         rol             ebx, 8
  1173.         shl             ax, 8
  1174.         neg             ah
  1175.         add             ah, 0xff
  1176.         test            bl, bl
  1177.         jz              .clamp12
  1178.         cmp             ah, bl
  1179.         jae             .clamp22
  1180.         div             bl
  1181.         jmp             .done2
  1182.   .clamp12:
  1183.         mov             al, 0xff
  1184.         test            ah, ah
  1185.         jnz             @f
  1186.         not             al
  1187.     @@:
  1188.         jmp             .done2
  1189.   .clamp22:
  1190.         mov             al, 0xff
  1191.         jmp             .done2
  1192.   .done2:
  1193.         mov             ah, al
  1194.         neg             ah
  1195.         add             ah, 0xff
  1196.         loop            .color2
  1197.  
  1198.         ror             eax, 8
  1199.  
  1200.  
  1201.         movd            xmm3, eax
  1202.         pslldq          xmm3, 4
  1203.         pop             eax
  1204.         movd            xmm1, eax
  1205.         paddq           xmm3, xmm1
  1206.  
  1207.         punpcklbw       xmm2, xmm0
  1208.         punpcklbw       xmm3, xmm0
  1209.  
  1210.         pop             ecx ebx eax
  1211.         ret
  1212. endp
  1213.  
  1214.  
  1215. proc    xcf._.composite_rgb_18                  ; Hard Light
  1216.         push            eax ebx ecx
  1217.  
  1218.         movd            eax, xmm3
  1219.         movd            ebx, xmm2
  1220.  
  1221.         rol             eax, 8
  1222.         rol             ebx, 8
  1223.  
  1224.         mov             ecx, 3
  1225.  
  1226.   .color:
  1227.         rol             eax, 8
  1228.         rol             ebx, 8
  1229.         cmp             al, 127
  1230.         jna             .part1
  1231.         mov             ah, 0xff
  1232.         sub             ah, bl
  1233.         neg             al
  1234.         add             al, 0xff
  1235.         mul             ah
  1236.         shl             ax, 1
  1237.         neg             ah
  1238.         add             ah, 0xff
  1239.         jmp             .done
  1240.   .part1:
  1241.         mul             bl
  1242.         shl             ax, 1
  1243.   .done:
  1244.         loop            .color
  1245.  
  1246.         ror             eax, 8
  1247.  
  1248.  
  1249.         push            eax
  1250.         movq            xmm1, xmm3
  1251.         psrldq          xmm1, 4
  1252.         movd            eax, xmm1
  1253.         movq            xmm1, xmm2
  1254.         psrldq          xmm1, 4
  1255.         movd            ebx, xmm1
  1256.  
  1257.  
  1258.         rol             eax, 8
  1259.         rol             ebx, 8
  1260.  
  1261.         mov             ecx, 3
  1262.  
  1263.   .color2:
  1264.         rol             eax, 8
  1265.         rol             ebx, 8
  1266.         cmp             al, 127
  1267.         jna             .part12
  1268.         mov             ah, 0xff
  1269.         sub             ah, bl
  1270.         neg             al
  1271.         add             al, 0xff
  1272.         mul             ah
  1273.         shl             ax, 1
  1274.         neg             ah
  1275.         add             ah, 0xff
  1276.         jmp             .done2
  1277.   .part12:
  1278.         mul             bl
  1279.         shl             ax, 1
  1280.   .done2:
  1281.         loop            .color2
  1282.  
  1283.         ror             eax, 8
  1284.  
  1285.  
  1286.         movd            xmm3, eax
  1287.         pslldq          xmm3, 4
  1288.         pop             eax
  1289.         movd            xmm1, eax
  1290.         paddq           xmm3, xmm1
  1291.  
  1292.         punpcklbw       xmm2, xmm0
  1293.         punpcklbw       xmm3, xmm0
  1294.  
  1295.         pop             ecx ebx eax
  1296.         ret
  1297. endp
  1298.  
  1299.  
  1300. proc    xcf._.composite_rgb_20                  ; Grain Extract
  1301.  
  1302.         punpcklbw       xmm2, xmm0
  1303.         punpcklbw       xmm3, xmm0
  1304.         movdqu          xmm4, xmm2
  1305.         psubw           xmm3, xword[xcf._.xmm_0080]
  1306.         psubw           xmm4, xmm3
  1307.         movdqa          xmm3, xmm4
  1308.         packuswb        xmm3, xmm0
  1309.         punpcklbw       xmm3, xmm0
  1310.         ret
  1311. endp
  1312.  
  1313.  
  1314. proc    xcf._.composite_rgb_21                  ; Grain Merge
  1315.  
  1316.         punpcklbw       xmm2, xmm0
  1317.         punpcklbw       xmm3, xmm0
  1318.         paddw           xmm3, xmm2
  1319.         psubusw         xmm3, xword[xcf._.xmm_0080]
  1320.         packuswb        xmm3, xmm0
  1321.         punpcklbw       xmm3, xmm0
  1322.         ret
  1323. endp
  1324.  
  1325.  
  1326. ; starting numbers for pseudo-random number generator
  1327. xcf._.random_a          dd      1103515245
  1328. xcf._.random_b          dd      777
  1329. xcf._.random_c          dd      12345
  1330.  
  1331. xcf._.xmm_8080          dq      0x8080808080808080, 0x8080808080808080
  1332. xcf._.xmm_0080          dq      0x0080008000800080, 0x0080008000800080
  1333. xcf._.xmm_00ff          dq      0x00ff00ff00ff00ff, 0x00ff00ff00ff00ff
  1334. xcf._.xmm_0100          dq      0x0100010001000100, 0x0100010001000100
  1335. xcf._.xmm_000000ff      dq      0x000000ff000000ff, 0x0000000000000000
  1336.