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