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