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