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