91
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
118
|
13 |
SequenceableCollection subclass:#Colormap
|
572
|
14 |
instanceVariableNames:'redVector greenVector blueVector'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Graphics-Images support'
|
91
|
18 |
!
|
|
19 |
|
|
20 |
!Colormap class methodsFor:'documentation'!
|
|
21 |
|
|
22 |
copyright
|
|
23 |
"
|
|
24 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
25 |
All Rights Reserved
|
|
26 |
|
|
27 |
This software is furnished under a license and may be used
|
|
28 |
only in accordance with the terms of that license and with the
|
|
29 |
inclusion of the above copyright notice. This software may not
|
|
30 |
be provided or otherwise made available to, or used by, any
|
|
31 |
other person. No title to or ownership of the software is
|
|
32 |
hereby transferred.
|
|
33 |
"
|
|
34 |
!
|
|
35 |
|
|
36 |
documentation
|
|
37 |
"
|
|
38 |
Colormaps are used with images (and Forms) to keep the byte-to-color
|
|
39 |
mapping.
|
|
40 |
Internally, the values are stored as 3 separate byte-arrays
|
|
41 |
(i.e. individual components can be 0..255).
|
|
42 |
"
|
|
43 |
! !
|
|
44 |
|
|
45 |
!Colormap class methodsFor:'instance creation'!
|
|
46 |
|
118
|
47 |
fromColors:aColorArray
|
|
48 |
|n rV gV bV|
|
|
49 |
|
|
50 |
n := aColorArray size.
|
|
51 |
rV := ByteArray new:n.
|
|
52 |
gV := ByteArray new:n.
|
|
53 |
bV := ByteArray new:n.
|
|
54 |
1 to:n do:[:i |
|
|
55 |
|clr|
|
|
56 |
|
|
57 |
clr := aColorArray at:i.
|
|
58 |
rV at:i put:(clr red * 255 / 100) rounded.
|
|
59 |
bV at:i put:(clr green * 255 / 100) rounded.
|
|
60 |
gV at:i put:(clr blue * 255 / 100) rounded.
|
|
61 |
].
|
|
62 |
^ self new redVector:rV greenVector:gV blueVector:bV
|
|
63 |
|
|
64 |
"
|
|
65 |
Colormap
|
|
66 |
fromColors:(Array with:Color black
|
|
67 |
with:Color red
|
|
68 |
with:Color white)
|
|
69 |
"
|
91
|
70 |
!
|
|
71 |
|
|
72 |
redVector:r greenVector:g blueVector:b
|
285
|
73 |
^ self new redVector:r greenVector:g blueVector:b
|
91
|
74 |
|
285
|
75 |
"
|
|
76 |
Colormap
|
|
77 |
redVector:#[0 127 255]
|
|
78 |
greenVector:#[0 127 255]
|
|
79 |
blueVector:#[0 127 255]
|
|
80 |
"
|
|
81 |
! !
|
91
|
82 |
|
285
|
83 |
!Colormap methodsFor:'accessing'!
|
91
|
84 |
|
|
85 |
at:index
|
|
86 |
"return the color at index - notice, that index is a typically derived
|
|
87 |
from an images pixel value which ranges 0..255; while the index here
|
|
88 |
starts at 1 (to make colormap look more like a collection)."
|
|
89 |
|
|
90 |
|r g b|
|
|
91 |
r := redVector at:index.
|
|
92 |
g := greenVector at:index.
|
|
93 |
b := blueVector at:index.
|
|
94 |
^ Color
|
|
95 |
red:(r * 100 / 255)
|
|
96 |
green:(g * 100 / 255)
|
|
97 |
blue:(b * 100 / 255)
|
|
98 |
!
|
|
99 |
|
|
100 |
at:index put:aColor
|
572
|
101 |
"set the color at index to aColor. Return aColor (sigh).
|
|
102 |
- notice, that a color index is a typically derived
|
|
103 |
from an images pixel value which ranges 0..255;
|
|
104 |
while the index here starts at 1
|
|
105 |
(to make colormap look more like a collection).
|
|
106 |
Therefore, to modify a colorMap entry for pixel i, change
|
|
107 |
the colorMaps slot at i+1."
|
91
|
108 |
|
|
109 |
|r g b|
|
572
|
110 |
|
91
|
111 |
r := (aColor red * 255 / 100) rounded.
|
|
112 |
g := (aColor green * 255 / 100) rounded.
|
|
113 |
b := (aColor blue * 255 / 100) rounded.
|
|
114 |
redVector at:index put:r.
|
|
115 |
greenVector at:index put:g.
|
|
116 |
blueVector at:index put:b.
|
572
|
117 |
^ aColor
|
|
118 |
|
|
119 |
"Modified: 19.4.1996 / 11:19:04 / cg"
|
118
|
120 |
!
|
91
|
121 |
|
285
|
122 |
blueAt:index
|
|
123 |
"return the blue component at some index.
|
153
|
124 |
The returned value is scaled from the internal 0.. 255 to
|
|
125 |
a percentage value 0..100"
|
|
126 |
|
285
|
127 |
^ (blueVector at:index) * 100 / 255
|
|
128 |
!
|
|
129 |
|
|
130 |
blueVector
|
|
131 |
"return blueVector"
|
|
132 |
|
|
133 |
^ blueVector
|
|
134 |
!
|
|
135 |
|
|
136 |
blueVector:something
|
|
137 |
"set blueVector"
|
|
138 |
|
|
139 |
blueVector := something.
|
|
140 |
!
|
|
141 |
|
|
142 |
colors
|
|
143 |
"ST-80 compatibility: return a collection containing the colors I hold"
|
|
144 |
|
|
145 |
^ self asArray
|
153
|
146 |
!
|
|
147 |
|
|
148 |
greenAt:index
|
|
149 |
"return the green component at some index.
|
|
150 |
The returned value is scaled from the internal 0.. 255 to
|
|
151 |
a percentage value 0..100"
|
|
152 |
|
|
153 |
^ (greenVector at:index) * 100 / 255
|
|
154 |
!
|
|
155 |
|
285
|
156 |
greenVector
|
|
157 |
"return greenVector"
|
|
158 |
|
|
159 |
^ greenVector
|
|
160 |
!
|
|
161 |
|
|
162 |
greenVector:something
|
|
163 |
"set greenVector"
|
|
164 |
|
|
165 |
greenVector := something.
|
|
166 |
!
|
|
167 |
|
|
168 |
redAt:index
|
|
169 |
"return the red component at some index.
|
153
|
170 |
The returned value is scaled from the internal 0.. 255 to
|
|
171 |
a percentage value 0..100"
|
|
172 |
|
285
|
173 |
^ (redVector at:index) * 100 / 255
|
|
174 |
!
|
|
175 |
|
|
176 |
redVector
|
|
177 |
"return redVector"
|
|
178 |
|
|
179 |
^ redVector
|
153
|
180 |
!
|
|
181 |
|
285
|
182 |
redVector:something
|
|
183 |
"set redVector"
|
153
|
184 |
|
285
|
185 |
redVector := something.
|
|
186 |
!
|
91
|
187 |
|
285
|
188 |
redVector:r greenVector:g blueVector:b
|
|
189 |
redVector := r.
|
|
190 |
greenVector := g.
|
|
191 |
blueVector := b.
|
|
192 |
!
|
|
193 |
|
|
194 |
size
|
|
195 |
^ redVector size
|
91
|
196 |
! !
|
|
197 |
|
|
198 |
!Colormap methodsFor:'misc'!
|
|
199 |
|
|
200 |
scaleValuesBy:scaleFactor
|
153
|
201 |
"multiply all values by scaleFactor; finally round to integer.
|
|
202 |
This can be used to brighten/darken an images colormap"
|
91
|
203 |
|
|
204 |
1 to:redVector size do:[:index |
|
|
205 |
redVector at:index put:((redVector at:index) * scaleFactor) rounded.
|
153
|
206 |
greenVector at:index put:((greenVector at:index) * scaleFactor) rounded.
|
|
207 |
blueVector at:index put:((blueVector at:index) * scaleFactor) rounded.
|
91
|
208 |
]
|
|
209 |
! !
|
285
|
210 |
|
|
211 |
!Colormap class methodsFor:'documentation'!
|
|
212 |
|
|
213 |
version
|
572
|
214 |
^ '$Header: /cvs/stx/stx/libview/Colormap.st,v 1.6 1996-04-19 10:45:59 cg Exp $'
|
285
|
215 |
! !
|