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