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