35 |
35 |
36 documentation |
36 documentation |
37 " |
37 " |
38 Colormaps are used with images (and Forms) to keep the byte-to-color |
38 Colormaps are used with images (and Forms) to keep the byte-to-color |
39 mapping. |
39 mapping. |
|
40 Externally, either colors or pixel values can be accessed. |
40 Internally, the values are stored as 3 separate byte-arrays |
41 Internally, the values are stored as 3 separate byte-arrays |
41 (i.e. individual components can be 0..255). |
42 (i.e. individual components can be 0..255). |
|
43 This was done to avoid overhead due to allocation of many color |
|
44 instances. |
|
45 |
|
46 [see also:] |
|
47 Color |
42 " |
48 " |
43 ! ! |
49 ! ! |
44 |
50 |
45 !Colormap class methodsFor:'instance creation'! |
51 !Colormap class methodsFor:'instance creation'! |
46 |
52 |
47 fromColors:aColorArray |
53 fromColors:aColorArray |
|
54 "given a collection of real colors, return a new instance |
|
55 of myself" |
|
56 |
48 |n rV gV bV| |
57 |n rV gV bV| |
49 |
58 |
50 n := aColorArray size. |
59 n := aColorArray size. |
51 rV := ByteArray new:n. |
60 rV := ByteArray new:n. |
52 gV := ByteArray new:n. |
61 gV := ByteArray new:n. |
53 bV := ByteArray new:n. |
62 bV := ByteArray new:n. |
54 1 to:n do:[:i | |
63 1 to:n do:[:i | |
55 |clr| |
64 |clr| |
56 |
65 |
57 clr := aColorArray at:i. |
66 clr := aColorArray at:i. |
58 rV at:i put:(clr red * 255 / 100) rounded. |
67 rV at:i put:(clr red * 255 / 100) rounded. |
59 bV at:i put:(clr green * 255 / 100) rounded. |
68 bV at:i put:(clr green * 255 / 100) rounded. |
60 gV at:i put:(clr blue * 255 / 100) rounded. |
69 gV at:i put:(clr blue * 255 / 100) rounded. |
61 ]. |
70 ]. |
62 ^ self new redVector:rV greenVector:gV blueVector:bV |
71 ^ self new redVector:rV greenVector:gV blueVector:bV |
63 |
72 |
64 " |
73 " |
65 Colormap |
74 Colormap |
66 fromColors:(Array with:Color black |
75 fromColors:(Array with:Color black |
67 with:Color red |
76 with:Color red |
68 with:Color white) |
77 with:Color white) |
69 " |
78 " |
|
79 |
|
80 "Modified: 23.4.1996 / 22:15:22 / cg" |
70 ! |
81 ! |
71 |
82 |
72 redVector:r greenVector:g blueVector:b |
83 redVector:r greenVector:g blueVector:b |
|
84 "given vectors of red/green/and blue pixelValues, |
|
85 return a new instance of myself. |
|
86 The values must be in the range 0..255." |
|
87 |
73 ^ self new redVector:r greenVector:g blueVector:b |
88 ^ self new redVector:r greenVector:g blueVector:b |
74 |
89 |
75 " |
90 " |
76 Colormap |
91 Colormap |
77 redVector:#[0 127 255] |
92 redVector:#[0 127 255] |
78 greenVector:#[0 127 255] |
93 greenVector:#[0 127 255] |
79 blueVector:#[0 127 255] |
94 blueVector:#[0 127 255] |
80 " |
95 " |
|
96 |
|
97 "Modified: 23.4.1996 / 22:16:00 / cg" |
81 ! ! |
98 ! ! |
82 |
99 |
83 !Colormap methodsFor:'accessing'! |
100 !Colormap methodsFor:'accessing'! |
84 |
101 |
85 at:index |
102 at:index |
184 |
201 |
185 redVector := something. |
202 redVector := something. |
186 ! |
203 ! |
187 |
204 |
188 redVector:r greenVector:g blueVector:b |
205 redVector:r greenVector:g blueVector:b |
|
206 "set the red, green and blueVectors" |
|
207 |
189 redVector := r. |
208 redVector := r. |
190 greenVector := g. |
209 greenVector := g. |
191 blueVector := b. |
210 blueVector := b. |
|
211 |
|
212 "Modified: 23.4.1996 / 22:13:31 / cg" |
192 ! |
213 ! |
193 |
214 |
194 size |
215 size |
|
216 "return the number of colors in the receiver" |
|
217 |
195 ^ redVector size |
218 ^ redVector size |
|
219 |
|
220 "Modified: 23.4.1996 / 22:13:43 / cg" |
196 ! ! |
221 ! ! |
197 |
222 |
198 !Colormap methodsFor:'misc'! |
223 !Colormap methodsFor:'misc'! |
199 |
224 |
200 scaleValuesBy:scaleFactor |
225 scaleValuesBy:scaleFactor |