home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Converter / IMAFX26.lha / imagefx2 / rexx / Find.ifx < prev    next >
Encoding:
Text File  |  1992-09-21  |  1.1 KB  |  63 lines

  1. /*
  2.  * $VER: Find 1.00.00 (24.9.92)
  3.  *
  4.  * Arexx program for the ImageFX image processing system.
  5.  * Written by Thomas Krehbiel
  6.  *
  7.  * This program will find and activate the nearest palette color for
  8.  * the pixel that the user clicks the mouse over.  Demonstrates the use
  9.  * of the WAITFOR command.
  10.  *
  11.  */
  12.  
  13. OPTIONS RESULTS
  14.  
  15. /* Save current color, because we're going to trash it */
  16. GetPalette '-1'
  17. PARSE VAR result oldr oldg oldb
  18.  
  19. LockInput ; LockGui
  20.  
  21. /* Pick color, wait for user to pick something */
  22. Pick
  23. WaitFor SELECTUP
  24.  
  25. /* Find out what we got, save it */
  26. GetPalette '-1'
  27. PARSE VAR result dstr dstg dstb
  28.  
  29. /* Restore original palette color */
  30. SetPalette '-1' oldr oldg oldb
  31.  
  32. UnlockGui
  33.  
  34. /* Now look through the palette for the closest match.  This is
  35.    a fairly elementary matching routine, since we don't happen
  36.    to have square roots available in standard REXX. */
  37.  
  38. bestdist = 999999
  39. bestcol = 0
  40.  
  41. BeginBar 'Finding' 1
  42.  
  43. DO i = 0 TO 31
  44.  
  45.    GetPalette i
  46.    PARSE VAR result r g b
  47.  
  48.    dist = ABS(r - dstr) + ABS(g - dstg) + ABS(b - dstb)
  49.    IF dist < bestdist THEN DO
  50.       bestdist = dist
  51.       bestcol = i
  52.       END
  53.  
  54.    END
  55.  
  56. EndBar
  57.  
  58. ActiveColor bestcol
  59.  
  60. UnlockInput
  61.  
  62. EXIT
  63.