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