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