author | Claus Gittinger <cg@exept.de> |
Mon, 24 Feb 1997 18:32:40 +0100 | |
changeset 1365 | 37a9e7ac4dbc |
parent 1348 | acb4e4874e4d |
child 1368 | cb5fbbcf568f |
permissions | -rw-r--r-- |
1023 | 1 |
" |
2 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
1348 | 3 |
All Rights Reserved |
1023 | 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 |
||
13 |
Object subclass:#Color |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
14 |
instanceVariableNames:'red green blue device colorId ditherForm replacementColor |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
15 |
writable' |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
16 |
classVariableNames:'MaxValue Cells Black White LightGrey Grey DarkGrey Pseudo0 |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
17 |
Pseudo1 PseudoAll Red Green Blue RetryAllocation DitherBits |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
18 |
ColorAllocationFailSignal InvalidColorNameSignal' |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
19 |
poolDictionaries:'' |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
20 |
category:'Graphics-Support' |
1023 | 21 |
! |
22 |
||
1144 | 23 |
!Color class methodsFor:'documentation'! |
1023 | 24 |
|
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
1348 | 28 |
All Rights Reserved |
1023 | 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 |
" |
|
41 |
Color represents colors in a device independent manner, main info I keep about |
|
42 |
mySelf are the red, green and blue components scaled into 0 .. MaxValue. |
|
43 |
The device specific color can be aquired by sending a color the 'on:aDevice' message, |
|
44 |
which will return a color with the same rgb values as the receiver but specific |
|
45 |
for that device. |
|
46 |
||
47 |
Colors can be pure or dithered, depending on the capabilities of the device. |
|
48 |
For plain colors, the colorId-instvar is a handle (usually lookup-table entry) for that |
|
49 |
device. For dithered colors, the colorId is nil and ditherForm specifies the form |
|
50 |
used to dither that color. The ditherForm can be either a depth-1 bitmap or a pixmap |
|
51 |
with the devices depth. The plain colors needed by the ditherForm are found in its |
|
52 |
colormap (as usual for bitmaps). |
|
53 |
||
54 |
The default algorithm for color allocation is to ask the display for colors as |
|
55 |
new colors are created. When running out of colors, dithered colors will be used, |
|
56 |
using existing nearest colors and a dither pattern to aproximate the color. |
|
57 |
There could be situations, where no good colors are available for the dither, leading |
|
58 |
to ugly looking dither colors. |
|
59 |
This can be avoided by preallocating a set of colors over the complete range, which |
|
60 |
makes certain that appropriate colors are later available for the dither process. |
|
61 |
To do so, add a statement like: 'Color getColors5x5x5' to the startup.rc file. |
|
62 |
(beside 5x5x5, there are various other size combinations available). |
|
63 |
However, doing so may make things worse when displaying bitmap images, since this |
|
64 |
preallocated table may steal colors from the image ... |
|
65 |
||
66 |
[Instance variables:] |
|
67 |
||
68 |
red <Integer> the red component (0..MaxValue) |
|
69 |
green <Integer> the green component (0..MaxValue) |
|
70 |
blue <Integer> the blue component (0..MaxValue) |
|
71 |
||
72 |
device <Device> the device I am on, or nil |
|
73 |
colorId <Object> some device dependent identifier (or nil if dithered) |
|
74 |
ditherForm <Form> the Form to dither this color (if non-nil) |
|
75 |
writable <Boolean> true if this is for a writable color cell |
|
76 |
||
77 |
[Class variables:] |
|
78 |
||
79 |
MaxValue <Integer> r/g/b components are scaled relative to this maximum |
|
80 |
||
81 |
Lobby <Registry> all colors in use - keeps track of already allocated |
|
1229 | 82 |
colors for reuse and finalization. |
83 |
(dont use it: this will be moved to the device) |
|
84 |
||
1023 | 85 |
Cells <Registry> keeps track of allocated writable color cells |
1229 | 86 |
(dont use it: this will be moved to the device) |
1023 | 87 |
|
88 |
FixColors <Array> preallocated colors for dithering on Display |
|
89 |
NumRedFix <Integer> number of distinct red values in FixColors |
|
90 |
NumGreenFix <Integer> number of distinct green values in FixColors |
|
91 |
NumBlueFix <Integer> number of distinct blue values in FixColors |
|
92 |
||
93 |
Black <Color> for fast return of black |
|
94 |
White <Color> for fast return of white |
|
95 |
Grey <Color> for fast return of grey |
|
96 |
LightGrey <Color> for fast return of lightGrey |
|
97 |
DarkGrey <Color> for fast return of darkGrey |
|
98 |
||
99 |
Pseudo0 <Color> a color with 0 as handle (for forms and bitblit) |
|
100 |
Pseudo1 <Color> a color with 1 as handle (for forms) |
|
101 |
PseudoAll <Color> a color with allPlanes as handle (for bitblit) |
|
102 |
||
103 |
Red <Color> red, needed for dithering |
|
104 |
Green <Color> green, for dithering |
|
105 |
Blue <Color> blue, for dithering |
|
106 |
||
107 |
DitherColors <Collection> some preallocated colors for dithering |
|
1229 | 108 |
(kept, so they are available when needed) |
1023 | 109 |
|
110 |
RetryAllocation <Boolean> this flag controls how a request for a |
|
1229 | 111 |
color should be handled which failed previously. |
112 |
I.e. a color is asked for, which was dithered |
|
113 |
the last time. Since it could happen, that in |
|
114 |
the meantime more colors became free, the request |
|
115 |
might succeed this time - however, your screen may |
|
116 |
look a bit funny, due to having both dithered and |
|
117 |
undithered versions around. |
|
118 |
The default is true, which means: do retry |
|
1023 | 119 |
|
120 |
compatibility issues: |
|
121 |
||
1229 | 122 |
ST-80 seems to represent colors internally with scaled smallInteger |
123 |
components (this can be guessed from uses of |
|
124 |
scaledRed:scaledGreen:scaledBlue:). The main instance creation method is |
|
125 |
via 'ColorValue red:green:blue:', passing components in 0..1. |
|
126 |
In ST/X, component are internally represented as percent. |
|
127 |
For more compatibility (when subclassing color), these internals may |
|
128 |
change in the near future. For migration, a compatibility subclass |
|
129 |
called ColorValue is provided. |
|
130 |
After the change, Color will be renamed to ColorValue and Color |
|
131 |
be made a subclass of ColorValue (offering the 0..100 interface for |
|
132 |
backward compatibility). |
|
1023 | 133 |
|
134 |
[see also:] |
|
1229 | 135 |
DeviceWorkstation |
136 |
GraphicsContext DeviceDrawable Form Image Colormap |
|
137 |
Font Cursor |
|
1023 | 138 |
|
139 |
[author:] |
|
1229 | 140 |
Claus Gittinger |
1023 | 141 |
" |
142 |
! ! |
|
143 |
||
1144 | 144 |
!Color class methodsFor:'initialization'! |
1023 | 145 |
|
146 |
flushDeviceColors |
|
147 |
"unassign all colors from their device" |
|
148 |
||
149 |
self allInstances do:[:aColor | |
|
1348 | 150 |
aColor restored |
1023 | 151 |
]. |
152 |
||
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
153 |
"Modified: 24.2.1997 / 18:27:06 / cg" |
1023 | 154 |
! |
155 |
||
156 |
getColors6x6x4 |
|
157 |
"preallocates a 6x6x4 (144) colorMap and later uses those colors only. |
|
158 |
Doing so has the advantage that the system will never run out of colors, |
|
159 |
however, colors may be either inexact or dithered." |
|
160 |
||
161 |
self getColorsRed:6 green:6 blue:4 |
|
162 |
||
163 |
" |
|
164 |
Color getColors6x6x4 |
|
165 |
" |
|
166 |
! |
|
167 |
||
168 |
getColors6x6x5 |
|
169 |
"preallocates a 6x6x5 (180) colorMap and later uses those colors only. |
|
170 |
Doing so has the advantage that the system will never run out of colors, |
|
171 |
however, colors may be either inexact or dithered." |
|
172 |
||
173 |
self getColorsRed:6 green:6 blue:5 |
|
174 |
||
175 |
" |
|
176 |
Color getColors6x6x5 |
|
177 |
" |
|
178 |
! |
|
179 |
||
180 |
getColors6x6x6 |
|
181 |
"preallocates a 6x6x6 (196) colorMap and later uses those colors only. |
|
182 |
Doing so has the advantage that the system will never run out of colors, |
|
183 |
however, colors may be either inexact or dithered." |
|
184 |
||
185 |
self getColorsRed:6 green:6 blue:6 |
|
186 |
||
187 |
" |
|
188 |
Color getColors6x6x6 |
|
189 |
" |
|
190 |
! |
|
191 |
||
192 |
getColors6x7x4 |
|
193 |
"preallocates a 6x7x4 (168) colorMap and later uses those colors only. |
|
194 |
Doing so has the advantage that the system will never run out of colors, |
|
195 |
however, colors may be either inexact or dithered." |
|
196 |
||
197 |
self getColorsRed:6 green:7 blue:4 |
|
198 |
||
199 |
" |
|
200 |
Color getColors6x7x4 |
|
201 |
" |
|
202 |
||
203 |
"Created: 12.6.1996 / 17:41:57 / cg" |
|
204 |
! |
|
205 |
||
206 |
getColors7x8x4 |
|
207 |
"preallocates a 7x8x4 (224) colorMap and later uses those colors only. |
|
208 |
Doing so has the advantage that the system will never run out of colors, |
|
209 |
however, colors may be either inexact or dithered." |
|
210 |
||
211 |
self getColorsRed:7 green:8 blue:4 |
|
212 |
||
213 |
" |
|
214 |
Color getColors7x8x4 |
|
215 |
" |
|
216 |
! |
|
217 |
||
218 |
getColorsRed:nRed green:nGreen blue:nBlue |
|
219 |
"preallocates a nR x nG x nB colorMap for later use in dithering. |
|
220 |
Doing so has the advantage that the system will never run out of colors, |
|
221 |
however, colors may be either inexact or dithered." |
|
222 |
||
223 |
self getColorsRed:nRed green:nGreen blue:nBlue on:Display |
|
224 |
||
225 |
" |
|
226 |
Color getColorsRed:2 green:2 blue:2 |
|
227 |
" |
|
228 |
||
229 |
"Modified: 11.7.1996 / 17:58:09 / cg" |
|
230 |
! |
|
231 |
||
232 |
getColorsRed:nRed green:nGreen blue:nBlue on:aDevice |
|
233 |
"preallocates a nR x nG x nB colorMap for later use in dithering. |
|
234 |
Doing so has the advantage that the system will never run out of colors, |
|
235 |
however, colors may be either inexact or dithered." |
|
236 |
||
237 |
|nR "{Class: SmallInteger }" |
|
238 |
nG "{Class: SmallInteger }" |
|
239 |
nB "{Class: SmallInteger }" |
|
240 |
dR dG dB red green blue dstIndex clr round |
|
241 |
fixColors| |
|
242 |
||
243 |
aDevice visualType == #TrueColor ifTrue:[^ self]. |
|
244 |
||
245 |
nR := nRed. |
|
246 |
nG := nGreen. |
|
247 |
nB := nBlue. |
|
248 |
||
249 |
dR := 100.0 / (nR - 1). |
|
250 |
dG := 100.0 / (nG - 1). |
|
251 |
dB := 100.0 / (nB - 1). |
|
252 |
||
253 |
fixColors := Array new:(nR * nG * nB). |
|
254 |
||
255 |
round := 0. |
|
256 |
||
257 |
dstIndex := 1. |
|
258 |
1 to:nR do:[:sR | |
|
1165 | 259 |
red := dR * (sR - 1). |
260 |
1 to:nG do:[:sG | |
|
261 |
green := dG * (sG - 1). |
|
262 |
1 to:nB do:[:sB | |
|
263 |
blue := dB * (sB - 1). |
|
264 |
clr := (self red:red green:green blue:blue) exactOn:aDevice. |
|
265 |
clr isNil ifTrue:[ |
|
266 |
round == 0 ifTrue:[ |
|
267 |
'Color [info]: scavenge to reclaim colors' infoPrintCR. |
|
268 |
ObjectMemory scavenge. |
|
269 |
round := 1. |
|
270 |
clr := (self red:red green:green blue:blue) exactOn:aDevice. |
|
271 |
]. |
|
272 |
]. |
|
273 |
clr isNil ifTrue:[ |
|
274 |
round == 1 ifTrue:[ |
|
275 |
'Color [info]: collect garbage to reclaim colors' infoPrintCR. |
|
276 |
ObjectMemory performLowSpaceCleanup. |
|
277 |
ObjectMemory garbageCollect. |
|
278 |
round := 2. |
|
279 |
clr := (self red:red green:green blue:blue) exactOn:aDevice. |
|
280 |
]. |
|
281 |
]. |
|
282 |
clr isNil ifTrue:[ |
|
283 |
ColorAllocationFailSignal raiseErrorString:'failed to allocate fix color'. |
|
284 |
^ self |
|
285 |
]. |
|
286 |
fixColors at:dstIndex put:clr. |
|
287 |
dstIndex := dstIndex + 1 |
|
288 |
] |
|
289 |
] |
|
1023 | 290 |
]. |
291 |
aDevice setFixColors:fixColors |
|
1165 | 292 |
numRed:nR numGreen:nG numBlue:nB |
1023 | 293 |
|
294 |
" |
|
295 |
Color getColorsRed:2 green:2 blue:2 on:Display |
|
296 |
" |
|
297 |
||
298 |
"Created: 11.7.1996 / 17:55:32 / cg" |
|
1165 | 299 |
"Modified: 10.1.1997 / 15:37:13 / cg" |
1023 | 300 |
! |
301 |
||
302 |
getPrimaryColors |
|
303 |
"preallocate the primary colors. |
|
304 |
Doing so during early startup prevents us from running out |
|
305 |
of (at least those required) colors later. |
|
306 |
This guarantees, that at least some colors are available |
|
307 |
for dithering." |
|
308 |
||
309 |
self getPrimaryColorsOn:Display |
|
310 |
||
311 |
"Modified: 11.7.1996 / 18:12:17 / cg" |
|
312 |
! |
|
313 |
||
314 |
getPrimaryColorsOn:aDevice |
|
315 |
"preallocate the primary colors. |
|
316 |
Doing so during early startup prevents us from running out |
|
317 |
of (at least those required) colors later. |
|
318 |
This guarantees, that at least some colors are available |
|
319 |
for dithering (although, with only black, white, red, green and blue, |
|
320 |
dithered images look very poor)." |
|
321 |
||
322 |
|colors white black red green blue| |
|
323 |
||
324 |
(aDevice notNil and:[aDevice ditherColors isNil]) ifTrue:[ |
|
1348 | 325 |
white := (self red:100 green:100 blue:100) exactOn:aDevice. |
326 |
black := (self red:0 green:0 blue:0) exactOn:aDevice. |
|
327 |
||
328 |
aDevice hasColors ifTrue:[ |
|
329 |
red := (self red:100 green:0 blue:0) exactOn:aDevice. |
|
330 |
green := (self red:0 green:100 blue:0) exactOn:aDevice. |
|
331 |
blue := (self red:0 green:0 blue:100) exactOn:aDevice. |
|
332 |
]. |
|
333 |
||
334 |
aDevice == Display ifTrue:[ |
|
335 |
"/ keep those around for the main display |
|
336 |
White := white. |
|
337 |
Black := black. |
|
338 |
Red := red. |
|
339 |
Green := green. |
|
340 |
Blue := blue |
|
341 |
]. |
|
342 |
||
343 |
aDevice visualType ~~ #TrueColor ifTrue:[ |
|
344 |
aDevice hasColors ifTrue:[ |
|
345 |
||
346 |
"preallocate some colors for dithering |
|
347 |
- otherwise, they may not be available when we need them ... |
|
348 |
these are: black, white, grey50, |
|
349 |
red, green, blue, yellow, cyan and magenta. |
|
350 |
" |
|
351 |
||
352 |
colors := OrderedCollection new. |
|
353 |
colors add:((self gray:50) exactOn:aDevice). |
|
354 |
||
355 |
colors add:white; add:black; add:red; add:green; add:blue. |
|
356 |
||
357 |
colors add:((self red:100 green:100 blue:0) exactOn:aDevice). |
|
358 |
colors add:((self red:100 green:0 blue:100) exactOn:aDevice). |
|
359 |
colors add:((self red:0 green:100 blue:100) exactOn:aDevice). |
|
360 |
||
361 |
colors := colors select:[:clr | clr notNil]. |
|
362 |
]. |
|
363 |
||
364 |
aDevice hasGreyscales ifTrue:[ |
|
365 |
aDevice hasColors ifFalse:[ |
|
366 |
colors := OrderedCollection new. |
|
367 |
colors add:((self gray:50) exactOn:aDevice). |
|
368 |
colors add:white; add:black. |
|
369 |
||
370 |
]. |
|
371 |
colors add:((self gray:25) exactOn:aDevice). |
|
372 |
colors add:((self gray:33) exactOn:aDevice). |
|
373 |
colors add:((self gray:67) exactOn:aDevice). |
|
374 |
colors add:((self gray:75) exactOn:aDevice). |
|
375 |
||
376 |
colors := colors select:[:clr | clr notNil]. |
|
377 |
]. |
|
378 |
||
379 |
colors notNil ifTrue:[ |
|
380 |
aDevice setDitherColors:(colors asArray). |
|
381 |
] |
|
382 |
] |
|
1023 | 383 |
] |
384 |
||
385 |
"Created: 11.7.1996 / 18:09:28 / cg" |
|
386 |
"Modified: 11.7.1996 / 18:27:39 / cg" |
|
387 |
! |
|
388 |
||
389 |
initialize |
|
390 |
"setup tracker of known colors and initialize classvars with |
|
391 |
heavily used colors" |
|
392 |
||
393 |
ColorAllocationFailSignal isNil ifTrue:[ |
|
1269
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
394 |
ColorAllocationFailSignal := ErrorSignal newSignalMayProceed:true. |
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
395 |
ColorAllocationFailSignal nameClass:self message:#colorAllocationFailSignal. |
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
396 |
ColorAllocationFailSignal notifierString:'color allocation failed'. |
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
397 |
|
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
398 |
InvalidColorNameSignal := ErrorSignal newSignalMayProceed:true. |
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
399 |
InvalidColorNameSignal nameClass:self message:#invalidColorNameSignal. |
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
400 |
InvalidColorNameSignal notifierString:'invalid color name'. |
1023 | 401 |
]. |
402 |
||
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
403 |
MaxValue := 16rFFFF. |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
404 |
|
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
405 |
self getPrimaryColors. |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
406 |
|
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
407 |
"want to be informed when returning from snapshot" |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
408 |
ObjectMemory addDependent:self. |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
409 |
|
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
410 |
RetryAllocation := true. |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
411 |
|
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
412 |
DitherBits := self ditherBits. |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
413 |
|
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
414 |
" |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
415 |
Color initialize |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
416 |
" |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
417 |
|
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
418 |
"Modified: 24.2.1997 / 18:26:41 / cg" |
1023 | 419 |
! |
420 |
||
421 |
update:something with:aParameter from:changedObject |
|
422 |
"handle image restarts and flush any device resource handles" |
|
423 |
||
424 |
(something == #restarted) ifTrue:[ |
|
1348 | 425 |
self flushDeviceColors |
1023 | 426 |
]. |
427 |
(something == #returnFromSnapshot) ifTrue:[ |
|
1348 | 428 |
self getPrimaryColors. |
429 |
||
430 |
Display visualType == #TrueColor ifTrue:[ |
|
431 |
Display releaseFixColors |
|
432 |
] ifFalse:[ |
|
433 |
Display fixColors notNil ifTrue:[ |
|
434 |
ColorAllocationFailSignal handle:[:ex | |
|
435 |
ex return |
|
436 |
] do:[ |
|
437 |
|nR nG nB| |
|
438 |
||
439 |
nR := Display numFixRed. |
|
440 |
nG := Display numFixGreen. |
|
441 |
nB := Display numFixBlue. |
|
442 |
Display releaseFixColors. |
|
443 |
self getColorsRed:nR |
|
444 |
green:nG |
|
445 |
blue:nB |
|
446 |
on:Display |
|
447 |
] |
|
448 |
] |
|
449 |
] |
|
1023 | 450 |
] |
451 |
||
452 |
"Created: 15.6.1996 / 15:14:03 / cg" |
|
453 |
"Modified: 11.7.1996 / 18:03:38 / cg" |
|
454 |
! ! |
|
455 |
||
1144 | 456 |
!Color class methodsFor:'instance creation'! |
1023 | 457 |
|
458 |
allColor |
|
459 |
"return a special color which, when used for bit-blitting will |
|
460 |
behave like a all-1-color (i.e. have a device-pixel value of all-1s)" |
|
461 |
||
462 |
PseudoAll isNil ifTrue:[ |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
463 |
PseudoAll := self basicNew setColorId:-1 |
1023 | 464 |
]. |
465 |
^ PseudoAll |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
466 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
467 |
"Modified: 17.1.1997 / 00:05:36 / cg" |
1023 | 468 |
! |
469 |
||
470 |
brightness:brightness |
|
471 |
"create a gray color with given brightness (0..1). |
|
472 |
ST-80 compatibility." |
|
473 |
||
474 |
^ self scaledGray:(brightness * MaxValue) |
|
475 |
! |
|
476 |
||
477 |
colorId:id |
|
478 |
"return a color for a specific colorid without associating it to a |
|
479 |
specific device. Use this only for bitmaps which want 0- or 1-color, |
|
480 |
or for bitblits if you want to manipulate a specific colorplane." |
|
481 |
||
482 |
id == 0 ifTrue:[ |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
483 |
^ self noColor |
1023 | 484 |
]. |
485 |
id == 1 ifTrue:[ |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
486 |
Pseudo1 isNil ifTrue:[ |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
487 |
Pseudo1 := self basicNew setColorId:1 |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
488 |
]. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
489 |
^ Pseudo1 |
1023 | 490 |
]. |
491 |
id == -1 ifTrue:[ |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
492 |
^ self allColor |
1023 | 493 |
]. |
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
494 |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
495 |
^ self basicNew setColorId:id |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
496 |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
497 |
"Modified: 24.2.1997 / 18:16:30 / cg" |
1023 | 498 |
! |
499 |
||
500 |
cyan:c magenta:m yellow:y |
|
501 |
"return a color from cyan, magenta and yellow values. |
|
502 |
all values are given in percent (0..100)" |
|
503 |
||
504 |
^ self |
|
1348 | 505 |
redPercent:(100 - c) |
506 |
greenPercent:(100 - m) |
|
507 |
bluePercent:(100 - y) |
|
1023 | 508 |
|
509 |
" |
|
510 |
Color cyan:100 magenta:0 yellow:0 - cyan |
|
511 |
Color cyan:100 magenta:100 yellow:0 - blue |
|
512 |
Color cyan:100 magenta:0 yellow:100 - green |
|
513 |
Color cyan:100 magenta:100 yellow:100 - black |
|
514 |
" |
|
515 |
||
516 |
"Modified: 11.6.1996 / 18:29:15 / cg" |
|
517 |
! |
|
518 |
||
519 |
fromUser |
|
520 |
"let user point on a screen pixel. |
|
521 |
Return an instance for that pixels color" |
|
522 |
||
523 |
|p img| |
|
524 |
||
525 |
p := Screen current pointFromUser. |
|
526 |
img := Image fromScreen:(p corner:p+1). |
|
527 |
^ img at:0@0 |
|
528 |
||
529 |
" |
|
530 |
Color fromUser |
|
531 |
" |
|
532 |
||
533 |
"Modified: 31.8.1995 / 01:34:22 / claus" |
|
534 |
! |
|
535 |
||
536 |
hue:h light:l saturation:s |
|
537 |
"return a color from hue, light and saturation values. |
|
538 |
Hue is in degrees (0..360); light and sturation are |
|
539 |
in percent (0..100)" |
|
540 |
||
541 |
self withRGBFromHue:h light:l saturation:s do:[:r :g :b | |
|
1348 | 542 |
^ self redPercent:r greenPercent:g bluePercent:b |
1023 | 543 |
] |
544 |
||
545 |
" |
|
546 |
Color hue:0 light:50 saturation:100 - red |
|
547 |
Color hue:60 light:50 saturation:100 - yellow |
|
548 |
Color hue:120 light:50 saturation:100 - green |
|
549 |
Color hue:120 light:75 saturation:100 - bright green |
|
550 |
Color hue:120 light:25 saturation:100 - dark green |
|
551 |
Color hue:120 light:50 saturation:50 - greyish dark green |
|
552 |
Color hue:120 light:50 saturation:0 - b&w television dark green |
|
553 |
" |
|
554 |
||
555 |
"Modified: 23.4.1996 / 13:22:22 / cg" |
|
556 |
! |
|
557 |
||
1233 | 558 |
name:colorName |
1023 | 559 |
"Return a named color (either exact or dithered). |
560 |
Report an error, if aString is not a valid color name. |
|
561 |
||
562 |
We hereby only guarantee that the 8 basic colors are supported |
|
563 |
on every device (X uses the Xcolor database, so it supports more |
|
564 |
names - other devices use a builtIn name table containing only the |
|
565 |
common names) - use with special names (such as 'mediumGoldenRod' |
|
566 |
is not recommended). Better use: #name:ifIllegal: and provide a fallBack." |
|
567 |
||
1233 | 568 |
^ self |
569 |
name:colorName |
|
1269
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
570 |
ifIllegal:[InvalidColorNameSignal |
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
571 |
raiseRequestWith:colorName |
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
572 |
errorString:'invalid colorName: '] |
1023 | 573 |
|
574 |
" |
|
575 |
Color name:'brown' |
|
576 |
Color name:'foo' |
|
577 |
Color name:'snow' |
|
578 |
" |
|
579 |
||
1269
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
580 |
"Modified: 24.1.1997 / 13:39:25 / cg" |
1023 | 581 |
! |
582 |
||
1233 | 583 |
name:colorName ifIllegal:errorBlock |
1023 | 584 |
"Return a named color (either exact or dithered). |
1233 | 585 |
If aString is not a valid color name, |
586 |
return the result from evaluating errorBlock." |
|
587 |
||
588 |
|r g b| |
|
589 |
||
590 |
Display |
|
591 |
getScaledRGBFromName:colorName |
|
592 |
into:[:rr :gg :bb | |
|
593 |
r := rr. |
|
594 |
g := gg. |
|
595 |
b := bb |
|
596 |
]. |
|
597 |
||
598 |
r notNil ifTrue:[ |
|
1348 | 599 |
^ here scaledRed:r scaledGreen:g scaledBlue:b |
1233 | 600 |
]. |
601 |
^ errorBlock value |
|
1023 | 602 |
|
603 |
" |
|
604 |
Color name:'brown' ifIllegal:[Color black] |
|
605 |
Color name:'foo' ifIllegal:[Color black] |
|
606 |
" |
|
607 |
||
1233 | 608 |
"Modified: 16.1.1997 / 22:59:24 / cg" |
1023 | 609 |
! |
610 |
||
611 |
noColor |
|
612 |
"return a special color which, when used for bit-blitting will |
|
613 |
behave like a 0-color (i.e. have a device-pixel value of all-0s)" |
|
614 |
||
615 |
Pseudo0 isNil ifTrue:[ |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
616 |
Pseudo0 := self basicNew setColorId:0 |
1023 | 617 |
]. |
618 |
^ Pseudo0 |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
619 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
620 |
"Modified: 17.1.1997 / 00:06:49 / cg" |
1023 | 621 |
! |
622 |
||
623 |
red:r green:g blue:b |
|
624 |
"return a color from red, green and blue values; |
|
625 |
the arguments, r, g and b are interpreted as percent (0..100)" |
|
626 |
||
1348 | 627 |
^ here scaledRed:(r * MaxValue // 100) |
628 |
scaledGreen:(g * MaxValue // 100) |
|
629 |
scaledBlue:(b * MaxValue // 100) |
|
1023 | 630 |
! |
631 |
||
1237 | 632 |
redByte:r greenByte:g blueByte:b |
633 |
"return a color from red, green and blue values; |
|
634 |
the arguments, r, g and b are interpreted as byte values (0..255)" |
|
635 |
||
1348 | 636 |
^ here scaledRed:(r * MaxValue // 255) |
1237 | 637 |
scaledGreen:(g * MaxValue // 255) |
638 |
scaledBlue:(b * MaxValue // 255) |
|
639 |
||
640 |
" |
|
641 |
(Color redByte:255 greenByte:0 blueByte:0) inspect |
|
642 |
(Color redByte:255 greenByte:255 blueByte:255) inspect |
|
643 |
(Color redByte:0 greenByte:0 blueByte:0) inspect |
|
644 |
" |
|
645 |
||
646 |
"Modified: 16.1.1997 / 23:32:43 / cg" |
|
647 |
! |
|
648 |
||
1348 | 649 |
redPercent:r greenPercent:g bluePercent:b |
650 |
"return a color from red, green and blue values; |
|
651 |
the arguments, r, g and b are interpreted as percent (0..100)" |
|
652 |
||
653 |
^ here scaledRed:(r * MaxValue // 100) |
|
654 |
scaledGreen:(g * MaxValue // 100) |
|
655 |
scaledBlue:(b * MaxValue // 100) |
|
656 |
! |
|
657 |
||
1023 | 658 |
scaledGray:aGrayValue |
659 |
"return a gray color with a scaled gray value (0..MaxValue)" |
|
660 |
||
661 |
^ self scaledRed:aGrayValue scaledGreen:aGrayValue scaledBlue:aGrayValue |
|
662 |
||
663 |
"Modified: 11.6.1996 / 16:31:42 / cg" |
|
664 |
! |
|
665 |
||
666 |
scaledRed:r scaledGreen:g scaledBlue:b |
|
667 |
"return a color from red, green and blue values; |
|
668 |
the arguments, r, g and b are interpreted as (0..MaxValue)" |
|
669 |
||
670 |
|newColor| |
|
671 |
||
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
672 |
"/ "look if already known" |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
673 |
"/ |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
674 |
"/ aDevice deviceColors do:[:aColor | |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
675 |
"/ (r == aColor scaledRed) ifTrue:[ |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
676 |
"/ (g == aColor scaledGreen) ifTrue:[ |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
677 |
"/ (b == aColor scaledBlue) ifTrue:[ |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
678 |
"/ ^ aColor |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
679 |
"/ ] |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
680 |
"/ ] |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
681 |
"/ ] |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
682 |
"/ ]. |
1023 | 683 |
newColor := self basicNew setScaledRed:r scaledGreen:g scaledBlue:b device:nil. |
684 |
^ newColor |
|
685 |
||
686 |
" |
|
687 |
(Color red:100 green:0 blue:0) inspect |
|
688 |
(Color red:100 green:50 blue:50) inspect |
|
689 |
(Color red:50 green:0 blue:0) inspect |
|
690 |
" |
|
691 |
||
692 |
"Modified: 2.5.1996 / 13:40:51 / stefan" |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
693 |
"Modified: 24.2.1997 / 18:18:47 / cg" |
1023 | 694 |
! |
695 |
||
696 |
variableColorOn:aDevice |
|
697 |
"return a variable color (i.e. allocate a writable colorcell) on |
|
698 |
aDevice. The returned color is not shared and its rgb components |
|
699 |
are initially undefined. The components can be set to any value |
|
700 |
using Color>>red:green:blue. Care should be taken, since this call |
|
701 |
fails on static color or b&w displays (i.e. it depends on the device |
|
702 |
being a pseudocolor device using colormaps). |
|
703 |
Returns nil, if no more colorCells are available, or the display |
|
704 |
uses a fix colormap (i.e. is a directColor or staticColor pr b&w device). |
|
705 |
Because of this, you should not write your application to depend on |
|
706 |
writable colors to be available (i.e. add fallBack code to redraw |
|
707 |
things in another color)" |
|
708 |
||
709 |
|c lutIndex| |
|
710 |
||
711 |
lutIndex := aDevice colorCell. |
|
712 |
lutIndex isNil ifTrue:[^ nil]. |
|
713 |
||
714 |
c := self new. |
|
715 |
c setDevice:aDevice colorId:lutIndex. |
|
716 |
c setWritable:true. |
|
717 |
Cells isNil ifTrue:[ |
|
1348 | 718 |
Cells := Registry new. |
1023 | 719 |
]. |
720 |
Cells register:c. |
|
721 |
^ c |
|
722 |
||
723 |
" |
|
724 |
|l cell| |
|
725 |
||
726 |
l := Label new. |
|
727 |
l label:('hello' asText allBold). |
|
728 |
||
729 |
cell := Color variableColorOn:(Screen current). |
|
730 |
l foregroundColor:cell. |
|
731 |
[ |
|
1348 | 732 |
1 to:40 do:[:i| |
733 |
i odd ifTrue:[ |
|
734 |
cell red:100 green:0 blue:0 |
|
735 |
] ifFalse:[ |
|
736 |
cell red:0 green:0 blue:0 |
|
737 |
]. |
|
738 |
Display flush. |
|
739 |
(Delay forSeconds:0.4) wait |
|
740 |
]. |
|
741 |
l destroy. |
|
1023 | 742 |
] fork. |
743 |
l open |
|
744 |
" |
|
745 |
||
746 |
"Modified: 13.5.1996 / 12:41:53 / cg" |
|
747 |
! ! |
|
748 |
||
1144 | 749 |
!Color class methodsFor:'Signal constants'! |
1023 | 750 |
|
751 |
colorAllocationFailSignal |
|
752 |
"return the signal raised when a color allocation failed." |
|
753 |
||
754 |
^ ColorAllocationFailSignal |
|
755 |
||
756 |
"Created: 12.6.1996 / 17:44:49 / cg" |
|
1269
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
757 |
! |
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
758 |
|
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
759 |
invalidColorNameSignal |
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
760 |
"return the signal raised when an invalid color name is encountered" |
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
761 |
|
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
762 |
^ InvalidColorNameSignal |
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
763 |
|
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
764 |
"Created: 24.1.1997 / 13:36:25 / cg" |
1023 | 765 |
! ! |
766 |
||
1144 | 767 |
!Color class methodsFor:'accessing'! |
1023 | 768 |
|
769 |
allocatedColorsOn:aDevice |
|
770 |
"return a collection of colors available on aDevice" |
|
771 |
||
772 |
|colors| |
|
773 |
||
774 |
colors := OrderedCollection new. |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
775 |
aDevice deviceColors do:[:clr | |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
776 |
clr colorId notNil ifTrue:[ |
1348 | 777 |
colors add:clr |
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
778 |
] ifFalse:[ |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
779 |
'color - oops' printCR. |
1348 | 780 |
] |
1023 | 781 |
]. |
782 |
^ colors asArray |
|
783 |
||
784 |
" |
|
785 |
Color allocatedColorsOn:Display |
|
786 |
" |
|
787 |
||
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
788 |
"Modified: 24.2.1997 / 18:16:14 / cg" |
1023 | 789 |
! ! |
790 |
||
1224
2a2270ec4236
added #releaseResourcesOnDevice:, to allow cleanup when
Claus Gittinger <cg@exept.de>
parents:
1205
diff
changeset
|
791 |
!Color class methodsFor:'cleanup'! |
2a2270ec4236
added #releaseResourcesOnDevice:, to allow cleanup when
Claus Gittinger <cg@exept.de>
parents:
1205
diff
changeset
|
792 |
|
2a2270ec4236
added #releaseResourcesOnDevice:, to allow cleanup when
Claus Gittinger <cg@exept.de>
parents:
1205
diff
changeset
|
793 |
releaseResourcesOnDevice:aDevice |
2a2270ec4236
added #releaseResourcesOnDevice:, to allow cleanup when
Claus Gittinger <cg@exept.de>
parents:
1205
diff
changeset
|
794 |
"this is sent when a display connection is closed, |
2a2270ec4236
added #releaseResourcesOnDevice:, to allow cleanup when
Claus Gittinger <cg@exept.de>
parents:
1205
diff
changeset
|
795 |
to release all cached Colors from that device" |
2a2270ec4236
added #releaseResourcesOnDevice:, to allow cleanup when
Claus Gittinger <cg@exept.de>
parents:
1205
diff
changeset
|
796 |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
797 |
aDevice releaseDeviceColors |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
798 |
"/ Lobby unregisterAllForWhich:[:aColor | aColor graphicsDevice == aDevice] |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
799 |
|
1224
2a2270ec4236
added #releaseResourcesOnDevice:, to allow cleanup when
Claus Gittinger <cg@exept.de>
parents:
1205
diff
changeset
|
800 |
"Created: 16.1.1997 / 16:44:20 / cg" |
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
801 |
"Modified: 24.2.1997 / 18:18:22 / cg" |
1224
2a2270ec4236
added #releaseResourcesOnDevice:, to allow cleanup when
Claus Gittinger <cg@exept.de>
parents:
1205
diff
changeset
|
802 |
! ! |
2a2270ec4236
added #releaseResourcesOnDevice:, to allow cleanup when
Claus Gittinger <cg@exept.de>
parents:
1205
diff
changeset
|
803 |
|
1144 | 804 |
!Color class methodsFor:'color space conversions'! |
1023 | 805 |
|
806 |
withHLSFromRed:r green:g blue:b do:aBlock |
|
807 |
"compute hls form rgb, evaluate aBlock with h,l and s as arguments" |
|
808 |
||
809 |
|max min r1 g1 b1 delta h l s| |
|
810 |
||
811 |
"compute hls; h in 0..360; l 0..100; s 0..100" |
|
812 |
||
813 |
r1 := r / 100. "scale to 0..1" |
|
814 |
g1 := g / 100. |
|
815 |
b1 := b / 100. |
|
816 |
||
817 |
max := (r1 max:g1) max:b1. |
|
818 |
min := (r1 min:g1) min:b1. |
|
819 |
l := (max + min) / 2. |
|
820 |
||
821 |
max = min ifTrue:[ |
|
1348 | 822 |
"achromatic, r=g=b" |
823 |
||
824 |
s := 0. |
|
825 |
h := nil |
|
1023 | 826 |
] ifFalse:[ |
1348 | 827 |
l < 0.5 ifTrue:[ |
828 |
s := (max - min) / (max + min) |
|
829 |
] ifFalse:[ |
|
830 |
s := (max - min) / (2 - max - min) |
|
831 |
]. |
|
832 |
||
833 |
"calc hue" |
|
834 |
||
835 |
delta := max - min. |
|
836 |
r1 = max ifTrue:[ |
|
837 |
h := (g1 - b1) / delta |
|
838 |
] ifFalse:[ |
|
839 |
g1 = max ifTrue:[ |
|
840 |
h := 2 + ((b1 - r1) / delta) |
|
841 |
] ifFalse:[ |
|
842 |
h := 4 + ((r1 - g1) / delta) |
|
843 |
] |
|
844 |
]. |
|
845 |
h := h * 60. |
|
846 |
h < 0 ifTrue:[ |
|
847 |
h := h + 360 |
|
848 |
]. |
|
1023 | 849 |
]. |
850 |
aBlock value:h value:(l * 100) value:(s * 100) |
|
851 |
! |
|
852 |
||
853 |
withHLSFromScaledRed:r scaledGreen:g scaledBlue:b do:aBlock |
|
854 |
"compute hls form rgb, evaluate aBlock with h,l and s as arguments" |
|
855 |
||
856 |
^ self withHLSFromRed:(r * 100.0 / MaxValue) |
|
1348 | 857 |
green:(g * 100.0 / MaxValue) |
858 |
blue:(b * 100.0 / MaxValue) |
|
859 |
do:aBlock |
|
1023 | 860 |
|
861 |
"Created: 11.6.1996 / 17:23:47 / cg" |
|
862 |
! |
|
863 |
||
864 |
withRGBFromHue:h light:l saturation:s do:aBlock |
|
865 |
"compute rgb form hls, evaluate aBlock with r,g and b as arguments" |
|
866 |
||
867 |
|valueFunc s1 l1 r g b m1 m2| |
|
868 |
||
869 |
valueFunc := [:n1 :n2 :hIn | |
|
1348 | 870 |
|hue| |
871 |
||
872 |
hue := hIn. |
|
873 |
hue > 360 ifTrue:[ |
|
874 |
hue := hue - 360 |
|
875 |
] ifFalse:[ |
|
876 |
hue < 0 ifTrue:[ |
|
877 |
hue := hue + 360 |
|
878 |
]. |
|
879 |
]. |
|
880 |
hue < 60 ifTrue:[ |
|
881 |
n1 + ((n2 - n1) * hue / 60) |
|
882 |
] ifFalse:[ |
|
883 |
hue < 180 ifTrue:[ |
|
884 |
n2 |
|
885 |
] ifFalse:[ |
|
886 |
hue < 240 ifTrue:[ |
|
887 |
n1 + ((n2 - n1) * (240 - hue) / 60) |
|
888 |
] ifFalse:[ |
|
889 |
n1 |
|
890 |
] |
|
891 |
] |
|
892 |
] |
|
1023 | 893 |
]. |
894 |
||
895 |
"compute hls; h in 0..360; l 0..100; s 0..100" |
|
896 |
||
897 |
s1 := s / 100.0. "scale to 0..1" |
|
898 |
l1 := l / 100.0. |
|
899 |
||
900 |
l1 <= 0.5 ifTrue:[ |
|
1348 | 901 |
m2 := l1 * (1 + s1) |
1023 | 902 |
] ifFalse:[ |
1348 | 903 |
m2 := l1 + s1 - (l1 * s1) |
1023 | 904 |
]. |
905 |
||
906 |
m1 := 2 * l1 - m2. |
|
907 |
||
908 |
s1 = 0 ifTrue:[ |
|
1348 | 909 |
"achromatic, ignore hue" |
910 |
r := g := b := l1 |
|
1023 | 911 |
] ifFalse:[ |
1348 | 912 |
r := valueFunc value:m1 value:m2 value:h + 120. |
913 |
g := valueFunc value:m1 value:m2 value:h. |
|
914 |
b := valueFunc value:m1 value:m2 value:h - 120. |
|
1023 | 915 |
]. |
916 |
aBlock value:r*100 value:g*100 value:b*100 |
|
917 |
! ! |
|
918 |
||
1144 | 919 |
!Color class methodsFor:'constant colors'! |
1023 | 920 |
|
921 |
black |
|
922 |
"return the black color" |
|
923 |
||
924 |
Black isNil ifTrue:[ |
|
1348 | 925 |
Black := (self red:0 green:0 blue:0) exactOn:Display |
1023 | 926 |
]. |
927 |
^ Black |
|
928 |
||
929 |
" |
|
930 |
Color black inspect |
|
931 |
" |
|
932 |
||
933 |
"Modified: 11.6.1996 / 15:55:31 / cg" |
|
934 |
! |
|
935 |
||
936 |
blue |
|
937 |
"return the blue color" |
|
938 |
||
939 |
Blue isNil ifTrue:[ |
|
1348 | 940 |
Blue := self redPercent:0 greenPercent:0 bluePercent:100 |
1023 | 941 |
]. |
942 |
^ Blue |
|
943 |
||
944 |
" |
|
945 |
Color blue inspect |
|
946 |
" |
|
947 |
||
948 |
"Modified: 23.4.1996 / 13:15:51 / cg" |
|
949 |
! |
|
950 |
||
951 |
cyan |
|
952 |
"return the cyan color - ST-80 compatibility" |
|
953 |
||
1348 | 954 |
^ self redPercent:0 greenPercent:100 bluePercent:100 |
1023 | 955 |
|
956 |
" |
|
957 |
Color cyan inspect |
|
958 |
" |
|
959 |
||
960 |
"Modified: 23.4.1996 / 13:16:07 / cg" |
|
961 |
! |
|
962 |
||
963 |
darkGray |
|
964 |
"return the dark grey color (English version ;-)" |
|
965 |
||
966 |
DarkGrey isNil ifTrue:[ |
|
1348 | 967 |
DarkGrey := self gray:33 |
1023 | 968 |
]. |
969 |
^ DarkGrey |
|
970 |
||
971 |
" |
|
972 |
Color darkGray inspect |
|
973 |
" |
|
974 |
||
975 |
"Modified: 28.5.1996 / 20:53:57 / cg" |
|
976 |
! |
|
977 |
||
978 |
darkGrey |
|
979 |
"return the darkGrey color (US version ;-)" |
|
980 |
||
981 |
^ self darkGray |
|
982 |
||
983 |
" |
|
984 |
Color darkGrey inspect |
|
985 |
" |
|
986 |
||
987 |
"Modified: 28.5.1996 / 20:47:14 / cg" |
|
988 |
! |
|
989 |
||
990 |
gray |
|
991 |
"return a medium grey color (US version ;-)" |
|
992 |
||
993 |
Grey isNil ifTrue:[ |
|
1348 | 994 |
Grey := self gray:50 |
1023 | 995 |
]. |
996 |
^ Grey |
|
997 |
||
998 |
" |
|
999 |
Color gray inspect |
|
1000 |
" |
|
1001 |
||
1002 |
"Modified: 28.5.1996 / 20:48:36 / cg" |
|
1003 |
! |
|
1004 |
||
1005 |
gray:gray |
|
1006 |
"return a gray color (US version). |
|
1007 |
The argument, gray is interpreted as percent (0..100)." |
|
1008 |
||
1348 | 1009 |
^ self redPercent:gray greenPercent:gray bluePercent:gray |
1010 |
||
1011 |
" |
|
1012 |
Color gray:25 |
|
1013 |
" |
|
1014 |
||
1015 |
"Modified: 28.5.1996 / 20:49:51 / cg" |
|
1016 |
! |
|
1017 |
||
1018 |
grayPercent:gray |
|
1019 |
"return a gray color (US version). |
|
1020 |
The argument, gray is interpreted as percent (0..100)." |
|
1021 |
||
1022 |
^ self redPercent:gray greenPercent:gray bluePercent:gray |
|
1023 | 1023 |
|
1024 |
" |
|
1025 |
Color gray:25 |
|
1026 |
" |
|
1027 |
||
1028 |
"Modified: 28.5.1996 / 20:49:51 / cg" |
|
1029 |
! |
|
1030 |
||
1031 |
green |
|
1032 |
"return green" |
|
1033 |
||
1034 |
Green isNil ifTrue:[ |
|
1348 | 1035 |
Green := self redPercent:0 greenPercent:100 bluePercent:0 |
1023 | 1036 |
]. |
1037 |
^ Green |
|
1038 |
||
1039 |
" |
|
1040 |
Color green inspect |
|
1041 |
" |
|
1042 |
||
1043 |
"Modified: 23.4.1996 / 13:23:08 / cg" |
|
1044 |
! |
|
1045 |
||
1046 |
grey |
|
1047 |
"return the grey color (English version ;-)" |
|
1048 |
||
1049 |
^ self gray |
|
1050 |
||
1051 |
" |
|
1052 |
Color grey inspect |
|
1053 |
" |
|
1054 |
||
1055 |
"Modified: 28.5.1996 / 20:48:26 / cg" |
|
1056 |
! |
|
1057 |
||
1058 |
grey:grey |
|
1059 |
"return a grey color (English version). |
|
1060 |
The argument, grey is interpreted as percent (0..100)." |
|
1061 |
||
1062 |
^ self gray:grey |
|
1063 |
||
1064 |
" |
|
1065 |
Color grey:25 |
|
1066 |
Color grey:12.5 |
|
1067 |
" |
|
1068 |
||
1069 |
"Modified: 28.5.1996 / 20:50:34 / cg" |
|
1070 |
! |
|
1071 |
||
1072 |
lightGray |
|
1073 |
"return the lightGrey color (US version ;-)" |
|
1074 |
||
1075 |
LightGrey isNil ifTrue:[ |
|
1348 | 1076 |
LightGrey := self gray:67 |
1023 | 1077 |
]. |
1078 |
^ LightGrey |
|
1079 |
||
1080 |
" |
|
1081 |
Color lightGray inspect |
|
1082 |
" |
|
1083 |
||
1084 |
"Modified: 28.5.1996 / 20:54:00 / cg" |
|
1085 |
! |
|
1086 |
||
1087 |
lightGrey |
|
1088 |
"return the lightGrey color (English version ;-)" |
|
1089 |
||
1090 |
^ self lightGray |
|
1091 |
||
1092 |
" |
|
1093 |
Color lightGrey inspect |
|
1094 |
" |
|
1095 |
||
1096 |
"Modified: 28.5.1996 / 20:51:11 / cg" |
|
1097 |
! |
|
1098 |
||
1099 |
magenta |
|
1100 |
"return the magenta color - ST-80 compatibility" |
|
1101 |
||
1348 | 1102 |
^ self redPercent:100 greenPercent:0 bluePercent:100 |
1023 | 1103 |
|
1104 |
" |
|
1105 |
Color magenta inspect |
|
1106 |
" |
|
1107 |
||
1108 |
"Modified: 23.4.1996 / 13:23:41 / cg" |
|
1109 |
! |
|
1110 |
||
1111 |
mediumGray |
|
1112 |
"return medium-grey color (US version ;-)" |
|
1113 |
||
1114 |
^ self gray |
|
1115 |
||
1116 |
" |
|
1117 |
Color mediumGray inspect |
|
1118 |
" |
|
1119 |
||
1120 |
"Created: 23.4.1996 / 13:24:17 / cg" |
|
1121 |
"Modified: 28.5.1996 / 20:51:21 / cg" |
|
1122 |
! |
|
1123 |
||
1124 |
mediumGrey |
|
1125 |
"return medium-grey color (English version ;-)" |
|
1126 |
||
1127 |
^ self gray |
|
1128 |
||
1129 |
" |
|
1130 |
Color mediumGrey inspect |
|
1131 |
" |
|
1132 |
||
1133 |
"Modified: 28.5.1996 / 20:51:24 / cg" |
|
1134 |
! |
|
1135 |
||
1136 |
orange |
|
1137 |
"return the orange color - ST-80 compatibility" |
|
1138 |
||
1348 | 1139 |
^ self redPercent:75 greenPercent:50 bluePercent:0 |
1023 | 1140 |
|
1141 |
"Modified: 23.4.1996 / 13:29:32 / cg" |
|
1142 |
! |
|
1143 |
||
1144 |
pink |
|
1145 |
"return the pink color - ST-80 compatibility" |
|
1146 |
||
1348 | 1147 |
^ self redPercent:100 greenPercent:0 bluePercent:100 |
1023 | 1148 |
|
1149 |
"Modified: 23.4.1996 / 13:29:38 / cg" |
|
1150 |
! |
|
1151 |
||
1152 |
red |
|
1153 |
"return the red color" |
|
1154 |
||
1155 |
Red isNil ifTrue:[ |
|
1348 | 1156 |
Red := self redPercent:100 greenPercent:0 bluePercent:0. |
1023 | 1157 |
]. |
1158 |
^ Red |
|
1159 |
||
1160 |
"Modified: 23.4.1996 / 13:29:44 / cg" |
|
1161 |
! |
|
1162 |
||
1163 |
veryDarkGray |
|
1164 |
"return a very dark-grey color (US version ;-)" |
|
1165 |
||
1166 |
^ self gray:13 |
|
1167 |
||
1168 |
"Created: 23.4.1996 / 13:33:14 / cg" |
|
1169 |
"Modified: 28.5.1996 / 20:51:41 / cg" |
|
1170 |
! |
|
1171 |
||
1172 |
veryDarkGrey |
|
1173 |
"return a very dark-grey color (English version ;-)" |
|
1174 |
||
1175 |
^ self veryDarkGray |
|
1176 |
||
1177 |
"Modified: 28.5.1996 / 20:52:49 / cg" |
|
1178 |
! |
|
1179 |
||
1180 |
veryLightGray |
|
1181 |
"return a very light-grey color (US version ;-)" |
|
1182 |
||
1183 |
^ self gray:87 |
|
1184 |
||
1185 |
"Created: 23.4.1996 / 13:33:46 / cg" |
|
1186 |
"Modified: 28.5.1996 / 20:51:59 / cg" |
|
1187 |
! |
|
1188 |
||
1189 |
veryLightGrey |
|
1190 |
"return a very light-grey color (English version ;-)" |
|
1191 |
||
1192 |
^ self veryLightGray |
|
1193 |
||
1194 |
"Modified: 28.5.1996 / 20:52:03 / cg" |
|
1195 |
! |
|
1196 |
||
1197 |
white |
|
1198 |
"return the white-color" |
|
1199 |
||
1200 |
White isNil ifTrue:[ |
|
1348 | 1201 |
White := (self redPercent:100 greenPercent:100 bluePercent:100) exactOn:Display |
1023 | 1202 |
]. |
1203 |
^ White |
|
1204 |
! |
|
1205 |
||
1206 |
yellow |
|
1207 |
"return the yellow color - ST-80 compatibility" |
|
1208 |
||
1348 | 1209 |
^ self redPercent:100 greenPercent:100 bluePercent:0 |
1023 | 1210 |
|
1211 |
"Modified: 23.4.1996 / 13:33:56 / cg" |
|
1212 |
! ! |
|
1213 |
||
1233 | 1214 |
!Color class methodsFor:'obsolete'! |
1215 |
||
1216 |
nameOrDither:colorName |
|
1217 |
"return a named color - if the exact color is not available, |
|
1218 |
return a dithered color. Report an error, if the colorname is |
|
1219 |
illegal." |
|
1220 |
||
1221 |
self obsoleteMethodWarning:'use #name:'. |
|
1222 |
^ self name:colorName |
|
1223 |
||
1224 |
"Modified: 16.1.1997 / 23:01:03 / cg" |
|
1225 |
! |
|
1226 |
||
1227 |
nameOrDither:colorName ifIllegal:errorBlock |
|
1228 |
"return a named color - if the exact color is not available, |
|
1229 |
return a dithered color. If the colorname is illegal, return |
|
1230 |
the value of evaluating errorBlock." |
|
1231 |
||
1232 |
self obsoleteMethodWarning:'use #name:ifIllegal:'. |
|
1233 |
^ self name:colorName ifIllegal:errorBlock |
|
1234 |
||
1235 |
"Modified: 16.1.1997 / 23:01:32 / cg" |
|
1236 |
! |
|
1237 |
||
1238 |
nameOrNearest:colorName |
|
1239 |
"return a named color - or its nearest match" |
|
1240 |
||
1241 |
self obsoleteMethodWarning:'use #name:'. |
|
1242 |
^ self name:colorName |
|
1243 |
||
1244 |
"Modified: 16.1.1997 / 23:02:18 / cg" |
|
1245 |
! ! |
|
1246 |
||
1144 | 1247 |
!Color class methodsFor:'private'! |
1023 | 1248 |
|
1249 |
colorNearRed:r green:g blue:b on:aDevice |
|
1250 |
"return a device color on aDevice with rgb values |
|
1251 |
almost matching. If there is one, nil otherwise. |
|
1252 |
This is tried as a last chance before dithering. |
|
1253 |
The algorithm needs rework, the color components |
|
1254 |
should be weighted according some theory :-)" |
|
1255 |
||
1256 |
|bestColor minDelta diff rr rg rb dRed| |
|
1257 |
||
1258 |
"/ rr := (r * 3.0) rounded / 3.0. |
|
1259 |
"/ rg := (g * 3.0) rounded / 3.0. |
|
1260 |
"/ rb := (b * 3.0) rounded / 3.0. |
|
1261 |
||
1262 |
rr := r rounded. "round to 1%" |
|
1263 |
rg := (g * 2.0) rounded / 2.0. "round to 0.5%" |
|
1264 |
rb := (b / 2) rounded * 2. "round to 2%" |
|
1265 |
||
1266 |
minDelta := 100*100*100. |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1267 |
aDevice deviceColors do:[:aColor | |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1268 |
dRed := rr - aColor red. |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1269 |
dRed < 10 ifTrue:[ |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1270 |
diff := dRed asInteger squared |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1271 |
+ (rg - aColor green) asInteger squared |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1272 |
+ (rb - aColor blue) asInteger squared. |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1273 |
|
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1274 |
diff < minDelta ifTrue:[ |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1275 |
diff = 0 ifTrue:[ |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1276 |
"got it" |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1277 |
^ aColor |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1278 |
]. |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1279 |
bestColor := aColor. |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1280 |
minDelta := diff |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1281 |
] |
1348 | 1282 |
] |
1023 | 1283 |
]. |
1284 |
||
1285 |
"allow an error of 10% per component" |
|
1286 |
minDelta < (100+100+100) ifTrue:[ ^ bestColor ]. |
|
1287 |
^ nil |
|
1288 |
||
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1289 |
"Modified: 24.2.1997 / 18:17:24 / cg" |
1023 | 1290 |
! |
1291 |
||
1292 |
ditherBits |
|
1293 |
"return a dither pattern for x/64; x in 1..63" |
|
1294 |
||
1295 |
^ #( |
|
1296 |
||
1348 | 1297 |
"/ 1in64 |
1298 |
||
1299 |
#[2r10000000 |
|
1300 |
2r00000000 |
|
1301 |
2r00000000 |
|
1302 |
2r00000000 |
|
1303 |
2r00000000 |
|
1304 |
2r00000000 |
|
1305 |
2r00000000 |
|
1306 |
2r00000000] |
|
1307 |
||
1308 |
"/ 2in64 |
|
1309 |
||
1310 |
#[2r10000000 |
|
1311 |
2r00000000 |
|
1312 |
2r00000000 |
|
1313 |
2r00000000 |
|
1314 |
2r00001000 |
|
1315 |
2r00000000 |
|
1316 |
2r00000000 |
|
1317 |
2r00000000] |
|
1318 |
||
1319 |
"/ 3in64 |
|
1320 |
||
1321 |
#[2r10000000 |
|
1322 |
2r00000000 |
|
1323 |
2r00000000 |
|
1324 |
2r00000000 |
|
1325 |
2r10001000 |
|
1326 |
2r00000000 |
|
1327 |
2r00000000 |
|
1328 |
2r00000000] |
|
1329 |
||
1330 |
"/ 4in64 |
|
1331 |
||
1332 |
#[2r10001000 |
|
1333 |
2r00000000 |
|
1334 |
2r00000000 |
|
1335 |
2r00000000 |
|
1336 |
2r10001000 |
|
1337 |
2r00000000 |
|
1338 |
2r00000000 |
|
1339 |
2r00000000] |
|
1340 |
||
1341 |
"/ 5in64 |
|
1342 |
||
1343 |
#[2r10001000 |
|
1344 |
2r00000000 |
|
1345 |
2r00000000 |
|
1346 |
2r00000000 |
|
1347 |
2r10001000 |
|
1348 |
2r00000000 |
|
1349 |
2r00000010 |
|
1350 |
2r00000000] |
|
1351 |
||
1352 |
"/ 6in64 |
|
1353 |
||
1354 |
#[2r10001000 |
|
1355 |
2r00000000 |
|
1356 |
2r00100000 |
|
1357 |
2r00000000 |
|
1358 |
2r10001000 |
|
1359 |
2r00000000 |
|
1360 |
2r00000010 |
|
1361 |
2r00000000] |
|
1362 |
||
1363 |
"/ 7in64 |
|
1364 |
||
1365 |
#[2r10001000 |
|
1366 |
2r00000000 |
|
1367 |
2r00100010 |
|
1368 |
2r00000000 |
|
1369 |
2r10001000 |
|
1370 |
2r00000000 |
|
1371 |
2r00000010 |
|
1372 |
2r00000000] |
|
1373 |
||
1374 |
"/ 8in64 |
|
1375 |
||
1376 |
#[2r10001000 |
|
1377 |
2r00000000 |
|
1378 |
2r00100010 |
|
1379 |
2r00000000 |
|
1380 |
2r10001000 |
|
1381 |
2r00000000 |
|
1382 |
2r00100010 |
|
1383 |
2r00000000] |
|
1384 |
||
1385 |
"/ 9in64 |
|
1386 |
||
1387 |
#[2r10001000 |
|
1388 |
2r00000000 |
|
1389 |
2r00100010 |
|
1390 |
2r00000000 |
|
1391 |
2r10001000 |
|
1392 |
2r00000000 |
|
1393 |
2r10100010 |
|
1394 |
2r00000000] |
|
1395 |
||
1396 |
"/ 10in64 |
|
1397 |
||
1398 |
#[2r10001000 |
|
1399 |
2r00000000 |
|
1400 |
2r00101010 |
|
1401 |
2r00000000 |
|
1402 |
2r10001000 |
|
1403 |
2r00000000 |
|
1404 |
2r10100010 |
|
1405 |
2r00000000] |
|
1406 |
||
1407 |
"/ 11in64 |
|
1408 |
||
1409 |
#[2r10001000 |
|
1410 |
2r00000000 |
|
1411 |
2r00101010 |
|
1412 |
2r00000000 |
|
1413 |
2r10001000 |
|
1414 |
2r00000000 |
|
1415 |
2r10101010 |
|
1416 |
2r00000000] |
|
1417 |
||
1418 |
"/ 12in64 |
|
1419 |
||
1420 |
#[2r10001000 |
|
1421 |
2r00000000 |
|
1422 |
2r10101010 |
|
1423 |
2r00000000 |
|
1424 |
2r10001000 |
|
1425 |
2r00000000 |
|
1426 |
2r10101010 |
|
1427 |
2r00000000] |
|
1428 |
||
1429 |
"/ 13in64 |
|
1430 |
||
1431 |
#[2r10001000 |
|
1432 |
2r00000000 |
|
1433 |
2r10101010 |
|
1434 |
2r00000000 |
|
1435 |
2r10101000 |
|
1436 |
2r00000000 |
|
1437 |
2r10101010 |
|
1438 |
2r00000000] |
|
1439 |
||
1440 |
"/ 14in64 |
|
1441 |
||
1442 |
#[2r10001010 |
|
1443 |
2r00000000 |
|
1444 |
2r10101010 |
|
1445 |
2r00000000 |
|
1446 |
2r10101000 |
|
1447 |
2r00000000 |
|
1448 |
2r10101010 |
|
1449 |
2r00000000] |
|
1450 |
||
1451 |
"/ 15in64 |
|
1452 |
||
1453 |
#[2r10001010 |
|
1454 |
2r00000000 |
|
1455 |
2r10101010 |
|
1456 |
2r00000000 |
|
1457 |
2r10101010 |
|
1458 |
2r00000000 |
|
1459 |
2r10101010 |
|
1460 |
2r00000000] |
|
1461 |
||
1462 |
"/ 16in64 |
|
1463 |
||
1464 |
#[2r10101010 |
|
1465 |
2r00000000 |
|
1466 |
2r10101010 |
|
1467 |
2r00000000 |
|
1468 |
2r10101010 |
|
1469 |
2r00000000 |
|
1470 |
2r10101010 |
|
1471 |
2r00000000] |
|
1472 |
||
1473 |
"/ 17in64 |
|
1474 |
||
1475 |
#[2r10101010 |
|
1476 |
2r01000000 |
|
1477 |
2r10101010 |
|
1478 |
2r00000000 |
|
1479 |
2r10101010 |
|
1480 |
2r00000000 |
|
1481 |
2r10101010 |
|
1482 |
2r00000000] |
|
1483 |
||
1484 |
"/ 18in64 |
|
1485 |
||
1486 |
#[2r10101010 |
|
1487 |
2r01000000 |
|
1488 |
2r10101010 |
|
1489 |
2r00000000 |
|
1490 |
2r10101010 |
|
1491 |
2r00000100 |
|
1492 |
2r10101010 |
|
1493 |
2r00000000] |
|
1494 |
||
1495 |
"/ 19in64 |
|
1496 |
||
1497 |
#[2r10101010 |
|
1498 |
2r01000000 |
|
1499 |
2r10101010 |
|
1500 |
2r00000000 |
|
1501 |
2r10101010 |
|
1502 |
2r01000100 |
|
1503 |
2r10101010 |
|
1504 |
2r00000000] |
|
1505 |
||
1506 |
"/ 20in64 |
|
1507 |
||
1508 |
#[2r10101010 |
|
1509 |
2r01000100 |
|
1510 |
2r10101010 |
|
1511 |
2r00000000 |
|
1512 |
2r10101010 |
|
1513 |
2r01000100 |
|
1514 |
2r10101010 |
|
1515 |
2r00000000] |
|
1516 |
||
1517 |
"/ 21in64 |
|
1518 |
||
1519 |
#[2r10101010 |
|
1520 |
2r01000100 |
|
1521 |
2r10101010 |
|
1522 |
2r00000000 |
|
1523 |
2r10101010 |
|
1524 |
2r01000100 |
|
1525 |
2r10101010 |
|
1526 |
2r00000001] |
|
1527 |
||
1528 |
"/ 22in64 |
|
1529 |
||
1530 |
#[2r10101010 |
|
1531 |
2r01000100 |
|
1532 |
2r10101010 |
|
1533 |
2r00010000 |
|
1534 |
2r10101010 |
|
1535 |
2r01000100 |
|
1536 |
2r10101010 |
|
1537 |
2r00000001] |
|
1538 |
||
1539 |
"/ 23in64 |
|
1540 |
||
1541 |
#[2r10101010 |
|
1542 |
2r01000100 |
|
1543 |
2r10101010 |
|
1544 |
2r00010001 |
|
1545 |
2r10101010 |
|
1546 |
2r01000100 |
|
1547 |
2r10101010 |
|
1548 |
2r00000001] |
|
1549 |
||
1550 |
"/ 24in64 |
|
1551 |
||
1552 |
#[2r10101010 |
|
1553 |
2r01000100 |
|
1554 |
2r10101010 |
|
1555 |
2r00010001 |
|
1556 |
2r10101010 |
|
1557 |
2r01000100 |
|
1558 |
2r10101010 |
|
1559 |
2r00010001] |
|
1560 |
||
1561 |
"/ 25in64 |
|
1562 |
||
1563 |
#[2r10101010 |
|
1564 |
2r01000100 |
|
1565 |
2r10101010 |
|
1566 |
2r00010001 |
|
1567 |
2r10101010 |
|
1568 |
2r01000100 |
|
1569 |
2r10101010 |
|
1570 |
2r01010001] |
|
1571 |
||
1572 |
"/ 26in64 |
|
1573 |
||
1574 |
#[2r10101010 |
|
1575 |
2r01000100 |
|
1576 |
2r10101010 |
|
1577 |
2r00010101 |
|
1578 |
2r10101010 |
|
1579 |
2r01000100 |
|
1580 |
2r10101010 |
|
1581 |
2r01010001] |
|
1582 |
||
1583 |
"/ 27in64 |
|
1584 |
||
1585 |
#[2r10101010 |
|
1586 |
2r01000100 |
|
1587 |
2r10101010 |
|
1588 |
2r00010101 |
|
1589 |
2r10101010 |
|
1590 |
2r01000100 |
|
1591 |
2r10101010 |
|
1592 |
2r01010101] |
|
1593 |
||
1594 |
"/ 28in64 |
|
1595 |
||
1596 |
#[2r10101010 |
|
1597 |
2r01000100 |
|
1598 |
2r10101010 |
|
1599 |
2r01010101 |
|
1600 |
2r10101010 |
|
1601 |
2r01000100 |
|
1602 |
2r10101010 |
|
1603 |
2r01010101] |
|
1604 |
||
1605 |
"/ 29in64 |
|
1606 |
||
1607 |
#[2r10101010 |
|
1608 |
2r01000100 |
|
1609 |
2r10101010 |
|
1610 |
2r01010101 |
|
1611 |
2r10101010 |
|
1612 |
2r01010100 |
|
1613 |
2r10101010 |
|
1614 |
2r01010101] |
|
1615 |
||
1616 |
"/ 30in64 |
|
1617 |
||
1618 |
#[2r10101010 |
|
1619 |
2r01000101 |
|
1620 |
2r10101010 |
|
1621 |
2r01010101 |
|
1622 |
2r10101010 |
|
1623 |
2r01010100 |
|
1624 |
2r10101010 |
|
1625 |
2r01010101] |
|
1626 |
||
1627 |
"/ 31in64 |
|
1628 |
||
1629 |
#[2r10101010 |
|
1630 |
2r01000101 |
|
1631 |
2r10101010 |
|
1632 |
2r01010101 |
|
1633 |
2r10101010 |
|
1634 |
2r01010101 |
|
1635 |
2r10101010 |
|
1636 |
2r01010101] |
|
1637 |
||
1638 |
"/ 32in64 |
|
1639 |
||
1640 |
#[2r10101010 |
|
1641 |
2r01010101 |
|
1642 |
2r10101010 |
|
1643 |
2r01010101 |
|
1644 |
2r10101010 |
|
1645 |
2r01010101 |
|
1646 |
2r10101010 |
|
1647 |
2r01010101] |
|
1648 |
||
1649 |
"/ 33in64 |
|
1650 |
||
1651 |
#[2r11101010 |
|
1652 |
2r01010101 |
|
1653 |
2r10101010 |
|
1654 |
2r01010101 |
|
1655 |
2r10101010 |
|
1656 |
2r01010101 |
|
1657 |
2r10101010 |
|
1658 |
2r01010101] |
|
1659 |
||
1660 |
"/ 34in64 |
|
1661 |
||
1662 |
#[2r11101010 |
|
1663 |
2r01010101 |
|
1664 |
2r10101010 |
|
1665 |
2r01010101 |
|
1666 |
2r10101110 |
|
1667 |
2r01010101 |
|
1668 |
2r10101010 |
|
1669 |
2r01010101] |
|
1670 |
||
1671 |
"/ 35in64 |
|
1672 |
||
1673 |
#[2r11101010 |
|
1674 |
2r01010101 |
|
1675 |
2r10101010 |
|
1676 |
2r01010101 |
|
1677 |
2r11101110 |
|
1678 |
2r01010101 |
|
1679 |
2r10101010 |
|
1680 |
2r01010101] |
|
1681 |
||
1682 |
"/ 36in64 |
|
1683 |
||
1684 |
#[2r11101110 |
|
1685 |
2r01010101 |
|
1686 |
2r10101010 |
|
1687 |
2r01010101 |
|
1688 |
2r11101110 |
|
1689 |
2r01010101 |
|
1690 |
2r10101010 |
|
1691 |
2r01010101] |
|
1692 |
||
1693 |
"/ 37in64 |
|
1694 |
||
1695 |
#[2r11101110 |
|
1696 |
2r01010101 |
|
1697 |
2r10101010 |
|
1698 |
2r01010101 |
|
1699 |
2r11101110 |
|
1700 |
2r01010101 |
|
1701 |
2r10101011 |
|
1702 |
2r01010101] |
|
1703 |
||
1704 |
"/ 38in64 |
|
1705 |
||
1706 |
#[2r11101110 |
|
1707 |
2r01010101 |
|
1708 |
2r10111010 |
|
1709 |
2r01010101 |
|
1710 |
2r11101110 |
|
1711 |
2r01010101 |
|
1712 |
2r10101011 |
|
1713 |
2r01010101] |
|
1714 |
||
1715 |
"/ 39in64 |
|
1716 |
||
1717 |
#[2r11101110 |
|
1718 |
2r01010101 |
|
1719 |
2r10111011 |
|
1720 |
2r01010101 |
|
1721 |
2r11101110 |
|
1722 |
2r01010101 |
|
1723 |
2r10101011 |
|
1724 |
2r01010101] |
|
1725 |
||
1726 |
"/ 40in64 |
|
1727 |
||
1728 |
#[2r11101110 |
|
1729 |
2r01010101 |
|
1730 |
2r10111011 |
|
1731 |
2r01010101 |
|
1732 |
2r11101110 |
|
1733 |
2r01010101 |
|
1734 |
2r10111011 |
|
1735 |
2r01010101] |
|
1736 |
||
1737 |
"/ 41in64 |
|
1738 |
||
1739 |
#[2r11101110 |
|
1740 |
2r01010101 |
|
1741 |
2r10111011 |
|
1742 |
2r01010101 |
|
1743 |
2r11101110 |
|
1744 |
2r01010101 |
|
1745 |
2r11111011 |
|
1746 |
2r01010101] |
|
1747 |
||
1748 |
"/ 42in64 |
|
1749 |
||
1750 |
#[2r11101110 |
|
1751 |
2r01010101 |
|
1752 |
2r10111111 |
|
1753 |
2r01010101 |
|
1754 |
2r11101110 |
|
1755 |
2r01010101 |
|
1756 |
2r11111011 |
|
1757 |
2r01010101] |
|
1758 |
||
1759 |
"/ 43in64 |
|
1760 |
||
1761 |
#[2r11101110 |
|
1762 |
2r01010101 |
|
1763 |
2r10111111 |
|
1764 |
2r01010101 |
|
1765 |
2r11101110 |
|
1766 |
2r01010101 |
|
1767 |
2r11111111 |
|
1768 |
2r01010101] |
|
1769 |
||
1770 |
"/ 44in64 |
|
1771 |
||
1772 |
#[2r11101110 |
|
1773 |
2r01010101 |
|
1774 |
2r11111111 |
|
1775 |
2r01010101 |
|
1776 |
2r11101110 |
|
1777 |
2r01010101 |
|
1778 |
2r11111111 |
|
1779 |
2r01010101] |
|
1780 |
||
1781 |
"/ 45in64 |
|
1782 |
||
1783 |
#[2r11101110 |
|
1784 |
2r01010101 |
|
1785 |
2r11111111 |
|
1786 |
2r01010101 |
|
1787 |
2r11111110 |
|
1788 |
2r01010101 |
|
1789 |
2r11111111 |
|
1790 |
2r01010101] |
|
1791 |
||
1792 |
"/ 46in64 |
|
1793 |
||
1794 |
#[2r11101111 |
|
1795 |
2r01010101 |
|
1796 |
2r11111111 |
|
1797 |
2r01010101 |
|
1798 |
2r11111110 |
|
1799 |
2r01010101 |
|
1800 |
2r11111111 |
|
1801 |
2r01010101] |
|
1802 |
||
1803 |
"/ 47in64 |
|
1804 |
||
1805 |
#[2r11101111 |
|
1806 |
2r01010101 |
|
1807 |
2r11111111 |
|
1808 |
2r01010101 |
|
1809 |
2r11111111 |
|
1810 |
2r01010101 |
|
1811 |
2r11111111 |
|
1812 |
2r01010101] |
|
1813 |
||
1814 |
"/ 48in64 |
|
1815 |
||
1816 |
#[2r11111111 |
|
1817 |
2r01010101 |
|
1818 |
2r11111111 |
|
1819 |
2r01010101 |
|
1820 |
2r11111111 |
|
1821 |
2r01010101 |
|
1822 |
2r11111111 |
|
1823 |
2r01010101] |
|
1824 |
||
1825 |
"/ 49in64 |
|
1826 |
||
1827 |
#[2r11111111 |
|
1828 |
2r01110101 |
|
1829 |
2r11111111 |
|
1830 |
2r01010101 |
|
1831 |
2r11111111 |
|
1832 |
2r01010101 |
|
1833 |
2r11111111 |
|
1834 |
2r01010101] |
|
1835 |
||
1836 |
"/ 50in64 |
|
1837 |
||
1838 |
#[2r11111111 |
|
1839 |
2r01110101 |
|
1840 |
2r11111111 |
|
1841 |
2r01010101 |
|
1842 |
2r11111111 |
|
1843 |
2r01010111 |
|
1844 |
2r11111111 |
|
1845 |
2r01010101] |
|
1846 |
||
1847 |
"/ 51in64 |
|
1848 |
||
1849 |
#[2r11111111 |
|
1850 |
2r01110101 |
|
1851 |
2r11111111 |
|
1852 |
2r01010101 |
|
1853 |
2r11111111 |
|
1854 |
2r01110111 |
|
1855 |
2r11111111 |
|
1856 |
2r01010101] |
|
1857 |
||
1858 |
"/ 52in64 |
|
1859 |
||
1860 |
#[2r11111111 |
|
1861 |
2r01110111 |
|
1862 |
2r11111111 |
|
1863 |
2r01010101 |
|
1864 |
2r11111111 |
|
1865 |
2r01110111 |
|
1866 |
2r11111111 |
|
1867 |
2r01010101] |
|
1868 |
||
1869 |
"/ 53in64 |
|
1870 |
||
1871 |
#[2r11111111 |
|
1872 |
2r01110111 |
|
1873 |
2r11111111 |
|
1874 |
2r01010101 |
|
1875 |
2r11111111 |
|
1876 |
2r01110111 |
|
1877 |
2r11111111 |
|
1878 |
2r11010101] |
|
1879 |
||
1880 |
"/ 54in64 |
|
1881 |
||
1882 |
#[2r11111111 |
|
1883 |
2r01110111 |
|
1884 |
2r11111111 |
|
1885 |
2r01011101 |
|
1886 |
2r11111111 |
|
1887 |
2r01110111 |
|
1888 |
2r11111111 |
|
1889 |
2r11010101] |
|
1890 |
||
1891 |
"/ 55in64 |
|
1892 |
||
1893 |
#[2r11111111 |
|
1894 |
2r01110111 |
|
1895 |
2r11111111 |
|
1896 |
2r11011101 |
|
1897 |
2r11111111 |
|
1898 |
2r01110111 |
|
1899 |
2r11111111 |
|
1900 |
2r11010101] |
|
1901 |
||
1902 |
"/ 56in64 |
|
1903 |
||
1904 |
#[2r11111111 |
|
1905 |
2r01110111 |
|
1906 |
2r11111111 |
|
1907 |
2r11011101 |
|
1908 |
2r11111111 |
|
1909 |
2r01110111 |
|
1910 |
2r11111111 |
|
1911 |
2r11011101] |
|
1912 |
||
1913 |
"/ 57in64 |
|
1914 |
||
1915 |
#[2r11111111 |
|
1916 |
2r01110111 |
|
1917 |
2r11111111 |
|
1918 |
2r11011101 |
|
1919 |
2r11111111 |
|
1920 |
2r01110111 |
|
1921 |
2r11111111 |
|
1922 |
2r11111101] |
|
1923 |
||
1924 |
"/ 58in64 |
|
1925 |
||
1926 |
#[2r11111111 |
|
1927 |
2r01110111 |
|
1928 |
2r11111111 |
|
1929 |
2r11011111 |
|
1930 |
2r11111111 |
|
1931 |
2r01110111 |
|
1932 |
2r11111111 |
|
1933 |
2r11111101] |
|
1934 |
||
1935 |
"/ 59in64 |
|
1936 |
||
1937 |
#[2r11111111 |
|
1938 |
2r01110111 |
|
1939 |
2r11111111 |
|
1940 |
2r11011111 |
|
1941 |
2r11111111 |
|
1942 |
2r01110111 |
|
1943 |
2r11111111 |
|
1944 |
2r11111111] |
|
1945 |
||
1946 |
"/ 60in64 |
|
1947 |
||
1948 |
#[2r11111111 |
|
1949 |
2r01110111 |
|
1950 |
2r11111111 |
|
1951 |
2r11111111 |
|
1952 |
2r11111111 |
|
1953 |
2r01110111 |
|
1954 |
2r11111111 |
|
1955 |
2r11111111] |
|
1956 |
||
1957 |
"/ 61in64 |
|
1958 |
||
1959 |
#[2r11111111 |
|
1960 |
2r01110111 |
|
1961 |
2r11111111 |
|
1962 |
2r11111111 |
|
1963 |
2r11111111 |
|
1964 |
2r01111111 |
|
1965 |
2r11111111 |
|
1966 |
2r11111111] |
|
1967 |
||
1968 |
"/ 62in64 |
|
1969 |
||
1970 |
#[2r11111111 |
|
1971 |
2r11110111 |
|
1972 |
2r11111111 |
|
1973 |
2r11111111 |
|
1974 |
2r11111111 |
|
1975 |
2r01111111 |
|
1976 |
2r11111111 |
|
1977 |
2r11111111] |
|
1978 |
||
1979 |
"/ 63in64 |
|
1980 |
||
1981 |
#[2r11111111 |
|
1982 |
2r11110111 |
|
1983 |
2r11111111 |
|
1984 |
2r11111111 |
|
1985 |
2r11111111 |
|
1986 |
2r11111111 |
|
1987 |
2r11111111 |
|
1988 |
2r11111111] |
|
1023 | 1989 |
) |
1990 |
||
1991 |
"Modified: 23.4.1996 / 13:31:50 / cg" |
|
1992 |
"Created: 11.6.1996 / 15:34:29 / cg" |
|
1993 |
! |
|
1994 |
||
1995 |
existingColorRed:r green:g blue:b on:aDevice |
|
1996 |
"return a device color on aDevice with rgb values |
|
1997 |
if there is one, nil otherwise." |
|
1998 |
||
1999 |
^ self existingColorScaledRed:(r * MaxValue // 100) |
|
1348 | 2000 |
scaledGreen:(g * MaxValue // 100) |
2001 |
scaledBlue:(b * MaxValue // 100) |
|
1023 | 2002 |
! |
2003 |
||
2004 |
existingColorScaledRed:r scaledGreen:g scaledBlue:b on:aDevice |
|
2005 |
"return a device color on aDevice with rgb values |
|
2006 |
if there is one, nil otherwise." |
|
2007 |
||
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2008 |
aDevice deviceColors do:[:aColor | |
1348 | 2009 |
(r == aColor scaledRed) ifTrue:[ |
2010 |
(g == aColor scaledGreen) ifTrue:[ |
|
2011 |
(b == aColor scaledBlue) ifTrue:[ |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2012 |
^ aColor |
1348 | 2013 |
] |
2014 |
] |
|
2015 |
] |
|
1023 | 2016 |
]. |
2017 |
^ nil |
|
2018 |
||
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2019 |
"Modified: 24.2.1997 / 18:17:35 / cg" |
1023 | 2020 |
! ! |
2021 |
||
1144 | 2022 |
!Color class methodsFor:'queries'! |
1023 | 2023 |
|
2024 |
constantNames |
|
2025 |
"return names known as instance creation messages" |
|
2026 |
||
2027 |
^ #(white black |
|
1348 | 2028 |
grey mediumGrey veryLightGrey lightGrey darkGrey veryDarkGrey |
2029 |
red green blue cyan yellow pink orange magenta) |
|
1023 | 2030 |
|
2031 |
"Modified: 2.5.1996 / 11:34:05 / cg" |
|
2032 |
! |
|
2033 |
||
2034 |
scalingValue |
|
2035 |
"ST-80 compatibility" |
|
2036 |
||
2037 |
^ MaxValue |
|
2038 |
||
2039 |
"Created: 2.5.1996 / 11:30:09 / cg" |
|
2040 |
"Modified: 11.7.1996 / 21:42:26 / cg" |
|
2041 |
! ! |
|
2042 |
||
1144 | 2043 |
!Color class methodsFor:'special instance creation'! |
1023 | 2044 |
|
2045 |
nearestColorRed:r green:g blue:b on:aDevice in:colors |
|
2046 |
"return the nearest color on aDevice with RGB values |
|
2047 |
same or near r/g/b in a collection of colors. |
|
2048 |
If there is one, return it; nil otherwise. |
|
2049 |
Near is defined as having an error less than the argument |
|
2050 |
error (in percent). The error is computed by the color |
|
2051 |
vector distance (which may not be the best possible solution)." |
|
2052 |
||
2053 |
^ self |
|
1348 | 2054 |
nearestColorScaledRed:(r * MaxValue // 100) |
2055 |
scaledGreen:(g * MaxValue // 100) |
|
2056 |
scaledBlue:(b * MaxValue // 100) |
|
2057 |
on:aDevice |
|
2058 |
in:colors |
|
1023 | 2059 |
|
2060 |
"Modified: 11.6.1996 / 18:04:55 / cg" |
|
2061 |
"Created: 14.6.1996 / 20:05:13 / cg" |
|
2062 |
! |
|
2063 |
||
2064 |
nearestColorScaledRed:r scaledGreen:g scaledBlue:b inCube:aColorCube numRed:nRed numGreen:nGreen numBlue:nBlue |
|
2065 |
"return a color with rgb values same or near r/g/b in a given |
|
2066 |
collection, containing colors from a colorCube. |
|
2067 |
This is used with preallocated fixColors and is quite fast |
|
2068 |
(no need to search)" |
|
2069 |
||
2070 |
|sR "{ Class: SmallInteger }" |
|
2071 |
sG "{ Class: SmallInteger }" |
|
2072 |
sB "{ Class: SmallInteger }" |
|
2073 |
idx "{ Class: SmallInteger }" |
|
2074 |
nR "{ Class: SmallInteger }" |
|
2075 |
nG "{ Class: SmallInteger }" |
|
2076 |
nB "{ Class: SmallInteger }" |
|
2077 |
rI "{ Class: SmallInteger }" |
|
2078 |
gI "{ Class: SmallInteger }" |
|
2079 |
bI "{ Class: SmallInteger }"| |
|
2080 |
||
2081 |
" |
|
2082 |
round to the step given by FixColors |
|
2083 |
" |
|
2084 |
nR := nRed. |
|
2085 |
nG := nGreen. |
|
2086 |
nB := nBlue. |
|
2087 |
||
2088 |
sR := MaxValue // (nR - 1). |
|
2089 |
sG := MaxValue // (nG - 1). |
|
2090 |
sB := MaxValue // (nB - 1). |
|
2091 |
||
2092 |
rI := (r + (sR // 2)) // sR. |
|
2093 |
gI := (g + (sG // 2)) // sG. |
|
2094 |
bI := (b + (sB // 2)) // sB. |
|
2095 |
idx := (((rI * nG) + gI) * nB + bI) + 1. |
|
2096 |
^ aColorCube at:idx |
|
2097 |
||
2098 |
"Modified: 11.7.1996 / 17:52:46 / cg" |
|
2099 |
"Created: 11.7.1996 / 18:20:13 / cg" |
|
2100 |
! |
|
2101 |
||
2102 |
nearestColorScaledRed:r scaledGreen:g scaledBlue:b on:aDevice |
|
2103 |
"return a device color on aDevice with RGB values |
|
2104 |
same or near r/g/b, if there is one, nil otherwise. |
|
2105 |
Near is defined as having an error less than the argument |
|
2106 |
error (in percent). The error is computed by the color |
|
2107 |
vector distance (which may not be the best possible solution)." |
|
2108 |
||
2109 |
|cube| |
|
2110 |
||
2111 |
" |
|
2112 |
if there are preallocated colors, things are much easier ... |
|
2113 |
" |
|
2114 |
(cube := aDevice fixColors) notNil ifTrue:[ |
|
1348 | 2115 |
^ self |
2116 |
nearestColorScaledRed:r |
|
2117 |
scaledGreen:g |
|
2118 |
scaledBlue:b |
|
2119 |
inCube:cube |
|
2120 |
numRed:(aDevice numFixRed) |
|
2121 |
numGreen:(aDevice numFixGreen) |
|
2122 |
numBlue:(aDevice numFixBlue) |
|
1023 | 2123 |
]. |
2124 |
||
2125 |
" |
|
2126 |
search in existing colors ... |
|
2127 |
" |
|
2128 |
^ self |
|
1348 | 2129 |
nearestColorScaledRed:r |
2130 |
scaledGreen:g |
|
2131 |
scaledBlue:b |
|
2132 |
on:aDevice |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2133 |
in:aDevice deviceColors |
1023 | 2134 |
|
2135 |
"Created: 14.6.1996 / 20:11:18 / cg" |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2136 |
"Modified: 24.2.1997 / 18:17:51 / cg" |
1023 | 2137 |
! |
2138 |
||
2139 |
nearestColorScaledRed:r scaledGreen:g scaledBlue:b on:aDevice in:colors |
|
2140 |
"return the nearest color on aDevice with RGB values |
|
2141 |
same or near r/g/b in a collection of colors. |
|
2142 |
If there is one, return it; nil otherwise." |
|
2143 |
||
2144 |
|delta minDelta bestSoFar| |
|
2145 |
||
2146 |
minDelta := 9999999. |
|
2147 |
||
2148 |
colors do:[:aColor | |
|
1348 | 2149 |
|cr cg cb| |
2150 |
||
2151 |
(aColor graphicsDevice == aDevice) ifTrue:[ |
|
2152 |
aColor colorId notNil ifTrue:[ |
|
2153 |
delta := aColor deltaFromScaledRed:r scaledGreen:g scaledBlue:b. |
|
2154 |
delta < minDelta ifTrue:[ |
|
2155 |
" |
|
2156 |
an exact fit - no need to continue search |
|
2157 |
" |
|
2158 |
delta == 0 ifTrue:[^ aColor]. |
|
2159 |
||
2160 |
bestSoFar := aColor. |
|
2161 |
minDelta := delta |
|
2162 |
] |
|
2163 |
] |
|
2164 |
] |
|
1023 | 2165 |
]. |
2166 |
||
2167 |
^ bestSoFar |
|
2168 |
||
2169 |
"Created: 11.6.1996 / 18:02:12 / cg" |
|
2170 |
"Modified: 5.7.1996 / 17:58:09 / cg" |
|
2171 |
! |
|
2172 |
||
2173 |
quickNearestColorScaledRed:r scaledGreen:g scaledBlue:b on:aDevice |
|
2174 |
"return a device color on aDevice with rgb values |
|
2175 |
same or near r/g/b. |
|
2176 |
Near is defined as having an error less than the argument |
|
2177 |
error (in percent). The error is computed by the color |
|
2178 |
vector distance (which may not be the best possible solution). |
|
2179 |
This looks for primary colors only and is thus faster |
|
2180 |
than the general nearestColor search (slightly uglier though)." |
|
2181 |
||
2182 |
|cube| |
|
2183 |
||
2184 |
" |
|
2185 |
if there are preallocated colors, thungs are much easier ... |
|
2186 |
" |
|
2187 |
(cube := aDevice fixColors) ifTrue:[ |
|
1348 | 2188 |
^ self |
2189 |
nearestColorScaledRed:r |
|
2190 |
scaledGreen:g |
|
2191 |
scaledBlue:b |
|
2192 |
inCube:cube |
|
2193 |
numRed:(aDevice numFixRed) |
|
2194 |
numGreen:(aDevice numFixGreen) |
|
2195 |
numBlue:(aDevice numFixBlue) |
|
1023 | 2196 |
]. |
2197 |
||
2198 |
" |
|
2199 |
search in existing colors ... |
|
2200 |
" |
|
2201 |
^ self nearestColorScaledRed:r |
|
1348 | 2202 |
scaledGreen:g |
2203 |
scaledBlue:b |
|
2204 |
on:aDevice |
|
2205 |
in:aDevice availableDitherColors |
|
1023 | 2206 |
|
2207 |
"Created: 14.6.1996 / 20:13:22 / cg" |
|
2208 |
"Modified: 11.7.1996 / 18:20:14 / cg" |
|
2209 |
! ! |
|
2210 |
||
1347 | 2211 |
!Color methodsFor:'ST-80 compatibility'! |
2212 |
||
2213 |
asDevicePaintOn:aDevice |
|
2214 |
"ST-80 compatibility: an alias for on:. |
|
2215 |
create a new Color representing the same color as |
|
2216 |
myself on aDevice; if one already exists, return the one" |
|
2217 |
||
2218 |
^ self on:aDevice |
|
2219 |
! ! |
|
2220 |
||
1023 | 2221 |
!Color methodsFor:'accessing'! |
2222 |
||
2223 |
blue |
|
2224 |
"return the blue component in percent [0..100]" |
|
2225 |
||
2226 |
(blue isNil and:[colorId notNil]) ifTrue:[ |
|
1348 | 2227 |
device getRGBFrom:colorId into:[:r :g :b | ^ b]. |
1023 | 2228 |
]. |
2229 |
^ blue * 100.0 / MaxValue |
|
2230 |
! |
|
2231 |
||
2232 |
blueByte |
|
2233 |
"return the blue components value mapped to 0..255" |
|
2234 |
||
2235 |
^ blue * 255 // MaxValue |
|
2236 |
||
2237 |
" |
|
2238 |
Color red blueByte |
|
2239 |
Color blue blueByte |
|
2240 |
Color green blueByte |
|
2241 |
Color black blueByte |
|
2242 |
Color grey blueByte |
|
2243 |
Color white blueByte |
|
2244 |
" |
|
2245 |
||
2246 |
"Created: 7.6.1996 / 18:30:25 / cg" |
|
2247 |
"Modified: 7.6.1996 / 18:32:03 / cg" |
|
2248 |
! |
|
2249 |
||
2250 |
colorId |
|
2251 |
"return the device-dependent color-id" |
|
2252 |
||
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2253 |
colorId notNil ifTrue:[^ colorId]. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2254 |
replacementColor notNil ifTrue:[^ replacementColor colorId]. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2255 |
^ nil |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2256 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2257 |
"Modified: 17.1.1997 / 00:03:18 / cg" |
1023 | 2258 |
! |
2259 |
||
2260 |
cyan |
|
2261 |
"return the cyan component in percent [0..100] in cmy color space" |
|
2262 |
||
2263 |
^ 100 - self red |
|
2264 |
||
2265 |
"Modified: 11.6.1996 / 17:20:07 / cg" |
|
2266 |
"Created: 11.6.1996 / 18:30:00 / cg" |
|
2267 |
! |
|
2268 |
||
2269 |
device |
|
2270 |
"return the device I am associated to" |
|
2271 |
||
2272 |
^ device |
|
2273 |
||
2274 |
"Modified: 23.4.1996 / 13:36:42 / cg" |
|
2275 |
! |
|
2276 |
||
2277 |
deviceBlue |
|
2278 |
"return the actual value of the blue component in percent." |
|
2279 |
||
2280 |
|v| |
|
2281 |
||
2282 |
device getRGBFrom:colorId into:[:r :g :b | v := b]. |
|
2283 |
^ v |
|
2284 |
! |
|
2285 |
||
2286 |
deviceGreen |
|
2287 |
"return the actual value of the green component in percent. |
|
2288 |
(usually 16bit in X; but could be different on other systems)" |
|
2289 |
||
2290 |
|v| |
|
2291 |
||
2292 |
device getRGBFrom:colorId into:[:r :g :b | v := g]. |
|
2293 |
^ v |
|
2294 |
! |
|
2295 |
||
2296 |
deviceRed |
|
2297 |
"return the actual value of the red component in percent." |
|
2298 |
||
2299 |
|v| |
|
2300 |
||
2301 |
device getRGBFrom:colorId into:[:r :g :b | v := r]. |
|
2302 |
^ v |
|
2303 |
||
2304 |
" |
|
2305 |
(Color yellow on:Display) deviceRedValue |
|
2306 |
(Color yellow on:aPrinterPage) deviceRedValue |
|
2307 |
" |
|
2308 |
! |
|
2309 |
||
2310 |
ditherForm |
|
2311 |
"return the form to dither the color" |
|
2312 |
||
2313 |
^ ditherForm |
|
2314 |
! |
|
2315 |
||
2316 |
graphicsDevice |
|
2317 |
"same as #device, for ST-80 compatibility naming. |
|
2318 |
Return the device I am associated with." |
|
2319 |
||
2320 |
^ device |
|
2321 |
||
2322 |
"Created: 28.5.1996 / 18:39:27 / cg" |
|
2323 |
! |
|
2324 |
||
2325 |
green |
|
2326 |
"return the green component in percent [0..100]" |
|
2327 |
||
2328 |
(green isNil and:[colorId notNil]) ifTrue:[ |
|
1348 | 2329 |
device getRGBFrom:colorId into:[:r :g :b | ^ g]. |
1023 | 2330 |
]. |
2331 |
^ green * 100.0 / MaxValue |
|
2332 |
! |
|
2333 |
||
2334 |
greenByte |
|
2335 |
"return the green components value mapped to 0..255" |
|
2336 |
||
2337 |
^ green * 255 // MaxValue |
|
2338 |
||
2339 |
" |
|
2340 |
Color red greenByte |
|
2341 |
Color blue greenByte |
|
2342 |
Color green greenByte |
|
2343 |
Color black greenByte |
|
2344 |
Color grey greenByte |
|
2345 |
Color white greenByte |
|
2346 |
" |
|
2347 |
||
2348 |
"Modified: 7.6.1996 / 18:31:30 / cg" |
|
2349 |
! |
|
2350 |
||
2351 |
hue |
|
2352 |
"return the hue (in hue/light/saturation model) in degrees [0..360]" |
|
2353 |
||
2354 |
|r g b h| |
|
2355 |
||
2356 |
(red isNil and:[colorId notNil]) ifTrue:[ |
|
1348 | 2357 |
device getRGBFrom:colorId into:[:xr :xg :xb | |
2358 |
r := xr. |
|
2359 |
g := xg. |
|
2360 |
b := xb. |
|
2361 |
] |
|
1023 | 2362 |
] ifFalse:[ |
1348 | 2363 |
r := self red. |
2364 |
g := self green. |
|
2365 |
b := self blue. |
|
1023 | 2366 |
]. |
2367 |
||
2368 |
self class withHLSFromRed:r green:g blue:b do:[:xh :xl :xs | |
|
1348 | 2369 |
h := xh |
1023 | 2370 |
]. |
2371 |
^ h |
|
2372 |
||
2373 |
" |
|
2374 |
Color yellow hue |
|
2375 |
" |
|
2376 |
||
2377 |
"Modified: 11.6.1996 / 17:14:51 / cg" |
|
2378 |
! |
|
2379 |
||
2380 |
light |
|
2381 |
"return the light (in hue/light/saturation model) in percent [0..100]. |
|
2382 |
This corresponds to the brightness of the color (if displayed on |
|
2383 |
a b&w television screen)" |
|
2384 |
||
2385 |
|r g b l| |
|
2386 |
||
2387 |
(red isNil and:[colorId notNil]) ifTrue:[ |
|
1348 | 2388 |
device getRGBFrom:colorId into:[:xr :xg :xb | |
2389 |
r := xr. |
|
2390 |
g := xg. |
|
2391 |
b := xb. |
|
2392 |
] |
|
1023 | 2393 |
] ifFalse:[ |
1348 | 2394 |
r := self red. |
2395 |
g := self green. |
|
2396 |
b := self blue. |
|
1023 | 2397 |
]. |
2398 |
||
2399 |
self class withHLSFromRed:r green:g blue:b do:[:xh :xl :xs | |
|
1348 | 2400 |
l := xl |
1023 | 2401 |
]. |
2402 |
^ l |
|
2403 |
||
2404 |
" |
|
2405 |
Color yellow light |
|
2406 |
Color yellow darkened light |
|
2407 |
" |
|
2408 |
||
2409 |
"Modified: 11.6.1996 / 17:15:24 / cg" |
|
2410 |
! |
|
2411 |
||
2412 |
magenta |
|
2413 |
"return the magenta component in percent [0..100] in cmy color space" |
|
2414 |
||
2415 |
^ 100 - self green |
|
2416 |
||
2417 |
"Modified: 11.6.1996 / 17:20:07 / cg" |
|
2418 |
"Created: 11.6.1996 / 18:30:11 / cg" |
|
2419 |
! |
|
2420 |
||
2421 |
red |
|
2422 |
"return the red component in percent [0..100]" |
|
2423 |
||
2424 |
(red isNil and:[colorId notNil]) ifTrue:[ |
|
1348 | 2425 |
device getRGBFrom:colorId into:[:r :g :b | ^ r]. |
1023 | 2426 |
]. |
2427 |
red isNil ifTrue:[^ 0]. |
|
2428 |
^ red * 100.0 / MaxValue |
|
2429 |
||
2430 |
"Modified: 11.6.1996 / 17:20:07 / cg" |
|
2431 |
! |
|
2432 |
||
2433 |
red:r green:g blue:b |
|
2434 |
"set r/g/b components in percent. This method will change the color lookup |
|
2435 |
table in pseudocolor devices. |
|
2436 |
This is only allowed for writable colors (i.e. those allocated with |
|
2437 |
Color>>variableColorOn: on pseudoColor displays). |
|
2438 |
Using this may make your code unportable, since it depends on a display |
|
2439 |
using palettes (i.e. it will not work on greyScale or b&w displays)." |
|
2440 |
||
2441 |
^ self scaledRed:(r * MaxValue // 100) |
|
1348 | 2442 |
scaledGreen:(g * MaxValue // 100) |
2443 |
scaledBlue:(b * MaxValue // 100) |
|
1023 | 2444 |
|
2445 |
" |
|
2446 |
|c| |
|
2447 |
||
2448 |
c := Color variableColorOn:Display. |
|
2449 |
c inspect. |
|
2450 |
(Delay forSeconds:5) wait. |
|
2451 |
c red:100 green:0 blue:0. |
|
2452 |
(Delay forSeconds:5) wait. |
|
2453 |
c red:0 green:100 blue:0. |
|
2454 |
(Delay forSeconds:5) wait. |
|
2455 |
c red:0 green:0 blue:100. |
|
2456 |
" |
|
2457 |
! |
|
2458 |
||
2459 |
redByte |
|
2460 |
"return the red components value mapped to 0..255" |
|
2461 |
||
2462 |
^ red * 255 // MaxValue |
|
2463 |
||
2464 |
" |
|
2465 |
Color red redByte |
|
2466 |
Color blue redByte |
|
2467 |
Color green redByte |
|
2468 |
Color black redByte |
|
2469 |
Color grey redByte |
|
2470 |
Color white redByte |
|
2471 |
" |
|
2472 |
||
2473 |
"Modified: 7.6.1996 / 18:31:51 / cg" |
|
2474 |
! |
|
2475 |
||
2476 |
saturation |
|
2477 |
"return the saturation (in hue/light/saturation model) in percent [0..100]. |
|
2478 |
This corresponds to the saturation setting of a color TV" |
|
2479 |
||
2480 |
|r g b s| |
|
2481 |
||
2482 |
(red isNil and:[colorId notNil]) ifTrue:[ |
|
1348 | 2483 |
device getRGBFrom:colorId into:[:xr :xg :xb | |
2484 |
r := xr. |
|
2485 |
g := xg. |
|
2486 |
b := xb. |
|
2487 |
] |
|
1023 | 2488 |
] ifFalse:[ |
1348 | 2489 |
r := self red. |
2490 |
g := self green. |
|
2491 |
b := self blue. |
|
1023 | 2492 |
]. |
2493 |
||
2494 |
self class withHLSFromRed:r green:g blue:b do:[:xh :xl :xs | |
|
1348 | 2495 |
s := xs |
1023 | 2496 |
]. |
2497 |
^ s |
|
2498 |
||
2499 |
" |
|
2500 |
Color yellow saturation |
|
2501 |
" |
|
2502 |
||
2503 |
"Modified: 11.6.1996 / 17:15:47 / cg" |
|
2504 |
! |
|
2505 |
||
2506 |
scaledBlue |
|
2507 |
"ST-80 compatibility: |
|
2508 |
return the blue components value mapped to 0..MaxValue" |
|
2509 |
||
2510 |
^ blue |
|
2511 |
||
2512 |
" |
|
2513 |
Color blue scaledBlue |
|
2514 |
Color black scaledBlue |
|
2515 |
Color grey scaledBlue |
|
2516 |
" |
|
2517 |
||
2518 |
"Modified: 7.6.1996 / 18:32:30 / cg" |
|
2519 |
! |
|
2520 |
||
2521 |
scaledGray |
|
2522 |
"return the grey intensity scaled to 0..MaxValue" |
|
2523 |
||
2524 |
^ ((red * 3) + (green * 6) + blue) // 10 |
|
2525 |
||
2526 |
" |
|
2527 |
Color blue scaledGray |
|
2528 |
Color black scaledGray |
|
2529 |
Color white scaledGray |
|
2530 |
Color grey scaledGray |
|
2531 |
" |
|
2532 |
||
2533 |
"Modified: 11.6.1996 / 14:43:51 / cg" |
|
2534 |
! |
|
2535 |
||
2536 |
scaledGreen |
|
2537 |
"ST-80 compatibility: |
|
2538 |
return the green components value mapped to 0..MaxValue" |
|
2539 |
||
2540 |
^ green |
|
2541 |
||
2542 |
" |
|
2543 |
Color green scaledRed |
|
2544 |
Color black scaledRed |
|
2545 |
Color grey scaledRed |
|
2546 |
" |
|
2547 |
||
2548 |
"Modified: 7.6.1996 / 18:32:38 / cg" |
|
2549 |
! |
|
2550 |
||
2551 |
scaledRed |
|
2552 |
"ST-80 compatibility: |
|
2553 |
return the red components value mapped to 0..MaxValue" |
|
2554 |
||
2555 |
^ red |
|
2556 |
||
2557 |
" |
|
2558 |
Color red scaledRed |
|
2559 |
Color black scaledRed |
|
2560 |
Color grey scaledRed |
|
2561 |
" |
|
2562 |
||
2563 |
"Modified: 7.6.1996 / 18:32:43 / cg" |
|
2564 |
! |
|
2565 |
||
2566 |
scaledRed:r scaledGreen:g scaledBlue:b |
|
2567 |
"set r/g/b components in 0..MaxValue. |
|
2568 |
This method will change the color lookup table in pseudocolor devices. |
|
2569 |
This is only allowed for writable colors (i.e. those allocated with |
|
2570 |
Color>>variableColorOn: on pseudoColor displays). |
|
2571 |
Using this may make your code unportable, since it depends on a display |
|
2572 |
using palettes (i.e. it will not work on greyScale or b&w displays)." |
|
2573 |
||
2574 |
(colorId isNil or:[red notNil]) ifTrue:[ |
|
1348 | 2575 |
^ self error:'operation is not allowed for shared colors' |
1023 | 2576 |
]. |
2577 |
device setColor:colorId scaledRed:r scaledGreen:g scaledBlue:b |
|
2578 |
! |
|
2579 |
||
2580 |
writable |
|
2581 |
"return true, if this is a writable colorcell" |
|
2582 |
||
2583 |
^ writable == true |
|
2584 |
! |
|
2585 |
||
2586 |
yellow |
|
2587 |
"return the yellow component in percent [0..100] in cmy color space" |
|
2588 |
||
2589 |
^ 100 - self blue |
|
2590 |
||
2591 |
"Modified: 11.6.1996 / 17:20:07 / cg" |
|
2592 |
"Created: 11.6.1996 / 18:30:20 / cg" |
|
2593 |
! ! |
|
2594 |
||
2595 |
!Color methodsFor:'binary storage'! |
|
2596 |
||
2597 |
readBinaryContentsFrom: stream manager: manager |
|
2598 |
"tell the newly restored Color about restoration" |
|
2599 |
||
2600 |
super readBinaryContentsFrom:stream manager:manager. |
|
2601 |
self postCopy |
|
2602 |
! ! |
|
2603 |
||
2604 |
!Color methodsFor:'comparing'! |
|
2605 |
||
2606 |
= aColor |
|
2607 |
"two colors are considered equal, if the color components are; |
|
2608 |
independent of the device, the color is on" |
|
2609 |
||
2610 |
aColor == self ifTrue:[^ self]. |
|
2611 |
aColor isColor ifTrue:[ |
|
1348 | 2612 |
(red == aColor scaledRed) ifTrue:[ |
2613 |
(green == aColor scaledGreen) ifTrue:[ |
|
2614 |
(blue == aColor scaledBlue) ifTrue:[ |
|
2615 |
^ true |
|
2616 |
] |
|
2617 |
] |
|
2618 |
] |
|
1023 | 2619 |
]. |
2620 |
^ false |
|
2621 |
! |
|
2622 |
||
2623 |
hash |
|
2624 |
"return an integer useful as hash key for the receiver. |
|
2625 |
Redefined since = is redefined" |
|
2626 |
||
2627 |
^ red + green + blue |
|
2628 |
! ! |
|
2629 |
||
2630 |
!Color methodsFor:'converting'! |
|
2631 |
||
2632 |
fromLiteralArrayEncoding:encoding |
|
2633 |
"read my values from an encoding. |
|
2634 |
The encoding is supposed to be of the form: |
|
1348 | 2635 |
(#Color redPart greenPart bluePart) |
1023 | 2636 |
This is the reverse operation to #literalArrayEncoding." |
2637 |
||
2638 |
red := ((encoding at:2) / 100.0 * MaxValue) rounded. |
|
2639 |
green := ((encoding at:3) / 100.0 * MaxValue) rounded. |
|
2640 |
blue := ((encoding at:4) / 100.0 * MaxValue) rounded. |
|
2641 |
||
2642 |
" |
|
2643 |
Color new fromLiteralArrayEncoding:#(#Color 50 25 25) |
|
2644 |
" |
|
2645 |
! |
|
2646 |
||
2647 |
literalArrayEncoding |
|
2648 |
"encode myself as an array, from which a copy of the receiver |
|
2649 |
can be reconstructed with #decodeAsLiteralArray. |
|
2650 |
The encoding is: |
|
1348 | 2651 |
(#Color redPart greenPart bluePart) |
1023 | 2652 |
" |
2653 |
||
2654 |
^ Array |
|
1348 | 2655 |
with:self class name asSymbol |
2656 |
with:(red * 100.0 / MaxValue) |
|
2657 |
with:(green * 100.0 / MaxValue) |
|
2658 |
with:(blue * 100.0 / MaxValue) |
|
1023 | 2659 |
|
2660 |
" |
|
2661 |
Color new fromLiteralArrayEncoding:#(#Color 50 25 25) |
|
2662 |
(Color red:25 green:30 blue:70) literalArrayEncoding |
|
2663 |
" |
|
2664 |
||
2665 |
"Modified: 22.4.1996 / 13:00:11 / cg" |
|
2666 |
! ! |
|
2667 |
||
2668 |
!Color methodsFor:'copying'! |
|
2669 |
||
2670 |
postCopy |
|
2671 |
"redefined to clear out any device handles in the copy" |
|
2672 |
||
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2673 |
device := colorId := ditherForm := replacementColor := nil |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2674 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2675 |
"Modified: 17.1.1997 / 00:03:42 / cg" |
1023 | 2676 |
! ! |
2677 |
||
2678 |
!Color methodsFor:'getting a device color'! |
|
2679 |
||
2680 |
exactOn:aDevice |
|
2681 |
"create a new Color representing the same color as |
|
2682 |
myself on aDevice; if one already exists, return the one. |
|
2683 |
Do not dither or otherwise approximate the color, but return |
|
2684 |
nil, if the exact color is not available. |
|
2685 |
Used to aquire primary colors for dithering, during startup." |
|
2686 |
||
2687 |
|newColor id r g b| |
|
2688 |
||
2689 |
"if Iam already assigned to that device ..." |
|
2690 |
(device == aDevice and:[ditherForm isNil]) ifTrue:[^ self]. |
|
2691 |
||
2692 |
r := red. |
|
2693 |
g := green. |
|
2694 |
b := blue. |
|
2695 |
||
1239
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
2696 |
"first look if not already there" |
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
2697 |
newColor := Color existingColorScaledRed:r scaledGreen:g scaledBlue:b on:aDevice. |
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
2698 |
(newColor notNil and:[newColor ditherForm isNil]) ifTrue:[^ newColor]. |
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
2699 |
|
1023 | 2700 |
r := (r bitAnd:16rFF00) bitOr:(r bitShift:-8). |
2701 |
g := (g bitAnd:16rFF00) bitOr:(g bitShift:-8). |
|
2702 |
b := (b bitAnd:16rFF00) bitOr:(b bitShift:-8). |
|
2703 |
||
2704 |
"ask that device for the color" |
|
2705 |
id := aDevice colorScaledRed:r scaledGreen:g scaledBlue:b. |
|
2706 |
id isNil ifTrue:[ |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2707 |
"/ this is a kludge: scavenge to free unused colors |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2708 |
"/ and try again ... |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2709 |
ObjectMemory scavenge; finalize. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2710 |
id := aDevice colorScaledRed:r scaledGreen:g scaledBlue:b |
1023 | 2711 |
]. |
2712 |
id isNil ifTrue:[ |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2713 |
"no such color - fail" |
1023 | 2714 |
|
2715 |
"/ 'COLOR: no color for ' infoPrint. self displayString infoPrintCR. |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2716 |
^ nil |
1023 | 2717 |
]. |
2718 |
||
2719 |
"receiver was not associated - do it now" |
|
2720 |
device isNil ifTrue:[ |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2721 |
device := aDevice. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2722 |
colorId := id. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2723 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2724 |
aDevice visualType ~~ #TrueColor ifTrue:[ |
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2725 |
"/ Lobby register:self. |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2726 |
aDevice registerColor:self. |
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2727 |
]. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2728 |
^ self |
1023 | 2729 |
]. |
2730 |
||
2731 |
"receiver was already associated to another device - need a new color" |
|
2732 |
newColor := (self class basicNew) setScaledRed:r scaledGreen:g scaledBlue:b device:aDevice. |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2733 |
newColor setColorId:id. |
1023 | 2734 |
aDevice visualType ~~ #TrueColor ifTrue:[ |
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2735 |
"/ Lobby register:newColor. |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2736 |
aDevice registerColor:newColor. |
1023 | 2737 |
]. |
2738 |
^ newColor |
|
2739 |
||
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2740 |
"Modified: 24.2.1997 / 18:23:20 / cg" |
1023 | 2741 |
! |
2742 |
||
2743 |
nearestOn:aDevice |
|
2744 |
"create a new Color representing the same color as myself on aDevice; |
|
2745 |
if one already exists, return the one. If no exact match is found, |
|
2746 |
search for the nearest match" |
|
2747 |
||
2748 |
|newColor id| |
|
2749 |
||
2750 |
"if I'am already assigned to that device ..." |
|
2751 |
(device == aDevice) ifTrue:[^ self]. |
|
2752 |
||
2753 |
"first look if not already there" |
|
2754 |
newColor := Color nearestColorScaledRed:red scaledGreen:green scaledBlue:blue on:aDevice. |
|
2755 |
newColor notNil ifTrue:[^ newColor]. |
|
2756 |
||
2757 |
"ask that device for the color" |
|
2758 |
id := aDevice colorScaledRed:red scaledGreen:green scaledBlue:blue. |
|
2759 |
id isNil ifTrue:[ |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2760 |
"this is a kludge: |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2761 |
scavenge to possuby free unused colors and try again ... |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2762 |
this is a compromise: actually a full GC is required here, |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2763 |
but that is too expensive. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2764 |
" |
1023 | 2765 |
" " |
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2766 |
ObjectMemory scavenge; finalize. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2767 |
id := aDevice colorScaledRed:red scaledGreen:green scaledBlue:blue |
1023 | 2768 |
" " |
2769 |
]. |
|
2770 |
id isNil ifTrue:[ |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2771 |
"no color - fail" |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2772 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2773 |
^ nil |
1023 | 2774 |
]. |
2775 |
||
2776 |
"receiver was not associated - do it now" |
|
2777 |
device isNil ifTrue:[ |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2778 |
device := aDevice. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2779 |
colorId := id. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2780 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2781 |
aDevice visualType ~~ #TrueColor ifTrue:[ |
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2782 |
"/ Lobby register:self. |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2783 |
aDevice registerColor:self. |
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2784 |
]. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2785 |
^ self |
1023 | 2786 |
]. |
2787 |
||
2788 |
"receiver was already associated to another device - need a new color" |
|
2789 |
newColor := (self class basicNew) setScaledRed:red scaledGreen:green sclaedBlue:blue device:aDevice. |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2790 |
newColor setColorId:id. |
1023 | 2791 |
aDevice visualType ~~ #TrueColor ifTrue:[ |
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2792 |
"/ Lobby register:newColor. |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2793 |
aDevice registerColor:newColor. |
1023 | 2794 |
]. |
2795 |
^ newColor |
|
2796 |
||
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2797 |
"Modified: 24.2.1997 / 18:23:26 / cg" |
1023 | 2798 |
! |
2799 |
||
2800 |
on:aDevice |
|
2801 |
"create a new Color representing the same color as |
|
2802 |
myself on aDevice; if one already exists, return the one" |
|
2803 |
||
2804 |
|newColor id grey form |
|
2805 |
greyV "{ Class: SmallInteger }" |
|
2806 |
rV "{ Class: SmallInteger }" |
|
2807 |
gV "{ Class: SmallInteger }" |
|
2808 |
bV "{ Class: SmallInteger }" |
|
1144 | 2809 |
deviceVisual deviceFixColors| |
1023 | 2810 |
|
1233 | 2811 |
"/ the most common cases (already allocated) first |
2812 |
||
2813 |
colorId notNil ifTrue:[ |
|
2814 |
||
2815 |
"/ is someone validating me before drawing on aDevice ? |
|
2816 |
||
2817 |
aDevice notNil ifTrue:[ |
|
2818 |
aDevice == device ifTrue:[ |
|
1144 | 2819 |
^ self |
2820 |
] |
|
1233 | 2821 |
]. |
2822 |
||
2823 |
"/ a special case for pseudo-colors (0 and 1 in bitmaps) |
|
2824 |
"/ those have nil r/g/b values, but a nonNil colorId |
|
2825 |
||
2826 |
red isNil ifTrue:[^ self]. |
|
2827 |
||
2828 |
"/ want to release color ? |
|
2829 |
||
2830 |
(aDevice isNil and:[device notNil]) ifTrue:[ |
|
2831 |
"/ trueColor device-colors are not registered |
|
2832 |
device visualType ~~ #TrueColor ifTrue:[ |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2833 |
"/ Lobby unregister:self. |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2834 |
device unregisterColor:newColor. |
1205 | 2835 |
device freeColor:colorId |
2836 |
]. |
|
1233 | 2837 |
device := nil. |
2838 |
colorId := nil. |
|
2839 |
^ self |
|
1205 | 2840 |
]. |
2841 |
]. |
|
2842 |
||
1233 | 2843 |
"/ on high-resolution true-color systems, dont care for dithering and/or |
1023 | 2844 |
"/ especially freeing colors |
2845 |
"/ (no need to remember in Lobby) |
|
2846 |
||
2847 |
(deviceVisual := aDevice visualType) == #TrueColor ifTrue:[ |
|
1144 | 2848 |
aDevice depth >= 15 ifTrue:[ |
2849 |
id := aDevice colorScaledRed:red scaledGreen:green scaledBlue:blue. |
|
2850 |
id notNil ifTrue:[ |
|
2851 |
device isNil ifTrue:[ |
|
2852 |
colorId := id. |
|
2853 |
ditherForm := nil. |
|
2854 |
^ self |
|
1233 | 2855 |
]. |
2856 |
newColor := (self class basicNew) |
|
2857 |
setScaledRed:red |
|
2858 |
scaledGreen:green |
|
2859 |
scaledBlue:blue |
|
2860 |
device:aDevice. |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
2861 |
newColor setColorId:id. |
1233 | 2862 |
^ newColor |
1144 | 2863 |
] |
2864 |
] |
|
1023 | 2865 |
]. |
2866 |
||
2867 |
"/ round a bit within 1% in red & green, 2% in blue |
|
2868 |
||
1239
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
2869 |
rV := red. |
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
2870 |
gV := green. |
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
2871 |
bV := blue. |
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
2872 |
|
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
2873 |
"/ rV := (red / 100.0) rounded * 100. |
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
2874 |
"/ gV := (green / 100.0) rounded * 100. |
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
2875 |
"/ bV := (blue / 50.0) rounded * 50. |
1023 | 2876 |
|
1233 | 2877 |
"/ if I am already assigned to that device ... |
2878 |
||
2879 |
((device == aDevice) and:[ditherForm notNil]) ifTrue:[ |
|
1023 | 2880 |
|
1144 | 2881 |
"/ mhmh - if I was dithered the last time (not enough colors then) |
2882 |
"/ try again - maybe some colors were reclaimed in the meanwhile |
|
2883 |
||
1233 | 2884 |
deviceFixColors := aDevice fixColors. |
2885 |
||
2886 |
(deviceFixColors isNil |
|
2887 |
and:[RetryAllocation]) ifTrue:[ |
|
2888 |
" |
|
2889 |
but there is no chance on b&w displays - so don't try |
|
2890 |
" |
|
1144 | 2891 |
aDevice depth > 2 ifTrue:[ |
2892 |
id := aDevice colorScaledRed:rV scaledGreen:gV scaledBlue:bV. |
|
2893 |
id notNil ifTrue:[ |
|
2894 |
colorId := id. |
|
2895 |
ditherForm := nil. |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2896 |
"/ Lobby register:self. |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2897 |
device registerColor:self. |
1144 | 2898 |
] |
2899 |
] |
|
2900 |
]. |
|
2901 |
^ self |
|
1023 | 2902 |
]. |
2903 |
||
2904 |
newColor := Color existingColorScaledRed:rV scaledGreen:gV scaledBlue:bV on:aDevice. |
|
2905 |
newColor notNil ifTrue:[^ newColor]. |
|
2906 |
||
2907 |
"/ |
|
2908 |
"/ ok, we are going to dither that color. |
|
2909 |
"/ if its 'almost' grey, make it grey and round it a bit (1%) |
|
2910 |
"/ |
|
2911 |
greyV := (3 * red) + (6 * green) + (1 * blue). |
|
2912 |
greyV := (greyV / 1000.0) rounded * 10. |
|
2913 |
||
2914 |
"/ allow an error of 1% in red & green, 2% in blue |
|
2915 |
||
2916 |
((rV - greyV) abs <= 655 "/ MaxValue // 100 |
|
2917 |
and:[(gV - greyV) abs <= 655 "/ MaxValue // 100 |
|
2918 |
and:[(bV - greyV) abs <= 1310]]) ifTrue:[ "/ MaxValue // 100 * 2 |
|
1144 | 2919 |
rV := gV := bV := greyV. |
1023 | 2920 |
] ifFalse:[ |
1144 | 2921 |
rV := red. gV := green. bV := blue. |
1023 | 2922 |
]. |
2923 |
||
2924 |
aDevice hasColors ifTrue:[ |
|
1144 | 2925 |
deviceFixColors isNil ifTrue:[ |
2926 |
"/ ask that device for the exact color |
|
2927 |
||
2928 |
id := aDevice colorScaledRed:rV scaledGreen:gV scaledBlue:bV. |
|
2929 |
id isNil ifTrue:[ |
|
2930 |
"/ this is a kludge: scavenge to free unused colors |
|
2931 |
"/ and try again ... |
|
2932 |
ObjectMemory scavenge; finalize. |
|
2933 |
id := aDevice colorScaledRed:rV scaledGreen:gV scaledBlue:bV |
|
2934 |
]. |
|
2935 |
||
2936 |
id isNil ifTrue:[ |
|
2937 |
"/ no such color - try color dithers |
|
2938 |
||
2939 |
self ditherRed:rV green:gV blue:bV on:aDevice |
|
2940 |
into:[:c :f | newColor := c. form := f]. |
|
2941 |
newColor notNil ifTrue:[^ newColor]. |
|
2942 |
]. |
|
2943 |
]. |
|
2944 |
||
2945 |
"/ none found ? -> do a hard dither using fixColors |
|
2946 |
||
2947 |
(id isNil and:[form isNil]) ifTrue:[ |
|
2948 |
(deviceFixColors notNil "and:[aDevice == Display]") ifTrue:[ |
|
2949 |
self fixDitherRed:rV green:gV blue:bV on:aDevice |
|
2950 |
into:[:c :f | newColor := c. form := f]. |
|
2951 |
newColor notNil ifTrue:[^ newColor]. |
|
2952 |
] |
|
2953 |
]. |
|
2954 |
||
2955 |
"/ still none found ? -> do a very hard dither using existing colors |
|
2956 |
||
2957 |
(id isNil and:[form isNil]) ifTrue:[ |
|
2958 |
self complexDitherRed:rV green:gV blue:bV on:aDevice |
|
2959 |
into:[:c :f | newColor := c. form := f]. |
|
2960 |
newColor notNil ifTrue:[^ newColor]. |
|
2961 |
]. |
|
1023 | 2962 |
]. |
2963 |
||
2964 |
(id isNil and:[form isNil]) ifTrue:[ |
|
1144 | 2965 |
"still no result - try greying" |
2966 |
||
2967 |
greyV == 0 ifTrue:[ |
|
2968 |
id := aDevice blackpixel |
|
2969 |
] ifFalse:[ |
|
2970 |
greyV == MaxValue ifTrue:[ |
|
2971 |
id := aDevice whitepixel |
|
2972 |
] ifFalse:[ |
|
2973 |
aDevice hasGrayscales ifTrue:[ |
|
2974 |
self ditherGrayFor:(greyV / MaxValue) |
|
2975 |
on:aDevice |
|
2976 |
into:[:c :f | newColor := c. form := f]. |
|
2977 |
newColor notNil ifTrue:[^ newColor]. |
|
2978 |
]. |
|
2979 |
] |
|
2980 |
]. |
|
1023 | 2981 |
]. |
2982 |
||
2983 |
device isNil ifTrue:[ |
|
1144 | 2984 |
"/ receiver was not associated - do it now & return mySelf |
2985 |
||
2986 |
device := aDevice. |
|
2987 |
id isNil ifTrue:[ |
|
2988 |
ditherForm := form |
|
2989 |
]. |
|
2990 |
colorId := id. |
|
2991 |
||
2992 |
"/ have to tell Lobby - otherwise it keeps old info around |
|
2993 |
||
2994 |
id notNil ifTrue:[ |
|
2995 |
deviceVisual ~~ #TrueColor ifTrue:[ |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2996 |
"/ Lobby register:self. |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2997 |
device registerColor:self. |
1144 | 2998 |
] |
2999 |
]. |
|
3000 |
^ self |
|
1023 | 3001 |
]. |
3002 |
||
3003 |
"/ receiver was already associated to another device |
|
3004 |
"/ - need a new color and return it |
|
3005 |
||
3006 |
newColor := (self class basicNew) |
|
1144 | 3007 |
setScaledRed:red |
3008 |
scaledGreen:green |
|
3009 |
scaledBlue:blue |
|
3010 |
device:aDevice. |
|
1023 | 3011 |
id isNil ifTrue:[ |
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3012 |
newColor setDitherForm:form |
1023 | 3013 |
] ifFalse:[ |
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3014 |
newColor setColorId:id. |
1233 | 3015 |
|
3016 |
"/ trueColor device-colors are not registered |
|
1144 | 3017 |
deviceVisual ~~ #TrueColor ifTrue:[ |
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
3018 |
"/ Lobby register:newColor. |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
3019 |
device registerColor:newColor. |
1144 | 3020 |
] |
1023 | 3021 |
]. |
3022 |
^ newColor |
|
3023 |
||
3024 |
"Created: 16.11.1995 / 20:16:42 / cg" |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
3025 |
"Modified: 24.2.1997 / 18:23:39 / cg" |
1023 | 3026 |
! ! |
3027 |
||
3028 |
!Color methodsFor:'inspecting'! |
|
3029 |
||
3030 |
inspectorClass |
|
3031 |
"return the class of an appropriate inspector. |
|
3032 |
ST/X has a specialized ColorInspectorView for that" |
|
3033 |
||
3034 |
^ ColorInspectorView |
|
3035 |
||
3036 |
"Modified: 23.4.1996 / 13:39:50 / cg" |
|
3037 |
! ! |
|
3038 |
||
3039 |
!Color methodsFor:'instance creation'! |
|
3040 |
||
3041 |
asHiliteColor |
|
3042 |
"same as lightened - for ST-80 compatibility" |
|
3043 |
||
3044 |
^ self lightened |
|
3045 |
! |
|
3046 |
||
3047 |
asShadowColor |
|
3048 |
"same as darkened - for ST-80 compatibility" |
|
3049 |
||
3050 |
^ self darkened |
|
3051 |
! |
|
3052 |
||
3053 |
blendWith:aColor |
|
3054 |
"create a new color from equally mixing the receiver |
|
3055 |
and the argument, aColor. |
|
3056 |
Mixing is done by adding components |
|
3057 |
(which is different from mixing colors on paper ..)" |
|
3058 |
||
3059 |
red isNil ifTrue:[ |
|
1326
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3060 |
^ aColor |
1023 | 3061 |
]. |
3062 |
||
3063 |
^ (self class) |
|
1326
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3064 |
scaledRed:(red + aColor scaledRed) // 2 |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3065 |
scaledGreen:(green + aColor scaledGreen) // 2 |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3066 |
scaledBlue:(blue + aColor scaledBlue) // 2 |
1023 | 3067 |
|
3068 |
" |
|
3069 |
(Color red) blendWith:(Color yellow) |
|
3070 |
(Color red) blendWith:(Color blue) |
|
1326
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3071 |
(Color red) blendWith:(Color black) |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3072 |
(Color red) blendWith:(Color white) |
1023 | 3073 |
" |
3074 |
||
1326
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3075 |
"Modified: 10.2.1997 / 22:08:14 / cg" |
1023 | 3076 |
! |
3077 |
||
3078 |
darkened |
|
3079 |
"return a new color, which is slightly darker than the receiver" |
|
3080 |
||
3081 |
^ self blendWith:Black |
|
3082 |
||
3083 |
" |
|
3084 |
(Color red) darkened |
|
3085 |
(Color red) darkened darkened |
|
3086 |
" |
|
3087 |
||
3088 |
"Modified: 11.6.1996 / 18:10:37 / cg" |
|
3089 |
! |
|
3090 |
||
3091 |
lightened |
|
3092 |
"return a new color, which is slightly lighter than the receiver" |
|
3093 |
||
3094 |
^ self blendWith:White |
|
3095 |
||
3096 |
" |
|
3097 |
(Color red) lightened |
|
3098 |
(Color red) lightened lightened |
|
3099 |
" |
|
3100 |
||
3101 |
"Modified: 11.6.1996 / 18:10:49 / cg" |
|
3102 |
! ! |
|
3103 |
||
3104 |
!Color methodsFor:'instance release'! |
|
3105 |
||
3106 |
shallowCopyForFinalization |
|
3107 |
"redefined, since for finalization only device and colorIndex |
|
3108 |
are needed - thus a faster copy is possible here" |
|
3109 |
||
3110 |
|aCopy| |
|
3111 |
||
1234 | 3112 |
aCopy := DeviceColorHandle basicNew. |
1023 | 3113 |
aCopy setDevice:device colorId:colorId. |
3114 |
^ aCopy |
|
3115 |
! ! |
|
3116 |
||
3117 |
!Color methodsFor:'printing & storing'! |
|
3118 |
||
3119 |
printOn:aStream |
|
3120 |
"append a string representing of the receiver |
|
3121 |
to the argument, aStream" |
|
3122 |
||
3123 |
self storeOn:aStream |
|
3124 |
! |
|
3125 |
||
3126 |
storeOn:aStream |
|
3127 |
"append a string representing an expression to reconstruct the receiver |
|
3128 |
to the argument, aStream" |
|
3129 |
||
3130 |
red isNil ifTrue:[ |
|
1348 | 3131 |
colorId notNil ifTrue:[ |
3132 |
aStream nextPutAll:'(Color colorId:'. |
|
3133 |
colorId storeOn:aStream. |
|
3134 |
aStream nextPut:$). |
|
3135 |
^ self |
|
3136 |
] |
|
1023 | 3137 |
]. |
3138 |
(red == green and:[red == blue]) ifTrue:[ |
|
1348 | 3139 |
red == 0 ifTrue:[ |
3140 |
aStream nextPutAll:'(Color black)'. |
|
3141 |
] ifFalse:[ |
|
3142 |
red == MaxValue ifTrue:[ |
|
3143 |
aStream nextPutAll:'(Color white)'. |
|
3144 |
] ifFalse:[ |
|
3145 |
aStream nextPutAll:'(Color grey:'. |
|
3146 |
(self red) storeOn:aStream. |
|
3147 |
aStream nextPut:$). |
|
3148 |
] |
|
3149 |
]. |
|
3150 |
^ self |
|
1023 | 3151 |
]. |
3152 |
aStream nextPutAll:'(Color red:'. |
|
3153 |
(self red) storeOn:aStream. |
|
3154 |
aStream nextPutAll:' green:'. |
|
3155 |
(self green) storeOn:aStream. |
|
3156 |
aStream nextPutAll:' blue:'. |
|
3157 |
(self blue) storeOn:aStream. |
|
3158 |
aStream nextPut:$). |
|
3159 |
! ! |
|
3160 |
||
3161 |
!Color methodsFor:'private'! |
|
3162 |
||
3163 |
complexDitherRed:red green:green blue:blue on:aDevice into:aBlock |
|
3164 |
"get a deep dither form for an rgb value. |
|
3165 |
Use all available colors for error dithering into a form." |
|
3166 |
||
3167 |
|errR errG errB f wantR wantG wantB clr |
|
3168 |
dir "{ Class: SmallInteger }" |
|
3169 |
start "{ Class: SmallInteger }" |
|
3170 |
end "{ Class: SmallInteger }" |
|
3171 |
map| |
|
3172 |
||
3173 |
errR := 0. |
|
3174 |
errG := 0. |
|
3175 |
errB := 0. |
|
3176 |
||
3177 |
"get a form and clear it" |
|
3178 |
f := Form width:4 height:4 depth:(aDevice depth) on:aDevice. |
|
3179 |
map := IdentityDictionary new. |
|
3180 |
||
3181 |
0 to:3 do:[:x | |
|
1348 | 3182 |
x even ifTrue:[ |
3183 |
dir := 1. |
|
3184 |
start := 0. |
|
3185 |
end := 3. |
|
3186 |
] ifFalse:[ |
|
3187 |
dir := -1. |
|
3188 |
start := 3. |
|
3189 |
end := 0. |
|
3190 |
]. |
|
3191 |
start to:end by:dir do:[:y | |
|
3192 |
wantR := red + errR. |
|
3193 |
wantR > MaxValue ifTrue:[ |
|
3194 |
wantR := MaxValue |
|
3195 |
] ifFalse:[ wantR < 0 ifTrue:[ |
|
3196 |
wantR := 0 |
|
3197 |
]]. |
|
3198 |
||
3199 |
wantG := green + errG. |
|
3200 |
wantG > MaxValue ifTrue:[ |
|
3201 |
wantG := MaxValue |
|
3202 |
] ifFalse:[ wantG < 0 ifTrue:[ |
|
3203 |
wantG := 0 |
|
3204 |
]]. |
|
3205 |
||
3206 |
wantB := blue + errB. |
|
3207 |
wantB > MaxValue ifTrue:[ |
|
3208 |
wantB := MaxValue |
|
3209 |
] ifFalse:[ wantB < 0 ifTrue:[ |
|
3210 |
wantB := 0 |
|
3211 |
]]. |
|
3212 |
||
3213 |
"find the nearest color" |
|
1023 | 3214 |
|
3215 |
" " |
|
1348 | 3216 |
clr := Color quickNearestColorScaledRed:wantR scaledGreen:wantG scaledBlue:wantB on:aDevice. |
1023 | 3217 |
" " |
3218 |
" |
|
1348 | 3219 |
clr := Color nearestColorScaledRed:wantR green:wantG blue:wantB on:aDevice. |
1023 | 3220 |
" |
1348 | 3221 |
clr isNil ifTrue:[ |
3222 |
clr := Color scaledRed:wantR scaledGreen:wantG scaledBlue:wantB. |
|
3223 |
clr brightness > 0.5 ifTrue:[ |
|
3224 |
clr := Color white on:aDevice |
|
3225 |
] ifFalse:[ |
|
3226 |
clr := Color black on:aDevice |
|
3227 |
] |
|
1023 | 3228 |
" |
1348 | 3229 |
^ aBlock value:nil value:nil |
1023 | 3230 |
" |
1348 | 3231 |
]. |
3232 |
||
3233 |
f paint:clr. |
|
3234 |
f displayPointX:x y:y. |
|
3235 |
map at:clr colorId + 1 put:clr. |
|
3236 |
||
3237 |
"compute the new error" |
|
3238 |
errR := wantR - clr scaledRed. |
|
3239 |
errG := wantG - clr scaledGreen. |
|
3240 |
errB := wantB - clr scaledBlue. |
|
3241 |
]. |
|
1023 | 3242 |
]. |
3243 |
||
3244 |
f colorMap:map. |
|
3245 |
" |
|
3246 |
'hard dither' printNewline. |
|
3247 |
" |
|
3248 |
^ aBlock value:nil value:f |
|
3249 |
||
3250 |
"Modified: 14.6.1996 / 20:13:39 / cg" |
|
3251 |
! |
|
3252 |
||
3253 |
ditherGrayFor:fraction on:aDevice into:aBlock |
|
3254 |
"get a dither form or colorId for a brightness value. |
|
3255 |
Returns 2 values (either color or ditherForm) through aBlock." |
|
3256 |
||
3257 |
|d nGray grayBelow scaledGrey scaledGray1 scaledGray2 clr1 clr2 newFraction step| |
|
3258 |
||
3259 |
d := aDevice depth. |
|
3260 |
||
3261 |
"/ special code for b&w displays |
|
3262 |
||
3263 |
d == 1 ifTrue:[ |
|
1348 | 3264 |
aDevice blackpixel == 0 ifTrue:[ |
3265 |
clr1 := Black. |
|
3266 |
clr2 := White. |
|
3267 |
newFraction := fraction. |
|
3268 |
] ifFalse:[ |
|
3269 |
clr1 := White. |
|
3270 |
clr2 := Black. |
|
3271 |
newFraction := 1 - fraction |
|
3272 |
] |
|
1023 | 3273 |
] ifFalse:[ |
1348 | 3274 |
"/ special code for 2-plane displays (NeXT) |
3275 |
||
3276 |
d == 2 ifTrue:[ |
|
3277 |
fraction <= 0.01 ifTrue:[ |
|
3278 |
clr1 := Black exactOn:aDevice |
|
3279 |
] ifFalse:[ |
|
3280 |
(fraction between:0.32 and:0.34) ifTrue:[ |
|
3281 |
clr1 := (Color gray:33) exactOn:aDevice |
|
3282 |
] ifFalse:[ |
|
3283 |
(fraction between:0.66 and:0.68) ifTrue:[ |
|
3284 |
clr1 := (Color gray:67) exactOn:aDevice |
|
3285 |
] ifFalse:[ |
|
3286 |
fraction >= 0.99 ifTrue:[ |
|
3287 |
clr1 := White exactOn:aDevice |
|
3288 |
] |
|
3289 |
] |
|
3290 |
] |
|
3291 |
]. |
|
3292 |
clr1 notNil ifTrue:[ |
|
3293 |
^ aBlock value:clr1 value:nil |
|
3294 |
]. |
|
3295 |
||
3296 |
(fraction between:0 and:0.33) ifTrue:[ |
|
3297 |
clr1 := Black. |
|
3298 |
clr2 := Color gray:33. |
|
3299 |
] ifFalse:[ |
|
3300 |
(fraction between:0.34 and:0.66) ifTrue:[ |
|
3301 |
clr1 := Color gray:33. |
|
3302 |
clr2 := Color gray:67. |
|
3303 |
] ifFalse:[ |
|
3304 |
clr1 := Color gray:67. |
|
3305 |
clr2 := White. |
|
3306 |
] |
|
3307 |
]. |
|
3308 |
scaledGray1 := clr1 scaledRed. |
|
3309 |
scaledGray2 := clr2 scaledRed. |
|
3310 |
||
3311 |
scaledGrey := (MaxValue * fraction) rounded. |
|
3312 |
||
3313 |
newFraction := (scaledGrey - scaledGray1) asFloat / (scaledGray2 - scaledGray1). |
|
3314 |
] ifFalse:[ |
|
3315 |
nGray := (1 bitShift:d) - 1. |
|
3316 |
||
3317 |
"/ scale greyValue into grey levels |
|
3318 |
||
3319 |
grayBelow := (fraction * nGray) truncated. |
|
3320 |
||
3321 |
grayBelow < 0 ifTrue:[ |
|
3322 |
^ Color black exactOn:aDevice |
|
3323 |
]. |
|
3324 |
grayBelow >= nGray ifTrue:[ |
|
3325 |
^ Color white exactOn:aDevice |
|
3326 |
]. |
|
3327 |
||
3328 |
scaledGrey := (MaxValue * fraction) rounded. |
|
3329 |
||
3330 |
step := MaxValue // nGray. |
|
3331 |
scaledGray1 := grayBelow * step. |
|
3332 |
scaledGray2 := scaledGray1 + step. |
|
3333 |
||
3334 |
clr1 := Color scaledGray:scaledGray1. |
|
3335 |
clr2 := Color scaledGray:scaledGray2. |
|
3336 |
||
3337 |
"/ scale remainder in between low..high |
|
3338 |
newFraction := (scaledGrey - scaledGray1) asFloat / (scaledGray2 - scaledGray1). |
|
3339 |
||
3340 |
"/ dither between those two colors |
|
3341 |
]. |
|
1023 | 3342 |
]. |
3343 |
clr1 := clr1 exactOn:aDevice. |
|
3344 |
clr2 := clr2 exactOn:aDevice. |
|
3345 |
||
3346 |
^ self monoDitherFor:newFraction |
|
1348 | 3347 |
between:clr1 and:clr2 |
3348 |
on:aDevice into:aBlock |
|
1023 | 3349 |
|
3350 |
" |
|
3351 |
Color basicNew |
|
1348 | 3352 |
ditherGrayFor:0.5 |
3353 |
on:Display |
|
3354 |
into:[:clr :form | clr notNil ifTrue:[clr inspect]. |
|
3355 |
form notNil ifTrue:[(form magnifiedBy:16) inspect].] |
|
1023 | 3356 |
" |
3357 |
" |
|
3358 |
Color basicNew |
|
1348 | 3359 |
ditherGrayFor:0.25 |
3360 |
on:Display |
|
3361 |
into:[:clr :form | clr notNil ifTrue:[clr inspect]. |
|
3362 |
form notNil ifTrue:[(form magnifiedBy:16) inspect].] |
|
1023 | 3363 |
" |
3364 |
||
3365 |
"Modified: 11.6.1996 / 17:08:14 / cg" |
|
3366 |
! |
|
3367 |
||
3368 |
ditherRed:rV green:gV blue:bV on:aDevice into:aBlock |
|
3369 |
"get a dither form or colorId for an rgb value. |
|
3370 |
Returns 2 values (either color or ditherForm) through |
|
3371 |
aBlock. |
|
3372 |
This code is just a minimum of what is really needed, |
|
3373 |
and needs much more work. Currently only some special cases |
|
3374 |
are handled" |
|
3375 |
||
3376 |
|rh rl rs |
|
3377 |
lowL hiL lowValL hiValL lowS hiS lowValS hiValS lowH hiH lowValH hiValH d| |
|
3378 |
||
3379 |
"get hls (since we dither anyway, round them a bit" |
|
3380 |
||
3381 |
Color withHLSFromScaledRed:rV scaledGreen:gV scaledBlue:bV do:[:h :l :s | |
|
1348 | 3382 |
h notNil ifTrue:[ |
3383 |
rh := (h * 3.0) rounded / 3.0. |
|
3384 |
]. |
|
3385 |
rl := (l * 3.0) rounded / 3.0. |
|
3386 |
rs := (s * 3.0) rounded / 3.0. |
|
1023 | 3387 |
]. |
3388 |
||
3389 |
rh isNil ifTrue:[ |
|
1348 | 3390 |
"achromatic, dither between achromatic colors" |
3391 |
||
3392 |
lowL := nil. |
|
3393 |
hiL := nil. |
|
3394 |
||
3395 |
"find the 2 bounding colors" |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
3396 |
aDevice deviceColors do:[:aColor | |
1348 | 3397 |
aColor colorId notNil ifTrue:[ |
1023 | 3398 |
|
1348 | 3399 |
Color withHLSFromRed:aColor red green:aColor green blue:aColor blue do:[:h :l :s | |
3400 |
| cl | |
|
3401 |
||
3402 |
h isNil ifTrue:[ |
|
3403 |
cl := (l * 3.0) rounded / 3.0. |
|
3404 |
||
3405 |
cl > rl ifTrue:[ |
|
3406 |
hiL isNil ifTrue:[ |
|
3407 |
hiL := aColor. |
|
3408 |
hiValL := cl. |
|
3409 |
] ifFalse:[ |
|
3410 |
cl < hiValL ifTrue:[ |
|
3411 |
hiL := aColor. |
|
3412 |
hiValL := cl. |
|
3413 |
] |
|
3414 |
] |
|
3415 |
] ifFalse:[ |
|
3416 |
lowL isNil ifTrue:[ |
|
3417 |
lowL := aColor. |
|
3418 |
lowValL := cl |
|
3419 |
] ifFalse:[ |
|
3420 |
cl > lowValL ifTrue:[ |
|
3421 |
lowL := aColor. |
|
3422 |
lowValL := cl |
|
3423 |
] |
|
3424 |
] |
|
3425 |
] |
|
3426 |
] |
|
3427 |
] |
|
3428 |
] |
|
3429 |
]. |
|
3430 |
||
3431 |
(lowL notNil and:[hiL notNil]) ifTrue:[ |
|
3432 |
^ self monoDitherFor:1.0 / (hiValL - lowValL) * (rl - lowValL) |
|
3433 |
between:lowL |
|
3434 |
and:hiL |
|
3435 |
on:aDevice |
|
3436 |
into:aBlock |
|
3437 |
]. |
|
3438 |
"cannot happen, should always find at least black and white" |
|
3439 |
self error:'cannot happen'. |
|
3440 |
^ aBlock value:nil value:nil |
|
1023 | 3441 |
]. |
3442 |
||
3443 |
"chromatic case" |
|
3444 |
||
3445 |
aDevice hasColors ifFalse:[ |
|
1348 | 3446 |
"no chance, return nil values" |
3447 |
^ aBlock value:nil value:nil |
|
1023 | 3448 |
]. |
3449 |
(Red isNil or:[Green isNil or:[Blue isNil]]) ifTrue:[ |
|
1348 | 3450 |
"if we where not able to get primary colors: no chance" |
3451 |
^ aBlock value:nil value:nil |
|
1023 | 3452 |
]. |
3453 |
||
3454 |
"try to find two bounding colors with same hue and saturation; |
|
3455 |
dither on light between those" |
|
3456 |
||
3457 |
lowL := nil. |
|
3458 |
hiL := nil. |
|
3459 |
lowS := nil. |
|
3460 |
hiS := nil. |
|
3461 |
lowH := nil. |
|
3462 |
hiH := nil. |
|
3463 |
||
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
3464 |
aDevice deviceColors do:[:aColor | |
1348 | 3465 |
aColor colorId notNil ifTrue:[ |
3466 |
Color withHLSFromRed:aColor red green:aColor green blue:aColor blue do:[:h :l :s | |
|
3467 |
| cl ch cs| |
|
3468 |
||
3469 |
h notNil ifTrue:[ |
|
3470 |
ch := (h * 3.0) rounded / 3.0. |
|
3471 |
] ifFalse:[ |
|
3472 |
ch := nil |
|
3473 |
]. |
|
3474 |
cl := (l * 3.0) rounded / 3.0. |
|
3475 |
cs := (s * 3.0) rounded / 3.0. |
|
3476 |
||
3477 |
((ch = rh) and:[cs = rs]) ifTrue:[ |
|
3478 |
"found a color with same saturation and same hue, keep for light" |
|
3479 |
||
3480 |
cl > rl ifTrue:[ |
|
3481 |
hiL isNil ifTrue:[ |
|
3482 |
hiL := aColor. |
|
3483 |
hiValL := cl |
|
3484 |
] ifFalse:[ |
|
3485 |
cl < hiValL ifTrue:[ |
|
3486 |
hiL := aColor. |
|
3487 |
hiValL := cl |
|
3488 |
] |
|
3489 |
]. |
|
3490 |
] ifFalse:[ |
|
3491 |
lowL isNil ifTrue:[ |
|
3492 |
lowL := aColor. |
|
3493 |
lowValL := cl |
|
3494 |
] ifFalse:[ |
|
3495 |
cl > lowValL ifTrue:[ |
|
3496 |
lowL := aColor. |
|
3497 |
lowValL := cl |
|
3498 |
] |
|
3499 |
] |
|
3500 |
] |
|
3501 |
]. |
|
3502 |
||
3503 |
(((ch = rh) or:[ch == nil]) and:[cl = rl]) ifTrue:[ |
|
3504 |
"found a color with same light and same hue, keep for saturation" |
|
3505 |
||
3506 |
cs > rs ifTrue:[ |
|
3507 |
hiS isNil ifTrue:[ |
|
3508 |
hiS := aColor. |
|
3509 |
hiValS := cs |
|
3510 |
] ifFalse:[ |
|
3511 |
cs < hiValS ifTrue:[ |
|
3512 |
hiS := aColor. |
|
3513 |
hiValS := cs |
|
3514 |
] |
|
3515 |
]. |
|
3516 |
] ifFalse:[ |
|
3517 |
lowS isNil ifTrue:[ |
|
3518 |
lowS := aColor. |
|
3519 |
lowValS := cs |
|
3520 |
] ifFalse:[ |
|
3521 |
cs > lowValS ifTrue:[ |
|
3522 |
lowS := aColor. |
|
3523 |
lowValS := cs |
|
3524 |
] |
|
3525 |
] |
|
3526 |
] |
|
3527 |
]. |
|
3528 |
||
3529 |
rh notNil ifTrue:[ |
|
3530 |
cl = rl ifTrue:[ |
|
3531 |
cs = rs ifTrue:[ |
|
3532 |
ch notNil ifTrue:[ |
|
3533 |
d := (ch - rh) abs. |
|
3534 |
d > 300 ifTrue:[ |
|
3535 |
rh > 180 ifTrue:[ |
|
3536 |
ch := ch + 360 |
|
3537 |
] ifFalse:[ |
|
3538 |
ch := ch - 360 |
|
3539 |
]. |
|
3540 |
]. |
|
3541 |
ch > rh ifTrue:[ |
|
3542 |
hiH isNil ifTrue:[ |
|
3543 |
hiH := aColor. |
|
3544 |
hiValH := ch |
|
3545 |
] ifFalse:[ |
|
3546 |
ch < hiValH ifTrue:[ |
|
3547 |
hiH := aColor. |
|
3548 |
hiValH := ch |
|
3549 |
] |
|
3550 |
] |
|
3551 |
] ifFalse:[ |
|
3552 |
lowH isNil ifTrue:[ |
|
3553 |
lowH := aColor. |
|
3554 |
lowValH := ch |
|
3555 |
] ifFalse:[ |
|
3556 |
ch > lowValH ifTrue:[ |
|
3557 |
lowH := aColor. |
|
3558 |
lowValH := ch |
|
3559 |
] |
|
3560 |
] |
|
3561 |
] |
|
3562 |
] |
|
3563 |
] |
|
3564 |
] |
|
3565 |
] |
|
3566 |
] |
|
3567 |
] |
|
1023 | 3568 |
]. |
3569 |
||
3570 |
"found bounds for light ?" |
|
3571 |
||
3572 |
lowL notNil ifTrue:[ |
|
1348 | 3573 |
rl = lowValL ifTrue:[ |
3574 |
^ aBlock value:lowL value:nil |
|
3575 |
]. |
|
3576 |
hiL notNil ifTrue:[ |
|
3577 |
^ self monoDitherFor:1.0 / (hiValL - lowValL) / (rl - lowValL) |
|
3578 |
between:lowL |
|
3579 |
and:hiL |
|
3580 |
on:aDevice |
|
3581 |
into:aBlock |
|
3582 |
]. |
|
3583 |
"found bound for light - dither with white" |
|
3584 |
^ self monoDitherFor:1.0 / (100 - lowValL) / (rl - lowValL) |
|
3585 |
between:lowL |
|
3586 |
and:White |
|
3587 |
on:aDevice |
|
3588 |
into:aBlock |
|
1023 | 3589 |
]. |
3590 |
||
3591 |
"found bound for light - dither with black" |
|
3592 |
hiL notNil ifTrue:[ |
|
1348 | 3593 |
^ self monoDitherFor:1.0 / (hiValL) / (rl) |
3594 |
between:Black |
|
3595 |
and:hiL |
|
3596 |
on:aDevice |
|
3597 |
into:aBlock |
|
1023 | 3598 |
]. |
3599 |
||
3600 |
||
3601 |
"found bounds for saturation?" |
|
3602 |
||
3603 |
(lowS notNil and:[hiS notNil]) ifTrue:[ |
|
3604 |
" |
|
1348 | 3605 |
'saturation dither' printNewline. |
1023 | 3606 |
" |
1348 | 3607 |
^ self monoDitherFor:1.0 / (hiValS - lowValS) / (rs - lowValS) |
3608 |
between:lowS |
|
3609 |
and:hiS |
|
3610 |
on:aDevice |
|
3611 |
into:aBlock |
|
1023 | 3612 |
]. |
3613 |
||
3614 |
"found bounds for hue ?" |
|
3615 |
||
3616 |
(lowH notNil and:[hiH notNil]) ifTrue:[ |
|
3617 |
" |
|
1348 | 3618 |
'hue dither' printNewline. |
1023 | 3619 |
" |
1348 | 3620 |
hiValH < lowValH ifTrue:[ |
3621 |
hiValH := hiValH + 360 |
|
3622 |
]. |
|
3623 |
||
3624 |
d := hiValH - lowValH. |
|
3625 |
||
3626 |
^ self monoDitherFor:1.0 / (d / (rh - lowValH)) |
|
3627 |
between:lowH |
|
3628 |
and:hiH |
|
3629 |
on:aDevice |
|
3630 |
into:aBlock |
|
1023 | 3631 |
]. |
3632 |
||
3633 |
^ aBlock value:nil value:nil |
|
3634 |
||
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
3635 |
"Modified: 24.2.1997 / 18:22:45 / cg" |
1023 | 3636 |
! |
3637 |
||
3638 |
fixDitherRed:redVal green:greenVal blue:blueVal on:aDevice into:aBlock |
|
3639 |
"get a dither form for an rgb value. |
|
3640 |
Returns 2 values (either color or ditherForm) through aBlock. |
|
3641 |
This code uses the table of preallocated fix-colors to find |
|
3642 |
dither colors." |
|
3643 |
||
3644 |
| |
|
3645 |
nR "{ Class: SmallInteger }" |
|
3646 |
nG "{ Class: SmallInteger }" |
|
3647 |
nB "{ Class: SmallInteger }" |
|
3648 |
hR "{ Class: SmallInteger }" |
|
3649 |
hG "{ Class: SmallInteger }" |
|
3650 |
hB "{ Class: SmallInteger }" |
|
3651 |
eR eG eB |
|
3652 |
rI "{ Class: SmallInteger }" |
|
3653 |
gI "{ Class: SmallInteger }" |
|
3654 |
bI "{ Class: SmallInteger }" |
|
3655 |
idx "{ Class: SmallInteger }" |
|
3656 |
f clr |
|
3657 |
r "{ Class: SmallInteger }" |
|
3658 |
g "{ Class: SmallInteger }" |
|
3659 |
b "{ Class: SmallInteger }" |
|
3660 |
x1 "{ Class: SmallInteger }" |
|
3661 |
x2 "{ Class: SmallInteger }" |
|
3662 |
step "{ Class: SmallInteger }" |
|
3663 |
lastIdx mx |
|
3664 |
dS "{ Class: SmallInteger }" |
|
3665 |
cube| |
|
3666 |
||
3667 |
(cube := aDevice fixColors) notNil ifTrue:[ |
|
1348 | 3668 |
dS := 4. |
3669 |
||
3670 |
f := Form width:dS height:dS depth:(aDevice depth) on:aDevice. |
|
3671 |
f initGC. |
|
3672 |
||
3673 |
mx := MaxValue asFloat. |
|
3674 |
||
3675 |
nR := aDevice numFixRed. |
|
3676 |
nG := aDevice numFixGreen. |
|
3677 |
nB := aDevice numFixBlue. |
|
3678 |
||
3679 |
hR := nR // 2. |
|
3680 |
hG := nG // 2. |
|
3681 |
hB := nB // 2. |
|
3682 |
||
3683 |
eR := eG := eB := 0. |
|
3684 |
r := redVal. |
|
3685 |
g := greenVal. |
|
3686 |
b := blueVal. |
|
3687 |
||
3688 |
step := -1. |
|
3689 |
||
3690 |
0 to:dS-1 do:[:y | |
|
3691 |
step == -1 ifTrue:[ |
|
3692 |
x1 := 0. x2 := dS-1. step := 1. |
|
3693 |
] ifFalse:[ |
|
3694 |
x1 := dS-1. x2 := 0. step := -1. |
|
3695 |
]. |
|
3696 |
||
3697 |
x1 to:x2 by:step do:[:x | |
|
3698 |
"/ the nearest along the grid |
|
3699 |
||
3700 |
r := redVal + eR. |
|
3701 |
r > MaxValue ifTrue:[r := MaxValue] |
|
3702 |
ifFalse:[r < 0 ifTrue:[r := 0]]. |
|
3703 |
g := greenVal + eG. |
|
3704 |
g > MaxValue ifTrue:[g := MaxValue] |
|
3705 |
ifFalse:[g < 0 ifTrue:[g := 0]]. |
|
3706 |
||
3707 |
b := blueVal + eB. |
|
3708 |
b > MaxValue ifTrue:[b := MaxValue] |
|
3709 |
ifFalse:[b < 0 ifTrue:[b := 0]]. |
|
3710 |
||
3711 |
rI := (r * (nR-1) + hR / mx) rounded. |
|
3712 |
gI := (g * (nG-1) + hG / mx) rounded . |
|
3713 |
bI := (b * (nB-1) + hB / mx) rounded . |
|
3714 |
||
3715 |
idx := (((rI * nG) + gI) * nB + bI) + 1. |
|
3716 |
clr := (cube at:idx) exactOn:aDevice. |
|
3717 |
lastIdx isNil ifTrue:[lastIdx := idx] |
|
3718 |
ifFalse:[lastIdx ~~ idx ifTrue:[lastIdx := -1]]. |
|
3719 |
||
3720 |
f foreground:clr. |
|
3721 |
f displayPointX:x y:y. |
|
3722 |
||
3723 |
eR := r - clr scaledRed. |
|
3724 |
eG := g - clr scaledGreen. |
|
3725 |
eB := b - clr scaledBlue. |
|
3726 |
]. |
|
3727 |
]. |
|
3728 |
f releaseGC. |
|
3729 |
||
3730 |
lastIdx ~~ -1 ifTrue:[ |
|
3731 |
^ aBlock value:clr value:nil |
|
3732 |
]. |
|
3733 |
^ aBlock value:nil value:f |
|
1023 | 3734 |
|
3735 |
]. |
|
3736 |
||
3737 |
^ aBlock value:nil value:nil |
|
3738 |
||
3739 |
"Modified: 11.7.1996 / 18:30:28 / cg" |
|
3740 |
! |
|
3741 |
||
3742 |
monoDitherFor:fraction between:color1 and:color2 on:aDevice into:aBlock |
|
3743 |
"get a dither form or colorId for dithering between 2 colors. |
|
3744 |
Returns 2 values (either color or ditherForm) through aBlock." |
|
3745 |
||
3746 |
|form c1 c2 |
|
3747 |
index "{ Class:SmallInteger }"| |
|
3748 |
||
3749 |
"/ |
|
3750 |
"/ having forms with: [1 .. 63] of 64 pixels (see Form), |
|
3751 |
"/ we get dithers for: 1/64, 2/64, ... 63/64 |
|
3752 |
"/ |
|
3753 |
||
3754 |
index := (fraction * 64) rounded. |
|
3755 |
||
3756 |
c1 := color1 exactOn:aDevice. |
|
3757 |
index < 1 ifTrue:[ |
|
1348 | 3758 |
^ aBlock value:c1 value:nil |
1023 | 3759 |
]. |
3760 |
||
3761 |
c2 := color2 exactOn:aDevice. |
|
3762 |
index >= 64 ifTrue:[ |
|
1348 | 3763 |
^ aBlock value:c2 value:nil |
1023 | 3764 |
]. |
3765 |
||
3766 |
form := Form width:8 height:8 fromArray:(DitherBits at:index) on:aDevice. |
|
3767 |
form colorMap:(Array with:c1 with:c2). |
|
3768 |
^ aBlock value:nil value:form |
|
3769 |
||
3770 |
" |
|
3771 |
Color basicNew |
|
1348 | 3772 |
monoDitherFor:(MaxValue // 2) |
3773 |
between:Color black |
|
3774 |
and:Color white |
|
3775 |
on:Display |
|
3776 |
into:[:clr :dither | clr inspect. dither inspect] |
|
1023 | 3777 |
" |
3778 |
||
3779 |
"Modified: 11.6.1996 / 16:55:37 / cg" |
|
3780 |
! |
|
3781 |
||
3782 |
restored |
|
3783 |
"private: color has been restored (either from snapin or binary store); |
|
3784 |
flush device stuff or reallocate a cell." |
|
3785 |
||
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3786 |
ditherForm := replacementColor := nil. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3787 |
|
1023 | 3788 |
red notNil ifTrue:[ |
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3789 |
device := nil. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3790 |
colorId := nil |
1023 | 3791 |
] ifFalse:[ |
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3792 |
"a variable color has been restored" |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3793 |
(colorId notNil and:[writable == true and:[device notNil]]) ifTrue:[ |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3794 |
colorId := device colorCell. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3795 |
device setColor:colorId scaledRed:red scaledGreen:green scaledBlue:blue |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3796 |
] |
1023 | 3797 |
] |
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3798 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3799 |
"Modified: 17.1.1997 / 00:04:14 / cg" |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3800 |
! |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3801 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3802 |
setColorId:anId |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3803 |
"private: set the deviceId" |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3804 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3805 |
colorId := anId |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3806 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3807 |
"Created: 17.1.1997 / 00:05:41 / cg" |
1023 | 3808 |
! |
3809 |
||
3810 |
setDevice:aDevice colorId:aNumber |
|
3811 |
"private:set device and colorId" |
|
3812 |
||
3813 |
device := aDevice. |
|
3814 |
colorId := aNumber |
|
3815 |
! |
|
3816 |
||
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3817 |
setDitherForm:aForm |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3818 |
"private: set the ditherForm" |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3819 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3820 |
ditherForm := aForm |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3821 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3822 |
"Created: 17.1.1997 / 00:04:57 / cg" |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3823 |
! |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
3824 |
|
1023 | 3825 |
setScaledRed:r scaledGreen:g scaledBlue:b device:aDevice |
3826 |
"private: set the components" |
|
3827 |
||
3828 |
red notNil ifTrue:[ |
|
1233 | 3829 |
"oops cannot change (you want to make red be green - or what)" |
3830 |
||
3831 |
self error:'Colors cannot change their components'. |
|
3832 |
^ self |
|
1023 | 3833 |
]. |
3834 |
red := r. |
|
3835 |
green := g. |
|
3836 |
blue := b. |
|
3837 |
device := aDevice |
|
1233 | 3838 |
|
3839 |
"Modified: 16.1.1997 / 22:39:26 / cg" |
|
1023 | 3840 |
! |
3841 |
||
3842 |
setWritable:aBoolean |
|
3843 |
"set/clear the writable attribute. Highly private" |
|
3844 |
||
3845 |
writable := aBoolean |
|
3846 |
||
3847 |
"Modified: 23.4.1996 / 13:40:18 / cg" |
|
3848 |
! ! |
|
3849 |
||
3850 |
!Color methodsFor:'queries'! |
|
3851 |
||
3852 |
averageColor |
|
3853 |
"return the average color - thats myself. |
|
3854 |
This method has been added for compatibility with the image |
|
3855 |
protocol." |
|
3856 |
||
3857 |
^ self |
|
3858 |
! |
|
3859 |
||
3860 |
averageColorIn:aRectangle |
|
3861 |
"return the average color - thats myself. |
|
3862 |
This method has been added for compatibility with the image |
|
3863 |
protocol." |
|
3864 |
||
3865 |
^ self |
|
3866 |
! |
|
3867 |
||
3868 |
brightness |
|
3869 |
"ST80 compatibility: return the grey intensity in [0..1]" |
|
3870 |
||
3871 |
^ ((3 * red) + (6 * green) + (blue)) / 10.0 / MaxValue |
|
3872 |
||
3873 |
"Modified: 7.6.1996 / 19:42:21 / cg" |
|
3874 |
! |
|
3875 |
||
3876 |
deltaFrom:aColor |
|
3877 |
"return the distance of the receiver from some color specified |
|
3878 |
by r/g/b values" |
|
3879 |
||
3880 |
^ aColor deltaFromRed:self red green:self green blue:self blue |
|
3881 |
||
3882 |
"Created: 14.6.1996 / 20:07:22 / cg" |
|
3883 |
"Modified: 14.6.1996 / 20:49:32 / cg" |
|
3884 |
! |
|
3885 |
||
3886 |
deltaFromRed:r green:g blue:b |
|
3887 |
"return the distance of the receiver from some color specified |
|
3888 |
by r/g/b values" |
|
3889 |
||
3890 |
" |
|
3891 |
Q: how should component errors be weighted ? |
|
3892 |
" |
|
3893 |
^ (self red - r) abs |
|
3894 |
+ (self green - g) abs |
|
3895 |
+ (self blue - b) abs. |
|
3896 |
||
3897 |
"Created: 14.6.1996 / 20:03:58 / cg" |
|
3898 |
"Modified: 14.6.1996 / 20:20:24 / cg" |
|
3899 |
! |
|
3900 |
||
3901 |
deltaFromScaledRed:r scaledGreen:g scaledBlue:b |
|
3902 |
"return the distance of the receiver from some color specified |
|
3903 |
by r/g/b values" |
|
3904 |
||
3905 |
" |
|
3906 |
Q: how should component errors be weighted ? |
|
3907 |
" |
|
3908 |
^ (red - r) abs |
|
3909 |
+ (green - g) abs |
|
3910 |
+ (blue - b) abs. |
|
3911 |
||
3912 |
"Created: 11.6.1996 / 18:01:12 / cg" |
|
3913 |
"Modified: 14.6.1996 / 20:36:14 / cg" |
|
3914 |
! |
|
3915 |
||
3916 |
errorFrom:aColor |
|
3917 |
"return some value which can be used to compare colors. |
|
3918 |
The following simply returns the vector distance of the r/g/b vectors. |
|
3919 |
This may not be a very good idea; probably, we should honor the |
|
3920 |
fact that the hue difference should have more weight than saturation and/or light" |
|
3921 |
||
3922 |
^ (red - aColor scaledRed) squared |
|
3923 |
+ (green - aColor scaledGreen) squared |
|
3924 |
+ (blue - aColor scaledBlue) squared. |
|
3925 |
! |
|
3926 |
||
3927 |
grayIntensity |
|
3928 |
"return the grey intensity in percent [0..100] (US version ;-)" |
|
3929 |
||
3930 |
^ ((3 * red) + (6 * green) + (1 * blue)) * 10.0 / MaxValue |
|
3931 |
||
3932 |
"Created: 2.5.1996 / 11:38:21 / cg" |
|
3933 |
! |
|
3934 |
||
3935 |
greyIntensity |
|
3936 |
"return the grey intensity in percent [0..100] (English version ;-)" |
|
3937 |
||
3938 |
^ self grayIntensity |
|
3939 |
||
3940 |
"Modified: 28.5.1996 / 20:45:41 / cg" |
|
3941 |
! |
|
3942 |
||
3943 |
isColor |
|
3944 |
"return true if the receiver is a Color." |
|
3945 |
||
3946 |
^ true |
|
3947 |
! |
|
3948 |
||
3949 |
isDithered |
|
3950 |
"return true, if this is a dithered Color. |
|
3951 |
Only makes sense if the receiver is a device color." |
|
3952 |
||
3953 |
^ ditherForm notNil |
|
3954 |
! |
|
3955 |
||
1326
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3956 |
isGray |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3957 |
"same as isGrayColor - for ST80 compatibility." |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3958 |
|
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3959 |
^ self isGrayColor |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3960 |
|
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3961 |
" |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3962 |
(Color grey:50) isGray |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3963 |
(Color red) isGray |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3964 |
" |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3965 |
|
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3966 |
"Created: 10.2.1997 / 22:10:25 / cg" |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3967 |
! |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
3968 |
|
1023 | 3969 |
isGrayColor |
3970 |
"return true, if this color is a gray one - |
|
3971 |
i.e. red = green = blue" |
|
3972 |
||
3973 |
red ~~ green ifTrue:[^ false]. |
|
3974 |
^ red == blue |
|
3975 |
||
3976 |
" |
|
3977 |
(Color grey:50) isGrayColor |
|
3978 |
(Color red) isGrayColor |
|
3979 |
" |
|
3980 |
||
3981 |
"Created: 2.5.1996 / 11:38:48 / cg" |
|
3982 |
! |
|
3983 |
||
3984 |
isGreyColor |
|
3985 |
"return true, if this color is a grey one (English version ;-) - |
|
3986 |
i.e. red = green = blue" |
|
3987 |
||
3988 |
^ self isGrayColor |
|
3989 |
||
3990 |
"(Color grey:50) isGreyColor" |
|
3991 |
"(Color red) isGreyColor" |
|
3992 |
||
3993 |
"Modified: 28.5.1996 / 20:44:36 / cg" |
|
3994 |
! ! |
|
3995 |
||
1347 | 3996 |
!Color methodsFor:'testing'! |
3997 |
||
3998 |
isColorObject |
|
3999 |
^ true |
|
4000 |
! ! |
|
4001 |
||
1144 | 4002 |
!Color class methodsFor:'documentation'! |
1023 | 4003 |
|
4004 |
version |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
4005 |
^ '$Header: /cvs/stx/stx/libview/Color.st,v 1.88 1997-02-24 17:32:40 cg Exp $' |
1023 | 4006 |
! ! |
4007 |
Color initialize! |