home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / gprocs / rgbcomp.icn < prev    next >
Text File  |  2000-07-29  |  2KB  |  99 lines

  1. ############################################################################
  2. #
  3. #    File:     rgbcomp.icn
  4. #
  5. #    Subject:  Procedures to perform computations on RGB values
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     January 14, 1995
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  rgbsum(s1, s2) returns a color whose RGB components are the sums of the
  18. #  components for s1 and s2.
  19. #
  20. #  rgbdif(s1, s2) returns a color whose RGB components are the differences of
  21. #  the components for s1 and s2. 
  22. #
  23. #  rgbavg(s1, s2) returns a color whose RGB components are the averages of
  24. #  the components for s1 and s2.
  25. #
  26. #  rsgcomp(s) returns the color that is the complement of s.
  27. #
  28. #  The results may not be what's expected in some cases.
  29. #
  30. ############################################################################
  31. #
  32. #  Requires:   Version 9 graphics
  33. #
  34. ############################################################################
  35. #
  36. #  Links:  numbers, rgbrec
  37. #
  38. ############################################################################
  39.  
  40. link numbers
  41. link rgbrec
  42.  
  43. $define MaxIntensity (2 ^ 16 - 1)
  44.  
  45. procedure rgbsum(s1, s2)
  46.    local rgb1, rgb2
  47.  
  48.     rgb1 := rgbrec(s1) | fail
  49.     rgb2 := rgbrec(s2) | fail
  50.  
  51.    return rgbrec(
  52.       max(rgb1.r + rgb2.r, MaxIntensity),
  53.       max(rgb1.g + rgb2.g, MaxIntensity),
  54.       max(rgb1.b + rgb2.b, MaxIntensity)
  55.       )
  56.  
  57. end
  58.  
  59. procedure rgbdif(s1, s2)
  60.    local rgb1, rgb2
  61.  
  62.     rgb1 := rgbrec(s1) | fail
  63.     rgb2 := rgbrec(s2) | fail
  64.  
  65.    return rgbrec(
  66.       min(rgb1.r - rgb2.r, 0),
  67.       min(rgb1.g - rgb2.g, 0),
  68.       min(rgb1.b - rgb2.b)
  69.       )
  70.  
  71. end
  72.  
  73. procedure rgbavg(s1, s2)
  74.    local rgb1, rgb2
  75.  
  76.     rgb1 := rgbrec(s1) | fail
  77.     rgb2 := rgbrec(s2) | fail
  78.  
  79.    return rgbrec(
  80.       (rgb1.r + rgb2.r) / 2,
  81.       (rgb1.g + rgb2.g) / 2,
  82.       (rgb1.b + rgb2.b) / 2
  83.       )
  84.  
  85. end
  86.  
  87. procedure rgbcomp(s)
  88.    local rgb
  89.  
  90.     rgb := rgbrec(s) | fail
  91.  
  92.    return rgbrec(
  93.       MaxIntensity - rgb.r,
  94.       MaxIntensity - rgb.g,
  95.       MaxIntensity - rgb.b
  96.       )
  97.  
  98. end
  99.