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

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