author | Claus Gittinger <cg@exept.de> |
Mon, 28 Apr 2003 12:14:49 +0200 | |
changeset 3864 | b04f2f0c5eae |
parent 3847 | 288ab85676aa |
child 3876 | f4dc6267a30a |
permissions | -rw-r--r-- |
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 |
||
3265 | 13 |
"{ Package: 'stx:libview' }" |
14 |
||
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
15 |
SequenceableCollection subclass:#Colormap |
572 | 16 |
instanceVariableNames:'redVector greenVector blueVector' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
665 | 19 |
category:'Graphics-Images-Support' |
91 | 20 |
! |
21 |
||
1092 | 22 |
!Colormap class methodsFor:'documentation'! |
91 | 23 |
|
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
3844 | 40 |
Colormaps are used with images (and Forms) to keep the byte-to-color mapping. |
602 | 41 |
Externally, either colors or pixel values can be accessed. |
91 | 42 |
Internally, the values are stored as 3 separate byte-arrays |
43 |
(i.e. individual components can be 0..255). |
|
3844 | 44 |
This was done to avoid overhead due to allocation of many color instances. |
611 | 45 |
|
3847 | 46 |
Notice: Colormap is going to be obsoleted, and the functionality will |
47 |
move to subclasses (MappedPalette etc.) |
|
48 |
||
611 | 49 |
[author:] |
50 |
Claus Gittinger |
|
51 |
||
602 | 52 |
[see also:] |
603 | 53 |
Color Image Form |
91 | 54 |
" |
55 |
! ! |
|
56 |
||
1092 | 57 |
!Colormap class methodsFor:'instance creation'! |
91 | 58 |
|
118 | 59 |
fromColors:aColorArray |
3844 | 60 |
"given a sequenceable collection of colors, return a new instance of myself. |
61 |
Obsolete: use #withColors: for VW compatibility." |
|
602 | 62 |
|
3844 | 63 |
self obsoleteMethodWarning:'use #withColors:'. |
1377 | 64 |
^ self withColors:aColorArray |
65 |
||
66 |
" |
|
67 |
Colormap |
|
68 |
fromColors:(Array with:Color black |
|
69 |
with:Color red |
|
70 |
with:Color white) |
|
71 |
" |
|
72 |
||
73 |
"Modified: 25.2.1997 / 19:00:31 / cg" |
|
74 |
! |
|
75 |
||
2448
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
76 |
new:numColors |
3844 | 77 |
"/ ^ self withColors:(Array new:numColors withAll:Color black) |
78 |
||
79 |
^ self |
|
80 |
redVector:(ByteArray new:numColors withAll:0) |
|
81 |
greenVector:(ByteArray new:numColors withAll:0) |
|
82 |
blueVector:(ByteArray new:numColors withAll:0) |
|
83 |
||
84 |
" |
|
85 |
self new:100 |
|
86 |
" |
|
2448
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
87 |
! |
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
88 |
|
3844 | 89 |
redVector:rV greenVector:gV blueVector:bV |
1377 | 90 |
"given vectors of red/green/and blue pixelValues, |
91 |
return a new instance of myself. |
|
92 |
The values must be in the range 0..255." |
|
93 |
||
3844 | 94 |
"/ rV size == 2 ifTrue:[ |
95 |
"/ "/ mhmh - actually a monochrome palette. |
|
96 |
"/ "/ should return an instance of MonochromePalette |
|
97 |
"/ self halt. |
|
98 |
"/ ]. |
|
99 |
||
100 |
^ self new |
|
101 |
redVector:rV |
|
102 |
greenVector:gV |
|
103 |
blueVector:bV |
|
1377 | 104 |
|
105 |
" |
|
106 |
Colormap |
|
107 |
redVector:#[0 127 255] |
|
108 |
greenVector:#[0 127 255] |
|
109 |
blueVector:#[0 127 255] |
|
110 |
" |
|
111 |
||
112 |
"Modified: 23.4.1996 / 22:16:00 / cg" |
|
113 |
! |
|
114 |
||
3864 | 115 |
rgbBytesVector:rgbVector |
116 |
"given a single vector containing r-g-b byte values, |
|
3844 | 117 |
return a new instance of myself. |
118 |
The values must be in the range 0..255." |
|
119 |
||
120 |
|rV gV bV srcIndex nColors| |
|
121 |
||
122 |
nColors := rgbVector size // 3. |
|
123 |
rV := ByteArray new:nColors. |
|
124 |
gV := ByteArray new:nColors. |
|
125 |
bV := ByteArray new:nColors. |
|
126 |
||
127 |
srcIndex := 1. |
|
128 |
1 to:nColors do:[:dstIndex | |
|
129 |
|r g b| |
|
130 |
||
131 |
r := rgbVector at:srcIndex. |
|
132 |
g := rgbVector at:srcIndex+1. |
|
133 |
b := rgbVector at:srcIndex+2. |
|
134 |
||
135 |
rV at:dstIndex put:r. |
|
136 |
gV at:dstIndex put:g. |
|
137 |
bV at:dstIndex put:b. |
|
138 |
srcIndex := srcIndex + 3. |
|
139 |
]. |
|
140 |
||
141 |
^ self |
|
142 |
redVector:rV |
|
143 |
greenVector:gV |
|
144 |
blueVector:bV |
|
145 |
||
146 |
" |
|
3845 | 147 |
|map| |
148 |
||
149 |
map := Colormap rgbVector:#[0 0 0 127 127 127 255 0 0 255 255 255]. |
|
150 |
map atPixelValue:2 |
|
3844 | 151 |
" |
152 |
! |
|
153 |
||
3864 | 154 |
rgbValueVector:rgbValueVector |
155 |
"given a single vector containing r-g-b pixel-values, |
|
156 |
return a new instance of myself. |
|
157 |
The values must be of the rgb-form i.e. 16rRRGGBB" |
|
158 |
||
159 |
|rV gV bV nColors| |
|
160 |
||
161 |
nColors := rgbValueVector size. |
|
162 |
rV := ByteArray new:nColors. |
|
163 |
gV := ByteArray new:nColors. |
|
164 |
bV := ByteArray new:nColors. |
|
165 |
||
166 |
1 to:nColors do:[:index | |
|
167 |
|rgb r g b| |
|
168 |
||
169 |
rgb := rgbValueVector at:index. |
|
170 |
r := (rgb bitShift:-16) bitAnd:16rFF. |
|
171 |
g := (rgb bitShift:-8) bitAnd:16rFF. |
|
172 |
b := rgb bitAnd:16rFF. |
|
173 |
||
174 |
rV at:index put:r. |
|
175 |
gV at:index put:g. |
|
176 |
bV at:index put:b. |
|
177 |
]. |
|
178 |
||
179 |
^ self |
|
180 |
redVector:rV |
|
181 |
greenVector:gV |
|
182 |
blueVector:bV |
|
183 |
||
184 |
" |
|
185 |
|map| |
|
186 |
||
187 |
map := Colormap rgbValueVector:#(16r000000 16r7F7F7F 16r800000 16rFFFFFF). |
|
188 |
map atPixelValue:2 |
|
189 |
" |
|
190 |
! |
|
191 |
||
1377 | 192 |
withColors:aColorArray |
193 |
"given a sequenceable collection of colors, return a new instance |
|
194 |
of myself. Renamed from #fromColors: for ST-80 compatibility." |
|
195 |
||
3846 | 196 |
"/ aColorArray size == 2 ifTrue:[ |
197 |
"/ "/ mhmh - actually a monochrome palette. |
|
198 |
"/ "/ should return an instance of MonochromePalette |
|
199 |
"/ self halt. |
|
200 |
"/ ]. |
|
1378
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
201 |
^ self new colors:aColorArray |
118 | 202 |
|
203 |
" |
|
204 |
Colormap |
|
1377 | 205 |
withColors:(Array with:Color black |
602 | 206 |
with:Color red |
207 |
with:Color white) |
|
118 | 208 |
" |
602 | 209 |
|
1377 | 210 |
"Created: 25.2.1997 / 18:59:09 / cg" |
1378
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
211 |
"Modified: 25.2.1997 / 19:03:08 / cg" |
285 | 212 |
! ! |
91 | 213 |
|
285 | 214 |
!Colormap methodsFor:'accessing'! |
91 | 215 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
216 |
at:index |
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
217 |
"return the color for a index. |
3844 | 218 |
Notice that index range is 1...nColors" |
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
219 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
220 |
|r g b idx "{ Class: SmallInteger }" | |
91 | 221 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
222 |
idx := index. |
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
223 |
r := redVector at:idx. |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
224 |
g := greenVector at:idx. |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
225 |
b := blueVector at:idx. |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
226 |
|
1351 | 227 |
^ Color redByte:r greenByte:g blueByte:b |
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
228 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
229 |
"Created: 2.5.1996 / 12:21:40 / cg" |
808 | 230 |
"Modified: 8.6.1996 / 14:25:30 / cg" |
91 | 231 |
! |
232 |
||
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
233 |
at:index put:aColor |
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
234 |
"set the color for a index. Return aColor (sigh). |
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
235 |
Notice that index range is 1..." |
91 | 236 |
|
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
237 |
|r g b idx "{ Class: SmallInteger }" | |
572 | 238 |
|
91 | 239 |
r := (aColor red * 255 / 100) rounded. |
240 |
g := (aColor green * 255 / 100) rounded. |
|
241 |
b := (aColor blue * 255 / 100) rounded. |
|
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
242 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
243 |
idx := index. |
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
244 |
redVector at:idx put:r. |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
245 |
greenVector at:idx put:g. |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
246 |
blueVector at:idx put:b. |
572 | 247 |
^ aColor |
248 |
||
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
249 |
"Modified: 2.5.1996 / 17:29:29 / cg" |
118 | 250 |
! |
91 | 251 |
|
3844 | 252 |
atPixelValue:pixelValue |
253 |
"return the color for a pixelValue. |
|
254 |
Notice that pixelValue range is 0...nColors-1" |
|
255 |
||
256 |
^ self at:(pixelValue + 1) |
|
257 |
! |
|
258 |
||
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
259 |
blueAt:index |
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
260 |
"return the blue component for some index. |
153 | 261 |
The returned value is scaled from the internal 0.. 255 to |
262 |
a percentage value 0..100" |
|
263 |
||
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
264 |
^ (blueVector at:index) * 100 / 255 |
285 | 265 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
266 |
"Modified: 2.5.1996 / 17:29:17 / cg" |
285 | 267 |
! |
268 |
||
269 |
colors |
|
270 |
"ST-80 compatibility: return a collection containing the colors I hold" |
|
271 |
||
272 |
^ self asArray |
|
153 | 273 |
! |
274 |
||
1378
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
275 |
colors:aCollectionOfColors |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
276 |
"setup the receiver from colors given in a sequenceable collection of colors" |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
277 |
|
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
278 |
|sz "{Class: SmallInteger }"| |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
279 |
|
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
280 |
sz := aCollectionOfColors size. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
281 |
redVector := ByteArray new:sz. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
282 |
greenVector := ByteArray new:sz. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
283 |
blueVector := ByteArray new:sz. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
284 |
|
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
285 |
1 to:sz do:[:i | |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
286 |
|clr r g b| |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
287 |
|
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
288 |
clr := aCollectionOfColors at:i. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
289 |
clr notNil ifTrue:[ |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
290 |
redVector at:i put:(clr redByte). |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
291 |
greenVector at:i put:(clr greenByte). |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
292 |
blueVector at:i put:(clr blueByte). |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
293 |
] |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
294 |
]. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
295 |
|
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
296 |
"Modified: 25.2.1997 / 19:02:47 / cg" |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
297 |
! |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
298 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
299 |
greenAt:index |
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
300 |
"return the green component for some index. |
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
301 |
The returned value is scaled from the internal 0.. 255 to |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
302 |
a percentage value 0..100" |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
303 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
304 |
^ (greenVector at:index) * 100 / 255 |
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
305 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
306 |
"Modified: 2.5.1996 / 17:29:36 / cg" |
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
307 |
! |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
308 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
309 |
redAt:index |
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
310 |
"return the red component for some index. |
153 | 311 |
The returned value is scaled from the internal 0.. 255 to |
312 |
a percentage value 0..100" |
|
313 |
||
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
314 |
^ (redVector at:index) * 100 / 255 |
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
315 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
316 |
"Modified: 2.5.1996 / 17:29:44 / cg" |
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
317 |
! ! |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
318 |
|
1092 | 319 |
!Colormap methodsFor:'accessing-internals'! |
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
320 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
321 |
blueVector |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
322 |
"return the blueVector" |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
323 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
324 |
^ blueVector |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
325 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
326 |
"Modified: 2.5.1996 / 12:44:17 / cg" |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
327 |
! |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
328 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
329 |
blueVector:something |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
330 |
"set blueVector" |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
331 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
332 |
blueVector := something. |
153 | 333 |
! |
334 |
||
285 | 335 |
greenVector |
336 |
"return greenVector" |
|
337 |
||
338 |
^ greenVector |
|
339 |
! |
|
340 |
||
341 |
greenVector:something |
|
342 |
"set greenVector" |
|
343 |
||
344 |
greenVector := something. |
|
345 |
! |
|
346 |
||
347 |
redVector |
|
348 |
"return redVector" |
|
349 |
||
350 |
^ redVector |
|
153 | 351 |
! |
352 |
||
285 | 353 |
redVector:something |
354 |
"set redVector" |
|
153 | 355 |
|
285 | 356 |
redVector := something. |
357 |
! |
|
91 | 358 |
|
285 | 359 |
redVector:r greenVector:g blueVector:b |
602 | 360 |
"set the red, green and blueVectors" |
361 |
||
285 | 362 |
redVector := r. |
363 |
greenVector := g. |
|
364 |
blueVector := b. |
|
602 | 365 |
|
366 |
"Modified: 23.4.1996 / 22:13:31 / cg" |
|
91 | 367 |
! ! |
368 |
||
943 | 369 |
!Colormap methodsFor:'converting'! |
917
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
370 |
|
941 | 371 |
asArray |
944 | 372 |
"return the receiver as an array containing my colors" |
941 | 373 |
|
374 |
|r g b n "{ Class: SmallInteger }" |
|
375 |
scale array| |
|
376 |
||
377 |
n := redVector size. |
|
378 |
array := Array new:n. |
|
379 |
scale := Color scalingValue / 255.0. |
|
380 |
||
381 |
1 to:n do:[:idx | |
|
382 |
r := redVector at:idx. |
|
383 |
g := greenVector at:idx. |
|
384 |
b := blueVector at:idx. |
|
385 |
||
386 |
array at:idx put:(Color |
|
387 |
scaledRed:(r * scale) rounded |
|
388 |
scaledGreen:(g * scale) rounded |
|
389 |
scaledBlue:(b * scale) rounded) |
|
943 | 390 |
]. |
391 |
^ array |
|
941 | 392 |
|
393 |
"Created: 11.7.1996 / 20:19:45 / cg" |
|
944 | 394 |
"Modified: 11.7.1996 / 21:34:16 / cg" |
943 | 395 |
! ! |
396 |
||
397 |
!Colormap methodsFor:'copying'! |
|
941 | 398 |
|
2483 | 399 |
copyFrom:start to:stop |
3844 | 400 |
^ self class |
401 |
redVector:(redVector copyFrom:start to:stop) |
|
402 |
greenVector:(greenVector copyFrom:start to:stop) |
|
403 |
blueVector:(blueVector copyFrom:start to:stop) |
|
2483 | 404 |
! |
405 |
||
917
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
406 |
postCopy |
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
407 |
redVector := redVector copy. |
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
408 |
greenVector := greenVector copy. |
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
409 |
blueVector := blueVector copy. |
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
410 |
|
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
411 |
"Created: 5.7.1996 / 14:52:15 / cg" |
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
412 |
! ! |
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
413 |
|
91 | 414 |
!Colormap methodsFor:'misc'! |
415 |
||
2448
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
416 |
grow:howBig |
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
417 |
"change the receivers size - not allowed" |
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
418 |
|
3271 | 419 |
|t| |
2448
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
420 |
|
3271 | 421 |
howBig == self size ifTrue:[^ self]. |
422 |
redVector isNil ifTrue:[ |
|
423 |
redVector := ByteArray new:howBig. |
|
424 |
greenVector := ByteArray new:howBig. |
|
425 |
blueVector := ByteArray new:howBig. |
|
426 |
^ self |
|
427 |
]. |
|
428 |
t := redVector. redVector := ByteArray new:howBig. redVector replaceFrom:1 to:t size with:t startingAt:1. |
|
429 |
t := greenVector. greenVector := ByteArray new:howBig. greenVector replaceFrom:1 to:t size with:t startingAt:1. |
|
430 |
t := blueVector. blueVector := ByteArray new:howBig. blueVector replaceFrom:1 to:t size with:t startingAt:1. |
|
431 |
^ self |
|
2448
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
432 |
|
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
433 |
! |
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
434 |
|
91 | 435 |
scaleValuesBy:scaleFactor |
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
436 |
"multiply all values by scaleFactor; finally round to integer. |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
437 |
This can be used to brighten/darken an images colormap" |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
438 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
439 |
|sz "{ Class: SmallInteger }" | |
91 | 440 |
|
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
441 |
sz := redVector size. |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
442 |
1 to:sz do:[:index | |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
443 |
redVector at:index put:((redVector at:index) * scaleFactor) rounded. |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
444 |
greenVector at:index put:((greenVector at:index) * scaleFactor) rounded. |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
445 |
blueVector at:index put:((blueVector at:index) * scaleFactor) rounded. |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
446 |
] |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
447 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
448 |
"Modified: 2.5.1996 / 12:46:07 / cg" |
91 | 449 |
! ! |
285 | 450 |
|
3276 | 451 |
!Colormap methodsFor:'printing & storing'! |
452 |
||
453 |
storeOn:aStream |
|
454 |
"append a representation to aStream, from which the receiver |
|
455 |
can be reconstructed" |
|
456 |
||
457 |
aStream nextPutAll:'(' , self class name ,' redVector:'. |
|
458 |
redVector storeOn:aStream. |
|
459 |
aStream nextPutAll:' greenVector:'. |
|
460 |
greenVector storeOn:aStream. |
|
461 |
aStream nextPutAll:' blueVector:'. |
|
462 |
blueVector storeOn:aStream. |
|
463 |
aStream nextPutAll:')' |
|
464 |
||
465 |
"Created: 30.5.1996 / 16:28:27 / ca" |
|
466 |
"Modified: 30.5.1996 / 16:32:44 / ca" |
|
467 |
! ! |
|
468 |
||
1435 | 469 |
!Colormap methodsFor:'queries'! |
470 |
||
471 |
indexOfPaintNearest: color |
|
472 |
|minDistance minIndex dist |
|
473 |
sz "{ Class: SmallInteger }"| |
|
474 |
||
475 |
minDistance := (self at:1) deltaFrom:color. |
|
476 |
minIndex := 1. |
|
477 |
sz := self size. |
|
478 |
2 to:sz do:[:idx | |
|
479 |
dist := (self at:idx) deltaFrom:color. |
|
480 |
dist < minDistance ifTrue:[ |
|
481 |
minDistance := dist. |
|
482 |
minIndex := idx. |
|
483 |
] |
|
484 |
]. |
|
485 |
^ minIndex |
|
486 |
||
487 |
"Created: 6.3.1997 / 15:45:39 / cg" |
|
3265 | 488 |
! |
489 |
||
3840 | 490 |
isGreyscaleColormap |
491 |
"return true, if the receiver is actually a greymap. |
|
492 |
Could be used to convert images as read from imageFiles |
|
493 |
(for example, GIF-files) automatically to greyScale (which is not yet done)." |
|
494 |
||
495 |
|sz "{ Class: SmallInteger }" |
|
496 |
redVal| |
|
497 |
||
498 |
sz := redVector size. |
|
499 |
||
500 |
1 to:sz do:[:i | |
|
501 |
redVal := redVector at:i. |
|
502 |
redVal ~~ (greenVector at:i) ifTrue:[^ false]. |
|
503 |
redVal ~~ (blueVector at:i) ifTrue:[^ false]. |
|
504 |
]. |
|
505 |
^ true |
|
506 |
! |
|
507 |
||
3265 | 508 |
size |
509 |
"return the number of colors in the receiver" |
|
510 |
||
511 |
^ redVector size |
|
512 |
||
513 |
"Modified: 23.4.1996 / 22:13:43 / cg" |
|
1435 | 514 |
! ! |
515 |
||
1092 | 516 |
!Colormap class methodsFor:'documentation'! |
285 | 517 |
|
518 |
version |
|
3864 | 519 |
^ '$Header: /cvs/stx/stx/libview/Colormap.st,v 1.35 2003-04-28 10:14:49 cg Exp $' |
285 | 520 |
! ! |