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