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