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