author | Claus Gittinger <cg@exept.de> |
Mon, 16 Sep 1996 21:06:05 +0200 | |
changeset 1057 | 410f0fec2872 |
parent 1051 | 5605bf1b10b9 |
child 1063 | ba1bf8091bc1 |
permissions | -rw-r--r-- |
0 | 1 |
" |
6 | 2 |
COPYRIGHT (c) 1991 by Claus Gittinger |
72 | 3 |
All Rights Reserved |
0 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
Object subclass:#Image |
|
306
5070ca5adcb1
more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
14 |
instanceVariableNames:'bytes width height bitsPerSample samplesPerPixel colorMap |
891 | 15 |
photometric device deviceForm monoDeviceForm fullColorDeviceForm |
16 |
mask' |
|
306
5070ca5adcb1
more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
17 |
classVariableNames:'Lobby DitherAlgorithm NumberOfDitherColors |
305
4ece2bdf1011
handle StaticColor visual (OS/2 server has this)
Claus Gittinger <cg@exept.de>
parents:
286
diff
changeset
|
18 |
CollectGarbageWhenRunningOutOfColors FileFormats' |
306
5070ca5adcb1
more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
19 |
poolDictionaries:'' |
5070ca5adcb1
more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
20 |
category:'Graphics-Images' |
0 | 21 |
! |
22 |
||
901 | 23 |
!Image class methodsFor:'documentation'! |
0 | 24 |
|
46 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
72 | 28 |
All Rights Reserved |
46 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
0 | 39 |
documentation |
40 |
" |
|
46 | 41 |
this class provides (some time in the future) representation |
42 |
for all kinds of images (monochrome, greyscale and color) |
|
592 | 43 |
and will finally replace Form. |
622 | 44 |
For now (only ;-) depths of 1, 2, 4, 8, 16 and 24 are supported. |
592 | 45 |
|
46 |
An Image keeps all of its information in a device independent way, |
|
47 |
but may be associated to a device. |
|
48 |
The data held keeps all information which was originally present, |
|
49 |
even if the display-device has lower resolution. |
|
46 | 50 |
Therefore, it is possible to process and manipulate images without loosing |
51 |
color information - even on low color resolution displays. |
|
52 |
||
53 |
Usually, you get a device specific representation of the image by |
|
592 | 54 |
sending the |
55 |
'on:aDevice' |
|
56 |
message to it, which will create a (possibly dithered) device-form, |
|
57 |
representing the image using the currently available colors. |
|
46 | 58 |
|
286 | 59 |
In rare cases, an explicit monochrome representation of the image is needed |
46 | 60 |
(X servers take monochrome icons only), this can be created by sending |
592 | 61 |
it the message |
62 |
'monochromeOn:aDevice'. |
|
0 | 63 |
|
46 | 64 |
Also, it is planned to generate another hi-color resolution version, |
286 | 65 |
which uses its own colormap and allows the use of all 256 colors on an 8bit display |
66 |
(this is not currently implemented). |
|
67 |
||
68 |
An images pixel interpretation is controlled by the photometric instance variable |
|
69 |
and (if that is #palette) a colorMap. |
|
70 |
This is in contrast to the ST-80 way, where all of this info is in the colorMap |
|
71 |
(and using specialized colorMaps for b&w / greyScale images). |
|
72 |
This may change in future versions for more application compatibility. |
|
73 |
||
74 |
To convert pictures from/to external file-formats, image readers are used |
|
592 | 75 |
which have the file-format knowledge built in. |
76 |
There are readers for most common formats available |
|
286 | 77 |
(see ImageReader and especially subclasses such as TIFFReader, GIFReader etc.). |
78 |
||
79 |
File formats are handled by subclasses of ImageReader, which understand |
|
80 |
a specific format. You can add more readers, by adding an association |
|
81 |
such as ('.jpg' -> JPEGReader) to the class variable 'FileFormats' |
|
82 |
(see the classes #initialize method, which dsets up some default, and the |
|
83 |
patches/display.rc files, which add more). |
|
84 |
||
85 |
Some algorithms used here (especially dithering & color allocation) are |
|
46 | 86 |
experimental and far from being perfect (some are very slow). |
592 | 87 |
For now, the most common cases have been optimized and perform reasonably |
88 |
fast - however, with uncommon depth/visualType combinations, you may |
|
89 |
run into slower fallback methods ... |
|
90 |
||
91 |
Much more work is needed if you plan to do heavy image processing and will |
|
92 |
(may) be done in the future if there is a demand for it ... |
|
93 |
Dithering can be controlled by the DitherAlgorithm classVariable: |
|
2 | 94 |
|
46 | 95 |
DitherAlgorithm: |
0 | 96 |
|
46 | 97 |
nil a simple threshold algorithm |
592 | 98 |
(i.e. for mono, p<0.5 -> black, p>=0.5 -> white) |
0 | 99 |
|
46 | 100 |
#pattern patterned dither |
592 | 101 |
(for p, take dithered color to fill pixel; |
102 |
uses dithering in color-class) |
|
0 | 103 |
|
46 | 104 |
#error error diffusion dither (Floyd-Steinberg) |
592 | 105 |
planned - not yet implemented. |
106 |
||
107 |
||
108 |
||
109 |
[instance variables:] |
|
110 |
||
111 |
width <Integer> the width in pixels |
|
112 |
height <Integer> the height in pixels |
|
113 |
bytes <ByteArray> the full image information |
|
114 |
photometric <Symbol> #rgb, #palette, #blackIs0 or #whiteIs0 |
|
115 |
samplesPerPixel <Integer> the number of planes |
|
116 |
bitsPerSample <Array> the number of bits per plane |
|
117 |
||
118 |
colorMap <Array> only if photometric is #pseudocolor; |
|
119 |
maps pixel values to r/g/b values. |
|
120 |
||
121 |
device <Workstation> the device on which deviceForm, |
|
122 |
monoDeviceForm and lowResDeviceForm are |
|
123 |
||
124 |
deviceForm <Form> the device form which gives the best |
|
125 |
possible aproximation of the image on |
|
126 |
device using standard colors. |
|
127 |
||
128 |
monoDeviceForm <Form> the device form which gives a monochrome |
|
129 |
aproximation of the image on device. |
|
130 |
||
131 |
fullColorDeviceForm <Form> the device form which gives the best |
|
132 |
possible aproximation of the image on |
|
133 |
device using private colors. |
|
134 |
||
135 |
[class variables:] |
|
136 |
||
137 |
Lobby <Registry> keeps track of known images |
|
138 |
(for resource freeing with garbage collector) |
|
139 |
||
140 |
DitherAlgorithm <Symbol> defines how to dither |
|
141 |
||
142 |
NumberOfDitherColors <Integer> defines, how many dither colors to use |
|
143 |
||
144 |
FileFormats <Dictionary> associates filename extensions to |
|
145 |
image reader classes (now set-up in startup-file) |
|
146 |
||
147 |
CollectGarbageWhenRunningOutOfColors |
|
148 |
<Boolean> if true, and we run out of available |
|
149 |
device colors during creation of a |
|
150 |
device image, collect garbage for |
|
151 |
possible image reclamation. |
|
152 |
If false, proceed immediately. |
|
153 |
Default is true. |
|
158 | 154 |
|
46 | 155 |
todo: |
592 | 156 |
there is currently no mask stored/available in the image itself; currently masks |
157 |
have to be stored as separate bitmaps. |
|
158 |
(which is bad for image-file formats, which provide a mask) |
|
159 |
Thus, currently, all images are completely opaque. |
|
160 |
||
161 |
[See also:] |
|
162 |
Form Icon ImageReader |
|
611 | 163 |
|
164 |
[author:] |
|
165 |
Claus Gittinger |
|
0 | 166 |
" |
649 | 167 |
! |
168 |
||
169 |
examples |
|
170 |
" |
|
171 |
reading from a file (many formats are supported): |
|
172 |
[exBegin] |
|
173 |
(Image fromFile:'bitmaps/claus.gif') inspect |
|
174 |
[exEnd] |
|
175 |
[exBegin] |
|
176 |
(Image fromFile:'bitmaps/SmalltalkX.xbm') inspect |
|
177 |
[exEnd] |
|
178 |
[exBegin] |
|
179 |
(Image fromFile:'bitmaps/okSmily_up.bmp') inspect |
|
180 |
[exEnd] |
|
181 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
182 |
inline image: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
183 |
default: depth=1 & #blackIs0 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
184 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
185 |
(Image width:8 height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
186 |
fromArray:#( 2r11111111 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
187 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
188 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
189 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
190 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
191 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
192 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
193 |
2r11111111 )) inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
194 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
195 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
196 |
with #whiteIs0 photometric |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
197 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
198 |
((Image width:8 height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
199 |
fromArray:#( 2r11111111 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
200 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
201 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
202 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
203 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
204 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
205 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
206 |
2r11111111 )) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
207 |
photometric:#whiteIs0) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
208 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
209 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
210 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
211 |
with a colorMap |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
212 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
213 |
((Image width:8 height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
214 |
fromArray:#( 2r11111111 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
215 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
216 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
217 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
218 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
219 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
220 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
221 |
2r11111111 )) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
222 |
colorMap:(Array with:(Color red) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
223 |
with:(Color yellow))) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
224 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
225 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
226 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
227 |
a depth4 greyScale image: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
228 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
229 |
((Depth4Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
230 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
231 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
232 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
233 |
16r01 16r23 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
234 |
16r45 16r67 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
235 |
16r89 16rab |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
236 |
16rcd 16ref |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
237 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
238 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
239 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
240 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
241 |
the following has the same effect: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
242 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
243 |
((Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
244 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
245 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
246 |
depth:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
247 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
248 |
16r01 16r23 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
249 |
16r45 16r67 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
250 |
16r89 16rab |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
251 |
16rcd 16ref |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
252 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
253 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
254 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
255 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
256 |
with reverse grey-interpretation: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
257 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
258 |
((Depth4Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
259 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
260 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
261 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
262 |
16r01 16r23 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
263 |
16r45 16r67 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
264 |
16r89 16rab |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
265 |
16rcd 16ref |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
266 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
267 |
photometric:#whiteIs0; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
268 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
269 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
270 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
271 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
272 |
with 1-bit-per-pixel rgb interpretation: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
273 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
274 |
((Depth4Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
275 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
276 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
277 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
278 |
16r01 16r23 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
279 |
16r45 16r67 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
280 |
16r89 16rab |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
281 |
16rcd 16ref |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
282 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
283 |
photometric:#rgb; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
284 |
samplesPerPixel:3; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
285 |
bitsPerSample:#(1 1 1); |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
286 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
287 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
288 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
289 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
290 |
with 1/2/1 rgb interpretation: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
291 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
292 |
((Depth4Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
293 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
294 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
295 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
296 |
16r01 16r23 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
297 |
16r45 16r67 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
298 |
16r89 16rab |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
299 |
16rcd 16ref |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
300 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
301 |
photometric:#rgb; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
302 |
samplesPerPixel:3; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
303 |
bitsPerSample:#(1 2 1); |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
304 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
305 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
306 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
307 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
308 |
a 2/2/0 rgb image (i.e. no blue): |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
309 |
[exBegin] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
310 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
311 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
312 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
313 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
314 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
315 |
fromArray:#[ 16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
316 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
317 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
318 |
16rcd 16ref ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
319 |
i photometric:#rgb. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
320 |
i samplesPerPixel:3. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
321 |
i bitsPerSample:#(2 2 0). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
322 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
323 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
324 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
325 |
[exEnd] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
326 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
327 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
328 |
a 0/0/4 rgb image (i.e. no red or green): |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
329 |
[exBegin] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
330 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
331 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
332 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
333 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
334 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
335 |
fromArray:#[ 16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
336 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
337 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
338 |
16rcd 16ref ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
339 |
i photometric:#rgb. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
340 |
i samplesPerPixel:3. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
341 |
i bitsPerSample:#(0 0 4). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
342 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
343 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
344 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
345 |
[exEnd] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
346 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
347 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
348 |
a 2plane greyscale image: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
349 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
350 |
((Depth2Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
351 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
352 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
353 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
354 |
4r0123 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
355 |
4r1230 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
356 |
4r2301 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
357 |
4r3012 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
358 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
359 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
360 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
361 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
362 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
363 |
with colors: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
364 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
365 |
((Depth2Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
366 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
367 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
368 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
369 |
4r0123 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
370 |
4r1230 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
371 |
4r2301 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
372 |
4r3012 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
373 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
374 |
colorMap:(Array with:(Color black) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
375 |
with:(Color red) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
376 |
with:(Color green) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
377 |
with:(Color blue)); |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
378 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
379 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
380 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
381 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
382 |
depth8 image with 3/3/2 rgb interpretation: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
383 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
384 |
((Depth8Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
385 |
width:16 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
386 |
height:16 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
387 |
fromArray:(ByteArray withAll:(0 to:16rFF))) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
388 |
photometric:#rgb; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
389 |
samplesPerPixel:3; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
390 |
bitsPerSample:#(3 3 2); |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
391 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
392 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
393 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
394 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
395 |
depth8 image with 2/2/2 rgb interpretation: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
396 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
397 |
((Depth8Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
398 |
width:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
399 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
400 |
fromArray:(ByteArray withAll:(0 to:16r3F))) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
401 |
photometric:#rgb; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
402 |
samplesPerPixel:3; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
403 |
bitsPerSample:#(2 2 2); |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
404 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
405 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
406 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
407 |
|
649 | 408 |
storing (only a few formats are currently supported): |
409 |
[exBegin] |
|
410 |
|img| |
|
411 |
||
412 |
img := Image fromFile:'bitmaps/okSmily_up.bmp'. |
|
413 |
img saveOn:'myImage.tiff'. |
|
414 |
(Image fromFile:'myImage.tiff') inspect |
|
415 |
[exEnd] |
|
416 |
magnifying (any factor): |
|
417 |
[exBegin] |
|
418 |
((Image fromFile:'bitmaps/claus.gif') |
|
419 |
magnifiedTo:(48@48)) |
|
420 |
inspect |
|
421 |
[exEnd] |
|
422 |
[exBegin] |
|
423 |
((Image fromFile:'bitmaps/claus.gif') |
|
424 |
magnifiedBy:0.7) |
|
425 |
inspect |
|
426 |
[exEnd] |
|
427 |
rotating (currently, only multiples of 90 degrees are supported): |
|
428 |
[exBegin] |
|
429 |
((Image fromFile:'bitmaps/claus.gif') |
|
430 |
rotated:90) |
|
431 |
inspect |
|
432 |
[exEnd] |
|
433 |
[exBegin] |
|
434 |
(((Image fromFile:'bitmaps/claus.gif') |
|
435 |
magnifiedBy:0.3@0.7) rotated:270) |
|
436 |
inspect |
|
437 |
[exEnd] |
|
438 |
" |
|
0 | 439 |
! ! |
440 |
||
901 | 441 |
!Image class methodsFor:'initialization'! |
283 | 442 |
|
443 |
fileFormats |
|
444 |
"return the collection of supported file formats. |
|
445 |
The returned dictionary maps file-extensions to image reader classes." |
|
446 |
||
447 |
FileFormats isNil ifTrue:[ |
|
448 |
self initializeFileFormatTable |
|
449 |
]. |
|
450 |
^ FileFormats |
|
451 |
||
452 |
" |
|
453 |
Image fileFormats |
|
454 |
" |
|
100 | 455 |
! |
456 |
||
283 | 457 |
flushDeviceImages |
869 | 458 |
"simply release all deviceForms" |
283 | 459 |
|
460 |
Lobby do:[:anImage | |
|
869 | 461 |
anImage restored |
283 | 462 |
] |
869 | 463 |
|
464 |
"Modified: 15.6.1996 / 15:45:02 / cg" |
|
0 | 465 |
! |
466 |
||
467 |
initialize |
|
2 | 468 |
"initialize class constants" |
469 |
||
0 | 470 |
"setup tracker of known pictures" |
24 | 471 |
Lobby isNil ifTrue:[ |
748 | 472 |
Lobby := Registry new. |
473 |
ObjectMemory addDependent:self. |
|
474 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
475 |
"/ define the algorithm to use for dithering - |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
476 |
"/ supported values are: |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
477 |
"/ #threshold |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
478 |
"/ #ordered |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
479 |
"/ #floydSteinberg |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
480 |
"/ #burkes |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
481 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
482 |
DitherAlgorithm := #floydSteinberg. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
483 |
|
748 | 484 |
(Display notNil and:[Display hasGrayscales]) ifFalse:[ |
485 |
NumberOfDitherColors := 64 |
|
486 |
] ifTrue:[ |
|
487 |
"as far as I remember, this is about the number of grey values, the eye can distinguish" |
|
488 |
NumberOfDitherColors := 100 |
|
489 |
]. |
|
490 |
||
491 |
"define reader classes" |
|
492 |
FileFormats isNil ifTrue:[ |
|
493 |
self initializeFileFormatTable |
|
494 |
]. |
|
495 |
||
496 |
CollectGarbageWhenRunningOutOfColors := false |
|
386 | 497 |
] |
748 | 498 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
499 |
"Modified: 10.6.1996 / 12:28:22 / cg" |
12 | 500 |
! |
501 |
||
24 | 502 |
initializeFileFormatTable |
46 | 503 |
"initialize a default table to map from file extension to reader class. |
504 |
The mapping here is a default needed for proper operation of ST/X; |
|
505 |
see the 'smalltalk.rc' startup file for a real (full) map." |
|
24 | 506 |
|
507 |
FileFormats := Dictionary new. |
|
508 |
FileFormats at:'.xbm' put:XBMReader. |
|
509 |
FileFormats at:'.tiff' put:TIFFReader. |
|
510 |
FileFormats at:'.gif' put:GIFReader. |
|
72 | 511 |
"/ FileFormats at:'.img' put:IMGReader. |
512 |
"/ FileFormats at:'.icon' put:SunRasterReader. |
|
24 | 513 |
|
72 | 514 |
" |
515 |
Image initializeFileFormatTable |
|
516 |
" |
|
24 | 517 |
! |
518 |
||
901 | 519 |
update:something with:aParameter from:changedObject |
0 | 520 |
"flush all device specific stuff when restarted from a snapshot" |
521 |
||
522 |
(something == #restarted) ifTrue:[ |
|
901 | 523 |
self flushDeviceImages |
0 | 524 |
] |
901 | 525 |
|
526 |
"Created: 21.6.1996 / 19:47:43 / cg" |
|
0 | 527 |
! ! |
528 |
||
901 | 529 |
!Image class methodsFor:'instance creation'! |
283 | 530 |
|
531 |
extent:ext depth:d bits:bits |
|
532 |
"ST-80 compatibility; assume 32-bit padding" |
|
533 |
||
534 |
^ self extent:ext depth:d bits:bits pad:32 |
|
24 | 535 |
! |
536 |
||
283 | 537 |
extent:ext depth:d bits:bits pad:padding |
538 |
"ST-80 compatibility" |
|
539 |
||
540 |
^ self width:ext x height:ext y depth:d fromArray:bits pad:padding |
|
24 | 541 |
! |
542 |
||
283 | 543 |
extent:ext depth:d palette:aColormap bits:bits pad:padding |
544 |
"ST-80 compatibility" |
|
545 |
||
546 |
^ self width:ext x height:ext y depth:d fromArray:bits pad:padding |
|
547 |
! |
|
548 |
||
549 |
extent:ext fromArray:bits offset:offset |
|
550 |
"ST-80 compatibility" |
|
551 |
||
552 |
^ self width:ext x height:ext y fromArray:bits |
|
89 | 553 |
! |
554 |
||
555 |
fromForm:aForm |
|
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
556 |
"create & return an Image given a aForm" |
89 | 557 |
|
936 | 558 |
|depth device vis img| |
559 |
||
560 |
depth := aForm depth. |
|
561 |
device := aForm device. |
|
562 |
||
563 |
(device notNil and:[depth == device depth]) ifTrue:[ |
|
564 |
"/ |
|
565 |
"/ for truecolor displays, return a Depth24Image |
|
566 |
"/ (must do this for depth15 & depth16 displays, since |
|
567 |
"/ Depth16Image has no way to specify r/g/b masks ...) |
|
568 |
"/ |
|
569 |
vis := device visualType. |
|
570 |
(vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[ |
|
571 |
depth > 8 ifTrue:[ |
|
572 |
depth := 24. |
|
573 |
] |
|
574 |
]. |
|
575 |
]. |
|
576 |
img := (self implementorForDepth:depth) new. |
|
577 |
device isNil ifTrue:[ |
|
578 |
^ img fromForm:aForm. |
|
579 |
]. |
|
580 |
^ img from:aForm in:(0@0 extent:(aForm extent)) |
|
89 | 581 |
|
582 |
" |
|
583 |
|f| |
|
584 |
||
585 |
f := Form width:16 height:16. |
|
586 |
f clear. |
|
587 |
f displayLineFromX:0 y:0 toX:15 y:15. |
|
588 |
f inspect. |
|
589 |
(Image fromForm:f) inspect |
|
590 |
" |
|
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
591 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
592 |
" |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
593 |
|f| |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
594 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
595 |
f := Form width:16 height:16 depth:(Display depth) on:Display. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
596 |
f clear. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
597 |
f paint:(Color red). |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
598 |
f displayLineFromX:0 y:0 toX:15 y:15. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
599 |
f paint:(Color green). |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
600 |
f displayLineFromX:15 y:0 toX:0 y:15. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
601 |
f inspect. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
602 |
(Image fromForm:f) inspect |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
603 |
" |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
604 |
|
936 | 605 |
"Modified: 11.7.1996 / 11:21:42 / cg" |
89 | 606 |
! |
607 |
||
608 |
fromImage:anImage |
|
609 |
"create & return an Image given another image. This can be used to |
|
610 |
convert an image to another depth." |
|
611 |
||
612 |
(self == Image or:[anImage class == self]) ifTrue:[^ anImage]. |
|
613 |
^ self new fromImage:anImage. |
|
614 |
||
615 |
" |
|
616 |
|i1 i8| |
|
617 |
||
618 |
i1 := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
619 |
i8 := Depth8Image fromImage:i1. |
|
620 |
i8 inspect |
|
621 |
" |
|
622 |
! |
|
623 |
||
191 | 624 |
fromSubImage:anImage in:aRectangle |
625 |
"create & return an Image from a rectangular area in another image. |
|
626 |
This can also be used to get a subimage in another depth." |
|
627 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
628 |
|newImage| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
629 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
630 |
self == Image ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
631 |
newImage := self implementorForDepth:anImage depth. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
632 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
633 |
newImage := self new. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
634 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
635 |
^ newImage fromSubImage:anImage in:aRectangle. |
191 | 636 |
|
637 |
" |
|
638 |
|i1 i8| |
|
639 |
||
640 |
i1 := Image fromFile:'bitmaps/garfield.gif'. |
|
641 |
i8 := Depth8Image fromSubImage:i1 in:(0@0 corner:20@20). |
|
642 |
i8 inspect |
|
643 |
" |
|
650 | 644 |
" |
645 |
|i1 i8| |
|
646 |
||
647 |
i1 := Image fromFile:'bitmaps/claus.gif'. |
|
648 |
i8 := Depth8Image fromSubImage:i1 in:(70@50 extent:50@50). |
|
649 |
i8 inspect |
|
650 |
" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
651 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
652 |
|i1 i8| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
653 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
654 |
i1 := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
655 |
i8 := Image fromSubImage:i1 in:(70@50 extent:50@50). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
656 |
i8 inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
657 |
" |
191 | 658 |
|
659 |
"Created: 20.9.1995 / 01:05:43 / claus" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
660 |
"Modified: 10.6.1996 / 18:11:08 / cg" |
191 | 661 |
! |
662 |
||
283 | 663 |
new |
664 |
"create a new image. Redefined to set the photometric to |
|
665 |
greyScale with black being 0 as default." |
|
666 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
667 |
^ super new photometric:(self defaultPhotometric) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
668 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
669 |
"Modified: 10.6.1996 / 18:08:37 / cg" |
283 | 670 |
! |
671 |
||
89 | 672 |
width:w height:h |
673 |
"create a new image, given width, height. Assume a depth of 1." |
|
674 |
||
675 |
|cls| |
|
676 |
||
677 |
cls := self. |
|
678 |
cls == Image ifTrue:[ |
|
679 |
cls := self implementorForDepth:1 |
|
680 |
]. |
|
681 |
^ cls new width:w height:h depth:1 |
|
682 |
! |
|
683 |
||
82 | 684 |
width:w height:h depth:d |
89 | 685 |
"create a new image, given width, height and depth" |
686 |
||
191 | 687 |
^ (self implementorForDepth:d) new |
688 |
width:w height:h depth:d |
|
82 | 689 |
! |
690 |
||
691 |
width:w height:h depth:d fromArray:pixelData |
|
89 | 692 |
"create a new image, given width, height, depth and data. |
693 |
Data must be a ByteArray containing correctly aligned bits for the specified |
|
134 | 694 |
depth (8-bit padded)." |
82 | 695 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
696 |
^ (self implementorForDepth:d) new |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
697 |
width:w height:h depth:d fromArray:pixelData |
82 | 698 |
|
699 |
" |
|
700 |
Image width:8 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
701 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
702 |
depth:1 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
703 |
fromArray:#[2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
704 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
705 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
706 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
707 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
708 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
709 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
710 |
2r00110011]. |
82 | 711 |
" |
712 |
||
713 |
" |
|
714 |
Image width:8 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
715 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
716 |
depth:2 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
717 |
fromArray:#[4r1100 4r1100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
718 |
4r0011 4r0011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
719 |
4r1100 4r1100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
720 |
4r0011 4r0011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
721 |
4r1100 4r1100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
722 |
4r0011 4r0011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
723 |
4r1100 4r1100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
724 |
4r0011 4r0011]. |
89 | 725 |
" |
726 |
||
727 |
" |
|
728 |
Image width:8 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
729 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
730 |
depth:4 |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
731 |
fromArray:#[16r00 16r01 16rf0 16rf1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
732 |
16r02 16r03 16rf2 16rf3 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
733 |
16r04 16r05 16rf4 16rf5 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
734 |
16r06 16r07 16rf6 16rf7 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
735 |
16r08 16r09 16rf8 16rf9 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
736 |
16r0a 16r0b 16rfa 16rfb |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
737 |
16r0c 16r0d 16rfc 16rfd |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
738 |
16r0e 16r0f 16rfe 16rff]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
739 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
740 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
741 |
"Modified: 10.6.1996 / 18:18:10 / cg" |
132 | 742 |
! |
743 |
||
134 | 744 |
width:w height:h depth:d fromArray:pixelData pad:padding |
745 |
"create a new image, given width, height, depth and data. |
|
746 |
Data must be a ByteArray containing correctly aligned bits for the specified |
|
747 |
depth." |
|
748 |
||
749 |
|img newBits srcRowBytes dstRowBytes srcIndex dstIndex| |
|
750 |
||
751 |
img := (self implementorForDepth:d) new width:w height:h depth:d . |
|
752 |
||
753 |
padding ~~ 8 ifTrue:[ |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
754 |
"must repad; ST/X uses byte padding, while ST-80 uses longword |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
755 |
padding. This is stupid, and may be changed in ST/X with future versions. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
756 |
" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
757 |
dstRowBytes := img bytesPerRow. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
758 |
srcRowBytes := ((w * d + padding - 1) bitShift:-5) bitShift:2. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
759 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
760 |
newBits := ByteArray new:(dstRowBytes * h). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
761 |
srcIndex := 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
762 |
dstIndex := 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
763 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
764 |
1 to:h do:[:row | |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
765 |
newBits replaceFrom:dstIndex |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
766 |
to:(dstIndex + dstRowBytes - 1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
767 |
with:pixelData |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
768 |
startingAt:srcIndex. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
769 |
srcIndex := srcIndex + srcRowBytes. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
770 |
dstIndex := dstIndex + dstRowBytes. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
771 |
]. |
134 | 772 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
773 |
pixelData class isBytes ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
774 |
newBits := ByteArray withAll:pixelData |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
775 |
] ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
776 |
newBits := pixelData |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
777 |
] |
134 | 778 |
]. |
779 |
img bits:newBits. |
|
780 |
^ img |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
781 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
782 |
"Modified: 8.6.1996 / 10:07:47 / cg" |
134 | 783 |
! |
784 |
||
283 | 785 |
width:w height:h fromArray:anArray |
786 |
"create a new image, given width, height. Assume a depth of 1 of the |
|
787 |
receiving class is Image. |
|
788 |
Data must be a ByteArray containing correctly aligned bits for depth 1 |
|
789 |
(i.e. 8 bits per byte)." |
|
790 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
791 |
|cls d pixels| |
283 | 792 |
|
793 |
cls := self. |
|
794 |
cls == Image ifTrue:[ |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
795 |
cls := self implementorForDepth:1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
796 |
d := 1. |
283 | 797 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
798 |
d := cls imageDepth |
283 | 799 |
]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
800 |
anArray class isBytes ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
801 |
pixels := ByteArray withAll:anArray |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
802 |
] ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
803 |
pixels := anArray |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
804 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
805 |
^ cls new width:w height:h depth:d fromArray:pixels |
191 | 806 |
|
807 |
" |
|
283 | 808 |
Image width:8 |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
809 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
810 |
fromArray:#[2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
811 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
812 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
813 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
814 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
815 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
816 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
817 |
2r00110011]. |
191 | 818 |
" |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
819 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
820 |
"Modified: 8.6.1996 / 10:07:26 / cg" |
283 | 821 |
! ! |
822 |
||
901 | 823 |
!Image class methodsFor:'file reading'! |
650 | 824 |
|
825 |
fromFile:aFileName |
|
826 |
"read an image from a file - this methods tries to find |
|
827 |
out the file format itself (by the extension and by contents) |
|
828 |
and lets the appropriate reader read the file." |
|
829 |
||
830 |
|image name nm inStream suffixLen| |
|
831 |
||
832 |
" |
|
833 |
before trying each reader, check if file is readable |
|
834 |
" |
|
835 |
name := aFileName. |
|
836 |
inStream := Smalltalk systemFileStreamFor:name. |
|
837 |
inStream isNil ifTrue:[ |
|
838 |
inStream := Smalltalk bitmapFileStreamFor:name. |
|
839 |
inStream isNil ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
840 |
('IMAGE: ' , aFileName , ' does not exist or is not readable') infoPrintCR. |
650 | 841 |
^ nil |
842 |
]. |
|
843 |
name := 'bitmaps/' , name. |
|
844 |
]. |
|
845 |
inStream close. |
|
846 |
||
847 |
" |
|
848 |
get the imageReader class from the files extension |
|
849 |
" |
|
850 |
nm := name. |
|
851 |
(name endsWith:'.Z') ifTrue:[ |
|
852 |
suffixLen := 2 |
|
853 |
] ifFalse:[ |
|
854 |
(name endsWith:'.gz') ifTrue:[ |
|
855 |
suffixLen := 3 |
|
856 |
] ifFalse:[ |
|
857 |
suffixLen := 0 |
|
858 |
] |
|
859 |
]. |
|
860 |
suffixLen ~~ 0 ifTrue:[ |
|
861 |
nm := name copyWithoutLast:suffixLen |
|
862 |
]. |
|
863 |
||
864 |
" |
|
865 |
ask the corresponding readerclass first |
|
866 |
" |
|
867 |
FileFormats keysAndValuesDo:[:suffix :readerClass | |
|
868 |
(nm endsWith:suffix) ifTrue:[ |
|
869 |
readerClass notNil ifTrue:[ |
|
870 |
image := readerClass fromFile:name. |
|
871 |
image notNil ifTrue:[^ image]. |
|
872 |
] |
|
873 |
] |
|
874 |
]. |
|
875 |
||
876 |
" |
|
877 |
no known extension - ask all readers if they know |
|
878 |
this format ... |
|
879 |
" |
|
880 |
FileFormats do:[:readerClass | |
|
881 |
readerClass notNil ifTrue:[ |
|
882 |
(readerClass isValidImageFile:name) ifTrue:[ |
|
883 |
^ readerClass fromFile:name |
|
884 |
] |
|
885 |
] |
|
886 |
]. |
|
887 |
||
888 |
" |
|
889 |
nope - unknown format |
|
890 |
" |
|
891 |
'IMAGE: unknown image file format: ' infoPrint. aFileName infoPrintNL. |
|
892 |
^ nil |
|
893 |
||
894 |
" |
|
895 |
Image fromFile:'bitmaps/dano.tiff' |
|
896 |
Image fromFile:'bitmaps/test.fax' |
|
897 |
Image fromFile:'bitmaps/voice.tiff' |
|
898 |
Image fromFile:'voice.tiff' |
|
899 |
||
900 |
Image fromFile:'../fileIn/bitmaps/claus.gif' |
|
901 |
Image fromFile:'../fileIn/bitmaps/garfield.gif' |
|
902 |
||
903 |
Image fromFile:'../fileIn/bitmaps/founders.im8' |
|
904 |
Image fromFile:'../goodies/faces/next.com/steve.face' |
|
905 |
||
906 |
Image fromFile:'/LocalLibrary/Images/OS2/dos3.ico' |
|
907 |
Image fromFile:'bitmaps/globe1.xbm' |
|
908 |
Image fromFile:'bitmaps/globe1.xbm.Z' |
|
909 |
Image fromFile:'bitmaps/hello_world.icon' |
|
910 |
" |
|
911 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
912 |
"Modified: 10.6.1996 / 14:36:18 / cg" |
1051 | 913 |
! |
914 |
||
915 |
fromStream:aStream |
|
916 |
"read an image from a stream - this methods tries to find |
|
917 |
out the file format itself (by contents) |
|
918 |
and lets the appropriate reader read the file. |
|
919 |
To do this, the stream must be positionable." |
|
920 |
||
921 |
|image name nm inStream| |
|
922 |
||
923 |
" |
|
924 |
ask all readers if they know |
|
925 |
this format ... |
|
926 |
" |
|
927 |
FileFormats do:[:readerClass | |
|
928 |
readerClass notNil ifTrue:[ |
|
929 |
image := readerClass fromStream:aStream. |
|
930 |
image notNil ifTrue:[^ image]. |
|
931 |
] |
|
932 |
]. |
|
933 |
||
934 |
" |
|
935 |
nope - unknown format |
|
936 |
" |
|
937 |
'IMAGE: unknown image file format in stream: ' infoPrintCR. |
|
938 |
^ nil |
|
939 |
||
940 |
" |
|
941 |
Image fromFile:'bitmaps/dano.tiff' |
|
942 |
Image fromFile:'bitmaps/test.fax' |
|
943 |
Image fromFile:'bitmaps/voice.tiff' |
|
944 |
Image fromFile:'voice.tiff' |
|
945 |
||
946 |
Image fromFile:'../fileIn/bitmaps/claus.gif' |
|
947 |
Image fromFile:'../fileIn/bitmaps/garfield.gif' |
|
948 |
||
949 |
Image fromFile:'../fileIn/bitmaps/founders.im8' |
|
950 |
Image fromFile:'../goodies/faces/next.com/steve.face' |
|
951 |
||
952 |
Image fromFile:'/LocalLibrary/Images/OS2/dos3.ico' |
|
953 |
Image fromFile:'bitmaps/globe1.xbm' |
|
954 |
Image fromFile:'bitmaps/globe1.xbm.Z' |
|
955 |
Image fromFile:'bitmaps/hello_world.icon' |
|
956 |
" |
|
957 |
||
958 |
"Created: 13.9.1996 / 18:06:00 / cg" |
|
959 |
"Modified: 13.9.1996 / 18:07:25 / cg" |
|
650 | 960 |
! ! |
961 |
||
901 | 962 |
!Image class methodsFor:'misc'! |
283 | 963 |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
964 |
ditherAlgorithm |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
965 |
"return the way we dither - |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
966 |
#threshold, or nil -> no dither |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
967 |
#pattern, or #ordered -> orderedDither (ugly, but fast) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
968 |
#error or #floydSteinberg -> errorDiffusion; much better |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
969 |
#burkes -> errorDiffusion; even better." |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
970 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
971 |
^ DitherAlgorithm |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
972 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
973 |
"Created: 17.6.1996 / 18:57:47 / cg" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
974 |
! |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
975 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
976 |
ditherAlgorithm:aSymbol |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
977 |
"define how to dither - |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
978 |
#threshold, or nil -> no dither |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
979 |
#pattern, or #ordered -> orderedDither (ugly, but fast) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
980 |
#error or #floydSteinberg -> errorDiffusion; much better |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
981 |
#burkes -> errorDiffusion; even better." |
283 | 982 |
|
983 |
DitherAlgorithm := aSymbol |
|
984 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
985 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
986 |
Image dither:#pattern |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
987 |
Image dither:#floydSteinberg |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
988 |
Image dither:#burkes |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
989 |
Image dither:nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
990 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
991 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
992 |
"Modified: 10.6.1996 / 12:27:09 / cg" |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
993 |
"Created: 17.6.1996 / 18:57:19 / cg" |
283 | 994 |
! |
995 |
||
996 |
numberOfDitherColors:n |
|
997 |
"define how many colors (i.e. patterns) to use when |
|
998 |
doing a pattern dither" |
|
999 |
||
1000 |
NumberOfDitherColors := n |
|
798 | 1001 |
! |
1002 |
||
1003 |
orderedDitherMatrixOfSize:sz |
|
1004 |
sz == 2 ifTrue:[ |
|
1005 |
^ #[ |
|
1006 |
0 2 |
|
1007 |
3 1 |
|
1008 |
]. |
|
1009 |
]. |
|
1010 |
||
1011 |
sz == 4 ifTrue:[ |
|
1012 |
^ #[ |
|
1013 |
0 8 2 10 |
|
1014 |
12 4 14 6 |
|
1015 |
3 11 1 9 |
|
1016 |
15 7 13 5 |
|
1017 |
]. |
|
1018 |
]. |
|
1019 |
||
1020 |
sz == 8 ifTrue:[ |
|
1021 |
^ #[ |
|
1022 |
0 32 8 40 2 34 10 42 |
|
1023 |
48 16 56 24 50 18 58 26 |
|
1024 |
12 44 4 36 14 46 6 38 |
|
1025 |
60 28 52 20 62 30 54 22 |
|
1026 |
||
1027 |
3 35 11 43 1 33 9 41 |
|
1028 |
51 19 59 27 49 17 57 25 |
|
1029 |
15 47 7 39 13 45 5 37 |
|
1030 |
63 31 55 23 61 29 53 21 |
|
1031 |
]. |
|
1032 |
]. |
|
1033 |
||
1034 |
^ nil |
|
1035 |
||
1036 |
"Created: 7.6.1996 / 14:15:05 / cg" |
|
283 | 1037 |
! ! |
1038 |
||
901 | 1039 |
!Image class methodsFor:'queries'! |
283 | 1040 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1041 |
defaultPhotometric |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1042 |
"return the default photometric pixel interpretation" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1043 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1044 |
^ #blackIs0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1045 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1046 |
"Modified: 20.4.1996 / 23:40:41 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1047 |
"Created: 10.6.1996 / 18:08:12 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1048 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1049 |
|
283 | 1050 |
imageDepth |
579 | 1051 |
"return the depth of images represented by instances of |
1052 |
this class. |
|
1053 |
Must be redefined in concrete subclasses" |
|
1054 |
||
1055 |
^ self shouldNotImplement |
|
1056 |
||
1057 |
"Modified: 20.4.1996 / 23:40:41 / cg" |
|
191 | 1058 |
! |
1059 |
||
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
1060 |
implementorForDepth:depth |
283 | 1061 |
"return the class, which best implements images of depth" |
1062 |
||
1063 |
depth == 1 ifTrue:[^ Depth1Image]. |
|
1064 |
depth == 2 ifTrue:[^ Depth2Image]. |
|
1065 |
depth == 4 ifTrue:[^ Depth4Image]. |
|
1066 |
depth == 8 ifTrue:[^ Depth8Image]. |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
1067 |
depth == 15 ifTrue:[^ Depth16Image]. "/ kludge for 15bit XFree |
283 | 1068 |
depth == 16 ifTrue:[^ Depth16Image]. |
1069 |
depth == 24 ifTrue:[^ Depth24Image]. |
|
1070 |
^ self |
|
1071 |
! ! |
|
1072 |
||
901 | 1073 |
!Image class methodsFor:'screen capture'! |
283 | 1074 |
|
1075 |
fromScreen |
|
1076 |
"return an image of the full screen" |
|
1077 |
||
1078 |
|display| |
|
1079 |
||
1080 |
display := Screen current. |
|
1081 |
^ self fromScreen:(0@0 corner:(display width @ display height)) |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1082 |
|
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1083 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1084 |
Image fromScreen |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1085 |
" |
283 | 1086 |
! |
1087 |
||
1088 |
fromScreen:aRectangle |
|
1089 |
"return an image of a part of the screen" |
|
1090 |
||
1091 |
^ self fromScreen:aRectangle on:Screen current |
|
1092 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1093 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1094 |
Image fromScreen:(0@0 corner:100@100) |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1095 |
" |
283 | 1096 |
! |
1097 |
||
1098 |
fromScreen:aRectangle on:aDisplay |
|
1099 |
"return an image of a part of the screen, which may be on |
|
1100 |
another Display." |
|
1101 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1102 |
|depth vis img| |
283 | 1103 |
|
1104 |
depth := aDisplay depth. |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1105 |
|
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1106 |
"/ |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1107 |
"/ for truecolor displays, return a Depth24Image |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1108 |
"/ (must do this for depth15 & depth16 displays, since |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1109 |
"/ Depth16Image has no way to specify r/g/b masks ...) |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1110 |
"/ |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1111 |
vis := aDisplay visualType. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1112 |
(vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[ |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1113 |
depth > 8 ifTrue:[ |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1114 |
depth := 24. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1115 |
] |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1116 |
]. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1117 |
|
283 | 1118 |
img := (self implementorForDepth: depth) new. |
1119 |
^ img fromScreen:aRectangle on:aDisplay |
|
1120 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1121 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1122 |
Image fromScreen:(0@0 corner:100@100) |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1123 |
" |
283 | 1124 |
! |
1125 |
||
1126 |
fromScreenArea |
|
1127 |
"return an image of a part of the screen; |
|
1128 |
let user specify screen area." |
|
1129 |
||
1130 |
^ self fromScreen:(Rectangle fromUser) |
|
1131 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1132 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1133 |
Image fromScreenArea |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1134 |
" |
283 | 1135 |
! |
1136 |
||
1137 |
fromUser |
|
1138 |
"return an image of a part of the screen; let user specify screen area. |
|
1139 |
Same as fromScreenArea, for ST-80 compatibility" |
|
1140 |
||
1141 |
^ self fromScreenArea |
|
1142 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1143 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1144 |
Image fromUser |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1145 |
" |
283 | 1146 |
! |
1147 |
||
1148 |
fromView:aView |
|
1149 |
"return an image taken from a views contents as currently |
|
1150 |
on the screen. The returned image has the same depth and photometric |
|
1151 |
as the Display. Notice, that for invisible or partial covered |
|
1152 |
views, the returned Image is NOT correct. You may want to raise |
|
1153 |
the view before using this method." |
|
1154 |
||
1155 |
|org dev| |
|
1156 |
||
744 | 1157 |
dev := aView graphicsDevice. |
283 | 1158 |
org := dev translatePoint:(0@0) |
744 | 1159 |
from:(aView id) |
1160 |
to:dev rootWindowId. |
|
283 | 1161 |
^ self fromScreen:(org extent:aView extent) on:dev |
191 | 1162 |
|
1163 |
" |
|
1043
0688425d02c9
Rename Launcher-->OldLauncher, NewLauncher-->Launcher.
Stefan Vogel <sv@exept.de>
parents:
1041
diff
changeset
|
1164 |
Image fromView:(Launcher allInstances first topView) |
283 | 1165 |
Image fromView:(SystemBrowser allInstances first topView) |
191 | 1166 |
" |
744 | 1167 |
|
1168 |
"Modified: 28.5.1996 / 20:23:32 / cg" |
|
1043
0688425d02c9
Rename Launcher-->OldLauncher, NewLauncher-->Launcher.
Stefan Vogel <sv@exept.de>
parents:
1041
diff
changeset
|
1169 |
"Modified: 9.9.1996 / 22:41:01 / stefan" |
157 | 1170 |
! ! |
1171 |
||
0 | 1172 |
!Image methodsFor:'accessing'! |
1173 |
||
592 | 1174 |
bitsPerSample |
1175 |
"return the number of bits per sample. |
|
1176 |
The return value is an array of bits-per-plane." |
|
1177 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1178 |
bitsPerSample notNil ifTrue:[^ bitsPerSample]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1179 |
^ Array with:self depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1180 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1181 |
"Modified: 10.6.1996 / 18:04:21 / cg" |
592 | 1182 |
! |
1183 |
||
1184 |
colorMap |
|
1185 |
"return the colormap" |
|
1186 |
||
1187 |
^ colorMap |
|
1188 |
! |
|
1189 |
||
852 | 1190 |
colorMap:aColorMap |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1191 |
"set the colorMap; this also set the photometric to a useful defualt." |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1192 |
|
852 | 1193 |
|sz "{ Class: SmallInteger }" |
1194 |
sameColors| |
|
1195 |
||
1196 |
(aColorMap isNil and:[colorMap isNil]) ifTrue:[^ self]. |
|
1197 |
photometric == #palette ifTrue:[ |
|
1198 |
"/ any change at all ? |
|
1199 |
(sz := aColorMap size) == colorMap size ifTrue:[ |
|
1200 |
sameColors := true. |
|
1201 |
||
1202 |
1 to:sz do:[:idx | |
|
1203 |
(aColorMap at:idx) = (colorMap at:idx) ifFalse:[ |
|
1204 |
sameColors := false. |
|
1205 |
] |
|
1206 |
]. |
|
1207 |
sameColors ifTrue:[^ self]. |
|
1208 |
] |
|
1209 |
]. |
|
1210 |
||
1211 |
colorMap := aColorMap. |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1212 |
colorMap notNil ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1213 |
photometric := #palette. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1214 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1215 |
(photometric == #palette) ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1216 |
photometric := #blackIs0 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1217 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1218 |
]. |
852 | 1219 |
deviceForm notNil ifTrue:[ |
1220 |
self release |
|
1221 |
] |
|
592 | 1222 |
|
1223 |
"Modified: 31.8.1995 / 03:05:59 / claus" |
|
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1224 |
"Modified: 15.6.1996 / 09:32:09 / cg" |
592 | 1225 |
! |
1226 |
||
757 | 1227 |
container:aVisualContainer |
1228 |
"ignored here - added to allow images to be used like |
|
1229 |
VisualComponents (later, Image should inherit from it)" |
|
1230 |
||
1231 |
"Created: 28.5.1996 / 23:43:49 / cg" |
|
1232 |
"Modified: 29.5.1996 / 10:22:23 / cg" |
|
1233 |
! |
|
1234 |
||
592 | 1235 |
depth |
1236 |
"return the depth of the image" |
|
1237 |
||
1238 |
^ self bitsPerPixel |
|
1239 |
! |
|
1240 |
||
1241 |
device |
|
1242 |
"return the device, the receiver is associated with. |
|
1243 |
Return nil, if the image is unassigned." |
|
1244 |
||
1245 |
^ device |
|
1246 |
! |
|
1247 |
||
1248 |
extent |
|
1249 |
"return the images extent" |
|
1250 |
||
1251 |
^ width@height |
|
1252 |
! |
|
1253 |
||
1254 |
fullColorId |
|
1255 |
"return the id of the full color image on the device. |
|
1256 |
Return nil, if the image is unassigned." |
|
1257 |
||
1258 |
fullColorDeviceForm isNil ifTrue:[^ nil]. |
|
1259 |
^ fullColorDeviceForm id |
|
1260 |
! |
|
1261 |
||
728 | 1262 |
graphicsDevice |
1263 |
"same as #device - for ST-80 compatibility" |
|
1264 |
||
1265 |
^ device |
|
1266 |
! |
|
744 | 1267 |
|
592 | 1268 |
height |
1269 |
"return the height of the image" |
|
1270 |
||
1271 |
^ height |
|
1272 |
! |
|
1273 |
||
1274 |
id |
|
1275 |
"return the id of the image on the device. |
|
1276 |
Return nil, if the image is unassigned." |
|
1277 |
||
1278 |
deviceForm isNil ifTrue:[^ nil]. |
|
1279 |
^ deviceForm id |
|
1280 |
! |
|
1281 |
||
896 | 1282 |
mask |
1283 |
^ mask |
|
1284 |
||
1285 |
"Created: 21.6.1996 / 12:57:44 / cg" |
|
1286 |
! |
|
1287 |
||
906 | 1288 |
mask:anotherImage |
1289 |
"set the images mask - currently, this may be nil or a Depth1Image. |
|
1290 |
(it is planned to support alpha information in a Depth8 maskImage in |
|
1291 |
the near future). |
|
1292 |
For depth1 masks: each pixel of the image where a corresponding |
|
1293 |
1-bit is present in the mask will be drawn; |
|
1294 |
0-bit mask pixels lead to transparent pixels. |
|
1295 |
||
1296 |
For depth8 masks: (future): |
|
1297 |
each pixel specifies the alpha value (0..255), |
|
1298 |
which specifies the transparency of that pixel. |
|
1299 |
0 means completely transparent, 255 means completely |
|
1300 |
opaque. The 1-plane mask is a special case of this, |
|
1301 |
interpreting a 0 as a 0 alpha value and 1's as an |
|
1302 |
alpha value of 255." |
|
1303 |
||
1304 |
mask := anotherImage |
|
1305 |
||
1306 |
"Created: 27.6.1996 / 17:45:22 / cg" |
|
1307 |
! |
|
1308 |
||
592 | 1309 |
monochromeId |
1310 |
"return the id of the monochrome image on the device. |
|
1311 |
Return nil, if the image is unassigned." |
|
1312 |
||
1313 |
monoDeviceForm isNil ifTrue:[^ nil]. |
|
1314 |
^ monoDeviceForm id |
|
1315 |
! |
|
1316 |
||
1317 |
palette |
|
1318 |
"return the colormap; ST-80 compatibility" |
|
1319 |
||
1320 |
^ colorMap |
|
1321 |
! |
|
1322 |
||
1323 |
palette:aColormap |
|
1324 |
"set the colormap; ST-80 compatibility" |
|
1325 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1326 |
self colorMap:aColormap |
592 | 1327 |
|
1328 |
"Created: 1.2.1996 / 15:09:25 / cg" |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1329 |
"Modified: 8.6.1996 / 09:54:02 / cg" |
592 | 1330 |
! |
1331 |
||
1332 |
photometric |
|
1333 |
"return the photometric, a symbol such as #palette, #rgb etc." |
|
1334 |
||
1335 |
^ photometric |
|
1336 |
! |
|
1337 |
||
1338 |
samplesPerPixel |
|
1339 |
"return the number of samples per pixel in the image. |
|
1340 |
The return value is an array of bits-per-plane." |
|
1341 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1342 |
samplesPerPixel notNil ifTrue:[^ samplesPerPixel]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1343 |
^ 1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1344 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1345 |
"Modified: 10.6.1996 / 18:03:30 / cg" |
592 | 1346 |
! |
1347 |
||
1348 |
width |
|
1349 |
"return the width of the image" |
|
1350 |
||
1351 |
^ width |
|
1352 |
! ! |
|
1353 |
||
1354 |
!Image methodsFor:'accessing - pixels'! |
|
1355 |
||
0 | 1356 |
at:aPoint |
2 | 1357 |
"retrieve the pixel at aPoint; return a color. |
1358 |
Pixels start at 0@0 for upper left pixel, end at |
|
81 | 1359 |
(width-1)@(height-1) for lower right pixel. |
2 | 1360 |
You should not use this method for image-processing, its |
81 | 1361 |
very slow ... |
1362 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
0 | 1363 |
|
1364 |
^ self atX:aPoint x y:aPoint y |
|
1365 |
! |
|
1366 |
||
283 | 1367 |
at:aPoint put:aColor |
1368 |
"set the pixel at aPoint to aColor. |
|
1369 |
Pixels start at 0@0 for the upper left pixel, end at |
|
1370 |
(width-1)@(height-1) for lower right pixel. |
|
1371 |
You should not use this method for image-processing, its |
|
1372 |
very slow ... |
|
1373 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
1374 |
||
1375 |
^ self atX:aPoint x y:aPoint y put:aColor |
|
1376 |
! |
|
1377 |
||
1378 |
atPoint:aPoint |
|
1379 |
"ST-80 compatibility: return the pixelValue at:aPoint." |
|
1380 |
||
1381 |
^ self valueAtX:aPoint x y:aPoint y |
|
1382 |
! |
|
1383 |
||
0 | 1384 |
atX:x y:y |
2 | 1385 |
"retrieve a pixel at x/y; return a color. |
81 | 1386 |
Pixels start at 0@0 for upper left pixel, end at |
1387 |
(width-1)@(height-1) for lower right pixel. |
|
2 | 1388 |
You should not use this method for image-processing, its |
81 | 1389 |
very slow ... |
1390 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
2 | 1391 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1392 |
|pixel maxPixel| |
89 | 1393 |
|
1394 |
pixel := self valueAtX:x y:y. |
|
1395 |
photometric == #blackIs0 ifTrue:[ |
|
746 | 1396 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
1397 |
^ Color gray:(pixel * (100 / maxPixel)). |
|
89 | 1398 |
]. |
1399 |
photometric == #whiteIs0 ifTrue:[ |
|
746 | 1400 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
1401 |
^ Color gray:100 - (pixel * (100 / maxPixel)). |
|
89 | 1402 |
]. |
1403 |
photometric == #palette ifTrue:[ |
|
746 | 1404 |
^ colorMap at:(pixel + 1) |
89 | 1405 |
]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1406 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1407 |
^ self colorFromValue:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1408 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1409 |
"Modified: 8.6.1996 / 10:53:22 / cg" |
2 | 1410 |
! |
1411 |
||
1412 |
atX:x y:y put:aColor |
|
1413 |
"set the pixel at x/y to aColor. |
|
81 | 1414 |
Pixels start at 0@0 for the upper left pixel, end at |
1415 |
(width-1)@(height-1) for the lower right pixel. |
|
89 | 1416 |
This method checks if the color can be stored in the image. |
1417 |
(i.e. if the receiver is a palette image, the color must be present in there). |
|
1418 |
You should not use this method for image-processing, it is very slow ... |
|
81 | 1419 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
1420 |
||
89 | 1421 |
|pixel maxPixel| |
1422 |
||
1423 |
photometric == #whiteIs0 ifTrue:[ |
|
798 | 1424 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
1425 |
pixel := maxPixel - (aColor brightness * maxPixel) rounded. |
|
89 | 1426 |
] ifFalse:[ |
798 | 1427 |
photometric == #blackIs0 ifTrue:[ |
1428 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
|
1429 |
pixel := (aColor brightness * maxPixel) rounded. |
|
1430 |
] ifFalse:[ |
|
1431 |
photometric ~~ #palette ifTrue:[ |
|
1432 |
self error:'format not supported'. |
|
1433 |
^ nil |
|
1434 |
]. |
|
1435 |
pixel := colorMap indexOf:aColor. |
|
1436 |
pixel == 0 ifTrue:[ |
|
1437 |
" |
|
1438 |
the color to be stored is not in the images colormap |
|
1439 |
" |
|
1440 |
self error:'invalid color - not in colorMap' |
|
1441 |
]. |
|
1442 |
pixel := pixel - 1 |
|
1443 |
] |
|
89 | 1444 |
]. |
1445 |
self atX:x y:y putValue:pixel. |
|
798 | 1446 |
|
1447 |
"Modified: 7.6.1996 / 19:17:48 / cg" |
|
81 | 1448 |
! |
1449 |
||
283 | 1450 |
atX:x y:y putValue:aPixelValue |
1451 |
"set the pixel at x/y to aPixelValue. |
|
1452 |
The interpretation of the pixelValue depends on the photometric |
|
1453 |
and the colormap. (see also: Image>>atX:y:put:) |
|
1454 |
Pixels start at 0@0 for the upper left pixel, end at |
|
1455 |
(width-1) @ (height-1) for the lower right pixel. |
|
1456 |
You should not use this method for image-processing, its |
|
1457 |
very slow ... |
|
1458 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
1459 |
||
1460 |
^ self subclassResponsibility |
|
1461 |
! |
|
1462 |
||
1463 |
bits |
|
1464 |
"return the raw image data; depending on the photometric, |
|
1465 |
this has to be interpreted as monochrome, greyscale, |
|
1466 |
palette or rgb data. It is also packed to be dense, so |
|
1467 |
a 4 bitPerSample palette image will store 2 pixels per byte." |
|
1468 |
||
1469 |
^ bytes |
|
1470 |
! |
|
1471 |
||
1472 |
data |
|
1473 |
"for backward compatibility - will vanish" |
|
1474 |
||
1475 |
^ bytes |
|
1476 |
! |
|
1477 |
||
1478 |
data:aByteArray |
|
1479 |
"for backward compatibility - will vanish" |
|
1480 |
||
1481 |
bytes := aByteArray |
|
1482 |
! |
|
1483 |
||
81 | 1484 |
valueAt:aPoint |
1485 |
"retrieve the pixelValue at aPoint; return an integer number. |
|
1486 |
Pixels start at 0@0 for upper left pixel, end at |
|
1487 |
width-1@height-1 for lower right pixel. |
|
1488 |
The returned numbers interpretation depends on the photometric |
|
1489 |
and the colormap. (see also Image>>at: and Image>>atX:y:) |
|
2 | 1490 |
You should not use this method for image-processing, its |
81 | 1491 |
very slow ... |
1492 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
1493 |
||
1494 |
^ self valueAtX:aPoint x y:aPoint y |
|
1495 |
! |
|
1496 |
||
1497 |
valueAtX:x y:y |
|
1498 |
"retrieve the pixelValue at aPoint; return an integer number. |
|
1499 |
Pixels start at 0/0 for upper left pixel, and end at |
|
1500 |
width-1@height-1 for lower right pixel. |
|
1501 |
The returned numbers interpretation depends on the photometric |
|
1502 |
and the colormap. (see also Image>>at: and Image>>atX:y:) |
|
1503 |
You should not use this method for image-processing of |
|
1504 |
big images, its very slow ... |
|
1505 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
2 | 1506 |
|
1507 |
^ self subclassResponsibility |
|
592 | 1508 |
! ! |
1509 |
||
1510 |
!Image methodsFor:'accessing - private'! |
|
1511 |
||
1512 |
bits:aByteArray |
|
1513 |
"set the raw data. |
|
1514 |
||
1515 |
This interface is only to be used when initializing |
|
1516 |
instances or by image readers. Calling for a change of an |
|
1517 |
existing image may confuse later pixel interpretation." |
|
1518 |
||
1519 |
bytes := aByteArray |
|
1520 |
||
1521 |
"Modified: 23.4.1996 / 11:08:28 / cg" |
|
2 | 1522 |
! |
1523 |
||
592 | 1524 |
bitsPerSample:aNumber |
1525 |
"set the number of bits per sample. |
|
1526 |
||
1527 |
This interface is only to be used when initializing |
|
1528 |
instances or by image readers. Calling for a change of an |
|
1529 |
existing image may confuse later pixel interpretation." |
|
1530 |
||
1531 |
bitsPerSample := aNumber |
|
1532 |
||
1533 |
"Modified: 23.4.1996 / 11:08:31 / cg" |
|
1534 |
! |
|
1535 |
||
1536 |
depth:d |
|
1537 |
"set the depth of the image. |
|
1538 |
||
1539 |
This interface is only to be used when initializing |
|
1540 |
instances or by image readers. Calling for a change of an |
|
1541 |
existing image may confuse later pixel interpretation." |
|
1542 |
||
1543 |
d == 24 ifTrue:[ |
|
1544 |
samplesPerPixel := 3. |
|
1545 |
bitsPerSample := #(8 8 8) |
|
1546 |
] ifFalse:[ |
|
1547 |
samplesPerPixel := 1. |
|
1548 |
bitsPerSample := Array with:d |
|
1549 |
] |
|
1550 |
||
1551 |
"Modified: 23.4.1996 / 11:08:34 / cg" |
|
1552 |
! |
|
1553 |
||
1554 |
extent:anExtent |
|
1555 |
"set the images extent. |
|
1556 |
||
1557 |
This interface is only to be used when initializing |
|
1558 |
instances or by image readers. Calling for a change of an |
|
1559 |
existing image may confuse later pixel interpretation." |
|
1560 |
||
1561 |
width := anExtent x. |
|
1562 |
height := anExtent y |
|
1563 |
||
1564 |
"Modified: 23.4.1996 / 11:08:38 / cg" |
|
1565 |
! |
|
1566 |
||
1567 |
height:aNumber |
|
1568 |
"set the height of the image. |
|
1569 |
||
1570 |
This interface is only to be used when initializing |
|
1571 |
instances or by image readers. Calling for a change of an |
|
1572 |
existing image may confuse later pixel interpretation." |
|
1573 |
||
1574 |
height := aNumber |
|
1575 |
||
1576 |
"Modified: 23.4.1996 / 11:08:40 / cg" |
|
1577 |
! |
|
1578 |
||
1579 |
photometric:aSymbol |
|
1580 |
"set the photometric interpretation of the pixel values. |
|
1581 |
The argument, aSymbol is one of: |
|
1582 |
#blackIs0, #whiteIs0, #palette, #rgb |
|
1583 |
See TIFF documentation, from which the photometric concept is borrowed. |
|
1584 |
||
1585 |
This interface is only to be used when initializing |
|
1586 |
instances or by image readers. Calling for a change of an |
|
1587 |
existing image may confuse later pixel interpretation." |
|
1588 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1589 |
|b| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1590 |
|
798 | 1591 |
photometric := aSymbol. |
1592 |
bitsPerSample isNil ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1593 |
photometric == #rgb ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1594 |
b := self class imageDepth // 3. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1595 |
bitsPerSample := Array with:b with:b with:b |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1596 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1597 |
bitsPerSample := Array with:(self class imageDepth) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1598 |
]. |
798 | 1599 |
]. |
1600 |
samplesPerPixel isNil ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1601 |
photometric == #rgb ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1602 |
samplesPerPixel := 3 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1603 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1604 |
samplesPerPixel := 1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1605 |
] |
798 | 1606 |
]. |
1607 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1608 |
"Modified: 10.6.1996 / 18:21:29 / cg" |
592 | 1609 |
! |
1610 |
||
1611 |
samplesPerPixel:aNumber |
|
1612 |
"set the array of samples per pixel. |
|
1613 |
||
1614 |
This interface is only to be used when initializing |
|
1615 |
instances or by image readers. Calling for a change of an |
|
1616 |
existing image may confuse later pixel interpretation." |
|
1617 |
||
1618 |
samplesPerPixel := aNumber |
|
1619 |
||
1620 |
"Modified: 23.4.1996 / 11:08:45 / cg" |
|
81 | 1621 |
! |
1622 |
||
283 | 1623 |
width:aNumber |
592 | 1624 |
"set the width of the image. |
1625 |
||
1626 |
This interface is only to be used when initializing |
|
1627 |
instances or by image readers. Calling for a change of an |
|
1628 |
existing image may confuse later pixel interpretation." |
|
283 | 1629 |
|
1630 |
width := aNumber |
|
592 | 1631 |
|
1632 |
"Modified: 23.4.1996 / 11:08:48 / cg" |
|
100 | 1633 |
! |
1634 |
||
283 | 1635 |
width:w height:h |
592 | 1636 |
"set the width and height of the image. |
1637 |
||
1638 |
This interface is only to be used when initializing |
|
1639 |
instances or by image readers. Calling for a change of an |
|
1640 |
existing image may confuse later pixel interpretation." |
|
283 | 1641 |
|
1642 |
width := w. |
|
1643 |
height := h |
|
592 | 1644 |
|
1645 |
"Modified: 23.4.1996 / 11:08:53 / cg" |
|
81 | 1646 |
! |
2 | 1647 |
|
283 | 1648 |
width:w height:h depth:d |
592 | 1649 |
"set the width, height and depth of the image. |
1650 |
||
1651 |
This interface is only to be used when initializing |
|
1652 |
instances or by image readers. Calling for a change of an |
|
1653 |
existing image may confuse later pixel interpretation." |
|
283 | 1654 |
|
1655 |
width := w. |
|
1656 |
height := h. |
|
1657 |
self depth:d. |
|
592 | 1658 |
|
1659 |
"Modified: 23.4.1996 / 11:08:56 / cg" |
|
89 | 1660 |
! |
1661 |
||
283 | 1662 |
width:w height:h depth:d fromArray:bits |
592 | 1663 |
"set the width, height, depth and pixels of the image. |
1664 |
||
1665 |
This interface is only to be used when initializing |
|
1666 |
instances or by image readers. Calling for a change of an |
|
1667 |
existing image may confuse later pixel interpretation." |
|
283 | 1668 |
|
1669 |
width := w. |
|
1670 |
height := h. |
|
1671 |
self depth:d. |
|
1672 |
bytes := bits |
|
592 | 1673 |
|
1674 |
"Modified: 23.4.1996 / 11:08:59 / cg" |
|
1675 |
! |
|
1676 |
||
1677 |
width:w height:h photometric:p samplesPerPixel:spp bitsPerSample:bps colorMap:cm bits:pixels |
|
1678 |
"set all relevant internal state of the image. |
|
1679 |
||
1680 |
This interface is only to be used when initializing |
|
1681 |
instances or by image readers. Calling for a change of an |
|
1682 |
existing image may confuse later pixel interpretation." |
|
1683 |
||
894
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1684 |
^ self |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1685 |
width:w |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1686 |
height:h |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1687 |
photometric:p |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1688 |
samplesPerPixel:spp |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1689 |
bitsPerSample:bps |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1690 |
colorMap:cm |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1691 |
bits:pixels |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1692 |
mask:nil |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1693 |
|
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1694 |
"Modified: 20.6.1996 / 17:10:24 / cg" |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1695 |
! |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1696 |
|
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1697 |
width:w height:h photometric:p samplesPerPixel:spp bitsPerSample:bps colorMap:cm bits:pixels mask:m |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1698 |
"set all relevant internal state of the image. |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1699 |
|
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1700 |
This interface is only to be used when initializing |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1701 |
instances or by image readers. Calling for a change of an |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1702 |
existing image may confuse later pixel interpretation." |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1703 |
|
592 | 1704 |
width := w. |
1705 |
height := h. |
|
1706 |
photometric := p. |
|
1707 |
samplesPerPixel := spp. |
|
1708 |
bitsPerSample := bps. |
|
1709 |
colorMap := cm. |
|
1710 |
bytes := pixels. |
|
894
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1711 |
mask := m. |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1712 |
|
592 | 1713 |
"Modified: 23.4.1996 / 11:09:02 / cg" |
894
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
1714 |
"Created: 20.6.1996 / 17:09:53 / cg" |
0 | 1715 |
! ! |
1716 |
||
283 | 1717 |
!Image methodsFor:'binary storage'! |
1718 |
||
1719 |
readBinaryContentsFrom: stream manager: manager |
|
1720 |
"read a binary representation of an image from stream. |
|
1721 |
Redefined to flush any device data." |
|
1722 |
||
1723 |
super readBinaryContentsFrom: stream manager: manager. |
|
1724 |
device := nil. |
|
1725 |
deviceForm := nil. |
|
1726 |
monoDeviceForm := nil. |
|
1727 |
fullColorDeviceForm := nil. |
|
0 | 1728 |
! |
1729 |
||
283 | 1730 |
storeBinaryDefinitionOn: stream manager: manager |
1731 |
"store a binary representation of the receiver on stream. |
|
592 | 1732 |
This is an internal interface for binary storage mechanism. |
283 | 1733 |
Redefined to not store the device form (which is recreated at |
1734 |
load time anyway)" |
|
1735 |
||
1736 |
|tDevice tDeviceForm tMonoDeviceForm tFullColorDeviceForm| |
|
1737 |
||
1738 |
tDevice := device. |
|
1739 |
tDeviceForm := deviceForm. |
|
1740 |
tMonoDeviceForm := monoDeviceForm. |
|
1741 |
tFullColorDeviceForm := fullColorDeviceForm. |
|
1742 |
||
1743 |
device := nil. |
|
1744 |
deviceForm := nil. |
|
1745 |
monoDeviceForm := nil. |
|
1746 |
fullColorDeviceForm := nil. |
|
1747 |
||
1748 |
super storeBinaryDefinitionOn: stream manager: manager. |
|
1749 |
||
1750 |
device := tDevice. |
|
1751 |
deviceForm := tDeviceForm. |
|
1752 |
monoDeviceForm := tMonoDeviceForm. |
|
1753 |
fullColorDeviceForm := tFullColorDeviceForm. |
|
592 | 1754 |
|
1755 |
"Modified: 23.4.1996 / 09:30:50 / cg" |
|
0 | 1756 |
! ! |
1757 |
||
1758 |
!Image methodsFor:'converting'! |
|
1759 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1760 |
asBurkesDitheredMonochromeImage |
837 | 1761 |
"return a burkes dithered monochrome image from the receiver image. |
1762 |
Depending on the images contents, this may or may not look better than |
|
1763 |
a floyd-steinberg dithered image. |
|
1764 |
Notice, that floyd-steinberg dithering is faster; both because less |
|
1765 |
error diffusion is done and due to being specially tuned." |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1766 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1767 |
|monoBits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1768 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1769 |
monoBits := self burkesDitheredMonochromeBits. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1770 |
^ Depth1Image width:width height:height fromArray:monoBits |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1771 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1772 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1773 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1774 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1775 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1776 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1777 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1778 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1779 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1780 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1781 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1782 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1783 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1784 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1785 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1786 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1787 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1788 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1789 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1790 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1791 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1792 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1793 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1794 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1795 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1796 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1797 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1798 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1799 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1800 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1801 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1802 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1803 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1804 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1805 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1806 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1807 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1808 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1809 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1810 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1811 |
"Created: 10.6.1996 / 12:34:44 / cg" |
837 | 1812 |
"Modified: 12.6.1996 / 13:58:16 / cg" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1813 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1814 |
|
283 | 1815 |
asCachedImage |
592 | 1816 |
"return the receiver associated to the current screens device. |
1817 |
For ST-80 compatibility |
|
1818 |
(ST/X uses Image for both device- and nonDevice-images)" |
|
283 | 1819 |
|
1820 |
^ self on:Screen current |
|
592 | 1821 |
|
1822 |
"Modified: 23.4.1996 / 11:10:32 / cg" |
|
0 | 1823 |
! |
1824 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1825 |
asErrorDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1826 |
"return an error-diffusion dithered monochrome image from the receiver image." |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1827 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1828 |
DitherAlgorithm == #burkes ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1829 |
^ self asBurkesDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1830 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1831 |
DitherAlgorithm == #stevensonArce ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1832 |
^ self asStevensonArgceDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1833 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1834 |
^ self asFloydSteinbergDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1835 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1836 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1837 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1838 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1839 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1840 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1841 |
i asErrorDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1842 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1843 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1844 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1845 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1846 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1847 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1848 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1849 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1850 |
i asErrorDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1851 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1852 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1853 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1854 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1855 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1856 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1857 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1858 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1859 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1860 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1861 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1862 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1863 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1864 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1865 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1866 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1867 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1868 |
i asErrorDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1869 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1870 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1871 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1872 |
"Modified: 10.6.1996 / 14:22:30 / cg" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1873 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1874 |
|
854 | 1875 |
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
1876 |
"return a floyd-steinberg dithered pseudoForm from the palette picture. |
|
1877 |
Use the colors in the fixColors array, which must be fixR x fixG x fixB |
|
1878 |
colors assigned to aDevice, such as the preallocated colors of the |
|
1879 |
Color class. |
|
1880 |
By passing the ditherColors as extra array, this method can |
|
1881 |
also be used to dither an 8bit image into a smaller number of colors, |
|
1882 |
for example to create dithered Depth4Images from Depth8Images." |
|
1883 |
||
1884 |
|pseudoBits f has8BitImage deviceDepth |
|
1885 |
map | |
|
1886 |
||
1887 |
deviceDepth := aDevice depth. |
|
1888 |
deviceDepth == 8 ifTrue:[ |
|
1889 |
has8BitImage := true. |
|
1890 |
] ifFalse:[ |
|
1891 |
has8BitImage := false. |
|
1892 |
aDevice supportedImageFormats do:[:fmt | |
|
1893 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
|
1894 |
has8BitImage := true. |
|
1895 |
] |
|
1896 |
] |
|
1897 |
]. |
|
1898 |
has8BitImage ifFalse:[^ nil]. |
|
1899 |
||
1900 |
pseudoBits := self floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue. |
|
1901 |
pseudoBits isNil ifTrue:[^ nil]. |
|
1902 |
||
1903 |
f := Form width:width height:height depth:deviceDepth on:aDevice. |
|
1904 |
f isNil ifTrue:[^ nil]. |
|
1905 |
||
1906 |
"/ |
|
1907 |
"/ have to create a funny colorMap, where |
|
1908 |
"/ color at:index == color colorId:index |
|
1909 |
"/ |
|
1910 |
map := Array new:256. |
|
1911 |
fixColors do:[:clr | |
|
1912 |
map at:clr colorId + 1 put:clr |
|
1913 |
]. |
|
1914 |
f colorMap:map. |
|
1915 |
f initGC. |
|
1916 |
f bits:pseudoBits. |
|
1917 |
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:deviceDepth |
|
1918 |
width:width height:height |
|
1919 |
x:0 y:0 |
|
1920 |
into:(f id) x:0 y:0 |
|
1921 |
width:width height:height with:(f gcId). |
|
1922 |
^ f |
|
1923 |
||
1924 |
" |
|
1925 |
example: |
|
1926 |
color reduction from Depth8 to Depth4 (dithering) can be done by: |
|
1927 |
||
1928 |
|img8 reducedImg8 img4 map form| |
|
1929 |
||
1930 |
map := #( |
|
1931 |
(0 0 0) |
|
1932 |
(0 0 100) |
|
1933 |
(0 50 0) |
|
1934 |
(0 50 100) |
|
1935 |
(0 100 0) |
|
1936 |
(0 100 100) |
|
1937 |
(100 0 0) |
|
1938 |
(100 0 100) |
|
1939 |
(100 50 0) |
|
1940 |
(100 50 100) |
|
1941 |
(100 100 0) |
|
1942 |
(100 100 100)) collect:[:rgb | (Color red:(rgb at:1) |
|
1943 |
green:(rgb at:2) |
|
1944 |
blue:(rgb at:3)) on:Display]. |
|
1945 |
||
1946 |
img8 := Image fromFile:'bitmaps/bf.im8'. |
|
1947 |
form := img8 paletteImageAsDitheredPseudoFormOn:Display |
|
1948 |
colors:map |
|
1949 |
nRed:2 |
|
1950 |
nGreen:3 |
|
1951 |
nBlue:2. |
|
1952 |
img8 := Depth8Image fromForm:form. 'dithered version of original image'. |
|
1953 |
img4 := Depth4Image fromImage:img8. |
|
1954 |
" |
|
1955 |
||
1956 |
"Modified: 14.6.1996 / 16:52:34 / cg" |
|
1957 |
! |
|
1958 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1959 |
asFloydSteinbergDitheredGrayFormOn:aDevice |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1960 |
"return a dithered depth-x grey form from the receiver image." |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1961 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1962 |
|f depth bits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1963 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1964 |
depth := aDevice depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1965 |
depth == 1 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1966 |
"/ for monochrome, there is specialized |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1967 |
"/ monochrome dither code available |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1968 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1969 |
bits := self floydSteinbergDitheredMonochromeBits. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1970 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1971 |
bits := self floydSteinbergDitheredBitsDepth:depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1972 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1973 |
|
816 | 1974 |
^ self makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1975 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1976 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1977 |
|i f| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1978 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1979 |
i := Image fromFile:'bitmaps/claus.gif'. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1980 |
(i asFloydSteinbergDitheredGrayFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1981 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1982 |
|
841 | 1983 |
" |
1984 |
|i f| |
|
1985 |
||
1986 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
1987 |
(i asFloydSteinbergDitheredGrayFormOn:Display) inspect |
|
1988 |
" |
|
1989 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1990 |
"Created: 10.6.1996 / 14:11:39 / cg" |
841 | 1991 |
"Modified: 12.6.1996 / 20:04:48 / cg" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1992 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1993 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1994 |
asFloydSteinbergDitheredGrayImageDepth:depth |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1995 |
"return a floyd-steinberg dithered image from the receiver image." |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1996 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1997 |
|ditheredBits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1998 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1999 |
depth == 1 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2000 |
^ self asFloydSteinbergDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2001 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2002 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2003 |
ditheredBits := self floydSteinbergDitheredBitsDepth:depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2004 |
^ (self class implementorForDepth:depth) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2005 |
width:width height:height fromArray:ditheredBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2006 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2007 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2008 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2009 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2010 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2011 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2012 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2013 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2014 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2015 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2016 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2017 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2018 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2019 |
|
829 | 2020 |
i := Depth24Image width:4 height:1 |
2021 |
fromArray:#[ |
|
2022 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 |
|
2023 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 |
|
2024 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 |
|
2025 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00]. |
|
2026 |
i := i magnifiedBy:4@1. |
|
2027 |
i inspect. |
|
2028 |
||
2029 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
|
2030 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
|
2031 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
|
2032 |
" |
|
2033 |
||
2034 |
" |
|
2035 |
|i| |
|
2036 |
||
2037 |
i := Depth24Image width:4 height:6 |
|
2038 |
fromArray:#[ |
|
2039 |
16r00 16r00 16r00 16r00 16r00 16r80 16r00 16r00 16rff 16r00 16r80 16r00 |
|
2040 |
16r00 16r80 16r80 16r00 16rFF 16r00 16r00 16rFF 16r80 16r00 16rFF 16rFF |
|
2041 |
16r80 16r00 16r00 16r80 16r00 16r80 16r80 16r00 16rff 16r80 16r80 16r00 |
|
2042 |
16r80 16r80 16r80 16r80 16rFF 16r00 16r80 16rFF 16r80 16r80 16rFF 16rFF |
|
2043 |
16rFF 16r00 16r00 16rFF 16r00 16r80 16rFF 16r00 16rff 16rFF 16r80 16r00 |
|
2044 |
16rFF 16r80 16r80 16rFF 16rFF 16r00 16rFF 16rFF 16r80 16rFF 16rFF 16rFF]. |
|
2045 |
i := i magnifiedBy:30. |
|
2046 |
i inspect. |
|
2047 |
||
2048 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
|
2049 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
|
2050 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
|
2051 |
" |
|
2052 |
" |
|
2053 |
|i| |
|
2054 |
||
2055 |
i := Image fromFile:'granite.tiff'. |
|
2056 |
i inspect. |
|
2057 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
|
2058 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
|
2059 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
|
2060 |
" |
|
2061 |
||
2062 |
" |
|
2063 |
|i| |
|
2064 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2065 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2066 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2067 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2068 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2069 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2070 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2071 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2072 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2073 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2074 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2075 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2076 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2077 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2078 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2079 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2080 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2081 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2082 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2083 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2084 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2085 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2086 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2087 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2088 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2089 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2090 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2091 |
"Created: 10.6.1996 / 12:33:47 / cg" |
829 | 2092 |
"Modified: 11.6.1996 / 00:16:17 / cg" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2093 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2094 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2095 |
asFloydSteinbergDitheredMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2096 |
"return a dithered moncohrome form from the receiver image." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2097 |
|
816 | 2098 |
|monoBits clr0 clr1| |
2099 |
||
2100 |
monoBits := self floydSteinbergDitheredMonochromeBits. |
|
2101 |
^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2102 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2103 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2104 |
|i f| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2105 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2106 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2107 |
(i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2108 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2109 |
|
816 | 2110 |
" |
2111 |
|i f| |
|
2112 |
||
2113 |
i := Depth2Image width:8 height:8 |
|
2114 |
fromArray:#[ |
|
2115 |
4r0000 4r0000 |
|
2116 |
4r0000 4r0000 |
|
2117 |
4r1111 4r1111 |
|
2118 |
4r1111 4r1111 |
|
2119 |
4r2222 4r2222 |
|
2120 |
4r2222 4r2222 |
|
2121 |
4r3333 4r3333 |
|
2122 |
4r3333 4r3333 |
|
2123 |
]. |
|
2124 |
(i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect. |
|
2125 |
" |
|
2126 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2127 |
"Created: 10.6.1996 / 14:11:39 / cg" |
816 | 2128 |
"Modified: 10.6.1996 / 20:18:01 / cg" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2129 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2130 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2131 |
asFloydSteinbergDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2132 |
"return a floyd-steinberg dithered monochrome image from the receiver image." |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2133 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2134 |
|monoBits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2135 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2136 |
monoBits := self floydSteinbergDitheredMonochromeBits. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2137 |
^ Depth1Image width:width height:height fromArray:monoBits |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2138 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2139 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2140 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2141 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2142 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2143 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2144 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2145 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2146 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2147 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2148 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2149 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2150 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2151 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2152 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2153 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2154 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2155 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2156 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2157 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2158 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2159 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2160 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2161 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2162 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2163 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2164 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2165 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2166 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2167 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2168 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2169 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2170 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2171 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2172 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2173 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2174 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2175 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2176 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2177 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2178 |
"Created: 10.6.1996 / 12:33:47 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2179 |
"Modified: 10.6.1996 / 17:45:48 / cg" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2180 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2181 |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2182 |
asFloydSteinbergDitheredPseudoFormUsing:colors on:aDevice |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2183 |
"return a floyd-steinberg dithered pseudoForm from the picture, |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2184 |
using colors in colors for dithering." |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2185 |
|
1041 | 2186 |
|pseudoBits pseudoBits8 f has8BitImage deviceDepth |
2187 |
map d | |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2188 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2189 |
deviceDepth := aDevice depth. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2190 |
deviceDepth == 8 ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2191 |
has8BitImage := true. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2192 |
] ifFalse:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2193 |
has8BitImage := false. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2194 |
aDevice supportedImageFormats do:[:fmt | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2195 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2196 |
has8BitImage := true. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2197 |
] |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2198 |
] |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2199 |
]. |
1041 | 2200 |
has8BitImage ifFalse:[ |
2201 |
deviceDepth == 4 ifFalse:[^ nil]. |
|
2202 |
||
2203 |
pseudoBits8 := self nfloydSteinbergDitheredDepth8BitsColors:colors. |
|
2204 |
pseudoBits8 isNil ifTrue:[^ nil]. |
|
2205 |
"/ convert to devices depth |
|
2206 |
||
2207 |
pseudoBits := ByteArray new:(width*4+7//8 * height). |
|
2208 |
pseudoBits8 compressPixels:4 width:width height:height into:pseudoBits mapping:nil. |
|
2209 |
d := 4. |
|
2210 |
] ifTrue:[ |
|
2211 |
pseudoBits := self nfloydSteinbergDitheredDepth8BitsColors:colors. |
|
2212 |
pseudoBits isNil ifTrue:[^ nil]. |
|
2213 |
d := 8. |
|
2214 |
]. |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2215 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2216 |
f := Form width:width height:height depth:deviceDepth on:aDevice. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2217 |
f isNil ifTrue:[^ nil]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2218 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2219 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2220 |
"/ have to create a funny colorMap, where |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2221 |
"/ color at:index == color colorId:index |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2222 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2223 |
map := Array new:256 withAll:0. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2224 |
colors do:[:clr | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2225 |
clr notNil ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2226 |
map at:clr colorId + 1 put:clr |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2227 |
] |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2228 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2229 |
f colorMap:map. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2230 |
f initGC. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2231 |
f bits:pseudoBits. |
1041 | 2232 |
aDevice drawBits:pseudoBits bitsPerPixel:d depth:deviceDepth |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2233 |
width:width height:height |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2234 |
x:0 y:0 |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2235 |
into:(f id) x:0 y:0 |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2236 |
width:width height:height with:(f gcId). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2237 |
^ f |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2238 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2239 |
" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2240 |
|i| |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2241 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2242 |
i := Image fromFile:'bitmaps/garfield.gif'. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2243 |
(i asFloydSteinbergDitheredPseudoFormUsing:(Smalltalk at:#'Color:DitherColors') on:Display) inspect |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2244 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2245 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2246 |
|i| |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2247 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2248 |
i := Image fromFile:'bitmaps/claus.gif'. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2249 |
(i asFloydSteinbergDitheredPseudoFormUsing:(Smalltalk at:#'Color:DitherColors') on:Display) inspect |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2250 |
" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2251 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2252 |
"Created: 17.6.1996 / 12:13:35 / cg" |
1041 | 2253 |
"Modified: 5.9.1996 / 19:42:57 / cg" |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2254 |
! |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2255 |
|
0 | 2256 |
asFormOn:aDevice |
72 | 2257 |
"get a device form, with best possible approximation. |
2258 |
remember it in case someone asks again." |
|
2259 |
||
1041 | 2260 |
|form visual| |
72 | 2261 |
|
2262 |
((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm]. |
|
0 | 2263 |
|
901 | 2264 |
mask notNil ifTrue:[ |
2265 |
mask := mask on:aDevice |
|
2266 |
]. |
|
2267 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2268 |
aDevice depth == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2269 |
^ self asMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2270 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2271 |
|
1041 | 2272 |
((visual := aDevice visualType) == #StaticGray) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2273 |
^ self asGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2274 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2275 |
|
1041 | 2276 |
(visual == #PseudoColor |
2277 |
or:[visual == #StaticColor]) ifTrue:[ |
|
873 | 2278 |
form := self asPseudoFormQuickOn:aDevice. |
2279 |
form notNil ifTrue:[ |
|
2280 |
^ form |
|
2281 |
]. |
|
2282 |
]. |
|
2283 |
||
0 | 2284 |
(photometric == #palette) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2285 |
form := self paletteImageAsFormOn:aDevice |
72 | 2286 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2287 |
(photometric == #rgb) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2288 |
form := self rgbImageAsFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2289 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2290 |
form := self greyImageAsFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2291 |
] |
0 | 2292 |
]. |
2293 |
||
72 | 2294 |
(device isNil or:[aDevice == device]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2295 |
"remember this form in the receiver ..." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2296 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2297 |
form notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2298 |
deviceForm := form. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2299 |
device isNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2300 |
device := aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2301 |
Lobby register:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2302 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2303 |
Lobby registerChange:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2304 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2305 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2306 |
can save space, by not keeping the images data-bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2307 |
twice (here and in the device form) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2308 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2309 |
form forgetBits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2310 |
] |
0 | 2311 |
]. |
2312 |
||
72 | 2313 |
^ form |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2314 |
|
1041 | 2315 |
"Modified: 10.7.1996 / 21:55:44 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2316 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2317 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2318 |
asGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2319 |
"get a gray device form" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2320 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2321 |
^ self asGrayFormOn:aDevice dither:DitherAlgorithm. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2322 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2323 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2324 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2325 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2326 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2327 |
(i asGrayFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2328 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2329 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2330 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2331 |
"Created: 10.6.1996 / 18:44:42 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2332 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2333 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2334 |
asGrayFormOn:aDevice dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2335 |
"get a greyscale device form, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2336 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2337 |
|grayBits depth| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2338 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2339 |
depth := aDevice depth. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2340 |
depth == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2341 |
^ self asMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2342 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2343 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2344 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2345 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2346 |
^ self asThresholdGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2347 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2348 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2349 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2350 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2351 |
^ self asOrderedDitheredGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2352 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2353 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2354 |
^ self asFloydSteinbergDitheredGrayFormOn:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2355 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2356 |
"Created: 10.6.1996 / 18:42:01 / cg" |
852 | 2357 |
"Modified: 14.6.1996 / 15:17:28 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2358 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2359 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2360 |
asGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2361 |
"get a gray image from the receiver" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2362 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2363 |
^ self asGrayImageDepth:depth dither:DitherAlgorithm. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2364 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2365 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2366 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2367 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2368 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2369 |
(i asGrayFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2370 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2371 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2372 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2373 |
"Created: 10.6.1996 / 19:07:08 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2374 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2375 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2376 |
asGrayImageDepth:depth dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2377 |
"get a greyscale image, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2378 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2379 |
|grayBits| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2380 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2381 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2382 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2383 |
^ self asThresholdGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2384 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2385 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2386 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2387 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2388 |
^ self asOrderedDitheredGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2389 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2390 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2391 |
^ self asFloydSteinbergDitheredGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2392 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2393 |
"Created: 10.6.1996 / 19:08:21 / cg" |
0 | 2394 |
! |
2395 |
||
2396 |
asMonochromeFormOn:aDevice |
|
2397 |
"get a monochrome device form" |
|
2398 |
||
72 | 2399 |
|form| |
2400 |
||
2401 |
((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ monoDeviceForm]. |
|
2402 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2403 |
form := self asMonochromeFormOn:aDevice dither:DitherAlgorithm. |
0 | 2404 |
|
72 | 2405 |
(device isNil or:[aDevice == device]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2406 |
"remember this form in the receiver ..." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2407 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2408 |
form notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2409 |
monoDeviceForm := form. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2410 |
device isNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2411 |
device := aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2412 |
Lobby register:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2413 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2414 |
Lobby registerChange:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2415 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2416 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2417 |
can save space, by not keeping the images data-bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2418 |
twice (here and in the device form) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2419 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2420 |
form forgetBits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2421 |
] |
0 | 2422 |
]. |
2423 |
||
72 | 2424 |
^ form |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2425 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2426 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2427 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2428 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2429 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2430 |
(i asMonochromeFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2431 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2432 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2433 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2434 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2435 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2436 |
asMonochromeFormOn:aDevice dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2437 |
"get a monochrome device form, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2438 |
|
816 | 2439 |
|monoBits clr0 clr1 mustInvert| |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2440 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2441 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2442 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2443 |
^ self asThresholdMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2444 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2445 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2446 |
aDitherAlgorithm == #burkes ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2447 |
monoBits := self burkesDitheredMonochromeBits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2448 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2449 |
aDitherAlgorithm == #stevensonArce ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2450 |
monoBits := self stevensonArceDitheredMonochromeBits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2451 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2452 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2453 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2454 |
^ self asOrderedDitheredGrayFormOn:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2455 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2456 |
^ self asFloydSteinbergDitheredMonochromeFormOn:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2457 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2458 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2459 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2460 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2461 |
"/ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2462 |
"/ make its pixel interpretation correct for the device |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2463 |
"/ |
816 | 2464 |
^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
2465 |
||
2466 |
"Modified: 10.6.1996 / 20:18:05 / cg" |
|
89 | 2467 |
! |
2468 |
||
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2469 |
asNearestPaintDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2470 |
"return a nearest paint pseudoForm from the palette picture. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2471 |
Use the colors in the fixColors array, which must be fixR x fixG x fixB |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2472 |
colors assigned to aDevice, such as the preallocated colors of the |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2473 |
Color class. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2474 |
By passing the ditherColors as extra array, this method can |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2475 |
also be used to dither an 8bit image into a smaller number of colors, |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2476 |
for example to create dithered Depth4Images from Depth8Images." |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2477 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2478 |
|pseudoBits f has8BitImage deviceDepth |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2479 |
map | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2480 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2481 |
deviceDepth := aDevice depth. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2482 |
deviceDepth == 8 ifTrue:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2483 |
has8BitImage := true. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2484 |
] ifFalse:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2485 |
has8BitImage := false. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2486 |
aDevice supportedImageFormats do:[:fmt | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2487 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2488 |
has8BitImage := true. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2489 |
] |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2490 |
] |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2491 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2492 |
has8BitImage ifFalse:[^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2493 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2494 |
pseudoBits := self nearestPaintDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2495 |
pseudoBits isNil ifTrue:[^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2496 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2497 |
f := Form width:width height:height depth:deviceDepth on:aDevice. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2498 |
f isNil ifTrue:[^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2499 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2500 |
"/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2501 |
"/ have to create a funny colorMap, where |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2502 |
"/ color at:index == color colorId:index |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2503 |
"/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2504 |
map := Array new:256. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2505 |
fixColors do:[:clr | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2506 |
map at:clr colorId + 1 put:clr |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2507 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2508 |
f colorMap:map. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2509 |
f initGC. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2510 |
f bits:pseudoBits. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2511 |
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:deviceDepth |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2512 |
width:width height:height |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2513 |
x:0 y:0 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2514 |
into:(f id) x:0 y:0 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2515 |
width:width height:height with:(f gcId). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2516 |
^ f |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2517 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2518 |
" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2519 |
example: |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2520 |
color reduction from Depth8 to Depth4 (dithering) can be done by: |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2521 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2522 |
|img8 reducedImg8 img4 map form| |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2523 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2524 |
map := #( |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2525 |
(0 0 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2526 |
(0 0 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2527 |
(0 50 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2528 |
(0 50 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2529 |
(0 100 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2530 |
(0 100 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2531 |
(100 0 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2532 |
(100 0 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2533 |
(100 50 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2534 |
(100 50 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2535 |
(100 100 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2536 |
(100 100 100)) collect:[:rgb | (Color red:(rgb at:1) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2537 |
green:(rgb at:2) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2538 |
blue:(rgb at:3)) on:Display]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2539 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2540 |
img8 := Image fromFile:'bitmaps/claus.gif'. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2541 |
form := img8 asNearestPaintDepth8FormOn:Display |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2542 |
colors:map |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2543 |
nRed:2 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2544 |
nGreen:3 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2545 |
nBlue:2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2546 |
img8 := Depth8Image fromForm:form. 'dithered version of original image'. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2547 |
img4 := Depth4Image fromImage:img8. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2548 |
" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2549 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2550 |
"Created: 17.6.1996 / 18:47:46 / cg" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2551 |
"Modified: 17.6.1996 / 18:52:47 / cg" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2552 |
! |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2553 |
|
808 | 2554 |
asOrderedDitheredGrayFormOn:aDevice |
2555 |
"return a dithered depth-x grey form from the receiver image. |
|
2556 |
Uses an 8x8 dithermatrix." |
|
2557 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2558 |
|f depth bits| |
808 | 2559 |
|
2560 |
depth := aDevice depth. |
|
2561 |
depth == 1 ifTrue:[ |
|
2562 |
"/ for monochrome, there is highly specialized |
|
2563 |
"/ monochrome dither code available |
|
2564 |
||
2565 |
^ self asOrderedDitheredMonochromeFormOn:aDevice |
|
2566 |
]. |
|
2567 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2568 |
bits := self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2569 |
orderedDitheredBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
808 | 2570 |
ditherWidth:8 |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2571 |
depth:depth. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2572 |
|
816 | 2573 |
^ self makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2574 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2575 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2576 |
|i| |
808 | 2577 |
|
2578 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2579 |
(i asOrderedDitheredGrayFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2580 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2581 |
|
816 | 2582 |
"Modified: 10.6.1996 / 20:10:07 / cg" |
808 | 2583 |
! |
2584 |
||
798 | 2585 |
asOrderedDitheredGrayImageDepth:depth |
2586 |
"return a dithered depth-x grey image from the receiver image. |
|
2587 |
Uses an 8x8 dithermatrix." |
|
2588 |
||
2589 |
|dither| |
|
2590 |
||
2591 |
dither := self class orderedDitherMatrixOfSize:8. |
|
2592 |
||
2593 |
depth == 1 ifTrue:[ |
|
2594 |
"/ for monochrome, there is highly specialized |
|
2595 |
"/ monochrome dither code available |
|
2596 |
||
2597 |
^ Depth1Image |
|
2598 |
width:width |
|
2599 |
height:height |
|
2600 |
fromArray:( |
|
2601 |
self |
|
2602 |
orderedDitheredMonochromeBitsWithDitherMatrix:dither |
|
2603 |
ditherWidth:8) |
|
2604 |
]. |
|
2605 |
||
2606 |
^ (self class implementorForDepth:depth) |
|
2607 |
width:width |
|
2608 |
height:height |
|
2609 |
fromArray:( |
|
2610 |
self |
|
2611 |
orderedDitheredBitsWithDitherMatrix:dither |
|
2612 |
ditherWidth:8 |
|
2613 |
depth:depth) |
|
2614 |
||
2615 |
" |
|
2616 |
|i i1 i2 i4 i8| |
|
2617 |
||
2618 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
2619 |
i1 := i asOrderedDitheredGrayImageDepth:1. |
|
2620 |
i1 inspect. |
|
2621 |
||
2622 |
i2 := i asOrderedDitheredGrayImageDepth:2. |
|
2623 |
i2 inspect. |
|
2624 |
||
2625 |
i4 := i asOrderedDitheredGrayImageDepth:4. |
|
2626 |
i4 inspect. |
|
2627 |
||
2628 |
i8 := i asOrderedDitheredGrayImageDepth:8. |
|
2629 |
i8 inspect. |
|
2630 |
" |
|
2631 |
||
2632 |
" |
|
2633 |
|i i1 i2 i4 i8| |
|
2634 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
2635 |
i1 := i asOrderedDitheredGrayImageDepth:1. |
|
2636 |
i1 inspect. |
|
2637 |
||
2638 |
i2 := i asOrderedDitheredGrayImageDepth:2. |
|
2639 |
i2 inspect. |
|
2640 |
||
2641 |
i4 := i asOrderedDitheredGrayImageDepth:4. |
|
2642 |
i4 inspect. |
|
2643 |
||
2644 |
i8 := i asOrderedDitheredGrayImageDepth:8. |
|
2645 |
i8 inspect. |
|
800 | 2646 |
|
2647 |
i2 := i8 asOrderedDitheredGrayImageDepth:2. |
|
2648 |
i2 inspect. |
|
798 | 2649 |
" |
2650 |
||
2651 |
"Created: 7.6.1996 / 18:03:54 / cg" |
|
800 | 2652 |
"Modified: 7.6.1996 / 19:41:59 / cg" |
798 | 2653 |
! |
2654 |
||
2655 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
2656 |
"return a dithered monochrome form from the grey image. |
|
2657 |
Uses a 4x4 dithermatrix." |
|
2658 |
||
2659 |
"/ 4x4 seems a good comprimize between: |
|
2660 |
"/ number of grey levels (8x8 is better) |
|
2661 |
"/ artifacts (4x4 is better) |
|
2662 |
"/ |
|
2663 |
"/ could look at the image and decide upon the number of |
|
2664 |
"/ distinct colors present. Use 8x8 for high-number, |
|
2665 |
"/ 4x4 for small number of colors ... |
|
2666 |
||
2667 |
^ self |
|
2668 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
2669 |
ditherMatrix:(self class orderedDitherMatrixOfSize:4) |
|
2670 |
ditherWidth:4 |
|
2671 |
||
2672 |
"/ ^ self |
|
2673 |
"/ asOrderedDitheredMonochromeFormOn:aDevice |
|
2674 |
"/ ditherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
2675 |
"/ ditherWidth:8 |
|
2676 |
||
2677 |
" |
|
2678 |
|i f| |
|
2679 |
||
2680 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
2681 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2682 |
||
2683 |
||
2684 |
|i f| |
|
2685 |
||
2686 |
i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10. |
|
2687 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2688 |
||
2689 |
||
2690 |
|i f| |
|
2691 |
||
2692 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
2693 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2694 |
||
2695 |
||
2696 |
|i f| |
|
2697 |
||
2698 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
2699 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2700 |
||
2701 |
||
2702 |
|i f| |
|
2703 |
||
2704 |
i := (Image fromFile:'bitmaps/blue-ball.gif') magnifiedBy:1. |
|
2705 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2706 |
" |
|
2707 |
||
2708 |
"Created: 7.6.1996 / 14:52:32 / cg" |
|
2709 |
"Modified: 7.6.1996 / 16:37:47 / cg" |
|
2710 |
! |
|
2711 |
||
2712 |
asOrderedDitheredMonochromeFormOn:aDevice ditherMatrix:ditherMatrix ditherWidth:dW |
|
2713 |
"return a dithered monochrome form from the image. |
|
2714 |
Uses the passed ditherMatrix and ditherWidth." |
|
2715 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2716 |
|monoBits clr0 clr1| |
798 | 2717 |
|
2718 |
monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW. |
|
816 | 2719 |
^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2720 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2721 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2722 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2723 |
|i| |
798 | 2724 |
|
2725 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2726 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2727 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2728 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2729 |
|i| |
798 | 2730 |
|
2731 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2732 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2733 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2734 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2735 |
|i| |
798 | 2736 |
|
2737 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2738 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
798 | 2739 |
" |
2740 |
||
2741 |
"Created: 7.6.1996 / 14:51:42 / cg" |
|
816 | 2742 |
"Modified: 10.6.1996 / 20:18:07 / cg" |
798 | 2743 |
! |
2744 |
||
2745 |
asOrderedDitheredMonochromeImage |
|
2746 |
"return a dithered monochrome image from the receiver image. |
|
2747 |
Uses a 4x4 dithermatrix." |
|
2748 |
||
2749 |
"/ 4x4 seems a good comprimize between: |
|
2750 |
"/ number of grey levels (8x8 is better) |
|
2751 |
"/ artifacts (4x4 is better) |
|
2752 |
"/ |
|
2753 |
"/ could look at the image and decide upon the number of |
|
2754 |
"/ distinct colors present. Use 8x8 for high-number, |
|
2755 |
"/ 4x4 for small number of colors ... |
|
2756 |
||
2757 |
^ self |
|
2758 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:4) |
|
2759 |
ditherWidth:4 |
|
2760 |
||
2761 |
"/ ^ self |
|
2762 |
"/ asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
2763 |
"/ ditherWidth:8 |
|
2764 |
||
2765 |
" |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2766 |
|i| |
798 | 2767 |
|
2768 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2769 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2770 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2771 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2772 |
|i| |
798 | 2773 |
|
2774 |
i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2775 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2776 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2777 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2778 |
|i| |
798 | 2779 |
|
2780 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2781 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2782 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2783 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2784 |
|i| |
798 | 2785 |
|
2786 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2787 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2788 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2789 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2790 |
|i| |
798 | 2791 |
|
2792 |
i := (Image fromFile:'bitmaps/blue-ball.gif') magnifiedBy:1. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2793 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2794 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2795 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2796 |
|i| |
798 | 2797 |
|
2798 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2799 |
i asOrderedDitheredMonochromeImage inspect |
798 | 2800 |
" |
2801 |
||
2802 |
"Created: 7.6.1996 / 15:02:07 / cg" |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2803 |
"Modified: 10.6.1996 / 11:15:09 / cg" |
798 | 2804 |
! |
2805 |
||
2806 |
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix ditherWidth:dW |
|
2807 |
"return a dithered monochrome image from the receiver image. |
|
2808 |
Uses the passed ditherMatrix and ditherWidth." |
|
2809 |
||
2810 |
|monoBits| |
|
2811 |
||
2812 |
monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW. |
|
2813 |
^ (Depth1Image width:width height:height fromArray:monoBits) photometric:#blackIs0 |
|
2814 |
||
2815 |
"order-4 dither: |
|
2816 |
||
2817 |
|i| |
|
2818 |
||
2819 |
i := Image fromFile:'garfield.gif'. |
|
2820 |
i |
|
2821 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:4) |
|
2822 |
ditherWidth:4 |
|
2823 |
" |
|
2824 |
||
2825 |
"order-6 dither: |
|
2826 |
||
2827 |
|i| |
|
2828 |
||
2829 |
i := Image fromFile:'garfield.gif'. |
|
2830 |
i |
|
2831 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:8) |
|
2832 |
ditherWidth:8 |
|
2833 |
" |
|
2834 |
||
2835 |
||
2836 |
"thresholding at:0.5 (all above 0.5 becomes white): |
|
2837 |
||
2838 |
|i| |
|
2839 |
||
2840 |
i := Image fromFile:'garfield.gif'. |
|
2841 |
i |
|
2842 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:8) |
|
2843 |
ditherWidth:4 |
|
2844 |
" |
|
2845 |
||
2846 |
"thresholding at: 0.25 (all above 0.25 becomes white): |
|
2847 |
||
2848 |
|i| |
|
2849 |
||
2850 |
i := Image fromFile:'garfield.gif'. |
|
2851 |
i |
|
2852 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:3) |
|
2853 |
ditherWidth:4 |
|
2854 |
" |
|
2855 |
||
2856 |
"thresholding at: 0.75 (all above 0.75 becomes white): |
|
2857 |
||
2858 |
|i| |
|
2859 |
||
2860 |
i := Image fromFile:'garfield.gif'. |
|
2861 |
i |
|
2862 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:11) |
|
2863 |
ditherWidth:4 |
|
2864 |
" |
|
2865 |
||
2866 |
"Modified: 7.6.1996 / 17:23:47 / cg" |
|
2867 |
! |
|
2868 |
||
873 | 2869 |
asPseudoFormQuickOn:aDevice |
2870 |
"return a pseudo-deviceForm from the image. |
|
878 | 2871 |
Fail if any color is not available (i.e. do not dither)." |
873 | 2872 |
|
2873 |
|f d dDev temp temp8 bits anyMissing clr cMap idMap |
|
878 | 2874 |
nClr "{ Class: SmallInteger }" |
2875 |
usedColors | |
|
873 | 2876 |
|
2877 |
d := self depth. |
|
2878 |
(d == 1 |
|
2879 |
or:[d == 2 |
|
2880 |
or:[d == 4 |
|
2881 |
or:[d == 8]]]) ifFalse:[^ nil]. |
|
2882 |
||
2883 |
"/ |
|
2884 |
"/ see if all of the images colors are representable |
|
2885 |
"/ on the device |
|
2886 |
||
2887 |
bits := self bitsPerPixel. |
|
2888 |
nClr := (1 bitShift:bits). |
|
2889 |
cMap := Array new:nClr. |
|
2890 |
idMap := ByteArray new:nClr. |
|
2891 |
||
2892 |
photometric == #palette ifTrue:[ |
|
2893 |
nClr := nClr min:(colorMap size) |
|
2894 |
]. |
|
2895 |
||
878 | 2896 |
d == 8 ifTrue:[ |
2897 |
usedColors := bytes usedValues. "gets us an array filled with used values" |
|
2898 |
1 to:nClr do:[:pixel | |
|
2899 |
(usedColors includes:(pixel - 1)) ifFalse:[ |
|
2900 |
clr := Color black |
|
2901 |
] ifTrue:[ |
|
2902 |
clr := self colorFromValue:pixel-1. |
|
2903 |
clr := clr exactOn:aDevice. |
|
2904 |
clr isNil ifTrue:[^ nil]. |
|
2905 |
]. |
|
2906 |
cMap at:(pixel) put:clr. |
|
2907 |
idMap at:(pixel) put:(clr colorId). |
|
2908 |
]. |
|
2909 |
] ifFalse:[ |
|
2910 |
1 to:nClr do:[:pixel | |
|
2911 |
clr := self colorFromValue:pixel-1. |
|
2912 |
clr := clr exactOn:aDevice. |
|
2913 |
clr isNil ifTrue:[^ nil]. |
|
2914 |
||
2915 |
cMap at:(pixel) put:clr. |
|
2916 |
idMap at:(pixel) put:(clr colorId). |
|
2917 |
]. |
|
873 | 2918 |
]. |
2919 |
||
2920 |
"/ got all colors; good - simply change depth & translate pixels |
|
2921 |
||
2922 |
dDev := aDevice depth. |
|
2923 |
||
2924 |
(d == 8 and:[dDev == 8]) ifTrue:[ |
|
2925 |
"/ only translate |
|
2926 |
temp := ByteArray uninitializedNew:(width * height). |
|
2927 |
bytes expandPixels:8 "xlate only" |
|
2928 |
width:width |
|
2929 |
height:height |
|
2930 |
into:temp |
|
2931 |
mapping:idMap. |
|
2932 |
] ifFalse:[ |
|
2933 |
||
2934 |
"/ stupid: expandPixels can only handle any-to-8 |
|
2935 |
"/ compressPixels can only handle 8-to-any |
|
2936 |
||
2937 |
d ~~ 8 ifTrue:[ |
|
2938 |
temp8 := ByteArray uninitializedNew:(width * height). |
|
2939 |
||
2940 |
bytes expandPixels:d |
|
2941 |
width:width |
|
2942 |
height:height |
|
2943 |
into:temp8 |
|
2944 |
mapping:idMap. |
|
2945 |
idMap := nil. |
|
2946 |
] ifFalse:[ |
|
2947 |
temp8 := bytes. |
|
2948 |
]. |
|
2949 |
||
2950 |
dDev ~~ 8 ifTrue:[ |
|
2951 |
temp := ByteArray uninitializedNew:((width * dDev + 7) // 8 * height). |
|
2952 |
||
2953 |
temp8 compressPixels:dDev |
|
2954 |
width:width |
|
2955 |
height:height |
|
2956 |
into:temp |
|
2957 |
mapping:idMap. |
|
2958 |
] ifFalse:[ |
|
2959 |
temp := temp8 |
|
2960 |
]. |
|
2961 |
]. |
|
2962 |
||
2963 |
f := Form width:width height:height depth:dDev on:aDevice. |
|
2964 |
f isNil ifTrue:[^ nil]. |
|
2965 |
||
2966 |
f colorMap:cMap. |
|
2967 |
f initGC. |
|
2968 |
||
2969 |
aDevice |
|
2970 |
drawBits:temp |
|
2971 |
depth:dDev |
|
2972 |
width:width |
|
2973 |
height:height |
|
2974 |
x:0 y:0 |
|
2975 |
into:(f id) x:0 y:0 |
|
2976 |
width:width |
|
2977 |
height:height |
|
2978 |
with:(f gcId). |
|
2979 |
||
2980 |
^ f |
|
2981 |
||
2982 |
" |
|
2983 |
( |
|
2984 |
(((Depth4Image |
|
2985 |
width:4 |
|
2986 |
height:4 |
|
2987 |
fromArray:#[ |
|
2988 |
16r01 16r23 |
|
2989 |
16r45 16r67 |
|
2990 |
16r89 16rab |
|
2991 |
16rcd 16ref |
|
2992 |
])) |
|
2993 |
magnifiedBy:30 |
|
2994 |
) |
|
2995 |
asPseudoFormQuickOn:Display |
|
2996 |
) inspect |
|
2997 |
" |
|
2998 |
||
878 | 2999 |
"Modified: 17.6.1996 / 17:31:49 / cg" |
873 | 3000 |
! |
3001 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3002 |
asStevensonArceDitheredMonochromeImage |
837 | 3003 |
"return a stevenson-arce dithered monochrome image from the receiver image. |
3004 |
Depending on the images contents, this may or may not look better than |
|
3005 |
a floyd-steinberg dithered image. |
|
3006 |
Notice, that floyd-steinberg dithering is faster; both because less |
|
3007 |
error diffusion is done and due to being specially tuned." |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3008 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3009 |
|monoBits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3010 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3011 |
monoBits := self stevensonArceDitheredMonochromeBits. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3012 |
^ (Depth1Image width:width height:height fromArray:monoBits) photometric:#blackIs0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3013 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3014 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3015 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3016 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3017 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3018 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3019 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3020 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3021 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3022 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3023 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3024 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3025 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3026 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3027 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3028 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3029 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3030 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3031 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3032 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3033 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3034 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3035 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3036 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3037 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3038 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3039 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3040 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3041 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3042 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3043 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3044 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3045 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3046 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3047 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3048 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3049 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3050 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3051 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3052 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3053 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3054 |
"Created: 10.6.1996 / 12:38:29 / cg" |
837 | 3055 |
"Modified: 12.6.1996 / 13:58:24 / cg" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3056 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3057 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3058 |
asThresholdGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3059 |
"return a thresholded grey form from the receiver image." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3060 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3061 |
|depth| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3062 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3063 |
(depth := aDevice depth) == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3064 |
^ self asThresholdMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3065 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3066 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3067 |
^ self |
816 | 3068 |
makeDeviceGrayPixmapOn:aDevice |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3069 |
depth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3070 |
fromArray:(self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3071 |
orderedDitheredBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3072 |
ditherWidth:4 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3073 |
depth:depth) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3074 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3075 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3076 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3077 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3078 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3079 |
(i asThresholdGrayFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3080 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3081 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3082 |
"Created: 10.6.1996 / 18:38:31 / cg" |
816 | 3083 |
"Modified: 10.6.1996 / 20:10:26 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3084 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3085 |
|
798 | 3086 |
asThresholdGrayImageDepth:depth |
3087 |
"return a thresholded depth-x grey image from the receiver image." |
|
3088 |
||
800 | 3089 |
depth == 1 ifTrue:[ |
3090 |
"/ for monochrome, there is highly specialized |
|
3091 |
"/ monochrome dither code available |
|
3092 |
||
3093 |
^ Depth1Image |
|
3094 |
width:width |
|
3095 |
height:height |
|
3096 |
fromArray:( |
|
3097 |
self |
|
3098 |
orderedDitheredMonochromeBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
3099 |
ditherWidth:4) |
|
3100 |
]. |
|
3101 |
||
798 | 3102 |
^ (self class implementorForDepth:depth) |
3103 |
width:width |
|
3104 |
height:height |
|
3105 |
fromArray:( |
|
3106 |
self |
|
3107 |
orderedDitheredBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
3108 |
ditherWidth:4 |
|
3109 |
depth:depth) |
|
3110 |
||
3111 |
" |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3112 |
|i| |
798 | 3113 |
|
3114 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3115 |
(i asThresholdGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3116 |
(i asThresholdGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3117 |
(i asThresholdGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3118 |
(i asThresholdGrayImageDepth:8) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3119 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3120 |
(i asOrderedDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3121 |
(i asOrderedDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3122 |
(i asOrderedDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3123 |
(i asOrderedDitheredGrayImageDepth:8) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3124 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3125 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3126 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3127 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3128 |
(i asFloydSteinbergDitheredGrayImageDepth:8) inspect. |
798 | 3129 |
" |
3130 |
||
3131 |
"Created: 7.6.1996 / 18:13:33 / cg" |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3132 |
"Modified: 10.6.1996 / 14:20:56 / cg" |
798 | 3133 |
! |
3134 |
||
3135 |
asThresholdMonochromeFormOn:aDevice |
|
3136 |
"return a threshold monochrome form from the image." |
|
3137 |
||
3138 |
^ self |
|
3139 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
3140 |
ditherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
3141 |
ditherWidth:4 |
|
3142 |
||
3143 |
" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3144 |
|i| |
798 | 3145 |
|
3146 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3147 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3148 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3149 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3150 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3151 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3152 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3153 |
i := (Image fromFile:'bitmaps/a11.ico') magnifiedBy:10. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3154 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3155 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3156 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3157 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3158 |
|i| |
798 | 3159 |
|
3160 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3161 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3162 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3163 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3164 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3165 |
|i| |
798 | 3166 |
|
3167 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3168 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3169 |
(i asThresholdMonochromeFormOn:Display) inspect |
798 | 3170 |
" |
3171 |
||
3172 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3173 |
"Modified: 10.6.1996 / 17:44:29 / cg" |
798 | 3174 |
! |
3175 |
||
3176 |
asThresholdMonochromeImage |
|
3177 |
"return a threshold monochrome image from the image. |
|
3178 |
Threshold means: brightness < 0.5 -> black / otherwise white" |
|
3179 |
||
3180 |
^ self |
|
3181 |
asOrderedDitheredMonochromeImageWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
3182 |
ditherWidth:4 |
|
3183 |
||
3184 |
" |
|
3185 |
|i i2| |
|
3186 |
||
3187 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
3188 |
i2 := i asThresholdMonochromeImage |
|
3189 |
||
3190 |
||
3191 |
|i i2| |
|
3192 |
||
3193 |
i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10. |
|
3194 |
i2 := i asThresholdMonochromeImage |
|
3195 |
||
3196 |
||
3197 |
|i i2| |
|
3198 |
||
3199 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
3200 |
i2 := i asThresholdMonochromeImage |
|
3201 |
||
3202 |
||
3203 |
|i i2| |
|
3204 |
||
3205 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
3206 |
i2 := i asThresholdMonochromeImage |
|
3207 |
" |
|
3208 |
||
3209 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
3210 |
"Modified: 7.6.1996 / 17:16:10 / cg" |
|
3211 |
! |
|
3212 |
||
808 | 3213 |
asThresholdMonochromeImage:thresholdBrighness |
3214 |
"return a threshold monochrome image from the image. |
|
3215 |
The argument (0..1) gives the threshold value; |
|
3216 |
Threshold means: brightness < threshold -> black / otherwise white" |
|
3217 |
||
3218 |
|value ditherMatrix| |
|
3219 |
||
3220 |
value := thresholdBrighness * 255. |
|
3221 |
ditherMatrix := ByteArray new:256 withAll:(value truncated). |
|
3222 |
||
3223 |
^ self |
|
3224 |
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix |
|
3225 |
ditherWidth:16 |
|
3226 |
||
3227 |
" |
|
3228 |
|i| |
|
3229 |
||
3230 |
i := Image width:4 height:4 depth:4 |
|
3231 |
fromArray:#[ 16r01 16r23 |
|
3232 |
16r45 16r67 |
|
3233 |
16r89 16rab |
|
3234 |
16rcd 16ref ]. |
|
3235 |
i := i magnifiedBy:30. |
|
3236 |
i inspect. |
|
3237 |
(i asThresholdMonochromeImage:0.125) inspect. |
|
3238 |
(i asThresholdMonochromeImage:0.25) inspect. |
|
3239 |
(i asThresholdMonochromeImage:0.5) inspect. |
|
3240 |
(i asThresholdMonochromeImage:0.75) inspect. |
|
3241 |
(i asThresholdMonochromeImage:1) inspect. |
|
3242 |
" |
|
3243 |
||
3244 |
" |
|
3245 |
|i| |
|
3246 |
||
3247 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
3248 |
i inspect. |
|
3249 |
(i asThresholdMonochromeImage:0.125) inspect. |
|
3250 |
(i asThresholdMonochromeImage:0.25) inspect. |
|
3251 |
(i asThresholdMonochromeImage:0.5) inspect. |
|
3252 |
(i asThresholdMonochromeImage:0.625) inspect. |
|
3253 |
(i asThresholdMonochromeImage:0.75) inspect. |
|
3254 |
" |
|
3255 |
||
3256 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
3257 |
"Modified: 8.6.1996 / 14:51:57 / cg" |
|
3258 |
! |
|
3259 |
||
283 | 3260 |
fromForm:aForm |
592 | 3261 |
"setup the receiver from a form" |
283 | 3262 |
|
3263 |
|map c0 c1| |
|
3264 |
||
3265 |
width := aForm width. |
|
3266 |
height := aForm height. |
|
3267 |
bitsPerSample := self bitsPerSample. |
|
3268 |
samplesPerPixel := self samplesPerPixel. |
|
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3269 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3270 |
aForm hasBits ifFalse:[ |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3271 |
"/ must read the data from the device |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3272 |
self from:aForm in:(0@0 extent:aForm extent). |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3273 |
^ self |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3274 |
]. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3275 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3276 |
"/ the form has all data available |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3277 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3278 |
bytes := aForm bits. |
283 | 3279 |
map := aForm colorMap. |
3280 |
||
3281 |
aForm depth == 1 ifTrue:[ |
|
592 | 3282 |
map isNil ifTrue:[ |
3283 |
photometric := #whiteIs0 |
|
3284 |
] ifFalse:[ |
|
3285 |
c0 := map at:1. |
|
3286 |
c1 := map at:2. |
|
3287 |
((c0 = Color white) |
|
3288 |
and:[c1 = Color black]) ifTrue:[ |
|
3289 |
photometric := #whiteIs0 |
|
3290 |
] ifFalse:[ |
|
3291 |
((c0 = Color black) |
|
3292 |
and:[c1 = Color white]) ifTrue:[ |
|
3293 |
photometric := #blackIs0 |
|
3294 |
] ifFalse:[ |
|
3295 |
photometric := #palette. |
|
3296 |
colorMap := Array with:c0 with:c1. |
|
3297 |
] |
|
3298 |
] |
|
3299 |
] |
|
283 | 3300 |
] ifFalse:[ |
592 | 3301 |
map notNil ifTrue:[ |
3302 |
photometric := #palette. |
|
3303 |
colorMap := map copy. |
|
3304 |
] ifFalse:[ |
|
3305 |
" |
|
3306 |
photometric stays at default |
|
3307 |
(which is rgb for d24, greyscale for others) |
|
3308 |
" |
|
3309 |
] |
|
283 | 3310 |
]. |
592 | 3311 |
|
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3312 |
"Modified: 5.7.1996 / 16:24:31 / cg" |
283 | 3313 |
! |
3314 |
||
89 | 3315 |
fromImage:anImage |
3316 |
"setup the receiver from another image. |
|
3317 |
Color precision may be lost, if conversion is from a higher depth |
|
191 | 3318 |
image. |
3319 |
WARNING: |
|
3320 |
This implementation is a slow fallback (the loop over the |
|
89 | 3321 |
source pixels is very slow). If this method is used heavily, you |
3322 |
may want to redefine it in concrete subclasses for common source images." |
|
3323 |
||
3324 |
width := anImage width. |
|
3325 |
height := anImage height. |
|
3326 |
bytes := ByteArray uninitializedNew:(self bytesPerRow * height). |
|
3327 |
bitsPerSample := self bitsPerSample. |
|
3328 |
samplesPerPixel := self samplesPerPixel. |
|
191 | 3329 |
self colormapFromImage:anImage. |
89 | 3330 |
anImage colorsFromX:0 y:0 toX:(width-1) y:(height-1) do:[:x :y :clr | |
798 | 3331 |
self atX:x y:y put:clr |
89 | 3332 |
]. |
3333 |
||
3334 |
" |
|
798 | 3335 |
|i i2 i4 i8 i16 i24| |
89 | 3336 |
|
3337 |
i := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
3338 |
i inspect. |
|
3339 |
i2 := Depth2Image fromImage:i. |
|
3340 |
i2 inspect. |
|
3341 |
i4 := Depth4Image fromImage:i. |
|
3342 |
i4 inspect. |
|
3343 |
i8 := Depth8Image fromImage:i. |
|
3344 |
i8 inspect. |
|
3345 |
i24 := Depth24Image fromImage:i. |
|
3346 |
i24 inspect. |
|
3347 |
" |
|
191 | 3348 |
|
3349 |
"Created: 20.9.1995 / 00:59:03 / claus" |
|
798 | 3350 |
"Modified: 7.6.1996 / 16:23:03 / cg" |
191 | 3351 |
! |
3352 |
||
3353 |
fromSubImage:anImage in:aRectangle |
|
3354 |
"setup the receiver from another image, extracting a rectangular |
|
3355 |
area. Color precision may be lost, if conversion is from a higher depth |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3356 |
image. For palette & rgb images, this may fail if a color cannot be |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3357 |
represented. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3358 |
|
191 | 3359 |
WARNING: |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3360 |
This implementation is a slow fallback (the loop over the |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3361 |
source pixels is very slow). If this method is used heavily, you |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3362 |
may want to redefine it in concrete subclasses for the common case of |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3363 |
of creating a subImage with the same depth & palette." |
191 | 3364 |
|
3365 |
|x0 y0| |
|
3366 |
||
3367 |
width := aRectangle width + 1. |
|
3368 |
height := aRectangle height + 1. |
|
3369 |
bytes := ByteArray uninitializedNew:(self bytesPerRow * height). |
|
3370 |
bitsPerSample := self bitsPerSample. |
|
3371 |
samplesPerPixel := self samplesPerPixel. |
|
3372 |
self colormapFromImage:anImage. |
|
3373 |
x0 := aRectangle left. |
|
3374 |
y0 := aRectangle top. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3375 |
|
191 | 3376 |
((photometric == anImage photometric) |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3377 |
and:[self bitsPerPixel = anImage bitsPerPixel |
191 | 3378 |
and:[colorMap = anImage colorMap]]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3379 |
"/ can do it by value |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3380 |
anImage valuesFromX:x0 y:y0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3381 |
toX:aRectangle right y:aRectangle bottom |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3382 |
do:[:x :y :pixelValue | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3383 |
self atX:x-x0 y:y-y0 putValue:pixelValue. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3384 |
] |
191 | 3385 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3386 |
"/ must do it by colors |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3387 |
anImage colorsFromX:x0 y:y0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3388 |
toX:aRectangle right y:aRectangle bottom |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3389 |
do:[:x :y :clr | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3390 |
self atX:x-x0 y:y-y0 put:clr. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3391 |
] |
191 | 3392 |
]. |
3393 |
||
3394 |
" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3395 |
|i i2 i4 i8 i16 i24| |
191 | 3396 |
|
3397 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
3398 |
i inspect. |
|
3399 |
i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200). |
|
3400 |
i4 inspect. |
|
3401 |
i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200). |
|
3402 |
i8 inspect. |
|
3403 |
i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200). |
|
3404 |
i24 inspect. |
|
3405 |
" |
|
3406 |
||
3407 |
"Created: 20.9.1995 / 01:06:02 / claus" |
|
3408 |
"Modified: 20.9.1995 / 10:15:37 / claus" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3409 |
"Modified: 10.6.1996 / 18:30:17 / cg" |
89 | 3410 |
! |
3411 |
||
283 | 3412 |
monochromeOn:aDevice |
3413 |
"return a monochrome device image of the receiver for aDevice. |
|
3414 |
(monochrome, even if device supports colors)" |
|
3415 |
||
3416 |
((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ self]. |
|
3417 |
(device notNil and:[aDevice ~~ device]) ifTrue:[ |
|
3418 |
"oops, I am already accociated to another device |
|
3419 |
- need a copy ... |
|
3420 |
" |
|
3421 |
^ self copy monochromeOn:aDevice |
|
3422 |
]. |
|
3423 |
monoDeviceForm := self asMonochromeFormOn:aDevice. |
|
3424 |
! |
|
3425 |
||
3426 |
on:aDevice |
|
3427 |
"return an image with the same pixels as the receiver, but |
|
3428 |
associated to aDevice. If the receiver is not yet bound to |
|
3429 |
a device, this will be the receiver. Otherwise, a new image |
|
3430 |
is returned." |
|
3431 |
||
3432 |
((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ self]. |
|
852 | 3433 |
|
283 | 3434 |
(device notNil and:[aDevice ~~ device]) ifTrue:[ |
852 | 3435 |
"oops, I am already accociated to another device |
3436 |
- need a copy ... |
|
3437 |
" |
|
3438 |
^ self copy on:aDevice |
|
283 | 3439 |
]. |
3440 |
deviceForm := self asFormOn:aDevice. |
|
1057
410f0fec2872
oops - must register Image after assigning a deviceForm
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
3441 |
device := aDevice. |
410f0fec2872
oops - must register Image after assigning a deviceForm
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
3442 |
Lobby register:self |
410f0fec2872
oops - must register Image after assigning a deviceForm
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
3443 |
|
410f0fec2872
oops - must register Image after assigning a deviceForm
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
3444 |
"Modified: 16.9.1996 / 21:02:33 / cg" |
283 | 3445 |
! ! |
3446 |
||
3447 |
!Image methodsFor:'converting greyscale images'! |
|
3448 |
||
3449 |
greyImageAsFormOn:aDevice |
|
3450 |
"return a thresholded grey-deviceForm from the grey image." |
|
3451 |
||
3452 |
|pictureDepth nPlanes f| |
|
3453 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3454 |
|
283 | 3455 |
nPlanes := samplesPerPixel. |
3456 |
(nPlanes == 2) ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3457 |
'IMAGE: alpha plane ignored' errorPrintNL. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3458 |
nPlanes := 1 |
283 | 3459 |
]. |
3460 |
||
3461 |
pictureDepth := bitsPerSample at:1. |
|
3462 |
||
3463 |
"monochrome is very easy ..." |
|
3464 |
||
3465 |
(pictureDepth == 1) ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3466 |
^ Form width:width height:height fromArray:bytes on:aDevice |
283 | 3467 |
]. |
3468 |
||
3469 |
(aDevice visualType == #TrueColor) ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3470 |
^ self greyImageAsTrueColorFormOn:aDevice |
283 | 3471 |
]. |
3472 |
||
858 | 3473 |
"/ (aDevice visualType == #PseudoColor |
3474 |
"/ or:[aDevice visualType == #GrayScale |
|
3475 |
"/ or:[aDevice visualType == #StaticColor]]) ifTrue:[ |
|
3476 |
||
3477 |
"/ PseudoColor conversion also works for StaticColor, |
|
3478 |
"/ GrayScale and DirectColor; although possibly with suboptimal results |
|
3479 |
||
3480 |
^ self greyImageAsPseudoFormOn:aDevice |
|
3481 |
||
3482 |
"Modified: 14.6.1996 / 19:32:01 / cg" |
|
283 | 3483 |
! |
3484 |
||
3485 |
greyImageAsPseudoFormOn:aDevice |
|
3486 |
"return an 8-bit pseudo Form from the grey image" |
|
3487 |
||
3488 |
|wideBits pictureDepth f map |
|
3489 |
colorMap usedColors nUsed aColor |
|
3490 |
nColors "{ Class: SmallInteger }" |
|
3491 |
range id| |
|
3492 |
||
3493 |
pictureDepth := bitsPerSample at:1. |
|
3494 |
||
3495 |
(#(2 4 8) includes:pictureDepth) ifFalse:[ |
|
746 | 3496 |
self error:'currently only depth-2, 4 or 8 supported'. |
3497 |
^ nil |
|
283 | 3498 |
]. |
3499 |
||
3500 |
wideBits := ByteArray uninitializedNew:(width * height). |
|
3501 |
||
3502 |
(pictureDepth == 8) ifTrue:[ |
|
746 | 3503 |
"for 8bits, we scan for used colors first; |
3504 |
to avoid allocating too many colors" |
|
3505 |
||
3506 |
usedColors := bytes usedValues. |
|
3507 |
nUsed := usedColors max + 1. |
|
3508 |
||
3509 |
colorMap := Array new:nUsed. |
|
3510 |
photometric == #blackIs0 ifTrue:[ |
|
3511 |
usedColors do:[:grey | |
|
3512 |
colorMap at:(grey + 1) put:(Color gray:(100.0 / 256.0 * grey)) |
|
3513 |
] |
|
3514 |
] ifFalse:[ |
|
3515 |
usedColors do:[:grey | |
|
3516 |
colorMap at:(grey + 1) put:(Color gray:(100 - (100.0 / 256.0 * grey))) |
|
3517 |
] |
|
3518 |
] |
|
89 | 3519 |
] ifFalse:[ |
746 | 3520 |
nColors := (1 bitShift:pictureDepth). |
3521 |
colorMap := Array new:nColors. |
|
3522 |
range := 100 / (nColors - 1) asFloat. |
|
3523 |
photometric == #blackIs0 ifTrue:[ |
|
3524 |
1 to:nColors do:[:i | |
|
3525 |
colorMap at:i put:(Color gray:(i - 1) * range). |
|
3526 |
]. |
|
3527 |
] ifFalse:[ |
|
3528 |
1 to:nColors do:[:i | |
|
3529 |
colorMap at:(nColors - i + 1) put:(Color gray:(i - 1) * range). |
|
3530 |
]. |
|
3531 |
]. |
|
283 | 3532 |
]. |
3533 |
||
3534 |
"XXX should reduce 8->6->4->2 planes, if not all colors could be allocated" |
|
3535 |
||
3536 |
"setup the translation map" |
|
3537 |
map := ByteArray uninitializedNew:256. |
|
3538 |
nColors := colorMap size. |
|
3539 |
1 to:nColors do:[:i | |
|
746 | 3540 |
aColor := colorMap at:i. |
3541 |
aColor notNil ifTrue:[ |
|
3542 |
aColor := aColor on:aDevice. |
|
3543 |
colorMap at:i put:aColor. |
|
3544 |
id := aColor colorId. |
|
3545 |
id notNil ifTrue:[ |
|
3546 |
map at:i put:id |
|
3547 |
] ifFalse:[ |
|
3548 |
map at:i put:0 |
|
3549 |
] |
|
3550 |
] |
|
89 | 3551 |
]. |
283 | 3552 |
|
3553 |
"expand & translate" |
|
3554 |
bytes expandPixels:pictureDepth |
|
746 | 3555 |
width:width |
3556 |
height:height |
|
3557 |
into:wideBits |
|
3558 |
mapping:map. |
|
283 | 3559 |
|
3560 |
f := Form width:width height:height depth:8 on:aDevice. |
|
3561 |
f isNil ifTrue:[^ nil]. |
|
3562 |
f colorMap:colorMap. |
|
3563 |
f initGC. |
|
3564 |
aDevice drawBits:wideBits depth:8 width:width height:height |
|
746 | 3565 |
x:0 y:0 |
3566 |
into:(f id) x:0 y:0 width:width height:height with:(f gcId). |
|
283 | 3567 |
^ f |
746 | 3568 |
|
3569 |
"Modified: 28.5.1996 / 20:55:57 / cg" |
|
0 | 3570 |
! |
3571 |
||
283 | 3572 |
greyImageAsTrueColorFormOn:aDevice |
3573 |
"return a true-color device-form for the grey-image receiver. |
|
3574 |
TODO: the pixel loops ought to be implemented as inline primitive code ..." |
|
3575 |
||
3576 |
|depth |
|
3577 |
myDepth "{ Class: SmallInteger }" |
|
3578 |
nColors "{ Class: SmallInteger }" |
|
3579 |
colorValues |
|
3580 |
scaleDown scaleRed scaleGreen scaleBlue redShift blueShift greenShift |
|
3581 |
form imageBitsdestIndex |
|
3582 |
bestFormat usedDeviceDepth usedDeviceBitsPerPixel imageBits destIndex |
|
3583 |
nPixels| |
|
3584 |
||
3585 |
"/ this is a slow fallback method; this ought to be |
|
3586 |
"/ redefined in DepthxImage for more performance. |
|
3587 |
||
3588 |
depth := aDevice depth. |
|
3589 |
myDepth := self depth. |
|
3590 |
myDepth > 12 ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3591 |
self error:'unsupported trueColor depth in greyImageAsTrueColorFormOn:'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3592 |
^ nil |
0 | 3593 |
]. |
3594 |
||
283 | 3595 |
"/ compute scale to map from my pixels into devices range |
3596 |
||
3597 |
scaleDown := 1 bitShift:myDepth. |
|
3598 |
scaleRed := (1 bitShift:aDevice bitsRed). |
|
3599 |
scaleGreen := (1 bitShift:aDevice bitsGreen). |
|
3600 |
scaleBlue := (1 bitShift:aDevice bitsBlue). |
|
3601 |
redShift := aDevice shiftRed. |
|
3602 |
greenShift := aDevice shiftGreen. |
|
3603 |
blueShift := aDevice shiftBlue. |
|
3604 |
||
3605 |
nColors := (1 bitShift:myDepth). |
|
3606 |
colorValues := Array new:nColors. |
|
3607 |
1 to:nColors do:[:i | |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3608 |
|v gv bv rv nv| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3609 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3610 |
"/ scale down to 0..1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3611 |
v := (i-1) / scaleDown. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3612 |
rv := (v * scaleRed) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3613 |
gv := (v * scaleGreen) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3614 |
bv := (v * scaleBlue) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3615 |
nv := rv bitShift:redShift. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3616 |
nv := nv bitOr:(gv bitShift:greenShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3617 |
nv := nv bitOr:(bv bitShift:blueShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3618 |
colorValues at:i put:nv |
0 | 3619 |
]. |
283 | 3620 |
photometric == #whiteIs0 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3621 |
"/ reverse the order; 0 is brightest |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3622 |
colorValues reverse |
283 | 3623 |
]. |
193 | 3624 |
|
3625 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3626 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3627 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 3628 |
|
283 | 3629 |
"/ for now, only support some depths |
3630 |
||
3631 |
usedDeviceBitsPerPixel == 16 ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3632 |
imageBits := ByteArray uninitializedNew:(width * height * 2). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3633 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3634 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3635 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3636 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3637 |
destIndex := 1. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3638 |
0 to:height-1 do:[:y | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3639 |
0 to:width-1 do:[:x | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3640 |
|greyValue| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3641 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3642 |
greyValue := self valueAtX:x y:y. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3643 |
imageBits wordAt:destIndex put:(colorValues at:greyValue + 1) MSB:true. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3644 |
destIndex := destIndex + 2. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3645 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3646 |
] |
283 | 3647 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3648 |
usedDeviceBitsPerPixel == 32 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3649 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3650 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3651 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3652 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3653 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3654 |
destIndex := 1. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3655 |
0 to:height-1 do:[:y | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3656 |
0 to:width-1 do:[:x | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3657 |
|greyValue| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3658 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3659 |
greyValue := self valueAtX:x y:y. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3660 |
imageBits doubleWordAt:destIndex put:(colorValues at:greyValue + 1) MSB:true. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3661 |
destIndex := destIndex + 4. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3662 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3663 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3664 |
] |
193 | 3665 |
]. |
3666 |
||
283 | 3667 |
imageBits isNil ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3668 |
'IMAGE: unimplemented trueColor depth on greyImageAsTrueColorFormOn:' errorPrintNL. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3669 |
^ self asMonochromeFormOn:aDevice |
283 | 3670 |
]. |
3671 |
||
3672 |
form := |
|
193 | 3673 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
283 | 3674 |
form isNil ifTrue:[^ nil]. |
193 | 3675 |
form initGC. |
3676 |
||
3677 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3678 |
copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3679 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3680 |
x:0 y:0 toX:0 y:0. |
193 | 3681 |
|
3682 |
^ form |
|
3683 |
||
283 | 3684 |
"Created: 20.10.1995 / 22:05:10 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3685 |
"Modified: 10.6.1996 / 19:15:13 / cg" |
0 | 3686 |
! ! |
3687 |
||
3688 |
!Image methodsFor:'converting palette images'! |
|
3689 |
||
3690 |
paletteImageAsFormOn:aDevice |
|
72 | 3691 |
"return a device-form for the palette-image receiver" |
3692 |
||
380 | 3693 |
|type ddepth| |
193 | 3694 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3695 |
ddepth := aDevice depth. |
379 | 3696 |
|
193 | 3697 |
((type := aDevice visualType) == #StaticGray) ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3698 |
ddepth == 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3699 |
^ self paletteImageAsGray8FormOn:aDevice |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3700 |
]. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3701 |
^ self asGrayFormOn:aDevice |
0 | 3702 |
]. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3703 |
|
193 | 3704 |
(type == #TrueColor) ifTrue:[ |
854 | 3705 |
DitherAlgorithm == #floydSteinberg ifTrue:[ |
3706 |
ddepth == 8 ifTrue:[ |
|
3707 |
self depth == 8 ifTrue:[ |
|
3708 |
"/ use fixColor dither algorithm |
|
3709 |
^ self asDitheredTrueColor8FormOn:aDevice |
|
3710 |
] |
|
3711 |
] |
|
3712 |
]. |
|
3713 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3714 |
^ self paletteImageAsTrueColorFormOn:aDevice |
193 | 3715 |
]. |
858 | 3716 |
|
3717 |
"/ the PseudoColor conversion also works for |
|
3718 |
"/ StaticColor, GrayScale & DirectColor; although possibly with suboptimal results |
|
3719 |
||
3720 |
^ self paletteImageAsPseudoFormOn:aDevice |
|
3721 |
||
3722 |
"Modified: 14.6.1996 / 19:31:01 / cg" |
|
0 | 3723 |
! |
3724 |
||
3725 |
paletteImageAsPseudoFormOn:aDevice |
|
72 | 3726 |
"return a pseudo-deviceForm from the palette image." |
0 | 3727 |
|
89 | 3728 |
|tempImage d temp8| |
3729 |
||
3730 |
d := self depth. |
|
3731 |
(#(1 2 4 8) includes:d) ifTrue:[ |
|
3732 |
" |
|
3733 |
fallback code for some depth's: |
|
3734 |
create a temporary Depth8Image and use its conversion method |
|
3735 |
" |
|
3736 |
temp8 := ByteArray uninitializedNew:(width * height). |
|
3737 |
||
3738 |
bytes expandPixels:d |
|
3739 |
width:width |
|
3740 |
height:height |
|
3741 |
into:temp8 |
|
3742 |
mapping:nil. |
|
3743 |
||
3744 |
tempImage := Image width:width height:height depth:8 fromArray:temp8. |
|
3745 |
tempImage colorMap:colorMap. |
|
3746 |
^ tempImage paletteImageAsPseudoFormOn:aDevice |
|
3747 |
]. |
|
2 | 3748 |
^ self subclassResponsibility |
0 | 3749 |
! |
3750 |
||
193 | 3751 |
paletteImageAsTrueColorFormOn:aDevice |
3752 |
"return a true-color device-form for the palette-image receiver." |
|
3753 |
||
209 | 3754 |
|depth |
3755 |
myDepth "{ Class: SmallInteger }" |
|
3756 |
nColors "{ Class: SmallInteger }" |
|
3757 |
colorValues |
|
193 | 3758 |
scaleRed scaleGreen scaleBlue redShift greenShift blueShift |
194 | 3759 |
form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel |
854 | 3760 |
destIndex| |
193 | 3761 |
|
3762 |
"/ this is a slow fallback method; this ought to be |
|
3763 |
"/ redefined in DepthxImage for more performance. |
|
3764 |
||
3765 |
depth := aDevice depth. |
|
3766 |
myDepth := self bitsPerPixel. |
|
3767 |
myDepth > 12 ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3768 |
'IMAGE: depth > 12 not supported' errorPrintNL. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3769 |
^ nil |
193 | 3770 |
]. |
3771 |
||
3772 |
"/ gather r/g/b values for all colors in the map ... |
|
3773 |
||
3774 |
nColors := colorMap size. |
|
3775 |
||
3776 |
"/ precompute scales to map from 0..100 into devices range |
|
3777 |
"/ (this may be different for the individual components) |
|
3778 |
||
3779 |
scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 100. |
|
3780 |
scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 100. |
|
3781 |
scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 100. |
|
3782 |
redShift := aDevice shiftRed. |
|
3783 |
greenShift := aDevice shiftGreen. |
|
3784 |
blueShift := aDevice shiftBlue. |
|
3785 |
||
3786 |
colorValues := Array uninitializedNew:nColors. |
|
3787 |
||
3788 |
1 to:nColors do:[:index | |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3789 |
|clr rv gv bv v "{ Class: SmallInteger }" | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3790 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3791 |
clr := colorMap at:index. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3792 |
clr notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3793 |
rv := (clr red * scaleRed) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3794 |
gv := (clr green * scaleGreen) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3795 |
bv := (clr blue * scaleBlue) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3796 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3797 |
v := rv bitShift:redShift. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3798 |
v := v bitOr:(gv bitShift:greenShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3799 |
v := v bitOr:(bv bitShift:blueShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3800 |
colorValues at:index put:v. |
193 | 3801 |
"/ clr print. ' ' print. |
3802 |
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print. |
|
3803 |
"/ ' -> ' print. v printNL. |
|
3804 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3805 |
] |
193 | 3806 |
]. |
3807 |
||
3808 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3809 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3810 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 3811 |
|
3812 |
"/ for now, only support some depths |
|
3813 |
||
854 | 3814 |
"/ 16 bits/pixel |
3815 |
||
193 | 3816 |
usedDeviceBitsPerPixel == 16 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3817 |
imageBits := ByteArray uninitializedNew:(width * height * 2). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3818 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3819 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3820 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3821 |
|
854 | 3822 |
%{ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3823 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3824 |
&& __isArray(colorValues) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3825 |
&& __isByteArray(_INST(bytes)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3826 |
&& (myDepth == __MKSMALLINT(8)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3827 |
&& __isByteArray(imageBits)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3828 |
int x, y, w, h, nPix; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3829 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3830 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3831 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3832 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3833 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3834 |
w = __intVal(_INST(width)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3835 |
h = __intVal(_INST(height)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3836 |
nPix = w * h; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3837 |
while (nPix > 0) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3838 |
unsigned idx, v; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3839 |
OBJ clr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3840 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3841 |
idx = *srcPtr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3842 |
clr = ap[idx]; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3843 |
v = __intVal(clr); |
193 | 3844 |
#ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3845 |
((short *)dstPtr)[0] = v; |
193 | 3846 |
#else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3847 |
dstPtr[0] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3848 |
dstPtr[1] = (v) & 0xFF; |
193 | 3849 |
#endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3850 |
dstPtr += 2; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3851 |
srcPtr += 1; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3852 |
nPix--; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3853 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3854 |
} |
193 | 3855 |
%}. |
3856 |
] ifFalse:[ |
|
854 | 3857 |
"/ 32 bits/pixel |
3858 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3859 |
usedDeviceBitsPerPixel == 32 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3860 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3861 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3862 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3863 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3864 |
|
854 | 3865 |
%{ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3866 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3867 |
&& __isArray(colorValues) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3868 |
&& __isByteArray(_INST(bytes)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3869 |
&& (myDepth == __MKSMALLINT(8)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3870 |
&& __isByteArray(imageBits)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3871 |
int x, y, w, h, nPix; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3872 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3873 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3874 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3875 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3876 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3877 |
w = __intVal(_INST(width)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3878 |
h = __intVal(_INST(height)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3879 |
nPix = w * h; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3880 |
while (nPix > 0) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3881 |
unsigned idx, v; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3882 |
OBJ clr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3883 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3884 |
idx = *srcPtr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3885 |
clr = ap[idx]; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3886 |
v = __intVal(clr); |
193 | 3887 |
#ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3888 |
((long *)dstPtr)[0] = v; |
193 | 3889 |
#else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3890 |
dstPtr[0] = (v>>24) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3891 |
dstPtr[1] = (v>>16) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3892 |
dstPtr[2] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3893 |
dstPtr[3] = (v) & 0xFF; |
193 | 3894 |
#endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3895 |
dstPtr += 4; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3896 |
srcPtr += 1; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3897 |
nPix--; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3898 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3899 |
} |
193 | 3900 |
%}. |
854 | 3901 |
] ifFalse:[ |
3902 |
"/ 8 bits/pixel |
|
3903 |
||
3904 |
usedDeviceBitsPerPixel == 8 ifTrue:[ |
|
3905 |
imageBits := ByteArray uninitializedNew:(width * height). |
|
3906 |
||
3907 |
"/ now, walk over the image and replace |
|
3908 |
"/ colorMap indices by color values in the bits array |
|
3909 |
||
3910 |
%{ |
|
3911 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
|
3912 |
&& __isArray(colorValues) |
|
3913 |
&& __isByteArray(_INST(bytes)) |
|
3914 |
&& (myDepth == __MKSMALLINT(8)) |
|
3915 |
&& __isByteArray(imageBits)) { |
|
3916 |
int x, y, w, h, nPix; |
|
3917 |
||
3918 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
|
3919 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
|
3920 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
|
3921 |
||
3922 |
w = __intVal(_INST(width)); |
|
3923 |
h = __intVal(_INST(height)); |
|
3924 |
nPix = w * h; |
|
3925 |
while (nPix > 0) { |
|
3926 |
unsigned idx, v; |
|
3927 |
OBJ clr; |
|
3928 |
||
3929 |
idx = *srcPtr; |
|
3930 |
clr = ap[idx]; |
|
3931 |
v = __intVal(clr); |
|
3932 |
||
3933 |
dstPtr[0] = v; |
|
3934 |
||
3935 |
dstPtr += 1; |
|
3936 |
srcPtr += 1; |
|
3937 |
nPix--; |
|
3938 |
} |
|
3939 |
} |
|
3940 |
%}. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3941 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3942 |
] |
193 | 3943 |
]. |
3944 |
||
3945 |
imageBits isNil ifTrue:[ |
|
854 | 3946 |
'IMAGE: unimplemented trueColor depth in paletteImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintNL. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3947 |
^ self asMonochromeFormOn:aDevice |
193 | 3948 |
]. |
3949 |
||
3950 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
|
3951 |
form isNil ifTrue:[^ nil]. |
|
3952 |
form initGC. |
|
3953 |
||
3954 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3955 |
copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3956 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3957 |
x:0 y:0 toX:0 y:0. |
193 | 3958 |
|
3959 |
^ form |
|
3960 |
||
3961 |
"Created: 20.10.1995 / 22:05:10 / cg" |
|
3962 |
"Modified: 21.10.1995 / 19:30:26 / cg" |
|
0 | 3963 |
! ! |
3964 |
||
283 | 3965 |
!Image methodsFor:'converting rgb images'! |
3966 |
||
854 | 3967 |
asDitheredTrueColor8FormOn:aDevice |
3968 |
"convert an rgb image to a dithered depth8-form on aDevice. |
|
3969 |
Return the device-form." |
|
3970 |
||
3971 |
|fixColors pixel |
|
3972 |
dstIdx "{ Class: SmallInteger }" |
|
3973 |
shiftRed "{ Class: SmallInteger }" |
|
3974 |
shiftGreen "{ Class: SmallInteger }" |
|
3975 |
shiftBlue "{ Class: SmallInteger }" |
|
3976 |
nRed "{ Class: SmallInteger }" |
|
3977 |
nGreen "{ Class: SmallInteger }" |
|
3978 |
nBlue "{ Class: SmallInteger }"| |
|
3979 |
||
3980 |
shiftRed := aDevice shiftRed. |
|
3981 |
shiftGreen := aDevice shiftGreen. |
|
3982 |
shiftBlue := aDevice shiftBlue. |
|
3983 |
||
3984 |
nRed := (1 bitShift:aDevice bitsRed). |
|
3985 |
nGreen := (1 bitShift:aDevice bitsGreen). |
|
3986 |
nBlue := (1 bitShift:aDevice bitsBlue). |
|
3987 |
||
3988 |
fixColors := Array new:(nRed * nGreen * nBlue). |
|
3989 |
||
3990 |
dstIdx := 1. |
|
3991 |
0 to:nRed - 1 do:[:sR | |
|
3992 |
0 to:nGreen - 1 do:[:sG | |
|
3993 |
0 to:nBlue - 1 do:[:sB | |
|
3994 |
pixel := (sR bitShift:shiftRed) |
|
3995 |
+ (sG bitShift:shiftGreen) |
|
3996 |
+ (sB bitShift:shiftBlue). |
|
3997 |
fixColors at:dstIdx put:(Color colorId:(pixel)). |
|
3998 |
dstIdx := dstIdx + 1 |
|
3999 |
] |
|
4000 |
] |
|
4001 |
]. |
|
4002 |
||
4003 |
^ self |
|
4004 |
asFloydSteinbergDitheredDepth8FormOn:aDevice |
|
4005 |
colors:fixColors |
|
4006 |
nRed:nRed nGreen:nGreen nBlue:nBlue |
|
4007 |
||
4008 |
"Modified: 14.6.1996 / 17:18:57 / cg" |
|
4009 |
"Created: 14.6.1996 / 17:23:52 / cg" |
|
4010 |
! |
|
4011 |
||
283 | 4012 |
rgbImageAsFormOn:aDevice |
4013 |
"convert am rgb image to a device-form on aDevice. |
|
4014 |
Return the device-form." |
|
4015 |
||
4016 |
|visual| |
|
4017 |
||
4018 |
visual := aDevice visualType. |
|
4019 |
(visual == #StaticGray) ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4020 |
^ self asGrayFormOn:aDevice |
0 | 4021 |
]. |
283 | 4022 |
(visual == #TrueColor) ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4023 |
^ self rgbImageAsTrueColorFormOn:aDevice |
0 | 4024 |
]. |
858 | 4025 |
|
4026 |
"/ PseudoColor conversion also works for StaticColor, GrayScale |
|
4027 |
"/ and DirectColor displays; although possibly with suboptimal results |
|
4028 |
||
283 | 4029 |
^ self rgbImageAsPseudoFormOn:aDevice |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4030 |
|
858 | 4031 |
"Modified: 14.6.1996 / 19:30:06 / cg" |
283 | 4032 |
! |
4033 |
||
4034 |
rgbImageAsPseudoFormOn:aDevice |
|
4035 |
"return a pseudocolor form from the rgb-picture" |
|
4036 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4037 |
|n "{ Class: SmallInteger }" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4038 |
depth "{ Class: SmallInteger }" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4039 |
palette f| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4040 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4041 |
(depth := self depth) <= 8 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4042 |
"/ simulate it via a temporary palette image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4043 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4044 |
palette := Array new:(1 bitShift:depth). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4045 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4046 |
n := (1 bitShift:depth)-1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4047 |
0 to:n do:[:pixelValue | |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4048 |
palette at:(pixelValue+1) put:(self colorFromValue:pixelValue) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4049 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4050 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4051 |
colorMap := palette. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4052 |
photometric := #palette. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4053 |
f := self paletteImageAsPseudoFormOn:aDevice. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4054 |
colorMap := nil. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4055 |
photometric := #rgb. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4056 |
^ f |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4057 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4058 |
|
283 | 4059 |
^ self subclassResponsibility |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4060 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4061 |
"Modified: 8.6.1996 / 10:58:25 / cg" |
283 | 4062 |
! |
4063 |
||
4064 |
rgbImageAsTrueColorFormOn:aDevice |
|
4065 |
"return a truecolor form from the rgb-picture." |
|
4066 |
||
4067 |
|bestFormat usedDeviceDepth usedDeviceBitsPerPixel depth |
|
4068 |
form| |
|
193 | 4069 |
|
4070 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
4071 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
4072 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 4073 |
|
854 | 4074 |
"/ kludge for some 15bit XFree servers (should return 16 here - does not) |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
4075 |
usedDeviceBitsPerPixel == 15 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4076 |
usedDeviceBitsPerPixel := 16 |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
4077 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
4078 |
|
283 | 4079 |
"/ |
4080 |
"/ only the trivial case, where the depths match |
|
4081 |
"/ is handled here; conversions are supposed to |
|
4082 |
"/ be done in concrete subclasses (see D24Image) |
|
4083 |
"/ |
|
4084 |
self bitsPerPixel == usedDeviceBitsPerPixel ifFalse:[ |
|
854 | 4085 |
'IMAGE: unimplemented trueColor depth in rgbImageAsTrueColorFormOn: ' errorPrint. self bitsPerPixel errorPrintNL. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4086 |
^ self asMonochromeFormOn:aDevice |
193 | 4087 |
]. |
4088 |
||
283 | 4089 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
4090 |
form isNil ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4091 |
'IMAGE: display bitmap creation failed' errorPrintNL. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4092 |
^ nil |
193 | 4093 |
]. |
4094 |
form initGC. |
|
4095 |
||
4096 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4097 |
copyBitsFrom:bytes bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4098 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4099 |
x:0 y:0 toX:0 y:0. |
193 | 4100 |
|
4101 |
^ form |
|
4102 |
||
854 | 4103 |
"Modified: 14.6.1996 / 16:57:47 / cg" |
283 | 4104 |
! ! |
4105 |
||
4106 |
!Image methodsFor:'copying'! |
|
4107 |
||
4108 |
postCopy |
|
592 | 4109 |
"redefined to also copy the pixels and the colorMap |
4110 |
and clear out any device handles in the copy." |
|
4111 |
||
283 | 4112 |
bytes := bytes copy. |
916 | 4113 |
colorMap := colorMap copy. |
283 | 4114 |
device := deviceForm := monoDeviceForm := fullColorDeviceForm := nil |
592 | 4115 |
|
916 | 4116 |
"Modified: 5.7.1996 / 13:16:04 / cg" |
283 | 4117 |
! ! |
4118 |
||
4119 |
!Image methodsFor:'displaying'! |
|
4120 |
||
758 | 4121 |
displayFilledOn:aGC |
759 | 4122 |
"display the receiver as an opaque image. |
758 | 4123 |
This allows Images to be wrapped by a FillingWrapper" |
4124 |
||
4125 |
aGC displayOpaqueForm:self x:0 y:0. |
|
4126 |
||
4127 |
"Created: 29.5.1996 / 10:34:18 / cg" |
|
759 | 4128 |
"Modified: 29.5.1996 / 10:52:36 / cg" |
758 | 4129 |
! |
4130 |
||
283 | 4131 |
displayOn:aGC at:aPoint |
592 | 4132 |
"draw the receiver in the graphicsContext, aGC. |
283 | 4133 |
Smalltalk-80 compatibility" |
4134 |
||
672 | 4135 |
self displayOn:aGC x:aPoint x y:aPoint y. |
4136 |
||
4137 |
"Modified: 12.5.1996 / 20:16:38 / cg" |
|
4138 |
! |
|
4139 |
||
4140 |
displayOn:aGC x:x y:y |
|
4141 |
"draw the receiver in the graphicsContext, aGC. |
|
4142 |
Smalltalk-80 compatibility" |
|
4143 |
||
4144 |
aGC displayForm:self x:x y:y. |
|
592 | 4145 |
|
4146 |
"Modified: 23.4.1996 / 11:12:31 / cg" |
|
672 | 4147 |
"Created: 12.5.1996 / 20:14:31 / cg" |
758 | 4148 |
! |
4149 |
||
4150 |
displayStrokedOn:aGC |
|
759 | 4151 |
"display the receiver as an non opaque image. |
758 | 4152 |
This allows Images to be wrapped by a StrokingWrapper" |
4153 |
||
4154 |
aGC displayForm:self x:0 y:0. |
|
4155 |
||
759 | 4156 |
"Created: 29.5.1996 / 10:34:18 / cg" |
4157 |
"Modified: 29.5.1996 / 10:52:30 / cg" |
|
283 | 4158 |
! ! |
4159 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4160 |
!Image methodsFor:'dither helpers'! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4161 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4162 |
burkesDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4163 |
"return the bitmap for a dithered monochrome bitmap from the image. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4164 |
Works for any source depths / photometric" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4165 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4166 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4167 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4168 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4169 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4170 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4171 |
errorArray1 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4172 |
e t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4173 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4174 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4175 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4176 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4177 |
grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4178 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4179 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4180 |
self depth > 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4181 |
^ self floydSteinbergDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4182 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4183 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4184 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4185 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4186 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4187 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4188 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4189 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4190 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4191 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4192 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4193 |
errorArray := Array new:(w+4). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4194 |
errorArray1 := Array new:(w+4) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4195 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4196 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4197 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4198 |
"/ fetch scaled brightness values outside of loop into a table; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4199 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4200 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4201 |
greyValues := self greyMapForRange:(255*1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4202 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4203 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4204 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4205 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4206 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4207 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4208 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4209 |
errorArray := errorArray1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4210 |
errorArray1 := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4211 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4212 |
errorArray1 atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4213 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4214 |
self valuesAtY:y from:0 to:(w-1) do:[:x :pixel | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4215 |
|eP "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4216 |
eD |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4217 |
eI "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4218 |
xE "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4219 |
xN "{Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4220 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4221 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4222 |
grey := greyValues at:(pixel + 1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4223 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4224 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4225 |
xE := x + 2 + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4226 |
grey := (grey + (errorArray at:xE)). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4227 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4228 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4229 |
grey > (127*1024) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4230 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4231 |
e := grey - (255*1024) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4232 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4233 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4234 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4235 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4236 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4237 |
"/ distribute the error: |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4238 |
"/ XX 8 4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4239 |
"/ 2 4 8 4 2 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4240 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4241 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4242 |
eI := e // 32. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4243 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4244 |
eP := eI * 8. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4245 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4246 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4247 |
errorArray at:xN put:(errorArray at:xN) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4248 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4249 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4250 |
errorArray1 at:xE put:(errorArray1 at:xE) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4251 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4252 |
eP := eI * 4. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4253 |
xN := xE + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4254 |
errorArray at:xN put:(errorArray at:xN) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4255 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4256 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4257 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4258 |
errorArray1 at:xN put:(errorArray1 at:xN) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4259 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4260 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4261 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4262 |
errorArray1 at:xN put:(errorArray1 at:xN) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4263 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4264 |
eP := eI * 2. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4265 |
xN := xE - 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4266 |
errorArray1 at:xN put:(errorArray1 at:xN) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4267 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4268 |
eD := eD. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4269 |
xN := xE + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4270 |
errorArray1 at:xN put:(errorArray1 at:xN) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4271 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4272 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4273 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4274 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4275 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4276 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4277 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4278 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4279 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4280 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4281 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4282 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4283 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4284 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4285 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4286 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4287 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4288 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4289 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4290 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4291 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4292 |
"Created: 10.6.1996 / 12:18:20 / cg" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4293 |
"Modified: 10.6.1996 / 13:16:33 / cg" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4294 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4295 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4296 |
floydSteinbergDitheredBitsDepth:depth |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4297 |
"return the bitmap for a dithered depth bitmap from the image. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4298 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4299 |
but very slow since each pixel is processed individually. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4300 |
Redefined by some subclasses for more performance (D8Image)" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4301 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4302 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4303 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4304 |
bytesPerOutRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4305 |
outBits greyValues greyErrors greyPixels greyLevels |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4306 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4307 |
nextErrorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4308 |
e t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4309 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4310 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4311 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4312 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4313 |
grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4314 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4315 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4316 |
depth > 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4317 |
self error:'unimplemented conversion'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4318 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4319 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4320 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4321 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4322 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4323 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4324 |
bytesPerOutRow := ((w * depth) + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4325 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4326 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4327 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4328 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4329 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4330 |
greyLevels := (1 bitShift:depth) - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4331 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4332 |
errorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4333 |
nextErrorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4334 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4335 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4336 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4337 |
dstIndex := 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4338 |
bitCnt := 8. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4339 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4340 |
self depth <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4341 |
"/ fetch scaled brightness values outside of loop into a table; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4342 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4343 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4344 |
greyValues := self greyMapForRange:(greyLevels). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4345 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4346 |
greyPixels := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4347 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4348 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4349 |
v truncated]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4350 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4351 |
greyPixels := ByteArray withAll:greyPixels. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4352 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4353 |
greyErrors := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4354 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4355 |
] ifFalse:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4356 |
((v - v truncated) * 1024) truncated |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4357 |
]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4358 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4359 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4360 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4361 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4362 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4363 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4364 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4365 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4366 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4367 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4368 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4369 |
self valuesAtY:y from:0 to:(w-1) do:[:x :value | |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4370 |
|e "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4371 |
pixel "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4372 |
error "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4373 |
e16 "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4374 |
xE "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4375 |
xN "{ Class: SmallInteger }" | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4376 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4377 |
pixel := greyPixels at:(value + 1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4378 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4379 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4380 |
xE := x + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4381 |
error := (greyErrors at:(value + 1)) + (errorArray at:xE). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4382 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4383 |
byte := byte bitShift:depth. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4384 |
error > 512 "0.5" ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4385 |
pixel := pixel + 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4386 |
e := error - 1024 "1.0" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4387 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4388 |
e := error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4389 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4390 |
byte := byte bitOr:pixel. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4391 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4392 |
e ~= 0 ifTrue:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4393 |
e16 := e // 16. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4394 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4395 |
eR := e16 * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4396 |
eRB := e16 * 1. "/ 1/16 to right below |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4397 |
eB := e16 * 5. "/ 5/16 to below |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4398 |
eLB := e - eR - eRB - eB. "/ 3/16 to left below |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4399 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4400 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4401 |
eR ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4402 |
errorArray at:xN put:(errorArray at:xN) + eR. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4403 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4404 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4405 |
nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4406 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4407 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4408 |
nextErrorArray at:xE put:(nextErrorArray at:xE) + eB. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4409 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4410 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4411 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4412 |
nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4413 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4414 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4415 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4416 |
bitCnt := bitCnt - depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4417 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4418 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4419 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4420 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4421 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4422 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4423 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4424 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4425 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4426 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4427 |
outBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4428 |
bitCnt := 8. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4429 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4430 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4431 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4432 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4433 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4434 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4435 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4436 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4437 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4438 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4439 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4440 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4441 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4442 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4443 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4444 |
self colorsAtY:y from:0 to:(w-1) do:[:x :clr | |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4445 |
|e "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4446 |
pixel "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4447 |
error "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4448 |
e16 "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4449 |
xE "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4450 |
xN "{ Class: SmallInteger }" | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4451 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4452 |
grey := (clr brightness * greyLevels). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4453 |
pixel := grey truncated. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4454 |
error := ((grey - pixel) * 1024) truncated. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4455 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4456 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4457 |
xE := x + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4458 |
error := error + (errorArray at:xE). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4459 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4460 |
byte := byte bitShift:depth. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4461 |
error > 512 "0.5" ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4462 |
pixel := pixel + 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4463 |
e := error - 1024 "1.0" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4464 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4465 |
e := error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4466 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4467 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4468 |
byte := byte bitOr:pixel. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4469 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4470 |
e ~= 0 ifTrue:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4471 |
e16 := e // 16. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4472 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4473 |
eR := e16 * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4474 |
eRB := e16 * 1. "/ 1/16 to right below |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4475 |
eB := e16 * 5. "/ 5/16 to below |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4476 |
eLB := e - eR - eRB - eB. "/ 3/16 to left below |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4477 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4478 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4479 |
eR ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4480 |
errorArray at:xN put:(errorArray at:xN) + eR. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4481 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4482 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4483 |
nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4484 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4485 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4486 |
nextErrorArray at:xE put:(nextErrorArray at:xE) + eB. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4487 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4488 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4489 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4490 |
nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4491 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4492 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4493 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4494 |
bitCnt := bitCnt - depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4495 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4496 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4497 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4498 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4499 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4500 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4501 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4502 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4503 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4504 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4505 |
outBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4506 |
bitCnt := 8. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4507 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4508 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4509 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4510 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4511 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4512 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4513 |
^ outBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4514 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4515 |
"Created: 10.6.1996 / 13:28:22 / cg" |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4516 |
"Modified: 11.6.1996 / 00:13:38 / cg" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4517 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4518 |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4519 |
floydSteinbergDitheredDepth8BitsColors:colors |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4520 |
"return a floyd-steinberg dithered bitmap from the receiver picture, |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4521 |
which must be a depth-8 image. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4522 |
This method expects an array of colors to be used for dithering |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4523 |
(which need not be a colorCubes colors)." |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4524 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4525 |
|pseudoBits |
882 | 4526 |
rgbBytes |
4527 |
ditherRGBBytes ditherColors |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4528 |
w "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4529 |
h "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4530 |
index "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4531 |
fixR "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4532 |
fixG "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4533 |
fixB "{Class: SmallInteger }" |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4534 |
ditherIds failed map lastColor colorsByDistance qScramble |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4535 |
clrLookup lookupPos |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4536 |
error clr| |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4537 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4538 |
self depth ~~ 8 ifTrue:[^ nil]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4539 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4540 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4541 |
"/ collect color components as integer values (for integer arithmetic) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4542 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4543 |
rgbBytes := ByteArray uninitializedNew:256 * 3. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4544 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4545 |
photometric == #palette ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4546 |
lastColor := colorMap size - 1 |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4547 |
] ifFalse:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4548 |
lastColor := 255. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4549 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4550 |
index := 1. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4551 |
0 to:lastColor do:[:pix | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4552 |
clr := self colorFromValue:pix. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4553 |
rgbBytes at:index put:(clr redByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4554 |
rgbBytes at:index+1 put:(clr greenByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4555 |
rgbBytes at:index+2 put:(clr blueByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4556 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4557 |
index := index + 3. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4558 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4559 |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4560 |
"/ collect valid ditherColors ... |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4561 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4562 |
ditherColors := colors select:[:clr | clr notNil]. |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4563 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4564 |
"/ ... and sort by manhatten distance from black |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4565 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4566 |
qScramble := #( |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4567 |
"/ 2rX00X00X00X00 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4568 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4569 |
2r000000000000 "/ 0 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4570 |
2r000000000100 "/ 1 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4571 |
2r000000100000 "/ 2 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4572 |
2r000000100100 "/ 3 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4573 |
2r000100000000 "/ 4 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4574 |
2r000100000100 "/ 5 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4575 |
2r000100100000 "/ 6 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4576 |
2r000100100100 "/ 7 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4577 |
2r100000000000 "/ 8 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4578 |
2r100000000100 "/ 9 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4579 |
2r100000100000 "/ a |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4580 |
2r100000100100 "/ b |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4581 |
2r100100000000 "/ c |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4582 |
2r100100000100 "/ d |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4583 |
2r100100100000 "/ e |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4584 |
2r100100100100 "/ f |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4585 |
). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4586 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4587 |
ditherColors := ditherColors sort:[:a :b | |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4588 |
|cr "{Class: SmallInteger }" |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4589 |
cg "{Class: SmallInteger }" |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4590 |
cb "{Class: SmallInteger }" |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4591 |
i1 "{Class: SmallInteger }" |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4592 |
i2 "{Class: SmallInteger }"| |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4593 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4594 |
cr := a redByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4595 |
cg := a greenByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4596 |
cb := a blueByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4597 |
i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4598 |
i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4599 |
i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4600 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4601 |
cr := b redByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4602 |
cg := b greenByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4603 |
cb := b blueByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4604 |
i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4605 |
i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4606 |
i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4607 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4608 |
i1 < i2 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4609 |
]. |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4610 |
ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4611 |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4612 |
"/ build an index table, for fast lookup from manhatten-r-g-b distance |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4613 |
"/ to the position in the colorList |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4614 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4615 |
clrLookup := ByteArray new:(4096). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4616 |
index := 0. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4617 |
ditherColors keysAndValuesDo:[:clrPosition :clr | |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4618 |
|r g b i| |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4619 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4620 |
r := clr redByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4621 |
g := clr greenByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4622 |
b := clr blueByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4623 |
i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4624 |
i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4625 |
i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4626 |
lookupPos := i. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4627 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4628 |
[index < lookupPos] whileTrue:[ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4629 |
clrLookup at:(index+1) put:(clrPosition-1-1). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4630 |
index := index + 1 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4631 |
] |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4632 |
]. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4633 |
clrLookup from:index+1 to:4096 put:(ditherColors size - 1). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4634 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4635 |
"/ [index <= (4095)] whileTrue:[ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4636 |
"/ clrLookup at:(index+1) put:(ditherColors size - 1). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4637 |
"/ index := index + 1. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4638 |
"/ ]. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4639 |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4640 |
"/ collect ditherColor components |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4641 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4642 |
lastColor := ditherColors size. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4643 |
ditherIds := ByteArray uninitializedNew:lastColor. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4644 |
ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4645 |
index := 1. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4646 |
1 to:lastColor do:[:pix | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4647 |
clr := ditherColors at:pix. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4648 |
ditherRGBBytes at:index put:(clr redByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4649 |
ditherRGBBytes at:index+1 put:(clr greenByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4650 |
ditherRGBBytes at:index+2 put:(clr blueByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4651 |
ditherIds at:pix put:clr colorId. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4652 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4653 |
index := index + 3. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4654 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4655 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4656 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4657 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4658 |
w := width + 2. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4659 |
error := ByteArray uninitializedNew:w*(3*2). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4660 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4661 |
w := width. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4662 |
h := height. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4663 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4664 |
failed := true. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4665 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4666 |
%{ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4667 |
int __x, __y; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4668 |
int __eR, __eG, __eB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4669 |
unsigned char *srcP, *dstP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4670 |
unsigned char *rgbP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4671 |
unsigned char *idP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4672 |
unsigned char *dp; |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4673 |
unsigned char *__clrLookup; |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4674 |
short *errP, *eP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4675 |
int __fR, __fG, __fB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4676 |
int iR, iG, iB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4677 |
int idx; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4678 |
int __w = __intVal(w); |
882 | 4679 |
int __h = __intVal(h); |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4680 |
int __nColors = __intVal(lastColor); |
882 | 4681 |
int __wR = -1, __wG, __wB; |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4682 |
static int __qScramble[16] = { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4683 |
0x000 /* 2r000000000000 0 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4684 |
0x004 /* 2r000000000100 1 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4685 |
0x020 /* 2r000000100000 2 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4686 |
0x024 /* 2r000000100100 3 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4687 |
0x100 /* 2r000100000000 4 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4688 |
0x104 /* 2r000100000100 5 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4689 |
0x120 /* 2r000100100000 6 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4690 |
0x124 /* 2r000100100100 7 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4691 |
0x800 /* 2r100000000000 8 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4692 |
0x804 /* 2r100000000100 9 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4693 |
0x820 /* 2r100000100000 a */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4694 |
0x824 /* 2r100000100100 b */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4695 |
0x900 /* 2r100100000000 c */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4696 |
0x904 /* 2r100100000100 d */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4697 |
0x920 /* 2r100100100000 e */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4698 |
0x924 /* 2r100100100100 f */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4699 |
}; |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4700 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4701 |
if (__isByteArray(__INST(bytes)) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4702 |
&& __isByteArray(pseudoBits) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4703 |
&& __isByteArray(rgbBytes) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4704 |
&& __isByteArray(ditherRGBBytes) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4705 |
&& __isByteArray(ditherIds) |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4706 |
&& __isByteArray(clrLookup) |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4707 |
&& __isByteArray(error)) { |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4708 |
failed = false; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4709 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4710 |
srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4711 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4712 |
rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4713 |
idP = __ByteArrayInstPtr(ditherIds)->ba_element; |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4714 |
__clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element; |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4715 |
errP = (short *) _ByteArrayInstPtr(error)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4716 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4717 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4718 |
* clear error accumulator |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4719 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4720 |
eP = errP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4721 |
bzero(eP, (__w+2) * 2 * 3); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4722 |
|
882 | 4723 |
for (__y=__h; __y>0; __y--) { |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4724 |
__eR = __eG = __eB = 0; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4725 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4726 |
eP = &(errP[3]); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4727 |
__eR = eP[0]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4728 |
__eG = eP[1]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4729 |
__eB = eP[2]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4730 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4731 |
for (__x=__w; __x>0; __x--) { |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4732 |
int __want; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4733 |
int pix; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4734 |
int __wantR, __wantG, __wantB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4735 |
int idx; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4736 |
int tR, tG, tB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4737 |
int nR, nG, nB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4738 |
int dR, dG, dB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4739 |
int minDelta, bestIdx; |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4740 |
int cnt; |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4741 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4742 |
pix = *srcP++; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4743 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4744 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4745 |
* wR, wG and wB is the wanted r/g/b value; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4746 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4747 |
idx = pix+pix+pix; /* pix * 3 */ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4748 |
|
882 | 4749 |
__wantR = rgbP[idx] + __eR; |
4750 |
__wantG = rgbP[idx+1] + __eG; |
|
4751 |
__wantB = rgbP[idx+2] + __eB; |
|
4752 |
||
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4753 |
#define RED_SCALE 30 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4754 |
#define GREEN_SCALE 59 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4755 |
#define BLUE_SCALE 11 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4756 |
#define GOOD_DELTA 30 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4757 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4758 |
#define xRED_SCALE 1 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4759 |
#define xGREEN_SCALE 1 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4760 |
#define xBLUE_SCALE 1 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4761 |
#define xGOOD_DELTA 3 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4762 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4763 |
#define FAST_LOOKUP |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4764 |
/* #define ONE_SHOT */ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4765 |
#define NPROBE 8 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4766 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4767 |
#ifndef FAST_LOOKUP |
882 | 4768 |
if ((__wantR == __wR) |
4769 |
&& (__wantG == __wG) |
|
4770 |
&& (__wantB == __wB)) { |
|
4771 |
/* |
|
4772 |
* same color again - reuse last bestMatch |
|
4773 |
*/ |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4774 |
} else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4775 |
#endif |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4776 |
{ |
882 | 4777 |
__wR = __wantR; |
4778 |
__wG = __wantG; |
|
4779 |
__wB = __wantB; |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4780 |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4781 |
#ifdef FAST_LOOKUP |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4782 |
if(__wR > 255) __wR = 255; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4783 |
else if (__wR < 0) __wR = 0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4784 |
if(__wG > 255) __wG = 255; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4785 |
else if (__wG < 0) __wG = 0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4786 |
if(__wB > 255) __wB = 255; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4787 |
else if (__wB < 0) __wB = 0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4788 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4789 |
{ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4790 |
int lookupIndex; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4791 |
int idx, idx0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4792 |
int d, delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4793 |
unsigned char *dp0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4794 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4795 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4796 |
lookupIndex = __qScramble[((__wR & 0xF0)>>4)]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4797 |
lookupIndex |= __qScramble[((__wG & 0xF0)>>4)] >> 1; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4798 |
lookupIndex |= __qScramble[((__wB & 0xF0)>>4)] >> 2; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4799 |
idx = bestIdx =__clrLookup[lookupIndex]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4800 |
dp += (idx+idx+idx); |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4801 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4802 |
/* try color at lookupIndex */ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4803 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4804 |
d = dp[0]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4805 |
delta = (__wR - d) * RED_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4806 |
if (delta < 0) delta = -delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4807 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4808 |
d = dp[1]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4809 |
if (__wG > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4810 |
delta += (__wG - d) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4811 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4812 |
delta += (d - __wG) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4813 |
d = dp[2]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4814 |
if (__wB > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4815 |
delta += (__wB - d) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4816 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4817 |
delta += (d - __wB) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4818 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4819 |
if (delta <= GOOD_DELTA) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4820 |
goto foundBest; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4821 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4822 |
minDelta = delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4823 |
# ifndef ONE_SHOT |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4824 |
idx0 = idx; dp0 = dp; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4825 |
cnt = 0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4826 |
while ((++cnt <= NPROBE) && (idx > 0)) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4827 |
/* try previous color(s) */ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4828 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4829 |
idx--; dp -= 3; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4830 |
d = dp[0]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4831 |
delta = (__wR - d) * RED_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4832 |
if (delta < 0) delta = -delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4833 |
d = dp[1]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4834 |
if (__wG > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4835 |
delta += (__wG - d) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4836 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4837 |
delta += (d - __wG) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4838 |
d = dp[2]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4839 |
if (__wB > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4840 |
delta += (__wB - d) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4841 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4842 |
delta += (d - __wB) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4843 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4844 |
if (delta < minDelta) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4845 |
bestIdx = idx; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4846 |
if (delta <= GOOD_DELTA) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4847 |
goto foundBest; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4848 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4849 |
minDelta = delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4850 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4851 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4852 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4853 |
idx = idx0; dp = dp0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4854 |
cnt = 0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4855 |
while ((++cnt <= NPROBE) && (++idx < __nColors)) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4856 |
/* try next color */ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4857 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4858 |
dp += 3; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4859 |
d = dp[0]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4860 |
delta = (__wR - d) * RED_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4861 |
if (delta < 0) delta = -delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4862 |
d = dp[1]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4863 |
if (__wG > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4864 |
delta += (__wG - d) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4865 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4866 |
delta += (d - __wG) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4867 |
d = dp[2]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4868 |
if (__wB > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4869 |
delta += (__wB - d) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4870 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4871 |
delta += (d - __wB) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4872 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4873 |
if (delta < minDelta) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4874 |
bestIdx = idx; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4875 |
if (delta <= GOOD_DELTA) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4876 |
goto foundBest; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4877 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4878 |
minDelta = delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4879 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4880 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4881 |
# endif |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4882 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4883 |
foundBest: ; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4884 |
#else |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4885 |
/* |
882 | 4886 |
if(__wR > 255) __wR = 255; |
4887 |
else if (__wR < 0) __wR = 0; |
|
4888 |
if(__wG > 255) __wG = 255; |
|
4889 |
else if (__wG < 0) __wG = 0; |
|
4890 |
if(__wB > 255) __wB = 255; |
|
4891 |
else if (__wB < 0) __wB = 0; |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4892 |
*/ |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4893 |
|
882 | 4894 |
/* find the best matching color */ |
4895 |
||
4896 |
minDelta = 99999; |
|
4897 |
bestIdx = -1; |
|
4898 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
|
4899 |
for (idx = 0; idx<__nColors; idx++) { |
|
4900 |
int d, delta; |
|
4901 |
||
4902 |
d = dp[0]; |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4903 |
delta = (__wR - d) * RED_SCALE; |
882 | 4904 |
if (delta < 0) delta = -delta; |
878 | 4905 |
if (delta < minDelta) { |
882 | 4906 |
d = dp[1]; |
4907 |
if (__wG > d) |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4908 |
delta += (__wG - d) * GREEN_SCALE; |
878 | 4909 |
else |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4910 |
delta += (d - __wG) * GREEN_SCALE; |
878 | 4911 |
if (delta < minDelta) { |
882 | 4912 |
d = dp[2]; |
4913 |
if (__wB > d) |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4914 |
delta += (__wB - d) * BLUE_SCALE; |
882 | 4915 |
else |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4916 |
delta += (d - __wB) * BLUE_SCALE; |
882 | 4917 |
|
4918 |
if (delta < minDelta) { |
|
4919 |
bestIdx = idx; |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4920 |
if (delta <= GOOD_DELTA) { |
882 | 4921 |
break; |
4922 |
} |
|
4923 |
minDelta = delta; |
|
878 | 4924 |
} |
4925 |
} |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4926 |
} |
882 | 4927 |
dp += 3; |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4928 |
} |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4929 |
#endif |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4930 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4931 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4932 |
dp += bestIdx * 3; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4933 |
dR = dp[0]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4934 |
dG = dp[1]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4935 |
dB = dp[2]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4936 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4937 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4938 |
printf("want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n", |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4939 |
__wantR, __wantG, __wantB, |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4940 |
__wR, __wG, __wB, |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4941 |
dR, dG, dB); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4942 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4943 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4944 |
* store the corresponding dither colors colorId |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4945 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4946 |
*dstP++ = idP[bestIdx]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4947 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4948 |
/* |
882 | 4949 |
* the new error & distribute the error |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4950 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4951 |
__eR = __wantR - dR; |
882 | 4952 |
if (__eR) { |
4953 |
tR = __eR >> 4; /* 16th of error */ |
|
4954 |
nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */ |
|
4955 |
eP[0] = tR*5; /* 5/16th for (x / y+1) */ |
|
4956 |
eP[-3] = tR*3; /* 3/16th for (x-1 / y+1) */ |
|
4957 |
eP[3] = __eR - (tR*15); /* 1/16th for (x+1 / y+1) */ |
|
4958 |
__eR = nR; |
|
4959 |
} else { |
|
4960 |
__eR = eP[3]; |
|
4961 |
eP[0] = eP[-3] = eP[3] = 0; |
|
4962 |
} |
|
4963 |
||
4964 |
__eG = __wantG - dG; |
|
4965 |
if (__eG) { |
|
4966 |
tG = __eG >> 4; |
|
4967 |
nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */ |
|
4968 |
eP[1] = tG*5; |
|
4969 |
eP[-2] = tG*3; |
|
4970 |
eP[4] = __eG - (tG*15); |
|
4971 |
__eG = nG; |
|
4972 |
} else { |
|
4973 |
__eG = eP[4]; |
|
4974 |
eP[1] = eP[-2] = eP[4] = 0; |
|
4975 |
} |
|
4976 |
||
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4977 |
__eB = __wantB - dB; |
882 | 4978 |
if (__eB) { |
4979 |
tB = __eB >> 4; |
|
4980 |
nB = eP[5] + (tB * 7); |
|
4981 |
eP[2] = tB*5; |
|
4982 |
eP[-1] = tB*3; |
|
4983 |
eP[5] = __eB - (tB*15); |
|
4984 |
__eB = nB; |
|
4985 |
} else { |
|
4986 |
__eB = eP[5]; |
|
4987 |
eP[2] = eP[-1] = eP[5] = 0; |
|
4988 |
} |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4989 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4990 |
eP += 3; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4991 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4992 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4993 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4994 |
%}. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4995 |
failed ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4996 |
self primitiveFailed. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4997 |
^ nil |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4998 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4999 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5000 |
^ pseudoBits |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5001 |
! |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5002 |
|
854 | 5003 |
floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
858 | 5004 |
"return a floyd-steinberg dithered bitmap from the receiver picture, |
5005 |
which must be a depth-8 image. |
|
5006 |
This is a special-cased dither method for 8-bit palette images being displayed on |
|
5007 |
an 8-bit pseudoColor display, AND fixColor dithering is used. |
|
854 | 5008 |
Use the colors in the fixColors array, which must be fixR x fixG x fixB |
5009 |
colors assigned to aDevice, such as the preallocated colors of the |
|
5010 |
Color class. |
|
5011 |
By passing the ditherColors as extra array, this method can |
|
5012 |
also be used to dither an 8bit image into a smaller number of colors, |
|
5013 |
for example to create dithered Depth4Images from Depth8Images." |
|
5014 |
||
858 | 5015 |
|pseudoBits |
854 | 5016 |
rgbBytes |
5017 |
w "{Class: SmallInteger }" |
|
5018 |
h "{Class: SmallInteger }" |
|
5019 |
index "{Class: SmallInteger }" |
|
5020 |
fixR "{Class: SmallInteger }" |
|
5021 |
fixG "{Class: SmallInteger }" |
|
5022 |
fixB "{Class: SmallInteger }" |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5023 |
fixGfixB |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5024 |
fixIds failed map lastColor |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5025 |
rgbIDX "{Class: SmallInteger }" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5026 |
idxAndErrRBytes idxAndErrGBytes idxAndErrBBytes |
854 | 5027 |
error clr| |
5028 |
||
858 | 5029 |
self depth ~~ 8 ifTrue:[^ nil]. |
5030 |
||
854 | 5031 |
fixR := nRed. |
5032 |
fixR == 0 ifTrue:[ ^ nil]. |
|
5033 |
fixG := nGreen. |
|
5034 |
fixG == 0 ifTrue:[ ^ nil]. |
|
5035 |
fixB := nBlue. |
|
5036 |
fixB == 0 ifTrue:[ ^ nil]. |
|
5037 |
||
5038 |
"/ simple check |
|
5039 |
(fixR * fixG * fixB) ~~ fixColors size ifTrue:[ |
|
5040 |
self error:'invalid color array passed'. |
|
5041 |
^ nil |
|
5042 |
]. |
|
5043 |
fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray. |
|
5044 |
||
5045 |
"/ |
|
5046 |
"/ collect color components as integer values (for integer arithmetic) |
|
5047 |
"/ |
|
5048 |
rgbBytes := ByteArray uninitializedNew:256 * 3. |
|
5049 |
||
5050 |
index := 1. |
|
5051 |
||
5052 |
photometric == #palette ifTrue:[ |
|
5053 |
lastColor := colorMap size - 1 |
|
5054 |
] ifFalse:[ |
|
5055 |
lastColor := 255. |
|
5056 |
]. |
|
5057 |
0 to:lastColor do:[:pix | |
|
5058 |
clr := self colorFromValue:pix. |
|
5059 |
rgbBytes at:index put:(clr redByte). |
|
5060 |
rgbBytes at:index+1 put:(clr greenByte). |
|
5061 |
rgbBytes at:index+2 put:(clr blueByte). |
|
5062 |
||
5063 |
index := index + 3. |
|
5064 |
]. |
|
5065 |
||
5066 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
|
5067 |
||
5068 |
w := width + 2. |
|
5069 |
error := ByteArray uninitializedNew:w*(3*2). |
|
5070 |
||
5071 |
w := width. |
|
5072 |
h := height. |
|
5073 |
||
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5074 |
idxAndErrRBytes := ByteArray uninitializedNew:256*2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5075 |
idxAndErrGBytes := ByteArray uninitializedNew:256*2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5076 |
idxAndErrBBytes := ByteArray uninitializedNew:256*2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5077 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5078 |
fixGfixB := fixG * fixB. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5079 |
index := 1. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5080 |
0 to:255 do:[:i | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5081 |
rgbIDX := (i * (fixR-1) + 128) // 255. "red index rounded" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5082 |
idxAndErrRBytes at:index put:(rgbIDX * fixGfixB). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5083 |
idxAndErrRBytes at:index+1 put:i - (rgbIDX * 255 // (fixR-1)) + 128. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5084 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5085 |
rgbIDX := (i * (fixG-1) + 128) // 255. "green index rounded" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5086 |
idxAndErrGBytes at:index put:(rgbIDX * fixB). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5087 |
idxAndErrGBytes at:index+1 put:i - (rgbIDX * 255 // (fixG-1)) + 128. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5088 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5089 |
rgbIDX := (i * (fixB-1) + 128) // 255. "blue index rounded" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5090 |
idxAndErrBBytes at:index put:(rgbIDX ). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5091 |
idxAndErrBBytes at:index+1 put:i - (rgbIDX * 255 // (fixB-1)) + 128. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5092 |
index := index + 2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5093 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5094 |
|
854 | 5095 |
failed := true. |
5096 |
||
5097 |
%{ |
|
5098 |
int __x, __y; |
|
5099 |
int __eR, __eG, __eB; |
|
5100 |
unsigned char *srcP, *dstP; |
|
5101 |
unsigned char *rgbP; |
|
5102 |
unsigned char *idP; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5103 |
unsigned char *__idxAndErrRBytes, *__idxAndErrGBytes, *__idxAndErrBBytes; |
854 | 5104 |
short *errP, *eP; |
5105 |
int idx; |
|
5106 |
int __w = __intVal(w); |
|
5107 |
||
5108 |
if (__isByteArray(__INST(bytes)) |
|
5109 |
&& __isByteArray(pseudoBits) |
|
5110 |
&& __isByteArray(rgbBytes) |
|
5111 |
&& __isByteArray(fixIds) |
|
5112 |
&& __isByteArray(error) |
|
5113 |
&& __bothSmallInteger(fixR, fixG) |
|
5114 |
&& __isSmallInteger(fixB)) { |
|
5115 |
failed = false; |
|
5116 |
||
5117 |
srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
|
5118 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
|
5119 |
rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element; |
|
5120 |
idP = __ByteArrayInstPtr(fixIds)->ba_element; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5121 |
__idxAndErrRBytes = __ByteArrayInstPtr(idxAndErrRBytes)->ba_element; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5122 |
__idxAndErrGBytes = __ByteArrayInstPtr(idxAndErrGBytes)->ba_element; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5123 |
__idxAndErrBBytes = __ByteArrayInstPtr(idxAndErrBBytes)->ba_element; |
854 | 5124 |
errP = (short *) _ByteArrayInstPtr(error)->ba_element; |
5125 |
||
5126 |
/* |
|
5127 |
* clear error accumulator |
|
5128 |
*/ |
|
5129 |
eP = errP; |
|
5130 |
bzero(eP, (__w+2) * 2 * 3); |
|
5131 |
||
5132 |
for (__y=__intVal(h); __y>0; __y--) { |
|
5133 |
__eR = __eG = __eB = 0; |
|
5134 |
||
5135 |
eP = &(errP[3]); |
|
5136 |
__eR = eP[0]; |
|
5137 |
__eG = eP[1]; |
|
5138 |
__eB = eP[2]; |
|
5139 |
||
5140 |
for (__x=__w; __x>0; __x--) { |
|
5141 |
int __want; |
|
5142 |
int pix; |
|
5143 |
int idx; |
|
5144 |
int tR, tG, tB; |
|
5145 |
int nR, nG, nB; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5146 |
int iRGB; |
854 | 5147 |
|
5148 |
pix = *srcP++; |
|
5149 |
||
5150 |
/* |
|
5151 |
* wR, wG and wB is the wanted r/g/b value; |
|
5152 |
*/ |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5153 |
pix = pix+pix+pix; /* pix * 3 */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5154 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5155 |
/* |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5156 |
* compute indexR/G/B and the new error: |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5157 |
*/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5158 |
__want = rgbP[pix] + __eR; |
854 | 5159 |
if (__want > 255) __want = 255; |
5160 |
else if (__want < 0) __want = 0; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5161 |
__want += __want; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5162 |
idx = __idxAndErrRBytes[__want]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5163 |
__eR = __idxAndErrRBytes[__want+1]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5164 |
__eR -= 128; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5165 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5166 |
__want = rgbP[pix+1] + __eG; |
854 | 5167 |
if (__want > 255) __want = 255; |
5168 |
else if (__want < 0) __want = 0; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5169 |
__want += __want; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5170 |
idx += __idxAndErrGBytes[__want]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5171 |
__eG = __idxAndErrGBytes[__want+1]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5172 |
__eG -= 128; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5173 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5174 |
__want = rgbP[pix+2] + __eB; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5175 |
if (__want > 255) __want = 255; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5176 |
else if (__want < 0) __want = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5177 |
__want += __want; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5178 |
idx += __idxAndErrBBytes[__want]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5179 |
__eB = __idxAndErrBBytes[__want+1]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5180 |
__eB -= 128; |
854 | 5181 |
|
5182 |
/* |
|
5183 |
* store the corresponding dither colors colorId |
|
5184 |
*/ |
|
5185 |
*dstP++ = idP[idx]; |
|
5186 |
||
5187 |
/* |
|
5188 |
* distribute the error |
|
5189 |
*/ |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5190 |
if (__eR) { |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5191 |
tR = __eR >> 4; /* 16th of error */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5192 |
nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5193 |
eP[0] = tR*5; /* 5/16th for (x / y+1) */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5194 |
eP[-3] = tR*3; /* 3/16th for (x-1 / y+1) */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5195 |
eP[3] = __eR - (tR*15); /* 1/16th for (x+1 / y+1) */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5196 |
__eR = nR; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5197 |
} else { |
882 | 5198 |
__eR = eP[3]; |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5199 |
eP[0] = eP[-3] = eP[3] = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5200 |
} |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5201 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5202 |
if (__eG) { |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5203 |
tG = __eG >> 4; /* 16th of error */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5204 |
nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5205 |
eP[1] = tG*5; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5206 |
eP[-2] = tG*3; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5207 |
eP[4] = __eG - (tG*15); |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5208 |
__eG = nG; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5209 |
} else { |
882 | 5210 |
__eG = eP[4]; |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5211 |
eP[1] = eP[-2] = eP[4] = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5212 |
} |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5213 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5214 |
if (__eB) { |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5215 |
tB = __eB >> 4; /* 16th of error */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5216 |
nB = eP[5] + (tB * 7); |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5217 |
eP[2] = tB*5; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5218 |
eP[-1] = tB*3; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5219 |
eP[5] = __eB - (tB*15); |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5220 |
__eB = nB; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5221 |
} else { |
882 | 5222 |
__eB = eP[5]; |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5223 |
eP[2] = eP[-1] = eP[5] = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5224 |
} |
854 | 5225 |
|
5226 |
eP += 3; |
|
5227 |
} |
|
5228 |
} |
|
5229 |
} |
|
5230 |
%}. |
|
5231 |
failed ifTrue:[ |
|
5232 |
self primitiveFailed. |
|
5233 |
^ nil |
|
5234 |
]. |
|
5235 |
||
5236 |
^ pseudoBits |
|
5237 |
||
5238 |
||
5239 |
! |
|
5240 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5241 |
floydSteinbergDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5242 |
"return the bitmap for a dithered monochrome bitmap from the image. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5243 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5244 |
but very very slow since each pixel is processed individually. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5245 |
Redefined by some subclasses for more performance (D8Image)" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5246 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5247 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5248 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5249 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5250 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5251 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5252 |
nextErrorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5253 |
e eD t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5254 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5255 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5256 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5257 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5258 |
grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5259 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5260 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5261 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5262 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5263 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5264 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5265 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5266 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5267 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5268 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5269 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5270 |
errorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5271 |
nextErrorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5272 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5273 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5274 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5275 |
dstIndex := 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5276 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5277 |
byte := 0. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5278 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5279 |
self depth <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5280 |
"/ fetch scaled brightness values outside of loop into a table; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5281 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5282 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5283 |
greyValues := self greyMapForRange:(255 * 1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5284 |
greyValues := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5285 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5286 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5287 |
v rounded |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5288 |
]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5289 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5290 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5291 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5292 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5293 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5294 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5295 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5296 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5297 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5298 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5299 |
self valuesAtY:y from:0 to:(w-1) do:[:x :pixel | |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5300 |
%{ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5301 |
int __grey, __e; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5302 |
int __byte = __intVal(byte); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5303 |
OBJ *__errorArray = __ArrayInstPtr(errorArray)->a_element; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5304 |
OBJ *__nextErrorArray = __ArrayInstPtr(nextErrorArray)->a_element; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5305 |
int __x = __intVal(x); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5306 |
int __eR, __eB, __eRB, __eLB, __eI; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5307 |
int __bitCnt = __intVal(bitCnt); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5308 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5309 |
__grey = __intVal(__ArrayInstPtr(greyValues)->a_element[__intVal(pixel)]); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5310 |
__grey += __intVal(__errorArray[__x+1]); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5311 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5312 |
__byte <<= 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5313 |
if (__grey > 127*1024) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5314 |
__e = __grey - (255*1024); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5315 |
__byte |= 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5316 |
} else { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5317 |
__e = __grey; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5318 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5319 |
if (__e) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5320 |
__eI = __e >> 4; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5321 |
__eR = __eI * 7; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5322 |
__eRB = __eI * 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5323 |
__eB = __eI * 5; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5324 |
__eLB = __e - __eR - __eRB - __eB; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5325 |
__errorArray[__x+2] = __MKSMALLINT(__intVal(__errorArray[__x+2]) + __eR); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5326 |
__nextErrorArray[__x+2] = __MKSMALLINT(__intVal(__nextErrorArray[__x+2]) + __eRB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5327 |
__nextErrorArray[__x+1] = __MKSMALLINT(__intVal(__nextErrorArray[__x+1]) + __eB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5328 |
__nextErrorArray[__x ] = __MKSMALLINT(__intVal(__nextErrorArray[__x ]) + __eLB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5329 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5330 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5331 |
__bitCnt--; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5332 |
if (__bitCnt == 0) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5333 |
int __dstIndex = __intVal(dstIndex); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5334 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5335 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIndex-1] = __byte; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5336 |
dstIndex = __MKSMALLINT(__dstIndex + 1); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5337 |
__byte = 0; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5338 |
__bitCnt = 8; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5339 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5340 |
byte = __MKSMALLINT(__byte); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5341 |
bitCnt = __MKSMALLINT(__bitCnt); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5342 |
%}. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5343 |
|
829 | 5344 |
"/ |eI "{ Class: SmallInteger }" |
5345 |
"/ xE "{ Class: SmallInteger }" |
|
5346 |
"/ xN "{ Class: SmallInteger }" | |
|
5347 |
"/ |
|
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5348 |
"/ "/ get the colors grey value [0 .. 1] |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5349 |
"/ grey := greyValues at:(pixel + 1). |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5350 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5351 |
"/ "/ adjust error |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5352 |
"/ xE := x + 2. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5353 |
"/ grey := (grey + (errorArray at:xE)). |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5354 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5355 |
"/ byte := byte bitShift:1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5356 |
"/ grey > (127*1024) ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5357 |
"/ byte := byte bitOr:1. "/ white |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5358 |
"/ e := grey - (255*1024) |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5359 |
"/ ] ifFalse:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5360 |
"/ e := grey "/ black |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5361 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5362 |
"/ e ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5363 |
"/ eD := e. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5364 |
"/ eI := e // 16. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5365 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5366 |
"/ eR := eI * 7. "/ 7/16 to right |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5367 |
"/ eRB := eI * 1. "/ 1/16 to right below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5368 |
"/ eB := eI * 5. "/ 5/16 to below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5369 |
"/ eLB := eD - eR - eRB - eB. "/ 3/16 to left below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5370 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5371 |
"/ xN := xE + 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5372 |
"/ eR ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5373 |
"/ errorArray at:xN put:(errorArray at:xN) + eR. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5374 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5375 |
"/ eRB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5376 |
"/ nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5377 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5378 |
"/ eB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5379 |
"/ nextErrorArray at:xE put:(nextErrorArray at:xE) + eB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5380 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5381 |
"/ eLB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5382 |
"/ xN := xE - 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5383 |
"/ nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5384 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5385 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5386 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5387 |
"/ bitCnt := bitCnt - 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5388 |
"/ bitCnt == 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5389 |
"/ monoBits at:dstIndex put:byte. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5390 |
"/ dstIndex := dstIndex + 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5391 |
"/ byte := 0. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5392 |
"/ bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5393 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5394 |
0 |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5395 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5396 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5397 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5398 |
monoBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5399 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5400 |
byte := 0. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5401 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5402 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5403 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5404 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5405 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5406 |
'IMAGE: slow floydSteinberg dither ..' infoPrintCR. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5407 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5408 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5409 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5410 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5411 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5412 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5413 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5414 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5415 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5416 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5417 |
self colorsAtY:y from:0 to:(w-1) do:[:x :clr | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5418 |
|eI "{ Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5419 |
xE "{ Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5420 |
xN "{ Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5421 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5422 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5423 |
grey := (clr brightness * 255). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5424 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5425 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5426 |
xE := x + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5427 |
grey := (grey + (errorArray at:xE)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5428 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5429 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5430 |
grey > 127 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5431 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5432 |
e := grey - 255 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5433 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5434 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5435 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5436 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5437 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5438 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5439 |
eI := e // 16. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5440 |
eR := eI * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5441 |
eRB := eI * 1. "/ 1/16 to right below |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5442 |
eB := eI * 5. "/ 5/16 to below |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5443 |
eLB := eD - eR - eRB - eB. "/ 3/16 to left below |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5444 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5445 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5446 |
eR ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5447 |
errorArray at:xN put:(errorArray at:xN) + eR. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5448 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5449 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5450 |
nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5451 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5452 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5453 |
nextErrorArray at:xE put:(nextErrorArray at:xE) + eB. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5454 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5455 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5456 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5457 |
nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5458 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5459 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5460 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5461 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5462 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5463 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5464 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5465 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5466 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5467 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5468 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5469 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5470 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5471 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5472 |
monoBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5473 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5474 |
byte := 0. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5475 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5476 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5477 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5478 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5479 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5480 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5481 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5482 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5483 |
"Created: 8.6.1996 / 16:39:46 / cg" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5484 |
"Modified: 10.6.1996 / 15:12:11 / cg" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5485 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5486 |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5487 |
nearestPaintDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5488 |
"return a nearest paint bitmap from the receiver picture, |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5489 |
which must be a depth-8 image. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5490 |
This is a special-cased dither method for 8-bit palette images being displayed on |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5491 |
an 8-bit pseudoColor display, AND fixColor dithering is used. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5492 |
Use the colors in the fixColors array, which must be fixR x fixG x fixB |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5493 |
colors assigned to aDevice, such as the preallocated colors of the |
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5494 |
Color class." |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5495 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5496 |
|pseudoBits |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5497 |
fixR "{Class: SmallInteger }" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5498 |
fixG "{Class: SmallInteger }" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5499 |
fixB "{Class: SmallInteger }" |
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5500 |
fixGfixB |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5501 |
r "{Class: SmallInteger }" |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5502 |
g "{Class: SmallInteger }" |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5503 |
b "{Class: SmallInteger }" |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5504 |
idx "{Class: SmallInteger }" |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5505 |
idMap lastColor |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5506 |
clr| |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5507 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5508 |
self depth ~~ 8 ifTrue:[^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5509 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5510 |
fixR := nRed. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5511 |
fixR == 0 ifTrue:[ ^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5512 |
fixG := nGreen. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5513 |
fixG == 0 ifTrue:[ ^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5514 |
fixB := nBlue. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5515 |
fixB == 0 ifTrue:[ ^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5516 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5517 |
"/ simple check |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5518 |
(fixR * fixG * fixB) ~~ fixColors size ifTrue:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5519 |
self error:'invalid color array passed'. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5520 |
^ nil |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5521 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5522 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5523 |
"/ |
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5524 |
"/ collect colorIds |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5525 |
"/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5526 |
photometric == #palette ifTrue:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5527 |
lastColor := colorMap size - 1 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5528 |
] ifFalse:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5529 |
lastColor := 255. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5530 |
]. |
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5531 |
fixGfixB := fixG * fixB. |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5532 |
|
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5533 |
idMap := ByteArray uninitializedNew:256. |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5534 |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5535 |
0 to:lastColor do:[:pix | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5536 |
clr := self colorFromValue:pix. |
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5537 |
r := clr redByte. |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5538 |
g := clr greenByte. |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5539 |
b := clr blueByte. |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5540 |
idx := ((r * (fixR-1) + 128) // 255) * fixGfixB. |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5541 |
idx := idx + (((g * (fixG-1) + 128) // 255) * fixB). |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5542 |
idx := idx + ((b * (fixB-1) + 128) // 255). |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5543 |
idMap at:(pix+1) put:(fixColors at:(idx+1)) colorId. |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5544 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5545 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5546 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5547 |
|
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5548 |
"/ translate |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5549 |
|
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5550 |
bytes expandPixels:8 "xlate only" |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5551 |
width:width |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5552 |
height:height |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5553 |
into:pseudoBits |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5554 |
mapping:idMap. |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5555 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5556 |
^ pseudoBits |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5557 |
|
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5558 |
"Modified: 18.6.1996 / 09:18:09 / cg" |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5559 |
! |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5560 |
|
903
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5561 |
nfloydSteinbergDitheredDepth8BitsColors:colors |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5562 |
"return a floyd-steinberg dithered bitmap from the receiver picture, |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5563 |
which must be a depth-8 image. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5564 |
This method expects an array of colors to be used for dithering |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5565 |
(which need not be a colorCubes colors)." |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5566 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5567 |
|pseudoBits |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5568 |
rgbBytes |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5569 |
ditherRGBBytes ditherColors |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5570 |
w "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5571 |
h "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5572 |
index "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5573 |
numR "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5574 |
numG "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5575 |
numB "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5576 |
bitsR "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5577 |
bitsG "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5578 |
bitsB "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5579 |
maxBits "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5580 |
maskR "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5581 |
maskG "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5582 |
maskB "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5583 |
shR "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5584 |
shG "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5585 |
shB "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5586 |
ditherIds failed map lastColor colorsByDistance qScramble |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5587 |
clrLookup lookupPos cube nCube |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5588 |
dR "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5589 |
dG "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5590 |
dB "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5591 |
iR "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5592 |
iRG "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5593 |
iRGB "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5594 |
clr |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5595 |
rI "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5596 |
gI "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5597 |
bI "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5598 |
maxIDX "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5599 |
subCubeColorCollection |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5600 |
error |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5601 |
dl "{Class: SmallInteger }"| |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5602 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5603 |
self depth ~~ 8 ifTrue:[^ nil]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5604 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5605 |
"/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5606 |
"/ collect color components as integer values (for integer arithmetic) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5607 |
"/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5608 |
rgbBytes := ByteArray uninitializedNew:256 * 3. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5609 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5610 |
photometric == #palette ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5611 |
lastColor := colorMap size - 1 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5612 |
] ifFalse:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5613 |
lastColor := 255. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5614 |
]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5615 |
index := 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5616 |
0 to:lastColor do:[:pix | |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5617 |
clr := self colorFromValue:pix. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5618 |
rgbBytes at:index put:(clr redByte). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5619 |
rgbBytes at:index+1 put:(clr greenByte). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5620 |
rgbBytes at:index+2 put:(clr blueByte). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5621 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5622 |
index := index + 3. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5623 |
]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5624 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5625 |
"/ collect valid ditherColors ... |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5626 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5627 |
ditherColors := colors select:[:clr | clr notNil]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5628 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5629 |
"/ collect ditherColor components |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5630 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5631 |
lastColor := ditherColors size. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5632 |
ditherIds := ByteArray uninitializedNew:lastColor. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5633 |
ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5634 |
index := 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5635 |
1 to:lastColor do:[:pix | |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5636 |
clr := ditherColors at:pix. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5637 |
ditherRGBBytes at:index put:(clr redByte). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5638 |
ditherRGBBytes at:index+1 put:(clr greenByte). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5639 |
ditherRGBBytes at:index+2 put:(clr blueByte). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5640 |
ditherIds at:pix put:clr colorId. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5641 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5642 |
index := index + 3. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5643 |
]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5644 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5645 |
"/ place the ditherColor positions into a color cube |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5646 |
bitsR := 5. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5647 |
bitsG := 6. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5648 |
bitsB := 4. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5649 |
maxBits := 6. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5650 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5651 |
"/ bitsR := 4. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5652 |
"/ bitsG := 4. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5653 |
"/ bitsB := 3. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5654 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5655 |
numR := 1 bitShift:bitsR. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5656 |
numG := 1 bitShift:bitsG. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5657 |
numB := 1 bitShift:bitsB. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5658 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5659 |
maskR := (numR-1) bitShift:(bitsG + bitsB). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5660 |
maskG := (numG-1) bitShift:bitsB. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5661 |
maskB := numB-1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5662 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5663 |
shR := -16+bitsR+bitsG+bitsB. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5664 |
shG := -16+bitsG+bitsB. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5665 |
shB := -16+bitsB. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5666 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5667 |
maxIDX := numR*numG*numB. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5668 |
cube := Array new:maxIDX. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5669 |
1 to:lastColor do:[:clrIdx | |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5670 |
clr := ditherColors at:clrIdx. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5671 |
rI := clr scaledRed. rI := (rI bitShift:shR) bitAnd:maskR. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5672 |
gI := clr scaledGreen. gI := (gI bitShift:shG) bitAnd:maskG. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5673 |
bI := clr scaledBlue. bI := (bI bitShift:shB) bitAnd:maskB. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5674 |
index := rI + gI + bI + 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5675 |
subCubeColorCollection := cube at:index. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5676 |
subCubeColorCollection isNil ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5677 |
subCubeColorCollection := OrderedCollection new. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5678 |
cube at:index put:subCubeColorCollection. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5679 |
]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5680 |
subCubeColorCollection add:(clrIdx - 1). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5681 |
]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5682 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5683 |
shR := 1 bitShift:(bitsG+bitsB). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5684 |
shG := 1 bitShift:(bitsB). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5685 |
shB := 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5686 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5687 |
1 to:maxIDX do:[:i | |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5688 |
subCubeColorCollection := cube at:i. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5689 |
subCubeColorCollection notNil ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5690 |
cube at:i put:(subCubeColorCollection asByteArray) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5691 |
] |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5692 |
]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5693 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5694 |
"/ nCube := cube copy. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5695 |
"/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5696 |
"/ cube keysAndValuesDo:[:i :indices | |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5697 |
"/ indices notNil ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5698 |
"/ nCube at:i put:(indices asByteArray) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5699 |
"/ ] ifFalse:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5700 |
"/ "/ find nearest color |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5701 |
"/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5702 |
"/ dl := 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5703 |
"/ [dl < maxBits] whileTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5704 |
"/ dR := dl negated. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5705 |
"/ [dR <= dl] whileTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5706 |
"/ iR := i + (dR * shR). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5707 |
"/ (iR > 0 and:[iR < maxIDX]) ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5708 |
"/ dG := dl negated. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5709 |
"/ [dG < dl] whileTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5710 |
"/ iRG := iR + (dG * shG). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5711 |
"/ (iRG > 0 and:[iRG < maxIDX]) ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5712 |
"/ dB := dl negated. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5713 |
"/ [dB < dl] whileTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5714 |
"/ iRGB := iRG + dB. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5715 |
"/ (iRG > 0 and:[iRG < maxIDX]) ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5716 |
"/ (cube at:iRGB) notNil ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5717 |
"/ nCube at:i put:(cube at:iRGB). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5718 |
"/ dB := dG := dR := dl := 999. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5719 |
"/ ] |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5720 |
"/ ]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5721 |
"/ dB := dB + 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5722 |
"/ ] |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5723 |
"/ ]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5724 |
"/ dG := dG + 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5725 |
"/ ] |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5726 |
"/ ]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5727 |
"/ dR := dR + 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5728 |
"/ ]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5729 |
"/ dl := dl + 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5730 |
"/ ] |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5731 |
"/ ] |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5732 |
"/ ]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5733 |
"/self halt. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5734 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5735 |
"/ now, cube contains collections of colors which are |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5736 |
"/ positioned in a subCube; quickly accessed by a lookup |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5737 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5738 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5739 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5740 |
w := width. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5741 |
h := height. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5742 |
error := ByteArray new:(w+2)*3*2. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5743 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5744 |
%{ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5745 |
#define BITSR 5 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5746 |
#define BITSG 6 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5747 |
#define BITSB 4 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5748 |
#define MAXBITS 6 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5749 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5750 |
#define xBITSR 4 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5751 |
#define xBITSG 4 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5752 |
#define xBITSB 3 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5753 |
#define xMAXBITS 4 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5754 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5755 |
#define NR 32 /* (1<<BITSR) */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5756 |
#define NG 64 /* (1<<BITSG) */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5757 |
#define NB 16 /* (1<<BITSB) */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5758 |
#define MAXRGB 64 /* (1<<MAXBITS) */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5759 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5760 |
#define SHR (BITSG+BITSB) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5761 |
#define SHG BITSB |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5762 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5763 |
#define REMEMBER_SEARCH |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5764 |
#define xNO_FLOYD_STEINBERG |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5765 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5766 |
int __x, __y; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5767 |
int __eR, __eG, __eB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5768 |
unsigned char *srcP, *dstP; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5769 |
unsigned char *rgbP; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5770 |
unsigned char *idP; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5771 |
unsigned char *dp; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5772 |
short *errP, *eP; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5773 |
int __fR, __fG, __fB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5774 |
int idx; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5775 |
int __w = __intVal(w); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5776 |
int __h = __intVal(h); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5777 |
int __nColors = __intVal(lastColor); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5778 |
int __wR = -1, __wG, __wB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5779 |
OBJ *__cube; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5780 |
OBJ subCubeColors; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5781 |
int cubeIndex, cubeIndex2; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5782 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5783 |
if (__isByteArray(__INST(bytes)) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5784 |
&& __isByteArray(pseudoBits) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5785 |
&& __isByteArray(rgbBytes) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5786 |
&& __isByteArray(ditherRGBBytes) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5787 |
&& __isByteArray(ditherIds) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5788 |
&& __isByteArray(error)) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5789 |
failed = false; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5790 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5791 |
srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5792 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5793 |
rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5794 |
idP = __ByteArrayInstPtr(ditherIds)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5795 |
errP = (short *) __ByteArrayInstPtr(error)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5796 |
__cube = __ArrayInstPtr(cube)->a_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5797 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5798 |
eP = errP; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5799 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5800 |
for (__y=__h; __y>0; __y--) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5801 |
eP = &(errP[3]); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5802 |
__eR = eP[0]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5803 |
__eG = eP[1]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5804 |
__eB = eP[2]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5805 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5806 |
for (__x=__w; __x>0; __x--) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5807 |
int __want; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5808 |
int pix; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5809 |
int __wantR, __wantG, __wantB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5810 |
int idx; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5811 |
int tR, tG, tB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5812 |
int nR, nG, nB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5813 |
int __dR, __dG, __dB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5814 |
int minDelta, bestIdx; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5815 |
int __iR, __iG, __iB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5816 |
int cR, cG, cB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5817 |
int delta; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5818 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5819 |
pix = *srcP++; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5820 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5821 |
/* |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5822 |
* wR, wG and wB is the wanted r/g/b value; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5823 |
*/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5824 |
idx = pix+pix+pix; /* pix * 3 */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5825 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5826 |
__wR = __wantR = rgbP[idx] + __eR; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5827 |
__wG = __wantG = rgbP[idx+1] + __eG; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5828 |
__wB = __wantB = rgbP[idx+2] + __eB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5829 |
if(__wR > 255) __wR = 255; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5830 |
else if (__wR < 0) __wR = 0; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5831 |
if(__wG > 255) __wG = 255; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5832 |
else if (__wG < 0) __wG = 0; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5833 |
if(__wB > 255) __wB = 255; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5834 |
else if (__wB < 0) __wB = 0; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5835 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5836 |
__iR = __wR >> (8-BITSR); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5837 |
__iG = __wG >> (8-BITSG); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5838 |
__iB = __wB >> (8-BITSB); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5839 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5840 |
cubeIndex = (__iR<<SHR) + (__iG<<SHG) + __iB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5841 |
subCubeColors = __cube[cubeIndex]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5842 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5843 |
if (subCubeColors == nil) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5844 |
/* search around in spirals, for the first match */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5845 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5846 |
delta = 1; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5847 |
while (delta < MAXRGB) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5848 |
/* check plane above */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5849 |
cR = __iR + delta; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5850 |
if ((unsigned)cR < NR) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5851 |
for (cG=__iG-delta; cG<=__iG+delta; cG++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5852 |
if ((unsigned)cG < NG) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5853 |
for (cB=__iB-delta; cB<=__iB+delta; cB++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5854 |
if ((unsigned)cB < NB) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5855 |
cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5856 |
subCubeColors = __cube[cubeIndex2]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5857 |
if (__isNonNilObject(subCubeColors)) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5858 |
goto found; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5859 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5860 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5861 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5862 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5863 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5864 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5865 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5866 |
/* check plane below */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5867 |
cR = __iR - delta; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5868 |
if ((unsigned)cR < NR) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5869 |
for (cG=__iG-delta; cG<=__iG+delta; cG++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5870 |
if ((unsigned)cG < NG) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5871 |
for (cB=__iB-delta; cB<=__iB+delta; cB++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5872 |
if ((unsigned)cB < NB) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5873 |
cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5874 |
subCubeColors = __cube[cubeIndex2]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5875 |
if (__isNonNilObject(subCubeColors)) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5876 |
goto found; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5877 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5878 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5879 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5880 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5881 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5882 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5883 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5884 |
/* check plane to the right */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5885 |
cG = __iG + delta; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5886 |
if ((unsigned)cG < NG) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5887 |
for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5888 |
if ((unsigned)cR < NR) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5889 |
for (cB=__iB-delta; cB<=__iB+delta; cB++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5890 |
if ((unsigned)cB < NB) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5891 |
cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5892 |
subCubeColors = __cube[cubeIndex2]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5893 |
if (__isNonNilObject(subCubeColors)) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5894 |
goto found; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5895 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5896 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5897 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5898 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5899 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5900 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5901 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5902 |
/* check plane to the left */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5903 |
cG = __iG - delta; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5904 |
if ((unsigned)cG < NG) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5905 |
for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5906 |
if ((unsigned)cR < NR) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5907 |
for (cB=__iB-delta; cB<=__iB+delta; cB++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5908 |
if ((unsigned)cB < NB) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5909 |
cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5910 |
subCubeColors = __cube[cubeIndex2]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5911 |
if (__isNonNilObject(subCubeColors)) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5912 |
goto found; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5913 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5914 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5915 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5916 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5917 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5918 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5919 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5920 |
/* check plane at back */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5921 |
cB = __iB + delta; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5922 |
if ((unsigned)cB < NB) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5923 |
for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5924 |
if ((unsigned)cR < NR) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5925 |
for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5926 |
if ((unsigned)cG < NG) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5927 |
cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5928 |
subCubeColors = __cube[cubeIndex2]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5929 |
if (__isNonNilObject(subCubeColors)) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5930 |
goto found; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5931 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5932 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5933 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5934 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5935 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5936 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5937 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5938 |
/* check plane at front */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5939 |
cB = __iB - delta; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5940 |
if ((unsigned)cB < NB) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5941 |
for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5942 |
if ((unsigned)cR < NR) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5943 |
for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5944 |
if ((unsigned)cG < NG) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5945 |
cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5946 |
subCubeColors = __cube[cubeIndex2]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5947 |
if (__isNonNilObject(subCubeColors)) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5948 |
goto found; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5949 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5950 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5951 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5952 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5953 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5954 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5955 |
delta = delta + 1; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5956 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5957 |
if (InterruptPending) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5958 |
int d_srcP = srcP - __ByteArrayInstPtr(_INST(bytes))->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5959 |
int d_dstP = dstP - __ByteArrayInstPtr(pseudoBits)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5960 |
int d_errP = errP - (short *) __ByteArrayInstPtr(error)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5961 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5962 |
__interrupt__(); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5963 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5964 |
srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element + d_srcP; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5965 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element + d_dstP; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5966 |
rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5967 |
idP = __ByteArrayInstPtr(ditherIds)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5968 |
errP = (short *) __ByteArrayInstPtr(error)->ba_element + d_errP; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5969 |
__cube = __ArrayInstPtr(cube)->a_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5970 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5971 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5972 |
/* cannot happen - will lead to a segmentation violation ... */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5973 |
subCubeColors = nil; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5974 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5975 |
found: |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5976 |
__iR = cR; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5977 |
__iG = cG; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5978 |
__iB = cB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5979 |
bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5980 |
#ifdef REMEMBER_SEARCH |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5981 |
__cube[cubeIndex] = __MKSMALLINT(bestIdx); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5982 |
#endif |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5983 |
} else { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5984 |
#ifdef REMEMBER_SEARCH |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5985 |
if (__isSmallInteger(subCubeColors)) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5986 |
bestIdx = __intVal(subCubeColors); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5987 |
} else |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5988 |
#endif |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5989 |
{ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5990 |
bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5991 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5992 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5993 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5994 |
/* |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5995 |
* ok, now, we have found a collection of nearby |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5996 |
* colors in subCubeColors. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5997 |
* |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5998 |
* since the error is at most 1/16 (i.e. roughly 6%), |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
5999 |
* dont care for searching the best - simply take the |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6000 |
* first color found there. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6001 |
* (statistic reduces the error to even a smaller value). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6002 |
* There is no real problem due to that error, since |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6003 |
* it will be diffused anyway ... |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6004 |
*/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6005 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6006 |
#ifndef NO_FLOYD_STEINBERG |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6007 |
/* |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6008 |
* fetch that colors r/g/b components |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6009 |
*/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6010 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6011 |
dp += bestIdx * 3; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6012 |
__dR = dp[0]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6013 |
__dG = dp[1]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6014 |
__dB = dp[2]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6015 |
#endif |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6016 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6017 |
/* |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6018 |
printf("want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n", |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6019 |
__wantR, __wantG, __wantB, |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6020 |
__wR, __wG, __wB, |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6021 |
__dR, __dG, __dB); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6022 |
*/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6023 |
/* |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6024 |
* store the corresponding dither colors colorId |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6025 |
*/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6026 |
*dstP++ = idP[bestIdx]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6027 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6028 |
#ifndef NO_FLOYD_STEINBERG |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6029 |
/* |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6030 |
* the new error & distribute the error |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6031 |
*/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6032 |
__eR = __wantR - __dR; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6033 |
if (__eR) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6034 |
tR = __eR >> 4; /* 16th of error */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6035 |
nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6036 |
eP[0] = tR*5; /* 5/16th for (x / y+1) */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6037 |
eP[-3] = tR*3; /* 3/16th for (x-1 / y+1) */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6038 |
eP[3] = __eR - (tR*15); /* 1/16th for (x+1 / y+1) */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6039 |
__eR = nR; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6040 |
} else { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6041 |
__eR = eP[3]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6042 |
eP[0] = eP[-3] = eP[3] = 0; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6043 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6044 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6045 |
__eG = __wantG - __dG; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6046 |
if (__eG) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6047 |
tG = __eG >> 4; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6048 |
nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6049 |
eP[1] = tG*5; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6050 |
eP[-2] = tG*3; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6051 |
eP[4] = __eG - (tG*15); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6052 |
__eG = nG; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6053 |
} else { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6054 |
__eG = eP[4]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6055 |
eP[1] = eP[-2] = eP[4] = 0; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6056 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6057 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6058 |
__eB = __wantB - __dB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6059 |
if (__eB) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6060 |
tB = __eB >> 4; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6061 |
nB = eP[5] + (tB * 7); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6062 |
eP[2] = tB*5; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6063 |
eP[-1] = tB*3; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6064 |
eP[5] = __eB - (tB*15); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6065 |
__eB = nB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6066 |
} else { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6067 |
__eB = eP[5]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6068 |
eP[2] = eP[-1] = eP[5] = 0; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6069 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6070 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6071 |
eP += 3; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6072 |
#endif |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6073 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6074 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6075 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6076 |
%}. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6077 |
failed ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6078 |
self primitiveFailed. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6079 |
^ nil |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6080 |
]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6081 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6082 |
^ pseudoBits |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6083 |
! |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6084 |
|
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6085 |
orderedDitheredBitsDepth:depth |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6086 |
"return the bitmap for a dithered depth-bitmap from the image" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6087 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6088 |
^ self |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6089 |
orderedDitheredBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6090 |
ditherWidth:8 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6091 |
depth:depth. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6092 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6093 |
"Created: 15.6.1996 / 09:18:04 / cg" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6094 |
! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6095 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6096 |
orderedDitheredBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6097 |
"return the bitmap for a dithered depth-bitmap from the image; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6098 |
with a constant ditherMatrix, this can be used for thresholding. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6099 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6100 |
but very very slow since each pixel is processed individually. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6101 |
Redefined by some subclasses for more performance (D8Image)" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6102 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6103 |
|f last dH nDither |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6104 |
greyLevels greyValues greyPixels greyErrors |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6105 |
dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6106 |
nextDst |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6107 |
bytesPerOutRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6108 |
pixelsPerByte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6109 |
outBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6110 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6111 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6112 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6113 |
byte "{Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6114 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6115 |
depth > 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6116 |
'IMAGE: unimplemented orderedDither conversion' errorPrintCR. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6117 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6118 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6119 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6120 |
nDither := ditherMatrix size. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6121 |
dH := nDither / dW. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6122 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6123 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6124 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6125 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6126 |
greyLevels := 1 bitShift:depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6127 |
pixelsPerByte := 8 / depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6128 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6129 |
bytesPerOutRow := (w * depth + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6130 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6131 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6132 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6133 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6134 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6135 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6136 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6137 |
self bitsPerPixel <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6138 |
"/ fetch scaled brightness values outside of loop into a table; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6139 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6140 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6141 |
greyValues := self greyMapForRange:(greyLevels-1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6142 |
greyPixels := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6143 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6144 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6145 |
v truncated]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6146 |
greyPixels := ByteArray withAll:greyPixels. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6147 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6148 |
greyErrors := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6149 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6150 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6151 |
((v - v truncated) * nDither) rounded |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6152 |
]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6153 |
greyErrors := ByteArray withAll:greyErrors. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6154 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6155 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6156 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6157 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6158 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6159 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6160 |
self valuesAtY:y from:0 to:(w-1) do:[:x :value | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6161 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6162 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6163 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6164 |
int __value = __intVal(value); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6165 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6166 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6167 |
int __pixel, __grey; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6168 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6169 |
unsigned char *__greyPixels = __ByteArrayInstPtr(greyPixels)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6170 |
unsigned char *__greyErrors = __ByteArrayInstPtr(greyErrors)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6171 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6172 |
__pixel = __greyPixels[__value]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6173 |
__grey = __greyErrors[__value]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6174 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6175 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6176 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6177 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6178 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6179 |
if (__grey > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6180 |
__pixel++; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6181 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6182 |
__byte = (__byte << __intVal(depth)) | __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6183 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6184 |
__bitCnt = __bitCnt - __intVal(depth); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6185 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6186 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6187 |
__ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6188 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6189 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6190 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6191 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6192 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6193 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6194 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6195 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6196 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6197 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6198 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6199 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6200 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6201 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6202 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6203 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6204 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6205 |
] ifFalse:[ |
916 | 6206 |
'IMAGE: slow ordered dither ..' infoPrintCR. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6207 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6208 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6209 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6210 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6211 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6212 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6213 |
"/ this is the representaion independent (but slow) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6214 |
"/ inner loop - it extracts colors from the receiver |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6215 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6216 |
self colorsAtY:y from:0 to:(w-1) do:[:x :clr | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6217 |
|dstClr grey dT pixel| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6218 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6219 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6220 |
grey := clr brightness. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6221 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6222 |
"/ remap into [0 .. greyLevels-1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6223 |
grey := grey * (greyLevels-1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6224 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6225 |
"/ get threshold pixel [0 .. greyLevels-1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6226 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6227 |
pixel := grey truncated. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6228 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6229 |
"/ compute the error [0..1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6230 |
grey := grey - pixel. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6231 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6232 |
"/ map into dither space [0 .. nDither] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6233 |
grey := (grey * (nDither)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6234 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6235 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6236 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6237 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6238 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6239 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6240 |
int __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6241 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6242 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6243 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6244 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6245 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6246 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6247 |
__pixel = __intVal(pixel); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6248 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6249 |
if (__intVal(grey) > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6250 |
__pixel++; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6251 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6252 |
__byte = (__byte << __intVal(depth)) | __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6253 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6254 |
__bitCnt = __bitCnt - __intVal(depth); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6255 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6256 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6257 |
__ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6258 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6259 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6260 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6261 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6262 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6263 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6264 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6265 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6266 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6267 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6268 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6269 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6270 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6271 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6272 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6273 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6274 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6275 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6276 |
^ outBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6277 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6278 |
|
831 | 6279 |
orderedDitheredMonochromeBits |
6280 |
"return the bitmap for a dithered monochrome bitmap from the image; |
|
6281 |
using a default ditherMatrix." |
|
6282 |
||
6283 |
^ self |
|
6284 |
orderedDitheredMonochromeBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
6285 |
ditherWidth:8 |
|
6286 |
||
6287 |
"Created: 11.6.1996 / 16:48:57 / cg" |
|
6288 |
! |
|
6289 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6290 |
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6291 |
"return the bitmap for a dithered monochrome bitmap from the image; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6292 |
with a constant ditherMatrix, this can be used for thresholding. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6293 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6294 |
but very very slow since each pixel is processed individually. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6295 |
Redefined by some subclasses for more performance (D8Image)" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6296 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6297 |
|f last dH nDither |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6298 |
greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6299 |
dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6300 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6301 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6302 |
monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6303 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6304 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6305 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6306 |
byte "{Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6307 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6308 |
nDither := ditherMatrix size. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6309 |
dH := nDither / dW. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6310 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6311 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6312 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6313 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6314 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6315 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6316 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6317 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6318 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6319 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6320 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6321 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6322 |
self bitsPerPixel <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6323 |
"/ fetch scaled brightness values outside of loop into a table; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6324 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6325 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6326 |
greyValues := self greyByteMapForRange:nDither. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6327 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6328 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6329 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6330 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6331 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6332 |
self valuesAtY:y from:0 to:(w-1) do:[:x :value | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6333 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6334 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6335 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6336 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6337 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6338 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6339 |
int __grey; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6340 |
unsigned char *__greyValues = __ByteArrayInstPtr(greyValues)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6341 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6342 |
__grey = __greyValues[__intVal(value)]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6343 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6344 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6345 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6346 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6347 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6348 |
__byte = __byte << 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6349 |
if (__grey > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6350 |
__byte = __byte | 1; /* white */ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6351 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6352 |
__bitCnt = __bitCnt - 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6353 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6354 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6355 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6356 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6357 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6358 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6359 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6360 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6361 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6362 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6363 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6364 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6365 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6366 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6367 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6368 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6369 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6370 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6371 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6372 |
] ifFalse:[ |
916 | 6373 |
'IMAGE: slow ordered dither ..' infoPrintCR. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6374 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6375 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6376 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6377 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6378 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6379 |
self colorsAtY:y from:0 to:(w-1) do:[:x :clr | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6380 |
|dstClr grey dT| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6381 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6382 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6383 |
grey := clr brightness. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6384 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6385 |
"/ map into dither space [0 .. nDither] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6386 |
grey := (grey * (nDither)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6387 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6388 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6389 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6390 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6391 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6392 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6393 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6394 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6395 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6396 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6397 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6398 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6399 |
__byte = __byte << 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6400 |
if (__intVal(grey) > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6401 |
__byte = __byte | 1; /* white */ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6402 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6403 |
__bitCnt = __bitCnt - 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6404 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6405 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6406 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6407 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6408 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6409 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6410 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6411 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6412 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6413 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6414 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6415 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6416 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6417 |
"/ dT := ditherMatrix at:(x \\ dW) + (y \\ dH * dW) + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6418 |
"/ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6419 |
"/ byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6420 |
"/ grey < dT ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6421 |
"/ byte := byte bitOr:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6422 |
"/ ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6423 |
"/ bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6424 |
"/ bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6425 |
"/ monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6426 |
"/ dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6427 |
"/ byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6428 |
"/ bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6429 |
"/ ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6430 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6431 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6432 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6433 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6434 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6435 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6436 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6437 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6438 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6439 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6440 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6441 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6442 |
stevensonArceDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6443 |
"return the bitmap for a dithered monochrome bitmap from the image. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6444 |
Works for any source depths / photometric" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6445 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6446 |
|f last |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6447 |
dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6448 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6449 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6450 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6451 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6452 |
errorArray1 errorArray2 errorArray3 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6453 |
e t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6454 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6455 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6456 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6457 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6458 |
direction "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6459 |
dstClr grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6460 |
xE "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6461 |
xN "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6462 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6463 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6464 |
self depth > 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6465 |
^ self floydSteinbergDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6466 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6467 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6468 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6469 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6470 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6471 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6472 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6473 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6474 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6475 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6476 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6477 |
errorArray := Array new:(w+6). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6478 |
errorArray1 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6479 |
errorArray2 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6480 |
errorArray3 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6481 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6482 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6483 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6484 |
"/ fetch scaled brightness values outside of loop into a table; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6485 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6486 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6487 |
greyValues := self greyMapForRange:(255 * 1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6488 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6489 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6490 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6491 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6492 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6493 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6494 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6495 |
errorArray := errorArray1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6496 |
errorArray1 := errorArray2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6497 |
errorArray2 := errorArray3. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6498 |
errorArray3 := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6499 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6500 |
errorArray3 atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6501 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6502 |
self valuesAtY:y from:0 to:(w-1) do:[:x :pixel | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6503 |
|eP eD| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6504 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6505 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6506 |
grey := greyValues at:(pixel + 1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6507 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6508 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6509 |
xE := x + 3 + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6510 |
grey := (grey + (errorArray at:xE)). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6511 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6512 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6513 |
grey > (127 * 1024) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6514 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6515 |
e := grey - (255 * 1024) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6516 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6517 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6518 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6519 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6520 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6521 |
"/ distribute the error: |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6522 |
"/ XX 32 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6523 |
"/ 12 26 30 16 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6524 |
"/ 12 26 12 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6525 |
"/ 5 12 12 5 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6526 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6527 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6528 |
e := e // 200. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6529 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6530 |
eP := e * 32. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6531 |
errorArray at:xE+2 put:(errorArray at:xE+2) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6532 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6533 |
eP := e * 30. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6534 |
errorArray1 at:xE+1 put:(errorArray1 at:xE+1) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6535 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6536 |
eP := e * 16. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6537 |
errorArray1 at:xE+3 put:(errorArray1 at:xE+3) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6538 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6539 |
eP := e * 26. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6540 |
errorArray1 at:xE-1 put:(errorArray1 at:xE-1) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6541 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6542 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6543 |
errorArray2 at:xE put:(errorArray2 at:xE) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6544 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6545 |
eP := e * 12. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6546 |
errorArray1 at:xE-3 put:(errorArray1 at:xE-3) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6547 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6548 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6549 |
errorArray2 at:xE-2 put:(errorArray2 at:xE-2) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6550 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6551 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6552 |
errorArray2 at:xE+2 put:(errorArray2 at:xE+2) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6553 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6554 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6555 |
errorArray3 at:xE-1 put:(errorArray3 at:xE-1) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6556 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6557 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6558 |
errorArray3 at:xE+1 put:(errorArray3 at:xE+1) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6559 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6560 |
eP := e * 5. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6561 |
errorArray3 at:xE-3 put:(errorArray3 at:xE-3) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6562 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6563 |
eP := eD. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6564 |
errorArray3 at:xE+3 put:(errorArray3 at:xE+3) + eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6565 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6566 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6567 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6568 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6569 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6570 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6571 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6572 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6573 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6574 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6575 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6576 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6577 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6578 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6579 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6580 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6581 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6582 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6583 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6584 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6585 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6586 |
"Created: 10.6.1996 / 12:38:35 / cg" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6587 |
"Modified: 10.6.1996 / 12:52:20 / cg" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6588 |
! ! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6589 |
|
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6590 |
!Image methodsFor:'drawing'! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6591 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6592 |
fillRectangleX:x y:y width:w height:h with:aColor |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6593 |
|pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6594 |
xI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6595 |
yI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6596 |
wI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6597 |
hI "{ Class: SmallInteger }"| |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6598 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6599 |
pixel := self valueFromColor:aColor. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6600 |
xI := x. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6601 |
yI := y. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6602 |
wI := w. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6603 |
hI := h. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6604 |
yI to:yI+hI-1 do:[:yRun | |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6605 |
xI to:xI+wI-1 do:[:xRun | |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6606 |
self atX:xRun y:yRun putValue:pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6607 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6608 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6609 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6610 |
"Created: 15.6.1996 / 08:41:25 / cg" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6611 |
"Modified: 15.6.1996 / 10:08:15 / cg" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6612 |
! ! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6613 |
|
283 | 6614 |
!Image methodsFor:'enumerating'! |
6615 |
||
6616 |
atY:y from:x1 to:x2 do:aBlock |
|
6617 |
"perform aBlock for each pixel from x1 to x2 in row y. |
|
6618 |
The block is passed the color at each pixel. |
|
6619 |
The code here provides a generic and slow implementation, and |
|
6620 |
should be redefined in concrete subclasses, to avoid some processing |
|
6621 |
when going from pixel to pixel (i.e. the byte-index and mask computations |
|
6622 |
and also the color allocation)." |
|
6623 |
||
798 | 6624 |
self obsoleteMethodWarning:'use #colorsAtY:from:to:do:'. |
6625 |
self colorsAtY:y from:x1 to:x2 do:aBlock |
|
6626 |
||
6627 |
"Modified: 7.6.1996 / 19:13:30 / cg" |
|
6628 |
! |
|
6629 |
||
6630 |
colorsAtY:y from:x1 to:x2 do:aBlock |
|
6631 |
"perform aBlock for each pixel from x1 to x2 in row y. |
|
6632 |
The block is passed the color at each pixel. |
|
6633 |
The code here provides a generic and slow implementation, and |
|
6634 |
should be redefined in concrete subclasses, to avoid some processing |
|
6635 |
when going from pixel to pixel (i.e. the byte-index and mask computations |
|
6636 |
and also the color allocation)." |
|
6637 |
||
283 | 6638 |
|xStart "{Class: SmallInteger }" |
6639 |
xEnd "{Class: SmallInteger }"| |
|
6640 |
||
6641 |
xStart := x1. |
|
6642 |
xEnd := x2. |
|
6643 |
xStart to:xEnd do:[:xRun | |
|
798 | 6644 |
aBlock value:xRun value:(self atX:xRun y:y) |
283 | 6645 |
] |
798 | 6646 |
|
6647 |
"Created: 7.6.1996 / 19:12:51 / cg" |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6648 |
"Modified: 10.6.1996 / 10:27:29 / cg" |
283 | 6649 |
! |
6650 |
||
6651 |
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock |
|
6652 |
"perform aBlock for each color in a rectangular area of the image. |
|
6653 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
|
6654 |
The block is passed the x and y coordinates and pixelValue at each pixel. |
|
6655 |
The code here provides a generic and slow implementation, and |
|
6656 |
should be redefined in concrete subclasses, to avoid some processing |
|
6657 |
when going from pixel to pixel (i.e. the byte-index and mask computations, |
|
6658 |
and especially, the color allocations)." |
|
6659 |
||
940 | 6660 |
|yS "{Class: SmallInteger }" |
942 | 6661 |
yE "{Class: SmallInteger }" |
6662 |
yR| |
|
6663 |
||
6664 |
yS := yStart. |
|
6665 |
yE := yEnd. |
|
940 | 6666 |
|
6667 |
yS to:yE do:[:yRun | |
|
942 | 6668 |
yR := yRun. |
798 | 6669 |
self colorsAtY:yRun from:xStart to:xEnd do:[:xRun :color | |
942 | 6670 |
aBlock value:xRun value:yR value:color |
798 | 6671 |
] |
283 | 6672 |
] |
798 | 6673 |
|
940 | 6674 |
"Modified: 11.7.1996 / 19:50:47 / cg" |
283 | 6675 |
! |
6676 |
||
6677 |
valueAtY:y from:x1 to:x2 do:aBlock |
|
6678 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
|
798 | 6679 |
Obsolete - remains for backward compatibility." |
6680 |
||
6681 |
self obsoleteMethodWarning:'use #valuesAtY:from:to:do:'. |
|
6682 |
self valuesAtY:y from:x1 to:x2 do:aBlock |
|
6683 |
||
6684 |
"Modified: 7.6.1996 / 19:11:06 / cg" |
|
6685 |
! |
|
6686 |
||
6687 |
valuesAtY:y from:x1 to:x2 do:aBlock |
|
6688 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
|
283 | 6689 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
6690 |
The block is passed the x coordinate and the pixelValue at each pixel. |
|
6691 |
(see also Image>>atY:from:to:do:). |
|
6692 |
The code here provides a generic and slow implementation, and |
|
6693 |
should be redefined in concrete subclasses, to avoid some processing |
|
6694 |
when going from pixel to pixel (i.e. the byte-index and mask computations)." |
|
6695 |
||
6696 |
|xStart "{Class: SmallInteger }" |
|
6697 |
xEnd "{Class: SmallInteger }"| |
|
6698 |
||
6699 |
xStart := x1. |
|
6700 |
xEnd := x2. |
|
6701 |
xStart to:xEnd do:[:xRun | |
|
692 | 6702 |
aBlock value:xRun value:(self valueAtX:xRun y:y) |
283 | 6703 |
] |
692 | 6704 |
|
6705 |
"Modified: 17.5.1996 / 12:03:59 / cg" |
|
798 | 6706 |
"Created: 7.6.1996 / 19:09:51 / cg" |
283 | 6707 |
! |
6708 |
||
6709 |
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock |
|
6710 |
"perform aBlock for each pixelValue in a rectangular area of the image. |
|
6711 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
|
6712 |
The block is passed the x and y coordinates and pixelValue at each pixel. |
|
6713 |
The code here provides a generic and slow implementation, and |
|
6714 |
should be redefined in concrete subclasses, to avoid some processing |
|
6715 |
when going from pixel to pixel (i.e. the byte-index and mask computations)." |
|
6716 |
||
6717 |
|xS "{Class: SmallInteger }" |
|
6718 |
xE "{Class: SmallInteger }"| |
|
6719 |
||
6720 |
xS := xStart. |
|
6721 |
xE := xEnd. |
|
6722 |
yStart to:yEnd do:[:yRun | |
|
798 | 6723 |
self valuesAtY:yRun from:xStart to:xEnd do:[:xRun :pixel | |
6724 |
aBlock value:xRun value:yRun value:pixel |
|
6725 |
] |
|
283 | 6726 |
] |
798 | 6727 |
|
6728 |
"Modified: 7.6.1996 / 19:09:29 / cg" |
|
0 | 6729 |
! ! |
6730 |
||
6731 |
!Image methodsFor:'image manipulations'! |
|
6732 |
||
283 | 6733 |
colorMapProcessing:aBlock |
6734 |
"a helper for all kinds of colormap manipulations. |
|
592 | 6735 |
The argument, aBlock is called for every colormap entry, |
6736 |
and the returned value will replace the original entry in the map. |
|
283 | 6737 |
This will fail for non-palette images. |
592 | 6738 |
See examples in Image>>copyWithColorMapProcessing:" |
283 | 6739 |
|
6740 |
|nColors "{ Class: SmallInteger }"| |
|
6741 |
||
6742 |
colorMap isNil ifTrue:[ |
|
592 | 6743 |
^ self error:'image has no colormap' |
283 | 6744 |
]. |
6745 |
||
6746 |
nColors := colorMap size. |
|
6747 |
1 to:nColors do:[:index | |
|
592 | 6748 |
|clr| |
6749 |
||
6750 |
clr := colorMap at:index. |
|
6751 |
clr notNil ifTrue:[ |
|
6752 |
colorMap at:index put:(aBlock value:clr) |
|
6753 |
] |
|
283 | 6754 |
] |
592 | 6755 |
|
6756 |
"Modified: 23.4.1996 / 11:13:55 / cg" |
|
283 | 6757 |
! |
6758 |
||
89 | 6759 |
copyWithColorMapProcessing:aBlock |
81 | 6760 |
"a helper to create & return new images based on the receiver with |
89 | 6761 |
some colorMap processing. The receiver is copied, and the copied images |
6762 |
colormap is modified by replacing entries with the result of the processing block, |
|
6763 |
which is called with the original color values. The block is supposed to return |
|
6764 |
a color." |
|
81 | 6765 |
|
6766 |
|newImage| |
|
6767 |
||
6768 |
newImage := self copy. |
|
6769 |
newImage colorMap isNil ifTrue:[ |
|
6770 |
self error:'no colormap in image'. |
|
6771 |
^ nil |
|
6772 |
]. |
|
6773 |
||
6774 |
" |
|
6775 |
the code below manipulates the colormap. |
|
6776 |
For non-palette images, special code is required |
|
6777 |
" |
|
89 | 6778 |
newImage colorMapProcessing:aBlock. |
81 | 6779 |
^ newImage |
6780 |
||
6781 |
" |
|
6782 |
leave red component only: |
|
6783 |
||
6784 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 6785 |
copyWithColorMapProcessing:[:clr | Color red:(clr red) green:0 blue:0] |
81 | 6786 |
" |
89 | 6787 |
|
81 | 6788 |
" |
6789 |
make it reddish: |
|
6790 |
||
6791 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 6792 |
copyWithColorMapProcessing:[:clr | Color red:((clr red * 2) min:100) green:clr green blue:clr blue] |
81 | 6793 |
" |
89 | 6794 |
|
81 | 6795 |
" |
6796 |
invert: |
|
6797 |
||
6798 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 6799 |
copyWithColorMapProcessing:[:clr | Color red:(100 - clr red) green:(100 - clr green) blue:(100 - clr green)] |
81 | 6800 |
" |
89 | 6801 |
|
81 | 6802 |
" |
6803 |
lighter: |
|
6804 |
||
6805 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 6806 |
copyWithColorMapProcessing:[:clr | |r g b| |
6807 |
r := clr red. g := clr green. b := clr blue. |
|
6808 |
Color red:(r + (100-r//2)) |
|
6809 |
green:(g + (100-g//2)) |
|
6810 |
blue:(b + (100-b//2))] |
|
81 | 6811 |
" |
89 | 6812 |
|
81 | 6813 |
" |
6814 |
darker: |
|
6815 |
||
6816 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 6817 |
copyWithColorMapProcessing:[:clr | Color red:(clr red//2) green:(clr green // 2) blue:(clr blue // 2)] |
81 | 6818 |
" |
6819 |
! |
|
6820 |
||
283 | 6821 |
darkened |
6822 |
"return a new image which is slightly darker than the receiver. |
|
6823 |
The receiver must be a palette image (currently). |
|
592 | 6824 |
CAVEAT: Need an argument, which specifies by how much it should be darker." |
283 | 6825 |
|
6826 |
^ self |
|
592 | 6827 |
copyWithColorMapProcessing:[:clr | |
6828 |
Color red:(clr red // 2) |
|
6829 |
green:(clr green // 2) |
|
6830 |
blue:(clr blue // 2)] |
|
283 | 6831 |
|
6832 |
" |
|
6833 |
(Image fromFile:'bitmaps/claus.gif') inspect |
|
6834 |
(Image fromFile:'bitmaps/claus.gif') darkened inspect |
|
6835 |
" |
|
592 | 6836 |
|
6837 |
"Modified: 23.4.1996 / 11:14:34 / cg" |
|
283 | 6838 |
! |
6839 |
||
6840 |
flipHorizontal |
|
6841 |
"inplace horizontal flip" |
|
6842 |
||
6843 |
|w "{Class: SmallInteger }" |
|
6844 |
h "{Class: SmallInteger }" |
|
6845 |
c2 "{Class: SmallInteger }" |
|
6846 |
value | |
|
6847 |
||
6848 |
w := width - 1. |
|
6849 |
h := height - 1. |
|
6850 |
||
6851 |
0 to:h do:[:row | |
|
6852 |
c2 := w. |
|
6853 |
0 to:(w // 2) do:[:col | |
|
6854 |
value := self valueAtX:col y:row. |
|
6855 |
self atX:col y:row putValue:(self valueAtX:c2 y:row). |
|
6856 |
self atX:c2 y:row putValue:value. |
|
6857 |
c2 := c2 - 1. |
|
6858 |
] |
|
81 | 6859 |
]. |
283 | 6860 |
"flush device info" |
6861 |
self restored |
|
6862 |
! |
|
6863 |
||
6864 |
flipVertical |
|
6865 |
"inplace vertical flip" |
|
6866 |
||
6867 |
|h "{Class: SmallInteger }" |
|
6868 |
bytesPerRow "{Class: SmallInteger }" |
|
6869 |
buffer |
|
6870 |
indexLow "{Class: SmallInteger }" |
|
6871 |
indexHi "{Class: SmallInteger }"| |
|
6872 |
||
6873 |
bytesPerRow := self bytesPerRow. |
|
6874 |
buffer := ByteArray new:bytesPerRow. |
|
6875 |
||
6876 |
h := height - 1. |
|
6877 |
||
6878 |
indexLow := 1. |
|
6879 |
indexHi := bytesPerRow * h + 1. |
|
6880 |
||
6881 |
0 to:(h // 2) do:[:row | |
|
6882 |
buffer replaceFrom:1 to:bytesPerRow with:bytes startingAt:indexLow. |
|
6883 |
bytes replaceFrom:indexLow to:(indexLow + bytesPerRow - 1) with:bytes startingAt:indexHi. |
|
6884 |
bytes replaceFrom:indexHi to:(indexHi + bytesPerRow - 1) with:buffer startingAt:1. |
|
6885 |
indexLow := indexLow + bytesPerRow. |
|
6886 |
indexHi := indexHi - bytesPerRow. |
|
6887 |
]. |
|
6888 |
"flush device info" |
|
6889 |
self restored |
|
6890 |
! |
|
6891 |
||
6892 |
hardMagnifiedBy:scalePoint |
|
6893 |
"return a new image magnified by scalePoint, aPoint. |
|
6894 |
This is the general magnification method, handling non-integral values. |
|
6895 |
It is slower than the integral magnification method." |
|
6896 |
||
6897 |
|mX |
|
6898 |
mY |
|
6899 |
newWidth "{ Class: SmallInteger }" |
|
6900 |
newHeight "{ Class: SmallInteger }" |
|
6901 |
w "{ Class: SmallInteger }" |
|
6902 |
h "{ Class: SmallInteger }" |
|
906 | 6903 |
newImage newBits bitsPerPixel newBytesPerRow newMask |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6904 |
value |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6905 |
srcRow| |
283 | 6906 |
|
6907 |
mX := scalePoint x. |
|
6908 |
mY := scalePoint y. |
|
6909 |
((mX < 0) or:[mY < 0]) ifTrue:[^ nil]. |
|
6910 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
|
6911 |
||
6912 |
newWidth := (width * mX) truncated. |
|
6913 |
newHeight := (height * mY) truncated. |
|
6914 |
||
6915 |
bitsPerPixel := self depth. |
|
6916 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
|
6917 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight). |
|
6918 |
||
906 | 6919 |
mask notNil ifTrue:[ |
6920 |
newMask := (mask magnifiedBy:scalePoint) |
|
6921 |
]. |
|
6922 |
||
283 | 6923 |
newImage := self species new. |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6924 |
newImage |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6925 |
width:newWidth |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6926 |
height:newHeight |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6927 |
photometric:photometric |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6928 |
samplesPerPixel:samplesPerPixel |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6929 |
bitsPerSample:bitsPerSample |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6930 |
colorMap:colorMap copy |
906 | 6931 |
bits:newBits |
6932 |
mask:newMask. |
|
905
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
6933 |
|
283 | 6934 |
"walk over destination image fetching pixels from source image" |
6935 |
||
6936 |
w := newWidth - 1. |
|
6937 |
h := newHeight - 1. |
|
6938 |
||
6939 |
0 to:h do:[:row | |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6940 |
srcRow := (row // mY). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6941 |
0 to:w do:[:col | |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6942 |
value := self valueAtX:(col // mX) y:srcRow. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6943 |
newImage atX:col y:row putValue:value. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6944 |
] |
283 | 6945 |
]. |
6946 |
||
6947 |
^ newImage |
|
6948 |
||
6949 |
"((Image fromFile:'bitmaps/claus.gif') magnifiedBy:0.5@0.5)" |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6950 |
|
906 | 6951 |
"Modified: 27.6.1996 / 17:46:05 / cg" |
283 | 6952 |
! |
6953 |
||
6954 |
hardRotated:degrees |
|
592 | 6955 |
"raise an error - rotation by arbitrary angles is not yet implemented" |
6956 |
||
283 | 6957 |
self error:'not yet implemented' |
592 | 6958 |
|
6959 |
"Modified: 23.4.1996 / 11:15:33 / cg" |
|
81 | 6960 |
! |
6961 |
||
54 | 6962 |
lightened |
89 | 6963 |
"return a new image which is slightly brighter than the receiver. |
6964 |
The receiver must be a palette image (currently). |
|
592 | 6965 |
CAVEAT: Need an argument, which specifies by how much it should be lighter." |
54 | 6966 |
|
81 | 6967 |
^ self |
592 | 6968 |
copyWithColorMapProcessing:[:clr | |r g b| |
6969 |
r := clr red. |
|
6970 |
g := clr green. |
|
6971 |
b := clr blue. |
|
6972 |
Color red:(r + (100-r//2)) |
|
6973 |
green:(g + (100-g//2)) |
|
6974 |
blue:(b + (100-b//2))] |
|
81 | 6975 |
|
6976 |
" |
|
6977 |
(Image fromFile:'bitmaps/claus.gif') inspect |
|
6978 |
(Image fromFile:'bitmaps/claus.gif') lightened inspect |
|
6979 |
(Image fromFile:'bitmaps/claus.gif') darkened inspect |
|
6980 |
(Image fromFile:'bitmaps/claus.gif') darkened darkened inspect |
|
6981 |
" |
|
592 | 6982 |
|
6983 |
"Modified: 23.4.1996 / 11:14:41 / cg" |
|
54 | 6984 |
! |
6985 |
||
134 | 6986 |
magnifiedBy:scale |
81 | 6987 |
"return a new image magnified by scalePoint, aPoint. |
72 | 6988 |
If non-integral magnify is asked for, pass the work on to 'hardMagnifyBy:' |
6989 |
while simple (integral) magnifications are handled here." |
|
0 | 6990 |
|
81 | 6991 |
|scalePoint mX mY |
46 | 6992 |
magX "{ Class: SmallInteger }" "new version of stc can find this out itself..." |
6993 |
magY "{ Class: SmallInteger }" |
|
6994 |
srcOffset "{ Class: SmallInteger }" |
|
6995 |
dstOffset "{ Class: SmallInteger }" |
|
6996 |
w "{ Class: SmallInteger }" |
|
6997 |
h "{ Class: SmallInteger }" |
|
6998 |
first |
|
906 | 6999 |
newWidth newHeight newImage newBits newMask |
81 | 7000 |
bitsPerPixel newBytesPerRow oldBytesPerRow| |
0 | 7001 |
|
81 | 7002 |
scalePoint := scale asPoint. |
7003 |
mX := scalePoint asPoint x. |
|
7004 |
mY := scalePoint asPoint y. |
|
46 | 7005 |
((mX <= 0) or:[mY <= 0]) ifTrue:[^ nil]. |
0 | 7006 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
7007 |
||
12 | 7008 |
((mX isMemberOf:SmallInteger) and:[mY isMemberOf:SmallInteger]) ifFalse:[ |
905
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7009 |
^ self hardMagnifiedBy:scalePoint |
0 | 7010 |
]. |
7011 |
||
2 | 7012 |
bitsPerPixel := self depth. |
0 | 7013 |
oldBytesPerRow := ((width * bitsPerPixel) + 7) // 8. |
7014 |
||
46 | 7015 |
w := width. |
7016 |
h := height. |
|
7017 |
magX := mX. |
|
7018 |
magY := mY. |
|
7019 |
||
7020 |
newWidth := w * mX. |
|
7021 |
newHeight := h * mY. |
|
0 | 7022 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
7023 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight). |
|
7024 |
||
906 | 7025 |
mask notNil ifTrue:[ |
7026 |
newMask := (mask magnifiedBy:scalePoint) |
|
7027 |
]. |
|
7028 |
||
0 | 7029 |
newImage := self species new. |
905
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7030 |
newImage |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7031 |
width:newWidth |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7032 |
height:newHeight |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7033 |
photometric:photometric |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7034 |
samplesPerPixel:samplesPerPixel |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7035 |
bitsPerSample:bitsPerSample |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7036 |
colorMap:colorMap copy |
906 | 7037 |
bits:newBits |
7038 |
mask:newMask. |
|
0 | 7039 |
|
7040 |
mX = 1 ifTrue:[ |
|
905
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7041 |
"expand rows only" |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7042 |
srcOffset := 1. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7043 |
dstOffset := 1. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7044 |
|
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7045 |
1 to:h do:[:row | |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7046 |
1 to:mY do:[:i | |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7047 |
newBits replaceFrom:dstOffset |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7048 |
to:(dstOffset + oldBytesPerRow - 1) |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7049 |
with:bytes |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7050 |
startingAt:srcOffset. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7051 |
dstOffset := dstOffset + newBytesPerRow |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7052 |
]. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7053 |
srcOffset := srcOffset + oldBytesPerRow. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7054 |
]. |
0 | 7055 |
] ifFalse:[ |
905
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7056 |
"expand cols" |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7057 |
(mX > 1) ifTrue:[ |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7058 |
dstOffset := 1. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7059 |
srcOffset := 1. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7060 |
1 to:h do:[:row | |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7061 |
self magnifyRowFrom:bytes |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7062 |
offset:srcOffset |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7063 |
into:newBits |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7064 |
offset:dstOffset |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7065 |
factor:mX. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7066 |
|
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7067 |
first := dstOffset. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7068 |
dstOffset := dstOffset + newBytesPerRow. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7069 |
" and copy for row expansion " |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7070 |
2 to:mY do:[:i | |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7071 |
newBits replaceFrom:dstOffset |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7072 |
to:(dstOffset + newBytesPerRow - 1) |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7073 |
with:newBits |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7074 |
startingAt:first. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7075 |
dstOffset := dstOffset + newBytesPerRow |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7076 |
]. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7077 |
srcOffset := srcOffset + oldBytesPerRow. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7078 |
]. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7079 |
] |
0 | 7080 |
]. |
7081 |
^ newImage |
|
7082 |
||
134 | 7083 |
"((Image fromFile:'bitmaps/claus.gif') magnifiedBy:1@2)" |
905
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7084 |
|
906 | 7085 |
"Modified: 27.6.1996 / 17:46:28 / cg" |
2 | 7086 |
! |
7087 |
||
154 | 7088 |
magnifiedPreservingRatioTo:anExtent |
7089 |
"return a new image magnified to fit into anExtent, |
|
7090 |
preserving the receivers width/height ratio. |
|
7091 |
(i.e. not distorting the image). |
|
7092 |
See also #magnifiedTo: and #magnifiedBy:" |
|
7093 |
||
7094 |
|rX rY| |
|
7095 |
||
7096 |
rX := anExtent x / self width. |
|
7097 |
rY := anExtent y / self height. |
|
7098 |
^ self magnifiedBy:(rX min:rY) |
|
7099 |
||
7100 |
" |
|
7101 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedPreservingRatioTo:100@100) |
|
7102 |
||
7103 |
in contrast to: |
|
7104 |
||
7105 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:100@100) |
|
7106 |
" |
|
7107 |
! |
|
7108 |
||
134 | 7109 |
magnifiedTo:anExtent |
154 | 7110 |
"return a new image magnified to have the size specified by extent. |
7111 |
This may distort the image if the arguments ratio is not the images ratio. |
|
7112 |
See also #magnifiedPreservingRatioTo: and #magnifiedBy:" |
|
89 | 7113 |
|
134 | 7114 |
^ self magnifiedBy:(anExtent / self extent) |
89 | 7115 |
|
7116 |
" |
|
134 | 7117 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:100@100) |
154 | 7118 |
|
7119 |
in contrast to: |
|
7120 |
||
7121 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedPreservingRatioTo:100@100) |
|
89 | 7122 |
" |
7123 |
! |
|
7124 |
||
12 | 7125 |
rotated:degrees |
7126 |
"return a new image from the old one, by rotating the image |
|
46 | 7127 |
degrees clockwise. |
592 | 7128 |
CAVEAT: Currently, only rotation by a multiple of 90 degrees is implemented." |
12 | 7129 |
|
46 | 7130 |
|w "{Class: SmallInteger }" |
7131 |
h "{Class: SmallInteger }" |
|
12 | 7132 |
c2 "{Class: SmallInteger }" |
692 | 7133 |
r2 "{Class: SmallInteger }" |
7134 |
nW "{Class: SmallInteger }" |
|
7135 |
nH "{Class: SmallInteger }" |
|
24 | 7136 |
newImage newBits newBytesPerRow d| |
12 | 7137 |
|
7138 |
d := degrees. |
|
7139 |
[d < 0] whileTrue:[d := d + 360]. |
|
7140 |
d >= 360 ifTrue:[d := d \\ 360]. |
|
46 | 7141 |
d := d truncated. |
7142 |
d == 0 ifTrue:[^ self]. |
|
7143 |
((d ~~ 90) and:[(d ~~ 270) and:[d ~~ 180]]) ifTrue:[ |
|
592 | 7144 |
^ self hardRotated:d |
12 | 7145 |
]. |
7146 |
||
692 | 7147 |
d == 180 ifTrue:[ |
7148 |
nW := width. |
|
7149 |
nH := height. |
|
7150 |
] ifFalse:[ |
|
7151 |
nW := height. |
|
7152 |
nH := width. |
|
7153 |
]. |
|
7154 |
||
7155 |
newBytesPerRow := ((nW * self depth) + 7) // 8. |
|
7156 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * nH). |
|
12 | 7157 |
|
7158 |
newImage := self species new. |
|
7159 |
newImage bits:newBits. |
|
692 | 7160 |
newImage width:nW. |
7161 |
newImage height:nH. |
|
12 | 7162 |
newImage photometric:photometric. |
7163 |
newImage samplesPerPixel:samplesPerPixel. |
|
7164 |
newImage bitsPerSample:bitsPerSample. |
|
7165 |
newImage colorMap:colorMap copy. |
|
7166 |
||
7167 |
w := width - 1. |
|
7168 |
h := height - 1. |
|
7169 |
||
7170 |
d == 90 ifTrue:[ |
|
592 | 7171 |
0 to:h do:[:row | |
7172 |
c2 := h-row. |
|
798 | 7173 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 7174 |
newImage atX:c2 y:col putValue:pixel. |
592 | 7175 |
] |
692 | 7176 |
"/ 0 to:w do:[:col | |
7177 |
"/ newImage atX:c2 y:col putValue:(self valueAtX:col y:row). |
|
7178 |
"/ ] |
|
592 | 7179 |
] |
12 | 7180 |
]. |
46 | 7181 |
d == 180 ifTrue:[ |
592 | 7182 |
0 to:h do:[:row | |
692 | 7183 |
r2 := h - row. |
798 | 7184 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 7185 |
newImage atX:(w-col) y:r2 putValue:pixel. |
592 | 7186 |
] |
692 | 7187 |
"/ 0 to:w do:[:col | |
7188 |
"/ newImage atX:(w-col) y:r2 putValue:(self valueAtX:col y:row). |
|
7189 |
"/ ] |
|
592 | 7190 |
] |
46 | 7191 |
]. |
12 | 7192 |
d == 270 ifTrue:[ |
592 | 7193 |
0 to:h do:[:row | |
798 | 7194 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 7195 |
newImage atX:row y:(w-col) putValue:pixel. |
592 | 7196 |
] |
692 | 7197 |
"/ 0 to:w do:[:col | |
7198 |
"/ newImage atX:row y:(w-col) putValue:(self valueAtX:col y:row). |
|
7199 |
"/ ] |
|
592 | 7200 |
] |
12 | 7201 |
]. |
7202 |
^ newImage |
|
592 | 7203 |
|
692 | 7204 |
" |
7205 |
|i| |
|
7206 |
||
7207 |
i := Image fromFile:'claus.gif'. |
|
7208 |
i inspect. |
|
7209 |
(i rotated:90) inspect. |
|
7210 |
(i rotated:180) inspect. |
|
7211 |
(i rotated:270) inspect. |
|
7212 |
" |
|
7213 |
||
798 | 7214 |
"Modified: 7.6.1996 / 19:09:22 / cg" |
692 | 7215 |
! |
7216 |
||
7217 |
withPixelFunctionApplied:pixelFunctionBlock |
|
7218 |
"return a new image from the old one, by applying a pixel processor |
|
7219 |
(read `Behond photography, by Gerard J. Holzmann; |
|
7220 |
ISBM 0-13-074410-7) |
|
7221 |
See blurred / oilPointed as examples ...)" |
|
7222 |
||
7223 |
|w "{Class: SmallInteger }" |
|
7224 |
h "{Class: SmallInteger }" |
|
7225 |
newImage newBits newBytesPerRow d| |
|
7226 |
||
7227 |
newBytesPerRow := ((width * self depth) + 7) // 8. |
|
7228 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * height). |
|
7229 |
||
7230 |
newImage := self species new. |
|
7231 |
newImage bits:newBits. |
|
7232 |
newImage width:width. |
|
7233 |
newImage height:height. |
|
7234 |
newImage photometric:photometric. |
|
7235 |
newImage samplesPerPixel:samplesPerPixel. |
|
7236 |
newImage bitsPerSample:bitsPerSample. |
|
7237 |
newImage colorMap:colorMap copy. |
|
7238 |
||
7239 |
w := width - 1. |
|
7240 |
h := height - 1. |
|
7241 |
||
7242 |
0 to:h do:[:y | |
|
7243 |
0 to:w do:[:x | |
|
7244 |
newImage atX:x y:y put:(pixelFunctionBlock |
|
7245 |
value:self |
|
7246 |
value:x |
|
7247 |
value:y) |
|
7248 |
] |
|
7249 |
]. |
|
7250 |
^ newImage |
|
7251 |
||
7252 |
" |
|
7253 |
|i| |
|
7254 |
||
7255 |
i := Image fromFile:'claus.gif'. |
|
7256 |
i inspect. |
|
7257 |
(i withPixelFunctionApplied:[:oldImage :x :y | |
|
7258 |
((x between:100 and:200) |
|
7259 |
and:[y between:100 and:200]) ifTrue:[ |
|
7260 |
oldImage atX:x y:y |
|
7261 |
] ifFalse:[ |
|
7262 |
Color black. |
|
7263 |
] |
|
7264 |
]) inspect. |
|
7265 |
" |
|
7266 |
||
7267 |
"Modified: 17.5.1996 / 12:31:44 / cg" |
|
283 | 7268 |
! ! |
7269 |
||
7270 |
!Image methodsFor:'inspecting'! |
|
7271 |
||
7272 |
inspectorClass |
|
7273 |
"redefined to launch an ImageInspector |
|
7274 |
(instead of the default InspectorView)." |
|
7275 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7276 |
(width notNil and:[height notNil]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7277 |
^ ImageInspectorView |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7278 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7279 |
^ super inspectorClass |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7280 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7281 |
"Modified: 10.6.1996 / 18:23:55 / cg" |
283 | 7282 |
! ! |
7283 |
||
7284 |
!Image methodsFor:'instance release'! |
|
7285 |
||
7286 |
disposed |
|
7287 |
"some Image has been collected - nothing to do" |
|
12 | 7288 |
! |
7289 |
||
283 | 7290 |
release |
7291 |
"release device resources" |
|
7292 |
||
7293 |
device := nil. |
|
7294 |
deviceForm := nil. |
|
7295 |
monoDeviceForm := nil. |
|
7296 |
fullColorDeviceForm := nil. |
|
901 | 7297 |
mask notNil ifTrue:[ |
7298 |
mask release. |
|
7299 |
]. |
|
7300 |
Lobby unregister:self. |
|
7301 |
||
7302 |
"Modified: 21.6.1996 / 19:08:19 / cg" |
|
46 | 7303 |
! |
7304 |
||
283 | 7305 |
restored |
7306 |
"flush device specifics after a snapin or binary restore" |
|
7307 |
||
7308 |
self release |
|
7309 |
! ! |
|
7310 |
||
592 | 7311 |
!Image methodsFor:'obsolete'! |
7312 |
||
7313 |
magnifyBy:scale |
|
7314 |
"obsolete: has been renamed to magnifiedBy: for ST-80 compatibility |
|
7315 |
and name consistency ..." |
|
7316 |
||
7317 |
self obsoleteMethodWarning. |
|
7318 |
^ self magnifiedBy:scale |
|
7319 |
! ! |
|
7320 |
||
283 | 7321 |
!Image methodsFor:'pixel copying'! |
7322 |
||
7323 |
copyFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h |
|
7324 |
"replace a rectangulat area by pixels from another image. |
|
7325 |
WARNING: |
|
7326 |
This implementation is a slow fallback (the loop over the |
|
7327 |
source pixels is very slow). If this method is used heavily, you |
|
7328 |
may want to redefine it in concrete subclasses for the common case of |
|
7329 |
of copying from an Image with the same depth & palette." |
|
7330 |
||
7331 |
|dX dY| |
|
7332 |
||
7333 |
dX := srcX-dstX. |
|
7334 |
dY := srcY-dstY. |
|
7335 |
((photometric == anImage photometric) |
|
7336 |
and:[self bitsPerPixel == anImage bitsPerPixel |
|
7337 |
and:[colorMap = anImage colorMap]]) ifTrue:[ |
|
7338 |
"/ can loop over values |
|
7339 |
anImage valuesFromX:srcX y:srcY |
|
7340 |
toX:srcX+w-1 y:srcY+h-1 |
|
7341 |
do:[:x :y :pixelValue | |
|
7342 |
self atX:x-dX y:y-dY putValue:pixelValue. |
|
7343 |
] |
|
7344 |
] ifFalse:[ |
|
7345 |
"/ must loop over colors |
|
7346 |
anImage colorsFromX:srcX y:srcY |
|
7347 |
toX:srcX+w-1 y:srcY+h-1 |
|
7348 |
do:[:x :y :clr | |
|
7349 |
self atX:x-dX y:y-dY put:clr. |
|
7350 |
] |
|
7351 |
] |
|
7352 |
||
7353 |
" |
|
7354 |
|i1 i8 i4| |
|
7355 |
||
7356 |
i8 := Image fromFile:'bitmaps/garfield.gif'. |
|
7357 |
i8 inspect. |
|
7358 |
i1 := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
7359 |
i1 inspect. |
|
7360 |
||
7361 |
i4 := Depth4Image fromImage:i8. |
|
7362 |
i4 copyFrom:i1 x:0 y:0 toX:20 y:20 width:30 height:30. |
|
7363 |
i4 inspect. |
|
7364 |
" |
|
7365 |
||
7366 |
"Created: 20.9.1995 / 10:14:01 / claus" |
|
7367 |
"Modified: 20.9.1995 / 10:25:31 / claus" |
|
7368 |
! |
|
7369 |
||
7370 |
subImageIn:aRectangle |
|
7371 |
"create and return a new image consisting of a subArea of myself" |
|
7372 |
||
7373 |
^ self class fromSubImage:self in:aRectangle |
|
7374 |
||
7375 |
" |
|
7376 |
|i| |
|
7377 |
||
7378 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
7379 |
i inspect. |
|
7380 |
(i subImageIn:(300@160 corner:340@200)) inspect |
|
7381 |
" |
|
7382 |
||
7383 |
"Created: 20.9.1995 / 01:24:20 / claus" |
|
7384 |
! ! |
|
7385 |
||
7386 |
!Image methodsFor:'printing & storing'! |
|
7387 |
||
7388 |
storeOn:aStream |
|
592 | 7389 |
"append a printed representation of the receiver to aStream, |
7390 |
from which a copy of it can be reconstructed." |
|
7391 |
||
283 | 7392 |
aStream nextPutAll:'(' , self class name , ' new)'. |
7393 |
aStream nextPutAll:' width: '. width storeOn:aStream. |
|
7394 |
aStream nextPutAll:'; height: '. height storeOn:aStream. |
|
7395 |
aStream nextPutAll:'; photometric:('. photometric storeOn:aStream. |
|
7396 |
aStream nextPutAll:'); bitsPerSample:('. bitsPerSample storeOn:aStream. |
|
7397 |
aStream nextPutAll:'); samplesPerPixel:('. samplesPerPixel storeOn:aStream. |
|
7398 |
aStream nextPutAll:'); bits:('. bytes storeOn:aStream. aStream nextPutAll:') '. |
|
7399 |
colorMap notNil ifTrue:[ |
|
592 | 7400 |
aStream nextPutAll:'; colorMap:('. |
7401 |
colorMap storeOn:aStream. |
|
7402 |
aStream nextPutAll:')'. |
|
283 | 7403 |
]. |
7404 |
aStream nextPutAll:'; yourself' |
|
592 | 7405 |
|
7406 |
"Modified: 23.4.1996 / 11:18:05 / cg" |
|
0 | 7407 |
! ! |
7408 |
||
7409 |
!Image methodsFor:'private'! |
|
7410 |
||
193 | 7411 |
bestSupportedImageFormatFor:aDevice |
7412 |
"scan through the image formats as supported by aDevice, |
|
7413 |
and return the best to use when the receiver is to be represented |
|
7414 |
on it. The best format is the one with the same number or more bits per |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
7415 |
pixel. Here, the smallest format found which can represent enough pixels is taken." |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
7416 |
|
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
7417 |
|bestDeviceDepth bestDeviceBitsPerPixel bestInfo maxInfo myDepth maxDepth maxBitsPerPixel | |
193 | 7418 |
|
7419 |
myDepth := self bitsPerPixel. |
|
7420 |
maxBitsPerPixel := 0. |
|
7421 |
||
7422 |
aDevice supportedImageFormats do:[:entry | |
|
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7423 |
|deviceImageDepth deviceImageBitsPerPixel| |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7424 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7425 |
deviceImageDepth := entry at:#depth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7426 |
deviceImageBitsPerPixel := entry at:#bitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7427 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7428 |
deviceImageBitsPerPixel > maxBitsPerPixel ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7429 |
maxInfo := entry. |
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
7430 |
"/ maxBitsPerPixel := deviceImageBitsPerPixel. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
7431 |
"/ maxDepth := deviceImageDepth. |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7432 |
]. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7433 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7434 |
deviceImageDepth >= myDepth ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7435 |
deviceImageDepth == myDepth ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7436 |
"/ take the better one ... |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7437 |
(bestDeviceDepth isNil |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7438 |
or:[(bestDeviceBitsPerPixel ~~ bestDeviceDepth) |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7439 |
and:[deviceImageDepth == deviceImageBitsPerPixel]]) ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7440 |
bestInfo := entry. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7441 |
bestDeviceDepth := deviceImageDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7442 |
bestDeviceBitsPerPixel := deviceImageBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7443 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7444 |
] ifFalse:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7445 |
"/ take the next-larger depth |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7446 |
(bestDeviceDepth isNil |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7447 |
or:[deviceImageBitsPerPixel < bestDeviceBitsPerPixel]) ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7448 |
bestInfo := entry. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7449 |
bestDeviceDepth := deviceImageDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7450 |
bestDeviceBitsPerPixel := deviceImageBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7451 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7452 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7453 |
]. |
193 | 7454 |
]. |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7455 |
|
193 | 7456 |
bestDeviceDepth isNil ifTrue:[ |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7457 |
maxBitsPerPixel == 0 ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7458 |
"/ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7459 |
"/ oops - nothing appropriate |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7460 |
"/ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7461 |
maxInfo notNil ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7462 |
^ maxInfo |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7463 |
]. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7464 |
bestDeviceDepth := bestDeviceBitsPerPixel := aDevice depth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7465 |
bestInfo := IdentityDictionary new. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7466 |
bestInfo at:#depth put:bestDeviceDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7467 |
bestInfo at:#bitsPerPixel put:bestDeviceBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7468 |
bestInfo at:#padding put:32. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7469 |
] ifFalse:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7470 |
bestInfo := maxInfo. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7471 |
] |
193 | 7472 |
]. |
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
7473 |
^ bestInfo |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
7474 |
|
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
7475 |
"Modified: 14.6.1996 / 14:46:40 / cg" |
283 | 7476 |
! |
7477 |
||
7478 |
colormapFromImage:anImage |
|
7479 |
"setup the receivers colormap from another image. |
|
7480 |
Color precision may be lost, if conversion is from a higher depth |
|
7481 |
image. This does not convert any pixel values; it is non-public helper |
|
7482 |
for fromImage:/fromSubImake:" |
|
7483 |
||
7484 |
samplesPerPixel == 3 ifTrue:[ |
|
7485 |
photometric := #rgb |
|
7486 |
] ifFalse:[ |
|
7487 |
photometric := anImage photometric. |
|
7488 |
photometric == #palette ifTrue:[ |
|
7489 |
colorMap := anImage colorMap copy. |
|
7490 |
" |
|
7491 |
must compress the colormap, if source image has higher depth |
|
7492 |
than myself. |
|
7493 |
" |
|
7494 |
anImage bitsPerPixel > self bitsPerPixel ifTrue:[ |
|
7495 |
" |
|
7496 |
get used colors are extracted into our colorMap |
|
7497 |
(the at-put below will set the pixelValue according the |
|
7498 |
new colorIndex |
|
7499 |
" |
|
7500 |
colorMap := anImage usedColors asArray. |
|
7501 |
colorMap size > (1 bitShift:self bitsPerPixel) ifTrue:[ |
|
7502 |
'IMAGE: possibly too many colors in image' errorPrintNL |
|
7503 |
] |
|
7504 |
] |
|
7505 |
] |
|
7506 |
]. |
|
7507 |
||
7508 |
"Created: 20.9.1995 / 00:58:42 / claus" |
|
7509 |
! |
|
7510 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7511 |
greyByteMapForRange:range |
798 | 7512 |
"return a collection to map from pixelValues to greyLevels |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7513 |
in the range 0..range. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7514 |
Range must be < 256 (for elements to fit into a ByteArray). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7515 |
The values are rounded towards the nearest pixel." |
798 | 7516 |
|
808 | 7517 |
|d n greyMap r| |
7518 |
||
7519 |
r := range. |
|
7520 |
r == 256 ifTrue:[ |
|
7521 |
r := 255 |
|
798 | 7522 |
]. |
7523 |
||
7524 |
photometric == #palette ifTrue:[ |
|
808 | 7525 |
n := colorMap size. |
7526 |
greyMap := ByteArray new:n. |
|
7527 |
||
7528 |
1 to:n do:[:i | |
|
7529 |
greyMap at:i put:(r * (colorMap at:i) brightness) rounded |
|
798 | 7530 |
]. |
7531 |
] ifFalse:[ |
|
808 | 7532 |
d := self bitsPerPixel. |
7533 |
n := 1 bitShift:d. |
|
7534 |
n >= 4096 ifTrue:[ |
|
7535 |
self error:'size not supported - too large'. |
|
7536 |
^ nil |
|
7537 |
]. |
|
7538 |
greyMap := ByteArray new:n. |
|
7539 |
||
7540 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7541 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7542 |
1 to:n do:[:i | |
808 | 7543 |
greyMap at:i put:(r * (self colorFromValue:i-1) brightness) rounded |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7544 |
]. |
798 | 7545 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7546 |
1 to:n do:[:i | |
808 | 7547 |
greyMap at:i put:(r / (n-1) * (i-1)) rounded |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7548 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7549 |
photometric == #blackIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7550 |
"/ we are done |
798 | 7551 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7552 |
photometric == #whiteIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7553 |
greyMap reverse |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7554 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7555 |
self error:'invalid format'. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7556 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7557 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7558 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7559 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7560 |
]. |
808 | 7561 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7562 |
^ greyMap |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7563 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7564 |
" |
808 | 7565 |
Depth8Image new greyByteMapForRange:256 |
7566 |
||
7567 |
Depth8Image new greyByteMapForRange:64 |
|
7568 |
Depth4Image new greyByteMapForRange:64 |
|
7569 |
||
7570 |
Depth4Image new greyByteMapForRange:1 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7571 |
" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7572 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7573 |
"Created: 8.6.1996 / 08:34:14 / cg" |
808 | 7574 |
"Modified: 8.6.1996 / 14:52:32 / cg" |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7575 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7576 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7577 |
greyMapForRange:range |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7578 |
"return a collection to map from pixelValues to greyLevels |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7579 |
in the range 0..range. The brightness values are not rounded." |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7580 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7581 |
|d r |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7582 |
n "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7583 |
greyArray| |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7584 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7585 |
d := self bitsPerPixel. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7586 |
n := 1 bitShift:d. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7587 |
n >= 4096 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7588 |
self error:'size not supported - too large'. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7589 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7590 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7591 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7592 |
greyArray := Array new:n. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7593 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7594 |
photometric == #palette ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7595 |
1 to:(colorMap size) do:[:i | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7596 |
greyArray at:i put:(range * (colorMap at:i) brightness) |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7597 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7598 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7599 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7600 |
1 to:n do:[:i | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7601 |
greyArray at:i put:(range * (self colorFromValue:(i-1)) brightness) |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7602 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7603 |
] ifFalse:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7604 |
r := range asFloat. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7605 |
1 to:n do:[:i | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7606 |
greyArray at:i put:(r / (n-1) * (i-1)) |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7607 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7608 |
photometric == #blackIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7609 |
"/ we are done |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7610 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7611 |
photometric == #whiteIs0 ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7612 |
greyArray reverse |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7613 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7614 |
self error:'invalid format'. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7615 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7616 |
] |
798 | 7617 |
] |
7618 |
] |
|
7619 |
]. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7620 |
^ greyArray |
798 | 7621 |
|
7622 |
" |
|
7623 |
Depth8Image new greyMapForRange:64 |
|
7624 |
Depth4Image new greyMapForRange:64 |
|
7625 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7626 |
Depth16Image new greyMapForRange:1 |
798 | 7627 |
Depth4Image new greyMapForRange:1 |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7628 |
Depth2Image new greyMapForRange:1 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7629 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7630 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7631 |
"Modified: 10.6.1996 / 10:37:40 / cg" |
798 | 7632 |
! |
7633 |
||
283 | 7634 |
magnifyRowFrom:srcBytes offset:srcStart pixels:oldPixels |
7635 |
into:dstBytes offset:dstStart factor:mX |
|
7636 |
||
7637 |
"magnify a single pixel row - can only magnify by integer factors, |
|
7638 |
can only magnify 1,2,4,8 and 24 bit-per-pixel images. But this is done fast." |
|
7639 |
||
7640 |
^ self subclassResponsibility |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7641 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7642 |
|
816 | 7643 |
makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits |
7644 |
"given the bits of a grey/color bitmap, 8-bit padded and |
|
7645 |
pixels interpreted as greyValues, 0 is black, |
|
7646 |
create a device form for it" |
|
7647 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7648 |
|f| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7649 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7650 |
f := Form width:width height:height depth:depth on:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7651 |
f isNil ifTrue:[^ nil]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7652 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7653 |
f bits:bits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7654 |
f initGC. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7655 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7656 |
(aDevice blackpixel ~~ 0) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7657 |
"/ have to invert bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7658 |
f function:#copyInverted |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7659 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7660 |
aDevice drawBits:bits depth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7661 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7662 |
x:0 y:0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7663 |
into:(f id) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7664 |
x:0 y:0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7665 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7666 |
with:(f gcId). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7667 |
^ f |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7668 |
|
816 | 7669 |
"Created: 10.6.1996 / 20:10:31 / cg" |
7670 |
! |
|
7671 |
||
7672 |
makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
|
7673 |
"given the bits of a monochrome bitmap, 8-bit padded and |
|
7674 |
0-bits as black, create a device form for it" |
|
7675 |
||
7676 |
monoBits invert. |
|
7677 |
^ (Form width:width height:height fromArray:monoBits on:aDevice) |
|
7678 |
colorMap:(Array with:Color black with:Color white). |
|
7679 |
||
7680 |
"Created: 10.6.1996 / 20:18:09 / cg" |
|
7681 |
"Modified: 10.6.1996 / 20:31:24 / cg" |
|
7682 |
! |
|
7683 |
||
7684 |
makeDevicePixmapOn:aDevice depth:depth fromArray:bits |
|
7685 |
"given the bits of a grey/color bitmap, 8-bit padded and |
|
7686 |
pixels interpreted as in the devices colormap, |
|
7687 |
create a device form for it" |
|
7688 |
||
7689 |
|f| |
|
7690 |
||
7691 |
f := Form width:width height:height depth:depth on:aDevice. |
|
7692 |
f isNil ifTrue:[^ nil]. |
|
7693 |
||
7694 |
f bits:bits. |
|
7695 |
f initGC. |
|
7696 |
||
7697 |
aDevice drawBits:bits depth:depth |
|
7698 |
width:width height:height |
|
7699 |
x:0 y:0 |
|
7700 |
into:(f id) |
|
7701 |
x:0 y:0 |
|
7702 |
width:width height:height |
|
7703 |
with:(f gcId). |
|
7704 |
^ f |
|
7705 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7706 |
"Created: 10.6.1996 / 17:56:08 / cg" |
816 | 7707 |
"Modified: 10.6.1996 / 20:11:27 / cg" |
2 | 7708 |
! ! |
0 | 7709 |
|
283 | 7710 |
!Image methodsFor:'queries'! |
7711 |
||
7712 |
averageColor |
|
7713 |
"return the average color of the image. |
|
7714 |
This usually only makes sense for textures and patterns |
|
7715 |
(i.e. to compute shadow & light colors for viewBackgrounds). |
|
7716 |
Notice, that for the above purpose, it is usually ok to process |
|
7717 |
a subImage - i.e. use Image>>averageColorIn: on a smaller rectangle" |
|
7718 |
||
7719 |
^ self averageColorIn:(0@0 corner:(width-1)@(height-1)) |
|
7720 |
! |
|
7721 |
||
7722 |
averageColorIn:aRectangle |
|
7723 |
"return the images average color in an area. |
|
7724 |
The implementation below is slow - so you may want to |
|
7725 |
create tuned versions for DepthXImage if you plan to do |
|
7726 |
heavy image processing ... |
|
7727 |
(also, creating tuned versions of the enumeration messages helps a lot)" |
|
7728 |
||
7729 |
|x0 "{ Class:SmallInteger }" |
|
7730 |
y0 "{ Class:SmallInteger }" |
|
7731 |
x1 "{ Class:SmallInteger }" |
|
7732 |
y1 "{ Class:SmallInteger }" |
|
7733 |
sumRed sumGreen sumBlue n| |
|
7734 |
||
7735 |
sumRed := sumGreen := sumBlue := 0. |
|
7736 |
y0 := aRectangle top. |
|
7737 |
y1 := aRectangle bottom. |
|
7738 |
x0 := aRectangle left. |
|
7739 |
x1 := aRectangle right. |
|
7740 |
||
7741 |
self colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :colorAtXY | |
|
7742 |
sumRed := sumRed + colorAtXY red. |
|
7743 |
sumGreen := sumGreen + colorAtXY green. |
|
7744 |
sumBlue := sumBlue + colorAtXY blue. |
|
7745 |
]. |
|
7746 |
n := (x1 - x0 + 1) * (y1 - y0 + 1). |
|
7747 |
^ Color red:(sumRed / n) green:(sumGreen / n) blue:(sumBlue / n) |
|
7748 |
! |
|
7749 |
||
7750 |
bitsPerPixel |
|
7751 |
"return the number of bits per pixel" |
|
7752 |
||
7753 |
^ (bitsPerSample inject:0 into:[:sum :i | sum + i]) |
|
7754 |
! |
|
7755 |
||
7756 |
bitsPerRow |
|
7757 |
"return the number of bits in one scanline of the image" |
|
7758 |
||
7759 |
^ width * (self bitsPerPixel). |
|
7760 |
! |
|
7761 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7762 |
blueBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7763 |
"if the receiver is an rgb-image: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7764 |
return the blue bits of a pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7765 |
This has to be redefined by subclasses." |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7766 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7767 |
|blueBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7768 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7769 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7770 |
"/ assume that the red bits are the leftMost bits |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7771 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7772 |
blueBits := bitsPerSample at:3. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7773 |
blueBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7774 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7775 |
^ pixel bitAnd:(1 bitShift:blueBits)-1 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7776 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7777 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7778 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7779 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7780 |
"Created: 8.6.1996 / 09:44:21 / cg" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7781 |
"Modified: 10.6.1996 / 14:59:44 / cg" |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7782 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7783 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7784 |
blueComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7785 |
"if the receiver is an rgb-image: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7786 |
return the blue component (0 .. 100) of a pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7787 |
This has to be redefined by subclasses." |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7788 |
|
854 | 7789 |
|blueBits "{ Class: SmallInteger }" |
7790 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7791 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7792 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7793 |
"/ assume that the red bits are the leftMost bits |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7794 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7795 |
blueBits := bitsPerSample at:3. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7796 |
blueBits == 0 ifTrue:[^ 0]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7797 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7798 |
s := (1 bitShift:blueBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7799 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7800 |
^ 100.0 / s * (pixel bitAnd:(1 bitShift:blueBits)-1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7801 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7802 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7803 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7804 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7805 |
"Created: 8.6.1996 / 08:45:22 / cg" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7806 |
"Modified: 10.6.1996 / 14:55:39 / cg" |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7807 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7808 |
|
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7809 |
bounds |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7810 |
"return my bounds (added to make images usable as VisualComponents)" |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7811 |
|
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7812 |
^ Rectangle left:0 top:0 width:width height:height |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7813 |
|
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7814 |
"Created: 13.5.1996 / 10:27:06 / cg" |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7815 |
! |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7816 |
|
283 | 7817 |
brightness |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7818 |
"return the (average) brightness of the image. |
283 | 7819 |
This usually only makes sense for textures and patterns |
7820 |
(i.e. to compute shadow & light colors for viewBackgrounds). |
|
7821 |
Notice, that for the above purpose, only a subimage is inspected here" |
|
7822 |
||
7823 |
^ (self averageColorIn:(0@0 corner:7@7)) brightness |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7824 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7825 |
"Modified: 8.6.1996 / 08:46:46 / cg" |
283 | 7826 |
! |
7827 |
||
7828 |
bytesPerRow |
|
7829 |
"return the number of bytes in one scanline of the image" |
|
7830 |
||
7831 |
|bitsPerRow bytesPerRow| |
|
7832 |
||
7833 |
bitsPerRow := width * (self bitsPerPixel). |
|
7834 |
bytesPerRow := bitsPerRow // 8. |
|
7835 |
((bitsPerRow \\ 8) ~~ 0) ifTrue:[ |
|
7836 |
bytesPerRow := bytesPerRow + 1 |
|
7837 |
]. |
|
7838 |
^ bytesPerRow |
|
7839 |
! |
|
7840 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7841 |
colorFromValue:pixelValue |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7842 |
"given a pixel value, return the corresponding color. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7843 |
Pixel values start with 0." |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7844 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7845 |
|maxPixel r g b| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7846 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7847 |
photometric == #blackIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7848 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7849 |
^ Color gray:(pixelValue * (100 / maxPixel)). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7850 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7851 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7852 |
photometric == #whiteIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7853 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7854 |
^ Color gray:100 - (pixelValue * (100 / maxPixel)). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7855 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7856 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7857 |
photometric == #palette ifTrue:[ |
838
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
7858 |
pixelValue >= colorMap size ifTrue:[ |
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
7859 |
^ Color black |
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
7860 |
]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7861 |
^ colorMap at:(pixelValue + 1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7862 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7863 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7864 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7865 |
r := self redComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7866 |
g := self greenComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7867 |
b := self blueComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7868 |
^ Color red:r green:g blue:b |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7869 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7870 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7871 |
self error:'invalid photometric' |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7872 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7873 |
"Created: 8.6.1996 / 08:46:18 / cg" |
838
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
7874 |
"Modified: 12.6.1996 / 17:00:38 / cg" |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7875 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7876 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7877 |
greenBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7878 |
"if the receiver is an rgb-image: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7879 |
return the green bits of a pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7880 |
This has to be redefined by subclasses." |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7881 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7882 |
|blueBits greenBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7883 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7884 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7885 |
"/ assume that the red bits are the leftMost bits |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7886 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7887 |
greenBits := bitsPerSample at:2. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7888 |
greenBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7889 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7890 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7891 |
^ (pixel bitShift:blueBits negated) bitAnd:(1 bitShift:greenBits)-1 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7892 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7893 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7894 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7895 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7896 |
"Created: 8.6.1996 / 09:44:37 / cg" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7897 |
"Modified: 10.6.1996 / 14:59:35 / cg" |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7898 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7899 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7900 |
greenComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7901 |
"if the receiver is an rgb-image: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7902 |
return the green component (0..100) of a pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7903 |
This has to be redefined by subclasses." |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7904 |
|
854 | 7905 |
|greenBits "{ Class: SmallInteger }" |
7906 |
blueBits "{ Class: SmallInteger }" |
|
7907 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7908 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7909 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7910 |
"/ assume that the red bits are the leftMost bits |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7911 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7912 |
greenBits := bitsPerSample at:2. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7913 |
greenBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7914 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7915 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7916 |
s := (1 bitShift:greenBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7917 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7918 |
^ 100.0 / s * ((pixel bitShift:blueBits negated) bitAnd:(1 bitShift:greenBits)-1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7919 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7920 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7921 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7922 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7923 |
"Created: 8.6.1996 / 08:45:34 / cg" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7924 |
"Modified: 10.6.1996 / 14:55:24 / cg" |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7925 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7926 |
|
674 | 7927 |
heightOn:aGC |
7928 |
"return my height, if displayed on aGC; |
|
7929 |
since my height is independent of the device (the number of pixels), |
|
7930 |
return the pixel-height" |
|
7931 |
||
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7932 |
^ height |
674 | 7933 |
|
7934 |
"Created: 12.5.1996 / 21:35:06 / cg" |
|
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7935 |
"Modified: 13.5.1996 / 10:26:36 / cg" |
674 | 7936 |
! |
7937 |
||
283 | 7938 |
isImage |
7939 |
"return true, if the receiver is some kind of image; |
|
7940 |
true is returned here - the method is redefined from Object." |
|
7941 |
||
7942 |
^ true |
|
7943 |
! |
|
7944 |
||
7945 |
isImageOrForm |
|
7946 |
"return true, if the receiver is some kind of image or form; |
|
7947 |
true is returned here - the method is redefined from Object." |
|
7948 |
||
7949 |
^ true |
|
7950 |
! |
|
7951 |
||
940 | 7952 |
realColorMap |
7953 |
"return a collection usable as a real colormap of the image. |
|
7954 |
For palette images, this is the internal colormap; |
|
7955 |
for other photometrics (which do not have a real colormap), synthesize one. |
|
7956 |
This is different from #colorMap, which returns nil for non palette images." |
|
7957 |
||
7958 |
|d nEntries "{ Class: SmallInteger }" |
|
7959 |
colorArray| |
|
7960 |
||
7961 |
photometric == #palette ifTrue:[ |
|
7962 |
^ colorMap asArray |
|
7963 |
]. |
|
7964 |
||
7965 |
d := self depth. |
|
7966 |
d > 12 ifTrue:[ |
|
7967 |
self error:'deep palette images not supported'. |
|
7968 |
^ nil. |
|
7969 |
]. |
|
7970 |
||
7971 |
nEntries := 1 bitShift:d. |
|
7972 |
||
7973 |
colorArray := Array new:nEntries. |
|
7974 |
1 to:nEntries do:[:idx | |
|
7975 |
colorArray at:idx put:(self colorFromValue:(idx-1)). |
|
7976 |
]. |
|
7977 |
||
7978 |
^ colorArray |
|
7979 |
||
7980 |
"Created: 11.7.1996 / 20:20:35 / cg" |
|
7981 |
"Modified: 11.7.1996 / 20:49:21 / cg" |
|
7982 |
! |
|
7983 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7984 |
redBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7985 |
"if the receiver is an rgb-image: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7986 |
return the red component of a pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7987 |
This has to be redefined by subclasses." |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7988 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7989 |
|redBits greenBits blueBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7990 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7991 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7992 |
"/ assume that the red bits are the leftMost bits |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7993 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7994 |
redBits := bitsPerSample at:1. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7995 |
redBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7996 |
greenBits := bitsPerSample at:2. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7997 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7998 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7999 |
^ (pixel bitShift:(greenBits + blueBits) negated) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8000 |
bitAnd:(1 bitShift:redBits)-1 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8001 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8002 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8003 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8004 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8005 |
"Created: 8.6.1996 / 09:44:51 / cg" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8006 |
"Modified: 10.6.1996 / 14:59:05 / cg" |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8007 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8008 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8009 |
redComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8010 |
"if the receiver is an rgb-image: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8011 |
return the red component (0..100) of a pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8012 |
This has to be redefined by subclasses." |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8013 |
|
854 | 8014 |
|redBits "{ Class: SmallInteger }" |
8015 |
greenBits "{ Class: SmallInteger }" |
|
8016 |
blueBits "{ Class: SmallInteger }" |
|
8017 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8018 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8019 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8020 |
"/ assume that the red bits are the leftMost bits |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8021 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8022 |
redBits := bitsPerSample at:1. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8023 |
redBits == 0 ifTrue:[^ 0]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8024 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8025 |
greenBits := bitsPerSample at:2. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8026 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8027 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8028 |
s := (1 bitShift:redBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8029 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8030 |
^ 100.0 / s * |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8031 |
((pixel bitShift:(greenBits + blueBits) negated) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8032 |
bitAnd:(1 bitShift:redBits)-1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8033 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8034 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8035 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8036 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8037 |
"Created: 8.6.1996 / 08:45:30 / cg" |
854 | 8038 |
"Modified: 14.6.1996 / 17:34:00 / cg" |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8039 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8040 |
|
283 | 8041 |
usedColors |
8042 |
"return a collection of colors used in the receiver." |
|
8043 |
||
8044 |
|usedValues max| |
|
8045 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8046 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8047 |
"/ too many to be returned here (think of the mass of |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8048 |
"/ data to be returned by a 24bit image ... ;-) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8049 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8050 |
self error:'query not allowed for this image'. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8051 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8052 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8053 |
|
283 | 8054 |
usedValues := self usedValues asArray. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8055 |
photometric == #palette ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8056 |
^ usedValues collect:[:val | (colorMap at:val+1)] |
283 | 8057 |
]. |
8058 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8059 |
"/ (photometric == #blackIs0 or:[photometric == #whiteIs0]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8060 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8061 |
max := (1 bitShift:self depth) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8062 |
^ usedValues collect:[:val | (Color gray:(100 * val / max ))] |
283 | 8063 |
|
8064 |
" |
|
8065 |
(Image fromFile:'bitmaps/garfield.gif') usedColors |
|
8066 |
(Image fromFile:'bitmaps/SBrowser.xbm') usedColors |
|
8067 |
(Image fromFile:'ttt.tiff') usedColors |
|
8068 |
" |
|
746 | 8069 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8070 |
"Modified: 8.6.1996 / 09:04:56 / cg" |
283 | 8071 |
! |
8072 |
||
8073 |
usedValues |
|
8074 |
"return a collection of color values used in the receiver. |
|
8075 |
Notice, that the interpretation of the pixels depends on the photometric |
|
8076 |
of the image. |
|
8077 |
This is a general and therefore slow implementation; subclasses |
|
8078 |
may want to redefine this method for more performance." |
|
8079 |
||
8080 |
|set| |
|
8081 |
||
8082 |
set := IdentitySet new. |
|
8083 |
self valuesFromX:0 y:0 toX:(self width-1) y:(self height-1) do:[:x :y :pixel | |
|
8084 |
set add:pixel |
|
8085 |
]. |
|
8086 |
^ set |
|
8087 |
||
8088 |
" |
|
8089 |
(Image fromFile:'bitmaps/garfield.gif') usedValues |
|
8090 |
(Image fromFile:'bitmaps/SBrowser.xbm') usedValues |
|
8091 |
(Image fromFile:'ttt.tiff') usedValues |
|
8092 |
" |
|
674 | 8093 |
! |
8094 |
||
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8095 |
valueFromColor:color |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8096 |
"given a color, return the corresponding pixel value. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8097 |
Non-representable colors return nil." |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8098 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8099 |
|pixel maxPixel redBits greenBits blueBits r g b| |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8100 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8101 |
photometric == #whiteIs0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8102 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8103 |
^ maxPixel - (color brightness * maxPixel) rounded. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8104 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8105 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8106 |
photometric == #blackIs0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8107 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8108 |
^ (color brightness * maxPixel) rounded. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8109 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8110 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8111 |
photometric == #palette ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8112 |
pixel := colorMap indexOf:color. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8113 |
pixel == 0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8114 |
" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8115 |
the color to be stored is not in the images colormap |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8116 |
" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8117 |
^ nil |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8118 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8119 |
^ pixel - 1 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8120 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8121 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8122 |
photometric == #rgb ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8123 |
samplesPerPixel >= 3 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8124 |
redBits := bitsPerSample at:1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8125 |
greenBits := bitsPerSample at:2. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8126 |
blueBits := bitsPerSample at:3. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8127 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8128 |
"/ map r/g/b to 0..255 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8129 |
r := (color red / 100.0 * ((1 bitShift:redBits)-1)) rounded. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8130 |
g := (color green / 100.0 * ((1 bitShift:greenBits)-1)) rounded. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8131 |
b := (color blue / 100.0 * ((1 bitShift:blueBits)-1)) rounded. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8132 |
pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8133 |
^ pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8134 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8135 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8136 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8137 |
self error:'format not supported'. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8138 |
^ nil |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8139 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8140 |
"Modified: 15.6.1996 / 09:38:09 / cg" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8141 |
! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8142 |
|
674 | 8143 |
widthOn:aGC |
8144 |
"return my width, if displayed on aGC; |
|
8145 |
since my width is independent of the device (the number of pixels), |
|
8146 |
return the pixel-width" |
|
8147 |
||
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
8148 |
^ width |
674 | 8149 |
|
8150 |
"Created: 12.5.1996 / 21:34:59 / cg" |
|
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
8151 |
"Modified: 13.5.1996 / 10:26:42 / cg" |
283 | 8152 |
! ! |
8153 |
||
8154 |
!Image methodsFor:'saving on file'! |
|
8155 |
||
8156 |
saveOn:aFileName |
|
8157 |
"save the image in a aFileName. The suffix of the filename |
|
8158 |
controls the format. Currently, not all formats may be supported |
|
8159 |
(see ImageReader subclasses implementing save:onFile:)" |
|
8160 |
||
8161 |
" |
|
8162 |
from the extension, get the imageReader class |
|
8163 |
(which should know how to write images as well) |
|
8164 |
" |
|
8165 |
FileFormats associationsDo:[:a | |
|
8166 |
(aFileName endsWith:(a key)) ifTrue:[ |
|
8167 |
^ (a value) save:self onFile:aFileName |
|
8168 |
] |
|
8169 |
]. |
|
8170 |
||
8171 |
" |
|
8172 |
no known extension - could ask user for the format here. |
|
8173 |
currently default to tiff format. |
|
8174 |
" |
|
8175 |
'IMAGE: unknown extension - cannot figure out format - using tiff' errorPrintNL. |
|
8176 |
^ self saveOn:aFileName using:TIFFReader |
|
89 | 8177 |
! |
8178 |
||
283 | 8179 |
saveOn:aFileName using:readerClass |
8180 |
"save the receiver using the representation class" |
|
8181 |
||
8182 |
readerClass save:self onFile:aFileName |
|
8183 |
||
8184 |
" |
|
8185 |
anImage saveOn:'myImage' using:TIFFReader |
|
8186 |
anImage saveOn:'myImage' using:XBMReader |
|
8187 |
" |
|
0 | 8188 |
! ! |
283 | 8189 |
|
8190 |
!Image methodsFor:'screen capture'! |
|
8191 |
||
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8192 |
from:aDrawable in:aRectangle |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8193 |
"read an image from aDrawable. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8194 |
This may be a device Form, a view or the rootView. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8195 |
If its a view or rootView, it must be completely visible (or have |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8196 |
the backingStore option turned on). Otherwise, only the clipped contents |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8197 |
is returned. This is a common helper for form-to-image conversion, |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8198 |
and to read hardcopy images from the screen." |
283 | 8199 |
|
8200 |
|depth visType |
|
8201 |
x "{ Class: SmallInteger }" |
|
8202 |
y "{ Class: SmallInteger }" |
|
8203 |
w "{ Class: SmallInteger }" |
|
8204 |
h "{ Class: SmallInteger }" |
|
8205 |
dstIndex "{ Class: SmallInteger }" |
|
8206 |
srcIndex "{ Class: SmallInteger }" |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8207 |
srcRow "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8208 |
dstRow "{ Class: SmallInteger }" |
283 | 8209 |
inData tmpData usedPixels mapSize |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8210 |
map bitsPerPixel bytesPerLine byteOrder spaceBitsPerPixel |
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8211 |
info bitsPerPixelIn bytesPerLineIn |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8212 |
maskR "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8213 |
maskG "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8214 |
maskB "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8215 |
shR "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8216 |
shG "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8217 |
shB "{ Class: SmallInteger }" |
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
8218 |
shR2 "{ Class: SmallInteger }" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
8219 |
shG2 "{ Class: SmallInteger }" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
8220 |
shB2 "{ Class: SmallInteger }" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8221 |
r "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8222 |
g "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8223 |
b "{ Class: SmallInteger }" |
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8224 |
word device| |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8225 |
|
927
c4bc2a7ff733
use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents:
924
diff
changeset
|
8226 |
device := aDrawable graphicsDevice. |
283 | 8227 |
|
936 | 8228 |
(aDrawable isForm and:[aDrawable depth == 1]) ifTrue:[ |
8229 |
"/ a monochrome bitmap ? |
|
8230 |
visType := #StaticGray. |
|
8231 |
depth := 1. |
|
8232 |
] ifFalse:[ |
|
8233 |
" |
|
8234 |
get some attributes of the display device |
|
8235 |
" |
|
8236 |
visType := device visualType. |
|
8237 |
depth := device depth. |
|
8238 |
]. |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8239 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8240 |
"/ kludge for 15bit XFree server |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8241 |
depth == 15 ifTrue:[ |
518 | 8242 |
depth := 16 |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8243 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8244 |
|
283 | 8245 |
(visType == #StaticGray) ifTrue:[ |
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8246 |
(device blackpixel == 0) ifTrue:[ |
518 | 8247 |
photometric := #blackIs0 |
8248 |
] ifFalse:[ |
|
8249 |
photometric := #whiteIs0 |
|
8250 |
]. |
|
8251 |
samplesPerPixel := 1. |
|
8252 |
bitsPerPixel := depth. |
|
8253 |
bitsPerSample := Array with:bitsPerPixel. |
|
283 | 8254 |
] ifFalse:[ |
518 | 8255 |
((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[ |
8256 |
photometric := #palette. |
|
8257 |
samplesPerPixel := 1. |
|
8258 |
bitsPerPixel := depth. |
|
8259 |
bitsPerSample := Array with:bitsPerPixel. |
|
8260 |
] ifFalse:[ |
|
8261 |
((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[ |
|
8262 |
photometric := #rgb. |
|
8263 |
samplesPerPixel := 3. |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
8264 |
"/ bitsPerPixel := depth. |
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8265 |
"/ bitsPerSample := Array with:device bitsRed |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8266 |
"/ with:device bitsGreen |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8267 |
"/ with:device bitsBlue |
518 | 8268 |
bitsPerPixel := 24. |
8269 |
bitsPerSample := #(8 8 8). |
|
8270 |
] ifFalse:[ |
|
8271 |
self error:'screen visual not supported'. |
|
8272 |
^ nil |
|
8273 |
] |
|
8274 |
] |
|
283 | 8275 |
]. |
8276 |
||
8277 |
" |
|
8278 |
dont know yet, how the display pads; assume worst case, |
|
8279 |
offering enough space for 32 bit padding |
|
8280 |
" |
|
8281 |
w := width := aRectangle width. |
|
8282 |
h := height := aRectangle height. |
|
8283 |
x := aRectangle left. |
|
8284 |
y := aRectangle top. |
|
8285 |
||
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8286 |
" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8287 |
a kludge: we dont know in advance how much we are going to need |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8288 |
(its too late when info is present ...) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8289 |
" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8290 |
spaceBitsPerPixel := bitsPerPixel. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8291 |
(bitsPerPixel > 8) ifTrue:[ |
518 | 8292 |
spaceBitsPerPixel := 16. |
8293 |
(bitsPerPixel > 16) ifTrue:[ |
|
8294 |
spaceBitsPerPixel := 32. |
|
8295 |
(bitsPerPixel > 32) ifTrue:[ |
|
8296 |
spaceBitsPerPixel := bitsPerPixel. |
|
8297 |
] |
|
8298 |
] |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8299 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8300 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8301 |
bytesPerLine := (w * spaceBitsPerPixel + 31) // 32 * 4. |
283 | 8302 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
8303 |
||
8304 |
" |
|
8305 |
get the pixels |
|
8306 |
" |
|
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8307 |
info := device getBitsFrom:aDrawable id x:x y:y width:w height:h into:inData. |
283 | 8308 |
|
8309 |
" |
|
396
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
8310 |
check if byteorder is what I like (msbFirst) |
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
8311 |
" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8312 |
byteOrder := info at:#byteOrder. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8313 |
bitsPerPixelIn := info at:#bitsPerPixel. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8314 |
byteOrder ~~ #msbFirst ifTrue:[ |
518 | 8315 |
bitsPerPixelIn == 16 ifTrue:[ |
8316 |
"/ must swap bytes |
|
8317 |
inData swapBytes |
|
8318 |
] ifFalse:[ |
|
8319 |
bitsPerPixelIn == 32 ifTrue:[ |
|
8320 |
"/ must swap longs |
|
8321 |
inData swapLongs |
|
8322 |
] |
|
8323 |
] |
|
396
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
8324 |
]. |
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
8325 |
|
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
8326 |
" |
283 | 8327 |
check, if the devices padding is different .. |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8328 |
or if the bitsPerPixels are different |
283 | 8329 |
" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8330 |
bytesPerLineIn := (info at:#bytesPerLine). "what I got" |
283 | 8331 |
bytesPerLine := (w * bitsPerPixel + 7) // 8. "what I want" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8332 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8333 |
((bytesPerLine ~~ bytesPerLineIn) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8334 |
or:[bitsPerPixelIn ~~ bitsPerPixel]) ifTrue:[ |
518 | 8335 |
tmpData := inData. |
8336 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
|
8337 |
||
8338 |
srcRow := 1. |
|
8339 |
dstRow := 1. |
|
8340 |
||
8341 |
bitsPerPixelIn ~~ bitsPerPixel ifTrue:[ |
|
8342 |
"/ for now, only 32 -> 24 is supported |
|
8343 |
||
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8344 |
maskR := (1 bitShift:device bitsRed) - 1. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8345 |
maskG := (1 bitShift:device bitsGreen) - 1. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8346 |
maskB := (1 bitShift:device bitsBlue) - 1. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8347 |
shR := device shiftRed negated. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8348 |
shG := device shiftGreen negated. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8349 |
shB := device shiftBlue negated. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8350 |
shR2 := (8 - device bitsRed). |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8351 |
shG2 := (8 - device bitsGreen). |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8352 |
shB2 := (8 - device bitsBlue). |
518 | 8353 |
|
8354 |
((bitsPerPixelIn == 32) and:[bitsPerPixel == 24]) ifTrue:[ |
|
8355 |
"/ 'reformatting 32->24...' printNL. |
|
8356 |
1 to:h do:[:hi | |
|
8357 |
srcIndex := srcRow. |
|
8358 |
dstIndex := dstRow. |
|
8359 |
||
8360 |
1 to:w do:[:wi | |
|
8361 |
word := tmpData doubleWordAt:srcIndex MSB:true. |
|
8362 |
r := (word bitShift:shR) bitAnd:maskR. |
|
8363 |
g := (word bitShift:shG) bitAnd:maskG. |
|
8364 |
b := (word bitShift:shB) bitAnd:maskB. |
|
8365 |
||
8366 |
inData at:dstIndex put:r. |
|
8367 |
inData at:dstIndex+1 put:g. |
|
8368 |
inData at:dstIndex+2 put:b. |
|
8369 |
srcIndex := srcIndex + 4. |
|
8370 |
dstIndex := dstIndex + 3. |
|
8371 |
]. |
|
8372 |
dstRow := dstRow + bytesPerLine. |
|
8373 |
srcRow := srcRow + bytesPerLineIn |
|
8374 |
] |
|
8375 |
] ifFalse:[ |
|
8376 |
((bitsPerPixelIn == 16) and:[bitsPerPixel == 24]) ifTrue:[ |
|
8377 |
"/ 'reformatting 16->24...' printNL. |
|
8378 |
1 to:h do:[:hi | |
|
8379 |
srcIndex := srcRow. |
|
8380 |
dstIndex := dstRow. |
|
8381 |
||
8382 |
1 to:w do:[:wi | |
|
8383 |
word := tmpData wordAt:srcIndex MSB:true. |
|
8384 |
r := (word bitShift:shR) bitAnd:maskR. |
|
8385 |
g := (word bitShift:shG) bitAnd:maskG. |
|
8386 |
b := (word bitShift:shB) bitAnd:maskB. |
|
8387 |
||
8388 |
inData at:dstIndex put:(r bitShift:shR2). |
|
8389 |
inData at:dstIndex+1 put:(g bitShift:shG2). |
|
8390 |
inData at:dstIndex+2 put:(b bitShift:shB2). |
|
8391 |
srcIndex := srcIndex + 2. |
|
8392 |
dstIndex := dstIndex + 3. |
|
8393 |
]. |
|
8394 |
dstRow := dstRow + bytesPerLine. |
|
8395 |
srcRow := srcRow + bytesPerLineIn |
|
8396 |
] |
|
8397 |
] ifFalse:[ |
|
8398 |
('IMAGE: unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' , |
|
8399 |
bitsPerPixel printString) errorPrintNL. |
|
8400 |
^ nil |
|
8401 |
] |
|
8402 |
]. |
|
8403 |
] ifFalse:[ |
|
8404 |
" |
|
8405 |
repad in the buffer |
|
8406 |
" |
|
8407 |
1 to:h do:[:hi | |
|
8408 |
inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1) |
|
8409 |
with:tmpData startingAt:srcRow. |
|
8410 |
dstRow := dstRow + bytesPerLine. |
|
8411 |
srcRow := srcRow + bytesPerLineIn |
|
8412 |
] |
|
8413 |
] |
|
283 | 8414 |
] ifFalse:[ |
518 | 8415 |
(bytesPerLine * height) ~~ inData size ifTrue:[ |
8416 |
tmpData := inData. |
|
8417 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
|
8418 |
inData replaceFrom:1 to:bytesPerLine * height with:tmpData startingAt:1 |
|
8419 |
] |
|
283 | 8420 |
]. |
8421 |
bytes := inData. |
|
8422 |
||
8423 |
"info printNL." |
|
8424 |
||
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8425 |
((visType == #StaticGray) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8426 |
or:[visType == #TrueColor |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
8427 |
or:[visType == #DirectColor]]) ifTrue:[ |
518 | 8428 |
" |
8429 |
were done, the pixel values are the rgb/grey values |
|
8430 |
" |
|
283 | 8431 |
] ifFalse:[ |
518 | 8432 |
" |
8433 |
what we have now are the color numbers - still need the r/g/b values. |
|
8434 |
find out, which colors are in the picture |
|
8435 |
" |
|
8436 |
usedPixels := inData usedValues. |
|
8437 |
mapSize := usedPixels max + 1. |
|
8438 |
||
8439 |
"get the palette" |
|
8440 |
map := Array new:mapSize. |
|
8441 |
usedPixels do:[:colorIndex | |
|
8442 |
|i| |
|
8443 |
||
8444 |
i := colorIndex + 1. |
|
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8445 |
device getRGBFrom:colorIndex into:[:r :g :b | |
518 | 8446 |
map at:i put:(Color red:r green:g blue:b) |
8447 |
] |
|
8448 |
]. |
|
8449 |
colorMap := map. |
|
283 | 8450 |
]. |
8451 |
||
936 | 8452 |
"Modified: 11.7.1996 / 11:29:15 / cg" |
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8453 |
! |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8454 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8455 |
fromScreen:aRectangle |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8456 |
"read an image from the display screen" |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8457 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8458 |
^ self fromScreen:aRectangle on:Screen current |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8459 |
! |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8460 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8461 |
fromScreen:aRectangle on:aDevice |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8462 |
"read an image from aDevices display screen. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8463 |
Since I have no other displays, only the MonoChrome, StaticGrey |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8464 |
and PseudoColor cases have been tested ... |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8465 |
(especially True- and DirectColor may be wrong). |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8466 |
Late note: 24bit rgb now also works." |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8467 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8468 |
|curs cid rootView| |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8469 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8470 |
curs := Cursor sourceForm:(Form fromFile:'Camera.xbm') |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8471 |
maskForm:(Form fromFile:'Camera_m.xbm') |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8472 |
hotSpot:16@16. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8473 |
curs notNil ifTrue:[ |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8474 |
cid := (curs on:aDevice) id |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8475 |
]. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8476 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8477 |
" |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8478 |
actually have to grabServer ... but thats not yet available |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8479 |
" |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8480 |
rootView := aDevice rootView. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8481 |
aDevice setActivePointerGrab:rootView. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8482 |
aDevice grabPointerIn:rootView id |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8483 |
withCursor:cid |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8484 |
pointerMode:#async |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8485 |
keyboardMode:#sync |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8486 |
confineTo:nil. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8487 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8488 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8489 |
" |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8490 |
get the pixels |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8491 |
" |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8492 |
self from:rootView in:aRectangle. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8493 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8494 |
|
283 | 8495 |
aDevice ungrabPointer. |
8496 |
||
8497 |
" |
|
8498 |
(Image new) fromScreen:((0 @ 0) corner:(100 @ 100)) on:Display |
|
8499 |
(Image new) fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display |
|
8500 |
" |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
8501 |
|
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
8502 |
"Modified: 5.7.1996 / 16:16:51 / cg" |
936 | 8503 |
! |
8504 |
||
8505 |
photometricFromScreen:aDevice |
|
8506 |
"read aDevices display photometric and set my colormap for it. |
|
8507 |
This must be used after an images bits have been read from the screen |
|
8508 |
or from an offScreen bitmap, for correct pixel interpretation." |
|
8509 |
||
8510 |
|depth visType bitsPerPixel| |
|
8511 |
||
8512 |
" |
|
8513 |
get some attributes of the display device |
|
8514 |
" |
|
8515 |
visType := aDevice visualType. |
|
8516 |
depth := aDevice depth. |
|
8517 |
||
8518 |
"/ kludge for 15bit XFree server |
|
8519 |
depth == 15 ifTrue:[ |
|
8520 |
depth := 16 |
|
8521 |
]. |
|
8522 |
||
8523 |
(visType == #StaticGray) ifTrue:[ |
|
8524 |
(aDevice blackpixel == 0) ifTrue:[ |
|
8525 |
photometric := #blackIs0 |
|
8526 |
] ifFalse:[ |
|
8527 |
photometric := #whiteIs0 |
|
8528 |
]. |
|
8529 |
samplesPerPixel := 1. |
|
8530 |
bitsPerPixel := depth. |
|
8531 |
bitsPerSample := Array with:bitsPerPixel. |
|
8532 |
" |
|
8533 |
were done, the pixel values are the grey values |
|
8534 |
" |
|
8535 |
^ self |
|
8536 |
]. |
|
8537 |
||
8538 |
((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[ |
|
8539 |
photometric := #rgb. |
|
8540 |
samplesPerPixel := 3. |
|
8541 |
||
8542 |
"/ for now - only support 24bit TrueColor |
|
8543 |
depth ~~ 24 ifTrue:[ |
|
8544 |
'IMAGE: unsupported display depth' errorPrintCR. |
|
8545 |
]. |
|
8546 |
"/ bitsPerPixel := depth. |
|
8547 |
"/ bitsPerSample := Array with:aDevice bitsRed |
|
8548 |
"/ with:aDevice bitsGreen |
|
8549 |
"/ with:aDevice bitsBlue |
|
8550 |
bitsPerPixel := 24. |
|
8551 |
bitsPerSample := #(8 8 8). |
|
8552 |
" |
|
8553 |
were done, the pixel values are the rgb values |
|
8554 |
" |
|
8555 |
^ self |
|
8556 |
]. |
|
8557 |
||
8558 |
((visType ~~ #PseudoColor) |
|
8559 |
and:[(visType ~~ #StaticColor) |
|
8560 |
and:[visType ~~ #GrayScale]]) ifTrue:[ |
|
8561 |
self error:'screen visual not supported'. |
|
8562 |
^ nil |
|
8563 |
]. |
|
8564 |
||
8565 |
photometric := #palette. |
|
8566 |
samplesPerPixel := 1. |
|
8567 |
bitsPerPixel := depth. |
|
8568 |
bitsPerSample := Array with:bitsPerPixel. |
|
8569 |
||
8570 |
" |
|
8571 |
still need the pixels r/g/b values ... |
|
8572 |
" |
|
8573 |
colorMap := aDevice colorMap |
|
8574 |
||
8575 |
"Modified: 11.7.1996 / 11:11:34 / cg" |
|
283 | 8576 |
! ! |
8577 |
||
901 | 8578 |
!Image class methodsFor:'documentation'! |
283 | 8579 |
|
8580 |
version |
|
1057
410f0fec2872
oops - must register Image after assigning a deviceForm
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
8581 |
^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.125 1996-09-16 19:06:05 cg Exp $' |
650 | 8582 |
! ! |
283 | 8583 |
Image initialize! |