author | Stefan Vogel <sv@exept.de> |
Tue, 28 Apr 2020 15:28:14 +0200 | |
changeset 9038 | dd177fea6408 |
parent 8957 | 2eed7c24eda7 |
permissions | -rw-r--r-- |
8957 | 1 |
"{ Encoding: utf8 }" |
2 |
||
91 | 3 |
" |
4 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
3265 | 14 |
"{ Package: 'stx:libview' }" |
15 |
||
6786 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
18 |
SequenceableCollection subclass:#Colormap |
572 | 19 |
instanceVariableNames:'redVector greenVector blueVector' |
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
665 | 22 |
category:'Graphics-Images-Support' |
91 | 23 |
! |
24 |
||
1092 | 25 |
!Colormap class methodsFor:'documentation'! |
91 | 26 |
|
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
30 |
All Rights Reserved |
|
31 |
||
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
41 |
documentation |
|
42 |
" |
|
3844 | 43 |
Colormaps are used with images (and Forms) to keep the byte-to-color mapping. |
602 | 44 |
Externally, either colors or pixel values can be accessed. |
91 | 45 |
Internally, the values are stored as 3 separate byte-arrays |
46 |
(i.e. individual components can be 0..255). |
|
3844 | 47 |
This was done to avoid overhead due to allocation of many color instances. |
611 | 48 |
|
3847 | 49 |
Notice: Colormap is going to be obsoleted, and the functionality will |
50 |
move to subclasses (MappedPalette etc.) |
|
51 |
||
611 | 52 |
[author:] |
53 |
Claus Gittinger |
|
54 |
||
602 | 55 |
[see also:] |
603 | 56 |
Color Image Form |
91 | 57 |
" |
58 |
! ! |
|
59 |
||
1092 | 60 |
!Colormap class methodsFor:'instance creation'! |
91 | 61 |
|
118 | 62 |
fromColors:aColorArray |
3844 | 63 |
"given a sequenceable collection of colors, return a new instance of myself. |
64 |
Obsolete: use #withColors: for VW compatibility." |
|
602 | 65 |
|
4176 | 66 |
<resource: #obsolete> |
3844 | 67 |
self obsoleteMethodWarning:'use #withColors:'. |
1377 | 68 |
^ self withColors:aColorArray |
69 |
||
70 |
" |
|
71 |
Colormap |
|
72 |
fromColors:(Array with:Color black |
|
73 |
with:Color red |
|
74 |
with:Color white) |
|
75 |
" |
|
76 |
||
77 |
"Modified: 25.2.1997 / 19:00:31 / cg" |
|
78 |
! |
|
79 |
||
2448
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
80 |
new:numColors |
3844 | 81 |
"/ ^ self withColors:(Array new:numColors withAll:Color black) |
82 |
||
3876 | 83 |
self == Colormap ifTrue:[ |
84 |
"/ Colormap will be abstract in the near future |
|
85 |
self obsoleteFeatureWarning:'please change your code to use a concrete subclass of ColorPalette'. |
|
86 |
]. |
|
87 |
||
3844 | 88 |
^ self |
89 |
redVector:(ByteArray new:numColors withAll:0) |
|
90 |
greenVector:(ByteArray new:numColors withAll:0) |
|
91 |
blueVector:(ByteArray new:numColors withAll:0) |
|
92 |
||
93 |
" |
|
3876 | 94 |
MappedPalette new:100 |
3844 | 95 |
" |
2448
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
96 |
! |
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
97 |
|
3844 | 98 |
redVector:rV greenVector:gV blueVector:bV |
1377 | 99 |
"given vectors of red/green/and blue pixelValues, |
100 |
return a new instance of myself. |
|
101 |
The values must be in the range 0..255." |
|
102 |
||
3876 | 103 |
self == Colormap ifTrue:[ |
104 |
"/ Colormap will be abstract in the near future |
|
105 |
self obsoleteFeatureWarning:'please change your code to use a concrete subclass of ColorPalette'. |
|
106 |
]. |
|
3844 | 107 |
^ self new |
108 |
redVector:rV |
|
109 |
greenVector:gV |
|
110 |
blueVector:bV |
|
1377 | 111 |
|
112 |
" |
|
3876 | 113 |
MappedPalette |
1377 | 114 |
redVector:#[0 127 255] |
115 |
greenVector:#[0 127 255] |
|
116 |
blueVector:#[0 127 255] |
|
117 |
" |
|
118 |
||
119 |
"Modified: 23.4.1996 / 22:16:00 / cg" |
|
120 |
! |
|
121 |
||
3864 | 122 |
rgbBytesVector:rgbVector |
123 |
"given a single vector containing r-g-b byte values, |
|
3844 | 124 |
return a new instance of myself. |
125 |
The values must be in the range 0..255." |
|
126 |
||
127 |
|rV gV bV srcIndex nColors| |
|
128 |
||
129 |
nColors := rgbVector size // 3. |
|
130 |
rV := ByteArray new:nColors. |
|
131 |
gV := ByteArray new:nColors. |
|
132 |
bV := ByteArray new:nColors. |
|
133 |
||
134 |
srcIndex := 1. |
|
135 |
1 to:nColors do:[:dstIndex | |
|
136 |
|r g b| |
|
137 |
||
138 |
r := rgbVector at:srcIndex. |
|
139 |
g := rgbVector at:srcIndex+1. |
|
140 |
b := rgbVector at:srcIndex+2. |
|
141 |
||
142 |
rV at:dstIndex put:r. |
|
143 |
gV at:dstIndex put:g. |
|
144 |
bV at:dstIndex put:b. |
|
145 |
srcIndex := srcIndex + 3. |
|
146 |
]. |
|
147 |
||
148 |
^ self |
|
149 |
redVector:rV |
|
150 |
greenVector:gV |
|
151 |
blueVector:bV |
|
152 |
||
153 |
" |
|
3845 | 154 |
|map| |
155 |
||
8957 | 156 |
map := MappedPalette rgbBytesVector:#[0 0 0 127 127 127 255 0 0 255 255 255]. |
3845 | 157 |
map atPixelValue:2 |
3844 | 158 |
" |
159 |
! |
|
160 |
||
3864 | 161 |
rgbValueVector:rgbValueVector |
162 |
"given a single vector containing r-g-b pixel-values, |
|
163 |
return a new instance of myself. |
|
164 |
The values must be of the rgb-form i.e. 16rRRGGBB" |
|
165 |
||
166 |
|rV gV bV nColors| |
|
167 |
||
168 |
nColors := rgbValueVector size. |
|
169 |
rV := ByteArray new:nColors. |
|
170 |
gV := ByteArray new:nColors. |
|
171 |
bV := ByteArray new:nColors. |
|
172 |
||
173 |
1 to:nColors do:[:index | |
|
174 |
|rgb r g b| |
|
175 |
||
176 |
rgb := rgbValueVector at:index. |
|
177 |
r := (rgb bitShift:-16) bitAnd:16rFF. |
|
178 |
g := (rgb bitShift:-8) bitAnd:16rFF. |
|
179 |
b := rgb bitAnd:16rFF. |
|
180 |
||
181 |
rV at:index put:r. |
|
182 |
gV at:index put:g. |
|
183 |
bV at:index put:b. |
|
184 |
]. |
|
185 |
||
186 |
^ self |
|
187 |
redVector:rV |
|
188 |
greenVector:gV |
|
189 |
blueVector:bV |
|
190 |
||
191 |
" |
|
192 |
|map| |
|
193 |
||
8957 | 194 |
map := MappedPalette rgbValueVector:#(16r000000 16r7F7F7F 16r800000 16rFFFFFF). |
3864 | 195 |
map atPixelValue:2 |
196 |
" |
|
197 |
! |
|
198 |
||
1377 | 199 |
withColors:aColorArray |
200 |
"given a sequenceable collection of colors, return a new instance |
|
201 |
of myself. Renamed from #fromColors: for ST-80 compatibility." |
|
202 |
||
3876 | 203 |
self == Colormap ifTrue:[ |
204 |
"/ Colormap will be abstract in the near future |
|
205 |
self obsoleteFeatureWarning:'please change your code to use a concrete subclass of ColorPalette'. |
|
206 |
]. |
|
1378
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
207 |
^ self new colors:aColorArray |
118 | 208 |
|
209 |
" |
|
3876 | 210 |
MappedPalette |
1377 | 211 |
withColors:(Array with:Color black |
602 | 212 |
with:Color red |
213 |
with:Color white) |
|
118 | 214 |
" |
602 | 215 |
|
1377 | 216 |
"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
|
217 |
"Modified: 25.2.1997 / 19:03:08 / cg" |
285 | 218 |
! ! |
91 | 219 |
|
285 | 220 |
!Colormap methodsFor:'accessing'! |
91 | 221 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
222 |
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
|
223 |
"return the color for a index. |
6786 | 224 |
Notice that the 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
|
225 |
|
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 g b idx "{ Class: SmallInteger }" | |
91 | 227 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
228 |
idx := index. |
4185
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
229 |
r := self redByteAt:idx. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
230 |
g := self greenByteAt:idx. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
231 |
b := self blueByteAt:idx. |
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
232 |
|
1351 | 233 |
^ 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
|
234 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
235 |
"Created: 2.5.1996 / 12:21:40 / cg" |
808 | 236 |
"Modified: 8.6.1996 / 14:25:30 / cg" |
91 | 237 |
! |
238 |
||
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
239 |
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
|
240 |
"set the color for a index. Return aColor (sigh). |
6786 | 241 |
Notice that the index range is 1..." |
91 | 242 |
|
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
243 |
|r g b idx "{ Class: SmallInteger }" | |
572 | 244 |
|
91 | 245 |
r := (aColor red * 255 / 100) rounded. |
246 |
g := (aColor green * 255 / 100) rounded. |
|
247 |
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
|
248 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
249 |
idx := index. |
4794 | 250 |
self redByteAt:idx put:(r max:0). |
251 |
self greenByteAt:idx put:(g max:0). |
|
252 |
self blueByteAt:idx put:(b max:0). |
|
572 | 253 |
^ aColor |
254 |
||
4794 | 255 |
"Modified: / 22-07-2007 / 15:28:32 / cg" |
118 | 256 |
! |
91 | 257 |
|
6307 | 258 |
at:index putRGB:rgbValue |
259 |
"set the color for an index, given rrggbb as an integer (8bits each, red in high bits). |
|
260 |
Notice that the index range is 1..." |
|
261 |
||
262 |
|r g b idx "{ Class: SmallInteger }" | |
|
263 |
||
264 |
r := (rgbValue bitShift:-16) bitAnd:16rFF. |
|
265 |
g := (rgbValue bitShift:-8) bitAnd:16rFF. |
|
266 |
b := rgbValue bitAnd:16rFF. |
|
267 |
||
268 |
idx := index. |
|
269 |
self redByteAt:idx put:r. |
|
270 |
self greenByteAt:idx put:g. |
|
271 |
self blueByteAt:idx put:b. |
|
272 |
! |
|
273 |
||
274 |
at:index putRGBTriple:aTriple |
|
275 |
"set the color for an index from an rgb triple. |
|
276 |
The components are r,g,b; each 0..1. |
|
277 |
Notice that the index range is 1..." |
|
278 |
||
279 |
|r g b idx "{ Class: SmallInteger }" | |
|
280 |
||
281 |
r := ((aTriple at:1) * 255) rounded. |
|
282 |
g := ((aTriple at:2) * 255) rounded. |
|
283 |
b := ((aTriple at:3) * 255) rounded. |
|
284 |
||
285 |
idx := index. |
|
286 |
self redByteAt:idx put:(r max:0). |
|
287 |
self greenByteAt:idx put:(g max:0). |
|
288 |
self blueByteAt:idx put:(b max:0). |
|
289 |
! |
|
290 |
||
3844 | 291 |
atPixelValue:pixelValue |
292 |
"return the color for a pixelValue. |
|
293 |
Notice that pixelValue range is 0...nColors-1" |
|
294 |
||
295 |
^ self at:(pixelValue + 1) |
|
296 |
! |
|
297 |
||
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
298 |
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
|
299 |
"return the blue component for some index. |
153 | 300 |
The returned value is scaled from the internal 0.. 255 to |
4185
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
301 |
a percentage value 0..100. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
302 |
Notice that index range is 1..." |
153 | 303 |
|
4185
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
304 |
^ (self blueByteAt:index) * 100 / 255 |
285 | 305 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
306 |
"Modified: 2.5.1996 / 17:29:17 / cg" |
285 | 307 |
! |
308 |
||
309 |
colors |
|
310 |
"ST-80 compatibility: return a collection containing the colors I hold" |
|
311 |
||
312 |
^ self asArray |
|
153 | 313 |
! |
314 |
||
1378
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
315 |
colors:aCollectionOfColors |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
316 |
"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
|
317 |
|
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
318 |
|sz "{Class: SmallInteger }"| |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
319 |
|
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
320 |
sz := aCollectionOfColors size. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
321 |
redVector := ByteArray new:sz. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
322 |
greenVector := ByteArray new:sz. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
323 |
blueVector := ByteArray new:sz. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
324 |
|
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
325 |
1 to:sz do:[:i | |
7594 | 326 |
|clr| |
1378
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
327 |
|
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
328 |
clr := aCollectionOfColors at:i. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
329 |
clr notNil ifTrue:[ |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
330 |
redVector at:i put:(clr redByte). |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
331 |
greenVector at:i put:(clr greenByte). |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
332 |
blueVector at:i put:(clr blueByte). |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
333 |
] |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
334 |
]. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
335 |
|
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
336 |
"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
|
337 |
! |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
338 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
339 |
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
|
340 |
"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
|
341 |
The returned value is scaled from the internal 0.. 255 to |
4185
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
342 |
a percentage value 0..100. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
343 |
Notice that index range is 1..." |
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
344 |
|
4185
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
345 |
^ (self greenByteAt: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
|
346 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
347 |
"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
|
348 |
! |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
349 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
350 |
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
|
351 |
"return the red component for some index. |
153 | 352 |
The returned value is scaled from the internal 0.. 255 to |
4185
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
353 |
a percentage value 0..100. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
354 |
Notice that index range is 1..." |
153 | 355 |
|
4185
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
356 |
^ (self redByteAt: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
|
357 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
358 |
"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
|
359 |
! ! |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
360 |
|
1092 | 361 |
!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
|
362 |
|
4185
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
363 |
blueByteAt:index |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
364 |
"return the blueByte component for some index. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
365 |
The returned value is from the internal 0.. 255" |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
366 |
|
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
367 |
^ (blueVector at:index) |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
368 |
! |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
369 |
|
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
370 |
blueByteAt:index put:anInteger |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
371 |
"change the internal blueByte component for some index. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
372 |
The argument, anInteger should be from the internal 0.. 255. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
373 |
Notice that index range is 1..." |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
374 |
|
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
375 |
^ blueVector at:index put:anInteger |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
376 |
! |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
377 |
|
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
378 |
blueVector |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
379 |
"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
|
380 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
381 |
^ blueVector |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
382 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
383 |
"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
|
384 |
! |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
385 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
386 |
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
|
387 |
"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
|
388 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
389 |
blueVector := something. |
153 | 390 |
! |
391 |
||
4185
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
392 |
greenByteAt:index |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
393 |
"return the greenByte component for some index. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
394 |
The returned value is from the internal 0.. 255" |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
395 |
|
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
396 |
^ (greenVector at:index) |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
397 |
! |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
398 |
|
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
399 |
greenByteAt:index put:anInteger |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
400 |
"change the internal greenByte component for some index. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
401 |
The argument, anInteger should be from the internal 0.. 255. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
402 |
Notice that index range is 1..." |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
403 |
|
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
404 |
^ greenVector at:index put:anInteger |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
405 |
! |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
406 |
|
285 | 407 |
greenVector |
408 |
"return greenVector" |
|
409 |
||
410 |
^ greenVector |
|
411 |
! |
|
412 |
||
413 |
greenVector:something |
|
414 |
"set greenVector" |
|
415 |
||
416 |
greenVector := something. |
|
417 |
! |
|
418 |
||
4185
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
419 |
redByteAt:index |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
420 |
"return the redByte component for some index. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
421 |
The returned value is from the internal 0.. 255" |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
422 |
|
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
423 |
^ (redVector at:index) |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
424 |
! |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
425 |
|
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
426 |
redByteAt:index put:anInteger |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
427 |
"change the internal redByte component for some index. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
428 |
The argument, anInteger should be from the internal 0.. 255. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
429 |
Notice that index range is 1..." |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
430 |
|
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
431 |
^ redVector at:index put:anInteger |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
432 |
! |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
433 |
|
285 | 434 |
redVector |
435 |
"return redVector" |
|
436 |
||
437 |
^ redVector |
|
153 | 438 |
! |
439 |
||
285 | 440 |
redVector:something |
441 |
"set redVector" |
|
153 | 442 |
|
285 | 443 |
redVector := something. |
444 |
! |
|
91 | 445 |
|
285 | 446 |
redVector:r greenVector:g blueVector:b |
602 | 447 |
"set the red, green and blueVectors" |
448 |
||
285 | 449 |
redVector := r. |
450 |
greenVector := g. |
|
451 |
blueVector := b. |
|
602 | 452 |
|
453 |
"Modified: 23.4.1996 / 22:13:31 / cg" |
|
91 | 454 |
! ! |
455 |
||
943 | 456 |
!Colormap methodsFor:'converting'! |
917
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
457 |
|
941 | 458 |
asArray |
944 | 459 |
"return the receiver as an array containing my colors" |
941 | 460 |
|
461 |
|r g b n "{ Class: SmallInteger }" |
|
462 |
scale array| |
|
463 |
||
4185
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
464 |
n := self size. |
941 | 465 |
array := Array new:n. |
466 |
scale := Color scalingValue / 255.0. |
|
467 |
||
468 |
1 to:n do:[:idx | |
|
4185
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
469 |
r := self redByteAt:idx. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
470 |
g := self greenByteAt:idx. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
471 |
b := self blueByteAt:idx. |
941 | 472 |
|
473 |
array at:idx put:(Color |
|
474 |
scaledRed:(r * scale) rounded |
|
475 |
scaledGreen:(g * scale) rounded |
|
476 |
scaledBlue:(b * scale) rounded) |
|
943 | 477 |
]. |
478 |
^ array |
|
941 | 479 |
|
480 |
"Created: 11.7.1996 / 20:19:45 / cg" |
|
944 | 481 |
"Modified: 11.7.1996 / 21:34:16 / cg" |
943 | 482 |
! ! |
483 |
||
484 |
!Colormap methodsFor:'copying'! |
|
941 | 485 |
|
2483 | 486 |
copyFrom:start to:stop |
3844 | 487 |
^ self class |
488 |
redVector:(redVector copyFrom:start to:stop) |
|
489 |
greenVector:(greenVector copyFrom:start to:stop) |
|
490 |
blueVector:(blueVector copyFrom:start to:stop) |
|
8688 | 491 |
! ! |
492 |
||
493 |
!Colormap methodsFor:'copying-private'! |
|
2483 | 494 |
|
917
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
495 |
postCopy |
7850 | 496 |
<modifier: #super> "must be called if redefined" |
497 |
||
917
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
498 |
redVector := redVector copy. |
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
499 |
greenVector := greenVector copy. |
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
500 |
blueVector := blueVector copy. |
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
501 |
|
7850 | 502 |
"Created: / 05-07-1996 / 14:52:15 / cg" |
503 |
"Modified: / 08-02-2017 / 00:21:00 / cg" |
|
917
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
504 |
! ! |
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
505 |
|
91 | 506 |
!Colormap methodsFor:'misc'! |
507 |
||
2448
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
508 |
grow:howBig |
7241 | 509 |
"change the receiver's size" |
2448
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
510 |
|
3271 | 511 |
|t| |
2448
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
512 |
|
3271 | 513 |
howBig == self size ifTrue:[^ self]. |
514 |
redVector isNil ifTrue:[ |
|
515 |
redVector := ByteArray new:howBig. |
|
516 |
greenVector := ByteArray new:howBig. |
|
517 |
blueVector := ByteArray new:howBig. |
|
518 |
^ self |
|
519 |
]. |
|
520 |
t := redVector. redVector := ByteArray new:howBig. redVector replaceFrom:1 to:t size with:t startingAt:1. |
|
521 |
t := greenVector. greenVector := ByteArray new:howBig. greenVector replaceFrom:1 to:t size with:t startingAt:1. |
|
522 |
t := blueVector. blueVector := ByteArray new:howBig. blueVector replaceFrom:1 to:t size with:t startingAt:1. |
|
523 |
^ self |
|
2448
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
524 |
! |
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
525 |
|
91 | 526 |
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
|
527 |
"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
|
528 |
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
|
529 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
530 |
|sz "{ Class: SmallInteger }" | |
91 | 531 |
|
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
532 |
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
|
533 |
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
|
534 |
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
|
535 |
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
|
536 |
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
|
537 |
] |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
538 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
539 |
"Modified: 2.5.1996 / 12:46:07 / cg" |
91 | 540 |
! ! |
285 | 541 |
|
3276 | 542 |
!Colormap methodsFor:'printing & storing'! |
543 |
||
544 |
storeOn:aStream |
|
545 |
"append a representation to aStream, from which the receiver |
|
546 |
can be reconstructed" |
|
547 |
||
548 |
aStream nextPutAll:'(' , self class name ,' redVector:'. |
|
549 |
redVector storeOn:aStream. |
|
550 |
aStream nextPutAll:' greenVector:'. |
|
551 |
greenVector storeOn:aStream. |
|
552 |
aStream nextPutAll:' blueVector:'. |
|
553 |
blueVector storeOn:aStream. |
|
554 |
aStream nextPutAll:')' |
|
555 |
||
556 |
"Created: 30.5.1996 / 16:28:27 / ca" |
|
557 |
"Modified: 30.5.1996 / 16:32:44 / ca" |
|
558 |
! ! |
|
559 |
||
1435 | 560 |
!Colormap methodsFor:'queries'! |
561 |
||
6786 | 562 |
colorNearestTo:aColor |
563 |
"a very questionable algorithm; |
|
564 |
basing the distance on rgb values is very bad - better |
|
565 |
do a distance in a cie color cone" |
|
566 |
||
567 |
|minDelta nearest| |
|
568 |
||
569 |
nearest := self at:1. |
|
570 |
minDelta := aColor deltaFrom:nearest. |
|
571 |
2 to:self size do:[:idx | |
|
572 |
|delta clr| |
|
573 |
||
574 |
clr := self at:idx. |
|
575 |
delta := aColor deltaFrom:clr. |
|
576 |
delta < minDelta ifTrue:[ |
|
577 |
minDelta := delta. |
|
578 |
nearest := clr |
|
579 |
] |
|
580 |
]. |
|
581 |
^ nearest. |
|
582 |
! |
|
583 |
||
6150 | 584 |
indexOfColor: aColor |
585 |
1 to:self size do:[:idx | |
|
586 |
(self at:idx) = aColor ifTrue:[^ idx]. |
|
587 |
]. |
|
588 |
^ 0 |
|
589 |
||
590 |
"Created: / 05-11-2013 / 12:23:28 / cg" |
|
591 |
! |
|
592 |
||
1435 | 593 |
indexOfPaintNearest: color |
594 |
|minDistance minIndex dist |
|
595 |
sz "{ Class: SmallInteger }"| |
|
596 |
||
597 |
minDistance := (self at:1) deltaFrom:color. |
|
598 |
minIndex := 1. |
|
599 |
sz := self size. |
|
600 |
2 to:sz do:[:idx | |
|
601 |
dist := (self at:idx) deltaFrom:color. |
|
602 |
dist < minDistance ifTrue:[ |
|
603 |
minDistance := dist. |
|
604 |
minIndex := idx. |
|
605 |
] |
|
606 |
]. |
|
607 |
^ minIndex |
|
608 |
||
609 |
"Created: 6.3.1997 / 15:45:39 / cg" |
|
3265 | 610 |
! |
611 |
||
4185
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
612 |
isFixedPalette |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
613 |
^ false |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
614 |
! |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
615 |
|
3840 | 616 |
isGreyscaleColormap |
617 |
"return true, if the receiver is actually a greymap. |
|
618 |
Could be used to convert images as read from imageFiles |
|
619 |
(for example, GIF-files) automatically to greyScale (which is not yet done)." |
|
620 |
||
621 |
|sz "{ Class: SmallInteger }" |
|
622 |
redVal| |
|
623 |
||
4185
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
624 |
sz := self size. |
3840 | 625 |
|
626 |
1 to:sz do:[:i | |
|
4185
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
627 |
redVal := self redByteAt:i. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
628 |
redVal ~~ (self greenByteAt:i) ifTrue:[^ false]. |
cc96d1c1e28c
fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents:
4176
diff
changeset
|
629 |
redVal ~~ (self blueByteAt:i) ifTrue:[^ false]. |
3840 | 630 |
]. |
631 |
^ true |
|
632 |
! |
|
633 |
||
3265 | 634 |
size |
635 |
"return the number of colors in the receiver" |
|
636 |
||
637 |
^ redVector size |
|
638 |
||
639 |
"Modified: 23.4.1996 / 22:13:43 / cg" |
|
1435 | 640 |
! ! |
641 |
||
7804 | 642 |
!Colormap methodsFor:'testing'! |
643 |
||
644 |
isColormap |
|
645 |
^ true |
|
7836 | 646 |
! |
647 |
||
648 |
isMappedPalette |
|
649 |
^ false |
|
650 |
||
651 |
"Created: / 03-02-2017 / 21:41:11 / cg" |
|
7804 | 652 |
! ! |
653 |
||
1092 | 654 |
!Colormap class methodsFor:'documentation'! |
285 | 655 |
|
656 |
version |
|
7241 | 657 |
^ '$Header$' |
285 | 658 |
! ! |
6059 | 659 |