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