author | Claus Gittinger <cg@exept.de> |
Mon, 04 May 2020 19:16:06 +0200 | |
changeset 9042 | 28837096674b |
parent 8993 | 424fd9705378 |
permissions | -rw-r--r-- |
8792 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1023 | 3 |
" |
4 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
6353 | 5 |
All Rights Reserved |
1023 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
3213 | 14 |
"{ Package: 'stx:libview' }" |
15 |
||
6785 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1023 | 18 |
Object subclass:#Color |
3757 | 19 |
instanceVariableNames:'red green blue device colorId ditherForm replacementColor |
20 |
writable' |
|
8123 | 21 |
classVariableNames:'Black Blue Cells ColorAllocationFailSignal ColorErrorSignal |
22 |
DarkGrey DitherBits Green Grey InvalidColorNameSignal LightGrey |
|
23 |
MaxValue Orange Pseudo0 Pseudo1 PseudoAll Red RetryAllocation |
|
8660 | 24 |
StandardColorValues Transparent White Yellow DarkGreen DarkRed' |
3757 | 25 |
poolDictionaries:'' |
26 |
category:'Graphics-Support' |
|
1023 | 27 |
! |
28 |
||
1907
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
29 |
Object subclass:#DeviceColorHandle |
3757 | 30 |
instanceVariableNames:'device colorId' |
31 |
classVariableNames:'' |
|
32 |
poolDictionaries:'' |
|
33 |
privateIn:Color |
|
1907
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
34 |
! |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
35 |
|
1144 | 36 |
!Color class methodsFor:'documentation'! |
1023 | 37 |
|
38 |
copyright |
|
39 |
" |
|
40 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
6353 | 41 |
All Rights Reserved |
1023 | 42 |
|
43 |
This software is furnished under a license and may be used |
|
44 |
only in accordance with the terms of that license and with the |
|
45 |
inclusion of the above copyright notice. This software may not |
|
46 |
be provided or otherwise made available to, or used by, any |
|
47 |
other person. No title to or ownership of the software is |
|
48 |
hereby transferred. |
|
49 |
" |
|
50 |
! |
|
51 |
||
52 |
documentation |
|
53 |
" |
|
7782 | 54 |
Color represents colors in a device independent manner. |
55 |
The main info I keep in mySelf are the red, green and blue components scaled into 0 .. MaxValue. |
|
56 |
||
57 |
A device specific color can be acquired by sending a color the 'onDevice:aDevice' message, |
|
58 |
which will return a color with the same r/g/b values as the receiver but with a specific |
|
59 |
colorID for that device (which may or may not imply a colormap slot allocation on that device). |
|
60 |
A device-specific color index (i.e. palette-ID) is then found in the newly allocated color's colorID slot. |
|
61 |
||
62 |
Most of the device dependent coding was to support limited graphics devices (non truecolor, eg. palette) |
|
6553 | 63 |
in a transparent way. This was required at that time (late 80's, early 90's), |
7782 | 64 |
but is now almost obsolete, as these days, virtually any graphic systems supports true colors. |
6553 | 65 |
It is arguably, if that stuff should remain here, or if we should simply give up support |
7782 | 66 |
for old VGA-like displays |
67 |
(actually, there are still such limited displays around, for example in the embedded area. |
|
68 |
So we will leave that support in for another few years ;-) ). |
|
69 |
||
70 |
On such limited devices, colors can be pure or dithered, depending on the capabilities of the device. |
|
1023 | 71 |
For plain colors, the colorId-instvar is a handle (usually lookup-table entry) for that |
72 |
device. For dithered colors, the colorId is nil and ditherForm specifies the form |
|
73 |
used to dither that color. The ditherForm can be either a depth-1 bitmap or a pixmap |
|
74 |
with the devices depth. The plain colors needed by the ditherForm are found in its |
|
75 |
colormap (as usual for bitmaps). |
|
76 |
||
77 |
The default algorithm for color allocation is to ask the display for colors as |
|
78 |
new colors are created. When running out of colors, dithered colors will be used, |
|
7620 | 79 |
using existing nearest colors and a dither pattern to approximate the color. |
1023 | 80 |
There could be situations, where no good colors are available for the dither, leading |
81 |
to ugly looking dither colors. |
|
82 |
This can be avoided by preallocating a set of colors over the complete range, which |
|
83 |
makes certain that appropriate colors are later available for the dither process. |
|
84 |
To do so, add a statement like: 'Color getColors5x5x5' to the startup.rc file. |
|
85 |
(beside 5x5x5, there are various other size combinations available). |
|
86 |
However, doing so may make things worse when displaying bitmap images, since this |
|
87 |
preallocated table may steal colors from the image ... |
|
88 |
||
89 |
[Instance variables:] |
|
90 |
||
91 |
red <Integer> the red component (0..MaxValue) |
|
92 |
green <Integer> the green component (0..MaxValue) |
|
93 |
blue <Integer> the blue component (0..MaxValue) |
|
94 |
||
95 |
device <Device> the device I am on, or nil |
|
96 |
colorId <Object> some device dependent identifier (or nil if dithered) |
|
97 |
ditherForm <Form> the Form to dither this color (if non-nil) |
|
98 |
writable <Boolean> true if this is for a writable color cell |
|
99 |
||
100 |
[Class variables:] |
|
101 |
||
102 |
MaxValue <Integer> r/g/b components are scaled relative to this maximum |
|
103 |
||
104 |
Lobby <Registry> all colors in use - keeps track of already allocated |
|
6553 | 105 |
colors for reuse and finalization. |
7650 | 106 |
(don't use it: this will be moved to the device) |
1229 | 107 |
|
1023 | 108 |
Cells <Registry> keeps track of allocated writable color cells |
7650 | 109 |
(don't use it: this will be moved to the device) |
1023 | 110 |
|
111 |
FixColors <Array> preallocated colors for dithering on Display |
|
112 |
NumRedFix <Integer> number of distinct red values in FixColors |
|
113 |
NumGreenFix <Integer> number of distinct green values in FixColors |
|
114 |
NumBlueFix <Integer> number of distinct blue values in FixColors |
|
6353 | 115 |
|
1023 | 116 |
Black <Color> for fast return of black |
117 |
White <Color> for fast return of white |
|
118 |
Grey <Color> for fast return of grey |
|
119 |
LightGrey <Color> for fast return of lightGrey |
|
120 |
DarkGrey <Color> for fast return of darkGrey |
|
121 |
||
122 |
Pseudo0 <Color> a color with 0 as handle (for forms and bitblit) |
|
123 |
Pseudo1 <Color> a color with 1 as handle (for forms) |
|
124 |
PseudoAll <Color> a color with allPlanes as handle (for bitblit) |
|
125 |
||
126 |
Red <Color> red, needed for dithering |
|
127 |
Green <Color> green, for dithering |
|
128 |
Blue <Color> blue, for dithering |
|
129 |
||
130 |
DitherColors <Collection> some preallocated colors for dithering |
|
6553 | 131 |
(kept, so they are available when needed) |
1023 | 132 |
|
133 |
RetryAllocation <Boolean> this flag controls how a request for a |
|
6553 | 134 |
color should be handled which failed previously. |
135 |
I.e. a color is asked for, which was dithered |
|
136 |
the last time. Since it could happen, that in |
|
137 |
the meantime more colors became free, the request |
|
138 |
might succeed this time - however, your screen may |
|
139 |
look a bit funny, due to having both dithered and |
|
140 |
undithered versions around. |
|
141 |
The default is true, which means: do retry |
|
1023 | 142 |
|
143 |
compatibility issues: |
|
144 |
||
6553 | 145 |
ST-80 seems to represent colors internally with scaled smallInteger |
146 |
components (this can be guessed from uses of |
|
147 |
scaledRed:scaledGreen:scaledBlue:). The main instance creation method is |
|
148 |
via 'ColorValue red:green:blue:', passing components in 0..1. |
|
8277 | 149 |
In ST/X, rgb components are typically represented as percent. |
6553 | 150 |
For more compatibility (when subclassing color), these internals may |
151 |
change in the near future. For migration, a compatibility subclass |
|
152 |
called ColorValue is provided. |
|
153 |
After the change, Color will be renamed to ColorValue and Color |
|
154 |
be made a subclass of ColorValue (offering the 0..100 interface for |
|
155 |
backward compatibility). |
|
1023 | 156 |
|
157 |
[see also:] |
|
6553 | 158 |
DeviceWorkstation |
159 |
GraphicsContext DeviceDrawable Form Image Colormap |
|
160 |
Font Cursor |
|
1023 | 161 |
|
162 |
[author:] |
|
6553 | 163 |
Claus Gittinger |
1023 | 164 |
" |
165 |
! ! |
|
166 |
||
1144 | 167 |
!Color class methodsFor:'initialization'! |
1023 | 168 |
|
169 |
initialize |
|
170 |
"setup tracker of known colors and initialize classvars with |
|
171 |
heavily used colors" |
|
172 |
||
2379
b2a844aabc93
made my signals children of a common colorErrorSignal
Claus Gittinger <cg@exept.de>
parents:
2375
diff
changeset
|
173 |
ColorErrorSignal isNil ifTrue:[ |
6353 | 174 |
ColorErrorSignal := Error newSignalMayProceed:true. |
175 |
ColorErrorSignal nameClass:self message:#colorErrorSignal. |
|
176 |
ColorErrorSignal notifierString:'color error'. |
|
177 |
||
178 |
ColorAllocationFailSignal := ColorErrorSignal newSignalMayProceed:true. |
|
179 |
ColorAllocationFailSignal nameClass:self message:#colorAllocationFailSignal. |
|
180 |
ColorAllocationFailSignal notifierString:'color allocation failed'. |
|
181 |
||
182 |
InvalidColorNameSignal := ColorErrorSignal newSignalMayProceed:true. |
|
183 |
InvalidColorNameSignal nameClass:self message:#invalidColorNameSignal. |
|
184 |
InvalidColorNameSignal notifierString:'invalid color name'. |
|
185 |
||
186 |
MaxValue := 16rFFFF. |
|
187 |
||
188 |
"want to be informed when returning from snapshot" |
|
189 |
ObjectMemory addDependent:self. |
|
190 |
||
191 |
RetryAllocation := true. |
|
192 |
||
193 |
DitherBits := self ditherBits. |
|
194 |
self initializeStandardColorNames. |
|
1023 | 195 |
]. |
196 |
||
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
197 |
" |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
198 |
Color initialize |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
199 |
" |
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
200 |
|
2379
b2a844aabc93
made my signals children of a common colorErrorSignal
Claus Gittinger <cg@exept.de>
parents:
2375
diff
changeset
|
201 |
"Modified: / 30.9.1998 / 21:56:50 / cg" |
1428 | 202 |
! |
203 |
||
204 |
initializeStandardColorNames |
|
1929 | 205 |
"{ Pragma: +optSpace }" |
206 |
||
1428 | 207 |
"setup standard colors" |
208 |
||
209 |
StandardColorValues := Dictionary new. |
|
210 |
#( |
|
6353 | 211 |
'red' (16rFFFF 16r0000 16r0000) |
212 |
'green' (16r0000 16rFFFF 16r0000) |
|
213 |
'blue' (16r0000 16r0000 16rFFFF) |
|
214 |
'yellow' (16rFFFF 16rFFFF 16r0000) |
|
215 |
'magenta' (16rFFFF 16r0000 16rFFFF) |
|
216 |
'cyan' (16r0000 16rFFFF 16rFFFF) |
|
217 |
'white' (16rFFFF 16rFFFF 16rFFFF) |
|
218 |
'black' (16r0000 16r0000 16r0000) |
|
219 |
'olive' (16r7FFF 16r7FFF 16r0000) |
|
220 |
'teal' (16r0000 16r7FFF 16r7FFF) |
|
221 |
'silver' (16r6666 16r6666 16r6666) |
|
222 |
'lime' (16r3333 16rFFFF 16r0000) |
|
223 |
'fuchsia' (16r9999 16r07ae 16rFFFF) |
|
224 |
'aqua' (16r199a 16rFFFF 16rFFFF) |
|
1428 | 225 |
) pairWiseDo:[:name :value | |
6353 | 226 |
StandardColorValues at:name put:value |
1428 | 227 |
]. |
228 |
||
229 |
" |
|
230 |
Color initializeStandardColorNames |
|
231 |
" |
|
232 |
||
233 |
"Modified: 6.3.1997 / 02:28:58 / cg" |
|
1023 | 234 |
! |
235 |
||
236 |
update:something with:aParameter from:changedObject |
|
237 |
"handle image restarts and flush any device resource handles" |
|
238 |
||
239 |
(something == #returnFromSnapshot) ifTrue:[ |
|
6353 | 240 |
Display notNil ifTrue:[ |
241 |
Display visualType == #TrueColor ifTrue:[ |
|
242 |
Display releaseFixColors |
|
243 |
] ifFalse:[ |
|
244 |
Display fixColors notNil ifTrue:[ |
|
245 |
ColorAllocationFailSignal handle:[:ex | |
|
246 |
ex return |
|
247 |
] do:[ |
|
248 |
|nR nG nB| |
|
249 |
||
250 |
nR := Display numFixRed. |
|
251 |
nG := Display numFixGreen. |
|
252 |
nB := Display numFixBlue. |
|
253 |
Display releaseFixColors. |
|
254 |
self getColorsRed:nR |
|
255 |
green:nG |
|
256 |
blue:nB |
|
257 |
on:Display |
|
258 |
] |
|
259 |
] |
|
260 |
] |
|
261 |
] |
|
1023 | 262 |
] |
263 |
||
264 |
"Created: 15.6.1996 / 15:14:03 / cg" |
|
1370
37dfdffdd4b6
getPrimaryColors now invoked from device
Claus Gittinger <cg@exept.de>
parents:
1368
diff
changeset
|
265 |
"Modified: 24.2.1997 / 22:08:05 / cg" |
1023 | 266 |
! ! |
267 |
||
1144 | 268 |
!Color class methodsFor:'instance creation'! |
1023 | 269 |
|
270 |
allColor |
|
271 |
"return a special color which, when used for bit-blitting will |
|
272 |
behave like a all-1-color (i.e. have a device-pixel value of all-1s)" |
|
273 |
||
274 |
PseudoAll isNil ifTrue:[ |
|
6353 | 275 |
PseudoAll := self basicNew setColorId:-1 |
1023 | 276 |
]. |
277 |
^ PseudoAll |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
278 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
279 |
"Modified: 17.1.1997 / 00:05:36 / cg" |
1023 | 280 |
! |
281 |
||
2455 | 282 |
bgrValue:bgr |
3005 | 283 |
"return a color from a 24bit BGR value (intentionally not RGB); |
2455 | 284 |
The value is composed of b<<16 + g<<8 + r. |
285 |
(this byte-order is sometimes encountered with windows systems (progs)" |
|
286 |
||
287 |
|r g b| |
|
288 |
||
289 |
b := (bgr bitShift:-16) bitAnd:16rFF. |
|
290 |
g := (bgr bitShift:-8) bitAnd:16rFF. |
|
291 |
r := (bgr) bitAnd:16rFF. |
|
292 |
^ self redByte:r greenByte:g blueByte:b |
|
293 |
||
294 |
! |
|
295 |
||
1985 | 296 |
blue: blue |
297 |
"return a color from blue value; |
|
298 |
the argument green is interpreted as percent (0..100)" |
|
299 |
||
6353 | 300 |
^ here |
301 |
scaledRed:0 scaledGreen:0 scaledBlue:(blue * MaxValue // 100) |
|
3005 | 302 |
|
303 |
" |
|
304 |
(Color blue:50) inspect |
|
305 |
" |
|
306 |
||
1985 | 307 |
! |
308 |
||
1023 | 309 |
brightness:brightness |
310 |
"create a gray color with given brightness (0..1). |
|
311 |
ST-80 compatibility." |
|
312 |
||
3264 | 313 |
^ self scaledGray:(brightness * MaxValue) rounded |
1023 | 314 |
! |
315 |
||
316 |
colorId:id |
|
317 |
"return a color for a specific colorid without associating it to a |
|
318 |
specific device. Use this only for bitmaps which want 0- or 1-color, |
|
319 |
or for bitblits if you want to manipulate a specific colorplane." |
|
320 |
||
321 |
id == 0 ifTrue:[ |
|
6353 | 322 |
^ self noColor |
1023 | 323 |
]. |
324 |
id == 1 ifTrue:[ |
|
6353 | 325 |
Pseudo1 isNil ifTrue:[ |
326 |
Pseudo1 := self basicNew setColorId:1 |
|
327 |
]. |
|
328 |
^ Pseudo1 |
|
1023 | 329 |
]. |
330 |
id == -1 ifTrue:[ |
|
6353 | 331 |
^ self allColor |
1023 | 332 |
]. |
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
333 |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
334 |
^ self basicNew setColorId:id |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
335 |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
336 |
"Modified: 24.2.1997 / 18:16:30 / cg" |
1023 | 337 |
! |
338 |
||
339 |
cyan:c magenta:m yellow:y |
|
340 |
"return a color from cyan, magenta and yellow values. |
|
341 |
all values are given in percent (0..100)" |
|
342 |
||
343 |
^ self |
|
6353 | 344 |
redPercent:(100 - c) |
345 |
greenPercent:(100 - m) |
|
346 |
bluePercent:(100 - y) |
|
347 |
||
348 |
" |
|
349 |
Color cyan:100 magenta:0 yellow:0 - cyan |
|
350 |
Color cyan:100 magenta:100 yellow:0 - blue |
|
351 |
Color cyan:100 magenta:0 yellow:100 - green |
|
352 |
Color cyan:100 magenta:100 yellow:100 - black |
|
1023 | 353 |
" |
354 |
||
355 |
"Modified: 11.6.1996 / 18:29:15 / cg" |
|
356 |
! |
|
357 |
||
2888
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
358 |
cyan:c magenta:m yellow:y black:k |
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
359 |
"return a color from cyan, magenta, yellow and black values. |
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
360 |
all values are given in percent (0..100). |
2889 | 361 |
The value returned here is questionable. |
362 |
TODO: we loose information about one component here, |
|
363 |
and should actually return an instance of CMYK color, which keeps this |
|
364 |
information internally for later use (when saving)." |
|
2888
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
365 |
|
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
366 |
|scale r g b| |
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
367 |
|
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
368 |
"/ mhmh - how should we scale black into the components ? |
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
369 |
|
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
370 |
r := (100 - c). |
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
371 |
g := (100 - m). |
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
372 |
b := (100 - y). |
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
373 |
k ~~ 0 ifTrue:[ |
6353 | 374 |
"/ more black - darker |
375 |
scale := (100-k) max:0. |
|
376 |
scale := scale / 100. |
|
377 |
r := r * scale. |
|
378 |
g := g * scale. |
|
379 |
b := b * scale. |
|
2888
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
380 |
]. |
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
381 |
|
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
382 |
^ self redPercent:r greenPercent:g bluePercent:b |
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
383 |
|
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
384 |
" |
6353 | 385 |
Color cyan:100 magenta:0 yellow:0 black:0 - cyan |
386 |
Color cyan:100 magenta:0 yellow:0 black:50 - cyan darkened |
|
387 |
Color cyan:100 magenta:50 yellow:50 black:0 - cyan darkened |
|
388 |
Color cyan:0 magenta:0 yellow:0 black:100 - black |
|
2888
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
389 |
" |
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
390 |
|
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
391 |
"Modified: 11.6.1996 / 18:29:15 / cg" |
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
392 |
! |
ce7e932e7cf6
added cyan:magenta:yellow:black
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
393 |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
394 |
dither:fraction between:color1 and:color2 on:aDevice |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
395 |
"create a dithered Color which dithers between color1 and color2. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
396 |
Fraction must be 0..1, color1 and color2 must be real (i.e. undithered) |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
397 |
colors. |
6353 | 398 |
Useful, if you explicitely want a dithered color |
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
399 |
(for example, to not use up too many colors, or for special effects)" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
400 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
401 |
|newColor form c1 c2| |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
402 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
403 |
"/ both must be true device colors |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
404 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
405 |
c1 := color1 exactOn:aDevice. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
406 |
c2 := color2 exactOn:aDevice. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
407 |
(c1 isNil or:[c2 isNil]) ifTrue:[ |
6353 | 408 |
'Color [warning]: monoDither failed - no real colors given' errorPrintCR. |
409 |
^ nil |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
410 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
411 |
|
6353 | 412 |
self |
413 |
monoDitherFor:fraction |
|
414 |
between:c1 |
|
415 |
and:c2 |
|
416 |
on:aDevice |
|
417 |
into:[:c :f | newColor := c. form := f]. |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
418 |
newColor notNil ifTrue:[^ newColor]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
419 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
420 |
form isNil ifTrue:[ |
6353 | 421 |
"/ cannot happen |
422 |
'Color [warning]: monoDither failed' errorPrintCR. |
|
423 |
^ nil |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
424 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
425 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
426 |
newColor := self basicNew |
6353 | 427 |
setScaledRed:nil |
428 |
scaledGreen:nil |
|
429 |
scaledBlue:nil |
|
430 |
device:aDevice. |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
431 |
newColor setDitherForm:form. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
432 |
newColor setDevice:aDevice colorId:nil. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
433 |
^ newColor |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
434 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
435 |
" |
3005 | 436 |
(Color dither:0.25 between:Color red and:Color yellow on:Display) inspect |
437 |
(Color dither:0.5 between:Color red and:Color yellow on:Display) inspect |
|
438 |
(Color dither:0.75 between:Color red and:Color yellow on:Display) inspect |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
439 |
" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
440 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
441 |
"Created: 3.5.1997 / 10:54:32 / cg" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
442 |
"Modified: 3.5.1997 / 11:10:51 / cg" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
443 |
! |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
444 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
445 |
dithered:fraction between:color1 and:color2 on:aDevice |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
446 |
"create a dithered Color which dithers between color1 and color2. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
447 |
Fraction must be 0..1, color1 and color2 must be real (i.e. undithered) |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
448 |
colors. |
6353 | 449 |
Useful, if you explicitely want a dithered color |
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
450 |
(for example, to not use up too many colors, or for special effects)" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
451 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
452 |
|newColor form c1 c2| |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
453 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
454 |
"/ both must be true device colors |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
455 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
456 |
c1 := color1 exactOn:aDevice. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
457 |
c2 := color2 exactOn:aDevice. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
458 |
(c1 isNil or:[c2 isNil]) ifTrue:[ |
8277 | 459 |
'Color [warning]: monoDither failed - no real colors given' errorPrintCR. |
460 |
^ nil |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
461 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
462 |
|
6353 | 463 |
self |
8277 | 464 |
monoDitherFor:fraction |
465 |
between:c1 |
|
466 |
and:c2 |
|
467 |
on:aDevice |
|
468 |
into:[:c :f | newColor := c. form := f]. |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
469 |
newColor notNil ifTrue:[^ newColor]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
470 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
471 |
form isNil ifTrue:[ |
8277 | 472 |
"/ cannot happen |
473 |
'Color [warning]: monoDither failed' errorPrintCR. |
|
474 |
^ nil |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
475 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
476 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
477 |
newColor := self basicNew |
8277 | 478 |
setScaledRed:nil |
479 |
scaledGreen:nil |
|
480 |
scaledBlue:nil |
|
481 |
device:aDevice. |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
482 |
newColor setDitherForm:form. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
483 |
newColor setDevice:aDevice colorId:nil. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
484 |
^ newColor |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
485 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
486 |
" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
487 |
|c| |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
488 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
489 |
c := Color dithered:0.5 between:Color red and:Color yellow on:Display. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
490 |
c inspect. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
491 |
" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
492 |
" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
493 |
|v c| |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
494 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
495 |
v := StandardSystemView new. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
496 |
v extent:100@100. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
497 |
v openAndWait. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
498 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
499 |
c := Color dithered:0.5 between:Color red and:Color yellow on:Display. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
500 |
v paint:c. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
501 |
v fillRectangle:(10@10 corner:90@90). |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
502 |
" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
503 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
504 |
"Created: 3.5.1997 / 10:54:32 / cg" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
505 |
"Modified: 3.5.1997 / 11:13:12 / cg" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
506 |
! |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
507 |
|
8993 | 508 |
fromColorDialog |
509 |
"open a color editor, ask for a color; |
|
510 |
if cancelled, return nil. Otherwise return the chosen color." |
|
511 |
||
512 |
"{ Pragma: +optSpace }" |
|
513 |
||
514 |
|editor| |
|
515 |
||
516 |
editor := ColorEditDialog new. |
|
517 |
editor open. |
|
518 |
editor accepted ifTrue:[ |
|
519 |
^ editor color |
|
520 |
]. |
|
521 |
^ nil |
|
522 |
||
523 |
" |
|
524 |
Color fromColorDialog |
|
525 |
" |
|
526 |
! |
|
527 |
||
1023 | 528 |
fromUser |
1929 | 529 |
"{ Pragma: +optSpace }" |
530 |
||
1023 | 531 |
"let user point on a screen pixel. |
532 |
Return an instance for that pixels color" |
|
533 |
||
4896
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
534 |
^ self fromUserWithFeedBack:nil |
1023 | 535 |
|
536 |
" |
|
537 |
Color fromUser |
|
538 |
" |
|
539 |
||
1976
fcf9afd72f0f
Do not use obsolete method Color>>at:
Stefan Vogel <sv@exept.de>
parents:
1971
diff
changeset
|
540 |
"Modified: / 31.8.1995 / 01:34:22 / claus" |
fcf9afd72f0f
Do not use obsolete method Color>>at:
Stefan Vogel <sv@exept.de>
parents:
1971
diff
changeset
|
541 |
"Modified: / 9.1.1998 / 20:48:58 / stefan" |
1023 | 542 |
! |
543 |
||
4896
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
544 |
fromUserWithFeedBack:feedbackBlockOrNil |
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
545 |
"{ Pragma: +optSpace }" |
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
546 |
|
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
547 |
"let user point on a screen pixel. |
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
548 |
Return an instance for that pixels color" |
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
549 |
|
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
550 |
|p screen| |
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
551 |
|
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
552 |
screen := Screen current. |
6353 | 553 |
p := screen |
554 |
pointFromUserShowing:(Cursor crossHair) |
|
555 |
positionFeedback:[:p | |
|
556 |
feedbackBlockOrNil notNil ifTrue:[ |
|
557 |
feedbackBlockOrNil value:(screen colorAt:p) |
|
558 |
] |
|
559 |
]. |
|
4896
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
560 |
^ screen colorAt:p |
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
561 |
|
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
562 |
" |
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
563 |
Color fromUserWithFeedBack:nil |
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
564 |
" |
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
565 |
|
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
566 |
"Modified: / 31.8.1995 / 01:34:22 / claus" |
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
567 |
"Modified: / 9.1.1998 / 20:48:58 / stefan" |
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
568 |
! |
bd1f161a578a
added feedback option in color-fromUser
Claus Gittinger <cg@exept.de>
parents:
4851
diff
changeset
|
569 |
|
3005 | 570 |
green:green |
1985 | 571 |
"return a color from green value; |
572 |
the argument green is interpreted as percent (0..100)" |
|
573 |
||
6353 | 574 |
^ here |
575 |
scaledRed:0 scaledGreen:(green * MaxValue // 100) scaledBlue:0 |
|
3005 | 576 |
|
577 |
" |
|
578 |
(Color green:50) inspect |
|
579 |
" |
|
580 |
||
1985 | 581 |
! |
582 |
||
7910 | 583 |
htmlName:colorName |
584 |
"see https://en.wikipedia.org/wiki/Web-safe#HTML_color_names |
|
585 |
The web defines 16 standard color names, which are returned here. |
|
586 |
Attention: |
|
587 |
these are not the same colors as those built into X-servers; |
|
588 |
eg. (Color name:'green') returns a bright green, |
|
589 |
whereas (Color htmlName:'green') returns a dark green, and 'lime' would be the X-green. |
|
590 |
Sigh" |
|
591 |
||
592 |
^ self |
|
593 |
htmlName:colorName |
|
594 |
ifIllegal:[ |
|
595 |
InvalidColorNameSignal |
|
596 |
raiseRequestWith:colorName errorString:' : ' , colorName |
|
597 |
] |
|
598 |
||
599 |
" |
|
600 |
Color htmlName:'lime' |
|
601 |
||
602 |
Color htmlName:'green' |
|
603 |
Color name:'green' |
|
604 |
" |
|
605 |
||
606 |
"Created: / 17-02-2017 / 12:41:17 / cg" |
|
607 |
! |
|
608 |
||
609 |
htmlName:colorName ifIllegal:errorBlock |
|
610 |
"see https://en.wikipedia.org/wiki/Web-safe#HTML_color_names |
|
611 |
The web defines 16 standard color names, which are returned here. |
|
612 |
If aString is not a valid color name, |
|
613 |
return the result from evaluating errorBlock. |
|
614 |
Attention: |
|
615 |
these are not the same colors as those built into X-servers; |
|
616 |
eg. (Color name:'green') returns a bright green, |
|
617 |
whereas (Color htmlName:'green') returns a dark green, and 'lime' would be the X-green. |
|
618 |
Sigh" |
|
619 |
||
620 |
|nameLowercase| |
|
621 |
||
622 |
nameLowercase := colorName asLowercase. |
|
623 |
^ #( |
|
624 |
('silver' 16rC0C0C0) |
|
625 |
('maroon' 16r800000) |
|
626 |
('olive' 16r808000) |
|
627 |
('lime' 16r00FF00) |
|
628 |
('green' 16r008000) |
|
629 |
('aqua' 16r00FFFF) |
|
630 |
('teal' 16r008080) |
|
631 |
('navy' 16r000080) |
|
632 |
('fuchsia' 16rFF00FF) |
|
633 |
('purple' 16r800080) |
|
634 |
) |
|
635 |
detect:[:e | e first = nameLowercase] |
|
636 |
thenCompute:[:e | self rgbValue:(e second)] |
|
637 |
ifNone:[ self name:colorName ifIllegal:errorBlock ] |
|
638 |
||
639 |
" |
|
640 |
Color htmlName:'lime' |
|
641 |
||
642 |
Color htmlName:'green' |
|
643 |
Color name:'green' |
|
644 |
" |
|
645 |
||
646 |
"Created: / 17-02-2017 / 12:42:01 / cg" |
|
647 |
! |
|
648 |
||
1023 | 649 |
hue:h light:l saturation:s |
650 |
"return a color from hue, light and saturation values. |
|
7569 | 651 |
Hue is in degrees (0..360); light and saturation are |
1023 | 652 |
in percent (0..100)" |
653 |
||
654 |
self withRGBFromHue:h light:l saturation:s do:[:r :g :b | |
|
7569 | 655 |
^ self |
656 |
redPercent:(r clampBetween:0 and:100) |
|
657 |
greenPercent:(g clampBetween:0 and:100) |
|
658 |
bluePercent:(b clampBetween:0 and:100) |
|
1023 | 659 |
] |
660 |
||
661 |
" |
|
662 |
Color hue:0 light:50 saturation:100 - red |
|
663 |
Color hue:60 light:50 saturation:100 - yellow |
|
664 |
Color hue:120 light:50 saturation:100 - green |
|
665 |
Color hue:120 light:75 saturation:100 - bright green |
|
666 |
Color hue:120 light:25 saturation:100 - dark green |
|
667 |
Color hue:120 light:50 saturation:50 - greyish dark green |
|
668 |
Color hue:120 light:50 saturation:0 - b&w television dark green |
|
669 |
" |
|
670 |
||
671 |
"Modified: 23.4.1996 / 13:22:22 / cg" |
|
672 |
! |
|
673 |
||
8112 | 674 |
luma:y chromaBlue:cb chromaRed:cr |
675 |
"return a color from Y-Cb-Cr components. |
|
676 |
See https://en.wikipedia.org/wiki/YCbCr |
|
677 |
and ITU-R BT.601" |
|
678 |
||
679 |
|r g b| |
|
680 |
||
681 |
r := y + (1.400 * cr). |
|
682 |
g := y - (0.343 * (cb-128)) - (0.711 * (cr-128)). |
|
683 |
b := y + (1.765 * (cb-128)). |
|
684 |
||
685 |
^ self redByte:r greenByte:g blueByte:b |
|
686 |
||
687 |
" |
|
688 |
Color luma:0 chromaBlue:128 chromaRed:128 |
|
689 |
Color luma:1 chromaBlue:128 chromaRed:128 |
|
690 |
Color luma:0.5 chromaBlue:128 chromaRed:128 |
|
691 |
" |
|
692 |
||
693 |
"Created: / 26-08-2017 / 21:33:52 / cg" |
|
694 |
! |
|
695 |
||
1233 | 696 |
name:colorName |
1023 | 697 |
"Return a named color (either exact or dithered). |
698 |
Report an error, if aString is not a valid color name. |
|
699 |
||
700 |
We hereby only guarantee that the 8 basic colors are supported |
|
701 |
on every device (X uses the Xcolor database, so it supports more |
|
702 |
names - other devices use a builtIn name table containing only the |
|
6353 | 703 |
common names) |
704 |
- use with special names (such as 'mediumGoldenRod' is not recommended). |
|
3005 | 705 |
Better use: #name:ifIllegal: and provide a fallBack." |
1023 | 706 |
|
6353 | 707 |
^ self |
708 |
name:colorName |
|
709 |
ifIllegal:[ |
|
710 |
InvalidColorNameSignal |
|
711 |
raiseRequestWith:colorName errorString:' : ' , colorName |
|
712 |
] |
|
713 |
||
714 |
" |
|
715 |
Color name:'brown' |
|
716 |
Color name:'snow' |
|
1023 | 717 |
Color name:'foo' |
718 |
" |
|
719 |
||
1534 | 720 |
"Modified: 4.4.1997 / 15:32:33 / cg" |
1023 | 721 |
! |
722 |
||
1233 | 723 |
name:colorName ifIllegal:errorBlock |
1023 | 724 |
"Return a named color (either exact or dithered). |
6353 | 725 |
If aString is not a valid color name, |
1233 | 726 |
return the result from evaluating errorBlock." |
727 |
||
3399
02a4018f9549
care for no-display case when asking for a color-by-name
Claus Gittinger <cg@exept.de>
parents:
3396
diff
changeset
|
728 |
|triple r g b currScreen| |
1428 | 729 |
|
730 |
triple := StandardColorValues at:colorName asString ifAbsent:nil. |
|
731 |
triple notNil ifTrue:[ |
|
6353 | 732 |
r := triple at:1. |
733 |
g := triple at:2. |
|
734 |
b := triple at:3. |
|
1428 | 735 |
] ifFalse:[ |
6353 | 736 |
"/ ask display (if there is one) ... |
737 |
||
738 |
(Screen notNil |
|
739 |
and:[ (currScreen := Screen current) notNil]) |
|
740 |
ifTrue:[ |
|
741 |
currScreen |
|
742 |
getScaledRGBFromName:colorName |
|
743 |
into:[:rr :gg :bb | |
|
744 |
r := rr. |
|
745 |
g := gg. |
|
746 |
b := bb |
|
747 |
]. |
|
748 |
] |
|
1428 | 749 |
]. |
1233 | 750 |
r notNil ifTrue:[ |
6353 | 751 |
^ here scaledRed:r scaledGreen:g scaledBlue:b |
1233 | 752 |
]. |
753 |
^ errorBlock value |
|
1023 | 754 |
|
755 |
" |
|
756 |
Color name:'brown' ifIllegal:[Color black] |
|
6353 | 757 |
Color name:'red' ifIllegal:[Color black] |
758 |
Color name:'fuchsia' ifIllegal:[Color black] |
|
759 |
Color name:'foo' ifIllegal:[Color black] |
|
760 |
Color name:'foo' ifIllegal:[nil] |
|
1023 | 761 |
" |
762 |
||
1428 | 763 |
"Modified: 6.3.1997 / 02:32:41 / cg" |
1023 | 764 |
! |
765 |
||
766 |
noColor |
|
767 |
"return a special color which, when used for bit-blitting will |
|
768 |
behave like a 0-color (i.e. have a device-pixel value of all-0s)" |
|
769 |
||
770 |
Pseudo0 isNil ifTrue:[ |
|
6353 | 771 |
Pseudo0 := self basicNew setColorId:0 |
1023 | 772 |
]. |
773 |
^ Pseudo0 |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
774 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
775 |
"Modified: 17.1.1997 / 00:06:49 / cg" |
1023 | 776 |
! |
777 |
||
3005 | 778 |
red:red |
1985 | 779 |
"return a color from red value; |
780 |
the argument r is interpreted as percent (0..100)" |
|
781 |
||
6353 | 782 |
^ here |
783 |
scaledRed:(red * MaxValue // 100) scaledGreen:0 scaledBlue:0 |
|
3005 | 784 |
|
785 |
" |
|
786 |
(Color red:50) inspect |
|
787 |
" |
|
1985 | 788 |
! |
789 |
||
1023 | 790 |
red:r green:g blue:b |
791 |
"return a color from red, green and blue values; |
|
792 |
the arguments, r, g and b are interpreted as percent (0..100)" |
|
793 |
||
8277 | 794 |
^ self new |
795 |
setScaledRed:(r * MaxValue // 100) |
|
796 |
scaledGreen:(g * MaxValue // 100) |
|
797 |
scaledBlue:(b * MaxValue // 100) |
|
798 |
||
799 |
" |
|
800 |
Color red:50 green:50 blue:50 |
|
801 |
ColorValue red:0.5 green:0.5 blue:0.5 |
|
802 |
TranslucentColor red:50 green:50 blue:50 |
|
803 |
" |
|
1023 | 804 |
! |
805 |
||
1237 | 806 |
redByte:r greenByte:g blueByte:b |
807 |
"return a color from red, green and blue values; |
|
808 |
the arguments, r, g and b are interpreted as byte values (0..255)" |
|
809 |
||
1348 | 810 |
^ here scaledRed:(r * MaxValue // 255) |
6353 | 811 |
scaledGreen:(g * MaxValue // 255) |
812 |
scaledBlue:(b * MaxValue // 255) |
|
1237 | 813 |
|
814 |
" |
|
815 |
(Color redByte:255 greenByte:0 blueByte:0) inspect |
|
816 |
(Color redByte:255 greenByte:255 blueByte:255) inspect |
|
817 |
(Color redByte:0 greenByte:0 blueByte:0) inspect |
|
818 |
" |
|
819 |
||
820 |
"Modified: 16.1.1997 / 23:32:43 / cg" |
|
821 |
! |
|
822 |
||
4789 | 823 |
redByte:r greenByte:g blueByte:b alphaByte:a |
824 |
"return a color from red, green, blue and alpha values; |
|
825 |
the arguments, r, g, b and a are interpreted as byte values (0..255)" |
|
826 |
||
827 |
^ (here scaledRed:(r * MaxValue // 255) |
|
6353 | 828 |
scaledGreen:(g * MaxValue // 255) |
829 |
scaledBlue:(b * MaxValue // 255)) |
|
830 |
alpha:(a / 255) |
|
4789 | 831 |
|
832 |
" |
|
833 |
(Color redByte:255 greenByte:0 blueByte:0 alphaByte:127) inspect |
|
834 |
" |
|
835 |
||
836 |
"Created: / 06-06-2007 / 11:15:47 / cg" |
|
837 |
! |
|
838 |
||
5144 | 839 |
redFraction:r greenFraction:g blueFraction:b |
840 |
"return a color from red, green and blue values; |
|
841 |
the arguments, r, g and b are interpreted as fraction (0..1)" |
|
842 |
||
843 |
^ here scaledRed:(r * MaxValue) rounded |
|
6353 | 844 |
scaledGreen:(g * MaxValue) rounded |
845 |
scaledBlue:(b * MaxValue) rounded |
|
5144 | 846 |
! |
847 |
||
1348 | 848 |
redPercent:r greenPercent:g bluePercent:b |
849 |
"return a color from red, green and blue values; |
|
850 |
the arguments, r, g and b are interpreted as percent (0..100)" |
|
851 |
||
852 |
^ here scaledRed:(r * MaxValue // 100) |
|
6353 | 853 |
scaledGreen:(g * MaxValue // 100) |
854 |
scaledBlue:(b * MaxValue // 100) |
|
1348 | 855 |
! |
856 |
||
5127
40d2ac51c76d
color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents:
4986
diff
changeset
|
857 |
redPercent:r greenPercent:g bluePercent:b alphaPercent:a |
40d2ac51c76d
color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents:
4986
diff
changeset
|
858 |
"return a color from red, green and blue values; |
40d2ac51c76d
color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents:
4986
diff
changeset
|
859 |
the arguments, r, g and b are interpreted as percent (0..100)" |
40d2ac51c76d
color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents:
4986
diff
changeset
|
860 |
|
40d2ac51c76d
color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents:
4986
diff
changeset
|
861 |
^ (here scaledRed:(r * MaxValue // 100) |
6353 | 862 |
scaledGreen:(g * MaxValue // 100) |
863 |
scaledBlue:(b * MaxValue // 100)) |
|
864 |
alpha:(a * 255 // 100) |
|
5127
40d2ac51c76d
color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents:
4986
diff
changeset
|
865 |
! |
40d2ac51c76d
color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents:
4986
diff
changeset
|
866 |
|
3956
74f5434f3e38
+redShort:greenShort:blueShort:
Claus Gittinger <cg@exept.de>
parents:
3935
diff
changeset
|
867 |
redShort:r greenShort:g blueShort:b |
74f5434f3e38
+redShort:greenShort:blueShort:
Claus Gittinger <cg@exept.de>
parents:
3935
diff
changeset
|
868 |
"return a color from red, green and blue short values; |
74f5434f3e38
+redShort:greenShort:blueShort:
Claus Gittinger <cg@exept.de>
parents:
3935
diff
changeset
|
869 |
the arguments, r, g and b are interpreted as unsigned short values (0..16rFFFF)" |
74f5434f3e38
+redShort:greenShort:blueShort:
Claus Gittinger <cg@exept.de>
parents:
3935
diff
changeset
|
870 |
|
74f5434f3e38
+redShort:greenShort:blueShort:
Claus Gittinger <cg@exept.de>
parents:
3935
diff
changeset
|
871 |
^ here scaledRed:(r * MaxValue // 16rFFFF) |
6353 | 872 |
scaledGreen:(g * MaxValue // 16rFFFF) |
873 |
scaledBlue:(b * MaxValue // 16rFFFF) |
|
3956
74f5434f3e38
+redShort:greenShort:blueShort:
Claus Gittinger <cg@exept.de>
parents:
3935
diff
changeset
|
874 |
|
74f5434f3e38
+redShort:greenShort:blueShort:
Claus Gittinger <cg@exept.de>
parents:
3935
diff
changeset
|
875 |
" |
74f5434f3e38
+redShort:greenShort:blueShort:
Claus Gittinger <cg@exept.de>
parents:
3935
diff
changeset
|
876 |
(Color redShort:16rFFFF greenShort:0 blueShort:0) inspect |
74f5434f3e38
+redShort:greenShort:blueShort:
Claus Gittinger <cg@exept.de>
parents:
3935
diff
changeset
|
877 |
" |
74f5434f3e38
+redShort:greenShort:blueShort:
Claus Gittinger <cg@exept.de>
parents:
3935
diff
changeset
|
878 |
! |
74f5434f3e38
+redShort:greenShort:blueShort:
Claus Gittinger <cg@exept.de>
parents:
3935
diff
changeset
|
879 |
|
1859 | 880 |
rgbValue:rgb |
3005 | 881 |
"return a color from a 24bit RGB value; |
8109 | 882 |
The value is composed of r<<16 + g<<8 + b, |
883 |
i.e. rrggbb" |
|
1859 | 884 |
|
885 |
|r g b| |
|
886 |
||
8243 | 887 |
"/ constant colors |
888 |
rgb == 0 ifTrue:[ |
|
889 |
^ self black |
|
890 |
]. |
|
891 |
rgb == 16rFFFFFF ifTrue:[ |
|
892 |
^ self white |
|
893 |
]. |
|
894 |
||
1859 | 895 |
r := (rgb bitShift:-16) bitAnd:16rFF. |
896 |
g := (rgb bitShift:-8) bitAnd:16rFF. |
|
8243 | 897 |
b := rgb bitAnd:16rFF. |
1859 | 898 |
^ self redByte:r greenByte:g blueByte:b |
899 |
||
900 |
" |
|
901 |
(Color rgbValue:16rFF0000) inspect |
|
902 |
(Color rgbValue:16r00FF00) inspect |
|
903 |
(Color rgbValue:16r0000FF) inspect |
|
904 |
(Color rgbValue:16rFF00FF) inspect |
|
8243 | 905 |
(Color rgbValue:16rFFFFFF) inspect |
1859 | 906 |
" |
907 |
||
8109 | 908 |
"Modified: / 13-08-1997 / 20:24:37 / cg" |
909 |
"Modified (comment): / 26-08-2017 / 13:02:23 / cg" |
|
8243 | 910 |
"Modified (format): / 11-01-2018 / 12:21:56 / stefan" |
1859 | 911 |
! |
912 |
||
1023 | 913 |
scaledGray:aGrayValue |
914 |
"return a gray color with a scaled gray value (0..MaxValue)" |
|
915 |
||
916 |
^ self scaledRed:aGrayValue scaledGreen:aGrayValue scaledBlue:aGrayValue |
|
917 |
||
918 |
"Modified: 11.6.1996 / 16:31:42 / cg" |
|
919 |
! |
|
920 |
||
921 |
scaledRed:r scaledGreen:g scaledBlue:b |
|
922 |
"return a color from red, green and blue values; |
|
923 |
the arguments, r, g and b are interpreted as (0..MaxValue)" |
|
924 |
||
925 |
|newColor| |
|
926 |
||
8277 | 927 |
newColor := self basicNew setScaledRed:r scaledGreen:g scaledBlue:b. |
1023 | 928 |
^ newColor |
929 |
||
930 |
" |
|
931 |
(Color red:100 green:0 blue:0) inspect |
|
932 |
(Color red:100 green:50 blue:50) inspect |
|
933 |
(Color red:50 green:0 blue:0) inspect |
|
8277 | 934 |
(TranslucentColor red:50 green:0 blue:0) inspect |
1023 | 935 |
" |
936 |
||
937 |
"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
|
938 |
"Modified: 24.2.1997 / 18:18:47 / cg" |
1023 | 939 |
! |
940 |
||
941 |
variableColorOn:aDevice |
|
942 |
"return a variable color (i.e. allocate a writable colorcell) on |
|
943 |
aDevice. The returned color is not shared and its rgb components |
|
944 |
are initially undefined. The components can be set to any value |
|
945 |
using Color>>red:green:blue. Care should be taken, since this call |
|
946 |
fails on static color or b&w displays (i.e. it depends on the device |
|
947 |
being a pseudocolor device using colormaps). |
|
948 |
Returns nil, if no more colorCells are available, or the display |
|
949 |
uses a fix colormap (i.e. is a directColor or staticColor pr b&w device). |
|
950 |
Because of this, you should not write your application to depend on |
|
951 |
writable colors to be available (i.e. add fallBack code to redraw |
|
952 |
things in another color)" |
|
953 |
||
954 |
|c lutIndex| |
|
955 |
||
956 |
lutIndex := aDevice colorCell. |
|
957 |
lutIndex isNil ifTrue:[^ nil]. |
|
958 |
||
959 |
c := self new. |
|
1934 | 960 |
c setDevice:aDevice colorId:lutIndex writable:true. |
1023 | 961 |
Cells isNil ifTrue:[ |
6353 | 962 |
Cells := Registry new. |
1023 | 963 |
]. |
964 |
Cells register:c. |
|
965 |
^ c |
|
966 |
||
967 |
" |
|
968 |
|l cell| |
|
969 |
||
970 |
l := Label new. |
|
971 |
l label:('hello' asText allBold). |
|
972 |
||
973 |
cell := Color variableColorOn:(Screen current). |
|
974 |
l foregroundColor:cell. |
|
975 |
[ |
|
6353 | 976 |
1 to:40 do:[:i| |
977 |
i odd ifTrue:[ |
|
978 |
cell red:100 green:0 blue:0 |
|
979 |
] ifFalse:[ |
|
980 |
cell red:0 green:0 blue:0 |
|
981 |
]. |
|
982 |
Display flush. |
|
983 |
(Delay forSeconds:0.4) wait |
|
984 |
]. |
|
985 |
l destroy. |
|
1023 | 986 |
] fork. |
987 |
l open |
|
988 |
" |
|
989 |
||
990 |
"Modified: 13.5.1996 / 12:41:53 / cg" |
|
991 |
! ! |
|
992 |
||
3892 | 993 |
!Color class methodsFor:'Compatibility-Squeak'! |
2934 | 994 |
|
3021 | 995 |
colorPaletteForDepth: depth extent: chartExtent |
6353 | 996 |
"Squeak mimicri: |
997 |
Display a palette of colors sorted horizontally by hue and vertically by lightness. Useful for eyeballing the color gamut of the display, or for choosing a color interactively." |
|
998 |
||
999 |
"Note: It is slow to build this palette, so it should be cached for quick access." |
|
1000 |
"(Color colorPaletteForDepth: 16 extent: 190@60) display" |
|
1001 |
||
1002 |
| basicHue x y c startHue palette transHt vSteps transCaption grayWidth hSteps | |
|
3324 | 1003 |
|
1004 |
"/ Smalltalk isSmalltalkX ifTrue:[ |
|
6353 | 1005 |
palette := Image extent:chartExtent depth:24. |
1006 |
palette photometric:#rgb. |
|
1007 |
palette bits:(ByteArray new:chartExtent x * chartExtent y * 3). |
|
3324 | 1008 |
"/ ] ifFalse:[ |
1009 |
"/ palette := Form extent: chartExtent depth: depth. |
|
1010 |
"/ ]. |
|
6353 | 1011 |
transCaption := "(DisplayText text: 'no color' asText textStyle: (TextConstants at: #ComicPlain)) form storeString" |
1012 |
(Form extent: 34@9 depth: 1 |
|
1013 |
fromArray: #(0 0 256 0 256 0 3808663859 2147483648 2491688266 2147483648 2491688266 0 2491688266 0 2466486578 0 0 0) |
|
1014 |
offset: 0@0). |
|
1015 |
transHt := transCaption height. |
|
1016 |
palette fillWhite: (0@0 extent: palette width@transHt). |
|
1017 |
palette fillBlack: (0@transHt extent: palette width@1). |
|
3021 | 1018 |
"/ transCaption displayOn: palette at: palette boundingBox topCenter - ((transCaption width // 2)@0). |
6353 | 1019 |
grayWidth := 10. |
1020 |
startHue := 338.0. |
|
1021 |
vSteps := palette height - transHt // 2. |
|
1022 |
hSteps := palette width - grayWidth. |
|
1023 |
x := 0. |
|
1024 |
startHue to: startHue + 360.0 by: 360.0/hSteps do: [:h | |
|
1025 |
basicHue := Color h: h asFloat s: 1.0 v: 1.0. |
|
1026 |
y := transHt+1. |
|
1027 |
0 to: vSteps do: [:n | |
|
1028 |
c := basicHue mixed: (n asFloat / vSteps asFloat) with: Color white. |
|
1029 |
palette fill: (x@y extent: 1@1) fillColor: c. |
|
1030 |
y := y + 1]. |
|
1031 |
1 to: vSteps do: [:n | |
|
1032 |
c := Color black mixed: (n asFloat / vSteps asFloat) with: basicHue. |
|
1033 |
y < palette height ifTrue:[ |
|
1034 |
palette fill: (x@y extent: 1@1) fillColor: c. |
|
1035 |
]. |
|
1036 |
y := y + 1]. |
|
1037 |
x := x + 1]. |
|
1038 |
y := transHt + 1. |
|
1039 |
1 to: vSteps * 2 do: [:n | |
|
1040 |
c := Color black mixed: (n asFloat / (vSteps*2) asFloat) with: Color white. |
|
1041 |
palette fill: (x@y corner:(((x@y) +(10@1))min:palette extent)) fillColor: c. |
|
1042 |
y := y + 1]. |
|
1043 |
^ palette |
|
3021 | 1044 |
! |
1045 |
||
3024 | 1046 |
fromRgbTriplet:aTriple |
1047 |
^ self r:(aTriple at:1) |
|
6353 | 1048 |
g:(aTriple at:2) |
1049 |
b:(aTriple at:3) |
|
3024 | 1050 |
|
1051 |
! |
|
1052 |
||
3021 | 1053 |
h:hue s:saturation v:brightness |
1054 |
"Squeak mimicri: |
|
6353 | 1055 |
Create a color with the given hue, saturation, and brightness. |
3021 | 1056 |
Hue is given as the angle in degrees of the color on the color circle, |
6353 | 1057 |
where red is zero degrees. |
3021 | 1058 |
Saturation and brightness are numbers in [0.0..1.0], |
6353 | 1059 |
where larger values are more saturated or brighter colors. |
3021 | 1060 |
For example, (Color h: 0 s: 1 v: 1) is pure red." |
1061 |
||
7411 | 1062 |
"Note: By convention, brightness is abbreviated 'v' to avoid confusion with blue." |
3021 | 1063 |
|
3024 | 1064 |
^ self hue:hue light:(brightness*50) saturation:(saturation*100) |
1065 |
! |
|
1066 |
||
4986 | 1067 |
indexedColors |
1068 |
"Build an array of colors corresponding to the fixed colormap used |
|
1069 |
for display depths of 1, 2, 4, or 8 bits." |
|
1070 |
"Color indexedColors" |
|
1071 |
||
1072 |
| a index grayVal | |
|
1073 |
||
1074 |
a := Array new: 256. |
|
1075 |
||
1076 |
"1-bit colors (monochrome)" |
|
1077 |
a at: 1 put: (Color r: 1.0 g: 1.0 b: 1.0). "white or transparent" |
|
1078 |
a at: 2 put: (Color r: 0.0 g: 0.0 b: 0.0). "black" |
|
1079 |
||
1080 |
"additional colors for 2-bit color" |
|
1081 |
a at: 3 put: (Color r: 1.0 g: 1.0 b: 1.0). "opaque white" |
|
1082 |
a at: 4 put: (Color r: 0.5 g: 0.5 b: 0.5). "1/2 gray" |
|
1083 |
||
1084 |
"additional colors for 4-bit color" |
|
1085 |
a at: 5 put: (Color r: 1.0 g: 0.0 b: 0.0). "red" |
|
1086 |
a at: 6 put: (Color r: 0.0 g: 1.0 b: 0.0). "green" |
|
1087 |
a at: 7 put: (Color r: 0.0 g: 0.0 b: 1.0). "blue" |
|
1088 |
a at: 8 put: (Color r: 0.0 g: 1.0 b: 1.0). "cyan" |
|
1089 |
a at: 9 put: (Color r: 1.0 g: 1.0 b: 0.0). "yellow" |
|
1090 |
a at: 10 put: (Color r: 1.0 g: 0.0 b: 1.0). "magenta" |
|
1091 |
||
1092 |
a at: 11 put: (Color r: 0.125 g: 0.125 b: 0.125). "1/8 gray" |
|
1093 |
a at: 12 put: (Color r: 0.25 g: 0.25 b: 0.25). "2/8 gray" |
|
1094 |
a at: 13 put: (Color r: 0.375 g: 0.375 b: 0.375). "3/8 gray" |
|
1095 |
a at: 14 put: (Color r: 0.625 g: 0.625 b: 0.625). "5/8 gray" |
|
1096 |
a at: 15 put: (Color r: 0.75 g: 0.75 b: 0.75). "6/8 gray" |
|
1097 |
a at: 16 put: (Color r: 0.875 g: 0.875 b: 0.875). "7/8 gray" |
|
1098 |
||
1099 |
"additional colors for 8-bit color" |
|
1100 |
"24 more shades of gray (1/32 increments but not repeating 1/8 increments)" |
|
1101 |
index := 17. |
|
1102 |
1 to: 31 do: [:v | |
|
6353 | 1103 |
(v \\ 4) = 0 ifFalse: [ |
1104 |
grayVal := v / 32.0. |
|
1105 |
a at: index put: (Color r: grayVal g: grayVal b: grayVal). |
|
1106 |
index := index + 1]]. |
|
4986 | 1107 |
|
1108 |
"The remainder of color table defines a color cube with six steps |
|
1109 |
for each primary color. Note that the corners of this cube repeat |
|
1110 |
previous colors, but this simplifies the mapping between RGB colors |
|
1111 |
and color map indices. This color cube spans indices 40 through 255 |
|
1112 |
(indices 41-256 in this 1-based array)." |
|
1113 |
0 to: 5 do: [:r | |
|
6353 | 1114 |
0 to: 5 do: [:g | |
1115 |
0 to: 5 do: [:b | |
|
1116 |
index := 41 + ((36 * r) + (6 * b) + g). |
|
1117 |
index > 256 ifTrue: [ |
|
1118 |
self error: 'index out of range in color table compuation']. |
|
1119 |
a at: index put: (Color r: r g: g b: b range: 5)]]]. |
|
4986 | 1120 |
|
1121 |
^ a. |
|
1122 |
! |
|
1123 |
||
3893 | 1124 |
paleBlue |
1125 |
^ self r:0.75 g:0.75 b:1 |
|
1126 |
! |
|
1127 |
||
3024 | 1128 |
pixelScreenForDepth: depth |
3898
368c43005b5a
isSmalltalkX -> dialectName comparison (CS-Compatibility)
Claus Gittinger <cg@exept.de>
parents:
3893
diff
changeset
|
1129 |
"Return a 50% stipple containing alternating pixels of all-zeros and all-ones to be used as a mask at the given depth." |
368c43005b5a
isSmalltalkX -> dialectName comparison (CS-Compatibility)
Claus Gittinger <cg@exept.de>
parents:
3893
diff
changeset
|
1130 |
|
368c43005b5a
isSmalltalkX -> dialectName comparison (CS-Compatibility)
Claus Gittinger <cg@exept.de>
parents:
3893
diff
changeset
|
1131 |
| mask bits | |
368c43005b5a
isSmalltalkX -> dialectName comparison (CS-Compatibility)
Claus Gittinger <cg@exept.de>
parents:
3893
diff
changeset
|
1132 |
|
6584 | 1133 |
(Smalltalk isSmalltalkX) ifTrue:[ |
1134 |
depth == 1 ifTrue:[ |
|
1135 |
^ Form mediumGreyFormOn:Screen current |
|
1136 |
]. |
|
1137 |
self shouldImplement. |
|
3898
368c43005b5a
isSmalltalkX -> dialectName comparison (CS-Compatibility)
Claus Gittinger <cg@exept.de>
parents:
3893
diff
changeset
|
1138 |
]. |
368c43005b5a
isSmalltalkX -> dialectName comparison (CS-Compatibility)
Claus Gittinger <cg@exept.de>
parents:
3893
diff
changeset
|
1139 |
|
368c43005b5a
isSmalltalkX -> dialectName comparison (CS-Compatibility)
Claus Gittinger <cg@exept.de>
parents:
3893
diff
changeset
|
1140 |
mask := (1 bitShift: depth) - 1. |
368c43005b5a
isSmalltalkX -> dialectName comparison (CS-Compatibility)
Claus Gittinger <cg@exept.de>
parents:
3893
diff
changeset
|
1141 |
bits := 2 * depth. |
368c43005b5a
isSmalltalkX -> dialectName comparison (CS-Compatibility)
Claus Gittinger <cg@exept.de>
parents:
3893
diff
changeset
|
1142 |
[bits >= 32] whileFalse: [ |
6584 | 1143 |
mask := mask bitOr: (mask bitShift: bits). "double the length of mask" |
1144 |
bits := bits + bits |
|
3898
368c43005b5a
isSmalltalkX -> dialectName comparison (CS-Compatibility)
Claus Gittinger <cg@exept.de>
parents:
3893
diff
changeset
|
1145 |
]. |
368c43005b5a
isSmalltalkX -> dialectName comparison (CS-Compatibility)
Claus Gittinger <cg@exept.de>
parents:
3893
diff
changeset
|
1146 |
^ Bitmap with: mask with: mask bitInvert32 |
368c43005b5a
isSmalltalkX -> dialectName comparison (CS-Compatibility)
Claus Gittinger <cg@exept.de>
parents:
3893
diff
changeset
|
1147 |
|
368c43005b5a
isSmalltalkX -> dialectName comparison (CS-Compatibility)
Claus Gittinger <cg@exept.de>
parents:
3893
diff
changeset
|
1148 |
" |
368c43005b5a
isSmalltalkX -> dialectName comparison (CS-Compatibility)
Claus Gittinger <cg@exept.de>
parents:
3893
diff
changeset
|
1149 |
self pixelScreenForDepth: depth |
368c43005b5a
isSmalltalkX -> dialectName comparison (CS-Compatibility)
Claus Gittinger <cg@exept.de>
parents:
3893
diff
changeset
|
1150 |
" |
3021 | 1151 |
! |
1152 |
||
2934 | 1153 |
r:redFraction g:greenFraction b:blueFraction |
3021 | 1154 |
"Squeak mimicri: |
1155 |
return a color from red, green and blue fractional values; |
|
4789 | 1156 |
the arguments, r, g and b must be in (0..1)" |
2934 | 1157 |
|
2937 | 1158 |
^ here scaledRed:(redFraction * MaxValue) rounded |
6353 | 1159 |
scaledGreen:(greenFraction * MaxValue) rounded |
1160 |
scaledBlue:(blueFraction * MaxValue) rounded |
|
4789 | 1161 |
|
1162 |
"Modified: / 06-06-2007 / 11:19:53 / cg" |
|
1163 |
! |
|
1164 |
||
1165 |
r:r g:g b:b alpha:alphaValue |
|
1166 |
"return a color from red, green and blue values; |
|
1167 |
the arguments, r, g, b and alpha must be in 0..1" |
|
1168 |
||
1169 |
^ (self r:r g:g b:b) alpha:alphaValue |
|
1170 |
||
1171 |
" |
|
1172 |
(Color r:1 g:0 b:0 alpha:0) inspect |
|
1173 |
(Color r:0 g:1 b:0 alpha:0.5) inspect |
|
1174 |
(Color r:0 g:0 b:1 alpha:1) inspect |
|
1175 |
" |
|
1176 |
||
1177 |
"Created: / 06-06-2007 / 10:48:21 / cg" |
|
3396 | 1178 |
! |
1179 |
||
4202 | 1180 |
r:r g:g b:b range:componentMax |
1181 |
"return a color from red, green and blue values; |
|
1182 |
the arguments, r, g and b are interpreted as values (0..componentMax)" |
|
1183 |
||
1184 |
^ here scaledRed:(r * MaxValue // componentMax) |
|
6353 | 1185 |
scaledGreen:(g * MaxValue // componentMax) |
1186 |
scaledBlue:(b * MaxValue // componentMax) |
|
4202 | 1187 |
|
1188 |
" |
|
1189 |
(Color r:1023 g:0 b:0 range:1023) inspect |
|
1190 |
(Color r:1023 g:1023 b:1023 range:1023) inspect |
|
1191 |
(Color r:0 g:0 b:0 range:1023) inspect |
|
1192 |
" |
|
1193 |
! |
|
1194 |
||
3396 | 1195 |
showColors: colorList |
6353 | 1196 |
"Display the given collection of colors across the top of the Display." |
1197 |
||
1198 |
| w r | |
|
1199 |
w := Screen current width // colorList size. |
|
1200 |
r := 0@0 extent: w@((w min: 30) max: 10). |
|
1201 |
colorList do: [:c | |
|
1202 |
Screen current fill: r fillColor: c. |
|
1203 |
r := r translateBy: w@0]. |
|
3396 | 1204 |
! |
1205 |
||
1206 |
wheel: thisMany |
|
1207 |
"Return a collection of thisMany colors evenly spaced around the color wheel." |
|
1208 |
"Color showColors: (Color wheel: 12)" |
|
1209 |
||
1210 |
^ Color wheel: thisMany saturation: 0.9 brightness: 0.7 |
|
1211 |
! |
|
1212 |
||
1213 |
wheel: thisMany saturation: s brightness: v |
|
6353 | 1214 |
"Return a collection of thisMany colors evenly spaced around the color wheel, |
4789 | 1215 |
all of the given saturation and brightness." |
3396 | 1216 |
"Color showColors: (Color wheel: 12 saturation: 0.4 brightness: 1.0)" |
1217 |
"Color showColors: (Color wheel: 12 saturation: 0.8 brightness: 0.5)" |
|
1218 |
||
1219 |
^ (Color h: 0.0 s: s v: v) wheel: thisMany |
|
4789 | 1220 |
|
1221 |
"Modified: / 06-06-2007 / 11:20:59 / cg" |
|
2934 | 1222 |
! ! |
1223 |
||
1144 | 1224 |
!Color class methodsFor:'Signal constants'! |
1023 | 1225 |
|
1226 |
colorAllocationFailSignal |
|
1227 |
"return the signal raised when a color allocation failed." |
|
1228 |
||
1229 |
^ ColorAllocationFailSignal |
|
1230 |
||
1231 |
"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
|
1232 |
! |
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
1233 |
|
2379
b2a844aabc93
made my signals children of a common colorErrorSignal
Claus Gittinger <cg@exept.de>
parents:
2375
diff
changeset
|
1234 |
colorErrorSignal |
b2a844aabc93
made my signals children of a common colorErrorSignal
Claus Gittinger <cg@exept.de>
parents:
2375
diff
changeset
|
1235 |
"return the parent signal of all color error signals." |
b2a844aabc93
made my signals children of a common colorErrorSignal
Claus Gittinger <cg@exept.de>
parents:
2375
diff
changeset
|
1236 |
|
b2a844aabc93
made my signals children of a common colorErrorSignal
Claus Gittinger <cg@exept.de>
parents:
2375
diff
changeset
|
1237 |
^ ColorErrorSignal |
b2a844aabc93
made my signals children of a common colorErrorSignal
Claus Gittinger <cg@exept.de>
parents:
2375
diff
changeset
|
1238 |
|
b2a844aabc93
made my signals children of a common colorErrorSignal
Claus Gittinger <cg@exept.de>
parents:
2375
diff
changeset
|
1239 |
"Created: / 30.9.1998 / 21:56:04 / cg" |
b2a844aabc93
made my signals children of a common colorErrorSignal
Claus Gittinger <cg@exept.de>
parents:
2375
diff
changeset
|
1240 |
! |
b2a844aabc93
made my signals children of a common colorErrorSignal
Claus Gittinger <cg@exept.de>
parents:
2375
diff
changeset
|
1241 |
|
1269
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
1242 |
invalidColorNameSignal |
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
1243 |
"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
|
1244 |
|
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
1245 |
^ InvalidColorNameSignal |
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
1246 |
|
f0777b2cc08a
use a signal for invalid color names
Claus Gittinger <cg@exept.de>
parents:
1239
diff
changeset
|
1247 |
"Created: 24.1.1997 / 13:36:25 / cg" |
1023 | 1248 |
! ! |
1249 |
||
1144 | 1250 |
!Color class methodsFor:'accessing'! |
1023 | 1251 |
|
1252 |
allocatedColorsOn:aDevice |
|
3833 | 1253 |
"return a collection of colors which have already been allocated |
1254 |
on aDevice." |
|
1255 |
||
4176 | 1256 |
<resource: #obsolete> |
3833 | 1257 |
self obsoleteMethodWarning:'use #allocatedColorsOnDevice:'. |
1258 |
||
1259 |
^ self allocatedColorsOnDevice:aDevice |
|
1260 |
! |
|
1261 |
||
1262 |
allocatedColorsOnDevice:aDevice |
|
1263 |
"return a collection of colors which have already been allocated |
|
1264 |
on aDevice." |
|
1023 | 1265 |
|
1266 |
|colors| |
|
1267 |
||
1268 |
colors := OrderedCollection new. |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1269 |
aDevice deviceColors do:[:clr | |
6353 | 1270 |
clr colorId notNil ifTrue:[ |
1271 |
colors add:clr |
|
1272 |
] ifFalse:[ |
|
1273 |
'Color [oops]: nil colorId in color' infoPrintCR. |
|
1274 |
] |
|
1023 | 1275 |
]. |
1276 |
^ colors asArray |
|
1277 |
||
1278 |
" |
|
3833 | 1279 |
Color allocatedColorsOnDevice:Display |
1023 | 1280 |
" |
1281 |
||
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
1282 |
"Modified: 24.2.1997 / 18:16:14 / cg" |
1023 | 1283 |
! ! |
1284 |
||
1144 | 1285 |
!Color class methodsFor:'color space conversions'! |
1023 | 1286 |
|
1287 |
withHLSFromRed:r green:g blue:b do:aBlock |
|
3543 | 1288 |
"compute hls form rgb, evaluate aBlock with h,l and s as arguments. |
1289 |
r,g,b in 0..100 |
|
1290 |
h in 0..360; l in 0..100; s in 0..100" |
|
1023 | 1291 |
|
6110 | 1292 |
|max min r1 g1 b1 delta h l s divisor| |
1023 | 1293 |
|
1294 |
r1 := r / 100. "scale to 0..1" |
|
1295 |
g1 := g / 100. |
|
1296 |
b1 := b / 100. |
|
1297 |
||
1298 |
max := (r1 max:g1) max:b1. |
|
1299 |
min := (r1 min:g1) min:b1. |
|
1300 |
l := (max + min) / 2. |
|
1301 |
||
1302 |
max = min ifTrue:[ |
|
6353 | 1303 |
"achromatic, r=g=b" |
1304 |
||
1305 |
s := 0. |
|
1306 |
h := nil |
|
1023 | 1307 |
] ifFalse:[ |
6353 | 1308 |
l < 0.5 ifTrue:[ |
1309 |
divisor := (max + min) |
|
1310 |
] ifFalse:[ |
|
1311 |
divisor := (2 - max - min) |
|
1312 |
]. |
|
1313 |
divisor = 0 ifTrue:[ |
|
1314 |
s := 1.0 |
|
1315 |
] ifFalse:[ |
|
1316 |
s := (max - min) / divisor |
|
1317 |
]. |
|
1318 |
"calc hue" |
|
1319 |
||
1320 |
delta := max - min. |
|
1321 |
r1 = max ifTrue:[ |
|
1322 |
h := (g1 - b1) / delta |
|
1323 |
] ifFalse:[ |
|
1324 |
g1 = max ifTrue:[ |
|
1325 |
h := 2 + ((b1 - r1) / delta) |
|
1326 |
] ifFalse:[ |
|
1327 |
h := 4 + ((r1 - g1) / delta) |
|
1328 |
] |
|
1329 |
]. |
|
1330 |
h := h * 60. |
|
1331 |
h < 0 ifTrue:[ |
|
1332 |
h := h + 360 |
|
1333 |
]. |
|
1023 | 1334 |
]. |
1335 |
aBlock value:h value:(l * 100) value:(s * 100) |
|
6110 | 1336 |
|
1337 |
"Modified: / 27-07-2013 / 11:48:20 / cg" |
|
1023 | 1338 |
! |
1339 |
||
1340 |
withHLSFromScaledRed:r scaledGreen:g scaledBlue:b do:aBlock |
|
1341 |
"compute hls form rgb, evaluate aBlock with h,l and s as arguments" |
|
1342 |
||
1343 |
^ self withHLSFromRed:(r * 100.0 / MaxValue) |
|
6353 | 1344 |
green:(g * 100.0 / MaxValue) |
1345 |
blue:(b * 100.0 / MaxValue) |
|
1346 |
do:aBlock |
|
1023 | 1347 |
|
1348 |
"Created: 11.6.1996 / 17:23:47 / cg" |
|
1349 |
! |
|
1350 |
||
1351 |
withRGBFromHue:h light:l saturation:s do:aBlock |
|
3543 | 1352 |
"compute rgb form hls, evaluate aBlock with r,g and b as arguments |
1353 |
r,g,b in 0..100 |
|
1354 |
h in 0..360; l in 0..100; s in 0..100" |
|
1023 | 1355 |
|
1356 |
|valueFunc s1 l1 r g b m1 m2| |
|
1357 |
||
1358 |
valueFunc := [:n1 :n2 :hIn | |
|
6353 | 1359 |
|hue| |
1360 |
||
1361 |
hue := hIn. |
|
1362 |
hue > 360 ifTrue:[ |
|
1363 |
hue := hue - 360 |
|
1364 |
] ifFalse:[ |
|
1365 |
hue < 0 ifTrue:[ |
|
1366 |
hue := hue + 360 |
|
1367 |
]. |
|
1368 |
]. |
|
1369 |
hue < 60 ifTrue:[ |
|
1370 |
n1 + ((n2 - n1) * hue / 60) |
|
1371 |
] ifFalse:[ |
|
1372 |
hue < 180 ifTrue:[ |
|
1373 |
n2 |
|
1374 |
] ifFalse:[ |
|
1375 |
hue < 240 ifTrue:[ |
|
1376 |
n1 + ((n2 - n1) * (240 - hue) / 60) |
|
1377 |
] ifFalse:[ |
|
1378 |
n1 |
|
1379 |
] |
|
1380 |
] |
|
1381 |
] |
|
1023 | 1382 |
]. |
1383 |
||
1384 |
"compute hls; h in 0..360; l 0..100; s 0..100" |
|
1385 |
||
1386 |
s1 := s / 100.0. "scale to 0..1" |
|
1387 |
l1 := l / 100.0. |
|
1388 |
||
1389 |
l1 <= 0.5 ifTrue:[ |
|
6353 | 1390 |
m2 := l1 * (1 + s1) |
1023 | 1391 |
] ifFalse:[ |
6353 | 1392 |
m2 := l1 + s1 - (l1 * s1) |
1023 | 1393 |
]. |
1394 |
||
1395 |
m1 := 2 * l1 - m2. |
|
1396 |
||
1397 |
s1 = 0 ifTrue:[ |
|
6353 | 1398 |
"achromatic, ignore hue" |
1399 |
r := g := b := l1 |
|
1023 | 1400 |
] ifFalse:[ |
6353 | 1401 |
r := valueFunc value:m1 value:m2 value:h + 120. |
1402 |
g := valueFunc value:m1 value:m2 value:h. |
|
1403 |
b := valueFunc value:m1 value:m2 value:h - 120. |
|
1023 | 1404 |
]. |
1405 |
aBlock value:r*100 value:g*100 value:b*100 |
|
1406 |
! ! |
|
1407 |
||
1144 | 1408 |
!Color class methodsFor:'constant colors'! |
1023 | 1409 |
|
1410 |
black |
|
1411 |
"return the black color" |
|
1412 |
||
1413 |
Black isNil ifTrue:[ |
|
6353 | 1414 |
Black := self red:0 green:0 blue:0 |
1023 | 1415 |
]. |
1416 |
^ Black |
|
1417 |
||
1418 |
" |
|
1419 |
Color black inspect |
|
1420 |
" |
|
1421 |
||
1422 |
"Modified: 11.6.1996 / 15:55:31 / cg" |
|
1423 |
! |
|
1424 |
||
1425 |
blue |
|
1426 |
"return the blue color" |
|
1427 |
||
1428 |
Blue isNil ifTrue:[ |
|
6353 | 1429 |
Blue := self redPercent:0 greenPercent:0 bluePercent:100 |
1023 | 1430 |
]. |
1431 |
^ Blue |
|
1432 |
||
1433 |
" |
|
1434 |
Color blue inspect |
|
1435 |
" |
|
1436 |
||
1437 |
"Modified: 23.4.1996 / 13:15:51 / cg" |
|
1438 |
! |
|
1439 |
||
2962 | 1440 |
brown |
1441 |
^ self redPercent:60 greenPercent:20 bluePercent:0 |
|
1442 |
||
1443 |
" |
|
1444 |
Color brown |
|
1445 |
" |
|
1446 |
! |
|
1447 |
||
1023 | 1448 |
cyan |
1449 |
"return the cyan color - ST-80 compatibility" |
|
1450 |
||
2087 | 1451 |
^ self cyan:100 |
1023 | 1452 |
|
1453 |
" |
|
1454 |
Color cyan inspect |
|
1455 |
" |
|
1456 |
||
1457 |
"Modified: 23.4.1996 / 13:16:07 / cg" |
|
1458 |
! |
|
1459 |
||
2087 | 1460 |
cyan: cyan |
1461 |
"return a cyan color; |
|
1462 |
the argument cyan is interpreted as percent (0..100)" |
|
1463 |
||
1464 |
^ self cyan:100 magenta:100-cyan yellow:100-cyan |
|
6353 | 1465 |
|
2087 | 1466 |
! |
1467 |
||
1023 | 1468 |
darkGray |
1469 |
"return the dark grey color (English version ;-)" |
|
1470 |
||
1471 |
DarkGrey isNil ifTrue:[ |
|
6353 | 1472 |
DarkGrey := self grayPercent:33 |
1023 | 1473 |
]. |
1474 |
^ DarkGrey |
|
1475 |
||
1476 |
" |
|
1477 |
Color darkGray inspect |
|
1478 |
" |
|
1479 |
||
1368 | 1480 |
"Modified: 24.2.1997 / 21:33:11 / cg" |
1023 | 1481 |
! |
1482 |
||
8660 | 1483 |
darkGreen |
1484 |
"return a dark green color" |
|
1485 |
||
1486 |
DarkGreen isNil ifTrue:[ |
|
1487 |
DarkGreen := self green darkened |
|
1488 |
]. |
|
1489 |
^ DarkGreen |
|
1490 |
||
1491 |
" |
|
1492 |
Color darkGreen |
|
1493 |
" |
|
1494 |
||
1495 |
"Created: / 13-03-2019 / 21:10:09 / Claus Gittinger" |
|
1496 |
! |
|
1497 |
||
1023 | 1498 |
darkGrey |
1499 |
"return the darkGrey color (US version ;-)" |
|
1500 |
||
1501 |
^ self darkGray |
|
1502 |
||
1503 |
" |
|
1504 |
Color darkGrey inspect |
|
1505 |
" |
|
1506 |
||
1507 |
"Modified: 28.5.1996 / 20:47:14 / cg" |
|
1508 |
! |
|
1509 |
||
8660 | 1510 |
darkRed |
1511 |
"return a dark green color" |
|
1512 |
||
1513 |
DarkRed isNil ifTrue:[ |
|
1514 |
DarkRed := self red darkened |
|
1515 |
]. |
|
1516 |
^ DarkRed |
|
1517 |
||
1518 |
" |
|
1519 |
Color darkRed |
|
1520 |
" |
|
1521 |
||
1522 |
"Created: / 13-03-2019 / 21:16:02 / Claus Gittinger" |
|
1523 |
! |
|
1524 |
||
1023 | 1525 |
gray |
1526 |
"return a medium grey color (US version ;-)" |
|
1527 |
||
1528 |
Grey isNil ifTrue:[ |
|
6353 | 1529 |
Grey := self grayPercent:50 |
1023 | 1530 |
]. |
1531 |
^ Grey |
|
1532 |
||
1533 |
" |
|
1534 |
Color gray inspect |
|
1535 |
" |
|
1536 |
||
1368 | 1537 |
"Modified: 24.2.1997 / 21:33:19 / cg" |
1023 | 1538 |
! |
1539 |
||
1540 |
gray:gray |
|
6353 | 1541 |
"return a gray color (US version). |
1023 | 1542 |
The argument, gray is interpreted as percent (0..100)." |
1543 |
||
1348 | 1544 |
^ self redPercent:gray greenPercent:gray bluePercent:gray |
1545 |
||
1546 |
" |
|
1547 |
Color gray:25 |
|
1548 |
" |
|
1549 |
||
1550 |
"Modified: 28.5.1996 / 20:49:51 / cg" |
|
1551 |
! |
|
1552 |
||
1553 |
grayPercent:gray |
|
6353 | 1554 |
"return a gray color (US version). |
1348 | 1555 |
The argument, gray is interpreted as percent (0..100)." |
1556 |
||
1557 |
^ self redPercent:gray greenPercent:gray bluePercent:gray |
|
1023 | 1558 |
|
1559 |
" |
|
1560 |
Color gray:25 |
|
1561 |
" |
|
1562 |
||
1563 |
"Modified: 28.5.1996 / 20:49:51 / cg" |
|
1564 |
! |
|
1565 |
||
1566 |
green |
|
1567 |
"return green" |
|
1568 |
||
1569 |
Green isNil ifTrue:[ |
|
6353 | 1570 |
Green := self redPercent:0 greenPercent:100 bluePercent:0 |
1023 | 1571 |
]. |
1572 |
^ Green |
|
1573 |
||
1574 |
" |
|
1575 |
Color green inspect |
|
1576 |
" |
|
1577 |
||
1578 |
"Modified: 23.4.1996 / 13:23:08 / cg" |
|
1579 |
! |
|
1580 |
||
7832 | 1581 |
greenCaringForColorBlindness |
7833 | 1582 |
"return the color to use for a darkened green (showing text in that color), |
7832 | 1583 |
possibly using anther color if the settings specifies color blindness" |
1584 |
||
1585 |
UserPreferences current useColorsForColorBlindness ifTrue:[ |
|
1586 |
"/ for now: later, this will also be configurable |
|
1587 |
^ self blue. |
|
1588 |
] ifFalse:[ |
|
7833 | 1589 |
^ self green darkened. |
7832 | 1590 |
]. |
1591 |
||
7833 | 1592 |
" |
1593 |
self greenCaringForColorBlindness |
|
1594 |
" |
|
1595 |
||
7832 | 1596 |
"Created: / 03-02-2017 / 14:02:26 / cg" |
1597 |
! |
|
1598 |
||
1023 | 1599 |
grey |
1600 |
"return the grey color (English version ;-)" |
|
1601 |
||
1602 |
^ self gray |
|
1603 |
||
1604 |
" |
|
1605 |
Color grey inspect |
|
1606 |
" |
|
1607 |
||
1608 |
"Modified: 28.5.1996 / 20:48:26 / cg" |
|
1609 |
! |
|
1610 |
||
1611 |
grey:grey |
|
6353 | 1612 |
"return a grey color (English version). |
1023 | 1613 |
The argument, grey is interpreted as percent (0..100)." |
1614 |
||
1368 | 1615 |
^ self grayPercent:grey |
1023 | 1616 |
|
1617 |
" |
|
1618 |
Color grey:25 |
|
1619 |
Color grey:12.5 |
|
1620 |
" |
|
1621 |
||
1368 | 1622 |
"Modified: 24.2.1997 / 21:33:28 / cg" |
1023 | 1623 |
! |
1624 |
||
5419 | 1625 |
greyByte:greyByte |
6353 | 1626 |
"return a grey color (English version). |
5419 | 1627 |
The argument, grey is interpreted as byte-value (0..255)." |
1628 |
||
1629 |
^ self redByte:greyByte greenByte:greyByte blueByte:greyByte |
|
1630 |
||
1631 |
" |
|
1632 |
Color greyByte:127 |
|
1633 |
" |
|
1634 |
! |
|
1635 |
||
2388
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1636 |
lightBlue |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1637 |
"return a light blue color" |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1638 |
|
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1639 |
^ self redPercent:50 greenPercent:50 bluePercent:100 |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1640 |
|
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1641 |
" |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1642 |
Color lightBlue inspect |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1643 |
" |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1644 |
|
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1645 |
"Modified: 23.4.1996 / 13:23:08 / cg" |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1646 |
! |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1647 |
|
2962 | 1648 |
lightBrown |
1649 |
^ self brown lighter |
|
1650 |
||
1651 |
" |
|
1652 |
Color lightBrown |
|
1653 |
" |
|
1654 |
! |
|
1655 |
||
1023 | 1656 |
lightGray |
1657 |
"return the lightGrey color (US version ;-)" |
|
1658 |
||
1659 |
LightGrey isNil ifTrue:[ |
|
8792 | 1660 |
LightGrey := self grayPercent:67 |
1023 | 1661 |
]. |
1662 |
^ LightGrey |
|
1663 |
||
1664 |
" |
|
1665 |
Color lightGray inspect |
|
8792 | 1666 |
Color gray lightened inspect |
1023 | 1667 |
" |
1668 |
||
1368 | 1669 |
"Modified: 24.2.1997 / 21:33:41 / cg" |
1023 | 1670 |
! |
1671 |
||
2388
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1672 |
lightGreen |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1673 |
"return a light green color" |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1674 |
|
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1675 |
^ self redPercent:50 greenPercent:100 bluePercent:50 |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1676 |
|
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1677 |
" |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1678 |
Color lightGreen inspect |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1679 |
" |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1680 |
|
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1681 |
"Modified: 23.4.1996 / 13:23:08 / cg" |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1682 |
! |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1683 |
|
1023 | 1684 |
lightGrey |
1685 |
"return the lightGrey color (English version ;-)" |
|
1686 |
||
1687 |
^ self lightGray |
|
1688 |
||
1689 |
" |
|
1690 |
Color lightGrey inspect |
|
1691 |
" |
|
1692 |
||
1693 |
"Modified: 28.5.1996 / 20:51:11 / cg" |
|
1694 |
! |
|
1695 |
||
2388
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1696 |
lightRed |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1697 |
"return a light red color" |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1698 |
|
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1699 |
^ self redPercent:100 greenPercent:50 bluePercent:50 |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1700 |
|
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1701 |
" |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1702 |
Color lightRed inspect |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1703 |
" |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1704 |
|
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1705 |
"Modified: 23.4.1996 / 13:23:08 / cg" |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1706 |
! |
8a7f4bb3847c
added lightRed/lightGreen/lightBlue
Claus Gittinger <cg@exept.de>
parents:
2379
diff
changeset
|
1707 |
|
2949 | 1708 |
lightYellow |
1709 |
^ self yellow lighter |
|
1710 |
! |
|
1711 |
||
1023 | 1712 |
magenta |
1713 |
"return the magenta color - ST-80 compatibility" |
|
1714 |
||
2087 | 1715 |
^ self magenta:100 |
1023 | 1716 |
|
1717 |
" |
|
1718 |
Color magenta inspect |
|
1719 |
" |
|
1720 |
||
1721 |
"Modified: 23.4.1996 / 13:23:41 / cg" |
|
1722 |
! |
|
1723 |
||
2087 | 1724 |
magenta: magenta |
1725 |
"return a magenta color; |
|
1726 |
the argument magenta is interpreted as percent (0..100)" |
|
1727 |
||
1728 |
^ self cyan:100-magenta magenta:100 yellow:100-magenta |
|
6353 | 1729 |
|
2087 | 1730 |
! |
1731 |
||
1023 | 1732 |
mediumGray |
1733 |
"return medium-grey color (US version ;-)" |
|
1734 |
||
1735 |
^ self gray |
|
1736 |
||
1737 |
" |
|
1738 |
Color mediumGray inspect |
|
1739 |
" |
|
1740 |
||
1741 |
"Created: 23.4.1996 / 13:24:17 / cg" |
|
1742 |
"Modified: 28.5.1996 / 20:51:21 / cg" |
|
1743 |
! |
|
1744 |
||
1745 |
mediumGrey |
|
1746 |
"return medium-grey color (English version ;-)" |
|
1747 |
||
1748 |
^ self gray |
|
1749 |
||
1750 |
" |
|
1751 |
Color mediumGrey inspect |
|
1752 |
" |
|
1753 |
||
1754 |
"Modified: 28.5.1996 / 20:51:24 / cg" |
|
1755 |
! |
|
1756 |
||
8701 | 1757 |
neonPink |
1758 |
"return the neon pink color" |
|
1759 |
||
1760 |
^ self rgbValue:16rFF66CC |
|
1761 |
||
1762 |
"Created: / 06-06-2019 / 11:55:05 / Claus Gittinger" |
|
1763 |
! |
|
1764 |
||
1023 | 1765 |
orange |
1766 |
"return the orange color - ST-80 compatibility" |
|
1767 |
||
7642 | 1768 |
Orange isNil ifTrue:[ |
7909 | 1769 |
Orange := self rgbValue:16rFFA500. |
7642 | 1770 |
]. |
1771 |
^ Orange |
|
1772 |
||
1773 |
" |
|
1774 |
Color orange inspect |
|
1775 |
" |
|
7909 | 1776 |
|
1777 |
"Modified: / 17-02-2017 / 12:34:20 / cg" |
|
2077
442b9763111c
#orange should return an orange color and not a brown color
tz
parents:
2071
diff
changeset
|
1778 |
! |
442b9763111c
#orange should return an orange color and not a brown color
tz
parents:
2071
diff
changeset
|
1779 |
|
442b9763111c
#orange should return an orange color and not a brown color
tz
parents:
2071
diff
changeset
|
1780 |
orange: orange |
442b9763111c
#orange should return an orange color and not a brown color
tz
parents:
2071
diff
changeset
|
1781 |
"return a orange color; |
442b9763111c
#orange should return an orange color and not a brown color
tz
parents:
2071
diff
changeset
|
1782 |
the argument orange is interpreted as percent (0..100)" |
442b9763111c
#orange should return an orange color and not a brown color
tz
parents:
2071
diff
changeset
|
1783 |
|
442b9763111c
#orange should return an orange color and not a brown color
tz
parents:
2071
diff
changeset
|
1784 |
^ self redPercent:orange greenPercent:orange/2 bluePercent:0 |
6353 | 1785 |
|
1786 |
! |
|
1787 |
||
1788 |
pink |
|
1023 | 1789 |
"return the pink color - ST-80 compatibility" |
1790 |
||
8701 | 1791 |
^ self rgbValue:16rFC0FC0 |
1792 |
||
1793 |
"Modified: / 23-04-1996 / 13:29:38 / cg" |
|
1794 |
"Modified: / 06-06-2019 / 11:56:05 / Claus Gittinger" |
|
1023 | 1795 |
! |
1796 |
||
1797 |
red |
|
1798 |
"return the red color" |
|
1799 |
||
1800 |
Red isNil ifTrue:[ |
|
7642 | 1801 |
Red := self redPercent:100 greenPercent:0 bluePercent:0. |
1023 | 1802 |
]. |
1803 |
^ Red |
|
1804 |
||
7642 | 1805 |
" |
1806 |
Color red inspect |
|
1807 |
" |
|
1808 |
||
1023 | 1809 |
"Modified: 23.4.1996 / 13:29:44 / cg" |
1810 |
! |
|
1811 |
||
7832 | 1812 |
redCaringForColorBlindness |
1813 |
"return the color to use for green, |
|
1814 |
possibly using anther color if the settings specifies color blindness" |
|
1815 |
||
1816 |
UserPreferences current useColorsForColorBlindness ifTrue:[ |
|
1817 |
"/ for now: later, this will also be configurable |
|
1818 |
^ self red. |
|
1819 |
] ifFalse:[ |
|
1820 |
^ self red. |
|
1821 |
]. |
|
1822 |
||
1823 |
"Created: / 03-02-2017 / 14:02:50 / cg" |
|
1824 |
! |
|
1825 |
||
8701 | 1826 |
salmon |
1827 |
"return the salmon color" |
|
1828 |
||
1829 |
^ self rgbValue:16rFDAB9F |
|
1830 |
||
1831 |
"Created: / 06-06-2019 / 11:59:37 / Claus Gittinger" |
|
1832 |
! |
|
1833 |
||
2942
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1834 |
transparent |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1835 |
"return the transparent-color" |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1836 |
|
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1837 |
Transparent isNil ifTrue:[ |
6353 | 1838 |
Transparent := TranslucentColor scaledRed:0 scaledGreen:0 scaledBlue:0. |
1839 |
Transparent setAlphaByte:0. |
|
2942
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1840 |
]. |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1841 |
^ Transparent |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1842 |
|
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1843 |
" |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1844 |
self transparent |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1845 |
" |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1846 |
! |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
1847 |
|
1023 | 1848 |
veryDarkGray |
1849 |
"return a very dark-grey color (US version ;-)" |
|
1850 |
||
1368 | 1851 |
^ self grayPercent:13 |
1023 | 1852 |
|
1853 |
"Created: 23.4.1996 / 13:33:14 / cg" |
|
1368 | 1854 |
"Modified: 24.2.1997 / 21:33:52 / cg" |
1023 | 1855 |
! |
1856 |
||
8660 | 1857 |
veryDarkGreen |
1858 |
"return a very dark green color" |
|
1859 |
||
1860 |
^ self darkGreen darkened |
|
1861 |
||
1862 |
" |
|
1863 |
Color veryDarkGreen |
|
1864 |
" |
|
1865 |
||
1866 |
"Created: / 13-03-2019 / 21:15:31 / Claus Gittinger" |
|
1867 |
! |
|
1868 |
||
1023 | 1869 |
veryDarkGrey |
1870 |
"return a very dark-grey color (English version ;-)" |
|
1871 |
||
1872 |
^ self veryDarkGray |
|
1873 |
||
1874 |
"Modified: 28.5.1996 / 20:52:49 / cg" |
|
1875 |
! |
|
1876 |
||
1877 |
veryLightGray |
|
1878 |
"return a very light-grey color (US version ;-)" |
|
1879 |
||
1368 | 1880 |
^ self grayPercent:87 |
1023 | 1881 |
|
8792 | 1882 |
" |
1883 |
Color veryLightGray inspect |
|
1884 |
Color gray lightened lightened inspect |
|
1885 |
" |
|
1886 |
||
1023 | 1887 |
"Created: 23.4.1996 / 13:33:46 / cg" |
1368 | 1888 |
"Modified: 24.2.1997 / 21:33:58 / cg" |
1023 | 1889 |
! |
1890 |
||
1891 |
veryLightGrey |
|
1892 |
"return a very light-grey color (English version ;-)" |
|
1893 |
||
1894 |
^ self veryLightGray |
|
1895 |
||
1896 |
"Modified: 28.5.1996 / 20:52:03 / cg" |
|
1897 |
! |
|
1898 |
||
3030 | 1899 |
veryVeryLightGray |
1900 |
"return a very very light-grey color (US version ;-)" |
|
1901 |
||
1902 |
^ self grayPercent:93 |
|
1903 |
||
1904 |
! |
|
1905 |
||
1023 | 1906 |
white |
1907 |
"return the white-color" |
|
1908 |
||
1909 |
White isNil ifTrue:[ |
|
7642 | 1910 |
White := self redPercent:100 greenPercent:100 bluePercent:100. |
1023 | 1911 |
]. |
1912 |
^ White |
|
7642 | 1913 |
|
1914 |
" |
|
1915 |
Color white inspect |
|
1916 |
" |
|
1023 | 1917 |
! |
1918 |
||
1919 |
yellow |
|
1920 |
"return the yellow color - ST-80 compatibility" |
|
1921 |
||
7642 | 1922 |
Yellow isNil ifTrue:[ |
1923 |
Yellow := self redPercent:100 greenPercent:100 bluePercent:0. |
|
1924 |
]. |
|
1925 |
^ Yellow |
|
1926 |
||
1927 |
" |
|
1928 |
Color yellow inspect |
|
1929 |
" |
|
1023 | 1930 |
|
1931 |
"Modified: 23.4.1996 / 13:33:56 / cg" |
|
2087 | 1932 |
! |
1933 |
||
1934 |
yellow: yellow |
|
1935 |
"return a yellow color; |
|
1936 |
the argument yellow is interpreted as percent (0..100)" |
|
1937 |
||
1938 |
^ self cyan:100-yellow magenta:100-yellow yellow:100 |
|
6353 | 1939 |
|
1023 | 1940 |
! ! |
1941 |
||
1233 | 1942 |
!Color class methodsFor:'obsolete'! |
1943 |
||
1944 |
nameOrDither:colorName |
|
1945 |
"return a named color - if the exact color is not available, |
|
6353 | 1946 |
return a dithered color. Report an error, if the colorname is |
1233 | 1947 |
illegal." |
1948 |
||
3427 | 1949 |
<resource:#obsolete> |
1950 |
||
1233 | 1951 |
self obsoleteMethodWarning:'use #name:'. |
1952 |
^ self name:colorName |
|
1953 |
||
1954 |
"Modified: 16.1.1997 / 23:01:03 / cg" |
|
1955 |
! |
|
1956 |
||
1957 |
nameOrDither:colorName ifIllegal:errorBlock |
|
1958 |
"return a named color - if the exact color is not available, |
|
1959 |
return a dithered color. If the colorname is illegal, return |
|
1960 |
the value of evaluating errorBlock." |
|
1961 |
||
3427 | 1962 |
<resource:#obsolete> |
1963 |
||
1233 | 1964 |
self obsoleteMethodWarning:'use #name:ifIllegal:'. |
1965 |
^ self name:colorName ifIllegal:errorBlock |
|
1966 |
||
1967 |
"Modified: 16.1.1997 / 23:01:32 / cg" |
|
1968 |
! |
|
1969 |
||
1970 |
nameOrNearest:colorName |
|
1971 |
"return a named color - or its nearest match" |
|
1972 |
||
3427 | 1973 |
<resource:#obsolete> |
1974 |
||
1233 | 1975 |
self obsoleteMethodWarning:'use #name:'. |
1976 |
^ self name:colorName |
|
1977 |
||
1978 |
"Modified: 16.1.1997 / 23:02:18 / cg" |
|
1979 |
! ! |
|
1980 |
||
1144 | 1981 |
!Color class methodsFor:'private'! |
1023 | 1982 |
|
1983 |
colorNearRed:r green:g blue:b on:aDevice |
|
1984 |
"return a device color on aDevice with rgb values |
|
1985 |
almost matching. If there is one, nil otherwise. |
|
1986 |
This is tried as a last chance before dithering. |
|
1987 |
The algorithm needs rework, the color components |
|
1988 |
should be weighted according some theory :-)" |
|
1989 |
||
1990 |
|bestColor minDelta diff rr rg rb dRed| |
|
1991 |
||
1992 |
"/ rr := (r * 3.0) rounded / 3.0. |
|
1993 |
"/ rg := (g * 3.0) rounded / 3.0. |
|
1994 |
"/ rb := (b * 3.0) rounded / 3.0. |
|
1995 |
||
1996 |
rr := r rounded. "round to 1%" |
|
1997 |
rg := (g * 2.0) rounded / 2.0. "round to 0.5%" |
|
1998 |
rb := (b / 2) rounded * 2. "round to 2%" |
|
1999 |
||
2000 |
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
|
2001 |
aDevice deviceColors do:[:aColor | |
6353 | 2002 |
dRed := rr - aColor red. |
2003 |
dRed < 10 ifTrue:[ |
|
2004 |
diff := dRed asInteger squared |
|
2005 |
+ (rg - aColor green) asInteger squared |
|
2006 |
+ (rb - aColor blue) asInteger squared. |
|
2007 |
||
2008 |
diff < minDelta ifTrue:[ |
|
2009 |
diff = 0 ifTrue:[ |
|
2010 |
"got it" |
|
2011 |
^ aColor |
|
2012 |
]. |
|
2013 |
bestColor := aColor. |
|
2014 |
minDelta := diff |
|
2015 |
] |
|
2016 |
] |
|
1023 | 2017 |
]. |
2018 |
||
2019 |
"allow an error of 10% per component" |
|
2020 |
minDelta < (100+100+100) ifTrue:[ ^ bestColor ]. |
|
2021 |
^ nil |
|
2022 |
||
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
2023 |
"Modified: 24.2.1997 / 18:17:24 / cg" |
1023 | 2024 |
! |
2025 |
||
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2026 |
existingColorRed:r green:g blue:b on:aDevice |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2027 |
"return a device color on aDevice with rgb values |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2028 |
if there is one, nil otherwise." |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2029 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2030 |
^ self existingColorScaledRed:(r * MaxValue // 100) |
6353 | 2031 |
scaledGreen:(g * MaxValue // 100) |
2032 |
scaledBlue:(b * MaxValue // 100) |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2033 |
! |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2034 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2035 |
existingColorScaledRed:r scaledGreen:g scaledBlue:b on:aDevice |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2036 |
"return a device color on aDevice with rgb values |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2037 |
if there is one, nil otherwise." |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2038 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2039 |
aDevice deviceColors do:[:aColor | |
6353 | 2040 |
(r == aColor scaledRed) ifTrue:[ |
2041 |
(g == aColor scaledGreen) ifTrue:[ |
|
2042 |
(b == aColor scaledBlue) ifTrue:[ |
|
2043 |
^ aColor |
|
2044 |
] |
|
2045 |
] |
|
2046 |
] |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2047 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2048 |
^ nil |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2049 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2050 |
"Modified: 24.2.1997 / 18:17:35 / cg" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2051 |
! ! |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2052 |
|
3878 | 2053 |
!Color class methodsFor:'private-dithering'! |
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2054 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2055 |
complexDitherRed:red green:green blue:blue on:aDevice into:aBlock |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2056 |
"get a deep dither form for an rgb value. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2057 |
Use all available colors for error dithering into a form." |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2058 |
|
6353 | 2059 |
|errR errG errB f wantR wantG wantB clr |
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2060 |
dir "{ Class: SmallInteger }" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2061 |
start "{ Class: SmallInteger }" |
6353 | 2062 |
end "{ Class: SmallInteger }" |
1929 | 2063 |
map |
2064 |
w "{ Class: SmallInteger }" |
|
2065 |
h "{ Class: SmallInteger }"| |
|
2066 |
||
2067 |
"/ w := h := 32. |
|
2068 |
"/ w := h := 4. |
|
2069 |
w := h := 2. |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2070 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2071 |
errR := 0. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2072 |
errG := 0. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2073 |
errB := 0. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2074 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2075 |
"get a form and clear it" |
4785
ffb3b0caceb8
Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents:
4772
diff
changeset
|
2076 |
f := Form width:w height:h depth:(aDevice depth) onDevice:aDevice. |
7360 | 2077 |
f isNil ifTrue:[^ nil]. |
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2078 |
map := IdentityDictionary new. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2079 |
|
1929 | 2080 |
0 to:(w-1) do:[:x | |
7360 | 2081 |
x even ifTrue:[ |
2082 |
dir := 1. |
|
2083 |
start := 0. |
|
2084 |
end := (h-1). |
|
2085 |
] ifFalse:[ |
|
2086 |
dir := -1. |
|
2087 |
start := (h-1). |
|
2088 |
end := 0. |
|
2089 |
]. |
|
2090 |
start to:end by:dir do:[:y | |
|
2091 |
wantR := red + errR. |
|
2092 |
wantR > MaxValue ifTrue:[ |
|
2093 |
wantR := MaxValue |
|
2094 |
] ifFalse:[ wantR < 0 ifTrue:[ |
|
2095 |
wantR := 0 |
|
2096 |
]]. |
|
2097 |
||
2098 |
wantG := green + errG. |
|
2099 |
wantG > MaxValue ifTrue:[ |
|
2100 |
wantG := MaxValue |
|
2101 |
] ifFalse:[ wantG < 0 ifTrue:[ |
|
2102 |
wantG := 0 |
|
2103 |
]]. |
|
2104 |
||
2105 |
wantB := blue + errB. |
|
2106 |
wantB > MaxValue ifTrue:[ |
|
2107 |
wantB := MaxValue |
|
2108 |
] ifFalse:[ wantB < 0 ifTrue:[ |
|
2109 |
wantB := 0 |
|
2110 |
]]. |
|
2111 |
||
2112 |
"find the nearest color" |
|
2113 |
||
2114 |
clr := Color quickNearestColorScaledRed:wantR scaledGreen:wantG scaledBlue:wantB on:aDevice. |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2115 |
" |
7360 | 2116 |
clr := Color nearestColorScaledRed:wantR green:wantG blue:wantB on:aDevice. |
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2117 |
" |
7360 | 2118 |
clr isNil ifTrue:[ |
2119 |
clr := Color scaledRed:wantR scaledGreen:wantG scaledBlue:wantB. |
|
2120 |
clr brightness > 0.5 ifTrue:[ |
|
2121 |
clr := Color white |
|
2122 |
] ifFalse:[ |
|
2123 |
clr := Color black |
|
2124 |
]. |
|
2125 |
clr := clr onDevice:aDevice |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2126 |
" |
7360 | 2127 |
^ aBlock value:nil value:nil |
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2128 |
" |
7360 | 2129 |
]. |
2130 |
||
2131 |
f paint:clr. |
|
2132 |
f displayPointX:x y:y. |
|
2133 |
map at:clr colorId + 1 put:clr. |
|
2134 |
||
2135 |
"compute the new error" |
|
2136 |
errR := wantR - clr scaledRed. |
|
2137 |
errG := wantG - clr scaledGreen. |
|
2138 |
errB := wantB - clr scaledBlue. |
|
2139 |
]. |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2140 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2141 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2142 |
f colorMap:map. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2143 |
" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2144 |
'hard dither' printNewline. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2145 |
" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2146 |
^ aBlock value:nil value:f |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2147 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2148 |
"Created: 3.5.1997 / 11:02:47 / cg" |
1929 | 2149 |
"Modified: 19.10.1997 / 23:28:59 / cg" |
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2150 |
! |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2151 |
|
1023 | 2152 |
ditherBits |
2153 |
"return a dither pattern for x/64; x in 1..63" |
|
2154 |
||
2155 |
^ #( |
|
2156 |
||
6353 | 2157 |
"/ 1in64 |
2158 |
||
2159 |
#[2r10000000 |
|
2160 |
2r00000000 |
|
2161 |
2r00000000 |
|
2162 |
2r00000000 |
|
2163 |
2r00000000 |
|
2164 |
2r00000000 |
|
2165 |
2r00000000 |
|
2166 |
2r00000000] |
|
2167 |
||
2168 |
"/ 2in64 |
|
2169 |
||
2170 |
#[2r10000000 |
|
2171 |
2r00000000 |
|
2172 |
2r00000000 |
|
2173 |
2r00000000 |
|
2174 |
2r00001000 |
|
2175 |
2r00000000 |
|
2176 |
2r00000000 |
|
2177 |
2r00000000] |
|
2178 |
||
2179 |
"/ 3in64 |
|
2180 |
||
2181 |
#[2r10000000 |
|
2182 |
2r00000000 |
|
2183 |
2r00000000 |
|
2184 |
2r00000000 |
|
2185 |
2r10001000 |
|
2186 |
2r00000000 |
|
2187 |
2r00000000 |
|
2188 |
2r00000000] |
|
2189 |
||
2190 |
"/ 4in64 |
|
2191 |
||
2192 |
#[2r10001000 |
|
2193 |
2r00000000 |
|
2194 |
2r00000000 |
|
2195 |
2r00000000 |
|
2196 |
2r10001000 |
|
2197 |
2r00000000 |
|
2198 |
2r00000000 |
|
2199 |
2r00000000] |
|
2200 |
||
2201 |
"/ 5in64 |
|
2202 |
||
2203 |
#[2r10001000 |
|
2204 |
2r00000000 |
|
2205 |
2r00000000 |
|
2206 |
2r00000000 |
|
2207 |
2r10001000 |
|
2208 |
2r00000000 |
|
2209 |
2r00000010 |
|
2210 |
2r00000000] |
|
2211 |
||
2212 |
"/ 6in64 |
|
2213 |
||
2214 |
#[2r10001000 |
|
2215 |
2r00000000 |
|
2216 |
2r00100000 |
|
2217 |
2r00000000 |
|
2218 |
2r10001000 |
|
2219 |
2r00000000 |
|
2220 |
2r00000010 |
|
2221 |
2r00000000] |
|
2222 |
||
2223 |
"/ 7in64 |
|
2224 |
||
2225 |
#[2r10001000 |
|
2226 |
2r00000000 |
|
2227 |
2r00100010 |
|
2228 |
2r00000000 |
|
2229 |
2r10001000 |
|
2230 |
2r00000000 |
|
2231 |
2r00000010 |
|
2232 |
2r00000000] |
|
2233 |
||
2234 |
"/ 8in64 |
|
2235 |
||
2236 |
#[2r10001000 |
|
2237 |
2r00000000 |
|
2238 |
2r00100010 |
|
2239 |
2r00000000 |
|
2240 |
2r10001000 |
|
2241 |
2r00000000 |
|
2242 |
2r00100010 |
|
2243 |
2r00000000] |
|
2244 |
||
2245 |
"/ 9in64 |
|
2246 |
||
2247 |
#[2r10001000 |
|
2248 |
2r00000000 |
|
2249 |
2r00100010 |
|
2250 |
2r00000000 |
|
2251 |
2r10001000 |
|
2252 |
2r00000000 |
|
2253 |
2r10100010 |
|
2254 |
2r00000000] |
|
2255 |
||
2256 |
"/ 10in64 |
|
2257 |
||
2258 |
#[2r10001000 |
|
2259 |
2r00000000 |
|
2260 |
2r00101010 |
|
2261 |
2r00000000 |
|
2262 |
2r10001000 |
|
2263 |
2r00000000 |
|
2264 |
2r10100010 |
|
2265 |
2r00000000] |
|
2266 |
||
2267 |
"/ 11in64 |
|
2268 |
||
2269 |
#[2r10001000 |
|
2270 |
2r00000000 |
|
2271 |
2r00101010 |
|
2272 |
2r00000000 |
|
2273 |
2r10001000 |
|
2274 |
2r00000000 |
|
2275 |
2r10101010 |
|
2276 |
2r00000000] |
|
2277 |
||
2278 |
"/ 12in64 |
|
2279 |
||
2280 |
#[2r10001000 |
|
2281 |
2r00000000 |
|
2282 |
2r10101010 |
|
2283 |
2r00000000 |
|
2284 |
2r10001000 |
|
2285 |
2r00000000 |
|
2286 |
2r10101010 |
|
2287 |
2r00000000] |
|
2288 |
||
2289 |
"/ 13in64 |
|
2290 |
||
2291 |
#[2r10001000 |
|
2292 |
2r00000000 |
|
2293 |
2r10101010 |
|
2294 |
2r00000000 |
|
2295 |
2r10101000 |
|
2296 |
2r00000000 |
|
2297 |
2r10101010 |
|
2298 |
2r00000000] |
|
2299 |
||
2300 |
"/ 14in64 |
|
2301 |
||
2302 |
#[2r10001010 |
|
2303 |
2r00000000 |
|
2304 |
2r10101010 |
|
2305 |
2r00000000 |
|
2306 |
2r10101000 |
|
2307 |
2r00000000 |
|
2308 |
2r10101010 |
|
2309 |
2r00000000] |
|
2310 |
||
2311 |
"/ 15in64 |
|
2312 |
||
2313 |
#[2r10001010 |
|
2314 |
2r00000000 |
|
2315 |
2r10101010 |
|
2316 |
2r00000000 |
|
2317 |
2r10101010 |
|
2318 |
2r00000000 |
|
2319 |
2r10101010 |
|
2320 |
2r00000000] |
|
2321 |
||
2322 |
"/ 16in64 |
|
2323 |
||
2324 |
#[2r10101010 |
|
2325 |
2r00000000 |
|
2326 |
2r10101010 |
|
2327 |
2r00000000 |
|
2328 |
2r10101010 |
|
2329 |
2r00000000 |
|
2330 |
2r10101010 |
|
2331 |
2r00000000] |
|
2332 |
||
2333 |
"/ 17in64 |
|
2334 |
||
2335 |
#[2r10101010 |
|
2336 |
2r01000000 |
|
2337 |
2r10101010 |
|
2338 |
2r00000000 |
|
2339 |
2r10101010 |
|
2340 |
2r00000000 |
|
2341 |
2r10101010 |
|
2342 |
2r00000000] |
|
2343 |
||
2344 |
"/ 18in64 |
|
2345 |
||
2346 |
#[2r10101010 |
|
2347 |
2r01000000 |
|
2348 |
2r10101010 |
|
2349 |
2r00000000 |
|
2350 |
2r10101010 |
|
2351 |
2r00000100 |
|
2352 |
2r10101010 |
|
2353 |
2r00000000] |
|
2354 |
||
2355 |
"/ 19in64 |
|
2356 |
||
2357 |
#[2r10101010 |
|
2358 |
2r01000000 |
|
2359 |
2r10101010 |
|
2360 |
2r00000000 |
|
2361 |
2r10101010 |
|
2362 |
2r01000100 |
|
2363 |
2r10101010 |
|
2364 |
2r00000000] |
|
2365 |
||
2366 |
"/ 20in64 |
|
2367 |
||
2368 |
#[2r10101010 |
|
2369 |
2r01000100 |
|
2370 |
2r10101010 |
|
2371 |
2r00000000 |
|
2372 |
2r10101010 |
|
2373 |
2r01000100 |
|
2374 |
2r10101010 |
|
2375 |
2r00000000] |
|
2376 |
||
2377 |
"/ 21in64 |
|
2378 |
||
2379 |
#[2r10101010 |
|
2380 |
2r01000100 |
|
2381 |
2r10101010 |
|
2382 |
2r00000000 |
|
2383 |
2r10101010 |
|
2384 |
2r01000100 |
|
2385 |
2r10101010 |
|
2386 |
2r00000001] |
|
2387 |
||
2388 |
"/ 22in64 |
|
2389 |
||
2390 |
#[2r10101010 |
|
2391 |
2r01000100 |
|
2392 |
2r10101010 |
|
2393 |
2r00010000 |
|
2394 |
2r10101010 |
|
2395 |
2r01000100 |
|
2396 |
2r10101010 |
|
2397 |
2r00000001] |
|
2398 |
||
2399 |
"/ 23in64 |
|
2400 |
||
2401 |
#[2r10101010 |
|
2402 |
2r01000100 |
|
2403 |
2r10101010 |
|
2404 |
2r00010001 |
|
2405 |
2r10101010 |
|
2406 |
2r01000100 |
|
2407 |
2r10101010 |
|
2408 |
2r00000001] |
|
2409 |
||
2410 |
"/ 24in64 |
|
2411 |
||
2412 |
#[2r10101010 |
|
2413 |
2r01000100 |
|
2414 |
2r10101010 |
|
2415 |
2r00010001 |
|
2416 |
2r10101010 |
|
2417 |
2r01000100 |
|
2418 |
2r10101010 |
|
2419 |
2r00010001] |
|
2420 |
||
2421 |
"/ 25in64 |
|
2422 |
||
2423 |
#[2r10101010 |
|
2424 |
2r01000100 |
|
2425 |
2r10101010 |
|
2426 |
2r00010001 |
|
2427 |
2r10101010 |
|
2428 |
2r01000100 |
|
2429 |
2r10101010 |
|
2430 |
2r01010001] |
|
2431 |
||
2432 |
"/ 26in64 |
|
2433 |
||
2434 |
#[2r10101010 |
|
2435 |
2r01000100 |
|
2436 |
2r10101010 |
|
2437 |
2r00010101 |
|
2438 |
2r10101010 |
|
2439 |
2r01000100 |
|
2440 |
2r10101010 |
|
2441 |
2r01010001] |
|
2442 |
||
2443 |
"/ 27in64 |
|
2444 |
||
2445 |
#[2r10101010 |
|
2446 |
2r01000100 |
|
2447 |
2r10101010 |
|
2448 |
2r00010101 |
|
2449 |
2r10101010 |
|
2450 |
2r01000100 |
|
2451 |
2r10101010 |
|
2452 |
2r01010101] |
|
2453 |
||
2454 |
"/ 28in64 |
|
2455 |
||
2456 |
#[2r10101010 |
|
2457 |
2r01000100 |
|
2458 |
2r10101010 |
|
2459 |
2r01010101 |
|
2460 |
2r10101010 |
|
2461 |
2r01000100 |
|
2462 |
2r10101010 |
|
2463 |
2r01010101] |
|
2464 |
||
2465 |
"/ 29in64 |
|
2466 |
||
2467 |
#[2r10101010 |
|
2468 |
2r01000100 |
|
2469 |
2r10101010 |
|
2470 |
2r01010101 |
|
2471 |
2r10101010 |
|
2472 |
2r01010100 |
|
2473 |
2r10101010 |
|
2474 |
2r01010101] |
|
2475 |
||
2476 |
"/ 30in64 |
|
2477 |
||
2478 |
#[2r10101010 |
|
2479 |
2r01000101 |
|
2480 |
2r10101010 |
|
2481 |
2r01010101 |
|
2482 |
2r10101010 |
|
2483 |
2r01010100 |
|
2484 |
2r10101010 |
|
2485 |
2r01010101] |
|
2486 |
||
2487 |
"/ 31in64 |
|
2488 |
||
2489 |
#[2r10101010 |
|
2490 |
2r01000101 |
|
2491 |
2r10101010 |
|
2492 |
2r01010101 |
|
2493 |
2r10101010 |
|
2494 |
2r01010101 |
|
2495 |
2r10101010 |
|
2496 |
2r01010101] |
|
2497 |
||
2498 |
"/ 32in64 |
|
2499 |
||
2500 |
#[2r10101010 |
|
2501 |
2r01010101 |
|
2502 |
2r10101010 |
|
2503 |
2r01010101 |
|
2504 |
2r10101010 |
|
2505 |
2r01010101 |
|
2506 |
2r10101010 |
|
2507 |
2r01010101] |
|
2508 |
||
2509 |
"/ 33in64 |
|
2510 |
||
2511 |
#[2r11101010 |
|
2512 |
2r01010101 |
|
2513 |
2r10101010 |
|
2514 |
2r01010101 |
|
2515 |
2r10101010 |
|
2516 |
2r01010101 |
|
2517 |
2r10101010 |
|
2518 |
2r01010101] |
|
2519 |
||
2520 |
"/ 34in64 |
|
2521 |
||
2522 |
#[2r11101010 |
|
2523 |
2r01010101 |
|
2524 |
2r10101010 |
|
2525 |
2r01010101 |
|
2526 |
2r10101110 |
|
2527 |
2r01010101 |
|
2528 |
2r10101010 |
|
2529 |
2r01010101] |
|
2530 |
||
2531 |
"/ 35in64 |
|
2532 |
||
2533 |
#[2r11101010 |
|
2534 |
2r01010101 |
|
2535 |
2r10101010 |
|
2536 |
2r01010101 |
|
2537 |
2r11101110 |
|
2538 |
2r01010101 |
|
2539 |
2r10101010 |
|
2540 |
2r01010101] |
|
2541 |
||
2542 |
"/ 36in64 |
|
2543 |
||
2544 |
#[2r11101110 |
|
2545 |
2r01010101 |
|
2546 |
2r10101010 |
|
2547 |
2r01010101 |
|
2548 |
2r11101110 |
|
2549 |
2r01010101 |
|
2550 |
2r10101010 |
|
2551 |
2r01010101] |
|
2552 |
||
2553 |
"/ 37in64 |
|
2554 |
||
2555 |
#[2r11101110 |
|
2556 |
2r01010101 |
|
2557 |
2r10101010 |
|
2558 |
2r01010101 |
|
2559 |
2r11101110 |
|
2560 |
2r01010101 |
|
2561 |
2r10101011 |
|
2562 |
2r01010101] |
|
2563 |
||
2564 |
"/ 38in64 |
|
2565 |
||
2566 |
#[2r11101110 |
|
2567 |
2r01010101 |
|
2568 |
2r10111010 |
|
2569 |
2r01010101 |
|
2570 |
2r11101110 |
|
2571 |
2r01010101 |
|
2572 |
2r10101011 |
|
2573 |
2r01010101] |
|
2574 |
||
2575 |
"/ 39in64 |
|
2576 |
||
2577 |
#[2r11101110 |
|
2578 |
2r01010101 |
|
2579 |
2r10111011 |
|
2580 |
2r01010101 |
|
2581 |
2r11101110 |
|
2582 |
2r01010101 |
|
2583 |
2r10101011 |
|
2584 |
2r01010101] |
|
2585 |
||
2586 |
"/ 40in64 |
|
2587 |
||
2588 |
#[2r11101110 |
|
2589 |
2r01010101 |
|
2590 |
2r10111011 |
|
2591 |
2r01010101 |
|
2592 |
2r11101110 |
|
2593 |
2r01010101 |
|
2594 |
2r10111011 |
|
2595 |
2r01010101] |
|
2596 |
||
2597 |
"/ 41in64 |
|
2598 |
||
2599 |
#[2r11101110 |
|
2600 |
2r01010101 |
|
2601 |
2r10111011 |
|
2602 |
2r01010101 |
|
2603 |
2r11101110 |
|
2604 |
2r01010101 |
|
2605 |
2r11111011 |
|
2606 |
2r01010101] |
|
2607 |
||
2608 |
"/ 42in64 |
|
2609 |
||
2610 |
#[2r11101110 |
|
2611 |
2r01010101 |
|
2612 |
2r10111111 |
|
2613 |
2r01010101 |
|
2614 |
2r11101110 |
|
2615 |
2r01010101 |
|
2616 |
2r11111011 |
|
2617 |
2r01010101] |
|
2618 |
||
2619 |
"/ 43in64 |
|
2620 |
||
2621 |
#[2r11101110 |
|
2622 |
2r01010101 |
|
2623 |
2r10111111 |
|
2624 |
2r01010101 |
|
2625 |
2r11101110 |
|
2626 |
2r01010101 |
|
2627 |
2r11111111 |
|
2628 |
2r01010101] |
|
2629 |
||
2630 |
"/ 44in64 |
|
2631 |
||
2632 |
#[2r11101110 |
|
2633 |
2r01010101 |
|
2634 |
2r11111111 |
|
2635 |
2r01010101 |
|
2636 |
2r11101110 |
|
2637 |
2r01010101 |
|
2638 |
2r11111111 |
|
2639 |
2r01010101] |
|
2640 |
||
2641 |
"/ 45in64 |
|
2642 |
||
2643 |
#[2r11101110 |
|
2644 |
2r01010101 |
|
2645 |
2r11111111 |
|
2646 |
2r01010101 |
|
2647 |
2r11111110 |
|
2648 |
2r01010101 |
|
2649 |
2r11111111 |
|
2650 |
2r01010101] |
|
2651 |
||
2652 |
"/ 46in64 |
|
2653 |
||
2654 |
#[2r11101111 |
|
2655 |
2r01010101 |
|
2656 |
2r11111111 |
|
2657 |
2r01010101 |
|
2658 |
2r11111110 |
|
2659 |
2r01010101 |
|
2660 |
2r11111111 |
|
2661 |
2r01010101] |
|
2662 |
||
2663 |
"/ 47in64 |
|
2664 |
||
2665 |
#[2r11101111 |
|
2666 |
2r01010101 |
|
2667 |
2r11111111 |
|
2668 |
2r01010101 |
|
2669 |
2r11111111 |
|
2670 |
2r01010101 |
|
2671 |
2r11111111 |
|
2672 |
2r01010101] |
|
2673 |
||
2674 |
"/ 48in64 |
|
2675 |
||
2676 |
#[2r11111111 |
|
2677 |
2r01010101 |
|
2678 |
2r11111111 |
|
2679 |
2r01010101 |
|
2680 |
2r11111111 |
|
2681 |
2r01010101 |
|
2682 |
2r11111111 |
|
2683 |
2r01010101] |
|
2684 |
||
2685 |
"/ 49in64 |
|
2686 |
||
2687 |
#[2r11111111 |
|
2688 |
2r01110101 |
|
2689 |
2r11111111 |
|
2690 |
2r01010101 |
|
2691 |
2r11111111 |
|
2692 |
2r01010101 |
|
2693 |
2r11111111 |
|
2694 |
2r01010101] |
|
2695 |
||
2696 |
"/ 50in64 |
|
2697 |
||
2698 |
#[2r11111111 |
|
2699 |
2r01110101 |
|
2700 |
2r11111111 |
|
2701 |
2r01010101 |
|
2702 |
2r11111111 |
|
2703 |
2r01010111 |
|
2704 |
2r11111111 |
|
2705 |
2r01010101] |
|
2706 |
||
2707 |
"/ 51in64 |
|
2708 |
||
2709 |
#[2r11111111 |
|
2710 |
2r01110101 |
|
2711 |
2r11111111 |
|
2712 |
2r01010101 |
|
2713 |
2r11111111 |
|
2714 |
2r01110111 |
|
2715 |
2r11111111 |
|
2716 |
2r01010101] |
|
2717 |
||
2718 |
"/ 52in64 |
|
2719 |
||
2720 |
#[2r11111111 |
|
2721 |
2r01110111 |
|
2722 |
2r11111111 |
|
2723 |
2r01010101 |
|
2724 |
2r11111111 |
|
2725 |
2r01110111 |
|
2726 |
2r11111111 |
|
2727 |
2r01010101] |
|
2728 |
||
2729 |
"/ 53in64 |
|
2730 |
||
2731 |
#[2r11111111 |
|
2732 |
2r01110111 |
|
2733 |
2r11111111 |
|
2734 |
2r01010101 |
|
2735 |
2r11111111 |
|
2736 |
2r01110111 |
|
2737 |
2r11111111 |
|
2738 |
2r11010101] |
|
2739 |
||
2740 |
"/ 54in64 |
|
2741 |
||
2742 |
#[2r11111111 |
|
2743 |
2r01110111 |
|
2744 |
2r11111111 |
|
2745 |
2r01011101 |
|
2746 |
2r11111111 |
|
2747 |
2r01110111 |
|
2748 |
2r11111111 |
|
2749 |
2r11010101] |
|
2750 |
||
2751 |
"/ 55in64 |
|
2752 |
||
2753 |
#[2r11111111 |
|
2754 |
2r01110111 |
|
2755 |
2r11111111 |
|
2756 |
2r11011101 |
|
2757 |
2r11111111 |
|
2758 |
2r01110111 |
|
2759 |
2r11111111 |
|
2760 |
2r11010101] |
|
2761 |
||
2762 |
"/ 56in64 |
|
2763 |
||
2764 |
#[2r11111111 |
|
2765 |
2r01110111 |
|
2766 |
2r11111111 |
|
2767 |
2r11011101 |
|
2768 |
2r11111111 |
|
2769 |
2r01110111 |
|
2770 |
2r11111111 |
|
2771 |
2r11011101] |
|
2772 |
||
2773 |
"/ 57in64 |
|
2774 |
||
2775 |
#[2r11111111 |
|
2776 |
2r01110111 |
|
2777 |
2r11111111 |
|
2778 |
2r11011101 |
|
2779 |
2r11111111 |
|
2780 |
2r01110111 |
|
2781 |
2r11111111 |
|
2782 |
2r11111101] |
|
2783 |
||
2784 |
"/ 58in64 |
|
2785 |
||
2786 |
#[2r11111111 |
|
2787 |
2r01110111 |
|
2788 |
2r11111111 |
|
2789 |
2r11011111 |
|
2790 |
2r11111111 |
|
2791 |
2r01110111 |
|
2792 |
2r11111111 |
|
2793 |
2r11111101] |
|
2794 |
||
2795 |
"/ 59in64 |
|
2796 |
||
2797 |
#[2r11111111 |
|
2798 |
2r01110111 |
|
2799 |
2r11111111 |
|
2800 |
2r11011111 |
|
2801 |
2r11111111 |
|
2802 |
2r01110111 |
|
2803 |
2r11111111 |
|
2804 |
2r11111111] |
|
2805 |
||
2806 |
"/ 60in64 |
|
2807 |
||
2808 |
#[2r11111111 |
|
2809 |
2r01110111 |
|
2810 |
2r11111111 |
|
2811 |
2r11111111 |
|
2812 |
2r11111111 |
|
2813 |
2r01110111 |
|
2814 |
2r11111111 |
|
2815 |
2r11111111] |
|
2816 |
||
2817 |
"/ 61in64 |
|
2818 |
||
2819 |
#[2r11111111 |
|
2820 |
2r01110111 |
|
2821 |
2r11111111 |
|
2822 |
2r11111111 |
|
2823 |
2r11111111 |
|
2824 |
2r01111111 |
|
2825 |
2r11111111 |
|
2826 |
2r11111111] |
|
2827 |
||
2828 |
"/ 62in64 |
|
2829 |
||
2830 |
#[2r11111111 |
|
2831 |
2r11110111 |
|
2832 |
2r11111111 |
|
2833 |
2r11111111 |
|
2834 |
2r11111111 |
|
2835 |
2r01111111 |
|
2836 |
2r11111111 |
|
2837 |
2r11111111] |
|
2838 |
||
2839 |
"/ 63in64 |
|
2840 |
||
2841 |
#[2r11111111 |
|
2842 |
2r11110111 |
|
2843 |
2r11111111 |
|
2844 |
2r11111111 |
|
2845 |
2r11111111 |
|
2846 |
2r11111111 |
|
2847 |
2r11111111 |
|
2848 |
2r11111111] |
|
1023 | 2849 |
) |
2850 |
||
2851 |
"Modified: 23.4.1996 / 13:31:50 / cg" |
|
2852 |
"Created: 11.6.1996 / 15:34:29 / cg" |
|
2853 |
! |
|
2854 |
||
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2855 |
ditherGrayFor:fraction on:aDevice into:aBlock |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2856 |
"get a dither form or colorId for a brightness value. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2857 |
Fraction is 0..1. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2858 |
Returns 2 values (either color or ditherForm) through aBlock." |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2859 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2860 |
|d nGray grayBelow scaledGrey scaledGray1 scaledGray2 clr1 clr2 newFraction step| |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2861 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2862 |
d := aDevice depth. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2863 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2864 |
"/ special code for b&w displays |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2865 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2866 |
d == 1 ifTrue:[ |
6353 | 2867 |
aDevice blackpixel == 0 ifTrue:[ |
2868 |
clr1 := Black. |
|
2869 |
clr2 := White. |
|
2870 |
newFraction := fraction. |
|
2871 |
] ifFalse:[ |
|
2872 |
clr1 := White. |
|
2873 |
clr2 := Black. |
|
2874 |
newFraction := 1 - fraction |
|
2875 |
] |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2876 |
] ifFalse:[ |
6353 | 2877 |
"/ special code for 2-plane displays (NeXT) |
2878 |
||
2879 |
d == 2 ifTrue:[ |
|
2880 |
fraction <= 0.01 ifTrue:[ |
|
2881 |
clr1 := Black exactOn:aDevice |
|
2882 |
] ifFalse:[ |
|
2883 |
(fraction between:0.32 and:0.34) ifTrue:[ |
|
2884 |
clr1 := (Color gray:33) exactOn:aDevice |
|
2885 |
] ifFalse:[ |
|
2886 |
(fraction between:0.66 and:0.68) ifTrue:[ |
|
2887 |
clr1 := (Color gray:67) exactOn:aDevice |
|
2888 |
] ifFalse:[ |
|
2889 |
fraction >= 0.99 ifTrue:[ |
|
2890 |
clr1 := White exactOn:aDevice |
|
2891 |
] |
|
2892 |
] |
|
2893 |
] |
|
2894 |
]. |
|
2895 |
clr1 notNil ifTrue:[ |
|
2896 |
^ aBlock value:clr1 value:nil |
|
2897 |
]. |
|
2898 |
||
2899 |
(fraction between:0 and:0.33) ifTrue:[ |
|
2900 |
clr1 := Black. |
|
2901 |
clr2 := Color gray:33. |
|
2902 |
] ifFalse:[ |
|
2903 |
(fraction between:0.34 and:0.66) ifTrue:[ |
|
2904 |
clr1 := Color gray:33. |
|
2905 |
clr2 := Color gray:67. |
|
2906 |
] ifFalse:[ |
|
2907 |
clr1 := Color gray:67. |
|
2908 |
clr2 := White. |
|
2909 |
] |
|
2910 |
]. |
|
2911 |
scaledGray1 := clr1 scaledRed. |
|
2912 |
scaledGray2 := clr2 scaledRed. |
|
2913 |
||
2914 |
scaledGrey := (MaxValue * fraction) rounded. |
|
2915 |
] ifFalse:[ |
|
2916 |
nGray := (1 bitShift:d) - 1. |
|
2917 |
||
2918 |
"/ scale greyValue into grey levels |
|
2919 |
||
2920 |
grayBelow := (fraction * nGray) truncated. |
|
2921 |
||
2922 |
grayBelow < 0 ifTrue:[ |
|
2923 |
^ Color black exactOn:aDevice |
|
2924 |
]. |
|
2925 |
grayBelow >= nGray ifTrue:[ |
|
2926 |
^ Color white exactOn:aDevice |
|
2927 |
]. |
|
2928 |
||
2929 |
scaledGrey := (MaxValue * fraction) rounded. |
|
2930 |
||
2931 |
step := MaxValue // nGray. |
|
2932 |
scaledGray1 := grayBelow * step. |
|
2933 |
scaledGray2 := scaledGray1 + step. |
|
2934 |
||
2935 |
clr1 := Color scaledGray:scaledGray1. |
|
2936 |
clr2 := Color scaledGray:scaledGray2. |
|
2937 |
]. |
|
2938 |
||
2939 |
"/ scale remainder in between low..high |
|
2940 |
newFraction := (scaledGrey - scaledGray1) asFloat / (scaledGray2 - scaledGray1). |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2941 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2942 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2943 |
clr1 := clr1 exactOn:aDevice. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2944 |
clr2 := clr2 exactOn:aDevice. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2945 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2946 |
(clr1 isNil or:[clr2 isNil]) ifTrue:[ |
6353 | 2947 |
"/ fall back to b&w dither |
2948 |
aDevice blackpixel == 0 ifTrue:[ |
|
2949 |
clr1 := Black. |
|
2950 |
clr2 := White. |
|
2951 |
newFraction := fraction. |
|
2952 |
] ifFalse:[ |
|
2953 |
clr1 := White. |
|
2954 |
clr2 := Black. |
|
2955 |
newFraction := 1 - fraction |
|
2956 |
] |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2957 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2958 |
|
6353 | 2959 |
^ self |
2960 |
monoDitherFor:newFraction |
|
2961 |
between:clr1 and:clr2 |
|
2962 |
on:aDevice |
|
2963 |
into:aBlock |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2964 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2965 |
" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2966 |
Color basicNew |
6353 | 2967 |
ditherGrayFor:0.5 |
2968 |
on:Display |
|
2969 |
into:[:clr :form | clr notNil ifTrue:[clr inspect]. |
|
2970 |
form notNil ifTrue:[(form magnifiedBy:16) inspect].] |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2971 |
" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2972 |
" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2973 |
Color basicNew |
6353 | 2974 |
ditherGrayFor:0.25 |
2975 |
on:Display |
|
2976 |
into:[:clr :form | clr notNil ifTrue:[clr inspect]. |
|
2977 |
form notNil ifTrue:[(form magnifiedBy:16) inspect].] |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2978 |
" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2979 |
|
5779
def9764b9b8a
changed: #ditherGrayFor:on:into:
Claus Gittinger <cg@exept.de>
parents:
5689
diff
changeset
|
2980 |
"Created: / 03-05-1997 / 10:59:57 / cg" |
def9764b9b8a
changed: #ditherGrayFor:on:into:
Claus Gittinger <cg@exept.de>
parents:
5689
diff
changeset
|
2981 |
"Modified: / 24-07-2011 / 07:18:00 / cg" |
1023 | 2982 |
! |
2983 |
||
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2984 |
ditherRed:rV green:gV blue:bV on:aDevice into:aBlock |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2985 |
"get a dither form or colorId for an rgb value. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2986 |
Returns 2 values (either color or ditherForm) through |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2987 |
aBlock. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2988 |
This code is just a minimum of what is really needed, |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2989 |
and needs much more work. Currently only some special cases |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2990 |
are handled" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2991 |
|
6353 | 2992 |
|rh rl rs |
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2993 |
lowL hiL lowValL hiValL lowS hiS lowValS hiValS lowH hiH lowValH hiValH d| |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2994 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2995 |
"get hls (since we dither anyway, round them a bit" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
2996 |
|
7798 | 2997 |
Color withHLSFromScaledRed:rV scaledGreen:gV scaledBlue:bV do:[:hue :light :saturation | |
2998 |
hue notNil ifTrue:[ |
|
2999 |
rh := (hue * 3.0) rounded / 3.0. |
|
3000 |
]. |
|
3001 |
rl := (light * 3.0) rounded / 3.0. |
|
3002 |
rs := (saturation * 3.0) rounded / 3.0. |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3003 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3004 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3005 |
rh isNil ifTrue:[ |
7798 | 3006 |
"achromatic, dither between achromatic colors" |
3007 |
||
3008 |
lowL := nil. |
|
3009 |
hiL := nil. |
|
3010 |
||
3011 |
"find the 2 bounding colors" |
|
3012 |
aDevice deviceColors do:[:aColor | |
|
3013 |
aColor colorId notNil ifTrue:[ |
|
3014 |
||
3015 |
Color withHLSFromRed:aColor red green:aColor green blue:aColor blue do:[:hue :light :saturation | |
|
3016 |
| cl | |
|
3017 |
||
3018 |
hue isNil ifTrue:[ |
|
3019 |
cl := (light * 3.0) rounded / 3.0. |
|
3020 |
||
3021 |
cl > rl ifTrue:[ |
|
3022 |
hiL isNil ifTrue:[ |
|
3023 |
hiL := aColor. |
|
3024 |
hiValL := cl. |
|
3025 |
] ifFalse:[ |
|
3026 |
cl < hiValL ifTrue:[ |
|
3027 |
hiL := aColor. |
|
3028 |
hiValL := cl. |
|
3029 |
] |
|
3030 |
] |
|
3031 |
] ifFalse:[ |
|
3032 |
lowL isNil ifTrue:[ |
|
3033 |
lowL := aColor. |
|
3034 |
lowValL := cl |
|
3035 |
] ifFalse:[ |
|
3036 |
cl > lowValL ifTrue:[ |
|
3037 |
lowL := aColor. |
|
3038 |
lowValL := cl |
|
3039 |
] |
|
3040 |
] |
|
3041 |
] |
|
3042 |
] |
|
3043 |
] |
|
3044 |
] |
|
3045 |
]. |
|
3046 |
||
3047 |
(lowL notNil and:[hiL notNil]) ifTrue:[ |
|
3048 |
^ self |
|
3049 |
monoDitherFor:1.0 / (hiValL - lowValL) * (rl - lowValL) |
|
3050 |
between:lowL and:hiL |
|
3051 |
on:aDevice |
|
3052 |
into:aBlock |
|
3053 |
]. |
|
3054 |
"cannot happen, should always find at least black and white" |
|
3055 |
'Color [info]: oops - color to dither is not bound by b&w' infoPrintCR. |
|
3056 |
||
3057 |
^ aBlock value:nil value:nil |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3058 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3059 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3060 |
"chromatic case" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3061 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3062 |
aDevice hasColors ifFalse:[ |
7798 | 3063 |
"no chance, return nil values" |
3064 |
^ aBlock value:nil value:nil |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3065 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3066 |
(Red isNil or:[Green isNil or:[Blue isNil]]) ifTrue:[ |
7798 | 3067 |
"if we where not able to get primary colors: no chance" |
3068 |
^ aBlock value:nil value:nil |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3069 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3070 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3071 |
"try to find two bounding colors with same hue and saturation; |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3072 |
dither on light between those" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3073 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3074 |
lowL := nil. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3075 |
hiL := nil. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3076 |
lowS := nil. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3077 |
hiS := nil. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3078 |
lowH := nil. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3079 |
hiH := nil. |
1023 | 3080 |
|
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
3081 |
aDevice deviceColors do:[:aColor | |
7798 | 3082 |
aColor colorId notNil ifTrue:[ |
3083 |
Color withHLSFromRed:aColor red green:aColor green blue:aColor blue do:[:hue :light :saturation | |
|
3084 |
| cl ch cs| |
|
3085 |
||
3086 |
hue notNil ifTrue:[ |
|
3087 |
ch := (hue * 3.0) rounded / 3.0. |
|
3088 |
] ifFalse:[ |
|
3089 |
ch := nil |
|
3090 |
]. |
|
3091 |
cl := (light * 3.0) rounded / 3.0. |
|
3092 |
cs := (saturation * 3.0) rounded / 3.0. |
|
3093 |
||
3094 |
((ch = rh) and:[cs = rs]) ifTrue:[ |
|
3095 |
"found a color with same saturation and same hue, keep for light" |
|
3096 |
||
3097 |
cl > rl ifTrue:[ |
|
3098 |
hiL isNil ifTrue:[ |
|
3099 |
hiL := aColor. |
|
3100 |
hiValL := cl |
|
3101 |
] ifFalse:[ |
|
3102 |
cl < hiValL ifTrue:[ |
|
3103 |
hiL := aColor. |
|
3104 |
hiValL := cl |
|
3105 |
] |
|
3106 |
]. |
|
3107 |
] ifFalse:[ |
|
3108 |
lowL isNil ifTrue:[ |
|
3109 |
lowL := aColor. |
|
3110 |
lowValL := cl |
|
3111 |
] ifFalse:[ |
|
3112 |
cl > lowValL ifTrue:[ |
|
3113 |
lowL := aColor. |
|
3114 |
lowValL := cl |
|
3115 |
] |
|
3116 |
] |
|
3117 |
] |
|
3118 |
]. |
|
3119 |
||
3120 |
(((ch = rh) or:[ch isNil]) and:[cl = rl]) ifTrue:[ |
|
3121 |
"found a color with same light and same hue, keep for saturation" |
|
3122 |
||
3123 |
cs > rs ifTrue:[ |
|
3124 |
hiS isNil ifTrue:[ |
|
3125 |
hiS := aColor. |
|
3126 |
hiValS := cs |
|
3127 |
] ifFalse:[ |
|
3128 |
cs < hiValS ifTrue:[ |
|
3129 |
hiS := aColor. |
|
3130 |
hiValS := cs |
|
3131 |
] |
|
3132 |
]. |
|
3133 |
] ifFalse:[ |
|
3134 |
lowS isNil ifTrue:[ |
|
3135 |
lowS := aColor. |
|
3136 |
lowValS := cs |
|
3137 |
] ifFalse:[ |
|
3138 |
cs > lowValS ifTrue:[ |
|
3139 |
lowS := aColor. |
|
3140 |
lowValS := cs |
|
3141 |
] |
|
3142 |
] |
|
3143 |
] |
|
3144 |
]. |
|
3145 |
||
3146 |
rh notNil ifTrue:[ |
|
3147 |
cl = rl ifTrue:[ |
|
3148 |
cs = rs ifTrue:[ |
|
3149 |
ch notNil ifTrue:[ |
|
3150 |
d := (ch - rh) abs. |
|
3151 |
d > 300 ifTrue:[ |
|
3152 |
rh > 180 ifTrue:[ |
|
3153 |
ch := ch + 360 |
|
3154 |
] ifFalse:[ |
|
3155 |
ch := ch - 360 |
|
3156 |
]. |
|
3157 |
]. |
|
3158 |
ch > rh ifTrue:[ |
|
3159 |
hiH isNil ifTrue:[ |
|
3160 |
hiH := aColor. |
|
3161 |
hiValH := ch |
|
3162 |
] ifFalse:[ |
|
3163 |
ch < hiValH ifTrue:[ |
|
3164 |
hiH := aColor. |
|
3165 |
hiValH := ch |
|
3166 |
] |
|
3167 |
] |
|
3168 |
] ifFalse:[ |
|
3169 |
lowH isNil ifTrue:[ |
|
3170 |
lowH := aColor. |
|
3171 |
lowValH := ch |
|
3172 |
] ifFalse:[ |
|
3173 |
ch > lowValH ifTrue:[ |
|
3174 |
lowH := aColor. |
|
3175 |
lowValH := ch |
|
3176 |
] |
|
3177 |
] |
|
3178 |
] |
|
3179 |
] |
|
3180 |
] |
|
3181 |
] |
|
3182 |
] |
|
3183 |
] |
|
3184 |
] |
|
1023 | 3185 |
]. |
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3186 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3187 |
"found bounds for light ?" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3188 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3189 |
lowL notNil ifTrue:[ |
7798 | 3190 |
rl = lowValL ifTrue:[ |
3191 |
^ aBlock value:lowL value:nil |
|
3192 |
]. |
|
3193 |
hiL notNil ifTrue:[ |
|
3194 |
^ self |
|
3195 |
monoDitherFor:1.0 / (hiValL - lowValL) / (rl - lowValL) |
|
3196 |
between:lowL and:hiL |
|
3197 |
on:aDevice |
|
3198 |
into:aBlock |
|
3199 |
]. |
|
3200 |
"found bound for light - dither with white" |
|
3201 |
^ self |
|
3202 |
monoDitherFor:1.0 / (100 - lowValL) / (rl - lowValL) |
|
3203 |
between:lowL and:White |
|
3204 |
on:aDevice |
|
3205 |
into:aBlock |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3206 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3207 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3208 |
"found bound for light - dither with black" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3209 |
hiL notNil ifTrue:[ |
7798 | 3210 |
^ self |
3211 |
monoDitherFor:1.0 / (hiValL) / (rl) |
|
3212 |
between:Black and:hiL |
|
3213 |
on:aDevice |
|
3214 |
into:aBlock |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3215 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3216 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3217 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3218 |
"found bounds for saturation?" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3219 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3220 |
(lowS notNil and:[hiS notNil]) ifTrue:[ |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3221 |
" |
7798 | 3222 |
'saturation dither' printNewline. |
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3223 |
" |
7798 | 3224 |
^ self |
3225 |
monoDitherFor:1.0 / (hiValS - lowValS) / (rs - lowValS) |
|
3226 |
between:lowS and:hiS |
|
3227 |
on:aDevice |
|
3228 |
into:aBlock |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3229 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3230 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3231 |
"found bounds for hue ?" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3232 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3233 |
(lowH notNil and:[hiH notNil]) ifTrue:[ |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3234 |
" |
7798 | 3235 |
'hue dither' printNewline. |
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3236 |
" |
7798 | 3237 |
hiValH < lowValH ifTrue:[ |
3238 |
hiValH := hiValH + 360 |
|
3239 |
]. |
|
3240 |
||
3241 |
d := hiValH - lowValH. |
|
3242 |
||
3243 |
^ self |
|
3244 |
monoDitherFor:1.0 / (d / (rh - lowValH)) |
|
3245 |
between:lowH and:hiH |
|
3246 |
on:aDevice |
|
3247 |
into:aBlock |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3248 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3249 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3250 |
^ aBlock value:nil value:nil |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3251 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3252 |
"Modified: 3.5.1997 / 10:58:54 / cg" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3253 |
"Created: 3.5.1997 / 11:02:03 / cg" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3254 |
! |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3255 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3256 |
fixDitherRed:redVal green:greenVal blue:blueVal on:aDevice into:aBlock |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3257 |
"get a dither form for an rgb value. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3258 |
Returns 2 values (either color or ditherForm) through aBlock. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3259 |
This code uses the table of preallocated fix-colors to find |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3260 |
dither colors." |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3261 |
|
6353 | 3262 |
| |
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3263 |
nR "{ Class: SmallInteger }" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3264 |
nG "{ Class: SmallInteger }" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3265 |
nB "{ Class: SmallInteger }" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3266 |
hR "{ Class: SmallInteger }" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3267 |
hG "{ Class: SmallInteger }" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3268 |
hB "{ Class: SmallInteger }" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3269 |
eR eG eB |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3270 |
rI "{ Class: SmallInteger }" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3271 |
gI "{ Class: SmallInteger }" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3272 |
bI "{ Class: SmallInteger }" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3273 |
idx "{ Class: SmallInteger }" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3274 |
f clr |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3275 |
r "{ Class: SmallInteger }" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3276 |
g "{ Class: SmallInteger }" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3277 |
b "{ Class: SmallInteger }" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3278 |
x1 "{ Class: SmallInteger }" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3279 |
x2 "{ Class: SmallInteger }" |
6353 | 3280 |
step "{ Class: SmallInteger }" |
3281 |
lastIdx mx |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3282 |
dS "{ Class: SmallInteger }" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3283 |
cube| |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3284 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3285 |
(cube := aDevice fixColors) notNil ifTrue:[ |
7360 | 3286 |
dS := 4. |
3287 |
||
3288 |
f := Form width:dS height:dS depth:(aDevice depth) onDevice:aDevice. |
|
3289 |
f isNil ifTrue:[^ nil]. |
|
3290 |
f initGC. |
|
3291 |
||
3292 |
mx := MaxValue asFloat. |
|
3293 |
||
3294 |
nR := aDevice numFixRed. |
|
3295 |
nG := aDevice numFixGreen. |
|
3296 |
nB := aDevice numFixBlue. |
|
3297 |
||
3298 |
hR := nR // 2. |
|
3299 |
hG := nG // 2. |
|
3300 |
hB := nB // 2. |
|
3301 |
||
3302 |
eR := eG := eB := 0. |
|
3303 |
r := redVal. |
|
3304 |
g := greenVal. |
|
3305 |
b := blueVal. |
|
3306 |
||
3307 |
step := -1. |
|
3308 |
||
3309 |
0 to:dS-1 do:[:y | |
|
3310 |
step == -1 ifTrue:[ |
|
3311 |
x1 := 0. x2 := dS-1. step := 1. |
|
3312 |
] ifFalse:[ |
|
3313 |
x1 := dS-1. x2 := 0. step := -1. |
|
3314 |
]. |
|
3315 |
||
3316 |
x1 to:x2 by:step do:[:x | |
|
3317 |
"/ the nearest along the grid |
|
3318 |
||
3319 |
r := redVal + eR. |
|
3320 |
r > MaxValue ifTrue:[r := MaxValue] |
|
3321 |
ifFalse:[r < 0 ifTrue:[r := 0]]. |
|
3322 |
g := greenVal + eG. |
|
3323 |
g > MaxValue ifTrue:[g := MaxValue] |
|
3324 |
ifFalse:[g < 0 ifTrue:[g := 0]]. |
|
3325 |
||
3326 |
b := blueVal + eB. |
|
3327 |
b > MaxValue ifTrue:[b := MaxValue] |
|
3328 |
ifFalse:[b < 0 ifTrue:[b := 0]]. |
|
3329 |
||
3330 |
rI := (r * (nR-1) + hR / mx) rounded. |
|
3331 |
gI := (g * (nG-1) + hG / mx) rounded . |
|
3332 |
bI := (b * (nB-1) + hB / mx) rounded . |
|
3333 |
||
3334 |
idx := (((rI * nG) + gI) * nB + bI) + 1. |
|
3335 |
clr := (cube at:idx) exactOn:aDevice. |
|
3336 |
lastIdx isNil ifTrue:[lastIdx := idx] |
|
3337 |
ifFalse:[lastIdx ~~ idx ifTrue:[lastIdx := -1]]. |
|
3338 |
||
3339 |
f foreground:clr. |
|
3340 |
f displayPointX:x y:y. |
|
3341 |
||
3342 |
eR := r - clr scaledRed. |
|
3343 |
eG := g - clr scaledGreen. |
|
3344 |
eB := b - clr scaledBlue. |
|
3345 |
]. |
|
3346 |
]. |
|
3347 |
f releaseGC. |
|
3348 |
||
3349 |
lastIdx ~~ -1 ifTrue:[ |
|
3350 |
^ aBlock value:clr value:nil |
|
3351 |
]. |
|
3352 |
^ aBlock value:nil value:f |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3353 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3354 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3355 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3356 |
^ aBlock value:nil value:nil |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3357 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3358 |
"Modified: 11.7.1996 / 18:30:28 / cg" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3359 |
"Created: 3.5.1997 / 11:03:18 / cg" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3360 |
! |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3361 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3362 |
monoDitherFor:fraction between:color1 and:color2 on:aDevice into:aBlock |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3363 |
"get a dither form or colorId for dithering between 2 colors. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3364 |
Fraction is 0..1. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3365 |
Returns 2 values (either color or ditherForm) through aBlock." |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3366 |
|
6353 | 3367 |
|form c1 c2 |
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3368 |
index "{ Class:SmallInteger }"| |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3369 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3370 |
"/ |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3371 |
"/ having forms with: [1 .. 63] of 64 pixels (see Form), |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3372 |
"/ we get dithers for: 1/64, 2/64, ... 63/64 |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3373 |
"/ |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3374 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3375 |
index := (fraction * 64) rounded. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3376 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3377 |
c1 := color1 exactOn:aDevice. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3378 |
index < 1 ifTrue:[ |
6353 | 3379 |
^ aBlock value:c1 value:nil |
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3380 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3381 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3382 |
c2 := color2 exactOn:aDevice. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3383 |
index >= 64 ifTrue:[ |
6353 | 3384 |
^ aBlock value:c2 value:nil |
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3385 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3386 |
|
4772
be4524221fa7
Use Form class>>#width:height:fromArray:onDevice: instead of obsolete
Stefan Vogel <sv@exept.de>
parents:
4749
diff
changeset
|
3387 |
form := Form width:8 height:8 fromArray:(DitherBits at:index) onDevice:aDevice. |
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3388 |
form colorMap:(Array with:c1 with:c2). |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3389 |
^ aBlock value:nil value:form |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3390 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3391 |
" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3392 |
Color basicNew |
6353 | 3393 |
monoDitherFor:(MaxValue // 2) |
3394 |
between:Color black |
|
3395 |
and:Color white |
|
3396 |
on:Display |
|
3397 |
into:[:clr :dither | clr inspect. dither inspect] |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3398 |
" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3399 |
|
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3400 |
"Created: 3.5.1997 / 10:55:06 / cg" |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
3401 |
"Modified: 3.5.1997 / 11:05:20 / cg" |
1023 | 3402 |
! ! |
3403 |
||
1144 | 3404 |
!Color class methodsFor:'queries'! |
1023 | 3405 |
|
3406 |
constantNames |
|
3407 |
"return names known as instance creation messages" |
|
3408 |
||
6353 | 3409 |
^ #(white black |
6534 | 3410 |
grey mediumGray veryLightGray lightGray darkGray veryDarkGray |
8966 | 3411 |
red green blue |
3412 |
cyan yellow pink orange magenta brown |
|
3413 |
darkGreen darkRed |
|
3414 |
lightGreen lightRed lightBlue |
|
3415 |
salmon) |
|
1023 | 3416 |
|
3417 |
"Modified: 2.5.1996 / 11:34:05 / cg" |
|
3418 |
! |
|
3419 |
||
3420 |
scalingValue |
|
3421 |
"ST-80 compatibility" |
|
3422 |
||
3423 |
^ MaxValue |
|
3424 |
||
3425 |
"Created: 2.5.1996 / 11:30:09 / cg" |
|
3426 |
"Modified: 11.7.1996 / 21:42:26 / cg" |
|
3427 |
! ! |
|
3428 |
||
1144 | 3429 |
!Color class methodsFor:'special instance creation'! |
1023 | 3430 |
|
3431 |
nearestColorRed:r green:g blue:b on:aDevice in:colors |
|
3432 |
"return the nearest color on aDevice with RGB values |
|
3433 |
same or near r/g/b in a collection of colors. |
|
3434 |
If there is one, return it; nil otherwise. |
|
3435 |
Near is defined as having an error less than the argument |
|
3436 |
error (in percent). The error is computed by the color |
|
3437 |
vector distance (which may not be the best possible solution)." |
|
3438 |
||
3439 |
^ self |
|
6353 | 3440 |
nearestColorScaledRed:(r * MaxValue // 100) |
3441 |
scaledGreen:(g * MaxValue // 100) |
|
3442 |
scaledBlue:(b * MaxValue // 100) |
|
3443 |
on:aDevice |
|
3444 |
in:colors |
|
1023 | 3445 |
|
3446 |
"Modified: 11.6.1996 / 18:04:55 / cg" |
|
3447 |
"Created: 14.6.1996 / 20:05:13 / cg" |
|
3448 |
! |
|
3449 |
||
3450 |
nearestColorScaledRed:r scaledGreen:g scaledBlue:b inCube:aColorCube numRed:nRed numGreen:nGreen numBlue:nBlue |
|
3451 |
"return a color with rgb values same or near r/g/b in a given |
|
3452 |
collection, containing colors from a colorCube. |
|
6353 | 3453 |
This is used with preallocated fixColors and is quite fast |
1023 | 3454 |
(no need to search)" |
3455 |
||
3456 |
|sR "{ Class: SmallInteger }" |
|
3457 |
sG "{ Class: SmallInteger }" |
|
3458 |
sB "{ Class: SmallInteger }" |
|
3459 |
idx "{ Class: SmallInteger }" |
|
3460 |
nR "{ Class: SmallInteger }" |
|
3461 |
nG "{ Class: SmallInteger }" |
|
3462 |
nB "{ Class: SmallInteger }" |
|
3463 |
rI "{ Class: SmallInteger }" |
|
3464 |
gI "{ Class: SmallInteger }" |
|
3465 |
bI "{ Class: SmallInteger }"| |
|
3466 |
||
3467 |
" |
|
3468 |
round to the step given by FixColors |
|
3469 |
" |
|
3470 |
nR := nRed. |
|
3471 |
nG := nGreen. |
|
3472 |
nB := nBlue. |
|
3473 |
||
3474 |
sR := MaxValue // (nR - 1). |
|
3475 |
sG := MaxValue // (nG - 1). |
|
3476 |
sB := MaxValue // (nB - 1). |
|
3477 |
||
3478 |
rI := (r + (sR // 2)) // sR. |
|
3479 |
gI := (g + (sG // 2)) // sG. |
|
3480 |
bI := (b + (sB // 2)) // sB. |
|
3481 |
idx := (((rI * nG) + gI) * nB + bI) + 1. |
|
3482 |
^ aColorCube at:idx |
|
3483 |
||
3484 |
"Modified: 11.7.1996 / 17:52:46 / cg" |
|
3485 |
"Created: 11.7.1996 / 18:20:13 / cg" |
|
3486 |
! |
|
3487 |
||
3488 |
nearestColorScaledRed:r scaledGreen:g scaledBlue:b on:aDevice |
|
3489 |
"return a device color on aDevice with RGB values |
|
3490 |
same or near r/g/b, if there is one, nil otherwise. |
|
3491 |
Near is defined as having an error less than the argument |
|
3492 |
error (in percent). The error is computed by the color |
|
3493 |
vector distance (which may not be the best possible solution)." |
|
3494 |
||
3495 |
|cube| |
|
3496 |
||
3497 |
" |
|
3498 |
if there are preallocated colors, things are much easier ... |
|
3499 |
" |
|
3500 |
(cube := aDevice fixColors) notNil ifTrue:[ |
|
6353 | 3501 |
^ self |
3502 |
nearestColorScaledRed:r |
|
3503 |
scaledGreen:g |
|
3504 |
scaledBlue:b |
|
3505 |
inCube:cube |
|
3506 |
numRed:(aDevice numFixRed) |
|
3507 |
numGreen:(aDevice numFixGreen) |
|
3508 |
numBlue:(aDevice numFixBlue) |
|
1023 | 3509 |
]. |
3510 |
||
3511 |
" |
|
3512 |
search in existing colors ... |
|
3513 |
" |
|
6353 | 3514 |
^ self |
3515 |
nearestColorScaledRed:r |
|
3516 |
scaledGreen:g |
|
3517 |
scaledBlue:b |
|
3518 |
on:aDevice |
|
3519 |
in:aDevice deviceColors |
|
1023 | 3520 |
|
3521 |
"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
|
3522 |
"Modified: 24.2.1997 / 18:17:51 / cg" |
1023 | 3523 |
! |
3524 |
||
3525 |
nearestColorScaledRed:r scaledGreen:g scaledBlue:b on:aDevice in:colors |
|
3526 |
"return the nearest color on aDevice with RGB values |
|
3527 |
same or near r/g/b in a collection of colors. |
|
3528 |
If there is one, return it; nil otherwise." |
|
3529 |
||
3530 |
|delta minDelta bestSoFar| |
|
3531 |
||
3532 |
minDelta := 9999999. |
|
3533 |
||
1619
4a7dbd25c588
handle the case where not even r/g/b primaries can be allocated
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
3534 |
colors isNil ifTrue:[^ nil]. |
4a7dbd25c588
handle the case where not even r/g/b primaries can be allocated
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
3535 |
|
1023 | 3536 |
colors do:[:aColor | |
6353 | 3537 |
|cr cg cb| |
3538 |
||
3539 |
(aDevice isNil |
|
3540 |
or:[(aColor graphicsDevice == aDevice) |
|
3541 |
and:[aColor colorId notNil]]) ifTrue:[ |
|
3542 |
delta := aColor deltaFromScaledRed:r scaledGreen:g scaledBlue:b. |
|
3543 |
delta < minDelta ifTrue:[ |
|
3544 |
" |
|
3545 |
an exact fit - no need to continue search |
|
3546 |
" |
|
3547 |
delta == 0 ifTrue:[^ aColor]. |
|
3548 |
||
3549 |
bestSoFar := aColor. |
|
3550 |
minDelta := delta |
|
3551 |
] |
|
3552 |
] |
|
1023 | 3553 |
]. |
3554 |
||
3555 |
^ bestSoFar |
|
3556 |
||
2198
122ff0da86d6
added support to find the nearest color in a colorMap.
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
3557 |
"Created: / 11.6.1996 / 18:02:12 / cg" |
122ff0da86d6
added support to find the nearest color in a colorMap.
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
3558 |
"Modified: / 28.7.1998 / 20:40:41 / cg" |
1023 | 3559 |
! |
3560 |
||
3561 |
quickNearestColorScaledRed:r scaledGreen:g scaledBlue:b on:aDevice |
|
3562 |
"return a device color on aDevice with rgb values |
|
3563 |
same or near r/g/b. |
|
3564 |
This looks for primary colors only and is thus faster |
|
3565 |
than the general nearestColor search (slightly uglier though)." |
|
3566 |
||
3567 |
|cube| |
|
3568 |
||
3569 |
" |
|
1954 | 3570 |
if there are preallocated colors, things are much easier ... |
1023 | 3571 |
" |
1954 | 3572 |
(cube := aDevice fixColors) notNil ifTrue:[ |
6353 | 3573 |
^ self |
3574 |
nearestColorScaledRed:r |
|
3575 |
scaledGreen:g |
|
3576 |
scaledBlue:b |
|
3577 |
inCube:cube |
|
3578 |
numRed:(aDevice numFixRed) |
|
3579 |
numGreen:(aDevice numFixGreen) |
|
3580 |
numBlue:(aDevice numFixBlue) |
|
1023 | 3581 |
]. |
3582 |
||
3583 |
" |
|
3584 |
search in existing colors ... |
|
3585 |
" |
|
6353 | 3586 |
^ self nearestColorScaledRed:r |
3587 |
scaledGreen:g |
|
3588 |
scaledBlue:b |
|
3589 |
on:aDevice |
|
3590 |
in:(aDevice availableDitherColors) |
|
1023 | 3591 |
|
3592 |
"Created: 14.6.1996 / 20:13:22 / cg" |
|
3593 |
"Modified: 11.7.1996 / 18:20:14 / cg" |
|
3594 |
! ! |
|
3595 |
||
8123 | 3596 |
!Color class methodsFor:'utilities'! |
3597 |
||
3598 |
allocateColorsIn:aColorVector on:aDevice |
|
3599 |
"{ Pragma: +optSpace }" |
|
3600 |
||
3601 |
"preallocates a nR x nG x nB colorMap for later use in dithering. |
|
3602 |
Doing so has the advantage that the system will never run out of colors, |
|
3603 |
however, colors may be either inexact or dithered." |
|
3604 |
||
3605 |
|clr round devClr| |
|
3606 |
||
3607 |
round := 0. |
|
3608 |
1 to:aColorVector size do:[:dstIndex | |
|
3609 |
clr := aColorVector at:dstIndex. |
|
3610 |
devClr := clr exactOn:aDevice. |
|
3611 |
devClr isNil ifTrue:[ |
|
3612 |
round == 0 ifTrue:[ |
|
3613 |
Logger info:'scavenge to reclaim colors'. |
|
3614 |
ObjectMemory scavenge. |
|
3615 |
round := 1. |
|
3616 |
devClr := clr exactOn:aDevice. |
|
3617 |
]. |
|
3618 |
devClr isNil ifTrue:[ |
|
3619 |
round == 1 ifTrue:[ |
|
3620 |
Logger info:'collect garbage to reclaim colors'. |
|
3621 |
ObjectMemory |
|
3622 |
garbageCollect; finalize. |
|
3623 |
round := 2. |
|
3624 |
devClr := clr exactOn:aDevice. |
|
3625 |
]. |
|
3626 |
devClr isNil ifTrue:[ |
|
3627 |
round == 2 ifTrue:[ |
|
3628 |
Logger info:'lowSpaceCleanup and collect garbage to reclaim colors'. |
|
3629 |
ObjectMemory |
|
3630 |
performLowSpaceCleanup; |
|
3631 |
garbageCollect; finalize. |
|
3632 |
round := 3. |
|
3633 |
devClr := clr exactOn:aDevice. |
|
3634 |
]. |
|
3635 |
devClr isNil ifTrue:[ |
|
3636 |
ColorAllocationFailSignal raiseErrorString:'failed to allocate fix color'. |
|
3637 |
^ self |
|
3638 |
]. |
|
3639 |
]. |
|
3640 |
]. |
|
3641 |
]. |
|
3642 |
aColorVector at:dstIndex put:devClr. |
|
3643 |
]. |
|
3644 |
||
3645 |
"Modified: / 02-03-2017 / 17:43:36 / stefan" |
|
3646 |
! |
|
3647 |
||
3648 |
best:numColors ditherColorsForImage:anImage |
|
3649 |
"work in progress" |
|
3650 |
||
8126 | 3651 |
|cube boxMaxR boxMaxG boxMaxB numBitsR numBitsG numBitsB numGray usedColors |
8123 | 3652 |
minRed maxRed minGreen maxGreen minBlue maxBlue |
8126 | 3653 |
boundaryColors boxesAlreadySegmented segments boxesToDo enumerateNeighbors |
8123 | 3654 |
firstTry segmentColors| |
3655 |
||
3656 |
((anImage photometric == #blackIs0) or:[anImage photometric == #whiteIs0]) ifTrue:[ |
|
3657 |
numGray := (1 bitShift:anImage depth) min:numColors. |
|
3658 |
^ self grayColorVector:numGray |
|
3659 |
]. |
|
3660 |
(anImage photometric == #palette) ifTrue:[ |
|
3661 |
"/ all gray? |
|
3662 |
(anImage colorMap conform:[:clr | clr isGrayColor]) ifTrue:[ |
|
3663 |
numGray := ((1 bitShift:anImage depth) min:anImage colorMap size) min:numColors. |
|
3664 |
^ self grayColorVector:numGray |
|
3665 |
]. |
|
3666 |
]. |
|
3667 |
||
8126 | 3668 |
numBitsR := 7. |
3669 |
numBitsG := 8. |
|
3670 |
numBitsB := 5. |
|
3671 |
||
8123 | 3672 |
firstTry := true. |
3673 |
||
3674 |
[ |
|
8126 | 3675 |
boxMaxR := (1 << numBitsR) - 1. |
3676 |
boxMaxG := (1 << numBitsG) - 1. |
|
3677 |
boxMaxB := (1 << numBitsB) - 1. |
|
3678 |
||
3679 |
cube := IntegerArray new:(boxMaxR+1)*(boxMaxG+1)*(boxMaxB+1). |
|
8123 | 3680 |
|
3681 |
firstTry ifTrue:[ |
|
3682 |
usedColors := Set new. |
|
3683 |
minRed := minGreen := minBlue := 255. |
|
3684 |
maxRed := maxGreen := maxBlue := 0. |
|
3685 |
]. |
|
3686 |
||
3687 |
anImage |
|
3688 |
rgbValuesFromX:0 y:0 |
|
3689 |
toX:(anImage width-1) y:(anImage height-1) |
|
3690 |
do:[:x :y :rgb | |
|
3691 |
|redByte greenByte blueByte r g b idx oldCount| |
|
3692 |
||
3693 |
redByte := (rgb rightShift:16) bitAnd:16rFF. |
|
3694 |
greenByte := (rgb rightShift:8) bitAnd:16rFF. |
|
3695 |
blueByte := (rgb) bitAnd:16rFF. |
|
3696 |
||
8126 | 3697 |
r := redByte rightShift:(8-numBitsR). |
3698 |
g := greenByte rightShift:(8-numBitsG). |
|
3699 |
b := blueByte rightShift:(8-numBitsB). |
|
3700 |
idx := (((r * (boxMaxG+1))+g)*(boxMaxB+1))+b+1. |
|
3701 |
oldCount := cube at:idx. |
|
8123 | 3702 |
|
3703 |
firstTry ifTrue:[ |
|
3704 |
redByte < minRed ifTrue:[minRed := redByte] ifFalse:[redByte > maxRed ifTrue:[maxRed := redByte]]. |
|
3705 |
greenByte < minGreen ifTrue:[minGreen := greenByte] ifFalse:[greenByte > maxGreen ifTrue:[maxGreen := greenByte]]. |
|
3706 |
blueByte < minBlue ifTrue:[minBlue := blueByte] ifFalse:[blueByte > maxBlue ifTrue:[maxBlue := blueByte]]. |
|
3707 |
||
3708 |
oldCount == 0 ifTrue:[ |
|
3709 |
usedColors add:rgb. |
|
3710 |
]. |
|
3711 |
]. |
|
8126 | 3712 |
cube at:idx put:oldCount+1. |
8123 | 3713 |
]. |
3714 |
||
3715 |
firstTry ifTrue:[ |
|
3716 |
usedColors size <= numColors ifTrue:[ |
|
3717 |
"/ huh - that will be easy!! |
|
8968 | 3718 |
^ usedColors asArray collect:[:rgb | Color rgbValue:rgb]. |
8123 | 3719 |
]. |
3720 |
||
3721 |
"/ if not even the basic colors fit, dither to b&w |
|
3722 |
numColors == 2 ifTrue:[ |
|
3723 |
^ { Color black . Color white } |
|
3724 |
]. |
|
3725 |
"/ if not even the basic colors fit, dither to b&w |
|
3726 |
numColors == 4 ifTrue:[ |
|
3727 |
^ { Color black . Color red . Color green . Color blue. } |
|
3728 |
]. |
|
3729 |
||
3730 |
"/ we need the at least the 8 corners for dithering, at least... |
|
3731 |
boundaryColors := OrderedCollection new. |
|
3732 |
{ minRed . maxRed } do:[:r | |
|
3733 |
{ minGreen . maxGreen } do:[:g | |
|
3734 |
{ minBlue . maxBlue } do:[:b | |
|
3735 |
boundaryColors add:(Color redByte:r greenByte:g blueByte:b) |
|
3736 |
]. |
|
3737 |
]. |
|
3738 |
]. |
|
3739 |
numColors == 8 ifTrue:[ |
|
3740 |
^ boundaryColors |
|
3741 |
]. |
|
3742 |
]. |
|
3743 |
firstTry := false. |
|
3744 |
||
3745 |
"/ |
|
3746 |
"/ find and generate connected subarea box sets |
|
3747 |
"/ |
|
8126 | 3748 |
boxesAlreadySegmented := Set new. |
8123 | 3749 |
segments := OrderedCollection new. |
3750 |
boxesToDo := OrderedCollection new. |
|
3751 |
||
3752 |
"/ each box has 9+9+3+3+1+1 neighbors |
|
3753 |
"/ |
|
3754 |
enumerateNeighbors := |
|
3755 |
[:rgb :aBlock| |
|
3756 |
|r g b| |
|
3757 |
||
8126 | 3758 |
r := (rgb rightShift:(numBitsG+numBitsB)) bitAnd:boxMaxR. |
3759 |
g := (rgb rightShift:numBitsB) bitAnd:boxMaxG. |
|
3760 |
b := (rgb) bitAnd:boxMaxB. |
|
8123 | 3761 |
r-1 to:r+1 do:[:n_r | |
8126 | 3762 |
(n_r between:0 and:boxMaxR) ifTrue:[ |
8123 | 3763 |
g-1 to:g+1 do:[:n_g | |
8126 | 3764 |
(n_g between:0 and:boxMaxG) ifTrue:[ |
8123 | 3765 |
b-1 to:b+1 do:[:n_b | |
8126 | 3766 |
(n_b between:0 and:boxMaxB) ifTrue:[ |
8123 | 3767 |
((n_r == r) and:[n_g == g and:[n_b == b]]) ifFalse:[ |
8126 | 3768 |
aBlock value:((((n_r * (boxMaxG+1))+n_g)*(boxMaxB+1))+n_b). |
8123 | 3769 |
] |
3770 |
] |
|
3771 |
] |
|
3772 |
] |
|
3773 |
] |
|
3774 |
] |
|
3775 |
]. |
|
3776 |
]. |
|
3777 |
||
8126 | 3778 |
0 to:boxMaxR do:[:r | |
3779 |
0 to:boxMaxG do:[:g | |
|
3780 |
0 to:boxMaxB do:[:b | |
|
8123 | 3781 |
|rgb| |
3782 |
||
8126 | 3783 |
rgb := (((r * (boxMaxG+1))+g)*(boxMaxB+1))+b. |
8137 | 3784 |
((cube at:rgb+1) ~~ 0 |
3785 |
and:[(boxesAlreadySegmented includes:rgb) not]) ifTrue:[ |
|
3786 |
|currentSegment| |
|
3787 |
||
3788 |
"/ start a segment |
|
3789 |
currentSegment := OrderedCollection new. |
|
3790 |
segments add:currentSegment. |
|
3791 |
||
3792 |
boxesToDo add:rgb. |
|
3793 |
boxesAlreadySegmented add:rgb. |
|
3794 |
||
3795 |
[boxesToDo notEmpty] whileTrue:[ |
|
3796 |
|lastRgb| |
|
3797 |
||
3798 |
lastRgb := boxesToDo removeLast. |
|
3799 |
currentSegment add:lastRgb. |
|
3800 |
||
3801 |
enumerateNeighbors |
|
3802 |
value:lastRgb |
|
3803 |
value:[:n_rgb | |
|
3804 |
(cube at:n_rgb+1) ~~ 0 ifTrue:[ |
|
3805 |
"/ neighbor has used pixels as well... |
|
3806 |
(boxesAlreadySegmented includes:n_rgb) ifFalse:[ |
|
3807 |
"/ neighbor was not processed... |
|
3808 |
boxesAlreadySegmented add:lastRgb. |
|
3809 |
boxesToDo add:n_rgb. |
|
3810 |
]. |
|
3811 |
]. |
|
3812 |
]. |
|
3813 |
]. |
|
8123 | 3814 |
]. |
3815 |
] |
|
3816 |
] |
|
3817 |
]. |
|
3818 |
||
3819 |
(segments size < numColors) ifTrue:[ |
|
3820 |
segmentColors := segments |
|
3821 |
collect:[:eachSegment | |
|
8125 | 3822 |
|sumWeight sumRed sumGreen sumBlue centerRed centerGreen centerBlue| |
8123 | 3823 |
|
3824 |
"/ compute central point |
|
3825 |
"/ as center of mass (taking count per box as weight) |
|
3826 |
"/ this central point will be placed into the colormap. |
|
3827 |
sumRed := sumGreen := sumBlue := 0. |
|
8125 | 3828 |
|
3829 |
sumWeight := 0. |
|
8123 | 3830 |
eachSegment do:[:rgbOfBoxInSegment | |
8125 | 3831 |
|r g b idx count| |
8123 | 3832 |
|
8126 | 3833 |
r := (rgbOfBoxInSegment rightShift:(numBitsG+numBitsB)) bitAnd:boxMaxR. |
3834 |
g := (rgbOfBoxInSegment rightShift:numBitsB) bitAnd:boxMaxG. |
|
3835 |
b := (rgbOfBoxInSegment) bitAnd:boxMaxB. |
|
3836 |
||
3837 |
idx := (((r * (boxMaxG+1))+g)*(boxMaxB+1))+b+1. |
|
3838 |
count := cube at:idx. |
|
3839 |
||
3840 |
sumRed := sumRed + (r * count). |
|
3841 |
sumGreen := sumGreen + (g * count). |
|
3842 |
sumBlue := sumBlue + (b * count). |
|
3843 |
||
8125 | 3844 |
sumWeight := sumWeight + count. |
8123 | 3845 |
]. |
8125 | 3846 |
centerRed := (sumRed / sumWeight) rounded. |
3847 |
centerGreen := (sumGreen / sumWeight) rounded. |
|
3848 |
centerBlue := (sumBlue / sumWeight) rounded. |
|
8123 | 3849 |
|
8126 | 3850 |
centerRed := (centerRed bitShift:(8-numBitsR)) |
3851 |
bitOr:(centerRed bitShift:(8-numBitsR-numBitsR)). |
|
3852 |
centerGreen := (centerGreen bitShift:(8-numBitsG)) |
|
3853 |
bitOr:(centerGreen bitShift:(8-numBitsG-numBitsG)). |
|
3854 |
centerBlue := (centerBlue bitShift:(8-numBitsB)) |
|
3855 |
bitOr:(centerBlue bitShift:(8-numBitsB-numBitsB)). |
|
8123 | 3856 |
|
3857 |
Color redByte:centerRed greenByte:centerGreen blueByte:centerBlue. |
|
3858 |
] |
|
3859 |
as:OrderedCollection. |
|
3860 |
"/ can we add black & white? |
|
3861 |
(segmentColors includes:Color white) ifFalse:[ |
|
3862 |
segmentColors add:Color white. |
|
3863 |
]. |
|
3864 |
(segmentColors includes:Color black) ifFalse:[ |
|
3865 |
segmentColors add:Color black. |
|
3866 |
]. |
|
3867 |
"/ can we add the boundary colors? |
|
3868 |
boundaryColors do:[:each | |
|
3869 |
(segmentColors size < numColors) ifTrue:[ |
|
3870 |
(segmentColors includes:each) ifFalse:[ |
|
3871 |
segmentColors add:each. |
|
3872 |
]. |
|
3873 |
]. |
|
3874 |
]. |
|
3875 |
^ segmentColors. |
|
3876 |
]. |
|
3877 |
||
8126 | 3878 |
numBitsR > 2 ifTrue:[ numBitsR := numBitsR - 1 ]. |
3879 |
numBitsG > 2 ifTrue:[ numBitsG := numBitsG - 1 ]. |
|
3880 |
numBitsB > 2 ifTrue:[ numBitsB := numBitsB - 1 ]. |
|
8123 | 3881 |
|
8126 | 3882 |
((numBitsR == 0) or:[numBitsG == 0 or:[numBitsB == 0]]) ifTrue:[ |
8123 | 3883 |
self error. |
3884 |
]. |
|
3885 |
] loop. |
|
3886 |
||
3887 |
" |
|
3888 |
Color |
|
3889 |
best:16 |
|
3890 |
ditherColorsForImage:(Image fromFile:'../../goodies/bitmaps/pcxImages/lena_depth8_palette.pcx') |
|
3891 |
||
3892 |
Color |
|
3893 |
best:16 |
|
3894 |
ditherColorsForImage:(Image fromFile:'../../goodies/bitmaps/pcxImages/lena_depth24_rgb.pcx') |
|
3895 |
||
3896 |
Color |
|
3897 |
best:16 |
|
3898 |
ditherColorsForImage:((Image fromFile:'../../goodies/bitmaps/pcxImages/lena_depth8_palette.pcx') asGrayImageDepth:8) |
|
3899 |
||
3900 |
" |
|
3901 |
||
3902 |
"Created: / 29-08-2017 / 14:31:19 / cg" |
|
8126 | 3903 |
"Modified: / 29-08-2017 / 21:53:47 / cg" |
8123 | 3904 |
! |
3905 |
||
3906 |
browserColors |
|
3907 |
"return the palette, known as 'the color cube', 'the Netscape palette', |
|
3908 |
or 'the Browser-Safe palette'. |
|
3909 |
This is familiar to all seasoned Web designers and graphics production specialists; |
|
3910 |
Use this map for low-color-res depth 8 (gif-) images, if old pseudo displays are to be |
|
3911 |
supported." |
|
3912 |
||
3913 |
^ self colorCubeWithRed:6 green:6 blue:6. |
|
3914 |
||
3915 |
" |
|
3916 |
|img| |
|
3917 |
||
3918 |
img := Image width:(8*6*6)+1 height:(8*6)+1 depth:8. |
|
3919 |
img colorMap:(Color browserColors). |
|
3920 |
img pixelFunction: |
|
3921 |
[:x :y | |
|
3922 |
|r g b| |
|
3923 |
||
3924 |
(y \\ 8 == 0 ) ifTrue:[ |
|
3925 |
86 |
|
3926 |
] ifFalse:[ |
|
3927 |
x \\ 8 == 0 ifTrue:[ |
|
3928 |
86 |
|
3929 |
] ifFalse:[ |
|
3930 |
r := g := b := 0. |
|
3931 |
'y is green component'. |
|
3932 |
g := 5-(y // 8). |
|
3933 |
'x inside subsquare is blue component'. |
|
3934 |
b := (x \\ (8*6)) // 8. |
|
3935 |
'subsquare is red component'. |
|
3936 |
r := (x // (8*6)). |
|
3937 |
((r*6)+g)*6+b |
|
3938 |
] |
|
3939 |
]. |
|
3940 |
]. |
|
3941 |
img inspect. |
|
3942 |
" |
|
3943 |
||
3944 |
"Created: / 29-08-2017 / 17:01:23 / cg" |
|
3945 |
! |
|
3946 |
||
3947 |
colorCubeWithRed:nRed green:nGreen blue:nBlue |
|
3948 |
"given a number of red, green and blue shades, |
|
3949 |
return a color cube (map) containing those colors. |
|
3950 |
Eg, return a map containing any combination of the |
|
3951 |
nRed, nGreen and nBlue shades. |
|
3952 |
This is used for dithering of deep images onto limited-depth canvases |
|
3953 |
for example: with nRed,nGreen,nBlue == 2,3,2 |
|
3954 |
you will get a cube of 2*3*2 = 12 colors, with two shades of red (0 and 255), |
|
3955 |
threed shades of green (0, 127 and 255) and two shades of blue (0 and 255)." |
|
3956 |
||
3957 |
"{ Pragma: +optSpace }" |
|
3958 |
||
3959 |
|nR "{Class: SmallInteger }" |
|
3960 |
nG "{Class: SmallInteger }" |
|
3961 |
nB "{Class: SmallInteger }" |
|
3962 |
dR dG dB red green blue dstIndex clr round |
|
3963 |
colorCube| |
|
3964 |
||
3965 |
nR := nRed. |
|
3966 |
nG := nGreen. |
|
3967 |
nB := nBlue. |
|
3968 |
||
3969 |
dR := 100.0 / (nR - 1). |
|
3970 |
dG := 100.0 / (nG - 1). |
|
3971 |
dB := 100.0 / (nB - 1). |
|
3972 |
||
3973 |
colorCube := Array new:(nR * nG * nB). |
|
3974 |
||
3975 |
round := 0. |
|
3976 |
||
3977 |
dstIndex := 1. |
|
3978 |
1 to:nR do:[:sR | |
|
3979 |
red := dR * (sR - 1). |
|
3980 |
1 to:nG do:[:sG | |
|
3981 |
green := dG * (sG - 1). |
|
3982 |
1 to:nB do:[:sB | |
|
3983 |
blue := dB * (sB - 1). |
|
3984 |
clr := self red:red green:green blue:blue. |
|
3985 |
colorCube at:dstIndex put:clr. |
|
3986 |
dstIndex := dstIndex + 1 |
|
3987 |
] |
|
3988 |
] |
|
3989 |
]. |
|
3990 |
^ colorCube |
|
3991 |
||
3992 |
" |
|
3993 |
Color colorCubeWithRed:2 green:2 blue:2 |
|
3994 |
Color colorCubeWithRed:2 green:3 blue:2 |
|
3995 |
Color colorCubeWithRed:3 green:4 blue:3 |
|
3996 |
" |
|
3997 |
||
3998 |
"Created: / 11-07-1996 / 17:55:32 / cg" |
|
3999 |
"Modified: / 10-01-1997 / 15:37:13 / cg" |
|
4000 |
"Modified (comment): / 29-08-2017 / 14:27:58 / cg" |
|
4001 |
! |
|
4002 |
||
4003 |
flushDeviceColors |
|
4004 |
"unassign all colors from their device" |
|
4005 |
||
4006 |
self allInstances do:[:aColor | |
|
4007 |
aColor restored |
|
4008 |
]. |
|
4009 |
||
4010 |
"Modified: 24.2.1997 / 18:27:06 / cg" |
|
4011 |
! |
|
4012 |
||
4013 |
flushDeviceColorsFor:aDevice |
|
4014 |
self allInstancesDo:[:aColor | |
|
4015 |
aColor device == aDevice ifTrue:[ |
|
4016 |
aColor restored |
|
4017 |
] |
|
4018 |
] |
|
4019 |
! |
|
4020 |
||
4021 |
getColors6x6x4 |
|
4022 |
"{ Pragma: +optSpace }" |
|
4023 |
||
4024 |
"preallocates a 6x6x4 (144) colorMap and later uses those colors only |
|
4025 |
on a palette display (pseudoColor visual). |
|
4026 |
||
4027 |
Doing so has the advantage that the system will never run out of colors, |
|
4028 |
however, colors may be either inexact or dithered." |
|
4029 |
||
4030 |
self getColorsRed:6 green:6 blue:4 |
|
4031 |
||
4032 |
" |
|
4033 |
Color getColors6x6x4 |
|
4034 |
" |
|
4035 |
||
4036 |
"Modified (comment): / 29-08-2017 / 17:22:22 / cg" |
|
4037 |
! |
|
4038 |
||
4039 |
getColors6x6x5 |
|
4040 |
"{ Pragma: +optSpace }" |
|
4041 |
||
4042 |
"preallocates a 6x6x5 (180) colorMap and later uses those colors only |
|
4043 |
on a palette display (pseudoColor visual). |
|
4044 |
||
4045 |
Doing so has the advantage that the system will never run out of colors, |
|
4046 |
however, colors may be either inexact or dithered." |
|
4047 |
||
4048 |
self getColorsRed:6 green:6 blue:5 |
|
4049 |
||
4050 |
" |
|
4051 |
Color getColors6x6x5 |
|
4052 |
" |
|
4053 |
||
4054 |
"Modified (comment): / 29-08-2017 / 17:22:17 / cg" |
|
4055 |
! |
|
4056 |
||
4057 |
getColors6x6x6 |
|
4058 |
"{ Pragma: +optSpace }" |
|
4059 |
||
4060 |
"preallocates a 6x6x6 (196) colorMap and later uses those colors only |
|
4061 |
on a palette display (pseudoColor visual). |
|
4062 |
||
4063 |
Doing so has the advantage that the system will never run out of colors, |
|
4064 |
however, colors may be either inexact or dithered." |
|
4065 |
||
4066 |
self getColorsRed:6 green:6 blue:6 |
|
4067 |
||
4068 |
" |
|
4069 |
Color getColors6x6x6 |
|
4070 |
" |
|
4071 |
||
4072 |
"Modified (comment): / 29-08-2017 / 17:22:10 / cg" |
|
4073 |
! |
|
4074 |
||
4075 |
getColors6x7x4 |
|
4076 |
"{ Pragma: +optSpace }" |
|
4077 |
||
4078 |
"preallocates a 6x7x4 (168) colorMap and later uses those colors only |
|
4079 |
on a palette display (pseudoColor visual). |
|
4080 |
||
4081 |
Doing so has the advantage that the system will never run out of colors, |
|
4082 |
however, colors may be either inexact or dithered." |
|
4083 |
||
4084 |
self getColorsRed:6 green:7 blue:4 |
|
4085 |
||
4086 |
" |
|
4087 |
Color getColors6x7x4 |
|
4088 |
" |
|
4089 |
||
4090 |
"Created: / 12-06-1996 / 17:41:57 / cg" |
|
4091 |
"Modified (comment): / 29-08-2017 / 17:22:04 / cg" |
|
4092 |
! |
|
4093 |
||
4094 |
getColors7x8x4 |
|
4095 |
"{ Pragma: +optSpace }" |
|
4096 |
||
4097 |
"preallocates a 7x8x4 (224) colorMap and later uses those colors only |
|
4098 |
on a palette display (pseudoColor visual). |
|
4099 |
||
4100 |
Doing so has the advantage that the system will never run out of colors, |
|
4101 |
however, colors may be either inexact or dithered." |
|
4102 |
||
4103 |
self getColorsRed:7 green:8 blue:4 |
|
4104 |
||
4105 |
" |
|
4106 |
Color getColors7x8x4 |
|
4107 |
" |
|
4108 |
||
4109 |
"Modified (comment): / 29-08-2017 / 17:21:56 / cg" |
|
4110 |
! |
|
4111 |
||
4112 |
getColorsRed:nRed green:nGreen blue:nBlue |
|
4113 |
"{ Pragma: +optSpace }" |
|
4114 |
||
4115 |
"preallocates a nR x nG x nB colorMap for later use in dithering |
|
4116 |
on a palette display (pseudoColor visual). |
|
4117 |
||
4118 |
Doing so has the advantage that the system will never run out of colors, |
|
4119 |
however, colors may be either inexact or dithered." |
|
4120 |
||
4121 |
self getColorsRed:nRed green:nGreen blue:nBlue on:Screen current |
|
4122 |
||
4123 |
" |
|
4124 |
Color getColorsRed:2 green:2 blue:2 |
|
4125 |
" |
|
4126 |
||
4127 |
"Modified: / 11-07-1996 / 17:58:09 / cg" |
|
4128 |
"Modified (comment): / 29-08-2017 / 16:47:34 / cg" |
|
4129 |
! |
|
4130 |
||
4131 |
getColorsRed:nRed green:nGreen blue:nBlue on:aDevice |
|
4132 |
"{ Pragma: +optSpace }" |
|
4133 |
||
4134 |
"preallocates a nR x nG x nB colorMap for later use in dithering |
|
4135 |
on a palette display (pseudoColor visual). |
|
4136 |
||
4137 |
Doing so has the advantage that the system will never run out of colors, |
|
4138 |
however, colors may be either inexact or dithered." |
|
4139 |
||
4140 |
|nR "{Class: SmallInteger }" |
|
4141 |
nG "{Class: SmallInteger }" |
|
4142 |
nB "{Class: SmallInteger }" |
|
4143 |
dR dG dB fixColors| |
|
4144 |
||
4145 |
aDevice visualType == #TrueColor ifTrue:[^ self]. |
|
4146 |
||
4147 |
nR := nRed. |
|
4148 |
nG := nGreen. |
|
4149 |
nB := nBlue. |
|
4150 |
||
4151 |
dR := 100.0 / (nR - 1). |
|
4152 |
dG := 100.0 / (nG - 1). |
|
4153 |
dB := 100.0 / (nB - 1). |
|
4154 |
||
4155 |
fixColors := self colorCubeWithRed:nRed green:nGreen blue:nBlue. |
|
4156 |
self allocateColorsIn:fixColors on:aDevice. |
|
4157 |
||
4158 |
aDevice setFixColors:fixColors numRed:nR numGreen:nG numBlue:nB |
|
4159 |
||
4160 |
" |
|
4161 |
Color getColorsRed:2 green:2 blue:2 on:Display |
|
4162 |
" |
|
4163 |
||
4164 |
"Created: / 11-07-1996 / 17:55:32 / cg" |
|
4165 |
"Modified: / 10-01-1997 / 15:37:13 / cg" |
|
4166 |
"Modified (comment): / 29-08-2017 / 16:47:38 / cg" |
|
4167 |
! |
|
4168 |
||
4169 |
getGrayColors:nGray on:aDevice |
|
4170 |
"{ Pragma: +optSpace }" |
|
4171 |
||
4172 |
"preallocates nGray gray colors for later use in dithering |
|
4173 |
on a palette display (pseudoColor visual). |
|
4174 |
||
4175 |
Doing so has the advantage that the system will never run out of colors, |
|
4176 |
however, colors may be either inexact or dithered." |
|
4177 |
||
4178 |
|nG "{Class: SmallInteger }" |
|
4179 |
d fixGrayColors| |
|
4180 |
||
4181 |
aDevice visualType == #TrueColor ifTrue:[^ self]. |
|
4182 |
||
4183 |
nG := nGray. |
|
4184 |
d := 100.0 / (nG - 1). |
|
4185 |
||
4186 |
fixGrayColors := self grayColorVector:nGray. |
|
4187 |
self allocateColorsIn:fixGrayColors on:aDevice. |
|
4188 |
||
4189 |
aDevice setFixGrayColors:fixGrayColors |
|
4190 |
||
4191 |
" |
|
4192 |
Color getGrayColors:16 on:Display |
|
4193 |
" |
|
4194 |
||
4195 |
"Created: / 23-06-1997 / 15:29:50 / cg" |
|
4196 |
"Modified (comment): / 29-08-2017 / 17:23:18 / cg" |
|
4197 |
! |
|
4198 |
||
4199 |
getPrimaryColorsOn:aDevice |
|
4200 |
"{ Pragma: +optSpace }" |
|
4201 |
||
4202 |
"preallocate the primary colors on a palette display (pseudoColor visual). |
|
4203 |
||
4204 |
Doing so during early startup prevents us from running out |
|
4205 |
of (at least those required) colors later. |
|
4206 |
This guarantees, that at least some colors are available |
|
4207 |
for dithering (although, with only black, white, red, green and blue, |
|
4208 |
dithered images look very poor)." |
|
4209 |
||
4210 |
|colors white black red green blue clr dDepth |
|
4211 |
lastPix "{ Class: SmallInteger }" | |
|
4212 |
||
4213 |
(aDevice notNil and:[aDevice ditherColors isNil]) ifTrue:[ |
|
4214 |
white := (self red:100 green:100 blue:100) exactOn:aDevice. |
|
4215 |
white colorId isNil ifTrue:[ |
|
4216 |
'Color [warning]: cannot allocate white color' errorPrintCR. |
|
4217 |
]. |
|
4218 |
black := (self red:0 green:0 blue:0) exactOn:aDevice. |
|
4219 |
black colorId isNil ifTrue:[ |
|
4220 |
'Color [warning]: cannot allocate black color' errorPrintCR. |
|
4221 |
]. |
|
4222 |
||
4223 |
aDevice hasColors ifTrue:[ |
|
4224 |
red := (self red:100 green:0 blue:0) exactOn:aDevice. |
|
4225 |
green := (self red:0 green:100 blue:0) exactOn:aDevice. |
|
4226 |
blue := (self red:0 green:0 blue:100) exactOn:aDevice. |
|
4227 |
(red isNil |
|
4228 |
or:[green isNil |
|
4229 |
or:[blue isNil |
|
4230 |
or:[red colorId isNil |
|
4231 |
or:[green colorId isNil |
|
4232 |
or:[blue colorId isNil]]]]]) ifTrue:[ |
|
4233 |
'Color [warning]: cannot allocate primary color(s)' errorPrintCR. |
|
4234 |
dDepth := aDevice depth. |
|
4235 |
((dDepth >= 4) and:[dDepth <= 8]) ifTrue:[ |
|
4236 |
"/ |
|
4237 |
"/ see what we have ... |
|
4238 |
"/ |
|
4239 |
lastPix := (1 bitShift:dDepth) - 1. |
|
4240 |
0 to:lastPix do:[:pixel | |
|
4241 |
colors := OrderedCollection new. |
|
4242 |
aDevice getRGBFrom:pixel into:[:r :g :b | |
|
4243 |
colors add:((Color red:r green:g blue:b) exactOn:aDevice). |
|
4244 |
] |
|
4245 |
]. |
|
4246 |
red := (self red:100 green:0 blue:0) nearestOn:aDevice. |
|
4247 |
green := (self red:0 green:100 blue:0) nearestOn:aDevice. |
|
4248 |
blue := (self red:0 green:0 blue:100) nearestOn:aDevice. |
|
4249 |
] ifFalse:[ |
|
4250 |
aDevice hasColors:false. |
|
4251 |
aDevice hasGrayscales:false. |
|
4252 |
red := green := blue := nil. |
|
4253 |
] |
|
4254 |
] |
|
4255 |
]. |
|
4256 |
||
4257 |
aDevice == Display ifTrue:[ |
|
4258 |
"/ keep those around for the main display |
|
4259 |
White := white. |
|
4260 |
Black := black. |
|
4261 |
Red := red. |
|
4262 |
Green := green. |
|
4263 |
Blue := blue |
|
4264 |
]. |
|
4265 |
||
4266 |
aDevice visualType ~~ #TrueColor ifTrue:[ |
|
4267 |
aDevice hasColors ifTrue:[ |
|
4268 |
||
4269 |
"preallocate some colors for dithering |
|
4270 |
- otherwise, they may not be available when we need them ... |
|
4271 |
these are: black, white, grey50, |
|
4272 |
red, green, blue, yellow, cyan and magenta. |
|
4273 |
" |
|
4274 |
||
4275 |
colors := OrderedCollection new. |
|
4276 |
clr := (self gray:50) exactOn:aDevice. |
|
4277 |
(clr notNil and:[clr colorId notNil]) ifTrue:[ |
|
4278 |
colors add:clr |
|
4279 |
]. |
|
4280 |
||
4281 |
colors add:white; add:black; add:red; add:green; add:blue. |
|
4282 |
||
4283 |
colors add:((self red:100 green:100 blue:0) exactOn:aDevice). |
|
4284 |
colors add:((self red:100 green:0 blue:100) exactOn:aDevice). |
|
4285 |
colors add:((self red:0 green:100 blue:100) exactOn:aDevice). |
|
4286 |
]. |
|
4287 |
||
4288 |
aDevice hasGrayscales ifTrue:[ |
|
4289 |
aDevice hasColors ifFalse:[ |
|
8285 | 4290 |
colors := |
4291 |
OrderedCollection |
|
4292 |
with:((self gray:50) exactOn:aDevice) |
|
4293 |
with:white |
|
4294 |
with:black. |
|
8123 | 4295 |
|
4296 |
]. |
|
4297 |
colors add:((self gray:25) exactOn:aDevice). |
|
4298 |
colors add:((self gray:33) exactOn:aDevice). |
|
4299 |
colors add:((self gray:67) exactOn:aDevice). |
|
4300 |
colors add:((self gray:75) exactOn:aDevice). |
|
4301 |
]. |
|
4302 |
||
4303 |
colors notNil ifTrue:[ |
|
4304 |
colors := colors select:[:clr | clr notNil and:[clr colorId notNil]]. |
|
4305 |
aDevice setDitherColors:(colors asArray). |
|
4306 |
] |
|
4307 |
] |
|
4308 |
] |
|
4309 |
||
4310 |
"Created: / 11-07-1996 / 18:09:28 / cg" |
|
4311 |
"Modified: / 21-10-1997 / 02:42:28 / cg" |
|
4312 |
"Modified (comment): / 29-08-2017 / 17:23:36 / cg" |
|
4313 |
! |
|
4314 |
||
4315 |
grayColorVector:nGray |
|
4316 |
|nG "{Class: SmallInteger }" |
|
4317 |
d gray dstIndex clr round |
|
4318 |
grayColors| |
|
4319 |
||
4320 |
nG := nGray. |
|
4321 |
d := 100.0 / (nG - 1). |
|
4322 |
||
4323 |
grayColors := Array new:nG. |
|
4324 |
||
4325 |
round := 0. |
|
4326 |
||
4327 |
dstIndex := 1. |
|
4328 |
1 to:nG do:[:sG | |
|
4329 |
gray := d * (sG - 1). |
|
4330 |
clr := self red:gray green:gray blue:gray. |
|
4331 |
grayColors at:dstIndex put:clr. |
|
4332 |
dstIndex := dstIndex + 1 |
|
4333 |
]. |
|
4334 |
^ grayColors |
|
4335 |
||
4336 |
" |
|
4337 |
Color getGrayColors:16 on:Display |
|
4338 |
" |
|
4339 |
||
4340 |
"Created: 23.6.1997 / 15:29:50 / cg" |
|
4341 |
! |
|
4342 |
||
4343 |
standardDitherColorsForDepth8 |
|
4344 |
"return a set of colors useful for dithering (roughly 200 colors); |
|
4345 |
This includes a color cube and the main grayScale colors." |
|
4346 |
||
4347 |
|ditherColors| |
|
4348 |
||
4349 |
ditherColors := self colorCubeWithRed:6 green:8 blue:4. |
|
4350 |
ditherColors := ditherColors , |
|
4351 |
( #(10 20 25 30 40 50 60 70 75 80 90) |
|
4352 |
collect:[:grayPercent | Color gray:grayPercent] |
|
4353 |
thenSelect:[:grey | (ditherColors includes:grey) not] ) |
|
4354 |
asArray. |
|
4355 |
^ ditherColors |
|
4356 |
||
4357 |
" |
|
4358 |
self standardDitherColorsForDepth8 |
|
4359 |
" |
|
4360 |
||
4361 |
"Modified: / 29-08-2017 / 17:29:58 / cg" |
|
4362 |
! |
|
4363 |
||
4364 |
vgaColors |
|
4365 |
"{ Pragma: +optSpace }" |
|
4366 |
||
4367 |
|colors| |
|
4368 |
||
4369 |
colors := Array new:16. |
|
4370 |
colors at:1 put:(Color rgbValue:16rFFFFFF). |
|
4371 |
colors at:2 put:(Color rgbValue:16rC0C0C0). |
|
4372 |
colors at:3 put:(Color rgbValue:16r808080). |
|
4373 |
colors at:4 put:(Color rgbValue:16r000000). |
|
4374 |
colors at:5 put:(Color rgbValue:16rFF0000). |
|
4375 |
colors at:6 put:(Color rgbValue:16r800000). |
|
4376 |
colors at:7 put:(Color rgbValue:16r008000). |
|
4377 |
colors at:8 put:(Color rgbValue:16r00FF00). |
|
4378 |
colors at:9 put:(Color rgbValue:16r0000FF). |
|
4379 |
colors at:10 put:(Color rgbValue:16r000080). |
|
4380 |
colors at:11 put:(Color rgbValue:16rFF00FF). |
|
4381 |
colors at:12 put:(Color rgbValue:16r800080). |
|
4382 |
colors at:13 put:(Color rgbValue:16rFFFF00). |
|
4383 |
colors at:14 put:(Color rgbValue:16r808000). |
|
4384 |
colors at:15 put:(Color rgbValue:16r00FFFF). |
|
4385 |
colors at:16 put:(Color rgbValue:16r008080). |
|
4386 |
^ colors |
|
4387 |
||
4388 |
"Created: / 07-07-2006 / 13:36:15 / cg" |
|
4389 |
! ! |
|
4390 |
||
3880 | 4391 |
!Color methodsFor:'Compatibility-ST80'! |
1347 | 4392 |
|
4393 |
asDevicePaintOn:aDevice |
|
4394 |
"ST-80 compatibility: an alias for on:. |
|
4395 |
create a new Color representing the same color as |
|
4396 |
myself on aDevice; if one already exists, return the one" |
|
4397 |
||
2828 | 4398 |
^ self onDevice:aDevice |
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4399 |
! |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4400 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4401 |
asHiliteColor |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4402 |
"same as lightened - for ST-80 compatibility" |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4403 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4404 |
^ self lightened |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4405 |
! |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4406 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4407 |
asShadowColor |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4408 |
"same as darkened - for ST-80 compatibility" |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4409 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4410 |
^ self darkened |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4411 |
! ! |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4412 |
|
3880 | 4413 |
!Color methodsFor:'Compatibility-Squeak'! |
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4414 |
|
6353 | 4415 |
alphaMixed: proportion with: aColor |
7831 | 4416 |
"Squeak compatibility: |
4417 |
Answer this color mixed with the given color. The proportion, a number |
|
6353 | 4418 |
between 0.0 and 1.0, determines what what fraction of the receiver to |
8165 | 4419 |
use in the mix. |
4420 |
For example, 1.0 yields the receiver, 0.0 yields aColor |
|
4421 |
and 0.9 would yield a color close to the receiver. |
|
4422 |
This method uses RGB interpolation; |
|
4423 |
HSV interpolation can lead to surprises. |
|
4424 |
Mixes the alphas (for transparency) also." |
|
4789 | 4425 |
|
4426 |
| frac1 frac2 | |
|
4427 |
||
4428 |
frac1 := proportion asFloat min: 1.0 max: 0.0. |
|
4429 |
frac2 := 1.0 - frac1. |
|
7762 | 4430 |
^ self class |
4431 |
r: ((red * frac1) + (aColor scaledRed * frac2)) / MaxValue |
|
4432 |
g: ((green * frac1) + (aColor scaledGreen * frac2)) / MaxValue |
|
4433 |
b: ((blue * frac1) + (aColor scaledBlue * frac2)) / MaxValue |
|
4434 |
alpha: (self alpha * frac1) + (aColor alpha * frac2) |
|
6353 | 4435 |
|
4436 |
" |
|
4437 |
(Color r:1 g:0 b:0 alpha:1) alphaMixed:0.5 with:(Color r:1 g:0 b:0 alpha:1) |
|
4438 |
(Color r:1 g:0 b:0 alpha:0.5) alphaMixed:0.5 with:(Color r:0 g:1 b:0 alpha:0.5) |
|
4789 | 4439 |
" |
4440 |
||
4441 |
"Created: / 06-06-2007 / 10:53:25 / cg" |
|
8165 | 4442 |
"Modified (comment): / 05-09-2017 / 14:38:23 / cg" |
4789 | 4443 |
! |
4444 |
||
2945 | 4445 |
bitPatternForDepth: depth |
7831 | 4446 |
"Squeak compatibility: |
4447 |
Return a Bitmap, possibly containing a stipple pattern, |
|
6353 | 4448 |
that best represents this color at the given depth. |
4449 |
BitBlt calls this method to convert colors into Bitmaps. |
|
4450 |
The resulting Bitmap may be multiple words to represent a stipple |
|
2945 | 4451 |
pattern of several lines. " |
4452 |
||
6353 | 4453 |
"See also: |
7831 | 4454 |
pixelValueAtDepth: -- value for single pixel |
4455 |
pixelWordAtDepth: -- a 32-bit word filled with the pixel value" |
|
2945 | 4456 |
"Details: The pattern for the most recently requested depth is cached." |
4457 |
||
4458 |
^ self. |
|
4459 |
"/ depth == cachedDepth ifTrue: [^ cachedBitPattern]. |
|
4460 |
"/ cachedDepth _ depth. |
|
4461 |
"/ |
|
4462 |
"/ depth > 2 ifTrue: [^ cachedBitPattern _ Bitmap with: (self pixelWordForDepth: depth)]. |
|
4463 |
"/ depth = 1 ifTrue: [^ cachedBitPattern _ self halfTonePattern1]. |
|
4464 |
"/ depth = 2 ifTrue: [^ cachedBitPattern _ self halfTonePattern2]. |
|
4465 |
||
7831 | 4466 |
"Modified (comment): / 03-02-2017 / 11:38:04 / cg" |
2945 | 4467 |
! |
4468 |
||
3396 | 4469 |
colorForInsets |
7831 | 4470 |
"Squeak compatibility - dummy" |
4471 |
||
3396 | 4472 |
^ self |
7831 | 4473 |
|
4474 |
"Modified (comment): / 03-02-2017 / 11:38:24 / cg" |
|
3396 | 4475 |
! |
4476 |
||
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4477 |
darker |
7831 | 4478 |
"Squeak compatibility; |
4479 |
return a new color, which is darker than the receiver. |
|
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4480 |
Almost the same as darkened for Squeak compatibility." |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4481 |
|
8047 | 4482 |
^ self mixed:1 with:Black |
4483 |
"/ ^ self mixed:0.8333 with:Black |
|
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4484 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4485 |
" |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4486 |
(Color red) darker |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4487 |
(Color red) muchDarker |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4488 |
" |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4489 |
|
8047 | 4490 |
"Modified: / 05-07-2017 / 09:28:40 / cg" |
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4491 |
! |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4492 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4493 |
lighter |
7831 | 4494 |
"Squeak compatibility; |
4495 |
return a new color, which is slightly lighter than the receiver. |
|
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4496 |
Almost the same as lightened for Squeak compatibility." |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4497 |
|
8047 | 4498 |
^ self mixed:1 with:White |
4499 |
"/ ^ self mixed:0.8333 with:White |
|
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4500 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4501 |
" |
6353 | 4502 |
(Color red) |
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4503 |
(Color red) lighter |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4504 |
(Color red) muchLighter |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4505 |
(Color red) veryMuchLighter |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4506 |
" |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4507 |
|
8047 | 4508 |
"Modified: / 05-07-2017 / 09:29:18 / cg" |
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4509 |
! |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4510 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4511 |
muchDarker |
7831 | 4512 |
"Squeak compatibility: |
4513 |
return a new color, which is much darker than the receiver" |
|
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4514 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4515 |
^ self mixed:0.233 with:Black |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4516 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4517 |
" |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4518 |
(Color red) darker |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4519 |
(Color red) muchDarker |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4520 |
" |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4521 |
|
7831 | 4522 |
"Modified: / 11-06-1996 / 18:10:49 / cg" |
4523 |
"Modified (comment): / 03-02-2017 / 11:37:46 / cg" |
|
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4524 |
! |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4525 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4526 |
muchLighter |
7831 | 4527 |
"Squeak compatibility: |
4528 |
return a new color, which is much lighter than the receiver" |
|
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4529 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4530 |
^ self mixed:0.233 with:White |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4531 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4532 |
" |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4533 |
(Color red) lighter |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4534 |
(Color red) mixed:0.833 with:Color white |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4535 |
(Color red) muchLighter |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4536 |
(Color red) veryMuchLighter |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4537 |
" |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4538 |
|
7831 | 4539 |
"Modified: / 11-06-1996 / 18:10:49 / cg" |
4540 |
"Modified (comment): / 03-02-2017 / 11:39:05 / cg" |
|
3396 | 4541 |
! |
3024 | 4542 |
|
4203 | 4543 |
privateBlue |
4544 |
"Squeak compatibility: |
|
4545 |
return the blue components value mapped to 0..MaxValue" |
|
4546 |
||
4547 |
^ self scaledBlue |
|
4548 |
! |
|
4549 |
||
4550 |
privateGreen |
|
4551 |
"Squeak compatibility: |
|
4552 |
return the green components value mapped to 0..MaxValue" |
|
4553 |
||
4554 |
^ self scaledGreen |
|
4555 |
! |
|
4556 |
||
4557 |
privateRed |
|
4558 |
"Squeak compatibility: |
|
4559 |
return the red components value mapped to 0..MaxValue" |
|
4560 |
||
4561 |
^ self scaledRed |
|
4562 |
! |
|
4563 |
||
3309 | 4564 |
scaledPixelValue32 |
7831 | 4565 |
"Squeak compatibility: |
4566 |
return the argb byteValues packed into a 32bit integer; |
|
4567 |
The returned value is composed of a<<24 + r<<16 + g<<8 + b. |
|
4568 |
This is similar to rgbValue, but has an additional alpha byte value |
|
4569 |
in its high bits (which is 0 for fully transparent, 255 for fully opaque colors)" |
|
4570 |
||
3309 | 4571 |
^ (self redByte bitShift:16) |
4572 |
+ (self greenByte bitShift:8) |
|
4573 |
+ (self blueByte) |
|
4574 |
+ (self alphaByte bitShift:24) |
|
7831 | 4575 |
|
4576 |
||
4577 |
" |
|
4578 |
Color yellow scaledPixelValue |
|
4579 |
Color yellow rgbValue |
|
4580 |
Color yellow alpha |
|
4581 |
Color yellow alphaByte |
|
4582 |
" |
|
4583 |
||
4584 |
"Modified (comment): / 03-02-2017 / 11:40:03 / cg" |
|
3309 | 4585 |
! |
4586 |
||
8047 | 4587 |
twiceDarker |
4588 |
"Squeak compatibility: |
|
4589 |
return a new color, which is twice as dark as the receiver" |
|
4590 |
||
4591 |
^ self darker darker |
|
4592 |
||
4593 |
" |
|
4594 |
(Color red) |
|
4595 |
(Color red) darker |
|
4596 |
(Color red) twiceDarker |
|
4597 |
(Color red) muchDarker |
|
4598 |
" |
|
4599 |
||
4600 |
"Created: / 05-07-2017 / 09:27:16 / cg" |
|
4601 |
! |
|
4602 |
||
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4603 |
veryMuchLighter |
7831 | 4604 |
"Squeak compatibility: |
4605 |
return a new color, which is very much lighter than the receiver" |
|
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4606 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4607 |
^ self mixed:0.1165 with:White |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4608 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4609 |
" |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4610 |
(Color red) lighter |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4611 |
(Color red) muchLighter |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4612 |
(Color red) veryMuchLighter |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4613 |
" |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
4614 |
|
7831 | 4615 |
"Modified: / 11-06-1996 / 18:10:49 / cg" |
4616 |
"Modified (comment): / 03-02-2017 / 11:40:13 / cg" |
|
3396 | 4617 |
! |
4618 |
||
4619 |
wheel:thisMany |
|
7831 | 4620 |
"Squeak compatibility: |
4621 |
An array of thisMany colors around the color wheel, |
|
4622 |
starting at self and ending all the way around the hue space just before self. |
|
4623 |
Array is of length thisMany. |
|
4624 |
Very useful for displaying color based on a variable in your program. " |
|
4625 |
||
4626 |
| sat l hue step c | |
|
3396 | 4627 |
|
4628 |
thisMany = 1 ifTrue: [^ Array with: self]. |
|
7831 | 4629 |
|
4630 |
sat := self saturation. |
|
4631 |
l := self light. |
|
3396 | 4632 |
hue := self hue. |
4633 |
step := 360.0 / thisMany. |
|
4634 |
^ (1 to: thisMany) collect: [:num | |
|
7831 | 4635 |
c := self class hue: hue light:l saturation: sat. "hue is taken mod 360" |
4636 |
hue := hue + step. |
|
4637 |
c |
|
4638 |
]. |
|
4639 |
||
4640 |
" |
|
4641 |
Color red wheel:20 |
|
4642 |
Color red wheel:40 |
|
4643 |
" |
|
4644 |
||
4645 |
"Modified (comment): / 03-02-2017 / 11:50:59 / cg" |
|
1347 | 4646 |
! ! |
4647 |
||
1023 | 4648 |
!Color methodsFor:'accessing'! |
4649 |
||
2942
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
4650 |
alpha |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
4651 |
"return the alpha value (0..1), |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
4652 |
where 0 is completely transparent and 1 is completely opaque" |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
4653 |
|
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
4654 |
^ 1. |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
4655 |
! |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
4656 |
|
3309 | 4657 |
alphaByte |
4658 |
"return the alpha byte-value (0..255), |
|
4659 |
where 0 is completely transparent and 255 is completely opaque" |
|
4660 |
||
4661 |
^ 255. |
|
4662 |
! |
|
4663 |
||
1023 | 4664 |
blue |
4665 |
"return the blue component in percent [0..100]" |
|
4666 |
||
8163 | 4667 |
blue notNil ifTrue:[ |
4668 |
^ blue * 100.0 / MaxValue |
|
1023 | 4669 |
]. |
8163 | 4670 |
|
4671 |
(colorId notNil) ifTrue:[ |
|
4672 |
device notNil ifTrue:[ |
|
4673 |
device getRGBFrom:colorId into:[:r :g :b | ^ b]. |
|
4674 |
]. |
|
4675 |
]. |
|
4676 |
^ 0 |
|
4677 |
||
4678 |
"Modified: / 05-09-2017 / 12:15:57 / cg" |
|
1023 | 4679 |
! |
4680 |
||
4681 |
blueByte |
|
4682 |
"return the blue components value mapped to 0..255" |
|
4683 |
||
2183
3c2115660746
removed row[Red/Green/Blue]Byte;
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
4684 |
blue isNil ifTrue:[^ nil]. |
1023 | 4685 |
^ blue * 255 // MaxValue |
4686 |
||
4687 |
" |
|
6353 | 4688 |
Color red blueByte |
4689 |
Color blue blueByte |
|
4690 |
Color green blueByte |
|
4691 |
Color black blueByte |
|
4692 |
Color grey blueByte |
|
4693 |
Color white blueByte |
|
1023 | 4694 |
" |
4695 |
||
2183
3c2115660746
removed row[Red/Green/Blue]Byte;
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
4696 |
"Created: / 7.6.1996 / 18:30:25 / cg" |
3c2115660746
removed row[Red/Green/Blue]Byte;
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
4697 |
"Modified: / 26.7.1998 / 12:31:44 / cg" |
1023 | 4698 |
! |
4699 |
||
4700 |
colorId |
|
4701 |
"return the device-dependent color-id" |
|
4702 |
||
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
4703 |
colorId notNil ifTrue:[^ colorId]. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
4704 |
replacementColor notNil ifTrue:[^ replacementColor colorId]. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
4705 |
^ nil |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
4706 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
4707 |
"Modified: 17.1.1997 / 00:03:18 / cg" |
1023 | 4708 |
! |
4709 |
||
4710 |
cyan |
|
4711 |
"return the cyan component in percent [0..100] in cmy color space" |
|
4712 |
||
4713 |
^ 100 - self red |
|
4714 |
||
4715 |
"Modified: 11.6.1996 / 17:20:07 / cg" |
|
4716 |
"Created: 11.6.1996 / 18:30:00 / cg" |
|
4717 |
! |
|
4718 |
||
4719 |
device |
|
8966 | 4720 |
<resource: #obsolete> |
8812 | 4721 |
"return the device I am associated to. |
4722 |
Please use graphicsDevice for ST80 compatibility." |
|
1023 | 4723 |
|
4724 |
^ device |
|
4725 |
||
4726 |
"Modified: 23.4.1996 / 13:36:42 / cg" |
|
4727 |
! |
|
4728 |
||
4729 |
deviceBlue |
|
4730 |
"return the actual value of the blue component in percent." |
|
4731 |
||
4732 |
|v| |
|
4733 |
||
4734 |
device getRGBFrom:colorId into:[:r :g :b | v := b]. |
|
4735 |
^ v |
|
4736 |
! |
|
4737 |
||
4738 |
deviceGreen |
|
4739 |
"return the actual value of the green component in percent. |
|
4740 |
(usually 16bit in X; but could be different on other systems)" |
|
4741 |
||
4742 |
|v| |
|
4743 |
||
4744 |
device getRGBFrom:colorId into:[:r :g :b | v := g]. |
|
4745 |
^ v |
|
4746 |
! |
|
4747 |
||
4748 |
deviceRed |
|
4749 |
"return the actual value of the red component in percent." |
|
4750 |
||
4751 |
|v| |
|
4752 |
||
4753 |
device getRGBFrom:colorId into:[:r :g :b | v := r]. |
|
4754 |
^ v |
|
4755 |
||
4756 |
" |
|
4757 |
(Color yellow on:Display) deviceRedValue |
|
4758 |
(Color yellow on:aPrinterPage) deviceRedValue |
|
4759 |
" |
|
4760 |
! |
|
4761 |
||
4762 |
ditherForm |
|
4763 |
"return the form to dither the color" |
|
4764 |
||
4765 |
^ ditherForm |
|
4766 |
! |
|
4767 |
||
4768 |
graphicsDevice |
|
4769 |
"same as #device, for ST-80 compatibility naming. |
|
4770 |
Return the device I am associated with." |
|
4771 |
||
4772 |
^ device |
|
4773 |
||
4774 |
"Created: 28.5.1996 / 18:39:27 / cg" |
|
4775 |
! |
|
4776 |
||
4777 |
green |
|
4778 |
"return the green component in percent [0..100]" |
|
4779 |
||
8163 | 4780 |
green notNil ifTrue:[ |
4781 |
^ green * 100.0 / MaxValue |
|
1023 | 4782 |
]. |
8163 | 4783 |
|
4784 |
colorId notNil ifTrue:[ |
|
4785 |
device notNil ifTrue:[ |
|
4786 |
device getRGBFrom:colorId into:[:r :g :b | ^ g]. |
|
4787 |
]. |
|
4788 |
]. |
|
4789 |
^ 0 |
|
4790 |
||
4791 |
"Modified: / 05-09-2017 / 12:15:10 / cg" |
|
1023 | 4792 |
! |
4793 |
||
4794 |
greenByte |
|
4795 |
"return the green components value mapped to 0..255" |
|
4796 |
||
2183
3c2115660746
removed row[Red/Green/Blue]Byte;
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
4797 |
green isNil ifTrue:[^ nil]. |
1023 | 4798 |
^ green * 255 // MaxValue |
4799 |
||
4800 |
" |
|
6353 | 4801 |
Color red greenByte |
4802 |
Color blue greenByte |
|
4803 |
Color green greenByte |
|
4804 |
Color black greenByte |
|
4805 |
Color grey greenByte |
|
4806 |
Color white greenByte |
|
1023 | 4807 |
" |
4808 |
||
2183
3c2115660746
removed row[Red/Green/Blue]Byte;
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
4809 |
"Modified: / 26.7.1998 / 12:31:33 / cg" |
1023 | 4810 |
! |
4811 |
||
4812 |
hue |
|
6654 | 4813 |
"return the hue (in hue/light/saturation model) in degrees [0..360]. |
4814 |
The hue value is the position on the color wheel. |
|
4815 |
0 is red, 120 green, 240 blue" |
|
1023 | 4816 |
|
4817 |
|r g b h| |
|
4818 |
||
4819 |
(red isNil and:[colorId notNil]) ifTrue:[ |
|
6654 | 4820 |
device getRGBFrom:colorId into:[:xr :xg :xb | |
4821 |
r := xr. |
|
4822 |
g := xg. |
|
4823 |
b := xb. |
|
4824 |
] |
|
1023 | 4825 |
] ifFalse:[ |
6654 | 4826 |
r := self red. |
4827 |
g := self green. |
|
4828 |
b := self blue. |
|
1023 | 4829 |
]. |
4830 |
||
4831 |
self class withHLSFromRed:r green:g blue:b do:[:xh :xl :xs | |
|
6654 | 4832 |
h := xh |
1023 | 4833 |
]. |
4834 |
^ h |
|
4835 |
||
4836 |
" |
|
7411 | 4837 |
Color red hue |
1023 | 4838 |
Color yellow hue |
4839 |
" |
|
4840 |
||
6654 | 4841 |
" |
4842 |
color wheel: |
|
4843 |
||
4844 |
|v| |
|
4845 |
||
4846 |
v := View new extent:200@200. |
|
4847 |
v openAndWait. |
|
4848 |
0 to:360 do:[:hue | |
|
4849 |
100 downTo:0 do:[:sat | |
|
4850 |
|p| |
|
4851 |
v paint:(Color hue:hue light:50 saturation:sat). |
|
4852 |
p := Point r:sat degrees:hue. |
|
4853 |
v displayLineFrom:100@100 to:p+(100@100). |
|
4854 |
]. |
|
4855 |
]. |
|
4856 |
" |
|
4857 |
||
1023 | 4858 |
"Modified: 11.6.1996 / 17:14:51 / cg" |
4859 |
! |
|
4860 |
||
6353 | 4861 |
light |
1023 | 4862 |
"return the light (in hue/light/saturation model) in percent [0..100]. |
4863 |
This corresponds to the brightness of the color (if displayed on |
|
6170 | 4864 |
a b&w television screen). |
4865 |
Old; please use #brightness (which is 0..1) for compatibility with other smalltalks" |
|
1023 | 4866 |
|
4867 |
|r g b l| |
|
4868 |
||
4869 |
(red isNil and:[colorId notNil]) ifTrue:[ |
|
6353 | 4870 |
device getRGBFrom:colorId into:[:xr :xg :xb | |
4871 |
r := xr. |
|
4872 |
g := xg. |
|
4873 |
b := xb. |
|
4874 |
] |
|
1023 | 4875 |
] ifFalse:[ |
6353 | 4876 |
r := self red. |
4877 |
g := self green. |
|
4878 |
b := self blue. |
|
1023 | 4879 |
]. |
4880 |
||
4881 |
self class withHLSFromRed:r green:g blue:b do:[:xh :xl :xs | |
|
6353 | 4882 |
l := xl |
1023 | 4883 |
]. |
4884 |
^ l |
|
4885 |
||
4886 |
" |
|
6353 | 4887 |
Color yellow light |
4888 |
Color yellow darkened light |
|
1023 | 4889 |
" |
4890 |
||
4891 |
"Modified: 11.6.1996 / 17:15:24 / cg" |
|
4892 |
! |
|
4893 |
||
4894 |
magenta |
|
4895 |
"return the magenta component in percent [0..100] in cmy color space" |
|
4896 |
||
4897 |
^ 100 - self green |
|
4898 |
||
4899 |
"Modified: 11.6.1996 / 17:20:07 / cg" |
|
4900 |
"Created: 11.6.1996 / 18:30:11 / cg" |
|
4901 |
! |
|
4902 |
||
2945 | 4903 |
privateAlpha |
4904 |
"return the internal alpha value (0..255), |
|
4905 |
where 0 is completely transparent and 255 is completely opaque" |
|
4906 |
||
6353 | 4907 |
^ 255 |
2945 | 4908 |
|
4909 |
! |
|
4910 |
||
1023 | 4911 |
red |
4912 |
"return the red component in percent [0..100]" |
|
4913 |
||
8163 | 4914 |
red notNil ifTrue:[ |
4915 |
^ red * 100.0 / MaxValue |
|
1023 | 4916 |
]. |
8163 | 4917 |
|
4918 |
(colorId notNil) ifTrue:[ |
|
4919 |
device notNil ifTrue:[ |
|
4920 |
device getRGBFrom:colorId into:[:r :g :b | ^ r]. |
|
4921 |
]. |
|
4922 |
]. |
|
4923 |
^ 0 |
|
4924 |
||
4925 |
"Modified (format): / 05-09-2017 / 12:15:34 / cg" |
|
1023 | 4926 |
! |
4927 |
||
4928 |
red:r green:g blue:b |
|
4929 |
"set r/g/b components in percent. This method will change the color lookup |
|
4930 |
table in pseudocolor devices. |
|
6353 | 4931 |
This is only allowed for writable colors (i.e. those allocated with |
4932 |
Color>>variableColorOn: on pseudoColor displays). |
|
4933 |
Using this may make your code unportable, since it depends on a display |
|
1023 | 4934 |
using palettes (i.e. it will not work on greyScale or b&w displays)." |
4935 |
||
4936 |
^ self scaledRed:(r * MaxValue // 100) |
|
6353 | 4937 |
scaledGreen:(g * MaxValue // 100) |
4938 |
scaledBlue:(b * MaxValue // 100) |
|
1023 | 4939 |
|
4940 |
" |
|
4941 |
|c| |
|
4942 |
||
4943 |
c := Color variableColorOn:Display. |
|
4944 |
c inspect. |
|
4945 |
(Delay forSeconds:5) wait. |
|
4946 |
c red:100 green:0 blue:0. |
|
4947 |
(Delay forSeconds:5) wait. |
|
4948 |
c red:0 green:100 blue:0. |
|
4949 |
(Delay forSeconds:5) wait. |
|
4950 |
c red:0 green:0 blue:100. |
|
4951 |
" |
|
4952 |
! |
|
4953 |
||
4954 |
redByte |
|
2183
3c2115660746
removed row[Red/Green/Blue]Byte;
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
4955 |
"return the red components value mapped to 0..255; |
3c2115660746
removed row[Red/Green/Blue]Byte;
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
4956 |
nil if it has no red component." |
3c2115660746
removed row[Red/Green/Blue]Byte;
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
4957 |
|
3c2115660746
removed row[Red/Green/Blue]Byte;
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
4958 |
red isNil ifTrue:[^ nil]. |
1023 | 4959 |
^ red * 255 // MaxValue |
4960 |
||
4961 |
" |
|
6353 | 4962 |
Color red redByte |
4963 |
Color blue redByte |
|
4964 |
Color green redByte |
|
4965 |
Color black redByte |
|
4966 |
Color grey redByte |
|
4967 |
Color white redByte |
|
1023 | 4968 |
" |
4969 |
||
2183
3c2115660746
removed row[Red/Green/Blue]Byte;
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
4970 |
"Modified: / 26.7.1998 / 12:31:22 / cg" |
1023 | 4971 |
! |
4972 |
||
7830 | 4973 |
rgbBytes |
4974 |
"return the rgb byteValues as a 3-byte byteArray #[red green blue]" |
|
4975 |
||
4976 |
|r "{ Class: SmallInteger }" |
|
4977 |
g "{ Class: SmallInteger }" |
|
4978 |
b "{ Class: SmallInteger }"| |
|
4979 |
||
4980 |
r := red * 255 // MaxValue. |
|
4981 |
g := green * 255 // MaxValue. |
|
4982 |
b := blue * 255 // MaxValue. |
|
4983 |
^ ByteArray with:r with:g with:b |
|
4984 |
||
4985 |
" |
|
4986 |
Color red rgbBytes |
|
4987 |
Color blue rgbBytes |
|
4988 |
Color green rgbBytes |
|
4989 |
Color black rgbBytes |
|
4990 |
Color grey rgbBytes |
|
4991 |
Color white rgbBytes |
|
4992 |
" |
|
4993 |
||
4994 |
"Created: / 03-02-2017 / 11:31:24 / cg" |
|
4995 |
! |
|
4996 |
||
1929 | 4997 |
rgbValue |
4998 |
"return the rgb byteValues packed into a 24bit integer; |
|
4999 |
The returned value is composed of r<<16 + g<<8 + b." |
|
5000 |
||
5001 |
|t "{ Class: SmallInteger }" |
|
5002 |
v "{ Class: SmallInteger }"| |
|
5003 |
||
5004 |
v := red * 255 // MaxValue. |
|
5005 |
t := green * 255 // MaxValue. |
|
5006 |
v := (v bitShift:8) + t. |
|
5007 |
t := blue * 255 // MaxValue. |
|
5008 |
^ (v bitShift:8) + t. |
|
5009 |
||
5010 |
" |
|
6353 | 5011 |
Color red rgbValue hexPrintString |
5012 |
Color blue rgbValue hexPrintString |
|
5013 |
Color green rgbValue hexPrintString |
|
5014 |
Color black rgbValue hexPrintString |
|
5015 |
Color grey rgbValue hexPrintString |
|
5016 |
Color white rgbValue hexPrintString |
|
1929 | 5017 |
" |
5018 |
||
5019 |
"Modified: 17.10.1997 / 20:00:25 / cg" |
|
5020 |
! |
|
5021 |
||
6353 | 5022 |
saturation |
1023 | 5023 |
"return the saturation (in hue/light/saturation model) in percent [0..100]. |
5024 |
This corresponds to the saturation setting of a color TV" |
|
5025 |
||
5026 |
|r g b s| |
|
5027 |
||
5028 |
(red isNil and:[colorId notNil]) ifTrue:[ |
|
6353 | 5029 |
device getRGBFrom:colorId into:[:xr :xg :xb | |
5030 |
r := xr. |
|
5031 |
g := xg. |
|
5032 |
b := xb. |
|
5033 |
] |
|
1023 | 5034 |
] ifFalse:[ |
6353 | 5035 |
r := self red. |
5036 |
g := self green. |
|
5037 |
b := self blue. |
|
1023 | 5038 |
]. |
5039 |
||
5040 |
self class withHLSFromRed:r green:g blue:b do:[:xh :xl :xs | |
|
6353 | 5041 |
s := xs |
1023 | 5042 |
]. |
5043 |
^ s |
|
5044 |
||
5045 |
" |
|
5046 |
Color yellow saturation |
|
5047 |
" |
|
5048 |
||
5049 |
"Modified: 11.6.1996 / 17:15:47 / cg" |
|
5050 |
! |
|
5051 |
||
6353 | 5052 |
scaledAlpha |
5053 |
"ST-80 compatibility: |
|
5054 |
return the alpha components value mapped to 0..MaxValue" |
|
5055 |
||
5056 |
^ MaxValue |
|
5057 |
||
5058 |
" |
|
5059 |
Color blue scaledBlue |
|
5060 |
Color black scaledBlue |
|
5061 |
Color grey scaledBlue |
|
5062 |
" |
|
5063 |
||
5064 |
"Modified: 7.6.1996 / 18:32:30 / cg" |
|
5065 |
! |
|
5066 |
||
1023 | 5067 |
scaledBlue |
5068 |
"ST-80 compatibility: |
|
5069 |
return the blue components value mapped to 0..MaxValue" |
|
5070 |
||
5071 |
^ blue |
|
5072 |
||
5073 |
" |
|
6353 | 5074 |
Color blue scaledBlue |
5075 |
Color black scaledBlue |
|
5076 |
Color grey scaledBlue |
|
1023 | 5077 |
" |
5078 |
||
5079 |
"Modified: 7.6.1996 / 18:32:30 / cg" |
|
5080 |
! |
|
5081 |
||
5082 |
scaledGray |
|
5083 |
"return the grey intensity scaled to 0..MaxValue" |
|
5084 |
||
5085 |
^ ((red * 3) + (green * 6) + blue) // 10 |
|
5086 |
||
5087 |
" |
|
6353 | 5088 |
Color blue scaledGray |
5089 |
Color black scaledGray |
|
5090 |
Color white scaledGray |
|
5091 |
Color grey scaledGray |
|
1023 | 5092 |
" |
5093 |
||
5094 |
"Modified: 11.6.1996 / 14:43:51 / cg" |
|
5095 |
! |
|
5096 |
||
5097 |
scaledGreen |
|
5098 |
"ST-80 compatibility: |
|
5099 |
return the green components value mapped to 0..MaxValue" |
|
5100 |
||
5101 |
^ green |
|
5102 |
||
5103 |
" |
|
6353 | 5104 |
Color green scaledRed |
5105 |
Color black scaledRed |
|
5106 |
Color grey scaledRed |
|
1023 | 5107 |
" |
5108 |
||
5109 |
"Modified: 7.6.1996 / 18:32:38 / cg" |
|
5110 |
! |
|
5111 |
||
5112 |
scaledRed |
|
5113 |
"ST-80 compatibility: |
|
5114 |
return the red components value mapped to 0..MaxValue" |
|
5115 |
||
5116 |
^ red |
|
5117 |
||
5118 |
" |
|
6353 | 5119 |
Color red scaledRed |
5120 |
Color black scaledRed |
|
5121 |
Color grey scaledRed |
|
1023 | 5122 |
" |
5123 |
||
5124 |
"Modified: 7.6.1996 / 18:32:43 / cg" |
|
5125 |
! |
|
5126 |
||
5127 |
scaledRed:r scaledGreen:g scaledBlue:b |
|
5128 |
"set r/g/b components in 0..MaxValue. |
|
5129 |
This method will change the color lookup table in pseudocolor devices. |
|
6353 | 5130 |
This is only allowed for writable colors (i.e. those allocated with |
1023 | 5131 |
Color>>variableColorOn: on pseudoColor displays). |
6353 | 5132 |
Using this may make your code unportable, since it depends on a display |
1023 | 5133 |
using palettes (i.e. it will not work on greyScale or b&w displays)." |
5134 |
||
5135 |
(colorId isNil or:[red notNil]) ifTrue:[ |
|
6353 | 5136 |
^ self error:'operation is not allowed for shared colors' |
1023 | 5137 |
]. |
5138 |
device setColor:colorId scaledRed:r scaledGreen:g scaledBlue:b |
|
5139 |
! |
|
5140 |
||
5141 |
writable |
|
5142 |
"return true, if this is a writable colorcell" |
|
5143 |
||
5144 |
^ writable == true |
|
5145 |
! |
|
5146 |
||
5147 |
yellow |
|
5148 |
"return the yellow component in percent [0..100] in cmy color space" |
|
5149 |
||
5150 |
^ 100 - self blue |
|
5151 |
||
5152 |
"Modified: 11.6.1996 / 17:20:07 / cg" |
|
5153 |
"Created: 11.6.1996 / 18:30:20 / cg" |
|
5154 |
! ! |
|
5155 |
||
5131
95d91d6d649c
care for invalid hue/light/saturation
Claus Gittinger <cg@exept.de>
parents:
5127
diff
changeset
|
5156 |
|
1023 | 5157 |
!Color methodsFor:'comparing'! |
5158 |
||
5159 |
= aColor |
|
5160 |
"two colors are considered equal, if the color components are; |
|
5161 |
independent of the device, the color is on" |
|
5162 |
||
2083 | 5163 |
aColor == self ifTrue:[^ true]. |
1023 | 5164 |
aColor isColor ifTrue:[ |
6353 | 5165 |
(red == aColor scaledRed) ifTrue:[ |
5166 |
(green == aColor scaledGreen) ifTrue:[ |
|
5167 |
(blue == aColor scaledBlue) ifTrue:[ |
|
5168 |
^ true |
|
5169 |
] |
|
5170 |
] |
|
5171 |
] |
|
1023 | 5172 |
]. |
5173 |
^ false |
|
2083 | 5174 |
|
5175 |
"Modified: / 2.4.1998 / 10:04:39 / cg" |
|
1023 | 5176 |
! |
5177 |
||
1390 | 5178 |
almostSameAs:aColor |
5179 |
"return true, if aColor looks almost the same as the receiver |
|
5180 |
(i.e. the components differ by a small, invisible amount). |
|
5181 |
We assume, that the human eye can distinguish roughly 100 grey levels |
|
5182 |
(which is optimistic ;-); |
|
5183 |
therefore, allow a 1 percent difference in each component for the colors |
|
5184 |
to compare as looking the same." |
|
5185 |
||
5186 |
(self red - aColor red) abs > 1 ifTrue:[^ false]. |
|
5187 |
(self green - aColor green) abs > 1 ifTrue:[^ false]. |
|
5188 |
(self blue - aColor blue) abs > 1 ifTrue:[^ false]. |
|
5189 |
^ true |
|
5190 |
||
5191 |
" |
|
5192 |
(Color red:10 green:10 blue:10) almostSameAs:(Color red:11 green:11 blue:11) |
|
5193 |
" |
|
5194 |
||
5195 |
"Modified: 28.2.1997 / 12:00:01 / cg" |
|
5196 |
! |
|
5197 |
||
1023 | 5198 |
hash |
5199 |
"return an integer useful as hash key for the receiver. |
|
5200 |
Redefined since = is redefined" |
|
5201 |
||
2318
36d73b850969
fixed hash for colorId colors.
Claus Gittinger <cg@exept.de>
parents:
2313
diff
changeset
|
5202 |
red isNil ifTrue:[ |
6353 | 5203 |
^ colorId |
2318
36d73b850969
fixed hash for colorId colors.
Claus Gittinger <cg@exept.de>
parents:
2313
diff
changeset
|
5204 |
]. |
1023 | 5205 |
^ red + green + blue |
5206 |
! ! |
|
5207 |
||
5208 |
!Color methodsFor:'converting'! |
|
5209 |
||
6830 | 5210 |
asByteArray |
7831 | 5211 |
"return the rgb byteValues as a 3-byte byteArray #[red green blue]" |
5212 |
||
5213 |
^ self rgbBytes. |
|
5214 |
"/ ^ByteArray |
|
5215 |
"/ with: self redByte |
|
5216 |
"/ with: self greenByte |
|
5217 |
"/ with: self blueByte |
|
5218 |
||
5219 |
"Modified: / 03-02-2017 / 11:33:23 / cg" |
|
6830 | 5220 |
! |
5221 |
||
1023 | 5222 |
fromLiteralArrayEncoding:encoding |
5223 |
"read my values from an encoding. |
|
6353 | 5224 |
The encoding is supposed to be either of the form: |
6552 | 5225 |
(#Color redPart greenPart bluePart) |
2778
3ef64f104266
allow 'Color colorName' in literalEncoding.
Claus Gittinger <cg@exept.de>
parents:
2455
diff
changeset
|
5226 |
or: |
6552 | 5227 |
(#Color constantColorSymbol) |
1023 | 5228 |
This is the reverse operation to #literalArrayEncoding." |
5229 |
||
6552 | 5230 |
|clr nameOrRGB| |
2778
3ef64f104266
allow 'Color colorName' in literalEncoding.
Claus Gittinger <cg@exept.de>
parents:
2455
diff
changeset
|
5231 |
|
8243 | 5232 |
red notNil ifTrue:[ |
5233 |
"oops cannot change an existing color (you want to make red be green - or what)" |
|
5234 |
self error:'Colors cannot change their components'. |
|
5235 |
^ self |
|
5236 |
]. |
|
5237 |
||
2778
3ef64f104266
allow 'Color colorName' in literalEncoding.
Claus Gittinger <cg@exept.de>
parents:
2455
diff
changeset
|
5238 |
encoding size == 2 ifTrue:[ |
6552 | 5239 |
nameOrRGB := encoding at:2. |
7411 | 5240 |
nameOrRGB isSymbol ifTrue:[ |
8243 | 5241 |
clr := self class name:nameOrRGB |
7411 | 5242 |
] ifFalse:[ |
7762 | 5243 |
clr := self class rgbValue:nameOrRGB. |
6552 | 5244 |
]. |
5245 |
red := clr scaledRed. |
|
5246 |
green := clr scaledGreen. |
|
5247 |
blue := clr scaledBlue |
|
2778
3ef64f104266
allow 'Color colorName' in literalEncoding.
Claus Gittinger <cg@exept.de>
parents:
2455
diff
changeset
|
5248 |
] ifFalse:[ |
8243 | 5249 |
red := ((encoding at:2) / 100.0 * MaxValue) rounded. |
5250 |
green := ((encoding at:3) / 100.0 * MaxValue) rounded. |
|
5251 |
blue := ((encoding at:4) / 100.0 * MaxValue) rounded. |
|
2778
3ef64f104266
allow 'Color colorName' in literalEncoding.
Claus Gittinger <cg@exept.de>
parents:
2455
diff
changeset
|
5252 |
]. |
1023 | 5253 |
|
5254 |
" |
|
8243 | 5255 |
Color new fromLiteralArrayEncoding:#(Color 50 25 25) |
5256 |
Color new fromLiteralArrayEncoding:#(Color 16rFF00FF) |
|
5257 |
Color new fromLiteralArrayEncoding:#(Color blue) |
|
5258 |
" |
|
5259 |
||
5260 |
"Modified (comment): / 11-01-2018 / 12:42:56 / stefan" |
|
1023 | 5261 |
! |
5262 |
||
5263 |
literalArrayEncoding |
|
5264 |
"encode myself as an array, from which a copy of the receiver |
|
5265 |
can be reconstructed with #decodeAsLiteralArray. |
|
6353 | 5266 |
The encoding is: |
6552 | 5267 |
(#Color redPart greenPart bluePart) |
1023 | 5268 |
" |
5269 |
||
5270 |
^ Array |
|
6552 | 5271 |
with:self class name |
7411 | 5272 |
with:((red * 100.0 / MaxValue) roundTo:0.25) |
5273 |
with:((green * 100.0 / MaxValue) roundTo:0.25) |
|
5274 |
with:((blue * 100.0 / MaxValue) roundTo:0.25) |
|
1023 | 5275 |
|
5276 |
" |
|
5277 |
Color new fromLiteralArrayEncoding:#(#Color 50 25 25) |
|
6353 | 5278 |
(Color red:25 green:30 blue:70) literalArrayEncoding |
1023 | 5279 |
" |
5280 |
||
5281 |
"Modified: 22.4.1996 / 13:00:11 / cg" |
|
5282 |
! ! |
|
5283 |
||
5284 |
!Color methodsFor:'copying'! |
|
5285 |
||
2910
97a836c7e15c
deepCopy fix (do not copy device dependent stuff)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
5286 |
skipInstvarIndexInDeepCopy:index |
97a836c7e15c
deepCopy fix (do not copy device dependent stuff)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
5287 |
index == 4 ifTrue:[ |
6353 | 5288 |
^ true "/ skip device |
2910
97a836c7e15c
deepCopy fix (do not copy device dependent stuff)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
5289 |
]. |
97a836c7e15c
deepCopy fix (do not copy device dependent stuff)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
5290 |
index == 5 ifTrue:[ |
6353 | 5291 |
^ true "/ skip colorId |
2910
97a836c7e15c
deepCopy fix (do not copy device dependent stuff)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
5292 |
]. |
97a836c7e15c
deepCopy fix (do not copy device dependent stuff)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
5293 |
index == 6 ifTrue:[ |
6353 | 5294 |
^ true "/ skip ditherForm |
2910
97a836c7e15c
deepCopy fix (do not copy device dependent stuff)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
5295 |
]. |
97a836c7e15c
deepCopy fix (do not copy device dependent stuff)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
5296 |
index == 7 ifTrue:[ |
6353 | 5297 |
^ true "/ skip replacementColor |
2910
97a836c7e15c
deepCopy fix (do not copy device dependent stuff)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
5298 |
]. |
97a836c7e15c
deepCopy fix (do not copy device dependent stuff)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
5299 |
^ false |
97a836c7e15c
deepCopy fix (do not copy device dependent stuff)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
5300 |
|
97a836c7e15c
deepCopy fix (do not copy device dependent stuff)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
5301 |
" |
97a836c7e15c
deepCopy fix (do not copy device dependent stuff)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
5302 |
(Color black onDevice:Screen current) deepCopy |
97a836c7e15c
deepCopy fix (do not copy device dependent stuff)
Claus Gittinger <cg@exept.de>
parents:
2889
diff
changeset
|
5303 |
" |
1023 | 5304 |
! ! |
5305 |
||
8692 | 5306 |
!Color methodsFor:'copying-private'! |
5307 |
||
5308 |
postCopy |
|
5309 |
"redefined to clear out any device handles in the copy" |
|
5310 |
||
5311 |
device := colorId := ditherForm := replacementColor := nil |
|
5312 |
||
5313 |
"Modified: 17.1.1997 / 00:03:42 / cg" |
|
5314 |
! ! |
|
5315 |
||
1023 | 5316 |
!Color methodsFor:'getting a device color'! |
5317 |
||
5318 |
exactOn:aDevice |
|
5319 |
"create a new Color representing the same color as |
|
5320 |
myself on aDevice; if one already exists, return the one. |
|
5321 |
Do not dither or otherwise approximate the color, but return |
|
6353 | 5322 |
nil, if the exact color is not available. |
7403 | 5323 |
Used to acquire primary colors for dithering, during startup." |
1023 | 5324 |
|
5325 |
|newColor id r g b| |
|
5326 |
||
5327 |
"if Iam already assigned to that device ..." |
|
5328 |
(device == aDevice and:[ditherForm isNil]) ifTrue:[^ self]. |
|
5329 |
||
5330 |
r := red. |
|
5331 |
g := green. |
|
5332 |
b := blue. |
|
5333 |
||
1239
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
5334 |
"first look if not already there" |
7762 | 5335 |
newColor := self class existingColorScaledRed:r scaledGreen:g scaledBlue:b on:aDevice. |
1239
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
5336 |
(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
|
5337 |
|
1023 | 5338 |
r := (r bitAnd:16rFF00) bitOr:(r bitShift:-8). |
5339 |
g := (g bitAnd:16rFF00) bitOr:(g bitShift:-8). |
|
5340 |
b := (b bitAnd:16rFF00) bitOr:(b bitShift:-8). |
|
5341 |
||
5342 |
"ask that device for the color" |
|
5343 |
id := aDevice colorScaledRed:r scaledGreen:g scaledBlue:b. |
|
5344 |
id isNil ifTrue:[ |
|
7403 | 5345 |
"/ this is a kludge: scavenge to free unused colors |
5346 |
"/ and try again ... |
|
5347 |
ObjectMemory scavenge; finalize. |
|
5348 |
id := aDevice colorScaledRed:r scaledGreen:g scaledBlue:b |
|
1023 | 5349 |
]. |
5350 |
id isNil ifTrue:[ |
|
7403 | 5351 |
"no such color - fail" |
1023 | 5352 |
|
5353 |
"/ 'COLOR: no color for ' infoPrint. self displayString infoPrintCR. |
|
7403 | 5354 |
^ nil |
1023 | 5355 |
]. |
5356 |
||
5357 |
"receiver was not associated - do it now" |
|
5358 |
device isNil ifTrue:[ |
|
7403 | 5359 |
device := aDevice. |
5360 |
colorId := id. |
|
5361 |
||
5362 |
aDevice visualType ~~ #TrueColor ifTrue:[ |
|
5363 |
"/ Lobby register:self. |
|
5364 |
aDevice registerColor:self. |
|
5365 |
]. |
|
5366 |
^ self |
|
1023 | 5367 |
]. |
5368 |
||
5369 |
"receiver was already associated to another device - need a new color" |
|
8277 | 5370 |
newColor := (self class basicNew) |
5371 |
setScaledRed:r scaledGreen:g scaledBlue:b |
|
5372 |
device:aDevice. |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
5373 |
newColor setColorId:id. |
1023 | 5374 |
aDevice visualType ~~ #TrueColor ifTrue:[ |
7403 | 5375 |
"/ Lobby register:newColor. |
5376 |
aDevice registerColor:newColor. |
|
1023 | 5377 |
]. |
5378 |
^ newColor |
|
5379 |
||
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
5380 |
"Modified: 24.2.1997 / 18:23:20 / cg" |
1023 | 5381 |
! |
5382 |
||
1856 | 5383 |
exactOrNearestOn:aDevice |
5384 |
"get a device color for the receiver, which is either exact |
|
5385 |
or the nearest, but never dithered. |
|
5386 |
This can be used for viewBackgrounds, where the exact greyLevel |
|
5387 |
does not matter, but a dithered color is not wanted." |
|
5388 |
||
5389 |
|deviceColor| |
|
5390 |
||
5391 |
deviceColor := self exactOn:aDevice. |
|
5392 |
deviceColor isNil ifTrue:[ |
|
6353 | 5393 |
deviceColor := self nearestOn:aDevice |
1856 | 5394 |
]. |
5395 |
^ deviceColor |
|
5396 |
||
5397 |
"Created: 13.8.1997 / 15:25:48 / cg" |
|
5398 |
! |
|
5399 |
||
6353 | 5400 |
nearestIn:aColorMap |
2198
122ff0da86d6
added support to find the nearest color in a colorMap.
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
5401 |
"return the nearest color in a colorMap" |
122ff0da86d6
added support to find the nearest color in a colorMap.
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
5402 |
|
122ff0da86d6
added support to find the nearest color in a colorMap.
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
5403 |
^ self class |
6353 | 5404 |
nearestColorScaledRed:(self scaledRed) |
5405 |
scaledGreen:(self scaledGreen) |
|
5406 |
scaledBlue:(self scaledBlue) |
|
5407 |
on:nil |
|
5408 |
in:aColorMap |
|
2198
122ff0da86d6
added support to find the nearest color in a colorMap.
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
5409 |
|
122ff0da86d6
added support to find the nearest color in a colorMap.
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
5410 |
"Created: / 28.7.1998 / 20:42:11 / cg" |
122ff0da86d6
added support to find the nearest color in a colorMap.
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
5411 |
! |
122ff0da86d6
added support to find the nearest color in a colorMap.
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
5412 |
|
6353 | 5413 |
nearestOn:aDevice |
5414 |
"create a new Color representing the same color as myself on aDevice; |
|
1023 | 5415 |
if one already exists, return the one. If no exact match is found, |
5416 |
search for the nearest match" |
|
5417 |
||
5418 |
|newColor id| |
|
5419 |
||
5420 |
"if I'am already assigned to that device ..." |
|
5421 |
(device == aDevice) ifTrue:[^ self]. |
|
5422 |
||
5423 |
"first look if not already there" |
|
7762 | 5424 |
newColor := self class nearestColorScaledRed:red scaledGreen:green scaledBlue:blue on:aDevice. |
1023 | 5425 |
newColor notNil ifTrue:[^ newColor]. |
5426 |
||
5427 |
"ask that device for the color" |
|
5428 |
id := aDevice colorScaledRed:red scaledGreen:green scaledBlue:blue. |
|
5429 |
id isNil ifTrue:[ |
|
7762 | 5430 |
"this is a kludge: |
5431 |
scavenge to possuby free unused colors and try again ... |
|
5432 |
this is a compromise: actually a full GC is required here, |
|
5433 |
but that is too expensive. |
|
5434 |
" |
|
5435 |
ObjectMemory scavenge; finalize. |
|
5436 |
id := aDevice colorScaledRed:red scaledGreen:green scaledBlue:blue |
|
1023 | 5437 |
]. |
5438 |
id isNil ifTrue:[ |
|
7762 | 5439 |
"no color - fail" |
5440 |
||
5441 |
^ nil |
|
1023 | 5442 |
]. |
5443 |
||
5444 |
"receiver was not associated - do it now" |
|
5445 |
device isNil ifTrue:[ |
|
7762 | 5446 |
device := aDevice. |
5447 |
colorId := id. |
|
5448 |
||
5449 |
aDevice visualType ~~ #TrueColor ifTrue:[ |
|
5450 |
"/ Lobby register:self. |
|
5451 |
aDevice registerColor:self. |
|
5452 |
]. |
|
5453 |
^ self |
|
1023 | 5454 |
]. |
5455 |
||
5456 |
"receiver was already associated to another device - need a new color" |
|
8277 | 5457 |
newColor := (self class basicNew) |
5458 |
setScaledRed:red scaledGreen:green scaledBlue:blue |
|
5459 |
device:aDevice. |
|
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
5460 |
newColor setColorId:id. |
1023 | 5461 |
aDevice visualType ~~ #TrueColor ifTrue:[ |
7762 | 5462 |
"/ Lobby register:newColor. |
5463 |
aDevice registerColor:newColor. |
|
1023 | 5464 |
]. |
5465 |
^ newColor |
|
5466 |
||
1365
37a9e7ac4dbc
moved color registration from Color class to per-device lobby
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
5467 |
"Modified: 24.2.1997 / 18:23:26 / cg" |
1023 | 5468 |
! |
5469 |
||
5470 |
on:aDevice |
|
5471 |
"create a new Color representing the same color as |
|
5472 |
myself on aDevice; if one already exists, return the one" |
|
5473 |
||
3623 | 5474 |
"/ send out a warning: #on: is typically used to create views |
5475 |
"/ operating on a model. |
|
5476 |
"/ Please use #onDevice: to avoid confusion. |
|
5477 |
||
5478 |
<resource:#obsolete> |
|
5479 |
||
5480 |
self obsoleteMethodWarning:'use #onDevice:'. |
|
2836 | 5481 |
^ self onDevice:aDevice |
5482 |
||
5483 |
"Created: / 16.11.1995 / 20:16:42 / cg" |
|
5484 |
"Modified: / 8.9.1998 / 17:32:10 / cg" |
|
5485 |
! |
|
5486 |
||
5487 |
onDevice:aDevice |
|
5488 |
"create a new Color representing the same color as |
|
5489 |
myself on aDevice; if one already exists, return the one" |
|
5490 |
||
6353 | 5491 |
|newColor id form |
1023 | 5492 |
greyV "{ Class: SmallInteger }" |
5493 |
rV "{ Class: SmallInteger }" |
|
6353 | 5494 |
gV "{ Class: SmallInteger }" |
1023 | 5495 |
bV "{ Class: SmallInteger }" |
2375
265a5137e286
oops - possible color reuse between devices fixed
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
5496 |
deviceVisual deviceFixColors deviceDepth| |
1023 | 5497 |
|
6353 | 5498 |
"/ the most common cases (already allocated) first |
1233 | 5499 |
|
5500 |
colorId notNil ifTrue:[ |
|
7291 | 5501 |
"/ is someone validating me before drawing on aDevice ? |
5502 |
(aDevice notNil and:[aDevice == device]) ifTrue:[ |
|
5503 |
^ self |
|
5504 |
]. |
|
5505 |
||
5506 |
"/ a special case for pseudo-colors (0 and 1 in bitmaps) |
|
5507 |
"/ those have nil r/g/b values, but a nonNil colorId |
|
5508 |
||
5509 |
red isNil ifTrue:[^ self]. |
|
5510 |
||
5511 |
"/ want to release color ? |
|
5512 |
||
5513 |
(aDevice isNil and:[device notNil]) ifTrue:[ |
|
5514 |
"/ trueColor device-colors are not registered |
|
5515 |
device visualType ~~ #TrueColor ifTrue:[ |
|
5516 |
device unregisterColor:newColor. |
|
5517 |
device freeColor:colorId |
|
5518 |
]. |
|
5519 |
device := nil. |
|
5520 |
colorId := nil. |
|
5521 |
^ self |
|
5522 |
]. |
|
1205 | 5523 |
]. |
2313 | 5524 |
aDevice isNil ifTrue:[ |
7291 | 5525 |
^ self |
2313 | 5526 |
]. |
1205 | 5527 |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
5528 |
device == aDevice ifTrue:[ |
7291 | 5529 |
ditherForm notNil ifTrue:[ |
5530 |
^ self |
|
5531 |
] |
|
1707
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
5532 |
]. |
c4ba0f13330c
made all dither stuff class protocol
Claus Gittinger <cg@exept.de>
parents:
1621
diff
changeset
|
5533 |
|
7650 | 5534 |
"/ on high-resolution true-color systems, don't care for dithering and |
1023 | 5535 |
"/ especially freeing colors |
2842 | 5536 |
"/ (no need to register) |
1023 | 5537 |
|
2375
265a5137e286
oops - possible color reuse between devices fixed
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
5538 |
deviceDepth := aDevice depth. |
1023 | 5539 |
(deviceVisual := aDevice visualType) == #TrueColor ifTrue:[ |
7291 | 5540 |
deviceDepth >= 15 ifTrue:[ |
8165 | 5541 |
id := aDevice colorScaledRed:(red ? 0) scaledGreen:(green ? 0) scaledBlue:(blue ? 0). |
7291 | 5542 |
id notNil ifTrue:[ |
5543 |
device isNil ifTrue:[ |
|
5544 |
"/ receiver was not associated - do it now & return mySelf |
|
5545 |
colorId := id. |
|
5546 |
ditherForm := nil. |
|
5547 |
device := aDevice. |
|
5548 |
^ self |
|
5549 |
]. |
|
8277 | 5550 |
newColor := (self class basicNew) |
8165 | 5551 |
setScaledRed:(red ? 0) |
5552 |
scaledGreen:(green ? 0) |
|
5553 |
scaledBlue:(blue ? 0) |
|
7291 | 5554 |
device:aDevice. |
5555 |
newColor setColorId:id. |
|
5556 |
^ newColor |
|
5557 |
] |
|
5558 |
] |
|
1023 | 5559 |
]. |
5560 |
||
1239
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
5561 |
rV := red. |
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
5562 |
gV := green. |
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
5563 |
bV := blue. |
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
5564 |
|
7782 | 5565 |
"/ "/ round a bit within 1% in red & green, 2% in blue |
1239
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
5566 |
"/ rV := (red / 100.0) rounded * 100. |
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
5567 |
"/ gV := (green / 100.0) rounded * 100. |
f4bd3bc9f3f9
oops - dont round when searching for existing colors
Claus Gittinger <cg@exept.de>
parents:
1238
diff
changeset
|
5568 |
"/ bV := (blue / 50.0) rounded * 50. |
7782 | 5569 |
"/ |
5570 |
"/ "/ if I am already assigned to that device ... |
|
5571 |
"/ |
|
1368 | 5572 |
"/ ((device == aDevice) and:[ditherForm notNil]) ifTrue:[ |
5573 |
"/ |
|
5574 |
"/ "/ mhmh - if I was dithered the last time (not enough colors then) |
|
5575 |
"/ "/ try again - maybe some colors were reclaimed in the meanwhile |
|
5576 |
"/ |
|
5577 |
"/ deviceFixColors := aDevice fixColors. |
|
5578 |
"/ |
|
5579 |
"/ (deviceFixColors isNil |
|
5580 |
"/ and:[RetryAllocation]) ifTrue:[ |
|
5581 |
"/ " |
|
5582 |
"/ but there is no chance on b&w displays - so don't try |
|
5583 |
"/ " |
|
5584 |
"/ aDevice depth > 2 ifTrue:[ |
|
5585 |
"/ id := aDevice colorScaledRed:rV scaledGreen:gV scaledBlue:bV. |
|
5586 |
"/ id notNil ifTrue:[ |
|
5587 |
"/ colorId := id. |
|
5588 |
"/ ditherForm := nil. |
|
5589 |
"/ device registerColor:self. |
|
5590 |
"/ ] |
|
5591 |
"/ ] |
|
5592 |
"/ ]. |
|
5593 |
"/ ^ self |
|
5594 |
"/ ]. |
|
1023 | 5595 |
|
7762 | 5596 |
newColor := self class existingColorScaledRed:rV scaledGreen:gV scaledBlue:bV on:aDevice. |
2973 | 5597 |
newColor notNil ifTrue:[ |
7291 | 5598 |
(newColor scaledRed ~~ red |
5599 |
or:[newColor scaledGreen ~~ green |
|
5600 |
or:[newColor scaledBlue ~~ blue]]) ifTrue:[ |
|
5601 |
Transcript showCR:'Color>>#onDevice: got different color'. |
|
5602 |
]. |
|
5603 |
^ newColor |
|
2973 | 5604 |
]. |
5605 |
||
5606 |
"/ ask that device for the exact color |
|
5607 |
id := aDevice colorScaledRed:red scaledGreen:green scaledBlue:blue. |
|
5608 |
id notNil ifTrue:[ |
|
7291 | 5609 |
device isNil ifTrue:[ |
5610 |
"/ receiver was not associated - do it now & return mySelf |
|
5611 |
colorId := id. |
|
5612 |
ditherForm := nil. |
|
5613 |
device := aDevice. |
|
5614 |
newColor := self. |
|
5615 |
] ifFalse:[ |
|
7762 | 5616 |
newColor := self class basicNew |
7291 | 5617 |
setScaledRed:red |
5618 |
scaledGreen:green |
|
5619 |
scaledBlue:blue |
|
5620 |
device:aDevice. |
|
5621 |
newColor setColorId:id. |
|
5622 |
]. |
|
5623 |
id notNil ifTrue:[ |
|
5624 |
deviceVisual ~~ #TrueColor ifTrue:[ |
|
5625 |
aDevice registerColor:newColor. |
|
5626 |
] |
|
5627 |
]. |
|
5628 |
^ newColor |
|
6353 | 5629 |
]. |
1023 | 5630 |
|
5631 |
"/ |
|
2973 | 5632 |
"/ ok, we are either going to dither that color, or look for |
5633 |
"/ the nearest. |
|
7885 | 5634 |
"/ if it's 'almost' grey, make it grey and round it a bit (1%) |
1023 | 5635 |
"/ |
5636 |
greyV := (3 * red) + (6 * green) + (1 * blue). |
|
1621 | 5637 |
greyV := (greyV / 1000.0) rounded * 100. |
1023 | 5638 |
|
5639 |
"/ allow an error of 1% in red & green, 2% in blue |
|
5640 |
||
5641 |
((rV - greyV) abs <= 655 "/ MaxValue // 100 |
|
5642 |
and:[(gV - greyV) abs <= 655 "/ MaxValue // 100 |
|
5643 |
and:[(bV - greyV) abs <= 1310]]) ifTrue:[ "/ MaxValue // 100 * 2 |
|
7291 | 5644 |
rV := gV := bV := greyV. |
1023 | 5645 |
] ifFalse:[ |
7291 | 5646 |
rV := red. gV := green. bV := blue. |
1023 | 5647 |
]. |
5648 |
||
5649 |
aDevice hasColors ifTrue:[ |
|
7291 | 5650 |
deviceFixColors := aDevice fixColors. |
5651 |
deviceFixColors isNil ifTrue:[ |
|
5652 |
"/ ask that device for the exact color |
|
5653 |
id := aDevice colorScaledRed:rV scaledGreen:gV scaledBlue:bV. |
|
5654 |
id isNil ifTrue:[ |
|
5655 |
aDevice isOpen ifFalse:[ |
|
5656 |
^ nil |
|
5657 |
]. |
|
5658 |
||
5659 |
"/ this is a kludge: scavenge to free unused colors |
|
5660 |
"/ and try again ... |
|
5661 |
ObjectMemory scavenge; finalize. |
|
5662 |
id := aDevice colorScaledRed:rV scaledGreen:gV scaledBlue:bV |
|
5663 |
]. |
|
5664 |
||
5665 |
id isNil ifTrue:[ |
|
5666 |
"/ no such color - try color dithers |
|
5667 |
||
5668 |
self class |
|
5669 |
ditherRed:rV green:gV blue:bV |
|
5670 |
on:aDevice |
|
5671 |
into:[:c :f | newColor := c. form := f]. |
|
5672 |
newColor notNil ifTrue:[^ newColor]. |
|
5673 |
]. |
|
5674 |
]. |
|
5675 |
||
5676 |
"/ none found ? -> do a hard dither using fixColors |
|
5677 |
||
5678 |
(id isNil and:[form isNil]) ifTrue:[ |
|
5679 |
deviceFixColors notNil ifTrue:[ |
|
5680 |
self class |
|
5681 |
fixDitherRed:rV green:gV blue:bV |
|
5682 |
on:aDevice |
|
5683 |
into:[:c :f | newColor := c. form := f]. |
|
5684 |
newColor notNil ifTrue:[^ newColor]. |
|
5685 |
] |
|
5686 |
]. |
|
5687 |
||
5688 |
"/ still none found ? -> do a very hard dither using existing colors |
|
5689 |
||
5690 |
(id isNil and:[form isNil]) ifTrue:[ |
|
5691 |
self class |
|
5692 |
complexDitherRed:rV green:gV blue:bV |
|
5693 |
on:aDevice |
|
5694 |
into:[:c :f | newColor := c. form := f]. |
|
5695 |
newColor notNil ifTrue:[^ newColor]. |
|
5696 |
]. |
|
1023 | 5697 |
]. |
5698 |
||
5699 |
(id isNil and:[form isNil]) ifTrue:[ |
|
7291 | 5700 |
"still no result - try graying" |
5701 |
||
5702 |
greyV == 0 ifTrue:[ |
|
5703 |
id := aDevice blackpixel |
|
5704 |
] ifFalse:[ |
|
5705 |
greyV == MaxValue ifTrue:[ |
|
5706 |
id := aDevice whitepixel |
|
5707 |
] ifFalse:[ |
|
5708 |
aDevice hasGrayscales ifTrue:[ |
|
5709 |
self class |
|
5710 |
ditherGrayFor:(greyV / MaxValue) |
|
5711 |
on:aDevice |
|
5712 |
into:[:c :f | newColor := c. form := f]. |
|
5713 |
newColor notNil ifTrue:[^ newColor]. |
|
5714 |
]. |
|
5715 |
form isNil ifTrue:[ |
|
5716 |
"/ still none - dither b&w |
|
5717 |
self class |
|
5718 |
monoDitherFor:(greyV / MaxValue) |
|
5719 |
between:Black and:White |
|
5720 |
on:aDevice |
|
5721 |
into:[:c :f | newColor := c. form := f]. |
|
5722 |
newColor notNil ifTrue:[^ newColor]. |
|
5723 |
form isNil ifTrue:[ |
|
5724 |
"/ cannot happen |
|
5725 |
'Color [warning]: monoDither failed' errorPrintCR. |
|
5726 |
^ nil |
|
5727 |
] |
|
5728 |
] |
|
5729 |
] |
|
5730 |
]. |
|
1023 | 5731 |
]. |
5732 |
||
5733 |
device isNil ifTrue:[ |
|
7291 | 5734 |
"/ receiver was not associated - do it now & return mySelf |
5735 |
||
5736 |
device := aDevice. |
|
5737 |
id isNil ifTrue:[ |
|
5738 |
ditherForm := form |
|
5739 |
]. |
|
5740 |
colorId := id. |
|
5741 |
||
5742 |
"/ have to register - otherwise it keeps old info around |
|
5743 |
||
5744 |
id notNil ifTrue:[ |
|
5745 |
deviceVisual ~~ #TrueColor ifTrue:[ |
|
5746 |
aDevice registerColor:self. |
|
5747 |
] |
|
5748 |
]. |
|
5749 |
^ self |
|
1023 | 5750 |
]. |
5751 |
||
5752 |
"/ receiver was already associated to another device |
|
5753 |
"/ - need a new color and return it |
|
5754 |
||
7762 | 5755 |
newColor := self class basicNew |
7291 | 5756 |
setScaledRed:red |
5757 |
scaledGreen:green |
|
5758 |
scaledBlue:blue |
|
5759 |
device:aDevice. |
|
1023 | 5760 |
id isNil ifTrue:[ |
7291 | 5761 |
newColor setDitherForm:form |
1023 | 5762 |
] ifFalse:[ |
7291 | 5763 |
newColor setColorId:id. |
5764 |
||
5765 |
"/ trueColor device-colors are not registered |
|
5766 |
deviceVisual ~~ #TrueColor ifTrue:[ |
|
5767 |
aDevice registerColor:newColor. |
|
5768 |
] |
|
1023 | 5769 |
]. |
5770 |
^ newColor |
|
5771 |
||
7885 | 5772 |
"Created: / 16-11-1995 / 20:16:42 / cg" |
8165 | 5773 |
"Modified: / 05-09-2017 / 12:20:54 / cg" |
1023 | 5774 |
! ! |
5775 |
||
5776 |
||
5777 |
!Color methodsFor:'instance creation'! |
|
5778 |
||
2948 | 5779 |
alpha:alphaValue |
4789 | 5780 |
"return a new color with the same color, but different alpha as the receiver. |
5781 |
The alpha arguments range is 0..1 (0=completely transparent; 1=completely opaque)" |
|
2948 | 5782 |
|
5783 |
alphaValue = 1 ifTrue:[ ^ self]. |
|
6353 | 5784 |
^ (TranslucentColor |
5785 |
scaledRed:red |
|
5786 |
scaledGreen:green |
|
5787 |
scaledBlue:blue) alpha:alphaValue |
|
2948 | 5788 |
|
5789 |
" |
|
4789 | 5790 |
(Color red alpha:0.5) alpha |
6353 | 5791 |
Color red alpha |
4789 | 5792 |
" |
5793 |
||
5794 |
"Modified: / 06-06-2007 / 11:17:55 / cg" |
|
2948 | 5795 |
! |
5796 |
||
1023 | 5797 |
blendWith:aColor |
5798 |
"create a new color from equally mixing the receiver |
|
5799 |
and the argument, aColor. |
|
6353 | 5800 |
Mixing is done by adding components |
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5801 |
(which is different from mixing colors on paper .. which is subtractive)." |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5802 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5803 |
^ self mixed:1 with:aColor |
1023 | 5804 |
|
5805 |
" |
|
5806 |
(Color red) blendWith:(Color yellow) |
|
5807 |
(Color red) blendWith:(Color blue) |
|
1326
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
5808 |
(Color red) blendWith:(Color black) |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
5809 |
(Color red) blendWith:(Color white) |
1023 | 5810 |
" |
5811 |
||
1326
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
5812 |
"Modified: 10.2.1997 / 22:08:14 / cg" |
1023 | 5813 |
! |
5814 |
||
5965 | 5815 |
contrastingBlackOrWhite |
7639 | 5816 |
"answer either black or white, whichever gives a better contrast |
5817 |
for drawing text on a background with my color. |
|
5818 |
(i.e. if I am dark, return white; if I am bright, return black" |
|
5819 |
||
5820 |
^ self brightness < 0.55 |
|
5821 |
ifTrue:[self class white] |
|
5822 |
ifFalse:[self class black] |
|
5823 |
||
5824 |
" |
|
5825 |
(Color blue) contrastingBlackOrWhite |
|
5826 |
(Color red) contrastingBlackOrWhite |
|
5827 |
(Color green) contrastingBlackOrWhite |
|
5828 |
(Color yellow) contrastingBlackOrWhite |
|
5829 |
" |
|
5830 |
! |
|
5831 |
||
5832 |
contrastingColorFor:aBackgroundColor |
|
5833 |
"answer a slightly brightened or darkened variant of myself, |
|
5834 |
to ensure a good contrast when showing text on a background color. |
|
5835 |
i.e. when drawing read on grey, it might be better to darken or brighten |
|
7885 | 5836 |
the red, if it's brightness is too near to the grey's brightness. |
7639 | 5837 |
Use this for alert strings shown on a color background." |
5838 |
||
5839 |
|colorUsed bgBrightness| |
|
5840 |
||
5841 |
colorUsed := self. |
|
5842 |
bgBrightness := aBackgroundColor brightness. |
|
5843 |
||
5844 |
(bgBrightness dist:colorUsed brightness) < 0.5 ifTrue:[ |
|
5845 |
bgBrightness > 0.5 ifTrue:[ |
|
5846 |
colorUsed := self slightlyDarkened. |
|
5847 |
(bgBrightness dist:colorUsed brightness) < 0.5 ifTrue:[ |
|
5848 |
colorUsed := self darkened. |
|
5849 |
]. |
|
5850 |
] ifFalse:[ |
|
5851 |
colorUsed := self slightlyLightened. |
|
5852 |
(bgBrightness dist:colorUsed brightness) < 0.5 ifTrue:[ |
|
5853 |
colorUsed := self lightened. |
|
5854 |
]. |
|
5855 |
]. |
|
5856 |
]. |
|
5857 |
^ colorUsed. |
|
5858 |
||
5859 |
" |
|
5860 |
(Color blue) contrastingColorFor:Color white. |
|
5861 |
(Color blue) contrastingColorFor:Color blue. |
|
8456 | 5862 |
(Color blue) contrastingColorFor:View defaultBackgroundColor. |
7639 | 5863 |
(Color red) contrastingColorFor:Color grey |
5864 |
(Color blue) contrastingColorFor:Color black |
|
5865 |
" |
|
7885 | 5866 |
|
5867 |
"Modified (comment): / 13-02-2017 / 19:58:34 / cg" |
|
8456 | 5868 |
"Modified (comment): / 29-08-2018 / 13:28:53 / Claus Gittinger" |
5965 | 5869 |
! |
5870 |
||
1023 | 5871 |
darkened |
5872 |
"return a new color, which is slightly darker than the receiver" |
|
5873 |
||
5874 |
^ self blendWith:Black |
|
5875 |
||
5876 |
" |
|
5877 |
(Color red) darkened |
|
5878 |
(Color red) darkened darkened |
|
5879 |
" |
|
5880 |
||
5881 |
"Modified: 11.6.1996 / 18:10:37 / cg" |
|
5882 |
! |
|
5883 |
||
5884 |
lightened |
|
5885 |
"return a new color, which is slightly lighter than the receiver" |
|
5886 |
||
5887 |
^ self blendWith:White |
|
5888 |
||
5889 |
" |
|
5890 |
(Color red) lightened |
|
5891 |
(Color red) lightened lightened |
|
5892 |
" |
|
5893 |
||
5894 |
"Modified: 11.6.1996 / 18:10:49 / cg" |
|
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5895 |
! |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5896 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5897 |
mixed:amount with:aColor |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5898 |
"create a new color from mixing amount of the receiver |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5899 |
with the argument, aColor. |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5900 |
Mixing is done by adding components (i.e. additive mixing) |
8165 | 5901 |
(which is different from mixing colors on paper, which is subtractive). |
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5902 |
With an amount of 1, this is the same as blendWith." |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5903 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5904 |
red isNil ifTrue:[ |
8165 | 5905 |
^ aColor |
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5906 |
]. |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5907 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5908 |
^ (self class) |
8165 | 5909 |
scaledRed:((red * amount) + aColor scaledRed) // (1 + amount) |
5910 |
scaledGreen:((green * amount) + aColor scaledGreen) // (1 + amount) |
|
5911 |
scaledBlue:((blue * amount) + aColor scaledBlue) // (1 + amount) |
|
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5912 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5913 |
" |
8437 | 5914 |
(Color red) mixed:1 with:(Color yellow) - 1 part red, 1 part yellow |
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5915 |
(Color red) mixed:0.9 with:(Color yellow) |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5916 |
(Color red) mixed:0.8 with:(Color yellow) |
8437 | 5917 |
(Color red) mixed:0.5 with:(Color yellow) - 1 part red, 2 parts yellow |
5918 |
(Color red) mixed:0.25 with:(Color yellow) - 1 part red, 4 parts yellow |
|
5919 |
(Color red) mixed:0 with:(Color yellow) - 0 parts red, 1 part yellow |
|
2943
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5920 |
|
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5921 |
(Color red) mixed:1 with:(Color white) |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5922 |
(Color red) mixed:0.8 with:(Color white) |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5923 |
(Color red) mixed:0.8 with:(Color black) |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5924 |
" |
6b4dca5fbee2
more lightening/darkening stuff
Claus Gittinger <cg@exept.de>
parents:
2942
diff
changeset
|
5925 |
|
8165 | 5926 |
"Modified: / 10-02-1997 / 22:08:14 / cg" |
5927 |
"Modified (comment): / 05-09-2017 / 14:35:40 / cg" |
|
8437 | 5928 |
"Modified (comment): / 31-07-2018 / 21:32:52 / Claus Gittinger" |
3724
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5929 |
! |
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5930 |
|
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5931 |
slightlyDarkened |
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5932 |
"return a new color, which is a bit darker than the receiver" |
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5933 |
|
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5934 |
^ self blendWith:(self blendWith:Black) |
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5935 |
|
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5936 |
" |
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5937 |
(Color green) inspect |
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5938 |
(Color green) darkened inspect |
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5939 |
(Color green) slightlyDarkened inspect |
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5940 |
" |
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5941 |
! |
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5942 |
|
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5943 |
slightlyLightened |
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5944 |
"return a new color, which is a bit lighter than the receiver" |
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5945 |
|
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5946 |
^ self blendWith:(self blendWith:White) |
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5947 |
|
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5948 |
" |
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5949 |
(Color red) inspect |
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5950 |
(Color red) lightened inspect |
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5951 |
(Color red) slightlyLightened inspect |
e35133b39f25
+ slightlyLightened/darkened
Claus Gittinger <cg@exept.de>
parents:
3665
diff
changeset
|
5952 |
" |
1023 | 5953 |
! ! |
5954 |
||
5955 |
!Color methodsFor:'instance release'! |
|
5956 |
||
2845 | 5957 |
executor |
1023 | 5958 |
"redefined, since for finalization only device and colorIndex |
5959 |
are needed - thus a faster copy is possible here" |
|
5960 |
||
2845 | 5961 |
^ DeviceColorHandle basicNew setDevice:device colorId:colorId |
5962 |
! |
|
5963 |
||
5964 |
releaseFromDevice |
|
5965 |
"I am no longer available on the device" |
|
5966 |
||
2975 | 5967 |
colorId := device := ditherForm := replacementColor := nil. |
2845 | 5968 |
|
1023 | 5969 |
! ! |
5970 |
||
3122 | 5971 |
!Color methodsFor:'misc'! |
5972 |
||
5973 |
magnifiedTo: extent |
|
5974 |
"do nothing here, for compatibility with Image/Form" |
|
5975 |
! ! |
|
5976 |
||
6967 | 5977 |
|
4851 | 5978 |
!Color methodsFor:'object persistency'! |
1023 | 5979 |
|
4207 | 5980 |
elementDescriptorFor:aspect |
4851 | 5981 |
"support for persistency: |
5982 |
answer the elements to be made persistent with an ObjectCoder" |
|
5983 |
||
3935 | 5984 |
red isNil ifTrue:[ |
6353 | 5985 |
^ Array with:(#colorId->colorId) |
3935 | 5986 |
]. |
5987 |
^ Array with:(#red->self red) with:(#green->self green) with:(#blue->self blue) |
|
4851 | 5988 |
! ! |
5989 |
||
5990 |
!Color methodsFor:'printing & storing'! |
|
3935 | 5991 |
|
8735 | 5992 |
displayOn:aStream |
8736 | 5993 |
|clsName colorName| |
5994 |
||
5995 |
clsName := self className. |
|
5996 |
(colorName := self standardColorNameOrNil) notNil ifTrue:[ |
|
5997 |
aStream nextPutAll:'(',clsName,' ',colorName,')'. |
|
5998 |
^ self |
|
5999 |
]. |
|
6000 |
aStream nextPutAll:clsName. |
|
8735 | 6001 |
aStream nextPutAll:'('. |
6002 |
aStream nextPutAll:self htmlPrintString. |
|
6003 |
aStream nextPutAll:')'. |
|
6004 |
||
6005 |
" |
|
6006 |
Color red printString |
|
6007 |
Color red displayString |
|
8736 | 6008 |
Color red storeString |
6009 |
||
6010 |
Color red lightened printString |
|
6011 |
Color red lightened displayString |
|
6012 |
Color red lightened storeString |
|
8735 | 6013 |
" |
6014 |
||
6015 |
"Created: / 18-07-2019 / 12:27:33 / Claus Gittinger" |
|
6016 |
! |
|
6017 |
||
4850
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6018 |
hex |
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6019 |
<resource: #obsolete> |
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6020 |
|
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6021 |
self obsoleteMethodWarning:'use #hexPrintString'. |
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6022 |
^ self hexPrintString |
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6023 |
! |
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6024 |
|
8063 | 6025 |
hexPrintOn:aStream |
6026 |
"print a base16 representation on aStream as rrggbb" |
|
6027 |
||
6028 |
red isNil ifTrue:[ |
|
6029 |
colorId notNil ifTrue:[ |
|
6030 |
colorId printOn:aStream base:16 size:6 fill:$0. |
|
6031 |
] |
|
6032 |
] ifFalse:[ |
|
6033 |
self redByte printOn:aStream base:16 size:2 fill:$0. |
|
6034 |
self greenByte printOn:aStream base:16 size:2 fill:$0. |
|
6035 |
self blueByte printOn:aStream base:16 size:2 fill:$0. |
|
6036 |
]. |
|
6037 |
||
6038 |
"Created: / 08-08-2017 / 15:58:52 / stefan" |
|
6039 |
! |
|
6040 |
||
4850
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6041 |
hexPrintString |
4908 | 6042 |
"return a hex-printString as rrggbb" |
6043 |
||
6044 |
|s| |
|
6045 |
||
6046 |
s := WriteStream on:(String new:6). |
|
8063 | 6047 |
self hexPrintOn:s. |
4908 | 6048 |
^ s contents. |
6049 |
||
6050 |
" |
|
6051 |
Color red hexPrintString |
|
6052 |
Color green hexPrintString |
|
6053 |
Color blue hexPrintString |
|
6353 | 6054 |
Color yellow hexPrintString |
4850
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6055 |
" |
8063 | 6056 |
|
6057 |
"Modified: / 08-08-2017 / 15:59:38 / stefan" |
|
4850
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6058 |
! |
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6059 |
|
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6060 |
htmlPrintString |
8787 | 6061 |
"return a hex-printString for html as #rrggbb" |
4850
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6062 |
|
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6063 |
^ '#',(self hexPrintString) |
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6064 |
|
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6065 |
" |
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6066 |
Color red htmlPrintString |
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6067 |
Color green htmlPrintString |
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6068 |
Color blue htmlPrintString |
6353 | 6069 |
Color yellow htmlPrintString |
4850
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6070 |
" |
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6071 |
! |
5e45abdda305
hexPrintString; htmlPrintString
Claus Gittinger <cg@exept.de>
parents:
4789
diff
changeset
|
6072 |
|
1023 | 6073 |
printOn:aStream |
6074 |
"append a string representing of the receiver |
|
6075 |
to the argument, aStream" |
|
6076 |
||
6077 |
self storeOn:aStream |
|
6078 |
! |
|
6079 |
||
8736 | 6080 |
standardColorNameOrNil |
6081 |
|myRed myGreen myBlue| |
|
6082 |
||
6083 |
myRed := self scaledRed. |
|
6084 |
myGreen := self scaledGreen. |
|
6085 |
myBlue := self scaledBlue. |
|
6086 |
StandardColorValues keysAndValuesDo:[:nm :rgbTriple | |
|
6087 |
(myRed = (rgbTriple at:1) |
|
6088 |
and:[ myGreen = (rgbTriple at:2) |
|
6089 |
and:[ myBlue = (rgbTriple at:3) |
|
6090 |
]]) ifTrue:[ |
|
6091 |
^ nm |
|
6092 |
] |
|
6093 |
]. |
|
6094 |
^ nil |
|
6095 |
||
6096 |
" |
|
6097 |
Color red standardColorNameOrNil |
|
6098 |
" |
|
6099 |
||
6100 |
"Created: / 18-07-2019 / 12:32:01 / Claus Gittinger" |
|
6101 |
! |
|
6102 |
||
1023 | 6103 |
storeOn:aStream |
6104 |
"append a string representing an expression to reconstruct the receiver |
|
6105 |
to the argument, aStream" |
|
6106 |
||
8736 | 6107 |
|clsName colorName| |
2942
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6108 |
|
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6109 |
clsName := self class name. |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6110 |
|
1023 | 6111 |
red isNil ifTrue:[ |
8736 | 6112 |
colorId notNil ifTrue:[ |
6113 |
aStream nextPutAll:'(' , clsName , ' colorId:'. |
|
6114 |
colorId storeOn:aStream. |
|
6115 |
aStream nextPut:$). |
|
6116 |
^ self |
|
6117 |
] |
|
1023 | 6118 |
]. |
8736 | 6119 |
(colorName := self standardColorNameOrNil) notNil ifTrue:[ |
6120 |
aStream nextPutAll:'(',clsName,' ',colorName,')'. |
|
6121 |
^ self |
|
1023 | 6122 |
]. |
8736 | 6123 |
|
2942
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6124 |
aStream nextPutAll:'(' , clsName , ' red:'. |
1023 | 6125 |
(self red) storeOn:aStream. |
6126 |
aStream nextPutAll:' green:'. |
|
6127 |
(self green) storeOn:aStream. |
|
6128 |
aStream nextPutAll:' blue:'. |
|
6129 |
(self blue) storeOn:aStream. |
|
6130 |
aStream nextPut:$). |
|
8736 | 6131 |
|
6132 |
"Modified: / 18-07-2019 / 12:33:21 / Claus Gittinger" |
|
1023 | 6133 |
! ! |
6134 |
||
6135 |
!Color methodsFor:'private'! |
|
6136 |
||
6137 |
restored |
|
6138 |
"private: color has been restored (either from snapin or binary store); |
|
6139 |
flush device stuff or reallocate a cell." |
|
6140 |
||
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6141 |
ditherForm := replacementColor := nil. |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6142 |
|
1023 | 6143 |
red notNil ifTrue:[ |
6353 | 6144 |
device := nil. |
6145 |
colorId := nil |
|
1023 | 6146 |
] ifFalse:[ |
6353 | 6147 |
"a variable color has been restored" |
6148 |
(colorId notNil and:[writable == true and:[device notNil]]) ifTrue:[ |
|
6149 |
colorId := device colorCell. |
|
6150 |
device setColor:colorId scaledRed:red scaledGreen:green scaledBlue:blue |
|
6151 |
] |
|
1023 | 6152 |
] |
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6153 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6154 |
"Modified: 17.1.1997 / 00:04:14 / cg" |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6155 |
! |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6156 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6157 |
setColorId:anId |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6158 |
"private: set the deviceId" |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6159 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6160 |
colorId := anId |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6161 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6162 |
"Created: 17.1.1997 / 00:05:41 / cg" |
1023 | 6163 |
! |
6164 |
||
6165 |
setDevice:aDevice colorId:aNumber |
|
6166 |
"private:set device and colorId" |
|
6167 |
||
6168 |
device := aDevice. |
|
1934 | 6169 |
colorId := aNumber. |
6170 |
writable := false. |
|
6171 |
! |
|
6172 |
||
6173 |
setDevice:aDevice colorId:aNumber writable:wBool |
|
6174 |
"private:set device, colorId and writable flag" |
|
6175 |
||
6176 |
device := aDevice. |
|
6177 |
colorId := aNumber. |
|
6178 |
writable := wBool. |
|
1023 | 6179 |
! |
6180 |
||
1238
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6181 |
setDitherForm:aForm |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6182 |
"private: set the ditherForm" |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6183 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6184 |
ditherForm := aForm |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6185 |
|
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6186 |
"Created: 17.1.1997 / 00:04:57 / cg" |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6187 |
! |
b363894182d0
prepare for replacement colors
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
6188 |
|
8277 | 6189 |
setScaledRed:r scaledGreen:g scaledBlue:b |
1023 | 6190 |
"private: set the components" |
6191 |
||
6192 |
red notNil ifTrue:[ |
|
8243 | 6193 |
"oops cannot change an existing color (you want to make red be green - or what)" |
6194 |
self error:'Colors cannot change their components'. |
|
6195 |
^ self |
|
1023 | 6196 |
]. |
6197 |
red := r. |
|
6198 |
green := g. |
|
6199 |
blue := b. |
|
8277 | 6200 |
! |
6201 |
||
6202 |
setScaledRed:r scaledGreen:g scaledBlue:b device:aDevice |
|
6203 |
"private: set the components" |
|
6204 |
||
6205 |
self setScaledRed:r scaledGreen:g scaledBlue:b. |
|
6206 |
device := aDevice. |
|
1233 | 6207 |
|
8243 | 6208 |
"Modified: / 16-01-1997 / 22:39:26 / cg" |
6209 |
"Modified (format): / 11-01-2018 / 12:25:46 / stefan" |
|
1023 | 6210 |
! ! |
6211 |
||
6212 |
!Color methodsFor:'queries'! |
|
6213 |
||
6214 |
averageColor |
|
6793 | 6215 |
"return the average color - that's myself. |
6216 |
This method has been added for compatibility with the image protocol." |
|
1023 | 6217 |
|
6353 | 6218 |
^ self |
1023 | 6219 |
! |
6220 |
||
6221 |
averageColorIn:aRectangle |
|
7580 | 6222 |
"return the average color - that's myself. |
6793 | 6223 |
This method has been added for compatibility with the image protocol." |
1023 | 6224 |
|
6353 | 6225 |
^ self |
1023 | 6226 |
! |
6227 |
||
6228 |
brightness |
|
6229 |
"ST80 compatibility: return the grey intensity in [0..1]" |
|
6230 |
||
6384 | 6231 |
red isNil ifTrue:[ |
6232 |
"/ a hack for colorId:0 and colorId:1 pseudo mask colors. |
|
6233 |
colorId == 0 ifTrue:[^ 0]. |
|
6234 |
^ 1 |
|
6235 |
]. |
|
1023 | 6236 |
^ ((3 * red) + (6 * green) + (blue)) / 10.0 / MaxValue |
6237 |
||
8171 | 6238 |
" |
6239 |
Color black brightness -> 0.0 |
|
6240 |
Color white brightness -> 1.0 |
|
6241 |
Color red brightness -> 0.3 |
|
6242 |
Color green brightness -> 0.6 |
|
6243 |
Color blue brightness -> 0.1 |
|
6244 |
" |
|
6245 |
||
6246 |
"Modified: / 07-06-1996 / 19:42:21 / cg" |
|
6247 |
"Modified (comment): / 10-09-2017 / 12:02:29 / cg" |
|
1023 | 6248 |
! |
6249 |
||
6250 |
deltaFrom:aColor |
|
6251 |
"return the distance of the receiver from some color specified |
|
6785 | 6252 |
by r/g/b values. |
6253 |
A very questionable value; |
|
7411 | 6254 |
basing the distance on rgb values is very bad |
6785 | 6255 |
- better do a distance in a cie color cone" |
1023 | 6256 |
|
6257 |
^ aColor deltaFromRed:self red green:self green blue:self blue |
|
6258 |
||
3005 | 6259 |
" |
6353 | 6260 |
Color red deltaFrom:(Color blue) |
6261 |
Color red deltaFrom:(Color yellow) |
|
6262 |
Color red deltaFrom:(Color red:50) |
|
3005 | 6263 |
" |
6264 |
||
1023 | 6265 |
"Created: 14.6.1996 / 20:07:22 / cg" |
6266 |
"Modified: 14.6.1996 / 20:49:32 / cg" |
|
6267 |
! |
|
6268 |
||
6269 |
deltaFromRed:r green:g blue:b |
|
6270 |
"return the distance of the receiver from some color specified |
|
6271 |
by r/g/b values" |
|
6272 |
||
6273 |
" |
|
6274 |
Q: how should component errors be weighted ? |
|
6275 |
" |
|
3005 | 6276 |
^ ((self red - r) abs |
1023 | 6277 |
+ (self green - g) abs |
3005 | 6278 |
+ (self blue - b) abs) rounded. |
1023 | 6279 |
|
6280 |
"Created: 14.6.1996 / 20:03:58 / cg" |
|
6281 |
"Modified: 14.6.1996 / 20:20:24 / cg" |
|
6282 |
! |
|
6283 |
||
6284 |
deltaFromScaledRed:r scaledGreen:g scaledBlue:b |
|
6285 |
"return the distance of the receiver from some color specified |
|
6286 |
by r/g/b values" |
|
6287 |
||
6288 |
" |
|
6289 |
Q: how should component errors be weighted ? |
|
6290 |
" |
|
6291 |
^ (red - r) abs |
|
6292 |
+ (green - g) abs |
|
6293 |
+ (blue - b) abs. |
|
6294 |
||
6295 |
"Created: 11.6.1996 / 18:01:12 / cg" |
|
6296 |
"Modified: 14.6.1996 / 20:36:14 / cg" |
|
6297 |
! |
|
6298 |
||
6299 |
errorFrom:aColor |
|
6300 |
"return some value which can be used to compare colors. |
|
6301 |
The following simply returns the vector distance of the r/g/b vectors. |
|
6302 |
This may not be a very good idea; probably, we should honor the |
|
6303 |
fact that the hue difference should have more weight than saturation and/or light" |
|
6304 |
||
6305 |
^ (red - aColor scaledRed) squared |
|
6306 |
+ (green - aColor scaledGreen) squared |
|
6307 |
+ (blue - aColor scaledBlue) squared. |
|
6308 |
! |
|
6309 |
||
8966 | 6310 |
grayByte |
6311 |
"return the grey intensity in [0..255]" |
|
6312 |
||
6313 |
red isNil ifTrue:[ |
|
6314 |
"/ a hack for colorId:0 and colorId:1 pseudo mask colors. |
|
6315 |
colorId == 0 ifTrue:[^ 0]. |
|
6316 |
^ 255 |
|
6317 |
]. |
|
6318 |
^ (((3 * red) + (6 * green) + (blue)) * 255 / 10 / MaxValue) rounded min:255 |
|
6319 |
||
6320 |
" |
|
6321 |
Color black grayByte -> 0.0 |
|
6322 |
Color white grayByte -> 1.0 |
|
6323 |
Color red grayByte -> 0.3 |
|
6324 |
Color green grayByte -> 0.6 |
|
6325 |
Color blue grayByte -> 0.1 |
|
6326 |
" |
|
6327 |
! |
|
6328 |
||
1023 | 6329 |
grayIntensity |
6330 |
"return the grey intensity in percent [0..100] (US version ;-)" |
|
6331 |
||
6385 | 6332 |
red isNil ifTrue:[ |
6333 |
"/ a hack for colorId:0 and colorId:1 pseudo mask colors. |
|
6334 |
colorId == 0 ifTrue:[^ 0]. |
|
6335 |
^ 100 |
|
6336 |
]. |
|
1023 | 6337 |
^ ((3 * red) + (6 * green) + (1 * blue)) * 10.0 / MaxValue |
6338 |
||
7758 | 6339 |
" |
6340 |
Color red brightness |
|
6341 |
Color red grayIntensity |
|
6342 |
" |
|
6343 |
||
1023 | 6344 |
"Created: 2.5.1996 / 11:38:21 / cg" |
6345 |
! |
|
6346 |
||
6347 |
greyIntensity |
|
6348 |
"return the grey intensity in percent [0..100] (English version ;-)" |
|
6349 |
||
6350 |
^ self grayIntensity |
|
6351 |
||
6352 |
"Modified: 28.5.1996 / 20:45:41 / cg" |
|
6353 |
! |
|
6354 |
||
8701 | 6355 |
isBlueGreen |
6356 |
"Am I considered BlueGreen ?" |
|
6357 |
||
6358 |
^green > red |
|
6359 |
and: [self red < 30] |
|
6360 |
and: [(self green - self blue) abs < 10] |
|
6361 |
||
6362 |
" |
|
6363 |
Color blue isBlueGreen |
|
6364 |
(Color blue blendWith:Color green) isBlueGreen |
|
6365 |
" |
|
6366 |
||
6367 |
"Created: / 06-06-2019 / 11:42:24 / Claus Gittinger" |
|
6368 |
! |
|
6369 |
||
6370 |
isBright |
|
6371 |
"Am I considered a Bright color ?" |
|
6372 |
||
6373 |
^ self brightness > 0.6 |
|
6374 |
||
6375 |
" |
|
6376 |
Color blue isBright |
|
6377 |
Color yellow isBright |
|
6378 |
Color white isBright |
|
6379 |
Color black isBright |
|
6380 |
" |
|
6381 |
||
6382 |
"Created: / 06-06-2019 / 11:44:26 / Claus Gittinger" |
|
6383 |
! |
|
6384 |
||
6385 |
isBrown |
|
6386 |
"Am I considered Brown ?" |
|
6387 |
||
6388 |
^red >= green |
|
6389 |
and: [green > blue] |
|
6390 |
and: [(self red - self green) < 50] |
|
6391 |
and: [(self green - self blue) < 30] |
|
6392 |
||
6393 |
" |
|
6394 |
Color blue isBrown |
|
6395 |
Color yellow isBrown |
|
6396 |
Color yellow darkened darkened isBrown |
|
6397 |
Color brown isBrown |
|
6398 |
Color black isBrown |
|
6399 |
" |
|
6400 |
||
6401 |
"Created: / 06-06-2019 / 11:45:50 / Claus Gittinger" |
|
6402 |
! |
|
6403 |
||
1023 | 6404 |
isColor |
6405 |
"return true if the receiver is a Color." |
|
6406 |
||
6407 |
^ true |
|
6408 |
! |
|
6409 |
||
2828 | 6410 |
isColorObject |
6411 |
^ true |
|
6412 |
! |
|
6413 |
||
8701 | 6414 |
isDark |
6415 |
"Am I considered a Dark color ?" |
|
6416 |
||
6417 |
^self brightness < 0.5 |
|
6418 |
||
6419 |
" |
|
6420 |
Color blue isDark |
|
6421 |
Color yellow isDark |
|
6422 |
Color yellow darkened darkened isDark |
|
6423 |
Color brown isDark |
|
6424 |
Color black isDark |
|
6425 |
" |
|
6426 |
||
6427 |
"Created: / 06-06-2019 / 11:46:55 / Claus Gittinger" |
|
6428 |
! |
|
6429 |
||
1023 | 6430 |
isDithered |
6431 |
"return true, if this is a dithered Color. |
|
6432 |
Only makes sense if the receiver is a device color." |
|
6433 |
||
6434 |
^ ditherForm notNil |
|
6435 |
! |
|
6436 |
||
1326
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
6437 |
isGray |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
6438 |
"same as isGrayColor - for ST80 compatibility." |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
6439 |
|
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
6440 |
^ self isGrayColor |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
6441 |
|
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
6442 |
" |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
6443 |
(Color grey:50) isGray |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
6444 |
(Color red) isGray |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
6445 |
" |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
6446 |
|
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
6447 |
"Created: 10.2.1997 / 22:10:25 / cg" |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
6448 |
! |
a519593747e8
#isGray - ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
6449 |
|
1023 | 6450 |
isGrayColor |
3005 | 6451 |
"return true, if this color is a gray one (US version ;-) - |
1023 | 6452 |
i.e. red = green = blue" |
6453 |
||
6454 |
red ~~ green ifTrue:[^ false]. |
|
6455 |
^ red == blue |
|
6456 |
||
6457 |
" |
|
6458 |
(Color grey:50) isGrayColor |
|
6459 |
(Color red) isGrayColor |
|
6460 |
" |
|
6461 |
||
6462 |
"Created: 2.5.1996 / 11:38:48 / cg" |
|
6463 |
! |
|
6464 |
||
8701 | 6465 |
isGrayish |
6466 |
"Am I considered almost Gray ?" |
|
6467 |
||
6468 |
^(self red closeTo: self green withEpsilon:0.1) |
|
6469 |
and: [self blue closeTo: self green withEpsilon:0.1] |
|
6470 |
||
6471 |
" |
|
6472 |
Color blue isGrayish |
|
6473 |
Color yellow isGrayish |
|
6474 |
Color yellow darkened darkened isGrayish |
|
6475 |
Color brown isGrayish |
|
6476 |
Color black isGrayish |
|
6477 |
Color white isGrayish |
|
6478 |
Color grey isGrayish |
|
6479 |
" |
|
6480 |
||
6481 |
"Created: / 06-06-2019 / 11:49:07 / Claus Gittinger" |
|
6482 |
! |
|
6483 |
||
1023 | 6484 |
isGreyColor |
6485 |
"return true, if this color is a grey one (English version ;-) - |
|
6486 |
i.e. red = green = blue" |
|
6487 |
||
6488 |
^ self isGrayColor |
|
6489 |
||
6490 |
"(Color grey:50) isGreyColor" |
|
6491 |
"(Color red) isGreyColor" |
|
6492 |
||
6493 |
"Modified: 28.5.1996 / 20:44:36 / cg" |
|
2942
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6494 |
! |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6495 |
|
3598 | 6496 |
isOnDevice:aGraphicsDevice |
6497 |
"return true if i am allocated on aGraphicsDevice" |
|
6498 |
||
6353 | 6499 |
^ device == aGraphicsDevice |
3598 | 6500 |
and:[colorId notNil or:[replacementColor notNil and:[replacementColor colorId notNil]]] |
6501 |
! |
|
6502 |
||
2942
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6503 |
isOpaque |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6504 |
"return true, if I represent an opaque color" |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6505 |
|
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6506 |
^ true |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6507 |
|
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6508 |
! |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6509 |
|
8701 | 6510 |
isOrange |
6511 |
"Am I considered Orange ?" |
|
6512 |
||
6513 |
^self red > ((self green max: self blue) + 20) |
|
6514 |
and: [self green > (self blue + 20)] |
|
6515 |
||
6516 |
" |
|
6517 |
Color blue isOrange |
|
6518 |
Color yellow isOrange |
|
6519 |
Color yellow darkened isOrange |
|
6520 |
(Color yellow blendWith:Color red) isOrange |
|
6521 |
Color orange isOrange |
|
6522 |
Color red isOrange |
|
6523 |
Color white isOrange |
|
6524 |
Color grey isOrange |
|
6525 |
" |
|
6526 |
||
6527 |
"Created: / 06-06-2019 / 11:50:53 / Claus Gittinger" |
|
6528 |
! |
|
6529 |
||
8163 | 6530 |
isPseudoColor |
6531 |
"for special uses only: |
|
6532 |
colors which ONLY hold alpha values or |
|
6533 |
colorIDs (for example, for bit-blt operaions) |
|
6534 |
are called 'pseudo colors'" |
|
6535 |
||
6536 |
^ red isNil |
|
6537 |
||
6538 |
"Created: / 05-09-2017 / 12:16:19 / cg" |
|
6539 |
! |
|
6540 |
||
8701 | 6541 |
isSaturated |
6542 |
"Am I considered to be a Saturated color ?" |
|
6543 |
||
6544 |
^self saturation > 0.6 |
|
6545 |
||
6546 |
"Created: / 06-06-2019 / 11:57:45 / Claus Gittinger" |
|
6547 |
! |
|
6548 |
||
2942
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6549 |
isTranslucent |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6550 |
"return true, if I represent a translucent color; |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6551 |
that is: not completely opaque" |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6552 |
|
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6553 |
^ false |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6554 |
|
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6555 |
! |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6556 |
|
2945 | 6557 |
isTranslucentColor |
6558 |
"return true, if I represent a translucent color, but not transparent" |
|
6559 |
||
6560 |
^ false |
|
6561 |
||
6562 |
! |
|
6563 |
||
2942
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6564 |
isTransparent |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6565 |
"return true, if I represent a completely transparent color" |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6566 |
|
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6567 |
^ false |
513981eb5180
prepared support for translucent colors
Claus Gittinger <cg@exept.de>
parents:
2937
diff
changeset
|
6568 |
|
1023 | 6569 |
! ! |
6570 |
||
1907
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6571 |
!Color::DeviceColorHandle class methodsFor:'documentation'! |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6572 |
|
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6573 |
documentation |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6574 |
" |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6575 |
This is an abstract class for device handles which are responsible |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6576 |
for finalization i.e. to destroy underlying system resources, when the GC |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6577 |
frees an object which has created some system object. |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6578 |
These are used with colors. |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6579 |
|
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6580 |
[see also:] |
6353 | 6581 |
Color |
1907
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6582 |
|
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6583 |
[author:] |
6353 | 6584 |
Claus Gittinger |
1907
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6585 |
|
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6586 |
" |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6587 |
! ! |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6588 |
|
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6589 |
!Color::DeviceColorHandle methodsFor:'accessing'! |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6590 |
|
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6591 |
setDevice:aDevice colorId:anId |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6592 |
"set the handles contents" |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6593 |
|
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6594 |
device := aDevice. |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6595 |
colorId := anId. |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6596 |
|
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6597 |
"Modified: 23.4.1996 / 22:10:26 / cg" |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6598 |
"Created: 25.3.1997 / 14:29:10 / stefan" |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6599 |
! ! |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6600 |
|
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6601 |
!Color::DeviceColorHandle methodsFor:'finalization'! |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6602 |
|
3611
8b4384c9e660
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
3598
diff
changeset
|
6603 |
finalize |
6353 | 6604 |
"the color for which I am a handle was collected |
1907
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6605 |
- release system resources" |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6606 |
|
2096 | 6607 |
|id| |
6608 |
||
6609 |
(id := colorId) notNil ifTrue:[ |
|
6353 | 6610 |
colorId := nil. |
6611 |
device freeColor:id. |
|
1907
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6612 |
]. |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6613 |
|
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6614 |
"Created: 25.3.1997 / 14:29:10 / stefan" |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6615 |
! ! |
61fdff318175
Make Device*Handles (used for finalization) private in their resp. classes.
Stefan Vogel <sv@exept.de>
parents:
1859
diff
changeset
|
6616 |
|
1144 | 6617 |
!Color class methodsFor:'documentation'! |
1023 | 6618 |
|
6619 |
version |
|
6967 | 6620 |
^ '$Header$' |
5419 | 6621 |
! |
6622 |
||
6623 |
version_CVS |
|
6967 | 6624 |
^ '$Header$' |
1023 | 6625 |
! ! |
3757 | 6626 |
|
6110 | 6627 |
|
1023 | 6628 |
Color initialize! |