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