author | Claus Gittinger <cg@exept.de> |
Sun, 27 Aug 2000 16:47:34 +0200 | |
changeset 3271 | 51d0adbc1aa0 |
parent 3265 | 408fac627dc4 |
child 3276 | 9ed39f7e7282 |
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 |
" |
|
40 |
Colormaps are used with images (and Forms) to keep the byte-to-color |
|
41 |
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). |
|
602 | 45 |
This was done to avoid overhead due to allocation of many color |
46 |
instances. |
|
47 |
||
611 | 48 |
|
49 |
[author:] |
|
50 |
Claus Gittinger |
|
51 |
||
602 | 52 |
[see also:] |
603 | 53 |
Color Image Form |
91 | 54 |
" |
55 |
! ! |
|
56 |
||
1092 | 57 |
!Colormap class methodsFor:'instance creation'! |
91 | 58 |
|
118 | 59 |
fromColors:aColorArray |
1377 | 60 |
"given a sequenceable collection of colors, return a new instance |
602 | 61 |
of myself" |
62 |
||
1377 | 63 |
^ self withColors:aColorArray |
64 |
||
65 |
" |
|
66 |
Colormap |
|
67 |
fromColors:(Array with:Color black |
|
68 |
with:Color red |
|
69 |
with:Color white) |
|
70 |
" |
|
71 |
||
72 |
"Modified: 25.2.1997 / 19:00:31 / cg" |
|
73 |
! |
|
74 |
||
2448
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
75 |
new:numColors |
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
76 |
^ self withColors:(Array new:numColors withAll:Color black) |
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
77 |
! |
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
78 |
|
1377 | 79 |
redVector:r greenVector:g blueVector:b |
80 |
"given vectors of red/green/and blue pixelValues, |
|
81 |
return a new instance of myself. |
|
82 |
The values must be in the range 0..255." |
|
83 |
||
84 |
^ self new redVector:r greenVector:g blueVector:b |
|
85 |
||
86 |
" |
|
87 |
Colormap |
|
88 |
redVector:#[0 127 255] |
|
89 |
greenVector:#[0 127 255] |
|
90 |
blueVector:#[0 127 255] |
|
91 |
" |
|
92 |
||
93 |
"Modified: 23.4.1996 / 22:16:00 / cg" |
|
94 |
! |
|
95 |
||
96 |
withColors:aColorArray |
|
97 |
"given a sequenceable collection of colors, return a new instance |
|
98 |
of myself. Renamed from #fromColors: for ST-80 compatibility." |
|
99 |
||
1378
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
100 |
^ self new colors:aColorArray |
118 | 101 |
|
102 |
" |
|
103 |
Colormap |
|
1377 | 104 |
withColors:(Array with:Color black |
602 | 105 |
with:Color red |
106 |
with:Color white) |
|
118 | 107 |
" |
602 | 108 |
|
1377 | 109 |
"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
|
110 |
"Modified: 25.2.1997 / 19:03:08 / cg" |
285 | 111 |
! ! |
91 | 112 |
|
285 | 113 |
!Colormap methodsFor:'accessing'! |
91 | 114 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
115 |
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
|
116 |
"return the color for a index. |
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
117 |
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
|
118 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
119 |
|r g b idx "{ Class: SmallInteger }" | |
91 | 120 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
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
|
125 |
|
1351 | 126 |
^ 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
|
127 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
128 |
"Created: 2.5.1996 / 12:21:40 / cg" |
808 | 129 |
"Modified: 8.6.1996 / 14:25:30 / cg" |
91 | 130 |
! |
131 |
||
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
132 |
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
|
133 |
"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
|
134 |
Notice that index range is 1..." |
91 | 135 |
|
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
136 |
|r g b idx "{ Class: SmallInteger }" | |
572 | 137 |
|
91 | 138 |
r := (aColor red * 255 / 100) rounded. |
139 |
g := (aColor green * 255 / 100) rounded. |
|
140 |
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
|
141 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
142 |
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
|
143 |
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
|
144 |
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
|
145 |
blueVector at:idx put:b. |
572 | 146 |
^ aColor |
147 |
||
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
148 |
"Modified: 2.5.1996 / 17:29:29 / cg" |
118 | 149 |
! |
91 | 150 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
151 |
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
|
152 |
"return the blue component for some index. |
153 | 153 |
The returned value is scaled from the internal 0.. 255 to |
154 |
a percentage value 0..100" |
|
155 |
||
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
156 |
^ (blueVector at:index) * 100 / 255 |
285 | 157 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
158 |
"Modified: 2.5.1996 / 17:29:17 / cg" |
285 | 159 |
! |
160 |
||
161 |
colors |
|
162 |
"ST-80 compatibility: return a collection containing the colors I hold" |
|
163 |
||
164 |
^ self asArray |
|
153 | 165 |
! |
166 |
||
1378
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
167 |
colors:aCollectionOfColors |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
168 |
"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
|
169 |
|
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
170 |
|sz "{Class: SmallInteger }"| |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
171 |
|
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
172 |
sz := aCollectionOfColors size. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
173 |
redVector := ByteArray new:sz. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
174 |
greenVector := ByteArray new:sz. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
175 |
blueVector := ByteArray new:sz. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
176 |
|
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
177 |
1 to:sz do:[:i | |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
178 |
|clr r g b| |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
179 |
|
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
180 |
clr := aCollectionOfColors at:i. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
181 |
clr notNil ifTrue:[ |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
182 |
redVector at:i put:(clr redByte). |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
183 |
greenVector at:i put:(clr greenByte). |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
184 |
blueVector at:i put:(clr blueByte). |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
185 |
] |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
186 |
]. |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
187 |
|
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
188 |
"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
|
189 |
! |
a83a3522a199
moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
190 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
191 |
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
|
192 |
"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
|
193 |
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
|
194 |
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
|
195 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
196 |
^ (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
|
197 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
198 |
"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
|
199 |
! |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
200 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
201 |
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
|
202 |
"return the red component for some index. |
153 | 203 |
The returned value is scaled from the internal 0.. 255 to |
204 |
a percentage value 0..100" |
|
205 |
||
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
206 |
^ (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
|
207 |
|
637
08e099c202db
oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
208 |
"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
|
209 |
! ! |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
210 |
|
1092 | 211 |
!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
|
212 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
213 |
blueVector |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
214 |
"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
|
215 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
216 |
^ blueVector |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
217 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
218 |
"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
|
219 |
! |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
220 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
221 |
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
|
222 |
"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
|
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 |
blueVector := something. |
153 | 225 |
! |
226 |
||
285 | 227 |
greenVector |
228 |
"return greenVector" |
|
229 |
||
230 |
^ greenVector |
|
231 |
! |
|
232 |
||
233 |
greenVector:something |
|
234 |
"set greenVector" |
|
235 |
||
236 |
greenVector := something. |
|
237 |
! |
|
238 |
||
239 |
redVector |
|
240 |
"return redVector" |
|
241 |
||
242 |
^ redVector |
|
153 | 243 |
! |
244 |
||
285 | 245 |
redVector:something |
246 |
"set redVector" |
|
153 | 247 |
|
285 | 248 |
redVector := something. |
249 |
! |
|
91 | 250 |
|
285 | 251 |
redVector:r greenVector:g blueVector:b |
602 | 252 |
"set the red, green and blueVectors" |
253 |
||
285 | 254 |
redVector := r. |
255 |
greenVector := g. |
|
256 |
blueVector := b. |
|
602 | 257 |
|
258 |
"Modified: 23.4.1996 / 22:13:31 / cg" |
|
91 | 259 |
! ! |
260 |
||
943 | 261 |
!Colormap methodsFor:'converting'! |
917
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
262 |
|
941 | 263 |
asArray |
944 | 264 |
"return the receiver as an array containing my colors" |
941 | 265 |
|
266 |
|r g b n "{ Class: SmallInteger }" |
|
267 |
scale array| |
|
268 |
||
269 |
n := redVector size. |
|
270 |
array := Array new:n. |
|
271 |
scale := Color scalingValue / 255.0. |
|
272 |
||
273 |
1 to:n do:[:idx | |
|
274 |
r := redVector at:idx. |
|
275 |
g := greenVector at:idx. |
|
276 |
b := blueVector at:idx. |
|
277 |
||
278 |
array at:idx put:(Color |
|
279 |
scaledRed:(r * scale) rounded |
|
280 |
scaledGreen:(g * scale) rounded |
|
281 |
scaledBlue:(b * scale) rounded) |
|
943 | 282 |
]. |
283 |
^ array |
|
941 | 284 |
|
285 |
"Created: 11.7.1996 / 20:19:45 / cg" |
|
944 | 286 |
"Modified: 11.7.1996 / 21:34:16 / cg" |
943 | 287 |
! ! |
288 |
||
289 |
!Colormap methodsFor:'copying'! |
|
941 | 290 |
|
2483 | 291 |
copyFrom:start to:stop |
292 |
^ self class withColors:(self asArray copyFrom:start to:stop) |
|
293 |
! |
|
294 |
||
917
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
295 |
postCopy |
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
296 |
redVector := redVector copy. |
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
297 |
greenVector := greenVector copy. |
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
298 |
blueVector := blueVector copy. |
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
299 |
|
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
300 |
"Created: 5.7.1996 / 14:52:15 / cg" |
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
301 |
! ! |
d0ab9a4e0344
postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
302 |
|
91 | 303 |
!Colormap methodsFor:'misc'! |
304 |
||
2448
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
305 |
grow:howBig |
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
306 |
"change the receivers size - not allowed" |
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
307 |
|
3271 | 308 |
|t| |
2448
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
309 |
|
3271 | 310 |
howBig == self size ifTrue:[^ self]. |
311 |
redVector isNil ifTrue:[ |
|
312 |
redVector := ByteArray new:howBig. |
|
313 |
greenVector := ByteArray new:howBig. |
|
314 |
blueVector := ByteArray new:howBig. |
|
315 |
^ self |
|
316 |
]. |
|
317 |
t := redVector. redVector := ByteArray new:howBig. redVector replaceFrom:1 to:t size with:t startingAt:1. |
|
318 |
t := greenVector. greenVector := ByteArray new:howBig. greenVector replaceFrom:1 to:t size with:t startingAt:1. |
|
319 |
t := blueVector. blueVector := ByteArray new:howBig. blueVector replaceFrom:1 to:t size with:t startingAt:1. |
|
320 |
^ self |
|
2448
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
321 |
|
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
322 |
! |
89c338d3412e
more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
323 |
|
91 | 324 |
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
|
325 |
"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
|
326 |
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
|
327 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
328 |
|sz "{ Class: SmallInteger }" | |
91 | 329 |
|
635
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
330 |
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
|
331 |
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
|
332 |
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
|
333 |
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
|
334 |
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
|
335 |
] |
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
336 |
|
1e1c3f870ba8
colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
337 |
"Modified: 2.5.1996 / 12:46:07 / cg" |
91 | 338 |
! ! |
285 | 339 |
|
1435 | 340 |
!Colormap methodsFor:'queries'! |
341 |
||
342 |
indexOfPaintNearest: color |
|
343 |
|minDistance minIndex dist |
|
344 |
sz "{ Class: SmallInteger }"| |
|
345 |
||
346 |
minDistance := (self at:1) deltaFrom:color. |
|
347 |
minIndex := 1. |
|
348 |
sz := self size. |
|
349 |
2 to:sz do:[:idx | |
|
350 |
dist := (self at:idx) deltaFrom:color. |
|
351 |
dist < minDistance ifTrue:[ |
|
352 |
minDistance := dist. |
|
353 |
minIndex := idx. |
|
354 |
] |
|
355 |
]. |
|
356 |
^ minIndex |
|
357 |
||
358 |
"Created: 6.3.1997 / 15:45:39 / cg" |
|
3265 | 359 |
! |
360 |
||
361 |
size |
|
362 |
"return the number of colors in the receiver" |
|
363 |
||
364 |
^ redVector size |
|
365 |
||
366 |
"Modified: 23.4.1996 / 22:13:43 / cg" |
|
1435 | 367 |
! ! |
368 |
||
773 | 369 |
!Colormap methodsFor:'storing'! |
370 |
||
371 |
storeOn:aStream |
|
372 |
"append a representation to aStream, from which the receiver |
|
373 |
can be reconstructed" |
|
374 |
||
375 |
aStream nextPutAll:'(' , self class name ,' redVector:'. |
|
376 |
redVector storeOn:aStream. |
|
377 |
aStream nextPutAll:' greenVector:'. |
|
378 |
greenVector storeOn:aStream. |
|
379 |
aStream nextPutAll:' blueVector:'. |
|
380 |
blueVector storeOn:aStream. |
|
381 |
aStream nextPutAll:')' |
|
382 |
||
383 |
"Created: 30.5.1996 / 16:28:27 / ca" |
|
384 |
"Modified: 30.5.1996 / 16:32:44 / ca" |
|
385 |
! ! |
|
386 |
||
1092 | 387 |
!Colormap class methodsFor:'documentation'! |
285 | 388 |
|
389 |
version |
|
3271 | 390 |
^ '$Header: /cvs/stx/stx/libview/Colormap.st,v 1.28 2000-08-27 14:47:34 cg Exp $' |
285 | 391 |
! ! |