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