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