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