home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 June / Chip_2002-06_cd1.bin / tema / grafika_plugin / install / FlipsRolls / fliproll.exe / Main / rgbbgr.asm < prev    next >
Encoding:
Assembly Source File  |  2002-05-06  |  4.7 KB  |  261 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;
  3. ;; rgbbgr.asm
  4. ;;
  5. ;; Copyright 1999 G. Adam Stanislav
  6. ;; All rights reserved
  7. ;;
  8. ;; Started: 17-Nov-1999
  9. ;; Updated: 17-Nov-1999
  10. ;;
  11. ;; This is a Photoshop plugin which switches the red and the blue channels
  12. ;; of an image, while leaving the green channel intact.
  13. ;;
  14. ;; This source code can be assembled by NASM:
  15. ;;
  16. ;;    nasm -f win32 rgbbgr.asm
  17. ;;
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19.  
  20. %include    'filter.inc'
  21.  
  22. global    filter.parameters, filter.prepare, filter.start
  23. global    filter.continue, filter.finish
  24.  
  25. section    .drectve    info
  26. db    "-out:rpRGBBGR.8bf "
  27.  
  28. section    .data
  29. total    dd    0
  30. partial    dd    0
  31. global    filter.name
  32. filter.name    db    "Flip Red and Blue", 0
  33.  
  34. section    .text align=4
  35.  
  36.     ; These procedures receive four parameters:
  37.     ;
  38.     ;    [esp+ 4] = selector (word) = EAX
  39.     ;    [esp+ 8] = address of filterParamBlock
  40.     ;    [esp+12] = address of data
  41.     ;    [esp+16] = address of result word, contains 0 (success)
  42.  
  43. align 4
  44. error.return:
  45.     mov    ecx, [esp+16]
  46.     mov    word [ecx], filterBadParameters
  47.     ret
  48.  
  49. align 4
  50. filter.start:
  51.     ; Get the pointer to the parameter block
  52.     mov    ecx, [esp+8]
  53.  
  54.     ; Quit if NULL.
  55.     jecxz    error.return
  56.  
  57.     ; Tell the host to give us r,g,b planes
  58.     mov    eax, 2 << 16
  59.     mov    [ecx+inLoPlane], eax
  60.     mov    [ecx+outLoPlane], eax
  61.  
  62.     ; Calculate the total number of pixels
  63.     movzx    eax, word [ecx+filterRect+right]
  64.     sub    ax, [ecx+filterRect+left]
  65.     movzx    edx, word [ecx+filterRect+bottom]
  66.     sub    dx, [ecx+filterRect+top]
  67.     mul    edx
  68.     mov    [total], eax
  69.     sub    edx, edx
  70.     mov    [partial], edx
  71.  
  72.     ; Ask the host for a NUMCOLSxNUMROWS input and output data. Less if the
  73.     ; image is small.
  74.     movzx    eax, word [ecx+filterRect+right]
  75.     movzx    edx, word [ecx+filterRect+left]
  76.     sub    ax, dx
  77.  
  78.     cmp    ax, NUMCOLS
  79.     jb    .X
  80.     mov    ax, NUMCOLS-1
  81.  
  82. .X:
  83.     mov    [ecx+inRect+left], dx
  84.     mov    [ecx+outRect+left], dx
  85.     add    ax, dx
  86.     mov    [ecx+inRect+right], ax
  87.     mov    [ecx+outRect+right], ax
  88.  
  89.     mov    ax, [ecx+filterRect+bottom]
  90.     mov    dx, [ecx+filterRect+top]
  91.     sub    ax, dx
  92.  
  93.     cmp    ax, NUMROWS
  94.     jb    .Y
  95.     mov    ax, NUMROWS-1
  96.  
  97. .Y:
  98.     mov    [ecx+inRect+top], dx
  99.     mov    [ecx+outRect+top], dx
  100.     add    ax, dx
  101.     mov    [ecx+inRect+bottom], ax
  102.     mov    [ecx+outRect+bottom], ax
  103.  
  104.     ret
  105.  
  106. align 4
  107. filter.continue:
  108.  
  109.     mov    ecx, [esp+8]
  110.     or    ecx, ecx
  111.     je    near error.return
  112.  
  113.     ; Calculate how far we are
  114.     movzx    eax, word [ecx+inRect+right]
  115.     sub    ax, [ecx+inRect+left]
  116.     movzx    edx, word [ecx+inRect+bottom]
  117.     sub    dx, [ecx+inRect+top]
  118.     mul    edx
  119.     add    [partial], eax
  120.  
  121.     push    ecx
  122.     push    dword [total]
  123.     push    dword [partial]
  124.     call    [ecx+progressProc]
  125.     add    esp, 8
  126.     pop    edx
  127.  
  128.     push    esi
  129.     push    edi
  130.  
  131.     mov    esi, [edx+inData]
  132.     mov    edi, [edx+outData]
  133.  
  134.     movzx    ecx, word [edx+inRect+bottom]
  135.     sub    cx, [edx+inRect+top]
  136.  
  137.     sub    eax, eax
  138.     cld
  139.  
  140.     ; ECX = number of rows
  141.  
  142. .bigloop:
  143.     push    ecx
  144.  
  145.     mov    cx, word [edx+inRect+right]
  146.     sub    cx, [edx+inRect+left]
  147.  
  148.     ; ECX = number of columns
  149.  
  150.     push    esi
  151.     push    edi
  152.     push    edx
  153.  
  154. .filterloop:
  155.     lodsb
  156.     mov    ah, al
  157.     lodsb
  158.     mov    dl, al
  159.     lodsb
  160.     
  161.     stosb
  162.     mov    al, dl
  163.     stosb
  164.     mov    al, ah
  165.     stosb
  166.  
  167.     loop    .filterloop
  168.  
  169.     pop    edx
  170.     pop    edi
  171.     pop    esi
  172.  
  173.     add    esi, [edx+inRowBytes]
  174.     add    edi, [edx+outRowBytes]
  175.     pop    ecx
  176.     loop    .bigloop
  177.  
  178.     pop    edi
  179.     pop    esi
  180.  
  181.     mov    ecx, edx
  182.  
  183.     ; See if there are more columns to process within these rows.
  184.     movzx    eax, word [ecx+inRect+right]
  185.     cmp    ax, [ecx+filterRect+right]
  186.     jae    .rows
  187.  
  188. .left:
  189.     mov    [ecx+inRect+left], ax
  190.     mov    [ecx+outRect+left], ax
  191.     add    ax, NUMCOLS-1
  192.     cmp    ax, [ecx+filterRect+right]
  193.     jbe    .right
  194.     mov    ax, [ecx+filterRect+right]
  195.  
  196. .right:
  197.     mov    [ecx+inRect+right], ax
  198.     mov    [ecx+outRect+right], ax
  199.  
  200.     ret
  201.  
  202. .rows:
  203.     ; See if there are any unprocessed rows
  204.     movzx    eax, word [ecx+inRect+bottom]
  205.     cmp    ax, [ecx+filterRect+bottom]
  206.     jae    filter.cleanup    ; all done
  207.     mov    [ecx+inRect+top], ax
  208.     mov    [ecx+outRect+top], ax
  209.     add    ax, NUMROWS-1
  210.     cmp    ax, [ecx+filterRect+bottom]
  211.     jbe    .bottom
  212.     mov    ax, [ecx+filterRect+bottom]
  213.  
  214. .bottom:
  215.     mov    [ecx+inRect+bottom], ax
  216.     mov    [ecx+outRect+bottom], ax
  217.  
  218.     movzx    eax, word [ecx+filterRect+left]
  219.     jmp    .left
  220.  
  221.  
  222. align 4
  223. filter.cleanup:
  224.     sub    eax, eax
  225.     mov    [ecx+inRect], eax
  226.     mov    [ecx+inRect+4], eax
  227.     mov    [ecx+outRect], eax
  228.     mov    [ecx+outRect+4], eax
  229.     mov    [ecx+inLoPlane], eax
  230.     mov    [ecx+outLoPlane], eax
  231.  
  232. .done:
  233.     ret
  234.  
  235. align 4
  236. filter.prepare:
  237.     mov    ecx, [esp+8]
  238.     or    ecx, ecx
  239.     jz    near error.return
  240.  
  241.     mov    eax, NUMROWS*NUMCOLS*4
  242.     cmp    eax, [ecx+maxSpace]
  243.     ja    near error.return
  244.     mov    [ecx+maxSpace], eax
  245.     sub    eax, eax
  246.     mov    [ecx+bufferSpace], eax
  247.  
  248.     ; FALL THROUGH
  249.  
  250. filter.finish:
  251.     ; Nothing to finish. Just return.
  252.  
  253.     ; FALL THROUGH
  254.  
  255. filter.parameters:
  256.     ; No parameters required. Just return.
  257.  
  258.     ret
  259.  
  260. align 4
  261.