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