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